Test Failed
Branch develop (86e751)
by Laurent
34:11
created
htdocs/api/class/api.class.php 4 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,6 @@
 block discarded – undo
19 19
 use Luracast\Restler\Restler;
20 20
 use Luracast\Restler\RestException;
21 21
 use Luracast\Restler\Defaults;
22
-use Luracast\Restler\Format\UploadFormat;
23 22
 
24 23
 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
25 24
 
Please login to merge, or discard this patch.
Braces   +17 added lines, -9 removed lines patch added patch discarded remove patch
@@ -50,7 +50,9 @@  discard block
 block discarded – undo
50 50
     {
51 51
         global $conf, $dolibarr_main_url_root;
52 52
 
53
-        if (empty($cachedir)) $cachedir = $conf->api->dir_temp;
53
+        if (empty($cachedir)) {
54
+        	$cachedir = $conf->api->dir_temp;
55
+        }
54 56
         Defaults::$cacheDirectory = $cachedir;
55 57
 
56 58
         $this->db = $db;
@@ -183,8 +185,7 @@  discard block
 block discarded – undo
183 185
 		$featuresarray = array($resource);
184 186
 		if (preg_match('/&/', $resource)) {
185 187
 			$featuresarray = explode("&", $resource);
186
-		}
187
-		else if (preg_match('/\|/', $resource)) {
188
+		} else if (preg_match('/\|/', $resource)) {
188 189
 			$featuresarray = explode("|", $resource);
189 190
 		}
190 191
 
@@ -212,8 +213,12 @@  discard block
 block discarded – undo
212 213
 	    $counter=0;
213 214
 	    while ($i < $nb)
214 215
 	    {
215
-	        if ($tmp[$i]=='(') $counter++;
216
-	        if ($tmp[$i]==')') $counter--;
216
+	        if ($tmp[$i]=='(') {
217
+	        	$counter++;
218
+	        }
219
+	        if ($tmp[$i]==')') {
220
+	        	$counter--;
221
+	        }
217 222
             if ($counter < 0)
218 223
             {
219 224
 	           $error="Bad sqlfilters=".$sqlfilters;
@@ -236,16 +241,19 @@  discard block
 block discarded – undo
236 241
 	    global $db;
237 242
 
238 243
 	    //dol_syslog("Convert matches ".$matches[1]);
239
-	    if (empty($matches[1])) return '';
244
+	    if (empty($matches[1])) {
245
+	    	return '';
246
+	    }
240 247
 	    $tmp=explode(':',$matches[1]);
241
-        if (count($tmp) < 3) return '';
248
+        if (count($tmp) < 3) {
249
+        	return '';
250
+        }
242 251
 
243 252
 	    $tmpescaped=$tmp[2];
244 253
 	    if (preg_match('/^\'(.*)\'$/', $tmpescaped, $regbis))
245 254
 	    {
246 255
 	        $tmpescaped = "'".$db->escape($regbis[1])."'";
247
-	    }
248
-	    else
256
+	    } else
249 257
 	    {
250 258
 	        $tmpescaped = $db->escape($tmpescaped);
251 259
 	    }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
      * @param   string  $cachedir       Cache dir
47 47
      * @param   boolean $refreshCache   Update cache
48 48
      */
49
-    function __construct($db, $cachedir='', $refreshCache=false)
49
+    function __construct($db, $cachedir = '', $refreshCache = false)
50 50
     {
51 51
         global $conf, $dolibarr_main_url_root;
52 52
 
@@ -54,14 +54,14 @@  discard block
 block discarded – undo
54 54
         Defaults::$cacheDirectory = $cachedir;
55 55
 
56 56
         $this->db = $db;
57
-        $production_mode = ( empty($conf->global->API_PRODUCTION_MODE) ? false : true );
57
+        $production_mode = (empty($conf->global->API_PRODUCTION_MODE) ? false : true);
58 58
         $this->r = new Restler($production_mode, $refreshCache);
59 59
 
60
-        $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
61
-        $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
60
+        $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
61
+        $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
62 62
 
63
-        $urlwithouturlrootautodetect=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim(DOL_MAIN_URL_ROOT));
64
-        $urlwithrootautodetect=$urlwithouturlroot.DOL_URL_ROOT; // This is to use local domain autodetected by dolibarr from url
63
+        $urlwithouturlrootautodetect = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim(DOL_MAIN_URL_ROOT));
64
+        $urlwithrootautodetect = $urlwithouturlroot.DOL_URL_ROOT; // This is to use local domain autodetected by dolibarr from url
65 65
 
66 66
         $this->r->setBaseUrls($urlwithouturlroot, $urlwithouturlrootautodetect);
67 67
         $this->r->setAPIVersion(1);
@@ -113,9 +113,9 @@  discard block
 block discarded – undo
113 113
         unset($object->ref_next);
114 114
         unset($object->ref_int);
115 115
 
116
-        unset($object->projet);     // Should be fk_project
117
-        unset($object->project);    // Should be fk_project
118
-        unset($object->author);     // Should be fk_user_author
116
+        unset($object->projet); // Should be fk_project
117
+        unset($object->project); // Should be fk_project
118
+        unset($object->author); // Should be fk_user_author
119 119
         unset($object->timespent_old_duration);
120 120
         unset($object->timespent_id);
121 121
         unset($object->timespent_duration);
@@ -148,9 +148,9 @@  discard block
 block discarded – undo
148 148
         unset($object->oldcopy);
149 149
 
150 150
         // If object has lines, remove $db property
151
-        if(isset($object->lines) && count($object->lines) > 0)  {
151
+        if (isset($object->lines) && count($object->lines) > 0) {
152 152
             $nboflines = count($object->lines);
153
-        	for ($i=0; $i < $nboflines; $i++)
153
+        	for ($i = 0; $i < $nboflines; $i++)
154 154
             {
155 155
                 $this->_cleanObjectDatas($object->lines[$i]);
156 156
             }
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 	 * @param string	$dbt_select     Field name for select if not rowid. Not used if objectid is null (optional)
183 183
 	 * @throws RestException
184 184
 	 */
185
-	static function _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid') {
185
+	static function _checkAccessToResource($resource, $resource_id = 0, $dbtablename = '', $feature2 = '', $dbt_keyfield = 'fk_soc', $dbt_select = 'rowid') {
186 186
 
187 187
 		// Features/modules to check
188 188
 		$featuresarray = array($resource);
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
 		}
195 195
 
196 196
 		// More subfeatures to check
197
-		if (! empty($feature2)) {
197
+		if (!empty($feature2)) {
198 198
 			$feature2 = explode("|", $feature2);
199 199
 		}
200 200
 
@@ -211,17 +211,17 @@  discard block
 block discarded – undo
211 211
 	{
212 212
 	    //$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
213 213
 	    //$tmp=preg_replace_all('/'.$regexstring.'/', '', $sqlfilters);
214
-	    $tmp=$sqlfilters;
215
-	    $ok=0;
216
-	    $i=0; $nb=count($tmp);
217
-	    $counter=0;
214
+	    $tmp = $sqlfilters;
215
+	    $ok = 0;
216
+	    $i = 0; $nb = count($tmp);
217
+	    $counter = 0;
218 218
 	    while ($i < $nb)
219 219
 	    {
220
-	        if ($tmp[$i]=='(') $counter++;
221
-	        if ($tmp[$i]==')') $counter--;
220
+	        if ($tmp[$i] == '(') $counter++;
221
+	        if ($tmp[$i] == ')') $counter--;
222 222
             if ($counter < 0)
223 223
             {
224
-	           $error="Bad sqlfilters=".$sqlfilters;
224
+	           $error = "Bad sqlfilters=".$sqlfilters;
225 225
 	           dol_syslog($error, LOG_WARNING);
226 226
 	           return false;
227 227
             }
@@ -242,10 +242,10 @@  discard block
 block discarded – undo
242 242
 
243 243
 	    //dol_syslog("Convert matches ".$matches[1]);
244 244
 	    if (empty($matches[1])) return '';
245
-	    $tmp=explode(':',$matches[1]);
245
+	    $tmp = explode(':', $matches[1]);
246 246
         if (count($tmp) < 3) return '';
247 247
 
248
-	    $tmpescaped=$tmp[2];
248
+	    $tmpescaped = $tmp[2];
249 249
 	    if (preg_match('/^\'(.*)\'$/', $tmpescaped, $regbis))
250 250
 	    {
251 251
 	        $tmpescaped = "'".$db->escape($regbis[1])."'";
Please login to merge, or discard this patch.
Indentation   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -29,52 +29,52 @@  discard block
 block discarded – undo
29 29
 class DolibarrApi
30 30
 {
31 31
 
32
-    /**
33
-     * @var DoliDb        $db Database object
34
-     */
35
-    static protected $db;
36
-
37
-    /**
38
-     * @var Restler     $r	Restler object
39
-     */
40
-    var $r;
41
-
42
-    /**
43
-     * Constructor
44
-     *
45
-     * @param	DoliDb	$db		        Database handler
46
-     * @param   string  $cachedir       Cache dir
47
-     * @param   boolean $refreshCache   Update cache
48
-     */
49
-    function __construct($db, $cachedir='', $refreshCache=false)
50
-    {
51
-        global $conf, $dolibarr_main_url_root;
32
+	/**
33
+	 * @var DoliDb        $db Database object
34
+	 */
35
+	static protected $db;
36
+
37
+	/**
38
+	 * @var Restler     $r	Restler object
39
+	 */
40
+	var $r;
41
+
42
+	/**
43
+	 * Constructor
44
+	 *
45
+	 * @param	DoliDb	$db		        Database handler
46
+	 * @param   string  $cachedir       Cache dir
47
+	 * @param   boolean $refreshCache   Update cache
48
+	 */
49
+	function __construct($db, $cachedir='', $refreshCache=false)
50
+	{
51
+		global $conf, $dolibarr_main_url_root;
52 52
 
53
-        if (empty($cachedir)) $cachedir = $conf->api->dir_temp;
54
-        Defaults::$cacheDirectory = $cachedir;
53
+		if (empty($cachedir)) $cachedir = $conf->api->dir_temp;
54
+		Defaults::$cacheDirectory = $cachedir;
55 55
 
56
-        $this->db = $db;
57
-        $production_mode = ( empty($conf->global->API_PRODUCTION_MODE) ? false : true );
58
-        $this->r = new Restler($production_mode, $refreshCache);
56
+		$this->db = $db;
57
+		$production_mode = ( empty($conf->global->API_PRODUCTION_MODE) ? false : true );
58
+		$this->r = new Restler($production_mode, $refreshCache);
59 59
 
60
-        $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
61
-        $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
60
+		$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
61
+		$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
62 62
 
63
-        $urlwithouturlrootautodetect=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim(DOL_MAIN_URL_ROOT));
64
-        $urlwithrootautodetect=$urlwithouturlroot.DOL_URL_ROOT; // This is to use local domain autodetected by dolibarr from url
63
+		$urlwithouturlrootautodetect=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim(DOL_MAIN_URL_ROOT));
64
+		$urlwithrootautodetect=$urlwithouturlroot.DOL_URL_ROOT; // This is to use local domain autodetected by dolibarr from url
65 65
 
66
-        $this->r->setBaseUrls($urlwithouturlroot, $urlwithouturlrootautodetect);
67
-        $this->r->setAPIVersion(1);
68
-    }
66
+		$this->r->setBaseUrls($urlwithouturlroot, $urlwithouturlrootautodetect);
67
+		$this->r->setAPIVersion(1);
68
+	}
69 69
 
70
-    /**
71
-     * Executed method when API is called without parameter
72
-     *
73
-     * Display a short message an return a http code 200
74
-     *
75
-     * @return array
76
-     */
77
-    /* Disabled, most APIs does not share same signature for method index
70
+	/**
71
+	 * Executed method when API is called without parameter
72
+	 *
73
+	 * Display a short message an return a http code 200
74
+	 *
75
+	 * @return array
76
+	 */
77
+	/* Disabled, most APIs does not share same signature for method index
78 78
     function index()
79 79
     {
80 80
         return array(
@@ -86,81 +86,81 @@  discard block
 block discarded – undo
86 86
     }*/
87 87
 
88 88
 
89
-    /**
90
-     * Clean sensible object datas
91
-     *
92
-     * @param   object  $object	Object to clean
93
-     * @return	array	Array of cleaned object properties
94
-     */
95
-    function _cleanObjectDatas($object) {
96
-
97
-        // Remove $db object property for object
98
-        unset($object->db);
99
-
100
-        // Remove linkedObjects. We should already have linkedObjectIds that avoid huge responses
101
-        unset($object->linkedObjects);
102
-
103
-        unset($object->lines); // should be ->lines
104
-
105
-        unset($object->fields);
106
-
107
-        unset($object->oldline);
108
-
109
-        unset($object->error);
110
-        unset($object->errors);
111
-
112
-        unset($object->ref_previous);
113
-        unset($object->ref_next);
114
-        unset($object->ref_int);
115
-
116
-        unset($object->projet);     // Should be fk_project
117
-        unset($object->project);    // Should be fk_project
118
-        unset($object->author);     // Should be fk_user_author
119
-        unset($object->timespent_old_duration);
120
-        unset($object->timespent_id);
121
-        unset($object->timespent_duration);
122
-        unset($object->timespent_date);
123
-        unset($object->timespent_datehour);
124
-        unset($object->timespent_withhour);
125
-        unset($object->timespent_fk_user);
126
-        unset($object->timespent_note);
127
-
128
-        unset($object->statuts);
129
-        unset($object->statuts_short);
130
-        unset($object->statuts_logo);
131
-        unset($object->statuts_long);
132
-
133
-        unset($object->element);
134
-        unset($object->fk_element);
135
-        unset($object->table_element);
136
-        unset($object->table_element_line);
137
-        unset($object->picto);
138
-
139
-        unset($object->skip_update_total);
140
-        unset($object->context);
141
-
142
-        // Remove the $oldcopy property because it is not supported by the JSON
143
-        // encoder. The following error is generated when trying to serialize
144
-        // it: "Error encoding/decoding JSON: Type is not supported"
145
-        // Note: Event if this property was correctly handled by the JSON
146
-        // encoder, it should be ignored because keeping it would let the API
147
-        // have a very strange behavior: calling PUT and then GET on the same
148
-        // resource would give different results:
149
-        // PUT /objects/{id} -> returns object with oldcopy = previous version of the object
150
-        // GET /objects/{id} -> returns object with oldcopy empty
151
-        unset($object->oldcopy);
152
-
153
-        // If object has lines, remove $db property
154
-        if(isset($object->lines) && count($object->lines) > 0)  {
155
-            $nboflines = count($object->lines);
156
-        	for ($i=0; $i < $nboflines; $i++)
157
-            {
158
-                $this->_cleanObjectDatas($object->lines[$i]);
159
-            }
160
-        }
89
+	/**
90
+	 * Clean sensible object datas
91
+	 *
92
+	 * @param   object  $object	Object to clean
93
+	 * @return	array	Array of cleaned object properties
94
+	 */
95
+	function _cleanObjectDatas($object) {
96
+
97
+		// Remove $db object property for object
98
+		unset($object->db);
99
+
100
+		// Remove linkedObjects. We should already have linkedObjectIds that avoid huge responses
101
+		unset($object->linkedObjects);
102
+
103
+		unset($object->lines); // should be ->lines
104
+
105
+		unset($object->fields);
106
+
107
+		unset($object->oldline);
108
+
109
+		unset($object->error);
110
+		unset($object->errors);
111
+
112
+		unset($object->ref_previous);
113
+		unset($object->ref_next);
114
+		unset($object->ref_int);
115
+
116
+		unset($object->projet);     // Should be fk_project
117
+		unset($object->project);    // Should be fk_project
118
+		unset($object->author);     // Should be fk_user_author
119
+		unset($object->timespent_old_duration);
120
+		unset($object->timespent_id);
121
+		unset($object->timespent_duration);
122
+		unset($object->timespent_date);
123
+		unset($object->timespent_datehour);
124
+		unset($object->timespent_withhour);
125
+		unset($object->timespent_fk_user);
126
+		unset($object->timespent_note);
127
+
128
+		unset($object->statuts);
129
+		unset($object->statuts_short);
130
+		unset($object->statuts_logo);
131
+		unset($object->statuts_long);
132
+
133
+		unset($object->element);
134
+		unset($object->fk_element);
135
+		unset($object->table_element);
136
+		unset($object->table_element_line);
137
+		unset($object->picto);
138
+
139
+		unset($object->skip_update_total);
140
+		unset($object->context);
141
+
142
+		// Remove the $oldcopy property because it is not supported by the JSON
143
+		// encoder. The following error is generated when trying to serialize
144
+		// it: "Error encoding/decoding JSON: Type is not supported"
145
+		// Note: Event if this property was correctly handled by the JSON
146
+		// encoder, it should be ignored because keeping it would let the API
147
+		// have a very strange behavior: calling PUT and then GET on the same
148
+		// resource would give different results:
149
+		// PUT /objects/{id} -> returns object with oldcopy = previous version of the object
150
+		// GET /objects/{id} -> returns object with oldcopy empty
151
+		unset($object->oldcopy);
152
+
153
+		// If object has lines, remove $db property
154
+		if(isset($object->lines) && count($object->lines) > 0)  {
155
+			$nboflines = count($object->lines);
156
+			for ($i=0; $i < $nboflines; $i++)
157
+			{
158
+				$this->_cleanObjectDatas($object->lines[$i]);
159
+			}
160
+		}
161 161
 
162
-        // If object has linked objects, remove $db property
163
-        /*
162
+		// If object has linked objects, remove $db property
163
+		/*
164 164
         if(isset($object->linkedObjects) && count($object->linkedObjects) > 0)  {
165 165
             foreach($object->linkedObjects as $type_object => $linked_object) {
166 166
                 foreach($linked_object as $object2clean) {
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
         }*/
171 171
 
172 172
 		return $object;
173
-    }
173
+	}
174 174
 
175 175
 	/**
176 176
 	 * Check user access to a resource
@@ -212,25 +212,25 @@  discard block
 block discarded – undo
212 212
 	 */
213 213
 	function _checkFilters($sqlfilters)
214 214
 	{
215
-	    //$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
216
-	    //$tmp=preg_replace_all('/'.$regexstring.'/', '', $sqlfilters);
217
-	    $tmp=$sqlfilters;
218
-	    $ok=0;
219
-	    $i=0; $nb=count($tmp);
220
-	    $counter=0;
221
-	    while ($i < $nb)
222
-	    {
223
-	        if ($tmp[$i]=='(') $counter++;
224
-	        if ($tmp[$i]==')') $counter--;
225
-            if ($counter < 0)
226
-            {
227
-	           $error="Bad sqlfilters=".$sqlfilters;
228
-	           dol_syslog($error, LOG_WARNING);
229
-	           return false;
230
-            }
231
-            $i++;
232
-	    }
233
-	    return true;
215
+		//$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
216
+		//$tmp=preg_replace_all('/'.$regexstring.'/', '', $sqlfilters);
217
+		$tmp=$sqlfilters;
218
+		$ok=0;
219
+		$i=0; $nb=count($tmp);
220
+		$counter=0;
221
+		while ($i < $nb)
222
+		{
223
+			if ($tmp[$i]=='(') $counter++;
224
+			if ($tmp[$i]==')') $counter--;
225
+			if ($counter < 0)
226
+			{
227
+			   $error="Bad sqlfilters=".$sqlfilters;
228
+			   dol_syslog($error, LOG_WARNING);
229
+			   return false;
230
+			}
231
+			$i++;
232
+		}
233
+		return true;
234 234
 	}
235 235
 
236 236
 	/**
@@ -241,22 +241,22 @@  discard block
 block discarded – undo
241 241
 	 */
242 242
 	static function _forge_criteria_callback($matches)
243 243
 	{
244
-	    global $db;
245
-
246
-	    //dol_syslog("Convert matches ".$matches[1]);
247
-	    if (empty($matches[1])) return '';
248
-	    $tmp=explode(':',$matches[1]);
249
-        if (count($tmp) < 3) return '';
250
-
251
-	    $tmpescaped=$tmp[2];
252
-	    if (preg_match('/^\'(.*)\'$/', $tmpescaped, $regbis))
253
-	    {
254
-	        $tmpescaped = "'".$db->escape($regbis[1])."'";
255
-	    }
256
-	    else
257
-	    {
258
-	        $tmpescaped = $db->escape($tmpescaped);
259
-	    }
260
-	    return $db->escape($tmp[0]).' '.strtoupper($db->escape($tmp[1]))." ".$tmpescaped;
244
+		global $db;
245
+
246
+		//dol_syslog("Convert matches ".$matches[1]);
247
+		if (empty($matches[1])) return '';
248
+		$tmp=explode(':',$matches[1]);
249
+		if (count($tmp) < 3) return '';
250
+
251
+		$tmpescaped=$tmp[2];
252
+		if (preg_match('/^\'(.*)\'$/', $tmpescaped, $regbis))
253
+		{
254
+			$tmpescaped = "'".$db->escape($regbis[1])."'";
255
+		}
256
+		else
257
+		{
258
+			$tmpescaped = $db->escape($tmpescaped);
259
+		}
260
+		return $db->escape($tmp[0]).' '.strtoupper($db->escape($tmp[1]))." ".$tmpescaped;
261 261
 	}
262 262
 }
Please login to merge, or discard this patch.
htdocs/api/class/api_documents.class.php 4 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,6 @@
 block discarded – undo
18 18
  */
19 19
 
20 20
 use Luracast\Restler\RestException;
21
-use Luracast\Restler\Format\UploadFormat;
22 21
 
23 22
 
24 23
 require_once DOL_DOCUMENT_ROOT.'/main.inc.php';
Please login to merge, or discard this patch.
Braces   +14 added lines, -9 removed lines patch added patch discarded remove patch
@@ -109,8 +109,12 @@  discard block
 block discarded – undo
109 109
         }
110 110
 
111 111
         $newfilecontent = '';
112
-        if (empty($fileencoding)) $newfilecontent = $filecontent;
113
-        if ($fileencoding == 'base64') $newfilecontent = base64_decode($filecontent);
112
+        if (empty($fileencoding)) {
113
+        	$newfilecontent = $filecontent;
114
+        }
115
+        if ($fileencoding == 'base64') {
116
+        	$newfilecontent = base64_decode($filecontent);
117
+        }
114 118
 
115 119
 		$original_file = dol_sanitizeFileName($filename);
116 120
 
@@ -138,10 +142,11 @@  discard block
 block discarded – undo
138 142
     		{
139 143
     		    throw new RestException(500, 'This value of modulepart does not support yet usage of ref. Check modulepart parameter or try to use subdir parameter instead of ref.');
140 144
     		}
141
-		}
142
-		else
145
+		} else
143 146
 		{
144
-		    if ($modulepart == 'invoice') $modulepart ='facture';
147
+		    if ($modulepart == 'invoice') {
148
+		    	$modulepart ='facture';
149
+		    }
145 150
 		    
146 151
 		    $tmp = dol_check_secure_access_document($modulepart, $subdir, $entity, DolibarrApiAccess::$user, '', 'write');
147 152
     		$upload_dir = $tmp['original_file'];
@@ -174,8 +179,7 @@  discard block
 block discarded – undo
174 179
             $nbofbyteswrote = fwrite($fhandle, $newfilecontent);
175 180
             fclose($fhandle);
176 181
             @chmod($destfiletmp, octdec($conf->global->MAIN_UMASK));
177
-        }
178
-        else
182
+        } else
179 183
         {
180 184
             throw new RestException(500, "Failed to open file '".$destfiletmp."' for write");
181 185
         }
@@ -195,8 +199,9 @@  discard block
 block discarded – undo
195 199
     function _validate_file($data) {
196 200
         $result = array();
197 201
         foreach (Documents::$DOCUMENT_FIELDS as $field) {
198
-            if (!isset($data[$field]))
199
-                throw new RestException(400, "$field field missing");
202
+            if (!isset($data[$field])) {
203
+                            throw new RestException(400, "$field field missing");
204
+            }
200 205
             $result[$field] = $data[$field];
201 206
         }
202 207
         return $result;
Please login to merge, or discard this patch.
Indentation   +174 added lines, -174 removed lines patch added patch discarded remove patch
@@ -33,49 +33,49 @@  discard block
 block discarded – undo
33 33
 class Documents extends DolibarrApi
34 34
 {
35 35
 
36
-    /**
37
-     * @var array   $DOCUMENT_FIELDS     Mandatory fields, checked when create and update object
38
-     */
39
-    static $DOCUMENT_FIELDS = array(
40
-        'modulepart'
41
-    );
42
-
43
-    /**
44
-     * Constructor
45
-     */
46
-    function __construct()
47
-    {
48
-        global $db;
49
-        $this->db = $db;
50
-    }
51
-
52
-
53
-    /**
54
-     * Returns a document. Note that, this API is similar to using the wrapper link "documents.php" to download
55
-     * a file (used for internal HTML links of documents into application), but with no need to be into a logged session (no need to post the session cookie).
56
-     *
57
-     * @param   string  $module_part    Name of module or area concerned by file download ('facture', ...)
58
-     * @param   string  $original_file  Relative path with filename, relative to modulepart (for example: IN201701-999/IN201701-999.pdf)
59
-     * @param	int		$regeneratedoc	If requested document is the main document of an object, setting this to 1 ask API to regenerate document before returning it (supported for some module_part only). It is no effect in other cases.
60
-     * 									Also, note that setting this to 1 nead write access on object.
61
-     * @return  array                   List of documents
62
-     *
63
-     * @throws 500
64
-     * @throws 501
65
-     * @throws 400
66
-     * @throws 401
67
-     * @throws 200
68
-     */
69
-    public function index($module_part, $original_file='', $regeneratedoc=0)
70
-    {
36
+	/**
37
+	 * @var array   $DOCUMENT_FIELDS     Mandatory fields, checked when create and update object
38
+	 */
39
+	static $DOCUMENT_FIELDS = array(
40
+		'modulepart'
41
+	);
42
+
43
+	/**
44
+	 * Constructor
45
+	 */
46
+	function __construct()
47
+	{
48
+		global $db;
49
+		$this->db = $db;
50
+	}
51
+
52
+
53
+	/**
54
+	 * Returns a document. Note that, this API is similar to using the wrapper link "documents.php" to download
55
+	 * a file (used for internal HTML links of documents into application), but with no need to be into a logged session (no need to post the session cookie).
56
+	 *
57
+	 * @param   string  $module_part    Name of module or area concerned by file download ('facture', ...)
58
+	 * @param   string  $original_file  Relative path with filename, relative to modulepart (for example: IN201701-999/IN201701-999.pdf)
59
+	 * @param	int		$regeneratedoc	If requested document is the main document of an object, setting this to 1 ask API to regenerate document before returning it (supported for some module_part only). It is no effect in other cases.
60
+	 * 									Also, note that setting this to 1 nead write access on object.
61
+	 * @return  array                   List of documents
62
+	 *
63
+	 * @throws 500
64
+	 * @throws 501
65
+	 * @throws 400
66
+	 * @throws 401
67
+	 * @throws 200
68
+	 */
69
+	public function index($module_part, $original_file='', $regeneratedoc=0)
70
+	{
71 71
 		global $conf;
72 72
 
73 73
 		if (empty($module_part)) {
74
-	            throw new RestException(400, 'bad value for parameter modulepart');
74
+				throw new RestException(400, 'bad value for parameter modulepart');
75
+		}
76
+		if (empty($original_file)) {
77
+			throw new RestException(400, 'bad value for parameter ref or subdir');
75 78
 		}
76
-        if (empty($original_file)) {
77
-            throw new RestException(400, 'bad value for parameter ref or subdir');
78
-        }
79 79
 
80 80
 		//--- Finds and returns the document
81 81
 		$entity=$conf->entity;
@@ -87,94 +87,94 @@  discard block
 block discarded – undo
87 87
 
88 88
 		if (preg_match('/\.\./',$original_file) || preg_match('/[<>|]/',$original_file))
89 89
 		{
90
-		    throw new RestException(401);
90
+			throw new RestException(401);
91
+		}
92
+		if (!$accessallowed) {
93
+			throw new RestException(401);
94
+		}
95
+
96
+		// --- Generates the document
97
+		if ($regeneratedoc)
98
+		{
99
+			$hidedetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 0 : 1;
100
+			$hidedesc = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 0 : 1;
101
+			$hideref = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 0 : 1;
102
+
103
+			if ($module_part == 'facture' || $module_part == 'invoice')
104
+			{
105
+				require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
106
+				$this->invoice = new Facture($this->db);
107
+				$result = $this->invoice->fetch(0, $ref);
108
+				if( ! $result ) {
109
+					throw new RestException(404, 'Invoice not found');
110
+				}
111
+				$result = $this->invoice->generateDocument($this->invoice->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
112
+				if( $result <= 0 ) {
113
+					throw new RestException(500, 'Error generating document');
114
+				}
115
+			}
91 116
 		}
92
-	    if (!$accessallowed) {
93
-	        throw new RestException(401);
94
-	    }
95
-
96
-        // --- Generates the document
97
-        if ($regeneratedoc)
98
-        {
99
-        	$hidedetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 0 : 1;
100
-        	$hidedesc = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 0 : 1;
101
-        	$hideref = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 0 : 1;
102
-
103
-        	if ($module_part == 'facture' || $module_part == 'invoice')
104
-        	{
105
-        		require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
106
-        		$this->invoice = new Facture($this->db);
107
-        		$result = $this->invoice->fetch(0, $ref);
108
-        		if( ! $result ) {
109
-        			throw new RestException(404, 'Invoice not found');
110
-        		}
111
-        		$result = $this->invoice->generateDocument($this->invoice->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
112
-        		if( $result <= 0 ) {
113
-        			throw new RestException(500, 'Error generating document');
114
-        		}
115
-        	}
116
-        }
117 117
 
118 118
 		$filename = basename($original_file);
119 119
 		$original_file_osencoded=dol_osencode($original_file);	// New file name encoded in OS encoding charset
120 120
 
121 121
 		if (! file_exists($original_file_osencoded))
122 122
 		{
123
-		    throw new RestException(404, 'File not found');
123
+			throw new RestException(404, 'File not found');
124 124
 		}
125 125
 
126 126
 		$file_content=file_get_contents($original_file_osencoded);
127
-        return array('filename'=>$filename, 'content'=>base64_encode($file_content), 'encoding'=>'MIME base64 (base64_encode php function, http://php.net/manual/en/function.base64-encode.php)' );
128
-    }
129
-
130
-
131
-    /**
132
-     * Return a document.
133
-     *
134
-     * @param   int         $id          ID of document
135
-     * @return  array                    Array with data of file
136
-     *
137
-     * @throws RestException
138
-     */
139
-    /*
127
+		return array('filename'=>$filename, 'content'=>base64_encode($file_content), 'encoding'=>'MIME base64 (base64_encode php function, http://php.net/manual/en/function.base64-encode.php)' );
128
+	}
129
+
130
+
131
+	/**
132
+	 * Return a document.
133
+	 *
134
+	 * @param   int         $id          ID of document
135
+	 * @return  array                    Array with data of file
136
+	 *
137
+	 * @throws RestException
138
+	 */
139
+	/*
140 140
     public function get($id) {
141 141
         return array('note'=>'xxx');
142 142
     }*/
143 143
 
144 144
 
145
-    /**
146
-     * Push a file.
147
-     * Test sample 1: { "filename": "mynewfile.txt", "modulepart": "facture", "ref": "FA1701-001", "subdir": "", "filecontent": "content text", "fileencoding": "", "overwriteifexists": "0" }.
148
-     * Test sample 2: { "filename": "mynewfile.txt", "modulepart": "medias", "ref": "", "subdir": "mysubdir1/mysubdir2", "filecontent": "content text", "fileencoding": "", "overwriteifexists": "0" }.
149
-     *
150
-     * @param   string  $filename           Name of file to create ('FA1705-0123')
151
-     * @param   string  $modulepart         Name of module or area concerned by file upload ('facture', ...)
152
-     * @param   string  $ref                Reference of object (This will define subdir automatically and store submited file into it)
153
-     * @param   string  $subdir             Subdirectory (Only if ref not provided)
154
-     * @param   string  $filecontent        File content (string with file content. An empty file will be created if this parameter is not provided)
155
-     * @param   string  $fileencoding       File encoding (''=no encoding, 'base64'=Base 64)
156
-     * @param   int 	$overwriteifexists  Overwrite file if exists (1 by default)
157
-     * @return  bool     				    State of copy
158
-     * @throws RestException
159
-     */
160
-    public function post($filename, $modulepart, $ref='', $subdir='', $filecontent='', $fileencoding='', $overwriteifexists=0)
161
-    {
162
-        global $db, $conf;
163
-
164
-        /*var_dump($modulepart);
145
+	/**
146
+	 * Push a file.
147
+	 * Test sample 1: { "filename": "mynewfile.txt", "modulepart": "facture", "ref": "FA1701-001", "subdir": "", "filecontent": "content text", "fileencoding": "", "overwriteifexists": "0" }.
148
+	 * Test sample 2: { "filename": "mynewfile.txt", "modulepart": "medias", "ref": "", "subdir": "mysubdir1/mysubdir2", "filecontent": "content text", "fileencoding": "", "overwriteifexists": "0" }.
149
+	 *
150
+	 * @param   string  $filename           Name of file to create ('FA1705-0123')
151
+	 * @param   string  $modulepart         Name of module or area concerned by file upload ('facture', ...)
152
+	 * @param   string  $ref                Reference of object (This will define subdir automatically and store submited file into it)
153
+	 * @param   string  $subdir             Subdirectory (Only if ref not provided)
154
+	 * @param   string  $filecontent        File content (string with file content. An empty file will be created if this parameter is not provided)
155
+	 * @param   string  $fileencoding       File encoding (''=no encoding, 'base64'=Base 64)
156
+	 * @param   int 	$overwriteifexists  Overwrite file if exists (1 by default)
157
+	 * @return  bool     				    State of copy
158
+	 * @throws RestException
159
+	 */
160
+	public function post($filename, $modulepart, $ref='', $subdir='', $filecontent='', $fileencoding='', $overwriteifexists=0)
161
+	{
162
+		global $db, $conf;
163
+
164
+		/*var_dump($modulepart);
165 165
         var_dump($filename);
166 166
         var_dump($filecontent);
167 167
         exit;*/
168 168
 
169
-        require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
169
+		require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
170 170
 
171
-        if (!DolibarrApiAccess::$user->rights->ecm->upload) {
172
-            throw new RestException(401);
173
-        }
171
+		if (!DolibarrApiAccess::$user->rights->ecm->upload) {
172
+			throw new RestException(401);
173
+		}
174 174
 
175
-        $newfilecontent = '';
176
-        if (empty($fileencoding)) $newfilecontent = $filecontent;
177
-        if ($fileencoding == 'base64') $newfilecontent = base64_decode($filecontent);
175
+		$newfilecontent = '';
176
+		if (empty($fileencoding)) $newfilecontent = $filecontent;
177
+		if ($fileencoding == 'base64') $newfilecontent = base64_decode($filecontent);
178 178
 
179 179
 		$original_file = dol_sanitizeFileName($filename);
180 180
 
@@ -183,37 +183,37 @@  discard block
 block discarded – undo
183 183
 		$entity = $user->entity;
184 184
 		if ($ref)
185 185
 		{
186
-    		if ($modulepart == 'facture' || $modulepart == 'invoice')
187
-    		{
188
-    		    $modulepart='facture';
189
-    		    $object=new Facture($db);
190
-    		    $result = $object->fetch('', $ref);
191
-    		}
192
-
193
-    		if (! ($object->id > 0))
194
-    		{
195
-   		        throw new RestException(500, 'The object '.$modulepart." with ref '".$ref."' was not found.");
196
-    		}
197
-
198
-    		$tmp = dol_check_secure_access_document($modulepart, $tmpreldir.$object->ref, $entity, DolibarrApiAccess::$user, $ref, 'write');
199
-    		$upload_dir = $tmp['original_file'];
200
-
201
-    		if (empty($upload_dir) || $upload_dir == '/')
202
-    		{
203
-    		    throw new RestException(500, 'This value of modulepart does not support yet usage of ref. Check modulepart parameter or try to use subdir parameter instead of ref.');
204
-    		}
186
+			if ($modulepart == 'facture' || $modulepart == 'invoice')
187
+			{
188
+				$modulepart='facture';
189
+				$object=new Facture($db);
190
+				$result = $object->fetch('', $ref);
191
+			}
192
+
193
+			if (! ($object->id > 0))
194
+			{
195
+   				throw new RestException(500, 'The object '.$modulepart." with ref '".$ref."' was not found.");
196
+			}
197
+
198
+			$tmp = dol_check_secure_access_document($modulepart, $tmpreldir.$object->ref, $entity, DolibarrApiAccess::$user, $ref, 'write');
199
+			$upload_dir = $tmp['original_file'];
200
+
201
+			if (empty($upload_dir) || $upload_dir == '/')
202
+			{
203
+				throw new RestException(500, 'This value of modulepart does not support yet usage of ref. Check modulepart parameter or try to use subdir parameter instead of ref.');
204
+			}
205 205
 		}
206 206
 		else
207 207
 		{
208
-		    if ($modulepart == 'invoice') $modulepart ='facture';
208
+			if ($modulepart == 'invoice') $modulepart ='facture';
209 209
 
210
-		    $tmp = dol_check_secure_access_document($modulepart, $subdir, $entity, DolibarrApiAccess::$user, '', 'write');
211
-    		$upload_dir = $tmp['original_file'];
210
+			$tmp = dol_check_secure_access_document($modulepart, $subdir, $entity, DolibarrApiAccess::$user, '', 'write');
211
+			$upload_dir = $tmp['original_file'];
212 212
 
213
-		    if (empty($upload_dir) || $upload_dir == '/')
214
-    		{
215
-    		    throw new RestException(500, 'This value of modulepart does not support yet usage of ref. Check modulepart parameter or try to use subdir parameter instead of ref.');
216
-    		}
213
+			if (empty($upload_dir) || $upload_dir == '/')
214
+			{
215
+				throw new RestException(500, 'This value of modulepart does not support yet usage of ref. Check modulepart parameter or try to use subdir parameter instead of ref.');
216
+			}
217 217
 		}
218 218
 
219 219
 
@@ -223,46 +223,46 @@  discard block
 block discarded – undo
223 223
 		$destfiletmp = DOL_DATA_ROOT.'/admin/temp/' . $original_file;
224 224
 		dol_delete_file($destfiletmp);
225 225
 
226
-        if (!dol_is_dir($upload_dir)) {
227
-            throw new RestException(401,'Directory not exists : '.$upload_dir);
228
-        }
229
-
230
-        if (! $overwriteifexists && dol_is_file($destfile))
231
-        {
232
-            throw new RestException(500, "File with name '".$original_file."' already exists.");
233
-        }
234
-
235
-        $fhandle = @fopen($destfiletmp, 'w');
236
-        if ($fhandle)
237
-        {
238
-            $nbofbyteswrote = fwrite($fhandle, $newfilecontent);
239
-            fclose($fhandle);
240
-            @chmod($destfiletmp, octdec($conf->global->MAIN_UMASK));
241
-        }
242
-        else
243
-        {
244
-            throw new RestException(500, "Failed to open file '".$destfiletmp."' for write");
245
-        }
246
-
247
-        $result = dol_move($destfiletmp, $destfile, 0, $overwriteifexists, 1);
248
-
249
-        return $result;
250
-    }
251
-
252
-    /**
253
-     * Validate fields before create or update object
254
-     *
255
-     * @param   array           $data   Array with data to verify
256
-     * @return  array
257
-     * @throws  RestException
258
-     */
259
-    function _validate_file($data) {
260
-        $result = array();
261
-        foreach (Documents::$DOCUMENT_FIELDS as $field) {
262
-            if (!isset($data[$field]))
263
-                throw new RestException(400, "$field field missing");
264
-            $result[$field] = $data[$field];
265
-        }
266
-        return $result;
267
-    }
226
+		if (!dol_is_dir($upload_dir)) {
227
+			throw new RestException(401,'Directory not exists : '.$upload_dir);
228
+		}
229
+
230
+		if (! $overwriteifexists && dol_is_file($destfile))
231
+		{
232
+			throw new RestException(500, "File with name '".$original_file."' already exists.");
233
+		}
234
+
235
+		$fhandle = @fopen($destfiletmp, 'w');
236
+		if ($fhandle)
237
+		{
238
+			$nbofbyteswrote = fwrite($fhandle, $newfilecontent);
239
+			fclose($fhandle);
240
+			@chmod($destfiletmp, octdec($conf->global->MAIN_UMASK));
241
+		}
242
+		else
243
+		{
244
+			throw new RestException(500, "Failed to open file '".$destfiletmp."' for write");
245
+		}
246
+
247
+		$result = dol_move($destfiletmp, $destfile, 0, $overwriteifexists, 1);
248
+
249
+		return $result;
250
+	}
251
+
252
+	/**
253
+	 * Validate fields before create or update object
254
+	 *
255
+	 * @param   array           $data   Array with data to verify
256
+	 * @return  array
257
+	 * @throws  RestException
258
+	 */
259
+	function _validate_file($data) {
260
+		$result = array();
261
+		foreach (Documents::$DOCUMENT_FIELDS as $field) {
262
+			if (!isset($data[$field]))
263
+				throw new RestException(400, "$field field missing");
264
+			$result[$field] = $data[$field];
265
+		}
266
+		return $result;
267
+	}
268 268
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
      * @throws 401
67 67
      * @throws 200
68 68
      */
69
-    public function index($module_part, $original_file='', $regeneratedoc=0)
69
+    public function index($module_part, $original_file = '', $regeneratedoc = 0)
70 70
     {
71 71
 		global $conf;
72 72
 
@@ -78,14 +78,14 @@  discard block
 block discarded – undo
78 78
         }
79 79
 
80 80
 		//--- Finds and returns the document
81
-		$entity=$conf->entity;
81
+		$entity = $conf->entity;
82 82
 
83 83
 		$check_access = dol_check_secure_access_document($module_part, $original_file, $entity, DolibarrApiAccess::$user, '', ($regeneratedoc ? 'write' : 'read'));
84 84
 		$accessallowed              = $check_access['accessallowed'];
85 85
 		$sqlprotectagainstexternals = $check_access['sqlprotectagainstexternals'];
86 86
 		$original_file              = $check_access['original_file'];
87 87
 
88
-		if (preg_match('/\.\./',$original_file) || preg_match('/[<>|]/',$original_file))
88
+		if (preg_match('/\.\./', $original_file) || preg_match('/[<>|]/', $original_file))
89 89
 		{
90 90
 		    throw new RestException(401);
91 91
 		}
@@ -105,26 +105,26 @@  discard block
 block discarded – undo
105 105
         		require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
106 106
         		$this->invoice = new Facture($this->db);
107 107
         		$result = $this->invoice->fetch(0, $ref);
108
-        		if( ! $result ) {
108
+        		if (!$result) {
109 109
         			throw new RestException(404, 'Invoice not found');
110 110
         		}
111 111
         		$result = $this->invoice->generateDocument($this->invoice->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
112
-        		if( $result <= 0 ) {
112
+        		if ($result <= 0) {
113 113
         			throw new RestException(500, 'Error generating document');
114 114
         		}
115 115
         	}
116 116
         }
117 117
 
118 118
 		$filename = basename($original_file);
119
-		$original_file_osencoded=dol_osencode($original_file);	// New file name encoded in OS encoding charset
119
+		$original_file_osencoded = dol_osencode($original_file); // New file name encoded in OS encoding charset
120 120
 
121
-		if (! file_exists($original_file_osencoded))
121
+		if (!file_exists($original_file_osencoded))
122 122
 		{
123 123
 		    throw new RestException(404, 'File not found');
124 124
 		}
125 125
 
126
-		$file_content=file_get_contents($original_file_osencoded);
127
-        return array('filename'=>$filename, 'content'=>base64_encode($file_content), 'encoding'=>'MIME base64 (base64_encode php function, http://php.net/manual/en/function.base64-encode.php)' );
126
+		$file_content = file_get_contents($original_file_osencoded);
127
+        return array('filename'=>$filename, 'content'=>base64_encode($file_content), 'encoding'=>'MIME base64 (base64_encode php function, http://php.net/manual/en/function.base64-encode.php)');
128 128
     }
129 129
 
130 130
 
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
      * @return  bool     				    State of copy
158 158
      * @throws RestException
159 159
      */
160
-    public function post($filename, $modulepart, $ref='', $subdir='', $filecontent='', $fileencoding='', $overwriteifexists=0)
160
+    public function post($filename, $modulepart, $ref = '', $subdir = '', $filecontent = '', $fileencoding = '', $overwriteifexists = 0)
161 161
     {
162 162
         global $db, $conf;
163 163
 
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
         var_dump($filecontent);
167 167
         exit;*/
168 168
 
169
-        require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
169
+        require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
170 170
 
171 171
         if (!DolibarrApiAccess::$user->rights->ecm->upload) {
172 172
             throw new RestException(401);
@@ -185,12 +185,12 @@  discard block
 block discarded – undo
185 185
 		{
186 186
     		if ($modulepart == 'facture' || $modulepart == 'invoice')
187 187
     		{
188
-    		    $modulepart='facture';
189
-    		    $object=new Facture($db);
188
+    		    $modulepart = 'facture';
189
+    		    $object = new Facture($db);
190 190
     		    $result = $object->fetch('', $ref);
191 191
     		}
192 192
 
193
-    		if (! ($object->id > 0))
193
+    		if (!($object->id > 0))
194 194
     		{
195 195
    		        throw new RestException(500, 'The object '.$modulepart." with ref '".$ref."' was not found.");
196 196
     		}
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 		}
206 206
 		else
207 207
 		{
208
-		    if ($modulepart == 'invoice') $modulepart ='facture';
208
+		    if ($modulepart == 'invoice') $modulepart = 'facture';
209 209
 
210 210
 		    $tmp = dol_check_secure_access_document($modulepart, $subdir, $entity, DolibarrApiAccess::$user, '', 'write');
211 211
     		$upload_dir = $tmp['original_file'];
@@ -219,15 +219,15 @@  discard block
 block discarded – undo
219 219
 
220 220
 		$upload_dir = dol_sanitizePathName($upload_dir);
221 221
 
222
-		$destfile = $upload_dir . '/' . $original_file;
223
-		$destfiletmp = DOL_DATA_ROOT.'/admin/temp/' . $original_file;
222
+		$destfile = $upload_dir.'/'.$original_file;
223
+		$destfiletmp = DOL_DATA_ROOT.'/admin/temp/'.$original_file;
224 224
 		dol_delete_file($destfiletmp);
225 225
 
226 226
         if (!dol_is_dir($upload_dir)) {
227
-            throw new RestException(401,'Directory not exists : '.$upload_dir);
227
+            throw new RestException(401, 'Directory not exists : '.$upload_dir);
228 228
         }
229 229
 
230
-        if (! $overwriteifexists && dol_is_file($destfile))
230
+        if (!$overwriteifexists && dol_is_file($destfile))
231 231
         {
232 232
             throw new RestException(500, "File with name '".$original_file."' already exists.");
233 233
         }
Please login to merge, or discard this patch.
htdocs/societe/class/api_thirdparties.class.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
      * @param int		$id	Id of thirdparty
278 278
      * @param array     $request_data   Request datas
279 279
      *
280
-     * @return mixed
280
+     * @return Societe
281 281
      *
282 282
      * @url POST {id}/addCategory
283 283
      */
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 	/**
315 315
 	 * Clean sensible object datas
316 316
 	 *
317
-	 * @param   object  $object    Object to clean
317
+	 * @param   Societe  $object    Object to clean
318 318
 	 * @return    array    Array of cleaned object properties
319 319
 	 */
320 320
 	function _cleanObjectDatas($object) {
Please login to merge, or discard this patch.
Braces   +46 added lines, -20 removed lines patch added patch discarded remove patch
@@ -107,23 +107,44 @@  discard block
 block discarded – undo
107 107
             
108 108
         // If the internal user must only see his customers, force searching by him
109 109
         $search_sale = 0;
110
-        if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id;
110
+        if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) {
111
+        	$search_sale = DolibarrApiAccess::$user->id;
112
+        }
111 113
 
112 114
         $sql = "SELECT t.rowid";
113
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
115
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
116
+        	$sql .= ", sc.fk_soc, sc.fk_user";
117
+        }
118
+        // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
114 119
         $sql.= " FROM ".MAIN_DB_PREFIX."societe as t";
115 120
         
116
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
121
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
122
+        	$sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
123
+        }
124
+        // We need this table joined to the select in order to filter by sale
117 125
         $sql.= ", ".MAIN_DB_PREFIX."c_stcomm as st";
118 126
         $sql.= " WHERE t.fk_stcomm = st.id";
119
-        if ($mode == 1) $sql.= " AND t.client IN (1, 3)";
120
-        if ($mode == 2) $sql.= " AND t.client IN (2, 3)";
121
-        if ($mode == 3) $sql.= " AND t.client IN (0)";
127
+        if ($mode == 1) {
128
+        	$sql.= " AND t.client IN (1, 3)";
129
+        }
130
+        if ($mode == 2) {
131
+        	$sql.= " AND t.client IN (2, 3)";
132
+        }
133
+        if ($mode == 3) {
134
+        	$sql.= " AND t.client IN (0)";
135
+        }
122 136
         $sql.= ' AND t.entity IN ('.getEntity('societe').')';
123
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc";
137
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
138
+        	$sql.= " AND t.rowid = sc.fk_soc";
139
+        }
124 140
         //if ($email != NULL) $sql.= " AND s.email = \"".$email."\"";
125
-        if ($socid) $sql.= " AND t.rowid IN (".$socids.")";
126
-        if ($search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc";		// Join for the needed table to filter by sale
141
+        if ($socid) {
142
+        	$sql.= " AND t.rowid IN (".$socids.")";
143
+        }
144
+        if ($search_sale > 0) {
145
+        	$sql.= " AND t.rowid = sc.fk_soc";
146
+        }
147
+        // Join for the needed table to filter by sale
127 148
         // Insert sale filter
128 149
         if ($search_sale > 0)
129 150
         {
@@ -166,8 +187,7 @@  discard block
 block discarded – undo
166 187
                 }
167 188
                 $i++;
168 189
             }
169
-        }
170
-        else {
190
+        } else {
171 191
             throw new RestException(503, 'Error when retrieve thirdparties : '.$db->lasterror());
172 192
         }
173 193
         if( ! count($obj_ret)) {
@@ -193,8 +213,9 @@  discard block
 block discarded – undo
193 213
       foreach($request_data as $field => $value) {
194 214
           $this->company->$field = $value;
195 215
       }
196
-      if ($this->company->create(DolibarrApiAccess::$user) < 0)
197
-          throw new RestException(500, 'Error creating thirdparty', array_merge(array($this->company->error), $this->company->errors));
216
+      if ($this->company->create(DolibarrApiAccess::$user) < 0) {
217
+                throw new RestException(500, 'Error creating thirdparty', array_merge(array($this->company->error), $this->company->errors));
218
+      }
198 219
       
199 220
       return $this->company->id;
200 221
     }
@@ -222,12 +243,15 @@  discard block
 block discarded – undo
222 243
 		}
223 244
 
224 245
         foreach($request_data as $field => $value) {
225
-            if ($field == 'id') continue;
246
+            if ($field == 'id') {
247
+            	continue;
248
+            }
226 249
             $this->company->$field = $value;
227 250
         }
228 251
         
229
-        if($this->company->update($id, DolibarrApiAccess::$user,1,'','','update'))
230
-            return $this->get ($id);
252
+        if($this->company->update($id, DolibarrApiAccess::$user,1,'','','update')) {
253
+                    return $this->get ($id);
254
+        }
231 255
         
232 256
         return false;
233 257
     }
@@ -282,8 +306,9 @@  discard block
 block discarded – undo
282 306
      * @url POST {id}/addCategory
283 307
      */
284 308
     function addCategory($id, $request_data = NULL) {
285
-        if (!isset($request_data["category_id"]))
286
-            throw new RestException(400, "category_id field missing");
309
+        if (!isset($request_data["category_id"])) {
310
+                    throw new RestException(400, "category_id field missing");
311
+        }
287 312
         $category_id = $request_data["category_id"];
288 313
 
289 314
       if(! DolibarrApiAccess::$user->rights->societe->creer) {
@@ -342,8 +367,9 @@  discard block
 block discarded – undo
342 367
     {
343 368
         $thirdparty = array();
344 369
         foreach (Thirdparties::$FIELDS as $field) {
345
-            if (!isset($data[$field]))
346
-                throw new RestException(400, "$field field missing");
370
+            if (!isset($data[$field])) {
371
+                            throw new RestException(400, "$field field missing");
372
+            }
347 373
             $thirdparty[$field] = $data[$field];
348 374
         }
349 375
         return $thirdparty;
Please login to merge, or discard this patch.
Indentation   +275 added lines, -275 removed lines patch added patch discarded remove patch
@@ -28,32 +28,32 @@  discard block
 block discarded – undo
28 28
  */
29 29
 class Thirdparties extends DolibarrApi
30 30
 {
31
-    /**
32
-     *
33
-     * @var array   $FIELDS     Mandatory fields, checked when create and update object
34
-     */
35
-    static $FIELDS = array(
36
-        'name'
37
-    );
38
-
39
-    /**
40
-     * @var Societe $company {@type Societe}
41
-     */
42
-    public $company;
43
-
44
-    /**
45
-     * Constructor
46
-     */
47
-    function __construct()
48
-    {
31
+	/**
32
+	 *
33
+	 * @var array   $FIELDS     Mandatory fields, checked when create and update object
34
+	 */
35
+	static $FIELDS = array(
36
+		'name'
37
+	);
38
+
39
+	/**
40
+	 * @var Societe $company {@type Societe}
41
+	 */
42
+	public $company;
43
+
44
+	/**
45
+	 * Constructor
46
+	 */
47
+	function __construct()
48
+	{
49 49
 		global $db, $conf;
50 50
 		$this->db = $db;
51
-        $this->company = new Societe($this->db);
51
+		$this->company = new Societe($this->db);
52 52
 
53
-        if (! empty($conf->global->SOCIETE_EMAIL_MANDATORY)) {
54
-            static::$FIELDS[] = 'email';
55
-        }
56
-    }
53
+		if (! empty($conf->global->SOCIETE_EMAIL_MANDATORY)) {
54
+			static::$FIELDS[] = 'email';
55
+		}
56
+	}
57 57
 
58 58
   /**
59 59
    * Get properties of a thirdparty object
@@ -62,211 +62,211 @@  discard block
 block discarded – undo
62 62
    *
63 63
    * @param 	int 	$id ID of thirdparty
64 64
    * @return 	array|mixed data without useless information
65
-	 *
65
+   *
66 66
    * @throws 	RestException
67 67
    */
68
-    function get($id)
69
-    {
70
-      if(! DolibarrApiAccess::$user->rights->societe->lire) {
71
-        throw new RestException(401);
72
-      }
68
+	function get($id)
69
+	{
70
+	  if(! DolibarrApiAccess::$user->rights->societe->lire) {
71
+		throw new RestException(401);
72
+	  }
73 73
 
74
-      $result = $this->company->fetch($id);
75
-      if( ! $result ) {
76
-          throw new RestException(404, 'Thirdparty not found');
77
-      }
74
+	  $result = $this->company->fetch($id);
75
+	  if( ! $result ) {
76
+		  throw new RestException(404, 'Thirdparty not found');
77
+	  }
78 78
 
79
-      if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
80
-        throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
81
-      }
79
+	  if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
80
+		throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
81
+	  }
82 82
 
83 83
 		  return $this->_cleanObjectDatas($this->company);
84
-    }
85
-
86
-    /**
87
-     * List thirdparties
88
-     *
89
-     * Get a list of thirdparties
90
-     *
91
-     * @param   string  $sortfield  Sort field
92
-     * @param   string  $sortorder  Sort order
93
-     * @param   int     $limit      Limit for list
94
-     * @param   int     $page       Page number
95
-     * @param   int     $mode       Set to 1 to show only customers
96
-     *                              Set to 2 to show only prospects
97
-     *                              Set to 3 to show only those are not customer neither prospect
98
-     * @param   string  $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
99
-     * @return  array               Array of thirdparty objects
100
-     */
101
-    function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $mode=0, $sqlfilters = '') {
102
-        global $db, $conf;
103
-
104
-        $obj_ret = array();
105
-
106
-        // case of external user, we force socids
107
-        $socids = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : '';
108
-
109
-        // If the internal user must only see his customers, force searching by him
110
-        $search_sale = 0;
111
-        if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id;
112
-
113
-        $sql = "SELECT t.rowid";
114
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
115
-        $sql.= " FROM ".MAIN_DB_PREFIX."societe as t";
116
-
117
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
118
-        $sql.= ", ".MAIN_DB_PREFIX."c_stcomm as st";
119
-        $sql.= " WHERE t.fk_stcomm = st.id";
120
-        if ($mode == 1) $sql.= " AND t.client IN (1, 3)";
121
-        if ($mode == 2) $sql.= " AND t.client IN (2, 3)";
122
-        if ($mode == 3) $sql.= " AND t.client IN (0)";
123
-        $sql.= ' AND t.entity IN ('.getEntity('societe').')';
124
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc";
125
-        //if ($email != NULL) $sql.= " AND s.email = \"".$email."\"";
126
-        if ($socid) $sql.= " AND t.rowid IN (".$socids.")";
127
-        if ($search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc";		// Join for the needed table to filter by sale
128
-        // Insert sale filter
129
-        if ($search_sale > 0)
130
-        {
131
-            $sql .= " AND sc.fk_user = ".$search_sale;
132
-        }
133
-        // Add sql filters
134
-        if ($sqlfilters)
135
-        {
136
-            if (! DolibarrApi::_checkFilters($sqlfilters))
137
-            {
138
-                throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
139
-            }
140
-	        $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
141
-            $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
142
-        }
143
-
144
-        $sql.= $db->order($sortfield, $sortorder);
145
-
146
-        if ($limit) {
147
-            if ($page < 0)
148
-            {
149
-                $page = 0;
150
-            }
151
-            $offset = $limit * $page;
152
-
153
-            $sql.= $db->plimit($limit + 1, $offset);
154
-        }
84
+	}
85
+
86
+	/**
87
+	 * List thirdparties
88
+	 *
89
+	 * Get a list of thirdparties
90
+	 *
91
+	 * @param   string  $sortfield  Sort field
92
+	 * @param   string  $sortorder  Sort order
93
+	 * @param   int     $limit      Limit for list
94
+	 * @param   int     $page       Page number
95
+	 * @param   int     $mode       Set to 1 to show only customers
96
+	 *                              Set to 2 to show only prospects
97
+	 *                              Set to 3 to show only those are not customer neither prospect
98
+	 * @param   string  $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
99
+	 * @return  array               Array of thirdparty objects
100
+	 */
101
+	function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $mode=0, $sqlfilters = '') {
102
+		global $db, $conf;
103
+
104
+		$obj_ret = array();
105
+
106
+		// case of external user, we force socids
107
+		$socids = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : '';
108
+
109
+		// If the internal user must only see his customers, force searching by him
110
+		$search_sale = 0;
111
+		if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id;
112
+
113
+		$sql = "SELECT t.rowid";
114
+		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
115
+		$sql.= " FROM ".MAIN_DB_PREFIX."societe as t";
116
+
117
+		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
118
+		$sql.= ", ".MAIN_DB_PREFIX."c_stcomm as st";
119
+		$sql.= " WHERE t.fk_stcomm = st.id";
120
+		if ($mode == 1) $sql.= " AND t.client IN (1, 3)";
121
+		if ($mode == 2) $sql.= " AND t.client IN (2, 3)";
122
+		if ($mode == 3) $sql.= " AND t.client IN (0)";
123
+		$sql.= ' AND t.entity IN ('.getEntity('societe').')';
124
+		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc";
125
+		//if ($email != NULL) $sql.= " AND s.email = \"".$email."\"";
126
+		if ($socid) $sql.= " AND t.rowid IN (".$socids.")";
127
+		if ($search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc";		// Join for the needed table to filter by sale
128
+		// Insert sale filter
129
+		if ($search_sale > 0)
130
+		{
131
+			$sql .= " AND sc.fk_user = ".$search_sale;
132
+		}
133
+		// Add sql filters
134
+		if ($sqlfilters)
135
+		{
136
+			if (! DolibarrApi::_checkFilters($sqlfilters))
137
+			{
138
+				throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
139
+			}
140
+			$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
141
+			$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
142
+		}
143
+
144
+		$sql.= $db->order($sortfield, $sortorder);
145
+
146
+		if ($limit) {
147
+			if ($page < 0)
148
+			{
149
+				$page = 0;
150
+			}
151
+			$offset = $limit * $page;
152
+
153
+			$sql.= $db->plimit($limit + 1, $offset);
154
+		}
155 155
 
156 156
 		$result = $db->query($sql);
157
-        if ($result)
158
-        {
159
-            $num = $db->num_rows($result);
160
-            $min = min($num, ($limit <= 0 ? $num : $limit));
161
-            while ($i < $min)
162
-            {
163
-                $obj = $db->fetch_object($result);
164
-                $soc_static = new Societe($db);
165
-                if($soc_static->fetch($obj->rowid)) {
166
-                    $obj_ret[] = $this->_cleanObjectDatas($soc_static);
167
-                }
168
-                $i++;
169
-            }
170
-        }
171
-        else {
172
-            throw new RestException(503, 'Error when retrieve thirdparties : '.$db->lasterror());
173
-        }
174
-        if( ! count($obj_ret)) {
175
-            throw new RestException(404, 'Thirdparties not found');
176
-        }
157
+		if ($result)
158
+		{
159
+			$num = $db->num_rows($result);
160
+			$min = min($num, ($limit <= 0 ? $num : $limit));
161
+			while ($i < $min)
162
+			{
163
+				$obj = $db->fetch_object($result);
164
+				$soc_static = new Societe($db);
165
+				if($soc_static->fetch($obj->rowid)) {
166
+					$obj_ret[] = $this->_cleanObjectDatas($soc_static);
167
+				}
168
+				$i++;
169
+			}
170
+		}
171
+		else {
172
+			throw new RestException(503, 'Error when retrieve thirdparties : '.$db->lasterror());
173
+		}
174
+		if( ! count($obj_ret)) {
175
+			throw new RestException(404, 'Thirdparties not found');
176
+		}
177 177
 		return $obj_ret;
178
-    }
179
-
180
-    /**
181
-     * Create thirdparty object
182
-     *
183
-     * @param array $request_data   Request datas
184
-     * @return int  ID of thirdparty
185
-     */
186
-    function post($request_data = NULL)
187
-    {
188
-      if(! DolibarrApiAccess::$user->rights->societe->creer) {
189
-        throw new RestException(401);
190
-      }
191
-      // Check mandatory fields
192
-      $result = $this->_validate($request_data);
193
-
194
-      foreach($request_data as $field => $value) {
195
-          $this->company->$field = $value;
196
-      }
197
-      if ($this->company->create(DolibarrApiAccess::$user) < 0)
198
-          throw new RestException(500, 'Error creating thirdparty', array_merge(array($this->company->error), $this->company->errors));
199
-
200
-      return $this->company->id;
201
-    }
202
-
203
-    /**
204
-     * Update thirdparty
205
-     *
206
-     * @param int   $id             Id of thirdparty to update
207
-     * @param array $request_data   Datas
208
-     * @return int
209
-     */
210
-    function put($id, $request_data = NULL)
211
-    {
212
-        if(! DolibarrApiAccess::$user->rights->societe->creer) {
178
+	}
179
+
180
+	/**
181
+	 * Create thirdparty object
182
+	 *
183
+	 * @param array $request_data   Request datas
184
+	 * @return int  ID of thirdparty
185
+	 */
186
+	function post($request_data = NULL)
187
+	{
188
+	  if(! DolibarrApiAccess::$user->rights->societe->creer) {
189
+		throw new RestException(401);
190
+	  }
191
+	  // Check mandatory fields
192
+	  $result = $this->_validate($request_data);
193
+
194
+	  foreach($request_data as $field => $value) {
195
+		  $this->company->$field = $value;
196
+	  }
197
+	  if ($this->company->create(DolibarrApiAccess::$user) < 0)
198
+		  throw new RestException(500, 'Error creating thirdparty', array_merge(array($this->company->error), $this->company->errors));
199
+
200
+	  return $this->company->id;
201
+	}
202
+
203
+	/**
204
+	 * Update thirdparty
205
+	 *
206
+	 * @param int   $id             Id of thirdparty to update
207
+	 * @param array $request_data   Datas
208
+	 * @return int
209
+	 */
210
+	function put($id, $request_data = NULL)
211
+	{
212
+		if(! DolibarrApiAccess::$user->rights->societe->creer) {
213 213
 			throw new RestException(401);
214 214
 		}
215 215
 
216
-        $result = $this->company->fetch($id);
217
-        if( ! $result ) {
218
-            throw new RestException(404, 'Thirdparty not found');
219
-        }
216
+		$result = $this->company->fetch($id);
217
+		if( ! $result ) {
218
+			throw new RestException(404, 'Thirdparty not found');
219
+		}
220 220
 
221 221
 		if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
222 222
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
223 223
 		}
224 224
 
225
-        foreach($request_data as $field => $value) {
226
-            if ($field == 'id') continue;
227
-            $this->company->$field = $value;
228
-        }
229
-
230
-        if($this->company->update($id, DolibarrApiAccess::$user,1,'','','update'))
231
-            return $this->get ($id);
232
-
233
-        return false;
234
-    }
235
-
236
-    /**
237
-     * Delete thirdparty
238
-     *
239
-     * @param int $id   Thirparty ID
240
-     * @return integer
241
-     */
242
-    function delete($id)
243
-    {
244
-      if(! DolibarrApiAccess::$user->rights->societe->supprimer) {
245
-        throw new RestException(401);
246
-      }
247
-      $result = $this->company->fetch($id);
248
-      if( ! $result ) {
249
-          throw new RestException(404, 'Thirdparty not found');
250
-      }
251
-      if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
252
-        throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
253
-      }
254
-      return $this->company->delete($id);
255
-    }
256
-
257
-    /**
258
-     * Get categories for a thirdparty
259
-     *
260
-     * @param int		$id         ID of thirdparty
261
-     * @param string	$sortfield	Sort field
262
-     * @param string	$sortorder	Sort order
263
-     * @param int		$limit		Limit for list
264
-     * @param int		$page		Page number
265
-     *
266
-     * @return mixed
267
-     *
268
-     * @url GET {id}/categories
269
-     */
225
+		foreach($request_data as $field => $value) {
226
+			if ($field == 'id') continue;
227
+			$this->company->$field = $value;
228
+		}
229
+
230
+		if($this->company->update($id, DolibarrApiAccess::$user,1,'','','update'))
231
+			return $this->get ($id);
232
+
233
+		return false;
234
+	}
235
+
236
+	/**
237
+	 * Delete thirdparty
238
+	 *
239
+	 * @param int $id   Thirparty ID
240
+	 * @return integer
241
+	 */
242
+	function delete($id)
243
+	{
244
+	  if(! DolibarrApiAccess::$user->rights->societe->supprimer) {
245
+		throw new RestException(401);
246
+	  }
247
+	  $result = $this->company->fetch($id);
248
+	  if( ! $result ) {
249
+		  throw new RestException(404, 'Thirdparty not found');
250
+	  }
251
+	  if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
252
+		throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
253
+	  }
254
+	  return $this->company->delete($id);
255
+	}
256
+
257
+	/**
258
+	 * Get categories for a thirdparty
259
+	 *
260
+	 * @param int		$id         ID of thirdparty
261
+	 * @param string	$sortfield	Sort field
262
+	 * @param string	$sortorder	Sort order
263
+	 * @param int		$limit		Limit for list
264
+	 * @param int		$page		Page number
265
+	 *
266
+	 * @return mixed
267
+	 *
268
+	 * @url GET {id}/categories
269
+	 */
270 270
 	function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
271 271
 	{
272 272
 		if (! DolibarrApiAccess::$user->rights->categorie->lire) {
@@ -286,47 +286,47 @@  discard block
 block discarded – undo
286 286
 		}
287 287
 
288 288
 		return $result;
289
-    }
290
-
291
-    /**
292
-     * Add category to a thirdparty
293
-     *
294
-     * @param int		$id	Id of thirdparty
295
-     * @param array     $request_data   Request datas
296
-     *
297
-     * @return mixed
298
-     *
299
-     * @url POST {id}/addCategory
300
-     */
301
-    function addCategory($id, $request_data = NULL) {
302
-        if (!isset($request_data["category_id"]))
303
-            throw new RestException(400, "category_id field missing");
304
-        $category_id = $request_data["category_id"];
305
-
306
-      if(! DolibarrApiAccess::$user->rights->societe->creer) {
289
+	}
290
+
291
+	/**
292
+	 * Add category to a thirdparty
293
+	 *
294
+	 * @param int		$id	Id of thirdparty
295
+	 * @param array     $request_data   Request datas
296
+	 *
297
+	 * @return mixed
298
+	 *
299
+	 * @url POST {id}/addCategory
300
+	 */
301
+	function addCategory($id, $request_data = NULL) {
302
+		if (!isset($request_data["category_id"]))
303
+			throw new RestException(400, "category_id field missing");
304
+		$category_id = $request_data["category_id"];
305
+
306
+	  if(! DolibarrApiAccess::$user->rights->societe->creer) {
307 307
 			  throw new RestException(401);
308
-      }
309
-
310
-      $result = $this->company->fetch($id);
311
-      if( ! $result ) {
312
-          throw new RestException(404, 'Thirdparty not found');
313
-      }
314
-      $category = new Categorie($this->db);
315
-      $result = $category->fetch($category_id);
316
-      if( ! $result ) {
317
-          throw new RestException(404, 'category not found');
318
-      }
319
-
320
-      if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
321
-        throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
322
-      }
323
-      if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) {
324
-        throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
325
-      }
326
-
327
-      $category->add_type($this->company,'customer');
328
-      return $this->company;
329
-    }
308
+	  }
309
+
310
+	  $result = $this->company->fetch($id);
311
+	  if( ! $result ) {
312
+		  throw new RestException(404, 'Thirdparty not found');
313
+	  }
314
+	  $category = new Categorie($this->db);
315
+	  $result = $category->fetch($category_id);
316
+	  if( ! $result ) {
317
+		  throw new RestException(404, 'category not found');
318
+	  }
319
+
320
+	  if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
321
+		throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
322
+	  }
323
+	  if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) {
324
+		throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
325
+	  }
326
+
327
+	  $category->add_type($this->company,'customer');
328
+	  return $this->company;
329
+	}
330 330
 
331 331
 	/**
332 332
 	 * Clean sensible object datas
@@ -336,33 +336,33 @@  discard block
 block discarded – undo
336 336
 	 */
337 337
 	function _cleanObjectDatas($object) {
338 338
 
339
-	    $object = parent::_cleanObjectDatas($object);
339
+		$object = parent::_cleanObjectDatas($object);
340 340
 
341
-	    unset($object->total_ht);
342
-	    unset($object->total_tva);
343
-	    unset($object->total_localtax1);
344
-	    unset($object->total_localtax2);
345
-	    unset($object->total_ttc);
341
+		unset($object->total_ht);
342
+		unset($object->total_tva);
343
+		unset($object->total_localtax1);
344
+		unset($object->total_localtax2);
345
+		unset($object->total_ttc);
346 346
 
347
-	    return $object;
347
+		return $object;
348 348
 	}
349 349
 
350 350
 	/**
351
-     * Validate fields before create or update object
352
-     *
353
-     * @param array $data   Datas to validate
354
-     * @return array
355
-     *
356
-     * @throws RestException
357
-     */
358
-    function _validate($data)
359
-    {
360
-        $thirdparty = array();
361
-        foreach (Thirdparties::$FIELDS as $field) {
362
-            if (!isset($data[$field]))
363
-                throw new RestException(400, "$field field missing");
364
-            $thirdparty[$field] = $data[$field];
365
-        }
366
-        return $thirdparty;
367
-    }
351
+	 * Validate fields before create or update object
352
+	 *
353
+	 * @param array $data   Datas to validate
354
+	 * @return array
355
+	 *
356
+	 * @throws RestException
357
+	 */
358
+	function _validate($data)
359
+	{
360
+		$thirdparty = array();
361
+		foreach (Thirdparties::$FIELDS as $field) {
362
+			if (!isset($data[$field]))
363
+				throw new RestException(400, "$field field missing");
364
+			$thirdparty[$field] = $data[$field];
365
+		}
366
+		return $thirdparty;
367
+	}
368 368
 }
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 		$this->db = $db;
51 51
         $this->company = new Societe($this->db);
52 52
 
53
-        if (! empty($conf->global->SOCIETE_EMAIL_MANDATORY)) {
53
+        if (!empty($conf->global->SOCIETE_EMAIL_MANDATORY)) {
54 54
             static::$FIELDS[] = 'email';
55 55
         }
56 56
     }
@@ -67,16 +67,16 @@  discard block
 block discarded – undo
67 67
    */
68 68
     function get($id)
69 69
     {
70
-      if(! DolibarrApiAccess::$user->rights->societe->lire) {
70
+      if (!DolibarrApiAccess::$user->rights->societe->lire) {
71 71
         throw new RestException(401);
72 72
       }
73 73
 
74 74
       $result = $this->company->fetch($id);
75
-      if( ! $result ) {
75
+      if (!$result) {
76 76
           throw new RestException(404, 'Thirdparty not found');
77 77
       }
78 78
 
79
-      if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
79
+      if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
80 80
         throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
81 81
       }
82 82
 
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
      * @param   string  $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
99 99
      * @return  array               Array of thirdparty objects
100 100
      */
101
-    function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $mode=0, $sqlfilters = '') {
101
+    function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $mode = 0, $sqlfilters = '') {
102 102
         global $db, $conf;
103 103
 
104 104
         $obj_ret = array();
@@ -108,23 +108,23 @@  discard block
 block discarded – undo
108 108
 
109 109
         // If the internal user must only see his customers, force searching by him
110 110
         $search_sale = 0;
111
-        if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id;
111
+        if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id;
112 112
 
113 113
         $sql = "SELECT t.rowid";
114 114
         if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
115
-        $sql.= " FROM ".MAIN_DB_PREFIX."societe as t";
116
-
117
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
118
-        $sql.= ", ".MAIN_DB_PREFIX."c_stcomm as st";
119
-        $sql.= " WHERE t.fk_stcomm = st.id";
120
-        if ($mode == 1) $sql.= " AND t.client IN (1, 3)";
121
-        if ($mode == 2) $sql.= " AND t.client IN (2, 3)";
122
-        if ($mode == 3) $sql.= " AND t.client IN (0)";
123
-        $sql.= ' AND t.entity IN ('.getEntity('societe').')';
124
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc";
115
+        $sql .= " FROM ".MAIN_DB_PREFIX."societe as t";
116
+
117
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
118
+        $sql .= ", ".MAIN_DB_PREFIX."c_stcomm as st";
119
+        $sql .= " WHERE t.fk_stcomm = st.id";
120
+        if ($mode == 1) $sql .= " AND t.client IN (1, 3)";
121
+        if ($mode == 2) $sql .= " AND t.client IN (2, 3)";
122
+        if ($mode == 3) $sql .= " AND t.client IN (0)";
123
+        $sql .= ' AND t.entity IN ('.getEntity('societe').')';
124
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc";
125 125
         //if ($email != NULL) $sql.= " AND s.email = \"".$email."\"";
126
-        if ($socid) $sql.= " AND t.rowid IN (".$socids.")";
127
-        if ($search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc";		// Join for the needed table to filter by sale
126
+        if ($socid) $sql .= " AND t.rowid IN (".$socids.")";
127
+        if ($search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
128 128
         // Insert sale filter
129 129
         if ($search_sale > 0)
130 130
         {
@@ -133,15 +133,15 @@  discard block
 block discarded – undo
133 133
         // Add sql filters
134 134
         if ($sqlfilters)
135 135
         {
136
-            if (! DolibarrApi::_checkFilters($sqlfilters))
136
+            if (!DolibarrApi::_checkFilters($sqlfilters))
137 137
             {
138 138
                 throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
139 139
             }
140
-	        $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
141
-            $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
140
+	        $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
141
+            $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
142 142
         }
143 143
 
144
-        $sql.= $db->order($sortfield, $sortorder);
144
+        $sql .= $db->order($sortfield, $sortorder);
145 145
 
146 146
         if ($limit) {
147 147
             if ($page < 0)
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
             }
151 151
             $offset = $limit * $page;
152 152
 
153
-            $sql.= $db->plimit($limit + 1, $offset);
153
+            $sql .= $db->plimit($limit + 1, $offset);
154 154
         }
155 155
 
156 156
 		$result = $db->query($sql);
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
             {
163 163
                 $obj = $db->fetch_object($result);
164 164
                 $soc_static = new Societe($db);
165
-                if($soc_static->fetch($obj->rowid)) {
165
+                if ($soc_static->fetch($obj->rowid)) {
166 166
                     $obj_ret[] = $this->_cleanObjectDatas($soc_static);
167 167
                 }
168 168
                 $i++;
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
         else {
172 172
             throw new RestException(503, 'Error when retrieve thirdparties : '.$db->lasterror());
173 173
         }
174
-        if( ! count($obj_ret)) {
174
+        if (!count($obj_ret)) {
175 175
             throw new RestException(404, 'Thirdparties not found');
176 176
         }
177 177
 		return $obj_ret;
@@ -185,13 +185,13 @@  discard block
 block discarded – undo
185 185
      */
186 186
     function post($request_data = NULL)
187 187
     {
188
-      if(! DolibarrApiAccess::$user->rights->societe->creer) {
188
+      if (!DolibarrApiAccess::$user->rights->societe->creer) {
189 189
         throw new RestException(401);
190 190
       }
191 191
       // Check mandatory fields
192 192
       $result = $this->_validate($request_data);
193 193
 
194
-      foreach($request_data as $field => $value) {
194
+      foreach ($request_data as $field => $value) {
195 195
           $this->company->$field = $value;
196 196
       }
197 197
       if ($this->company->create(DolibarrApiAccess::$user) < 0)
@@ -209,26 +209,26 @@  discard block
 block discarded – undo
209 209
      */
210 210
     function put($id, $request_data = NULL)
211 211
     {
212
-        if(! DolibarrApiAccess::$user->rights->societe->creer) {
212
+        if (!DolibarrApiAccess::$user->rights->societe->creer) {
213 213
 			throw new RestException(401);
214 214
 		}
215 215
 
216 216
         $result = $this->company->fetch($id);
217
-        if( ! $result ) {
217
+        if (!$result) {
218 218
             throw new RestException(404, 'Thirdparty not found');
219 219
         }
220 220
 
221
-		if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
221
+		if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
222 222
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
223 223
 		}
224 224
 
225
-        foreach($request_data as $field => $value) {
225
+        foreach ($request_data as $field => $value) {
226 226
             if ($field == 'id') continue;
227 227
             $this->company->$field = $value;
228 228
         }
229 229
 
230
-        if($this->company->update($id, DolibarrApiAccess::$user,1,'','','update'))
231
-            return $this->get ($id);
230
+        if ($this->company->update($id, DolibarrApiAccess::$user, 1, '', '', 'update'))
231
+            return $this->get($id);
232 232
 
233 233
         return false;
234 234
     }
@@ -241,14 +241,14 @@  discard block
 block discarded – undo
241 241
      */
242 242
     function delete($id)
243 243
     {
244
-      if(! DolibarrApiAccess::$user->rights->societe->supprimer) {
244
+      if (!DolibarrApiAccess::$user->rights->societe->supprimer) {
245 245
         throw new RestException(401);
246 246
       }
247 247
       $result = $this->company->fetch($id);
248
-      if( ! $result ) {
248
+      if (!$result) {
249 249
           throw new RestException(404, 'Thirdparty not found');
250 250
       }
251
-      if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
251
+      if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
252 252
         throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
253 253
       }
254 254
       return $this->company->delete($id);
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
      */
270 270
 	function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
271 271
 	{
272
-		if (! DolibarrApiAccess::$user->rights->categorie->lire) {
272
+		if (!DolibarrApiAccess::$user->rights->categorie->lire) {
273 273
 			throw new RestException(401);
274 274
 		}
275 275
 
@@ -303,28 +303,28 @@  discard block
 block discarded – undo
303 303
             throw new RestException(400, "category_id field missing");
304 304
         $category_id = $request_data["category_id"];
305 305
 
306
-      if(! DolibarrApiAccess::$user->rights->societe->creer) {
306
+      if (!DolibarrApiAccess::$user->rights->societe->creer) {
307 307
 			  throw new RestException(401);
308 308
       }
309 309
 
310 310
       $result = $this->company->fetch($id);
311
-      if( ! $result ) {
311
+      if (!$result) {
312 312
           throw new RestException(404, 'Thirdparty not found');
313 313
       }
314 314
       $category = new Categorie($this->db);
315 315
       $result = $category->fetch($category_id);
316
-      if( ! $result ) {
316
+      if (!$result) {
317 317
           throw new RestException(404, 'category not found');
318 318
       }
319 319
 
320
-      if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
320
+      if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) {
321 321
         throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
322 322
       }
323
-      if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) {
323
+      if (!DolibarrApi::_checkAccessToResource('category', $category->id)) {
324 324
         throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
325 325
       }
326 326
 
327
-      $category->add_type($this->company,'customer');
327
+      $category->add_type($this->company, 'customer');
328 328
       return $this->company;
329 329
     }
330 330
 
Please login to merge, or discard this patch.
htdocs/adherents/class/api_memberstypes.class.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -264,7 +264,7 @@
 block discarded – undo
264 264
     /**
265 265
      * Clean sensible object datas
266 266
      *
267
-     * @param   object  $object    Object to clean
267
+     * @param   AdherentType  $object    Object to clean
268 268
      * @return    array    Array of cleaned object properties
269 269
      */
270 270
     function _cleanObjectDatas($object) {
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -55,17 +55,17 @@  discard block
 block discarded – undo
55 55
      */
56 56
     function get($id)
57 57
     {
58
-        if(! DolibarrApiAccess::$user->rights->adherent->lire) {
58
+        if (!DolibarrApiAccess::$user->rights->adherent->lire) {
59 59
             throw new RestException(401);
60 60
         }
61 61
 
62 62
         $membertype = new AdherentType($this->db);
63 63
         $result = $membertype->fetch($id);
64
-        if( ! $result ) {
64
+        if (!$result) {
65 65
             throw new RestException(404, 'member type not found');
66 66
         }
67 67
 
68
-        if( ! DolibarrApi::_checkAccessToResource('member',$membertype->id,'adherent_type')) {
68
+        if (!DolibarrApi::_checkAccessToResource('member', $membertype->id, 'adherent_type')) {
69 69
             throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
70 70
         }
71 71
 
@@ -91,40 +91,40 @@  discard block
 block discarded – undo
91 91
 
92 92
         $obj_ret = array();
93 93
 
94
-        if(! DolibarrApiAccess::$user->rights->adherent->lire) {
94
+        if (!DolibarrApiAccess::$user->rights->adherent->lire) {
95 95
             throw new RestException(401);
96 96
         }
97 97
 
98 98
         $sql = "SELECT t.rowid";
99
-        $sql.= " FROM ".MAIN_DB_PREFIX."adherent_type as t";
100
-        $sql.= ' WHERE t.entity IN ('.getEntity('adherent').')';
99
+        $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as t";
100
+        $sql .= ' WHERE t.entity IN ('.getEntity('adherent').')';
101 101
 
102 102
         // Add sql filters
103 103
         if ($sqlfilters)
104 104
         {
105
-            if (! DolibarrApi::_checkFilters($sqlfilters))
105
+            if (!DolibarrApi::_checkFilters($sqlfilters))
106 106
             {
107 107
                 throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
108 108
             }
109
-	        $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
110
-            $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
109
+	        $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
110
+            $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
111 111
         }
112 112
 
113
-        $sql.= $db->order($sortfield, $sortorder);
114
-        if ($limit)    {
113
+        $sql .= $db->order($sortfield, $sortorder);
114
+        if ($limit) {
115 115
             if ($page < 0)
116 116
             {
117 117
                 $page = 0;
118 118
             }
119 119
             $offset = $limit * $page;
120 120
 
121
-            $sql.= $db->plimit($limit + 1, $offset);
121
+            $sql .= $db->plimit($limit + 1, $offset);
122 122
         }
123 123
 
124 124
         $result = $db->query($sql);
125 125
         if ($result)
126 126
         {
127
-            $i=0;
127
+            $i = 0;
128 128
             $num = $db->num_rows($result);
129 129
             $min = min($num, ($limit <= 0 ? $num : $limit));
130 130
             while ($i < $min)
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
         else {
141 141
             throw new RestException(503, 'Error when retrieve member type list : '.$db->lasterror());
142 142
         }
143
-        if ( ! count($obj_ret)) {
143
+        if (!count($obj_ret)) {
144 144
             throw new RestException(404, 'No member type found');
145 145
         }
146 146
 
@@ -155,14 +155,14 @@  discard block
 block discarded – undo
155 155
      */
156 156
     function post($request_data = null)
157 157
     {
158
-        if (! DolibarrApiAccess::$user->rights->adherent->configurer) {
158
+        if (!DolibarrApiAccess::$user->rights->adherent->configurer) {
159 159
             throw new RestException(401);
160 160
         }
161 161
         // Check mandatory fields
162 162
         $result = $this->_validate($request_data);
163 163
 
164 164
         $membertype = new AdherentType($this->db);
165
-        foreach($request_data as $field => $value) {
165
+        foreach ($request_data as $field => $value) {
166 166
             $membertype->$field = $value;
167 167
         }
168 168
         if ($membertype->create(DolibarrApiAccess::$user) < 0) {
@@ -180,21 +180,21 @@  discard block
 block discarded – undo
180 180
      */
181 181
     function put($id, $request_data = null)
182 182
     {
183
-        if (! DolibarrApiAccess::$user->rights->adherent->configurer) {
183
+        if (!DolibarrApiAccess::$user->rights->adherent->configurer) {
184 184
             throw new RestException(401);
185 185
         }
186 186
 
187 187
         $membertype = new AdherentType($this->db);
188 188
         $result = $membertype->fetch($id);
189
-        if( ! $result ) {
189
+        if (!$result) {
190 190
             throw new RestException(404, 'member type not found');
191 191
         }
192 192
 
193
-        if( ! DolibarrApi::_checkAccessToResource('member',$membertype->id,'adherent_type')) {
193
+        if (!DolibarrApi::_checkAccessToResource('member', $membertype->id, 'adherent_type')) {
194 194
             throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
195 195
         }
196 196
 
197
-        foreach($request_data as $field => $value) {
197
+        foreach ($request_data as $field => $value) {
198 198
             if ($field == 'id') continue;
199 199
             // Process the status separately because it must be updated using
200 200
             // the validate() and resiliate() methods of the class AdherentType.
@@ -217,21 +217,21 @@  discard block
 block discarded – undo
217 217
      */
218 218
     function delete($id)
219 219
     {
220
-        if (! DolibarrApiAccess::$user->rights->adherent->configurer) {
220
+        if (!DolibarrApiAccess::$user->rights->adherent->configurer) {
221 221
             throw new RestException(401);
222 222
         }
223 223
         $membertype = new AdherentType($this->db);
224 224
         $result = $membertype->fetch($id);
225
-        if( ! $result ) {
225
+        if (!$result) {
226 226
             throw new RestException(404, 'member type not found');
227 227
         }
228 228
 
229
-        if ( ! DolibarrApi::_checkAccessToResource('member',$membertype->id,'adherent_type')) {
229
+        if (!DolibarrApi::_checkAccessToResource('member', $membertype->id, 'adherent_type')) {
230 230
             throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
231 231
         }
232 232
 
233
-        if (! $membertype->delete($membertype->id)) {
234
-            throw new RestException(401,'error when deleting member type');
233
+        if (!$membertype->delete($membertype->id)) {
234
+            throw new RestException(401, 'error when deleting member type');
235 235
         }
236 236
 
237 237
         return array(
Please login to merge, or discard this patch.
Braces   +10 added lines, -7 removed lines patch added patch discarded remove patch
@@ -136,8 +136,7 @@  discard block
 block discarded – undo
136 136
                 }
137 137
                 $i++;
138 138
             }
139
-        }
140
-        else {
139
+        } else {
141 140
             throw new RestException(503, 'Error when retrieve member type list : '.$db->lasterror());
142 141
         }
143 142
         if ( ! count($obj_ret)) {
@@ -195,7 +194,9 @@  discard block
 block discarded – undo
195 194
         }
196 195
 
197 196
         foreach($request_data as $field => $value) {
198
-            if ($field == 'id') continue;
197
+            if ($field == 'id') {
198
+            	continue;
199
+            }
199 200
             // Process the status separately because it must be updated using
200 201
             // the validate() and resiliate() methods of the class AdherentType.
201 202
             $membertype->$field = $value;
@@ -203,8 +204,9 @@  discard block
 block discarded – undo
203 204
 
204 205
         // If there is no error, update() returns the number of affected rows
205 206
         // so if the update is a no op, the return value is zero.
206
-        if ($membertype->update(DolibarrApiAccess::$user) >= 0)
207
-            return $this->get($id);
207
+        if ($membertype->update(DolibarrApiAccess::$user) >= 0) {
208
+                    return $this->get($id);
209
+        }
208 210
 
209 211
         return false;
210 212
     }
@@ -254,8 +256,9 @@  discard block
 block discarded – undo
254 256
     {
255 257
         $membertype = array();
256 258
         foreach (MembersTypes::$FIELDS as $field) {
257
-            if (!isset($data[$field]))
258
-                throw new RestException(400, "$field field missing");
259
+            if (!isset($data[$field])) {
260
+                            throw new RestException(400, "$field field missing");
261
+            }
259 262
             $membertype[$field] = $data[$field];
260 263
         }
261 264
         return $membertype;
Please login to merge, or discard this patch.
Indentation   +289 added lines, -289 removed lines patch added patch discarded remove patch
@@ -27,294 +27,294 @@
 block discarded – undo
27 27
  */
28 28
 class MembersTypes extends DolibarrApi
29 29
 {
30
-    /**
31
-     * @var array   $FIELDS     Mandatory fields, checked when create and update object
32
-     */
33
-    static $FIELDS = array(
34
-        'label'
35
-    );
36
-
37
-    /**
38
-     * Constructor
39
-     */
40
-    function __construct()
41
-    {
42
-        global $db, $conf;
43
-        $this->db = $db;
44
-    }
45
-
46
-    /**
47
-     * Get properties of a member type object
48
-     *
49
-     * Return an array with member type informations
50
-     *
51
-     * @param     int     $id ID of member type
52
-     * @return    array|mixed data without useless information
53
-     *
54
-     * @throws    RestException
55
-     */
56
-    function get($id)
57
-    {
58
-        if(! DolibarrApiAccess::$user->rights->adherent->lire) {
59
-            throw new RestException(401);
60
-        }
61
-
62
-        $membertype = new AdherentType($this->db);
63
-        $result = $membertype->fetch($id);
64
-        if( ! $result ) {
65
-            throw new RestException(404, 'member type not found');
66
-        }
67
-
68
-        if( ! DolibarrApi::_checkAccessToResource('member',$membertype->id,'adherent_type')) {
69
-            throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
70
-        }
71
-
72
-        return $this->_cleanObjectDatas($membertype);
73
-    }
74
-
75
-    /**
76
-     * List members types
77
-     *
78
-     * Get a list of members types
79
-     *
80
-     * @param string    $sortfield  Sort field
81
-     * @param string    $sortorder  Sort order
82
-     * @param int       $limit      Limit for list
83
-     * @param int       $page       Page number
84
-     * @param string    $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.libelle:like:'SO-%') and (t.subscription:=:'1')"
85
-     * @return array                Array of member type objects
86
-     *
87
-     * @throws RestException
88
-     */
89
-    function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $sqlfilters = '') {
90
-        global $db, $conf;
91
-
92
-        $obj_ret = array();
93
-
94
-        if(! DolibarrApiAccess::$user->rights->adherent->lire) {
95
-            throw new RestException(401);
96
-        }
97
-
98
-        $sql = "SELECT t.rowid";
99
-        $sql.= " FROM ".MAIN_DB_PREFIX."adherent_type as t";
100
-        $sql.= ' WHERE t.entity IN ('.getEntity('adherent').')';
101
-
102
-        // Add sql filters
103
-        if ($sqlfilters)
104
-        {
105
-            if (! DolibarrApi::_checkFilters($sqlfilters))
106
-            {
107
-                throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
108
-            }
109
-	        $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
110
-            $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
111
-        }
112
-
113
-        $sql.= $db->order($sortfield, $sortorder);
114
-        if ($limit)    {
115
-            if ($page < 0)
116
-            {
117
-                $page = 0;
118
-            }
119
-            $offset = $limit * $page;
120
-
121
-            $sql.= $db->plimit($limit + 1, $offset);
122
-        }
123
-
124
-        $result = $db->query($sql);
125
-        if ($result)
126
-        {
127
-            $i=0;
128
-            $num = $db->num_rows($result);
129
-            $min = min($num, ($limit <= 0 ? $num : $limit));
130
-            while ($i < $min)
131
-            {
132
-            	$obj = $db->fetch_object($result);
133
-                $membertype = new AdherentType($this->db);
134
-                if ($membertype->fetch($obj->rowid)) {
135
-                    $obj_ret[] = $this->_cleanObjectDatas($membertype);
136
-                }
137
-                $i++;
138
-            }
139
-        }
140
-        else {
141
-            throw new RestException(503, 'Error when retrieve member type list : '.$db->lasterror());
142
-        }
143
-        if ( ! count($obj_ret)) {
144
-            throw new RestException(404, 'No member type found');
145
-        }
146
-
147
-        return $obj_ret;
148
-    }
149
-
150
-    /**
151
-     * Create member type object
152
-     *
153
-     * @param array $request_data   Request data
154
-     * @return int  ID of member type
155
-     */
156
-    function post($request_data = null)
157
-    {
158
-        if (! DolibarrApiAccess::$user->rights->adherent->configurer) {
159
-            throw new RestException(401);
160
-        }
161
-        // Check mandatory fields
162
-        $result = $this->_validate($request_data);
163
-
164
-        $membertype = new AdherentType($this->db);
165
-        foreach($request_data as $field => $value) {
166
-            $membertype->$field = $value;
167
-        }
168
-        if ($membertype->create(DolibarrApiAccess::$user) < 0) {
169
-            throw new RestException(500, 'Error creating member type', array_merge(array($membertype->error), $membertype->errors));
170
-        }
171
-        return $membertype->id;
172
-    }
173
-
174
-    /**
175
-     * Update member type
176
-     *
177
-     * @param int   $id             ID of member type to update
178
-     * @param array $request_data   Datas
179
-     * @return int
180
-     */
181
-    function put($id, $request_data = null)
182
-    {
183
-        if (! DolibarrApiAccess::$user->rights->adherent->configurer) {
184
-            throw new RestException(401);
185
-        }
186
-
187
-        $membertype = new AdherentType($this->db);
188
-        $result = $membertype->fetch($id);
189
-        if( ! $result ) {
190
-            throw new RestException(404, 'member type not found');
191
-        }
192
-
193
-        if( ! DolibarrApi::_checkAccessToResource('member',$membertype->id,'adherent_type')) {
194
-            throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
195
-        }
196
-
197
-        foreach($request_data as $field => $value) {
198
-            if ($field == 'id') continue;
199
-            // Process the status separately because it must be updated using
200
-            // the validate() and resiliate() methods of the class AdherentType.
201
-            $membertype->$field = $value;
202
-        }
203
-
204
-        // If there is no error, update() returns the number of affected rows
205
-        // so if the update is a no op, the return value is zero.
206
-        if ($membertype->update(DolibarrApiAccess::$user) >= 0)
207
-            return $this->get($id);
208
-
209
-        return false;
210
-    }
211
-
212
-    /**
213
-     * Delete member type
214
-     *
215
-     * @param int $id   member type ID
216
-     * @return array
217
-     */
218
-    function delete($id)
219
-    {
220
-        if (! DolibarrApiAccess::$user->rights->adherent->configurer) {
221
-            throw new RestException(401);
222
-        }
223
-        $membertype = new AdherentType($this->db);
224
-        $result = $membertype->fetch($id);
225
-        if( ! $result ) {
226
-            throw new RestException(404, 'member type not found');
227
-        }
228
-
229
-        if ( ! DolibarrApi::_checkAccessToResource('member',$membertype->id,'adherent_type')) {
230
-            throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
231
-        }
232
-
233
-        if (! $membertype->delete($membertype->id)) {
234
-            throw new RestException(401,'error when deleting member type');
235
-        }
236
-
237
-        return array(
238
-            'success' => array(
239
-                'code' => 200,
240
-                'message' => 'member type deleted'
241
-            )
242
-        );
243
-    }
244
-
245
-    /**
246
-     * Validate fields before creating an object
247
-     *
248
-     * @param array|null    $data   Data to validate
249
-     * @return array
250
-     *
251
-     * @throws RestException
252
-     */
253
-    function _validate($data)
254
-    {
255
-        $membertype = array();
256
-        foreach (MembersTypes::$FIELDS as $field) {
257
-            if (!isset($data[$field]))
258
-                throw new RestException(400, "$field field missing");
259
-            $membertype[$field] = $data[$field];
260
-        }
261
-        return $membertype;
262
-    }
263
-
264
-    /**
265
-     * Clean sensible object datas
266
-     *
267
-     * @param   object  $object    Object to clean
268
-     * @return    array    Array of cleaned object properties
269
-     */
270
-    function _cleanObjectDatas($object) {
271
-
272
-        $object = parent::_cleanObjectDatas($object);
273
-
274
-        unset($object->cotisation);
275
-
276
-        unset($object->array_options);
277
-        unset($object->linkedObjectsIds);
278
-        unset($object->context);
279
-        unset($object->canvas);
280
-        unset($object->fk_project);
281
-        unset($object->contact);
282
-        unset($object->contact_id);
283
-        unset($object->thirdparty);
284
-        unset($object->user);
285
-        unset($object->origin);
286
-        unset($object->origin_id);
287
-        unset($object->ref_ext);
288
-        unset($object->country);
289
-        unset($object->country_id);
290
-        unset($object->country_code);
291
-        unset($object->barcode_type);
292
-        unset($object->barcode_type_code);
293
-        unset($object->barcode_type_label);
294
-        unset($object->barcode_type_coder);
295
-        unset($object->mode_reglement_id);
296
-        unset($object->cond_reglement_id);
297
-        unset($object->cond_reglement);
298
-        unset($object->fk_delivery_address);
299
-        unset($object->shipping_method_id);
300
-        unset($object->modelpdf);
301
-        unset($object->fk_account);
302
-        unset($object->note_public);
303
-        unset($object->note_private);
304
-        unset($object->fk_incoterms);
305
-        unset($object->libelle_incoterms);
306
-        unset($object->location_incoterms);
307
-        unset($object->name);
308
-        unset($object->lastname);
309
-        unset($object->firstname);
310
-        unset($object->civility_id);
311
-        unset($object->total_ht);
312
-        unset($object->total_tva);
313
-        unset($object->total_localtax1);
314
-        unset($object->total_localtax2);
315
-        unset($object->total_ttc);
316
-
317
-        return $object;
318
-    }
30
+	/**
31
+	 * @var array   $FIELDS     Mandatory fields, checked when create and update object
32
+	 */
33
+	static $FIELDS = array(
34
+		'label'
35
+	);
36
+
37
+	/**
38
+	 * Constructor
39
+	 */
40
+	function __construct()
41
+	{
42
+		global $db, $conf;
43
+		$this->db = $db;
44
+	}
45
+
46
+	/**
47
+	 * Get properties of a member type object
48
+	 *
49
+	 * Return an array with member type informations
50
+	 *
51
+	 * @param     int     $id ID of member type
52
+	 * @return    array|mixed data without useless information
53
+	 *
54
+	 * @throws    RestException
55
+	 */
56
+	function get($id)
57
+	{
58
+		if(! DolibarrApiAccess::$user->rights->adherent->lire) {
59
+			throw new RestException(401);
60
+		}
61
+
62
+		$membertype = new AdherentType($this->db);
63
+		$result = $membertype->fetch($id);
64
+		if( ! $result ) {
65
+			throw new RestException(404, 'member type not found');
66
+		}
67
+
68
+		if( ! DolibarrApi::_checkAccessToResource('member',$membertype->id,'adherent_type')) {
69
+			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
70
+		}
71
+
72
+		return $this->_cleanObjectDatas($membertype);
73
+	}
74
+
75
+	/**
76
+	 * List members types
77
+	 *
78
+	 * Get a list of members types
79
+	 *
80
+	 * @param string    $sortfield  Sort field
81
+	 * @param string    $sortorder  Sort order
82
+	 * @param int       $limit      Limit for list
83
+	 * @param int       $page       Page number
84
+	 * @param string    $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.libelle:like:'SO-%') and (t.subscription:=:'1')"
85
+	 * @return array                Array of member type objects
86
+	 *
87
+	 * @throws RestException
88
+	 */
89
+	function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $sqlfilters = '') {
90
+		global $db, $conf;
91
+
92
+		$obj_ret = array();
93
+
94
+		if(! DolibarrApiAccess::$user->rights->adherent->lire) {
95
+			throw new RestException(401);
96
+		}
97
+
98
+		$sql = "SELECT t.rowid";
99
+		$sql.= " FROM ".MAIN_DB_PREFIX."adherent_type as t";
100
+		$sql.= ' WHERE t.entity IN ('.getEntity('adherent').')';
101
+
102
+		// Add sql filters
103
+		if ($sqlfilters)
104
+		{
105
+			if (! DolibarrApi::_checkFilters($sqlfilters))
106
+			{
107
+				throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
108
+			}
109
+			$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
110
+			$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
111
+		}
112
+
113
+		$sql.= $db->order($sortfield, $sortorder);
114
+		if ($limit)    {
115
+			if ($page < 0)
116
+			{
117
+				$page = 0;
118
+			}
119
+			$offset = $limit * $page;
120
+
121
+			$sql.= $db->plimit($limit + 1, $offset);
122
+		}
123
+
124
+		$result = $db->query($sql);
125
+		if ($result)
126
+		{
127
+			$i=0;
128
+			$num = $db->num_rows($result);
129
+			$min = min($num, ($limit <= 0 ? $num : $limit));
130
+			while ($i < $min)
131
+			{
132
+				$obj = $db->fetch_object($result);
133
+				$membertype = new AdherentType($this->db);
134
+				if ($membertype->fetch($obj->rowid)) {
135
+					$obj_ret[] = $this->_cleanObjectDatas($membertype);
136
+				}
137
+				$i++;
138
+			}
139
+		}
140
+		else {
141
+			throw new RestException(503, 'Error when retrieve member type list : '.$db->lasterror());
142
+		}
143
+		if ( ! count($obj_ret)) {
144
+			throw new RestException(404, 'No member type found');
145
+		}
146
+
147
+		return $obj_ret;
148
+	}
149
+
150
+	/**
151
+	 * Create member type object
152
+	 *
153
+	 * @param array $request_data   Request data
154
+	 * @return int  ID of member type
155
+	 */
156
+	function post($request_data = null)
157
+	{
158
+		if (! DolibarrApiAccess::$user->rights->adherent->configurer) {
159
+			throw new RestException(401);
160
+		}
161
+		// Check mandatory fields
162
+		$result = $this->_validate($request_data);
163
+
164
+		$membertype = new AdherentType($this->db);
165
+		foreach($request_data as $field => $value) {
166
+			$membertype->$field = $value;
167
+		}
168
+		if ($membertype->create(DolibarrApiAccess::$user) < 0) {
169
+			throw new RestException(500, 'Error creating member type', array_merge(array($membertype->error), $membertype->errors));
170
+		}
171
+		return $membertype->id;
172
+	}
173
+
174
+	/**
175
+	 * Update member type
176
+	 *
177
+	 * @param int   $id             ID of member type to update
178
+	 * @param array $request_data   Datas
179
+	 * @return int
180
+	 */
181
+	function put($id, $request_data = null)
182
+	{
183
+		if (! DolibarrApiAccess::$user->rights->adherent->configurer) {
184
+			throw new RestException(401);
185
+		}
186
+
187
+		$membertype = new AdherentType($this->db);
188
+		$result = $membertype->fetch($id);
189
+		if( ! $result ) {
190
+			throw new RestException(404, 'member type not found');
191
+		}
192
+
193
+		if( ! DolibarrApi::_checkAccessToResource('member',$membertype->id,'adherent_type')) {
194
+			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
195
+		}
196
+
197
+		foreach($request_data as $field => $value) {
198
+			if ($field == 'id') continue;
199
+			// Process the status separately because it must be updated using
200
+			// the validate() and resiliate() methods of the class AdherentType.
201
+			$membertype->$field = $value;
202
+		}
203
+
204
+		// If there is no error, update() returns the number of affected rows
205
+		// so if the update is a no op, the return value is zero.
206
+		if ($membertype->update(DolibarrApiAccess::$user) >= 0)
207
+			return $this->get($id);
208
+
209
+		return false;
210
+	}
211
+
212
+	/**
213
+	 * Delete member type
214
+	 *
215
+	 * @param int $id   member type ID
216
+	 * @return array
217
+	 */
218
+	function delete($id)
219
+	{
220
+		if (! DolibarrApiAccess::$user->rights->adherent->configurer) {
221
+			throw new RestException(401);
222
+		}
223
+		$membertype = new AdherentType($this->db);
224
+		$result = $membertype->fetch($id);
225
+		if( ! $result ) {
226
+			throw new RestException(404, 'member type not found');
227
+		}
228
+
229
+		if ( ! DolibarrApi::_checkAccessToResource('member',$membertype->id,'adherent_type')) {
230
+			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
231
+		}
232
+
233
+		if (! $membertype->delete($membertype->id)) {
234
+			throw new RestException(401,'error when deleting member type');
235
+		}
236
+
237
+		return array(
238
+			'success' => array(
239
+				'code' => 200,
240
+				'message' => 'member type deleted'
241
+			)
242
+		);
243
+	}
244
+
245
+	/**
246
+	 * Validate fields before creating an object
247
+	 *
248
+	 * @param array|null    $data   Data to validate
249
+	 * @return array
250
+	 *
251
+	 * @throws RestException
252
+	 */
253
+	function _validate($data)
254
+	{
255
+		$membertype = array();
256
+		foreach (MembersTypes::$FIELDS as $field) {
257
+			if (!isset($data[$field]))
258
+				throw new RestException(400, "$field field missing");
259
+			$membertype[$field] = $data[$field];
260
+		}
261
+		return $membertype;
262
+	}
263
+
264
+	/**
265
+	 * Clean sensible object datas
266
+	 *
267
+	 * @param   object  $object    Object to clean
268
+	 * @return    array    Array of cleaned object properties
269
+	 */
270
+	function _cleanObjectDatas($object) {
271
+
272
+		$object = parent::_cleanObjectDatas($object);
273
+
274
+		unset($object->cotisation);
275
+
276
+		unset($object->array_options);
277
+		unset($object->linkedObjectsIds);
278
+		unset($object->context);
279
+		unset($object->canvas);
280
+		unset($object->fk_project);
281
+		unset($object->contact);
282
+		unset($object->contact_id);
283
+		unset($object->thirdparty);
284
+		unset($object->user);
285
+		unset($object->origin);
286
+		unset($object->origin_id);
287
+		unset($object->ref_ext);
288
+		unset($object->country);
289
+		unset($object->country_id);
290
+		unset($object->country_code);
291
+		unset($object->barcode_type);
292
+		unset($object->barcode_type_code);
293
+		unset($object->barcode_type_label);
294
+		unset($object->barcode_type_coder);
295
+		unset($object->mode_reglement_id);
296
+		unset($object->cond_reglement_id);
297
+		unset($object->cond_reglement);
298
+		unset($object->fk_delivery_address);
299
+		unset($object->shipping_method_id);
300
+		unset($object->modelpdf);
301
+		unset($object->fk_account);
302
+		unset($object->note_public);
303
+		unset($object->note_private);
304
+		unset($object->fk_incoterms);
305
+		unset($object->libelle_incoterms);
306
+		unset($object->location_incoterms);
307
+		unset($object->name);
308
+		unset($object->lastname);
309
+		unset($object->firstname);
310
+		unset($object->civility_id);
311
+		unset($object->total_ht);
312
+		unset($object->total_tva);
313
+		unset($object->total_localtax1);
314
+		unset($object->total_localtax2);
315
+		unset($object->total_ttc);
316
+
317
+		return $object;
318
+	}
319 319
 
320 320
 }
Please login to merge, or discard this patch.
htdocs/comm/action/class/api_agendaevents.class.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@
 block discarded – undo
93 93
      * @param string	$sortorder	Sort order
94 94
      * @param int		$limit		Limit for list
95 95
      * @param int		$page		Page number
96
-     * @param string   	$user_ids   User ids filter field (owners of event). Example: '1' or '1,2,3'          {@pattern /^[0-9,]*$/i}
96
+     * @param integer   	$user_ids   User ids filter field (owners of event). Example: '1' or '1,2,3'          {@pattern /^[0-9,]*$/i}
97 97
      * @param string    $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.label:like:'%dol%') and (t.datec:<:'20160101')"
98 98
      * @return  array               Array of Agenda Events objects
99 99
      */
Please login to merge, or discard this patch.
Indentation   +251 added lines, -251 removed lines patch added patch discarded remove patch
@@ -29,196 +29,196 @@  discard block
 block discarded – undo
29 29
 class AgendaEvents extends DolibarrApi
30 30
 {
31 31
 
32
-    /**
33
-     * @var array   $FIELDS     Mandatory fields, checked when create and update object
34
-     */
35
-    static $FIELDS = array(
36
-    );
37
-
38
-    /**
39
-     * @var Event $actioncomm {@type ActionComm}
40
-     */
41
-    public $actioncomm;
42
-
43
-
44
-    /**
45
-     * Constructor
46
-     */
47
-    function __construct()
48
-    {
32
+	/**
33
+	 * @var array   $FIELDS     Mandatory fields, checked when create and update object
34
+	 */
35
+	static $FIELDS = array(
36
+	);
37
+
38
+	/**
39
+	 * @var Event $actioncomm {@type ActionComm}
40
+	 */
41
+	public $actioncomm;
42
+
43
+
44
+	/**
45
+	 * Constructor
46
+	 */
47
+	function __construct()
48
+	{
49 49
 		global $db, $conf;
50 50
 		$this->db = $db;
51
-        $this->actioncomm = new ActionComm($this->db);
52
-    }
51
+		$this->actioncomm = new ActionComm($this->db);
52
+	}
53 53
 
54
-    /**
55
-     * Get properties of a Agenda Events object
56
-     *
57
-     * Return an array with Agenda Events informations
58
-     *
59
-     * @param       int         $id         ID of Agenda Events
60
-     * @return 	    array|mixed             Data without useless information
54
+	/**
55
+	 * Get properties of a Agenda Events object
61 56
 	 *
62
-     * @throws 	RestException
63
-     */
64
-    function get($id)
65
-    {
66
-        if (! DolibarrApiAccess::$user->rights->agenda->myactions->read) {
67
-            throw new RestException(401, "Insuffisant rights to read an event");
68
-        }
57
+	 * Return an array with Agenda Events informations
58
+	 *
59
+	 * @param       int         $id         ID of Agenda Events
60
+	 * @return 	    array|mixed             Data without useless information
61
+	 *
62
+	 * @throws 	RestException
63
+	 */
64
+	function get($id)
65
+	{
66
+		if (! DolibarrApiAccess::$user->rights->agenda->myactions->read) {
67
+			throw new RestException(401, "Insuffisant rights to read an event");
68
+		}
69 69
 
70
-        $result = $this->actioncomm->fetch($id);
71
-        if ( ! $result ) {
72
-            throw new RestException(404, 'Agenda Events not found');
73
-        }
70
+		$result = $this->actioncomm->fetch($id);
71
+		if ( ! $result ) {
72
+			throw new RestException(404, 'Agenda Events not found');
73
+		}
74 74
 
75
-        if (! DolibarrApiAccess::$user->rights->agenda->allactions->read && $this->actioncomm->ownerid != DolibarrApiAccess::$user->id) {
76
-            throw new RestException(401, "Insuffisant rights to read event for owner id ".$request_data['userownerid'].' Your id is '.DolibarrApiAccess::$user->id);
77
-        }
75
+		if (! DolibarrApiAccess::$user->rights->agenda->allactions->read && $this->actioncomm->ownerid != DolibarrApiAccess::$user->id) {
76
+			throw new RestException(401, "Insuffisant rights to read event for owner id ".$request_data['userownerid'].' Your id is '.DolibarrApiAccess::$user->id);
77
+		}
78 78
 
79 79
 		if ( ! DolibarrApi::_checkAccessToResource('agenda',$this->actioncomm->id)) {
80 80
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
81 81
 		}
82 82
 
83
-        $this->actioncomm->fetchObjectLinked();
83
+		$this->actioncomm->fetchObjectLinked();
84 84
 		return $this->_cleanObjectDatas($this->actioncomm);
85
-    }
85
+	}
86 86
 
87
-    /**
88
-     * List Agenda Events
89
-     *
90
-     * Get a list of Agenda Events
91
-     *
92
-     * @param string	$sortfield	Sort field
93
-     * @param string	$sortorder	Sort order
94
-     * @param int		$limit		Limit for list
95
-     * @param int		$page		Page number
96
-     * @param string   	$user_ids   User ids filter field (owners of event). Example: '1' or '1,2,3'          {@pattern /^[0-9,]*$/i}
97
-     * @param string    $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.label:like:'%dol%') and (t.datec:<:'20160101')"
98
-     * @return  array               Array of Agenda Events objects
99
-     */
100
-    function index($sortfield = "t.id", $sortorder = 'ASC', $limit = 100, $page = 0, $user_ids = 0, $sqlfilters = '') {
101
-        global $db, $conf;
102
-
103
-        $obj_ret = array();
104
-
105
-        if (! DolibarrApiAccess::$user->rights->agenda->myactions->read) {
106
-        	throw new RestException(401, "Insuffisant rights to read events");
107
-        }
87
+	/**
88
+	 * List Agenda Events
89
+	 *
90
+	 * Get a list of Agenda Events
91
+	 *
92
+	 * @param string	$sortfield	Sort field
93
+	 * @param string	$sortorder	Sort order
94
+	 * @param int		$limit		Limit for list
95
+	 * @param int		$page		Page number
96
+	 * @param string   	$user_ids   User ids filter field (owners of event). Example: '1' or '1,2,3'          {@pattern /^[0-9,]*$/i}
97
+	 * @param string    $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.label:like:'%dol%') and (t.datec:<:'20160101')"
98
+	 * @return  array               Array of Agenda Events objects
99
+	 */
100
+	function index($sortfield = "t.id", $sortorder = 'ASC', $limit = 100, $page = 0, $user_ids = 0, $sqlfilters = '') {
101
+		global $db, $conf;
108 102
 
109
-        // case of external user
110
-        $socid = 0;
111
-        if (! empty(DolibarrApiAccess::$user->socid)) $socid = DolibarrApiAccess::$user->socid;
112
-
113
-        // If the internal user must only see his customers, force searching by him
114
-        $search_sale = 0;
115
-        if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
116
-
117
-        $sql = "SELECT t.id as rowid";
118
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
119
-        $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as t";
120
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
121
-        $sql.= ' WHERE t.entity IN ('.getEntity('agenda').')';
122
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= " AND t.fk_soc = sc.fk_soc";
123
-        if ($user_ids) $sql.=" AND t.fk_user_action IN (".$user_ids.")";
124
-        if ($socid > 0) $sql.= " AND t.fk_soc = ".$socid;
125
-        // Insert sale filter
126
-        if ($search_sale > 0)
127
-        {
128
-            $sql .= " AND sc.fk_user = ".$search_sale;
129
-        }
130
-        // Add sql filters
131
-        if ($sqlfilters)
132
-        {
133
-            if (! DolibarrApi::_checkFilters($sqlfilters))
134
-            {
135
-                throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
136
-            }
137
-	        $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
138
-            $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
139
-        }
103
+		$obj_ret = array();
140 104
 
141
-        $sql.= $db->order($sortfield, $sortorder);
142
-        if ($limit)	{
143
-            if ($page < 0)
144
-            {
145
-                $page = 0;
146
-            }
147
-            $offset = $limit * $page;
105
+		if (! DolibarrApiAccess::$user->rights->agenda->myactions->read) {
106
+			throw new RestException(401, "Insuffisant rights to read events");
107
+		}
148 108
 
149
-            $sql.= $db->plimit($limit + 1, $offset);
150
-        }
109
+		// case of external user
110
+		$socid = 0;
111
+		if (! empty(DolibarrApiAccess::$user->socid)) $socid = DolibarrApiAccess::$user->socid;
112
+
113
+		// If the internal user must only see his customers, force searching by him
114
+		$search_sale = 0;
115
+		if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
116
+
117
+		$sql = "SELECT t.id as rowid";
118
+		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
119
+		$sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as t";
120
+		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
121
+		$sql.= ' WHERE t.entity IN ('.getEntity('agenda').')';
122
+		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= " AND t.fk_soc = sc.fk_soc";
123
+		if ($user_ids) $sql.=" AND t.fk_user_action IN (".$user_ids.")";
124
+		if ($socid > 0) $sql.= " AND t.fk_soc = ".$socid;
125
+		// Insert sale filter
126
+		if ($search_sale > 0)
127
+		{
128
+			$sql .= " AND sc.fk_user = ".$search_sale;
129
+		}
130
+		// Add sql filters
131
+		if ($sqlfilters)
132
+		{
133
+			if (! DolibarrApi::_checkFilters($sqlfilters))
134
+			{
135
+				throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
136
+			}
137
+			$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
138
+			$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
139
+		}
151 140
 
152
-        $result = $db->query($sql);
153
-
154
-        if ($result)
155
-        {
156
-            $num = $db->num_rows($result);
157
-            $min = min($num, ($limit <= 0 ? $num : $limit));
158
-            while ($i < $min)
159
-            {
160
-                $obj = $db->fetch_object($result);
161
-                $actioncomm_static = new ActionComm($db);
162
-                if ($actioncomm_static->fetch($obj->rowid)) {
163
-                    $obj_ret[] = $this->_cleanObjectDatas($actioncomm_static);
164
-                }
165
-                $i++;
166
-            }
167
-        }
168
-        else {
169
-            throw new RestException(503, 'Error when retrieve Agenda Event list : '.$db->lasterror());
170
-        }
171
-        if ( ! count($obj_ret)) {
172
-            throw new RestException(404, 'No Agenda Event found');
173
-        }
141
+		$sql.= $db->order($sortfield, $sortorder);
142
+		if ($limit)	{
143
+			if ($page < 0)
144
+			{
145
+				$page = 0;
146
+			}
147
+			$offset = $limit * $page;
148
+
149
+			$sql.= $db->plimit($limit + 1, $offset);
150
+		}
151
+
152
+		$result = $db->query($sql);
153
+
154
+		if ($result)
155
+		{
156
+			$num = $db->num_rows($result);
157
+			$min = min($num, ($limit <= 0 ? $num : $limit));
158
+			while ($i < $min)
159
+			{
160
+				$obj = $db->fetch_object($result);
161
+				$actioncomm_static = new ActionComm($db);
162
+				if ($actioncomm_static->fetch($obj->rowid)) {
163
+					$obj_ret[] = $this->_cleanObjectDatas($actioncomm_static);
164
+				}
165
+				$i++;
166
+			}
167
+		}
168
+		else {
169
+			throw new RestException(503, 'Error when retrieve Agenda Event list : '.$db->lasterror());
170
+		}
171
+		if ( ! count($obj_ret)) {
172
+			throw new RestException(404, 'No Agenda Event found');
173
+		}
174 174
 		return $obj_ret;
175
-    }
175
+	}
176 176
 
177
-    /**
178
-     * Create Agenda Event object
179
-     *
180
-     * @param   array   $request_data   Request data
181
-     * @return  int                     ID of Agenda Event
182
-     */
183
-    function post($request_data = NULL)
184
-    {
185
-      if (! DolibarrApiAccess::$user->rights->agenda->myactions->create) {
177
+	/**
178
+	 * Create Agenda Event object
179
+	 *
180
+	 * @param   array   $request_data   Request data
181
+	 * @return  int                     ID of Agenda Event
182
+	 */
183
+	function post($request_data = NULL)
184
+	{
185
+	  if (! DolibarrApiAccess::$user->rights->agenda->myactions->create) {
186 186
 			  throw new RestException(401, "Insuffisant rights to create your Agenda Event");
187 187
 		  }
188
-      if (! DolibarrApiAccess::$user->rights->agenda->allactions->create && DolibarrApiAccess::$user->id != $request_data['userownerid']) {
189
-		      throw new RestException(401, "Insuffisant rights to create an Agenda Event for owner id ".$request_data['userownerid'].' Your id is '.DolibarrApiAccess::$user->id);
188
+	  if (! DolibarrApiAccess::$user->rights->agenda->allactions->create && DolibarrApiAccess::$user->id != $request_data['userownerid']) {
189
+			  throw new RestException(401, "Insuffisant rights to create an Agenda Event for owner id ".$request_data['userownerid'].' Your id is '.DolibarrApiAccess::$user->id);
190 190
 		  }
191 191
 
192
-        // Check mandatory fields
193
-        $result = $this->_validate($request_data);
192
+		// Check mandatory fields
193
+		$result = $this->_validate($request_data);
194 194
 
195
-        foreach($request_data as $field => $value) {
196
-            $this->actioncomm->$field = $value;
197
-        }
198
-        /*if (isset($request_data["lines"])) {
195
+		foreach($request_data as $field => $value) {
196
+			$this->actioncomm->$field = $value;
197
+		}
198
+		/*if (isset($request_data["lines"])) {
199 199
           $lines = array();
200 200
           foreach ($request_data["lines"] as $line) {
201 201
             array_push($lines, (object) $line);
202 202
           }
203 203
           $this->expensereport->lines = $lines;
204 204
         }*/
205
-        if ($this->actioncomm->create(DolibarrApiAccess::$user) < 0) {
206
-            throw new RestException(500, "Error creating event", array_merge(array($this->actioncomm->error), $this->actioncomm->errors));
207
-        }
205
+		if ($this->actioncomm->create(DolibarrApiAccess::$user) < 0) {
206
+			throw new RestException(500, "Error creating event", array_merge(array($this->actioncomm->error), $this->actioncomm->errors));
207
+		}
208 208
 
209
-        return $this->actioncomm->id;
210
-    }
209
+		return $this->actioncomm->id;
210
+	}
211 211
 
212 212
 
213
-    /**
214
-     * Update Agenda Event general fields (won't touch lines of expensereport)
215
-     *
216
-     * @param int   $id             Id of Agenda Event to update
217
-     * @param array $request_data   Datas
218
-     *
219
-     * @return int
220
-     */
221
-    /*
213
+	/**
214
+	 * Update Agenda Event general fields (won't touch lines of expensereport)
215
+	 *
216
+	 * @param int   $id             Id of Agenda Event to update
217
+	 * @param array $request_data   Datas
218
+	 *
219
+	 * @return int
220
+	 */
221
+	/*
222 222
     function put($id, $request_data = NULL) {
223 223
       if (! DolibarrApiAccess::$user->rights->agenda->myactions->create) {
224 224
 			  throw new RestException(401, "Insuffisant rights to create your Agenda Event");
@@ -247,116 +247,116 @@  discard block
 block discarded – undo
247 247
     }
248 248
     */
249 249
 
250
-    /**
251
-     * Delete Agenda Event
252
-     *
253
-     * @param   int     $id         Agenda Event ID
254
-     *
255
-     * @return  array
256
-     */
257
-    function delete($id)
258
-    {
259
-        if(! DolibarrApiAccess::$user->rights->agenda->myactions->delete) {
250
+	/**
251
+	 * Delete Agenda Event
252
+	 *
253
+	 * @param   int     $id         Agenda Event ID
254
+	 *
255
+	 * @return  array
256
+	 */
257
+	function delete($id)
258
+	{
259
+		if(! DolibarrApiAccess::$user->rights->agenda->myactions->delete) {
260 260
 			  throw new RestException(401, "Insuffisant rights to delete your Agenda Event");
261 261
 		}
262 262
 
263 263
 		$result = $this->actioncomm->fetch($id);
264 264
 
265
-        if(! DolibarrApiAccess::$user->rights->agenda->allactions->delete && DolibarrApiAccess::$user->id != $this->actioncomm->userownerid) {
266
-		      throw new RestException(401, "Insuffisant rights to delete an Agenda Event of owner id ".$request_data['userownerid'].' Your id is '.DolibarrApiAccess::$user->id);
265
+		if(! DolibarrApiAccess::$user->rights->agenda->allactions->delete && DolibarrApiAccess::$user->id != $this->actioncomm->userownerid) {
266
+			  throw new RestException(401, "Insuffisant rights to delete an Agenda Event of owner id ".$request_data['userownerid'].' Your id is '.DolibarrApiAccess::$user->id);
267 267
 		}
268 268
 
269 269
 		if( ! $result ) {
270
-            throw new RestException(404, 'Agenda Event not found');
271
-        }
270
+			throw new RestException(404, 'Agenda Event not found');
271
+		}
272 272
 
273 273
 		if( ! DolibarrApi::_checkAccessToResource('actioncomm',$this->actioncomm->id)) {
274 274
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
275 275
 		}
276 276
 
277
-        if( ! $this->actioncomm->delete(DolibarrApiAccess::$user)) {
278
-            throw new RestException(500, 'Error when delete Agenda Event : '.$this->actioncomm->error);
279
-        }
277
+		if( ! $this->actioncomm->delete(DolibarrApiAccess::$user)) {
278
+			throw new RestException(500, 'Error when delete Agenda Event : '.$this->actioncomm->error);
279
+		}
280 280
 
281
-        return array(
282
-            'success' => array(
283
-                'code' => 200,
284
-                'message' => 'Agenda Event deleted'
285
-            )
286
-        );
281
+		return array(
282
+			'success' => array(
283
+				'code' => 200,
284
+				'message' => 'Agenda Event deleted'
285
+			)
286
+		);
287 287
 
288
-    }
288
+	}
289 289
 
290
-    /**
291
-     * Validate fields before create or update object
292
-     *
293
-     * @param   array           $data   Array with data to verify
294
-     * @return  array
295
-     * @throws  RestException
296
-     */
297
-    function _validate($data)
298
-    {
299
-        $event = array();
300
-        foreach (AgendaEvents::$FIELDS as $field) {
301
-            if (!isset($data[$field]))
302
-                throw new RestException(400, "$field field missing");
303
-            $event[$field] = $data[$field];
290
+	/**
291
+	 * Validate fields before create or update object
292
+	 *
293
+	 * @param   array           $data   Array with data to verify
294
+	 * @return  array
295
+	 * @throws  RestException
296
+	 */
297
+	function _validate($data)
298
+	{
299
+		$event = array();
300
+		foreach (AgendaEvents::$FIELDS as $field) {
301
+			if (!isset($data[$field]))
302
+				throw new RestException(400, "$field field missing");
303
+			$event[$field] = $data[$field];
304 304
 
305
-        }
306
-        return $event;
307
-    }
305
+		}
306
+		return $event;
307
+	}
308 308
 
309
-    /**
310
-     * Clean sensible object datas
311
-     *
312
-     * @param	object	$object		Object to clean
313
-     * @return	array				Array of cleaned object properties
314
-     */
315
-    function _cleanObjectDatas($object) {
316
-
317
-    	$object = parent::_cleanObjectDatas($object);
318
-
319
-    	unset($object->usermod);
320
-    	unset($object->libelle);
321
-    	unset($object->array_options);
322
-    	unset($object->context);
323
-    	unset($object->canvas);
324
-    	unset($object->contact);
325
-    	unset($object->contact_id);
326
-    	unset($object->thirdparty);
327
-    	unset($object->user);
328
-    	unset($object->origin);
329
-    	unset($object->origin_id);
330
-    	unset($object->ref_ext);
331
-    	unset($object->statut);
332
-    	unset($object->country);
333
-    	unset($object->country_id);
334
-    	unset($object->country_code);
335
-    	unset($object->barcode_type);
336
-    	unset($object->barcode_type_code);
337
-    	unset($object->barcode_type_label);
338
-    	unset($object->barcode_type_coder);
339
-    	unset($object->mode_reglement_id);
340
-    	unset($object->cond_reglement_id);
341
-    	unset($object->cond_reglement);
342
-    	unset($object->fk_delivery_address);
343
-    	unset($object->shipping_method_id);
344
-    	unset($object->fk_account);
345
-    	unset($object->total_ht);
346
-    	unset($object->total_tva);
347
-    	unset($object->total_localtax1);
348
-    	unset($object->total_localtax2);
349
-    	unset($object->total_ttc);
350
-    	unset($object->fk_incoterms);
351
-    	unset($object->libelle_incoterms);
352
-    	unset($object->location_incoterms);
353
-    	unset($object->name);
354
-    	unset($object->lastname);
355
-    	unset($object->firstname);
356
-    	unset($object->civility_id);
357
-    	unset($object->contact);
358
-    	unset($object->societe);
359
-
360
-    	return $object;
361
-    }
309
+	/**
310
+	 * Clean sensible object datas
311
+	 *
312
+	 * @param	object	$object		Object to clean
313
+	 * @return	array				Array of cleaned object properties
314
+	 */
315
+	function _cleanObjectDatas($object) {
316
+
317
+		$object = parent::_cleanObjectDatas($object);
318
+
319
+		unset($object->usermod);
320
+		unset($object->libelle);
321
+		unset($object->array_options);
322
+		unset($object->context);
323
+		unset($object->canvas);
324
+		unset($object->contact);
325
+		unset($object->contact_id);
326
+		unset($object->thirdparty);
327
+		unset($object->user);
328
+		unset($object->origin);
329
+		unset($object->origin_id);
330
+		unset($object->ref_ext);
331
+		unset($object->statut);
332
+		unset($object->country);
333
+		unset($object->country_id);
334
+		unset($object->country_code);
335
+		unset($object->barcode_type);
336
+		unset($object->barcode_type_code);
337
+		unset($object->barcode_type_label);
338
+		unset($object->barcode_type_coder);
339
+		unset($object->mode_reglement_id);
340
+		unset($object->cond_reglement_id);
341
+		unset($object->cond_reglement);
342
+		unset($object->fk_delivery_address);
343
+		unset($object->shipping_method_id);
344
+		unset($object->fk_account);
345
+		unset($object->total_ht);
346
+		unset($object->total_tva);
347
+		unset($object->total_localtax1);
348
+		unset($object->total_localtax2);
349
+		unset($object->total_ttc);
350
+		unset($object->fk_incoterms);
351
+		unset($object->libelle_incoterms);
352
+		unset($object->location_incoterms);
353
+		unset($object->name);
354
+		unset($object->lastname);
355
+		unset($object->firstname);
356
+		unset($object->civility_id);
357
+		unset($object->contact);
358
+		unset($object->societe);
359
+
360
+		return $object;
361
+	}
362 362
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -63,20 +63,20 @@  discard block
 block discarded – undo
63 63
      */
64 64
     function get($id)
65 65
     {
66
-        if (! DolibarrApiAccess::$user->rights->agenda->myactions->read) {
66
+        if (!DolibarrApiAccess::$user->rights->agenda->myactions->read) {
67 67
             throw new RestException(401, "Insuffisant rights to read an event");
68 68
         }
69 69
 
70 70
         $result = $this->actioncomm->fetch($id);
71
-        if ( ! $result ) {
71
+        if (!$result) {
72 72
             throw new RestException(404, 'Agenda Events not found');
73 73
         }
74 74
 
75
-        if (! DolibarrApiAccess::$user->rights->agenda->allactions->read && $this->actioncomm->ownerid != DolibarrApiAccess::$user->id) {
75
+        if (!DolibarrApiAccess::$user->rights->agenda->allactions->read && $this->actioncomm->ownerid != DolibarrApiAccess::$user->id) {
76 76
             throw new RestException(401, "Insuffisant rights to read event for owner id ".$request_data['userownerid'].' Your id is '.DolibarrApiAccess::$user->id);
77 77
         }
78 78
 
79
-		if ( ! DolibarrApi::_checkAccessToResource('agenda',$this->actioncomm->id)) {
79
+		if (!DolibarrApi::_checkAccessToResource('agenda', $this->actioncomm->id)) {
80 80
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
81 81
 		}
82 82
 
@@ -102,26 +102,26 @@  discard block
 block discarded – undo
102 102
 
103 103
         $obj_ret = array();
104 104
 
105
-        if (! DolibarrApiAccess::$user->rights->agenda->myactions->read) {
105
+        if (!DolibarrApiAccess::$user->rights->agenda->myactions->read) {
106 106
         	throw new RestException(401, "Insuffisant rights to read events");
107 107
         }
108 108
 
109 109
         // case of external user
110 110
         $socid = 0;
111
-        if (! empty(DolibarrApiAccess::$user->socid)) $socid = DolibarrApiAccess::$user->socid;
111
+        if (!empty(DolibarrApiAccess::$user->socid)) $socid = DolibarrApiAccess::$user->socid;
112 112
 
113 113
         // If the internal user must only see his customers, force searching by him
114 114
         $search_sale = 0;
115
-        if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
115
+        if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
116 116
 
117 117
         $sql = "SELECT t.id as rowid";
118 118
         if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
119
-        $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as t";
120
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
121
-        $sql.= ' WHERE t.entity IN ('.getEntity('agenda').')';
122
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= " AND t.fk_soc = sc.fk_soc";
123
-        if ($user_ids) $sql.=" AND t.fk_user_action IN (".$user_ids.")";
124
-        if ($socid > 0) $sql.= " AND t.fk_soc = ".$socid;
119
+        $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as t";
120
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
121
+        $sql .= ' WHERE t.entity IN ('.getEntity('agenda').')';
122
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= " AND t.fk_soc = sc.fk_soc";
123
+        if ($user_ids) $sql .= " AND t.fk_user_action IN (".$user_ids.")";
124
+        if ($socid > 0) $sql .= " AND t.fk_soc = ".$socid;
125 125
         // Insert sale filter
126 126
         if ($search_sale > 0)
127 127
         {
@@ -130,23 +130,23 @@  discard block
 block discarded – undo
130 130
         // Add sql filters
131 131
         if ($sqlfilters)
132 132
         {
133
-            if (! DolibarrApi::_checkFilters($sqlfilters))
133
+            if (!DolibarrApi::_checkFilters($sqlfilters))
134 134
             {
135 135
                 throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
136 136
             }
137
-	        $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
138
-            $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
137
+	        $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
138
+            $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
139 139
         }
140 140
 
141
-        $sql.= $db->order($sortfield, $sortorder);
142
-        if ($limit)	{
141
+        $sql .= $db->order($sortfield, $sortorder);
142
+        if ($limit) {
143 143
             if ($page < 0)
144 144
             {
145 145
                 $page = 0;
146 146
             }
147 147
             $offset = $limit * $page;
148 148
 
149
-            $sql.= $db->plimit($limit + 1, $offset);
149
+            $sql .= $db->plimit($limit + 1, $offset);
150 150
         }
151 151
 
152 152
         $result = $db->query($sql);
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
         else {
169 169
             throw new RestException(503, 'Error when retrieve Agenda Event list : '.$db->lasterror());
170 170
         }
171
-        if ( ! count($obj_ret)) {
171
+        if (!count($obj_ret)) {
172 172
             throw new RestException(404, 'No Agenda Event found');
173 173
         }
174 174
 		return $obj_ret;
@@ -182,17 +182,17 @@  discard block
 block discarded – undo
182 182
      */
183 183
     function post($request_data = NULL)
184 184
     {
185
-      if (! DolibarrApiAccess::$user->rights->agenda->myactions->create) {
185
+      if (!DolibarrApiAccess::$user->rights->agenda->myactions->create) {
186 186
 			  throw new RestException(401, "Insuffisant rights to create your Agenda Event");
187 187
 		  }
188
-      if (! DolibarrApiAccess::$user->rights->agenda->allactions->create && DolibarrApiAccess::$user->id != $request_data['userownerid']) {
188
+      if (!DolibarrApiAccess::$user->rights->agenda->allactions->create && DolibarrApiAccess::$user->id != $request_data['userownerid']) {
189 189
 		      throw new RestException(401, "Insuffisant rights to create an Agenda Event for owner id ".$request_data['userownerid'].' Your id is '.DolibarrApiAccess::$user->id);
190 190
 		  }
191 191
 
192 192
         // Check mandatory fields
193 193
         $result = $this->_validate($request_data);
194 194
 
195
-        foreach($request_data as $field => $value) {
195
+        foreach ($request_data as $field => $value) {
196 196
             $this->actioncomm->$field = $value;
197 197
         }
198 198
         /*if (isset($request_data["lines"])) {
@@ -256,25 +256,25 @@  discard block
 block discarded – undo
256 256
      */
257 257
     function delete($id)
258 258
     {
259
-        if(! DolibarrApiAccess::$user->rights->agenda->myactions->delete) {
259
+        if (!DolibarrApiAccess::$user->rights->agenda->myactions->delete) {
260 260
 			  throw new RestException(401, "Insuffisant rights to delete your Agenda Event");
261 261
 		}
262 262
 
263 263
 		$result = $this->actioncomm->fetch($id);
264 264
 
265
-        if(! DolibarrApiAccess::$user->rights->agenda->allactions->delete && DolibarrApiAccess::$user->id != $this->actioncomm->userownerid) {
265
+        if (!DolibarrApiAccess::$user->rights->agenda->allactions->delete && DolibarrApiAccess::$user->id != $this->actioncomm->userownerid) {
266 266
 		      throw new RestException(401, "Insuffisant rights to delete an Agenda Event of owner id ".$request_data['userownerid'].' Your id is '.DolibarrApiAccess::$user->id);
267 267
 		}
268 268
 
269
-		if( ! $result ) {
269
+		if (!$result) {
270 270
             throw new RestException(404, 'Agenda Event not found');
271 271
         }
272 272
 
273
-		if( ! DolibarrApi::_checkAccessToResource('actioncomm',$this->actioncomm->id)) {
273
+		if (!DolibarrApi::_checkAccessToResource('actioncomm', $this->actioncomm->id)) {
274 274
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
275 275
 		}
276 276
 
277
-        if( ! $this->actioncomm->delete(DolibarrApiAccess::$user)) {
277
+        if (!$this->actioncomm->delete(DolibarrApiAccess::$user)) {
278 278
             throw new RestException(500, 'Error when delete Agenda Event : '.$this->actioncomm->error);
279 279
         }
280 280
 
Please login to merge, or discard this patch.
Braces   +27 added lines, -11 removed lines patch added patch discarded remove patch
@@ -108,20 +108,36 @@  discard block
 block discarded – undo
108 108
 
109 109
         // case of external user
110 110
         $socid = 0;
111
-        if (! empty(DolibarrApiAccess::$user->socid)) $socid = DolibarrApiAccess::$user->socid;
111
+        if (! empty(DolibarrApiAccess::$user->socid)) {
112
+        	$socid = DolibarrApiAccess::$user->socid;
113
+        }
112 114
 
113 115
         // If the internal user must only see his customers, force searching by him
114 116
         $search_sale = 0;
115
-        if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
117
+        if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) {
118
+        	$search_sale = DolibarrApiAccess::$user->id;
119
+        }
116 120
 
117 121
         $sql = "SELECT t.id as rowid";
118
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
122
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
123
+        	$sql .= ", sc.fk_soc, sc.fk_user";
124
+        }
125
+        // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
119 126
         $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as t";
120
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
127
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
128
+        	$sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
129
+        }
130
+        // We need this table joined to the select in order to filter by sale
121 131
         $sql.= ' WHERE t.entity IN ('.getEntity('agenda').')';
122
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= " AND t.fk_soc = sc.fk_soc";
123
-        if ($user_ids) $sql.=" AND t.fk_user_action IN (".$user_ids.")";
124
-        if ($socid > 0) $sql.= " AND t.fk_soc = ".$socid;
132
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
133
+        	$sql.= " AND t.fk_soc = sc.fk_soc";
134
+        }
135
+        if ($user_ids) {
136
+        	$sql.=" AND t.fk_user_action IN (".$user_ids.")";
137
+        }
138
+        if ($socid > 0) {
139
+        	$sql.= " AND t.fk_soc = ".$socid;
140
+        }
125 141
         // Insert sale filter
126 142
         if ($search_sale > 0)
127 143
         {
@@ -164,8 +180,7 @@  discard block
 block discarded – undo
164 180
                 }
165 181
                 $i++;
166 182
             }
167
-        }
168
-        else {
183
+        } else {
169 184
             throw new RestException(503, 'Error when retrieve Agenda Event list : '.$db->lasterror());
170 185
         }
171 186
         if ( ! count($obj_ret)) {
@@ -298,8 +313,9 @@  discard block
 block discarded – undo
298 313
     {
299 314
         $event = array();
300 315
         foreach (AgendaEvents::$FIELDS as $field) {
301
-            if (!isset($data[$field]))
302
-                throw new RestException(400, "$field field missing");
316
+            if (!isset($data[$field])) {
317
+                            throw new RestException(400, "$field field missing");
318
+            }
303 319
             $event[$field] = $data[$field];
304 320
 
305 321
         }
Please login to merge, or discard this patch.
htdocs/core/lib/expensereport.lib.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -82,7 +82,7 @@
 block discarded – undo
82 82
  * Returns an array with the tabs for the "Expense report payment" section
83 83
  * It loads tabs from modules looking for the entity payment
84 84
  * 
85
- * @param	Paiement	$object		Current payment object
85
+ * @param	PaymentExpenseReport	$object		Current payment object
86 86
  * @return	array					Tabs for the payment section
87 87
  */
88 88
 function payment_expensereport_prepare_head(PaymentExpenseReport $object) {
Please login to merge, or discard this patch.
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -41,15 +41,15 @@  discard block
 block discarded – undo
41 41
 
42 42
 	// Show more tabs from modules
43 43
 	// Entries must be declared in modules descriptor with line
44
-    // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
45
-    // $this->tabs = array('entity:-tabname);   												to remove a tab
44
+	// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
45
+	// $this->tabs = array('entity:-tabname);   												to remove a tab
46 46
 	complete_head_from_modules($conf,$langs,$object,$head,$h,'expensereport');
47 47
 
48 48
 	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
49
-    require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
49
+	require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
50 50
 	$upload_dir = $conf->expensereport->dir_output . "/" . dol_sanitizeFileName($object->ref);
51 51
 	$nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$'));
52
-    $nbLinks=Link::count($db, $object->element, $object->id);
52
+	$nbLinks=Link::count($db, $object->element, $object->id);
53 53
 	$head[$h][0] = DOL_URL_ROOT.'/expensereport/document.php?id='.$object->id;
54 54
 	$head[$h][1] = $langs->trans('Documents');
55 55
 	if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
@@ -58,14 +58,14 @@  discard block
 block discarded – undo
58 58
 
59 59
 	if (empty($conf->global->MAIN_DISABLE_NOTES_TAB))
60 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.'/expensereport/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++;
61
+		$nbNote = 0;
62
+		if(!empty($object->note_private)) $nbNote++;
63
+		if(!empty($object->note_public)) $nbNote++;
64
+		$head[$h][0] = DOL_URL_ROOT.'/expensereport/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 69
 	}
70 70
 	
71 71
 	$head[$h][0] = DOL_URL_ROOT . '/expensereport/info.php?id=' . $object->id;
@@ -97,11 +97,11 @@  discard block
 block discarded – undo
97 97
 	$head[$h][2] = 'payment';
98 98
 	$h++;
99 99
 
100
-    // Show more tabs from modules
101
-    // Entries must be declared in modules descriptor with line
102
-    // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
103
-    // $this->tabs = array('entity:-tabname);   												to remove a tab
104
-    complete_head_from_modules($conf,$langs,$object,$head,$h,'payment_expensereport');
100
+	// Show more tabs from modules
101
+	// Entries must be declared in modules descriptor with line
102
+	// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
103
+	// $this->tabs = array('entity:-tabname);   												to remove a tab
104
+	complete_head_from_modules($conf,$langs,$object,$head,$h,'payment_expensereport');
105 105
 
106 106
 	$head[$h][0] = DOL_URL_ROOT.'/expensereport/payment/info.php?id='.$object->id;
107 107
 	$head[$h][1] = $langs->trans("Info");
@@ -140,10 +140,10 @@  discard block
 block discarded – undo
140 140
 
141 141
 	$head[$h][0] = DOL_URL_ROOT.'/admin/expensereport_extrafields.php';
142 142
 	$head[$h][1] = $langs->trans("ExtraFields");
143
-    $head[$h][2] = 'attributes';
144
-    $h++;
143
+	$head[$h][2] = 'attributes';
144
+	$h++;
145 145
 
146
-    /*
146
+	/*
147 147
 	$head[$h][0] = DOL_URL_ROOT.'/fichinter/admin/fichinterdet_extrafields.php';
148 148
 	$head[$h][1] = $langs->trans("ExtraFieldsLines");
149 149
     $head[$h][2] = 'attributesdet';
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 	$h = 0;
35 35
 	$head = array();
36 36
 
37
-	$head[$h][0] = DOL_URL_ROOT . '/expensereport/card.php?id=' . $object->id;
37
+	$head[$h][0] = DOL_URL_ROOT.'/expensereport/card.php?id='.$object->id;
38 38
 	$head[$h][1] = $langs->trans("Card");
39 39
 	$head[$h][2] = 'card';
40 40
 	$h++;
@@ -43,37 +43,37 @@  discard block
 block discarded – undo
43 43
 	// Entries must be declared in modules descriptor with line
44 44
     // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
45 45
     // $this->tabs = array('entity:-tabname);   												to remove a tab
46
-	complete_head_from_modules($conf,$langs,$object,$head,$h,'expensereport');
46
+	complete_head_from_modules($conf, $langs, $object, $head, $h, 'expensereport');
47 47
 
48 48
 	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
49 49
     require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
50
-	$upload_dir = $conf->expensereport->dir_output . "/" . dol_sanitizeFileName($object->ref);
51
-	$nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$'));
52
-    $nbLinks=Link::count($db, $object->element, $object->id);
50
+	$upload_dir = $conf->expensereport->dir_output."/".dol_sanitizeFileName($object->ref);
51
+	$nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
52
+    $nbLinks = Link::count($db, $object->element, $object->id);
53 53
 	$head[$h][0] = DOL_URL_ROOT.'/expensereport/document.php?id='.$object->id;
54 54
 	$head[$h][1] = $langs->trans('Documents');
55
-	if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
55
+	if (($nbFiles + $nbLinks) > 0) $head[$h][1] .= ' <span class="badge">'.($nbFiles + $nbLinks).'</span>';
56 56
 	$head[$h][2] = 'documents';
57 57
 	$h++;
58 58
 
59 59
 	if (empty($conf->global->MAIN_DISABLE_NOTES_TAB))
60 60
 	{
61 61
 	    $nbNote = 0;
62
-	    if(!empty($object->note_private)) $nbNote++;
63
-	    if(!empty($object->note_public)) $nbNote++;
62
+	    if (!empty($object->note_private)) $nbNote++;
63
+	    if (!empty($object->note_public)) $nbNote++;
64 64
 	    $head[$h][0] = DOL_URL_ROOT.'/expensereport/note.php?id='.$object->id;
65 65
 	    $head[$h][1] = $langs->trans('Notes');
66
-	    if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
66
+	    if ($nbNote > 0) $head[$h][1] .= ' <span class="badge">'.$nbNote.'</span>';
67 67
 	    $head[$h][2] = 'note';
68 68
 	    $h++;
69 69
 	}
70 70
 	
71
-	$head[$h][0] = DOL_URL_ROOT . '/expensereport/info.php?id=' . $object->id;
71
+	$head[$h][0] = DOL_URL_ROOT.'/expensereport/info.php?id='.$object->id;
72 72
 	$head[$h][1] = $langs->trans("Info");
73 73
 	$head[$h][2] = 'info';
74 74
 	$h++;
75 75
 
76
-	complete_head_from_modules($conf,$langs,$object,$head,$h,'expensereport','remove');
76
+	complete_head_from_modules($conf, $langs, $object, $head, $h, 'expensereport', 'remove');
77 77
 
78 78
 	return $head;
79 79
 }
@@ -101,14 +101,14 @@  discard block
 block discarded – undo
101 101
     // Entries must be declared in modules descriptor with line
102 102
     // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
103 103
     // $this->tabs = array('entity:-tabname);   												to remove a tab
104
-    complete_head_from_modules($conf,$langs,$object,$head,$h,'payment_expensereport');
104
+    complete_head_from_modules($conf, $langs, $object, $head, $h, 'payment_expensereport');
105 105
 
106 106
 	$head[$h][0] = DOL_URL_ROOT.'/expensereport/payment/info.php?id='.$object->id;
107 107
 	$head[$h][1] = $langs->trans("Info");
108 108
 	$head[$h][2] = 'info';
109 109
 	$h++;
110 110
 
111
-	complete_head_from_modules($conf,$langs,$object,$head,$h,'payment_expensereport', 'remove');
111
+	complete_head_from_modules($conf, $langs, $object, $head, $h, 'payment_expensereport', 'remove');
112 112
 
113 113
 	return $head;
114 114
 }
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 	// Entries must be declared in modules descriptor with line
137 137
 	// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
138 138
 	// $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to remove a tab
139
-	complete_head_from_modules($conf,$langs,null,$head,$h,'expensereport_admin');
139
+	complete_head_from_modules($conf, $langs, null, $head, $h, 'expensereport_admin');
140 140
 
141 141
 	$head[$h][0] = DOL_URL_ROOT.'/admin/expensereport_extrafields.php';
142 142
 	$head[$h][1] = $langs->trans("ExtraFields");
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
     $h++;
151 151
 	*/
152 152
 
153
-	complete_head_from_modules($conf,$langs,null,$head,$h,'expensereport_admin','remove');
153
+	complete_head_from_modules($conf, $langs, null, $head, $h, 'expensereport_admin', 'remove');
154 154
 
155 155
 	return $head;
156 156
 }
Please login to merge, or discard this patch.
Braces   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -52,18 +52,26 @@
 block discarded – undo
52 52
     $nbLinks=Link::count($db, $object->element, $object->id);
53 53
 	$head[$h][0] = DOL_URL_ROOT.'/expensereport/document.php?id='.$object->id;
54 54
 	$head[$h][1] = $langs->trans('Documents');
55
-	if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
55
+	if (($nbFiles+$nbLinks) > 0) {
56
+		$head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
57
+	}
56 58
 	$head[$h][2] = 'documents';
57 59
 	$h++;
58 60
 
59 61
 	if (empty($conf->global->MAIN_DISABLE_NOTES_TAB))
60 62
 	{
61 63
 	    $nbNote = 0;
62
-	    if(!empty($object->note_private)) $nbNote++;
63
-	    if(!empty($object->note_public)) $nbNote++;
64
+	    if(!empty($object->note_private)) {
65
+	    	$nbNote++;
66
+	    }
67
+	    if(!empty($object->note_public)) {
68
+	    	$nbNote++;
69
+	    }
64 70
 	    $head[$h][0] = DOL_URL_ROOT.'/expensereport/note.php?id='.$object->id;
65 71
 	    $head[$h][1] = $langs->trans('Notes');
66
-	    if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
72
+	    if ($nbNote > 0) {
73
+	    	$head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
74
+	    }
67 75
 	    $head[$h][2] = 'note';
68 76
 	    $h++;
69 77
 	}
Please login to merge, or discard this patch.
htdocs/loan/class/loanschedule.class.php 5 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -226,7 +226,7 @@
 block discarded – undo
226 226
 	/**
227 227
 	 *  Update database
228 228
 	 *
229
-	 *  @param	User	$user        	User that modify
229
+	 *  @param	integer	$user        	User that modify
230 230
 	 *  @param  int		$notrigger	    0=launch triggers after, 1=disable triggers
231 231
 	 *  @return int         			<0 if KO, >0 if OK
232 232
 	 */
Please login to merge, or discard this patch.
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -36,8 +36,8 @@  discard block
 block discarded – undo
36 36
 	var $datec='';
37 37
 	var $tms='';
38 38
 	var $datep='';
39
-    var $amounts=array();   // Array of amounts
40
-    var $amount_capital;    // Total amount of payment
39
+	var $amounts=array();   // Array of amounts
40
+	var $amount_capital;    // Total amount of payment
41 41
 	var $amount_insurance;
42 42
 	var $amount_interest;
43 43
 	var $fk_typepayment;
@@ -65,8 +65,8 @@  discard block
 block discarded – undo
65 65
 
66 66
 	/**
67 67
 	 *  Create payment of loan into database.
68
-     *  Use this->amounts to have list of lines for the payment
69
-     *
68
+	 *  Use this->amounts to have list of lines for the payment
69
+	 *
70 70
 	 *  @param      User		$user   User making payment
71 71
 	 *  @return     int     			<0 if KO, id of payment if OK
72 72
 	 */
@@ -76,9 +76,9 @@  discard block
 block discarded – undo
76 76
 
77 77
 		$error=0;
78 78
 
79
-        $now=dol_now();
79
+		$now=dol_now();
80 80
 
81
-        // Validate parameters
81
+		// Validate parameters
82 82
 		if (! $this->datepaid)
83 83
 		{
84 84
 			$this->error='ErrorBadValueForParameter';
@@ -95,14 +95,14 @@  discard block
 block discarded – undo
95 95
 		if (isset($this->fk_user_creat))	$this->fk_user_creat = trim($this->fk_user_creat);
96 96
 		if (isset($this->fk_user_modif))	$this->fk_user_modif = trim($this->fk_user_modif);
97 97
 
98
-        $totalamount = $this->amount_capital + $this->amount_insurance + $this->amount_interest;
99
-        $totalamount = price2num($totalamount);
98
+		$totalamount = $this->amount_capital + $this->amount_insurance + $this->amount_interest;
99
+		$totalamount = price2num($totalamount);
100 100
 
101
-        // Check parameters
102
-        if ($totalamount == 0) {
103
-        	$this->errors[]='step1';
104
-        	return -1; // Negative amounts are accepted for reject prelevement but not null
105
-        }
101
+		// Check parameters
102
+		if ($totalamount == 0) {
103
+			$this->errors[]='step1';
104
+			return -1; // Negative amounts are accepted for reject prelevement but not null
105
+		}
106 106
 
107 107
 
108 108
 		$this->db->begin();
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 			}
129 129
 			else
130 130
 			{
131
-                $this->error=$this->db->lasterror();
131
+				$this->error=$this->db->lasterror();
132 132
 				$error++;
133 133
 			}
134 134
 
@@ -136,9 +136,9 @@  discard block
 block discarded – undo
136 136
 
137 137
 		if ($totalamount != 0 && ! $error)
138 138
 		{
139
-		    $this->amount_capital=$totalamount;
140
-            $this->total=$totalamount;    // deprecated
141
-		    $this->db->commit();
139
+			$this->amount_capital=$totalamount;
140
+			$this->total=$totalamount;    // deprecated
141
+			$this->db->commit();
142 142
 			return $this->id;
143 143
 		}
144 144
 		else
@@ -169,8 +169,8 @@  discard block
 block discarded – undo
169 169
 		$sql.= " t.amount_interest,";
170 170
 		$sql.= " t.fk_typepayment,";
171 171
 		$sql.= " t.num_payment,";
172
-        $sql.= " t.note_private,";
173
-        $sql.= " t.note_public,";
172
+		$sql.= " t.note_private,";
173
+		$sql.= " t.note_public,";
174 174
 		$sql.= " t.fk_bank,";
175 175
 		$sql.= " t.fk_user_creat,";
176 176
 		$sql.= " t.fk_user_modif,";
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 
323 323
 		$this->db->begin();
324 324
 
325
-	    if (! $error)
325
+		if (! $error)
326 326
 		{
327 327
 			$sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
328 328
 			$sql.= " WHERE rowid=".$this->id;
Please login to merge, or discard this patch.
Braces   +65 added lines, -33 removed lines patch added patch discarded remove patch
@@ -86,14 +86,30 @@  discard block
 block discarded – undo
86 86
 		}
87 87
 
88 88
 		// Clean parameters
89
-		if (isset($this->fk_loan)) 			$this->fk_loan = trim($this->fk_loan);
90
-		if (isset($this->amount_capital))	$this->amount_capital = trim($this->amount_capital?$this->amount_capital:0);
91
-		if (isset($this->amount_insurance))	$this->amount_insurance = trim($this->amount_insurance?$this->amount_insurance:0);
92
-		if (isset($this->amount_interest))	$this->amount_interest = trim($this->amount_interest?$this->amount_interest:0);
93
-		if (isset($this->fk_typepayment))	$this->fk_typepayment = trim($this->fk_typepayment);
94
-		if (isset($this->fk_bank))			$this->fk_bank = trim($this->fk_bank);
95
-		if (isset($this->fk_user_creat))	$this->fk_user_creat = trim($this->fk_user_creat);
96
-		if (isset($this->fk_user_modif))	$this->fk_user_modif = trim($this->fk_user_modif);
89
+		if (isset($this->fk_loan)) {
90
+			$this->fk_loan = trim($this->fk_loan);
91
+		}
92
+		if (isset($this->amount_capital)) {
93
+			$this->amount_capital = trim($this->amount_capital?$this->amount_capital:0);
94
+		}
95
+		if (isset($this->amount_insurance)) {
96
+			$this->amount_insurance = trim($this->amount_insurance?$this->amount_insurance:0);
97
+		}
98
+		if (isset($this->amount_interest)) {
99
+			$this->amount_interest = trim($this->amount_interest?$this->amount_interest:0);
100
+		}
101
+		if (isset($this->fk_typepayment)) {
102
+			$this->fk_typepayment = trim($this->fk_typepayment);
103
+		}
104
+		if (isset($this->fk_bank)) {
105
+			$this->fk_bank = trim($this->fk_bank);
106
+		}
107
+		if (isset($this->fk_user_creat)) {
108
+			$this->fk_user_creat = trim($this->fk_user_creat);
109
+		}
110
+		if (isset($this->fk_user_modif)) {
111
+			$this->fk_user_modif = trim($this->fk_user_modif);
112
+		}
97 113
 
98 114
         $totalamount = $this->amount_capital + $this->amount_insurance + $this->amount_interest;
99 115
         $totalamount = price2num($totalamount);
@@ -125,8 +141,7 @@  discard block
 block discarded – undo
125 141
 			if ($resql)
126 142
 			{
127 143
 				$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_loan");
128
-			}
129
-			else
144
+			} else
130 145
 			{
131 146
                 $this->error=$this->db->lasterror();
132 147
 				$error++;
@@ -140,8 +155,7 @@  discard block
 block discarded – undo
140 155
             $this->total=$totalamount;    // deprecated
141 156
 		    $this->db->commit();
142 157
 			return $this->id;
143
-		}
144
-		else
158
+		} else
145 159
 		{
146 160
 			$this->errors[]=$this->db->lasterror();
147 161
 			$this->db->rollback();
@@ -215,8 +229,7 @@  discard block
 block discarded – undo
215 229
 		$this->db->free($resql);
216 230
 
217 231
 			return 1;
218
-		}
219
-		else
232
+		} else
220 233
 		{
221 234
 			$this->error="Error ".$this->db->lasterror();
222 235
 			return -1;
@@ -237,17 +250,39 @@  discard block
 block discarded – undo
237 250
 		$error=0;
238 251
 
239 252
 		// Clean parameters
240
-		if (isset($this->fk_loan)) $this->fk_loan=trim($this->fk_loan);
241
-		if (isset($this->amount_capital)) $this->amount_capital=trim($this->amount_capital);
242
-		if (isset($this->amount_insurance)) $this->amount_insurance=trim($this->amount_insurance);
243
-		if (isset($this->amount_interest)) $this->amount_interest=trim($this->amount_interest);
244
-		if (isset($this->fk_typepayment)) $this->fk_typepayment=trim($this->fk_typepayment);
245
-		if (isset($this->num_payment)) $this->num_payment=trim($this->num_payment);
246
-		if (isset($this->note_private)) $this->note_private=trim($this->note_private);
247
-		if (isset($this->note_public)) $this->note_public=trim($this->note_public);
248
-		if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank);
249
-		if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat);
250
-		if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif);
253
+		if (isset($this->fk_loan)) {
254
+			$this->fk_loan=trim($this->fk_loan);
255
+		}
256
+		if (isset($this->amount_capital)) {
257
+			$this->amount_capital=trim($this->amount_capital);
258
+		}
259
+		if (isset($this->amount_insurance)) {
260
+			$this->amount_insurance=trim($this->amount_insurance);
261
+		}
262
+		if (isset($this->amount_interest)) {
263
+			$this->amount_interest=trim($this->amount_interest);
264
+		}
265
+		if (isset($this->fk_typepayment)) {
266
+			$this->fk_typepayment=trim($this->fk_typepayment);
267
+		}
268
+		if (isset($this->num_payment)) {
269
+			$this->num_payment=trim($this->num_payment);
270
+		}
271
+		if (isset($this->note_private)) {
272
+			$this->note_private=trim($this->note_private);
273
+		}
274
+		if (isset($this->note_public)) {
275
+			$this->note_public=trim($this->note_public);
276
+		}
277
+		if (isset($this->fk_bank)) {
278
+			$this->fk_bank=trim($this->fk_bank);
279
+		}
280
+		if (isset($this->fk_user_creat)) {
281
+			$this->fk_user_creat=trim($this->fk_user_creat);
282
+		}
283
+		if (isset($this->fk_user_modif)) {
284
+			$this->fk_user_modif=trim($this->fk_user_modif);
285
+		}
251 286
 
252 287
 		// Check parameters
253 288
 		// Put here code to add control on parameters values
@@ -299,8 +334,7 @@  discard block
 block discarded – undo
299 334
 		{
300 335
 			$this->db->rollback();
301 336
 			return -1*$error;
302
-		}
303
-		else
337
+		} else
304 338
 		{
305 339
 			$this->db->commit();
306 340
 			return 1;
@@ -358,8 +392,7 @@  discard block
 block discarded – undo
358 392
 			}
359 393
 			$this->db->rollback();
360 394
 			return -1*$error;
361
-		}
362
-		else
395
+		} else
363 396
 		{
364 397
 			$this->db->commit();
365 398
 			return 1;
@@ -438,8 +471,7 @@  discard block
 block discarded – undo
438 471
 			}
439 472
 			$this->db->free($resql);
440 473
 			return 1;
441
-		}
442
-		else
474
+		} else
443 475
 		{
444 476
 			$this->error="Error ".$this->db->lasterror();
445 477
 			return -1;
@@ -477,7 +509,7 @@  discard block
 block discarded – undo
477 509
 						$res=$this->db->query($sql);
478 510
 						if($res){
479 511
 							$this->db->commit();
480
-						}else {
512
+						} else {
481 513
 							$this->db->rollback();
482 514
 						}
483 515
 					}
@@ -506,7 +538,7 @@  discard block
 block discarded – undo
506 538
 		if($resql){
507 539
 			$obj = $this->db->fetch_object($resql);
508 540
 			return $this->db->jdate($obj->datep);
509
-		}else{
541
+		} else{
510 542
 			return -1;
511 543
 		}
512 544
 	}
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -415,7 +415,7 @@
 block discarded – undo
415 415
 		{
416 416
 			while($obj = $this->db->fetch_object($resql))
417 417
 			{
418
-				$line = New LoanSchedule($this->db);
418
+				$line = new LoanSchedule($this->db);
419 419
 				$line->id = $obj->rowid;
420 420
 				$line->ref = $obj->rowid;
421 421
 
Please login to merge, or discard this patch.
Spacing   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -29,15 +29,15 @@  discard block
 block discarded – undo
29 29
  */
30 30
 class LoanSchedule extends CommonObject
31 31
 {
32
-	public $element='loan_schedule';			//!< Id that identify managed objects
33
-	public $table_element='loan_schedule';	//!< Name of table without prefix where object is stored
32
+	public $element = 'loan_schedule'; //!< Id that identify managed objects
33
+	public $table_element = 'loan_schedule'; //!< Name of table without prefix where object is stored
34 34
 
35 35
 	var $fk_loan;
36
-	var $datec='';
37
-	var $tms='';
38
-	var $datep='';
39
-    var $amounts=array();   // Array of amounts
40
-    var $amount_capital;    // Total amount of payment
36
+	var $datec = '';
37
+	var $tms = '';
38
+	var $datep = '';
39
+    var $amounts = array(); // Array of amounts
40
+    var $amount_capital; // Total amount of payment
41 41
 	var $amount_insurance;
42 42
 	var $amount_interest;
43 43
 	var $fk_typepayment;
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 	var $fk_bank;
46 46
 	var $fk_user_creat;
47 47
 	var $fk_user_modif;
48
-	var $lines=array();
48
+	var $lines = array();
49 49
 
50 50
 	/**
51 51
 	 * @deprecated
@@ -74,22 +74,22 @@  discard block
 block discarded – undo
74 74
 	{
75 75
 		global $conf, $langs;
76 76
 
77
-		$error=0;
77
+		$error = 0;
78 78
 
79
-        $now=dol_now();
79
+        $now = dol_now();
80 80
 
81 81
         // Validate parameters
82
-		if (! $this->datepaid)
82
+		if (!$this->datepaid)
83 83
 		{
84
-			$this->error='ErrorBadValueForParameter';
84
+			$this->error = 'ErrorBadValueForParameter';
85 85
 			return -1;
86 86
 		}
87 87
 
88 88
 		// Clean parameters
89 89
 		if (isset($this->fk_loan)) 			$this->fk_loan = trim($this->fk_loan);
90
-		if (isset($this->amount_capital))	$this->amount_capital = trim($this->amount_capital?$this->amount_capital:0);
91
-		if (isset($this->amount_insurance))	$this->amount_insurance = trim($this->amount_insurance?$this->amount_insurance:0);
92
-		if (isset($this->amount_interest))	$this->amount_interest = trim($this->amount_interest?$this->amount_interest:0);
90
+		if (isset($this->amount_capital))	$this->amount_capital = trim($this->amount_capital ? $this->amount_capital : 0);
91
+		if (isset($this->amount_insurance))	$this->amount_insurance = trim($this->amount_insurance ? $this->amount_insurance : 0);
92
+		if (isset($this->amount_interest))	$this->amount_interest = trim($this->amount_interest ? $this->amount_interest : 0);
93 93
 		if (isset($this->fk_typepayment))	$this->fk_typepayment = trim($this->fk_typepayment);
94 94
 		if (isset($this->fk_bank))			$this->fk_bank = trim($this->fk_bank);
95 95
 		if (isset($this->fk_user_creat))	$this->fk_user_creat = trim($this->fk_user_creat);
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 
101 101
         // Check parameters
102 102
         if ($totalamount == 0) {
103
-        	$this->errors[]='step1';
103
+        	$this->errors[] = 'step1';
104 104
         	return -1; // Negative amounts are accepted for reject prelevement but not null
105 105
         }
106 106
 
@@ -110,40 +110,40 @@  discard block
 block discarded – undo
110 110
 		if ($totalamount != 0)
111 111
 		{
112 112
 			$sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." (fk_loan, datec, datep, amount_capital, amount_insurance, amount_interest,";
113
-			$sql.= " fk_typepayment, fk_user_creat, fk_bank)";
114
-			$sql.= " VALUES (".$this->fk_loan.", '".$this->db->idate($now)."',";
115
-			$sql.= " '".$this->db->idate($this->datepaid)."',";
116
-			$sql.= " ".$this->amount_capital.",";
117
-			$sql.= " ".$this->amount_insurance.",";
118
-			$sql.= " ".$this->amount_interest.",";
119
-			$sql.= " ".$this->fk_typepayment.", ";
120
-			$sql.= " ".$user->id.",";
121
-			$sql.= " ".$this->fk_bank . ")";
113
+			$sql .= " fk_typepayment, fk_user_creat, fk_bank)";
114
+			$sql .= " VALUES (".$this->fk_loan.", '".$this->db->idate($now)."',";
115
+			$sql .= " '".$this->db->idate($this->datepaid)."',";
116
+			$sql .= " ".$this->amount_capital.",";
117
+			$sql .= " ".$this->amount_insurance.",";
118
+			$sql .= " ".$this->amount_interest.",";
119
+			$sql .= " ".$this->fk_typepayment.", ";
120
+			$sql .= " ".$user->id.",";
121
+			$sql .= " ".$this->fk_bank.")";
122 122
 
123 123
 			dol_syslog(get_class($this)."::create", LOG_DEBUG);
124
-			$resql=$this->db->query($sql);
124
+			$resql = $this->db->query($sql);
125 125
 			if ($resql)
126 126
 			{
127 127
 				$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_loan");
128 128
 			}
129 129
 			else
130 130
 			{
131
-                $this->error=$this->db->lasterror();
131
+                $this->error = $this->db->lasterror();
132 132
 				$error++;
133 133
 			}
134 134
 
135 135
 		}
136 136
 
137
-		if ($totalamount != 0 && ! $error)
137
+		if ($totalamount != 0 && !$error)
138 138
 		{
139
-		    $this->amount_capital=$totalamount;
140
-            $this->total=$totalamount;    // deprecated
139
+		    $this->amount_capital = $totalamount;
140
+            $this->total = $totalamount; // deprecated
141 141
 		    $this->db->commit();
142 142
 			return $this->id;
143 143
 		}
144 144
 		else
145 145
 		{
146
-			$this->errors[]=$this->db->lasterror();
146
+			$this->errors[] = $this->db->lasterror();
147 147
 			$this->db->rollback();
148 148
 			return -1;
149 149
 		}
@@ -159,30 +159,30 @@  discard block
 block discarded – undo
159 159
 	{
160 160
 		global $langs;
161 161
 		$sql = "SELECT";
162
-		$sql.= " t.rowid,";
163
-		$sql.= " t.fk_loan,";
164
-		$sql.= " t.datec,";
165
-		$sql.= " t.tms,";
166
-		$sql.= " t.datep,";
167
-		$sql.= " t.amount_capital,";
168
-		$sql.= " t.amount_insurance,";
169
-		$sql.= " t.amount_interest,";
170
-		$sql.= " t.fk_typepayment,";
171
-		$sql.= " t.num_payment,";
172
-        $sql.= " t.note_private,";
173
-        $sql.= " t.note_public,";
174
-		$sql.= " t.fk_bank,";
175
-		$sql.= " t.fk_user_creat,";
176
-		$sql.= " t.fk_user_modif,";
177
-		$sql.= " pt.code as type_code, pt.libelle as type_libelle,";
178
-		$sql.= ' b.fk_account';
179
-		$sql.= " FROM (".MAIN_DB_PREFIX."c_paiement as pt, ".MAIN_DB_PREFIX.$this->table_element." as t)";
180
-		$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid';
181
-		$sql.= " WHERE t.rowid = ".$id." AND t.fk_typepayment = pt.id";
182
-		$sql.= " AND pt.entity = " . getEntity('c_paiement');
162
+		$sql .= " t.rowid,";
163
+		$sql .= " t.fk_loan,";
164
+		$sql .= " t.datec,";
165
+		$sql .= " t.tms,";
166
+		$sql .= " t.datep,";
167
+		$sql .= " t.amount_capital,";
168
+		$sql .= " t.amount_insurance,";
169
+		$sql .= " t.amount_interest,";
170
+		$sql .= " t.fk_typepayment,";
171
+		$sql .= " t.num_payment,";
172
+        $sql .= " t.note_private,";
173
+        $sql .= " t.note_public,";
174
+		$sql .= " t.fk_bank,";
175
+		$sql .= " t.fk_user_creat,";
176
+		$sql .= " t.fk_user_modif,";
177
+		$sql .= " pt.code as type_code, pt.libelle as type_libelle,";
178
+		$sql .= ' b.fk_account';
179
+		$sql .= " FROM (".MAIN_DB_PREFIX."c_paiement as pt, ".MAIN_DB_PREFIX.$this->table_element." as t)";
180
+		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid';
181
+		$sql .= " WHERE t.rowid = ".$id." AND t.fk_typepayment = pt.id";
182
+		$sql .= " AND pt.entity = ".getEntity('c_paiement');
183 183
 
184 184
 		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
185
-		$resql=$this->db->query($sql);
185
+		$resql = $this->db->query($sql);
186 186
 		if ($resql)
187 187
 	{
188 188
 		if ($this->db->num_rows($resql))
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 		}
220 220
 		else
221 221
 		{
222
-			$this->error="Error ".$this->db->lasterror();
222
+			$this->error = "Error ".$this->db->lasterror();
223 223
 			return -1;
224 224
 		}
225 225
 	}
@@ -232,23 +232,23 @@  discard block
 block discarded – undo
232 232
 	 *  @param  int		$notrigger	    0=launch triggers after, 1=disable triggers
233 233
 	 *  @return int         			<0 if KO, >0 if OK
234 234
 	 */
235
-	function update($user=0, $notrigger=0)
235
+	function update($user = 0, $notrigger = 0)
236 236
 	{
237 237
 		global $conf, $langs;
238
-		$error=0;
238
+		$error = 0;
239 239
 
240 240
 		// Clean parameters
241
-		if (isset($this->fk_loan)) $this->fk_loan=trim($this->fk_loan);
242
-		if (isset($this->amount_capital)) $this->amount_capital=trim($this->amount_capital);
243
-		if (isset($this->amount_insurance)) $this->amount_insurance=trim($this->amount_insurance);
244
-		if (isset($this->amount_interest)) $this->amount_interest=trim($this->amount_interest);
245
-		if (isset($this->fk_typepayment)) $this->fk_typepayment=trim($this->fk_typepayment);
246
-		if (isset($this->num_payment)) $this->num_payment=trim($this->num_payment);
247
-		if (isset($this->note_private)) $this->note_private=trim($this->note_private);
248
-		if (isset($this->note_public)) $this->note_public=trim($this->note_public);
249
-		if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank);
250
-		if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat);
251
-		if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif);
241
+		if (isset($this->fk_loan)) $this->fk_loan = trim($this->fk_loan);
242
+		if (isset($this->amount_capital)) $this->amount_capital = trim($this->amount_capital);
243
+		if (isset($this->amount_insurance)) $this->amount_insurance = trim($this->amount_insurance);
244
+		if (isset($this->amount_interest)) $this->amount_interest = trim($this->amount_interest);
245
+		if (isset($this->fk_typepayment)) $this->fk_typepayment = trim($this->fk_typepayment);
246
+		if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment);
247
+		if (isset($this->note_private)) $this->note_private = trim($this->note_private);
248
+		if (isset($this->note_public)) $this->note_public = trim($this->note_public);
249
+		if (isset($this->fk_bank)) $this->fk_bank = trim($this->fk_bank);
250
+		if (isset($this->fk_user_creat)) $this->fk_user_creat = trim($this->fk_user_creat);
251
+		if (isset($this->fk_user_modif)) $this->fk_user_modif = trim($this->fk_user_modif);
252 252
 
253 253
 		// Check parameters
254 254
 		// Put here code to add control on parameters values
@@ -256,32 +256,32 @@  discard block
 block discarded – undo
256 256
 		// Update request
257 257
 		$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET";
258 258
 
259
-		$sql.= " fk_loan=".(isset($this->fk_loan)?$this->fk_loan:"null").",";
260
-		$sql.= " datec=".(dol_strlen($this->datec)!=0 ? "'".$this->db->idate($this->datec)."'" : 'null').",";
261
-		$sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
262
-		$sql.= " datep=".(dol_strlen($this->datep)!=0 ? "'".$this->db->idate($this->datep)."'" : 'null').",";
263
-		$sql.= " amount_capital=".(isset($this->amount_capital)?$this->amount_capital:"null").",";
264
-		$sql.= " amount_insurance=".(isset($this->amount_insurance)?$this->amount_insurance:"null").",";
265
-		$sql.= " amount_interest=".(isset($this->amount_interest)?$this->amount_interest:"null").",";
266
-		$sql.= " fk_typepayment=".(isset($this->fk_typepayment)?$this->fk_typepayment:"null").",";
267
-		$sql.= " num_payment=".(isset($this->num_payment)?"'".$this->db->escape($this->num_payment)."'":"null").",";
268
-		$sql.= " note_private=".(isset($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null").",";
269
-		$sql.= " note_public=".(isset($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null").",";
270
-		$sql.= " fk_bank=".(isset($this->fk_bank)?$this->fk_bank:"null").",";
271
-		$sql.= " fk_user_creat=".(isset($this->fk_user_creat)?$this->fk_user_creat:"null").",";
272
-		$sql.= " fk_user_modif=".(isset($this->fk_user_modif)?$this->fk_user_modif:"null")."";
273
-
274
-		$sql.= " WHERE rowid=".$this->id;
259
+		$sql .= " fk_loan=".(isset($this->fk_loan) ? $this->fk_loan : "null").",";
260
+		$sql .= " datec=".(dol_strlen($this->datec) != 0 ? "'".$this->db->idate($this->datec)."'" : 'null').",";
261
+		$sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
262
+		$sql .= " datep=".(dol_strlen($this->datep) != 0 ? "'".$this->db->idate($this->datep)."'" : 'null').",";
263
+		$sql .= " amount_capital=".(isset($this->amount_capital) ? $this->amount_capital : "null").",";
264
+		$sql .= " amount_insurance=".(isset($this->amount_insurance) ? $this->amount_insurance : "null").",";
265
+		$sql .= " amount_interest=".(isset($this->amount_interest) ? $this->amount_interest : "null").",";
266
+		$sql .= " fk_typepayment=".(isset($this->fk_typepayment) ? $this->fk_typepayment : "null").",";
267
+		$sql .= " num_payment=".(isset($this->num_payment) ? "'".$this->db->escape($this->num_payment)."'" : "null").",";
268
+		$sql .= " note_private=".(isset($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null").",";
269
+		$sql .= " note_public=".(isset($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null").",";
270
+		$sql .= " fk_bank=".(isset($this->fk_bank) ? $this->fk_bank : "null").",";
271
+		$sql .= " fk_user_creat=".(isset($this->fk_user_creat) ? $this->fk_user_creat : "null").",";
272
+		$sql .= " fk_user_modif=".(isset($this->fk_user_modif) ? $this->fk_user_modif : "null")."";
273
+
274
+		$sql .= " WHERE rowid=".$this->id;
275 275
 
276 276
 		$this->db->begin();
277 277
 
278 278
 		dol_syslog(get_class($this)."::update", LOG_DEBUG);
279 279
 		$resql = $this->db->query($sql);
280
-		if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
280
+		if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
281 281
 
282
-		if (! $error)
282
+		if (!$error)
283 283
 		{
284
-			if (! $notrigger)
284
+			if (!$notrigger)
285 285
 			{
286 286
 				// Uncomment this and change MYOBJECT to your own tag if you
287 287
 				// want this action call a trigger.
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 		if ($error)
300 300
 		{
301 301
 			$this->db->rollback();
302
-			return -1*$error;
302
+			return -1 * $error;
303 303
 		}
304 304
 		else
305 305
 		{
@@ -316,26 +316,26 @@  discard block
 block discarded – undo
316 316
 	 *  @param  int		$notrigger		0=launch triggers after, 1=disable triggers
317 317
 	 *  @return int						<0 if KO, >0 if OK
318 318
 	 */
319
-	function delete($user, $notrigger=0)
319
+	function delete($user, $notrigger = 0)
320 320
 	{
321 321
 		global $conf, $langs;
322
-		$error=0;
322
+		$error = 0;
323 323
 
324 324
 		$this->db->begin();
325 325
 
326
-	    if (! $error)
326
+	    if (!$error)
327 327
 		{
328 328
 			$sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
329
-			$sql.= " WHERE rowid=".$this->id;
329
+			$sql .= " WHERE rowid=".$this->id;
330 330
 
331 331
 			dol_syslog(get_class($this)."::delete", LOG_DEBUG);
332 332
 			$resql = $this->db->query($sql);
333
-			if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
333
+			if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
334 334
 		}
335 335
 
336
-		if (! $error)
336
+		if (!$error)
337 337
 		{
338
-			if (! $notrigger)
338
+			if (!$notrigger)
339 339
 			{
340 340
 				// Uncomment this and change MYOBJECT to your own tag if you
341 341
 				// want this action call a trigger.
@@ -352,13 +352,13 @@  discard block
 block discarded – undo
352 352
 		// Commit or rollback
353 353
 		if ($error)
354 354
 		{
355
-			foreach($this->errors as $errmsg)
355
+			foreach ($this->errors as $errmsg)
356 356
 			{
357 357
 				dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
358
-				$this->error.=($this->error?', '.$errmsg:$errmsg);
358
+				$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
359 359
 			}
360 360
 			$this->db->rollback();
361
-			return -1*$error;
361
+			return -1 * $error;
362 362
 		}
363 363
 		else
364 364
 		{
@@ -367,13 +367,13 @@  discard block
 block discarded – undo
367 367
 		}
368 368
 	}
369 369
 
370
-	function calc_mens($capital,$rate,$nbterm)
370
+	function calc_mens($capital, $rate, $nbterm)
371 371
 	{
372
-		$result='';
372
+		$result = '';
373 373
 
374
-		if (!empty($capital)&&!empty($rate)&&!empty($nbterm))
374
+		if (!empty($capital) && !empty($rate) && !empty($nbterm))
375 375
 		{
376
-			$result=($capital*($rate/12))/(1-pow((1+($rate/12)),($nbterm*-1)));
376
+			$result = ($capital * ($rate / 12)) / (1 - pow((1 + ($rate / 12)), ($nbterm * -1)));
377 377
 		}
378 378
 
379 379
 		return $result;
@@ -391,30 +391,30 @@  discard block
 block discarded – undo
391 391
 		global $langs;
392 392
 
393 393
 		$sql = "SELECT";
394
-		$sql.= " t.rowid,";
395
-		$sql.= " t.fk_loan,";
396
-		$sql.= " t.datec,";
397
-		$sql.= " t.tms,";
398
-		$sql.= " t.datep,";
399
-		$sql.= " t.amount_capital,";
400
-		$sql.= " t.amount_insurance,";
401
-		$sql.= " t.amount_interest,";
402
-		$sql.= " t.fk_typepayment,";
403
-		$sql.= " t.num_payment,";
404
-		$sql.= " t.note_private,";
405
-		$sql.= " t.note_public,";
406
-		$sql.= " t.fk_bank,";
407
-		$sql.= " t.fk_user_creat,";
408
-		$sql.= " t.fk_user_modif";
409
-		$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
410
-		$sql.= " WHERE t.fk_loan = ".$loanid;
394
+		$sql .= " t.rowid,";
395
+		$sql .= " t.fk_loan,";
396
+		$sql .= " t.datec,";
397
+		$sql .= " t.tms,";
398
+		$sql .= " t.datep,";
399
+		$sql .= " t.amount_capital,";
400
+		$sql .= " t.amount_insurance,";
401
+		$sql .= " t.amount_interest,";
402
+		$sql .= " t.fk_typepayment,";
403
+		$sql .= " t.num_payment,";
404
+		$sql .= " t.note_private,";
405
+		$sql .= " t.note_public,";
406
+		$sql .= " t.fk_bank,";
407
+		$sql .= " t.fk_user_creat,";
408
+		$sql .= " t.fk_user_modif";
409
+		$sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
410
+		$sql .= " WHERE t.fk_loan = ".$loanid;
411 411
 
412 412
 		dol_syslog(get_class($this)."::fetchall", LOG_DEBUG);
413
-		$resql=$this->db->query($sql);
413
+		$resql = $this->db->query($sql);
414 414
 
415 415
 		if ($resql)
416 416
 		{
417
-			while($obj = $this->db->fetch_object($resql))
417
+			while ($obj = $this->db->fetch_object($resql))
418 418
 			{
419 419
 				$line = New LoanSchedule($this->db);
420 420
 				$line->id = $obj->rowid;
@@ -442,7 +442,7 @@  discard block
 block discarded – undo
442 442
 		}
443 443
 		else
444 444
 		{
445
-			$this->error="Error ".$this->db->lasterror();
445
+			$this->error = "Error ".$this->db->lasterror();
446 446
 			return -1;
447 447
 		}
448 448
 	}
@@ -461,24 +461,24 @@  discard block
 block discarded – undo
461 461
 		$toinsert = array();
462 462
 
463 463
 		$sql = "SELECT l.rowid";
464
-		$sql.= " FROM ".MAIN_DB_PREFIX."loan as l ";
465
-		$sql.= " WHERE l.paid = 0";
466
-		$resql=$this->db->query($sql);
464
+		$sql .= " FROM ".MAIN_DB_PREFIX."loan as l ";
465
+		$sql .= " WHERE l.paid = 0";
466
+		$resql = $this->db->query($sql);
467 467
 
468
-		if($resql){
469
-			while($obj = $this->db->fetch_object($resql)){
468
+		if ($resql) {
469
+			while ($obj = $this->db->fetch_object($resql)) {
470 470
 				$lastrecorded = $this->lastpaiment($obj->rowid);
471 471
 				$toinsert = $this->paimenttorecord($obj->rowid, $lastrecorded);
472
-				if(count($toinsert)>0){
473
-					foreach ($toinsert as $echid){
472
+				if (count($toinsert) > 0) {
473
+					foreach ($toinsert as $echid) {
474 474
 						$this->db->begin();
475
-						$sql = "INSERT INTO " .MAIN_DB_PREFIX . "payment_loan ";
476
-						$sql.= "(fk_loan,datec,tms,datep,amount_capital,amount_insurance,amount_interest,fk_typepayment,num_payment,note_private,note_public,fk_bank,fk_user_creat,fk_user_modif) ";
477
-						$sql.= "SELECT fk_loan,datec,tms,datep,amount_capital,amount_insurance,amount_interest,fk_typepayment,num_payment,note_private,note_public,fk_bank,fk_user_creat,fk_user_modif FROM " . MAIN_DB_PREFIX . "loan_schedule WHERE rowid =" .$echid;
478
-						$res=$this->db->query($sql);
479
-						if($res){
475
+						$sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_loan ";
476
+						$sql .= "(fk_loan,datec,tms,datep,amount_capital,amount_insurance,amount_interest,fk_typepayment,num_payment,note_private,note_public,fk_bank,fk_user_creat,fk_user_modif) ";
477
+						$sql .= "SELECT fk_loan,datec,tms,datep,amount_capital,amount_insurance,amount_interest,fk_typepayment,num_payment,note_private,note_public,fk_bank,fk_user_creat,fk_user_modif FROM ".MAIN_DB_PREFIX."loan_schedule WHERE rowid =".$echid;
478
+						$res = $this->db->query($sql);
479
+						if ($res) {
480 480
 							$this->db->commit();
481
-						}else {
481
+						} else {
482 482
 							$this->db->rollback();
483 483
 						}
484 484
 					}
@@ -497,17 +497,17 @@  discard block
 block discarded – undo
497 497
 	function lastpaiment($loanid)
498 498
 	{
499 499
 		$sql = "SELECT p.datep";
500
-		$sql.= " FROM ".MAIN_DB_PREFIX."payment_loan as p ";
501
-		$sql.= " WHERE p.fk_loan = " . $loanid;
502
-		$sql.= " ORDER BY p.datep DESC ";
503
-		$sql.= " LIMIT 1 ";
500
+		$sql .= " FROM ".MAIN_DB_PREFIX."payment_loan as p ";
501
+		$sql .= " WHERE p.fk_loan = ".$loanid;
502
+		$sql .= " ORDER BY p.datep DESC ";
503
+		$sql .= " LIMIT 1 ";
504 504
 
505
-		$resql=$this->db->query($sql);
505
+		$resql = $this->db->query($sql);
506 506
 
507
-		if($resql){
507
+		if ($resql) {
508 508
 			$obj = $this->db->fetch_object($resql);
509 509
 			return $this->db->jdate($obj->datep);
510
-		}else{
510
+		} else {
511 511
 			return -1;
512 512
 		}
513 513
 	}
@@ -522,15 +522,15 @@  discard block
 block discarded – undo
522 522
 	function paimenttorecord($loanid, $datemax)
523 523
 	{
524 524
 		$sql = "SELECT p.rowid";
525
-		$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as p ";
526
-		$sql.= " WHERE p.fk_loan = " . $loanid;
527
-		if (!empty($datemax)) { $sql.= " AND p.datep > '" . $this->db->idate($datemax) ."'";}
528
-		$sql.= " AND p.datep <= '" . $this->db->idate(dol_now()). "'";
525
+		$sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as p ";
526
+		$sql .= " WHERE p.fk_loan = ".$loanid;
527
+		if (!empty($datemax)) { $sql .= " AND p.datep > '".$this->db->idate($datemax)."'"; }
528
+		$sql .= " AND p.datep <= '".$this->db->idate(dol_now())."'";
529 529
 
530
-		$resql=$this->db->query($sql);
530
+		$resql = $this->db->query($sql);
531 531
 
532
-		if($resql){
533
-			while($obj = $this->db->fetch_object($resql))
532
+		if ($resql) {
533
+			while ($obj = $this->db->fetch_object($resql))
534 534
 			{
535 535
 				$result[] = $obj->rowid;
536 536
 			}
Please login to merge, or discard this patch.
htdocs/supplier_proposal/class/supplier_proposal.class.php 4 patches
Doc Comments   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -339,12 +339,12 @@  discard block
 block discarded – undo
339 339
      * 		@param    	double		$pu_ht				Prix unitaire
340 340
      * 		@param    	double		$qty             	Quantite
341 341
      * 		@param    	double		$txtva           	Taux de tva
342
-     * 		@param		double		$txlocaltax1		Local tax 1 rate
343
-     *  	@param		double		$txlocaltax2		Local tax 2 rate
342
+     * 		@param		integer		$txlocaltax1		Local tax 1 rate
343
+     *  	@param		integer		$txlocaltax2		Local tax 2 rate
344 344
      *		@param    	int			$fk_product      	Id du produit/service predefini
345
-     * 		@param    	double		$remise_percent  	Pourcentage de remise de la ligne
345
+     * 		@param    	integer		$remise_percent  	Pourcentage de remise de la ligne
346 346
      * 		@param    	string		$price_base_type	HT or TTC
347
-     * 		@param    	double		$pu_ttc             Prix unitaire TTC
347
+     * 		@param    	integer		$pu_ttc             Prix unitaire TTC
348 348
      * 		@param    	int			$info_bits			Bits de type de lignes
349 349
      *      @param      int			$type               Type of line (product, service)
350 350
      *      @param      int			$rang               Position of line
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
      *      @param		int			$fk_fournprice		Id supplier price
354 354
      *      @param		int			$pa_ht				Buying price without tax
355 355
      *      @param		string		$label				???
356
-     *      @param		array		$array_option		extrafields array
356
+     *      @param		integer		$array_option		extrafields array
357 357
 	 * 		@param		string		$ref_fourn			Supplier price reference
358 358
 	 * 		@param		int			$fk_unit			Id of the unit to use.
359 359
 	 * 		@param		string		$origin				'order', 'supplier_proposal', ...
@@ -537,8 +537,8 @@  discard block
 block discarded – undo
537 537
      *  @param      double		$qty            	Quantity
538 538
      *  @param      double		$remise_percent  	Remise effectuee sur le produit
539 539
      *  @param      double		$txtva	          	Taux de TVA
540
-     * 	@param	  	double		$txlocaltax1		Local tax 1 rate
541
-     *  @param	  	double		$txlocaltax2		Local tax 2 rate
540
+     * 	@param	  	integer		$txlocaltax1		Local tax 1 rate
541
+     *  @param	  	integer		$txlocaltax2		Local tax 2 rate
542 542
      *  @param      string		$desc            	Description
543 543
      *	@param	  	double		$price_base_type	HT ou TTC
544 544
      *	@param      int			$info_bits        	Miscellaneous informations
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
      *  @param		int			$pa_ht				Price (without tax) of product when it was bought
550 550
      *  @param		string		$label				???
551 551
      *  @param		int			$type				0/1=Product/service
552
-	 *  @param		array		$array_option		extrafields array
552
+	 *  @param		integer		$array_option		extrafields array
553 553
 	 * 	@param		string		$ref_fourn			Supplier price reference
554 554
 	 *	@param		int			$fk_unit			Id of the unit to use.
555 555
      *  @return     int     		        		0 if OK, <0 if KO
Please login to merge, or discard this patch.
Indentation   +2537 added lines, -2537 removed lines patch added patch discarded remove patch
@@ -44,29 +44,29 @@  discard block
 block discarded – undo
44 44
  */
45 45
 class SupplierProposal extends CommonObject
46 46
 {
47
-    public $element='supplier_proposal';
48
-    public $table_element='supplier_proposal';
49
-    public $table_element_line='supplier_proposaldet';
50
-    public $fk_element='fk_supplier_proposal';
51
-    protected $ismultientitymanaged = 1;	// 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
52
-    public $picto='propal';
47
+	public $element='supplier_proposal';
48
+	public $table_element='supplier_proposal';
49
+	public $table_element_line='supplier_proposaldet';
50
+	public $fk_element='fk_supplier_proposal';
51
+	protected $ismultientitymanaged = 1;	// 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
52
+	public $picto='propal';
53 53
 
54
-    /**
55
-     * {@inheritdoc}
56
-     */
57
-    protected $table_ref_field = 'ref';
54
+	/**
55
+	 * {@inheritdoc}
56
+	 */
57
+	protected $table_ref_field = 'ref';
58 58
 
59
-    var $socid;		// Id client
59
+	var $socid;		// Id client
60 60
 
61 61
 	/**
62 62
 	 * @deprecated
63 63
 	 * @see user_author_id
64 64
 	 */
65
-    var $author;
65
+	var $author;
66 66
 	var $ref_fourn;  //Reference saisie lors de l'ajout d'une ligne à la demande
67
-    var $statut;					// 0 (draft), 1 (validated), 2 (signed), 3 (not signed), 4 (processed/billed)
68
-    var $date;						// Date of proposal
69
-    var $date_livraison;
67
+	var $statut;					// 0 (draft), 1 (validated), 2 (signed), 3 (not signed), 4 (processed/billed)
68
+	var $date;						// Date of proposal
69
+	var $date_livraison;
70 70
 
71 71
 	/**
72 72
 	 * @deprecated
@@ -93,45 +93,45 @@  discard block
 block discarded – undo
93 93
 	public $date_validation;
94 94
 
95 95
 
96
-    var $user_author_id;
97
-    var $user_valid_id;
98
-    var $user_close_id;
96
+	var $user_author_id;
97
+	var $user_valid_id;
98
+	var $user_close_id;
99 99
 
100 100
 	/**
101 101
 	 * @deprecated
102 102
 	 * @see price_ht
103 103
 	 */
104
-    var $price;
104
+	var $price;
105 105
 	/**
106 106
 	 * @deprecated
107 107
 	 * @see total_tva
108 108
 	 */
109
-    var $tva;
109
+	var $tva;
110 110
 	/**
111 111
 	 * @deprecated
112 112
 	 * @see total_ttc
113 113
 	 */
114
-    var $total;
114
+	var $total;
115 115
 
116
-    var $cond_reglement_code;
117
-    var $mode_reglement_code;
118
-    var $remise;
119
-    var $remise_percent;
120
-    var $remise_absolue;
116
+	var $cond_reglement_code;
117
+	var $mode_reglement_code;
118
+	var $remise;
119
+	var $remise_percent;
120
+	var $remise_absolue;
121 121
 
122
-    var $products=array();
123
-    var $extraparams=array();
122
+	var $products=array();
123
+	var $extraparams=array();
124 124
 
125
-    var $lines = array();
126
-    var $line;
125
+	var $lines = array();
126
+	var $line;
127 127
 
128
-    var $labelstatut=array();
129
-    var $labelstatut_short=array();
128
+	var $labelstatut=array();
129
+	var $labelstatut_short=array();
130 130
 
131
-    var $nbtodo;
132
-    var $nbtodolate;
131
+	var $nbtodo;
132
+	var $nbtodolate;
133 133
 
134
-    var $specimen;
134
+	var $specimen;
135 135
 
136 136
 	// Multicurrency
137 137
 	var $fk_multicurrency;
@@ -164,319 +164,319 @@  discard block
 block discarded – undo
164 164
 
165 165
 
166 166
 
167
-    /**
168
-     *	Constructor
169
-     *
170
-     *	@param      DoliDB	$db         Database handler
171
-     *	@param      int		$socid		Id third party
172
-     *	@param      int		$supplier_proposalid   Id supplier_proposal
173
-     */
174
-    function __construct($db, $socid="", $supplier_proposalid=0)
175
-    {
176
-        global $conf,$langs;
177
-
178
-        $this->db = $db;
179
-        $this->socid = $socid;
180
-        $this->id = $supplier_proposalid;
181
-        $this->products = array();
182
-        $this->remise = 0;
183
-        $this->remise_percent = 0;
184
-        $this->remise_absolue = 0;
185
-
186
-        $langs->load("supplier_proposal");
187
-        $this->labelstatut[0]=$langs->trans("SupplierProposalStatusDraft");
188
-        $this->labelstatut[1]=$langs->trans("SupplierProposalStatusValidated");
189
-        $this->labelstatut[2]=$langs->trans("SupplierProposalStatusSigned");
190
-        $this->labelstatut[3]=$langs->trans("SupplierProposalStatusNotSigned");
191
-        $this->labelstatut[4]=$langs->trans("SupplierProposalStatusClosed");
192
-        $this->labelstatut_short[0]=$langs->trans("SupplierProposalStatusDraftShort");
193
-        $this->labelstatut_short[1]=$langs->trans("Opened");
194
-        $this->labelstatut_short[2]=$langs->trans("SupplierProposalStatusSignedShort");
195
-        $this->labelstatut_short[3]=$langs->trans("SupplierProposalStatusNotSignedShort");
196
-        $this->labelstatut_short[4]=$langs->trans("SupplierProposalStatusClosedShort");
197
-    }
198
-
199
-
200
-    /**
201
-     * 	Add line into array products
202
-     *	$this->client doit etre charge
203
-     *
204
-     * 	@param  int		$idproduct       	Product Id to add
205
-     * 	@param  int		$qty             	Quantity
206
-     * 	@param  int		$remise_percent  	Discount effected on Product
207
-     *  @return	int							<0 if KO, >0 if OK
208
-     *
209
-     *	TODO	Remplacer les appels a cette fonction par generation objet Ligne
210
-     *			insere dans tableau $this->products
211
-     */
212
-    function add_product($idproduct, $qty, $remise_percent=0)
213
-    {
214
-        global $conf, $mysoc;
215
-
216
-        if (! $qty) $qty = 1;
217
-
218
-        dol_syslog(get_class($this)."::add_product $idproduct, $qty, $remise_percent");
219
-        if ($idproduct > 0)
220
-        {
221
-            $prod=new Product($this->db);
222
-            $prod->fetch($idproduct);
223
-
224
-            $productdesc = $prod->description;
225
-
226
-            $tva_tx = get_default_tva($mysoc,$this->thirdparty,$prod->id);
227
-            $tva_npr = get_default_npr($mysoc,$this->thirdparty,$prod->id);
228
-            if (empty($tva_tx)) $tva_npr=0;
229
-            $localtax1_tx = get_localtax($tva_tx,1,$mysoc,$this->thirdparty,$tva_npr);
230
-            $localtax2_tx = get_localtax($tva_tx,2,$mysoc,$this->thirdparty,$tva_npr);
231
-
232
-            // multiprix
233
-            if($conf->global->PRODUIT_MULTIPRICES && $this->thirdparty->price_level)
234
-            {
235
-                $price = $prod->multiprices[$this->thirdparty->price_level];
236
-            }
237
-            else
238
-            {
239
-                $price = $prod->price;
240
-            }
241
-
242
-            $line = new SupplierProposalLine($this->db);
243
-
244
-            $line->fk_product=$idproduct;
245
-            $line->desc=$productdesc;
246
-            $line->qty=$qty;
247
-            $line->subprice=$price;
248
-            $line->remise_percent=$remise_percent;
249
-            $line->tva_tx=$tva_tx;
250
-
251
-            $this->lines[]=$line;
252
-        }
253
-    }
254
-
255
-    /**
256
-     *	Adding line of fixed discount in the proposal in DB
257
-     *
258
-     *	@param     int		$idremise			Id of fixed discount
259
-     *  @return    int          				>0 if OK, <0 if KO
260
-     */
261
-    function insert_discount($idremise)
262
-    {
263
-        global $langs;
264
-
265
-        include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
266
-        include_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
267
-
268
-        $this->db->begin();
269
-
270
-        $remise=new DiscountAbsolute($this->db);
271
-        $result=$remise->fetch($idremise);
272
-
273
-        if ($result > 0)
274
-        {
275
-            if ($remise->fk_facture)	// Protection against multiple submission
276
-            {
277
-                $this->error=$langs->trans("ErrorDiscountAlreadyUsed");
278
-                $this->db->rollback();
279
-                return -5;
280
-            }
281
-
282
-            $supplier_proposalligne=new SupplierProposalLine($this->db);
283
-            $supplier_proposalligne->fk_supplier_proposal=$this->id;
284
-            $supplier_proposalligne->fk_remise_except=$remise->id;
285
-            $supplier_proposalligne->desc=$remise->description;   	// Description ligne
286
-            $supplier_proposalligne->tva_tx=$remise->tva_tx;
287
-            $supplier_proposalligne->subprice=-$remise->amount_ht;
288
-            $supplier_proposalligne->fk_product=0;					// Id produit predefini
289
-            $supplier_proposalligne->qty=1;
290
-            $supplier_proposalligne->remise=0;
291
-            $supplier_proposalligne->remise_percent=0;
292
-            $supplier_proposalligne->rang=-1;
293
-            $supplier_proposalligne->info_bits=2;
294
-
295
-            // TODO deprecated
296
-            $supplier_proposalligne->price=-$remise->amount_ht;
297
-
298
-            $supplier_proposalligne->total_ht  = -$remise->amount_ht;
299
-            $supplier_proposalligne->total_tva = -$remise->amount_tva;
300
-            $supplier_proposalligne->total_ttc = -$remise->amount_ttc;
301
-
302
-            $result=$supplier_proposalligne->insert();
303
-            if ($result > 0)
304
-            {
305
-                $result=$this->update_price(1);
306
-                if ($result > 0)
307
-                {
308
-                    $this->db->commit();
309
-                    return 1;
310
-                }
311
-                else
312
-                {
313
-                    $this->db->rollback();
314
-                    return -1;
315
-                }
316
-            }
317
-            else
318
-            {
319
-                $this->error=$supplier_proposalligne->error;
320
-                $this->db->rollback();
321
-                return -2;
322
-            }
323
-        }
324
-        else
325
-        {
326
-            $this->db->rollback();
327
-            return -2;
328
-        }
329
-    }
330
-
331
-    /**
332
-     *    	Add a proposal line into database (linked to product/service or not)
333
-     * 		Les parametres sont deja cense etre juste et avec valeurs finales a l'appel
334
-     *		de cette methode. Aussi, pour le taux tva, il doit deja avoir ete defini
335
-     *		par l'appelant par la methode get_default_tva(societe_vendeuse,societe_acheteuse,'',produit)
336
-     *		et le desc doit deja avoir la bonne valeur (a l'appelant de gerer le multilangue)
337
-     *
338
-     * 		@param    	string		$desc				Description de la ligne
339
-     * 		@param    	double		$pu_ht				Prix unitaire
340
-     * 		@param    	double		$qty             	Quantite
341
-     * 		@param    	double		$txtva           	Taux de tva
342
-     * 		@param		double		$txlocaltax1		Local tax 1 rate
343
-     *  	@param		double		$txlocaltax2		Local tax 2 rate
344
-     *		@param    	int			$fk_product      	Id du produit/service predefini
345
-     * 		@param    	double		$remise_percent  	Pourcentage de remise de la ligne
346
-     * 		@param    	string		$price_base_type	HT or TTC
347
-     * 		@param    	double		$pu_ttc             Prix unitaire TTC
348
-     * 		@param    	int			$info_bits			Bits de type de lignes
349
-     *      @param      int			$type               Type of line (product, service)
350
-     *      @param      int			$rang               Position of line
351
-     *      @param		int			$special_code		Special code (also used by externals modules!)
352
-     *      @param		int			$fk_parent_line		Id of parent line
353
-     *      @param		int			$fk_fournprice		Id supplier price
354
-     *      @param		int			$pa_ht				Buying price without tax
355
-     *      @param		string		$label				???
356
-     *      @param		array		$array_option		extrafields array
167
+	/**
168
+	 *	Constructor
169
+	 *
170
+	 *	@param      DoliDB	$db         Database handler
171
+	 *	@param      int		$socid		Id third party
172
+	 *	@param      int		$supplier_proposalid   Id supplier_proposal
173
+	 */
174
+	function __construct($db, $socid="", $supplier_proposalid=0)
175
+	{
176
+		global $conf,$langs;
177
+
178
+		$this->db = $db;
179
+		$this->socid = $socid;
180
+		$this->id = $supplier_proposalid;
181
+		$this->products = array();
182
+		$this->remise = 0;
183
+		$this->remise_percent = 0;
184
+		$this->remise_absolue = 0;
185
+
186
+		$langs->load("supplier_proposal");
187
+		$this->labelstatut[0]=$langs->trans("SupplierProposalStatusDraft");
188
+		$this->labelstatut[1]=$langs->trans("SupplierProposalStatusValidated");
189
+		$this->labelstatut[2]=$langs->trans("SupplierProposalStatusSigned");
190
+		$this->labelstatut[3]=$langs->trans("SupplierProposalStatusNotSigned");
191
+		$this->labelstatut[4]=$langs->trans("SupplierProposalStatusClosed");
192
+		$this->labelstatut_short[0]=$langs->trans("SupplierProposalStatusDraftShort");
193
+		$this->labelstatut_short[1]=$langs->trans("Opened");
194
+		$this->labelstatut_short[2]=$langs->trans("SupplierProposalStatusSignedShort");
195
+		$this->labelstatut_short[3]=$langs->trans("SupplierProposalStatusNotSignedShort");
196
+		$this->labelstatut_short[4]=$langs->trans("SupplierProposalStatusClosedShort");
197
+	}
198
+
199
+
200
+	/**
201
+	 * 	Add line into array products
202
+	 *	$this->client doit etre charge
203
+	 *
204
+	 * 	@param  int		$idproduct       	Product Id to add
205
+	 * 	@param  int		$qty             	Quantity
206
+	 * 	@param  int		$remise_percent  	Discount effected on Product
207
+	 *  @return	int							<0 if KO, >0 if OK
208
+	 *
209
+	 *	TODO	Remplacer les appels a cette fonction par generation objet Ligne
210
+	 *			insere dans tableau $this->products
211
+	 */
212
+	function add_product($idproduct, $qty, $remise_percent=0)
213
+	{
214
+		global $conf, $mysoc;
215
+
216
+		if (! $qty) $qty = 1;
217
+
218
+		dol_syslog(get_class($this)."::add_product $idproduct, $qty, $remise_percent");
219
+		if ($idproduct > 0)
220
+		{
221
+			$prod=new Product($this->db);
222
+			$prod->fetch($idproduct);
223
+
224
+			$productdesc = $prod->description;
225
+
226
+			$tva_tx = get_default_tva($mysoc,$this->thirdparty,$prod->id);
227
+			$tva_npr = get_default_npr($mysoc,$this->thirdparty,$prod->id);
228
+			if (empty($tva_tx)) $tva_npr=0;
229
+			$localtax1_tx = get_localtax($tva_tx,1,$mysoc,$this->thirdparty,$tva_npr);
230
+			$localtax2_tx = get_localtax($tva_tx,2,$mysoc,$this->thirdparty,$tva_npr);
231
+
232
+			// multiprix
233
+			if($conf->global->PRODUIT_MULTIPRICES && $this->thirdparty->price_level)
234
+			{
235
+				$price = $prod->multiprices[$this->thirdparty->price_level];
236
+			}
237
+			else
238
+			{
239
+				$price = $prod->price;
240
+			}
241
+
242
+			$line = new SupplierProposalLine($this->db);
243
+
244
+			$line->fk_product=$idproduct;
245
+			$line->desc=$productdesc;
246
+			$line->qty=$qty;
247
+			$line->subprice=$price;
248
+			$line->remise_percent=$remise_percent;
249
+			$line->tva_tx=$tva_tx;
250
+
251
+			$this->lines[]=$line;
252
+		}
253
+	}
254
+
255
+	/**
256
+	 *	Adding line of fixed discount in the proposal in DB
257
+	 *
258
+	 *	@param     int		$idremise			Id of fixed discount
259
+	 *  @return    int          				>0 if OK, <0 if KO
260
+	 */
261
+	function insert_discount($idremise)
262
+	{
263
+		global $langs;
264
+
265
+		include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
266
+		include_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
267
+
268
+		$this->db->begin();
269
+
270
+		$remise=new DiscountAbsolute($this->db);
271
+		$result=$remise->fetch($idremise);
272
+
273
+		if ($result > 0)
274
+		{
275
+			if ($remise->fk_facture)	// Protection against multiple submission
276
+			{
277
+				$this->error=$langs->trans("ErrorDiscountAlreadyUsed");
278
+				$this->db->rollback();
279
+				return -5;
280
+			}
281
+
282
+			$supplier_proposalligne=new SupplierProposalLine($this->db);
283
+			$supplier_proposalligne->fk_supplier_proposal=$this->id;
284
+			$supplier_proposalligne->fk_remise_except=$remise->id;
285
+			$supplier_proposalligne->desc=$remise->description;   	// Description ligne
286
+			$supplier_proposalligne->tva_tx=$remise->tva_tx;
287
+			$supplier_proposalligne->subprice=-$remise->amount_ht;
288
+			$supplier_proposalligne->fk_product=0;					// Id produit predefini
289
+			$supplier_proposalligne->qty=1;
290
+			$supplier_proposalligne->remise=0;
291
+			$supplier_proposalligne->remise_percent=0;
292
+			$supplier_proposalligne->rang=-1;
293
+			$supplier_proposalligne->info_bits=2;
294
+
295
+			// TODO deprecated
296
+			$supplier_proposalligne->price=-$remise->amount_ht;
297
+
298
+			$supplier_proposalligne->total_ht  = -$remise->amount_ht;
299
+			$supplier_proposalligne->total_tva = -$remise->amount_tva;
300
+			$supplier_proposalligne->total_ttc = -$remise->amount_ttc;
301
+
302
+			$result=$supplier_proposalligne->insert();
303
+			if ($result > 0)
304
+			{
305
+				$result=$this->update_price(1);
306
+				if ($result > 0)
307
+				{
308
+					$this->db->commit();
309
+					return 1;
310
+				}
311
+				else
312
+				{
313
+					$this->db->rollback();
314
+					return -1;
315
+				}
316
+			}
317
+			else
318
+			{
319
+				$this->error=$supplier_proposalligne->error;
320
+				$this->db->rollback();
321
+				return -2;
322
+			}
323
+		}
324
+		else
325
+		{
326
+			$this->db->rollback();
327
+			return -2;
328
+		}
329
+	}
330
+
331
+	/**
332
+	 *    	Add a proposal line into database (linked to product/service or not)
333
+	 * 		Les parametres sont deja cense etre juste et avec valeurs finales a l'appel
334
+	 *		de cette methode. Aussi, pour le taux tva, il doit deja avoir ete defini
335
+	 *		par l'appelant par la methode get_default_tva(societe_vendeuse,societe_acheteuse,'',produit)
336
+	 *		et le desc doit deja avoir la bonne valeur (a l'appelant de gerer le multilangue)
337
+	 *
338
+	 * 		@param    	string		$desc				Description de la ligne
339
+	 * 		@param    	double		$pu_ht				Prix unitaire
340
+	 * 		@param    	double		$qty             	Quantite
341
+	 * 		@param    	double		$txtva           	Taux de tva
342
+	 * 		@param		double		$txlocaltax1		Local tax 1 rate
343
+	 *  	@param		double		$txlocaltax2		Local tax 2 rate
344
+	 *		@param    	int			$fk_product      	Id du produit/service predefini
345
+	 * 		@param    	double		$remise_percent  	Pourcentage de remise de la ligne
346
+	 * 		@param    	string		$price_base_type	HT or TTC
347
+	 * 		@param    	double		$pu_ttc             Prix unitaire TTC
348
+	 * 		@param    	int			$info_bits			Bits de type de lignes
349
+	 *      @param      int			$type               Type of line (product, service)
350
+	 *      @param      int			$rang               Position of line
351
+	 *      @param		int			$special_code		Special code (also used by externals modules!)
352
+	 *      @param		int			$fk_parent_line		Id of parent line
353
+	 *      @param		int			$fk_fournprice		Id supplier price
354
+	 *      @param		int			$pa_ht				Buying price without tax
355
+	 *      @param		string		$label				???
356
+	 *      @param		array		$array_option		extrafields array
357 357
 	 * 		@param		string		$ref_fourn			Supplier price reference
358 358
 	 * 		@param		int			$fk_unit			Id of the unit to use.
359 359
 	 * 		@param		string		$origin				'order', 'supplier_proposal', ...
360 360
 	 * 		@param		int			$origin_id			Id of origin line
361
-     *    	@return    	int         	    			>0 if OK, <0 if KO
362
-     *
363
-     *    	@see       	add_product
364
-     */
365
-    function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $pu_ttc=0, $info_bits=0, $type=0, $rang=-1, $special_code=0, $fk_parent_line=0, $fk_fournprice=0, $pa_ht=0, $label='',$array_option=0, $ref_fourn='', $fk_unit='', $origin='', $origin_id=0)
366
-    {
367
-    	global $mysoc;
368
-
369
-        dol_syslog(get_class($this)."::addline supplier_proposalid=$this->id, desc=$desc, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, fk_product=$fk_product, remise_except=$remise_percent, price_base_type=$price_base_type, pu_ttc=$pu_ttc, info_bits=$info_bits, type=$type");
370
-        include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
371
-
372
-        // Clean parameters
373
-        if (empty($remise_percent)) $remise_percent=0;
374
-        if (empty($qty)) $qty=0;
375
-        if (empty($info_bits)) $info_bits=0;
376
-        if (empty($rang)) $rang=0;
377
-        if (empty($fk_parent_line) || $fk_parent_line < 0) $fk_parent_line=0;
378
-
379
-        $remise_percent=price2num($remise_percent);
380
-        $qty=price2num($qty);
381
-        $pu_ht=price2num($pu_ht);
382
-        $pu_ttc=price2num($pu_ttc);
383
-        $txtva=price2num($txtva);
384
-        $txlocaltax1=price2num($txlocaltax1);
385
-        $txlocaltax2=price2num($txlocaltax2);
386
-    		$pa_ht=price2num($pa_ht);
387
-        if ($price_base_type=='HT')
388
-        {
389
-            $pu=$pu_ht;
390
-        }
391
-        else
392
-        {
393
-            $pu=$pu_ttc;
394
-        }
395
-
396
-        // Check parameters
397
-        if ($type < 0) return -1;
398
-
399
-        if ($this->statut == 0)
400
-        {
401
-            $this->db->begin();
402
-
403
-            // Calcul du total TTC et de la TVA pour la ligne a partir de
404
-            // qty, pu, remise_percent et txtva
405
-            // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
406
-            // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
407
-
408
-            $localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc);
409
-            $txtva = preg_replace('/\s*\(.*\)/','',$txtva);  // Remove code into vatrate.
410
-
411
-            $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx);
412
-            $total_ht  = $tabprice[0];
413
-            $total_tva = $tabprice[1];
414
-            $total_ttc = $tabprice[2];
415
-            $total_localtax1 = $tabprice[9];
416
-            $total_localtax2 = $tabprice[10];
361
+	 *    	@return    	int         	    			>0 if OK, <0 if KO
362
+	 *
363
+	 *    	@see       	add_product
364
+	 */
365
+	function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $pu_ttc=0, $info_bits=0, $type=0, $rang=-1, $special_code=0, $fk_parent_line=0, $fk_fournprice=0, $pa_ht=0, $label='',$array_option=0, $ref_fourn='', $fk_unit='', $origin='', $origin_id=0)
366
+	{
367
+		global $mysoc;
368
+
369
+		dol_syslog(get_class($this)."::addline supplier_proposalid=$this->id, desc=$desc, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, fk_product=$fk_product, remise_except=$remise_percent, price_base_type=$price_base_type, pu_ttc=$pu_ttc, info_bits=$info_bits, type=$type");
370
+		include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
371
+
372
+		// Clean parameters
373
+		if (empty($remise_percent)) $remise_percent=0;
374
+		if (empty($qty)) $qty=0;
375
+		if (empty($info_bits)) $info_bits=0;
376
+		if (empty($rang)) $rang=0;
377
+		if (empty($fk_parent_line) || $fk_parent_line < 0) $fk_parent_line=0;
378
+
379
+		$remise_percent=price2num($remise_percent);
380
+		$qty=price2num($qty);
381
+		$pu_ht=price2num($pu_ht);
382
+		$pu_ttc=price2num($pu_ttc);
383
+		$txtva=price2num($txtva);
384
+		$txlocaltax1=price2num($txlocaltax1);
385
+		$txlocaltax2=price2num($txlocaltax2);
386
+			$pa_ht=price2num($pa_ht);
387
+		if ($price_base_type=='HT')
388
+		{
389
+			$pu=$pu_ht;
390
+		}
391
+		else
392
+		{
393
+			$pu=$pu_ttc;
394
+		}
395
+
396
+		// Check parameters
397
+		if ($type < 0) return -1;
398
+
399
+		if ($this->statut == 0)
400
+		{
401
+			$this->db->begin();
402
+
403
+			// Calcul du total TTC et de la TVA pour la ligne a partir de
404
+			// qty, pu, remise_percent et txtva
405
+			// TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
406
+			// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
407
+
408
+			$localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc);
409
+			$txtva = preg_replace('/\s*\(.*\)/','',$txtva);  // Remove code into vatrate.
410
+
411
+			$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx);
412
+			$total_ht  = $tabprice[0];
413
+			$total_tva = $tabprice[1];
414
+			$total_ttc = $tabprice[2];
415
+			$total_localtax1 = $tabprice[9];
416
+			$total_localtax2 = $tabprice[10];
417 417
 
418 418
 			// MultiCurrency
419 419
 			$multicurrency_total_ht  = $tabprice[16];
420
-            $multicurrency_total_tva = $tabprice[17];
421
-            $multicurrency_total_ttc = $tabprice[18];
422
-
423
-            // Rang to use
424
-            $rangtouse = $rang;
425
-            if ($rangtouse == -1)
426
-            {
427
-                $rangmax = $this->line_max($fk_parent_line);
428
-                $rangtouse = $rangmax + 1;
429
-            }
430
-
431
-            // TODO A virer
432
-            // Anciens indicateurs: $price, $remise (a ne plus utiliser)
433
-            $price = $pu;
434
-            $remise = 0;
435
-            if ($remise_percent > 0)
436
-            {
437
-                $remise = round(($pu * $remise_percent / 100), 2);
438
-                $price = $pu - $remise;
439
-            }
440
-
441
-            // Insert line
442
-            $this->line=new SupplierProposalLine($this->db);
443
-
444
-            $this->line->fk_supplier_proposal=$this->id;
445
-            $this->line->label=$label;
446
-            $this->line->desc=$desc;
447
-            $this->line->qty=$qty;
448
-            $this->line->tva_tx=$txtva;
449
-            $this->line->localtax1_tx=$txlocaltax1;
450
-            $this->line->localtax2_tx=$txlocaltax2;
420
+			$multicurrency_total_tva = $tabprice[17];
421
+			$multicurrency_total_ttc = $tabprice[18];
422
+
423
+			// Rang to use
424
+			$rangtouse = $rang;
425
+			if ($rangtouse == -1)
426
+			{
427
+				$rangmax = $this->line_max($fk_parent_line);
428
+				$rangtouse = $rangmax + 1;
429
+			}
430
+
431
+			// TODO A virer
432
+			// Anciens indicateurs: $price, $remise (a ne plus utiliser)
433
+			$price = $pu;
434
+			$remise = 0;
435
+			if ($remise_percent > 0)
436
+			{
437
+				$remise = round(($pu * $remise_percent / 100), 2);
438
+				$price = $pu - $remise;
439
+			}
440
+
441
+			// Insert line
442
+			$this->line=new SupplierProposalLine($this->db);
443
+
444
+			$this->line->fk_supplier_proposal=$this->id;
445
+			$this->line->label=$label;
446
+			$this->line->desc=$desc;
447
+			$this->line->qty=$qty;
448
+			$this->line->tva_tx=$txtva;
449
+			$this->line->localtax1_tx=$txlocaltax1;
450
+			$this->line->localtax2_tx=$txlocaltax2;
451 451
 			$this->line->localtax1_type = $localtaxes_type[0];
452 452
 			$this->line->localtax2_type = $localtaxes_type[2];
453
-            $this->line->fk_product=$fk_product;
454
-            $this->line->remise_percent=$remise_percent;
455
-            $this->line->subprice=$pu_ht;
456
-            $this->line->rang=$rangtouse;
457
-            $this->line->info_bits=$info_bits;
458
-            $this->line->total_ht=$total_ht;
459
-            $this->line->total_tva=$total_tva;
460
-            $this->line->total_localtax1=$total_localtax1;
461
-            $this->line->total_localtax2=$total_localtax2;
462
-            $this->line->total_ttc=$total_ttc;
463
-            $this->line->product_type=$type;
464
-            $this->line->special_code=$special_code;
465
-            $this->line->fk_parent_line=$fk_parent_line;
466
-            $this->line->fk_unit=$fk_unit;
467
-            $this->line->origin=$origin;
468
-            $this->line->origin_id=$origin_id;
453
+			$this->line->fk_product=$fk_product;
454
+			$this->line->remise_percent=$remise_percent;
455
+			$this->line->subprice=$pu_ht;
456
+			$this->line->rang=$rangtouse;
457
+			$this->line->info_bits=$info_bits;
458
+			$this->line->total_ht=$total_ht;
459
+			$this->line->total_tva=$total_tva;
460
+			$this->line->total_localtax1=$total_localtax1;
461
+			$this->line->total_localtax2=$total_localtax2;
462
+			$this->line->total_ttc=$total_ttc;
463
+			$this->line->product_type=$type;
464
+			$this->line->special_code=$special_code;
465
+			$this->line->fk_parent_line=$fk_parent_line;
466
+			$this->line->fk_unit=$fk_unit;
467
+			$this->line->origin=$origin;
468
+			$this->line->origin_id=$origin_id;
469 469
 			$this->line->ref_fourn = $this->db->escape($ref_fourn);
470 470
 
471 471
 			// infos marge
472 472
 			if (!empty($fk_product) && empty($fk_fournprice) && empty($pa_ht)) {
473
-			    // by external module, take lowest buying price
474
-			    include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
475
-			    $productFournisseur = new ProductFournisseur($this->db);
476
-			    $productFournisseur->find_min_price_product_fournisseur($fk_product);
477
-			    $this->line->fk_fournprice = $productFournisseur->product_fourn_price_id;
473
+				// by external module, take lowest buying price
474
+				include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
475
+				$productFournisseur = new ProductFournisseur($this->db);
476
+				$productFournisseur->find_min_price_product_fournisseur($fk_product);
477
+				$this->line->fk_fournprice = $productFournisseur->product_fourn_price_id;
478 478
 			} else {
479
-			    $this->line->fk_fournprice = $fk_fournprice;
479
+				$this->line->fk_fournprice = $fk_fournprice;
480 480
 			}
481 481
 			$this->line->pa_ht = $pa_ht;
482 482
 
@@ -485,279 +485,279 @@  discard block
 block discarded – undo
485 485
 			$this->line->multicurrency_code			= $this->multicurrency_code;
486 486
 			$this->line->multicurrency_subprice		= price2num($pu_ht * $this->multicurrency_tx);
487 487
 			$this->line->multicurrency_total_ht 	= $multicurrency_total_ht;
488
-            $this->line->multicurrency_total_tva 	= $multicurrency_total_tva;
489
-            $this->line->multicurrency_total_ttc 	= $multicurrency_total_ttc;
490
-
491
-            // Mise en option de la ligne
492
-            if (empty($qty) && empty($special_code)) $this->line->special_code=3;
493
-
494
-            // TODO deprecated
495
-            $this->line->price=$price;
496
-            $this->line->remise=$remise;
497
-
498
-            if (is_array($array_option) && count($array_option)>0) {
499
-            	$this->line->array_options=$array_option;
500
-            }
501
-
502
-            $result=$this->line->insert();
503
-            if ($result > 0)
504
-            {
505
-                // Reorder if child line
506
-                if (! empty($fk_parent_line)) $this->line_order(true,'DESC');
507
-
508
-                // Mise a jour informations denormalisees au niveau de la propale meme
509
-                $result=$this->update_price(1,'auto',0,$this->thirdparty);	// This method is designed to add line from user input so total calculation must be done using 'auto' mode.
510
-                if ($result > 0)
511
-                {
512
-                    $this->db->commit();
513
-                    return $this->line->rowid;
514
-                }
515
-                else
516
-                {
517
-                    $this->error=$this->db->error();
518
-                    $this->db->rollback();
519
-                    return -1;
520
-                }
521
-            }
522
-            else
523
-            {
524
-                $this->error=$this->line->error;
525
-                $this->db->rollback();
526
-                return -2;
527
-            }
528
-        }
529
-    }
530
-
531
-
532
-    /**
533
-     *  Update a proposal line
534
-     *
535
-     *  @param      int			$rowid           	Id de la ligne
536
-     *  @param      double		$pu		     	  	Prix unitaire (HT ou TTC selon price_base_type)
537
-     *  @param      double		$qty            	Quantity
538
-     *  @param      double		$remise_percent  	Remise effectuee sur le produit
539
-     *  @param      double		$txtva	          	Taux de TVA
540
-     * 	@param	  	double		$txlocaltax1		Local tax 1 rate
541
-     *  @param	  	double		$txlocaltax2		Local tax 2 rate
542
-     *  @param      string		$desc            	Description
543
-     *	@param	  	double		$price_base_type	HT ou TTC
544
-     *	@param      int			$info_bits        	Miscellaneous informations
545
-     *	@param		int			$special_code		Special code (also used by externals modules!)
546
-     * 	@param		int			$fk_parent_line		Id of parent line (0 in most cases, used by modules adding sublevels into lines).
547
-     * 	@param		int			$skip_update_total	Keep fields total_xxx to 0 (used for special lines by some modules)
548
-     *  @param		int			$fk_fournprice		Id of origin supplier price
549
-     *  @param		int			$pa_ht				Price (without tax) of product when it was bought
550
-     *  @param		string		$label				???
551
-     *  @param		int			$type				0/1=Product/service
488
+			$this->line->multicurrency_total_tva 	= $multicurrency_total_tva;
489
+			$this->line->multicurrency_total_ttc 	= $multicurrency_total_ttc;
490
+
491
+			// Mise en option de la ligne
492
+			if (empty($qty) && empty($special_code)) $this->line->special_code=3;
493
+
494
+			// TODO deprecated
495
+			$this->line->price=$price;
496
+			$this->line->remise=$remise;
497
+
498
+			if (is_array($array_option) && count($array_option)>0) {
499
+				$this->line->array_options=$array_option;
500
+			}
501
+
502
+			$result=$this->line->insert();
503
+			if ($result > 0)
504
+			{
505
+				// Reorder if child line
506
+				if (! empty($fk_parent_line)) $this->line_order(true,'DESC');
507
+
508
+				// Mise a jour informations denormalisees au niveau de la propale meme
509
+				$result=$this->update_price(1,'auto',0,$this->thirdparty);	// This method is designed to add line from user input so total calculation must be done using 'auto' mode.
510
+				if ($result > 0)
511
+				{
512
+					$this->db->commit();
513
+					return $this->line->rowid;
514
+				}
515
+				else
516
+				{
517
+					$this->error=$this->db->error();
518
+					$this->db->rollback();
519
+					return -1;
520
+				}
521
+			}
522
+			else
523
+			{
524
+				$this->error=$this->line->error;
525
+				$this->db->rollback();
526
+				return -2;
527
+			}
528
+		}
529
+	}
530
+
531
+
532
+	/**
533
+	 *  Update a proposal line
534
+	 *
535
+	 *  @param      int			$rowid           	Id de la ligne
536
+	 *  @param      double		$pu		     	  	Prix unitaire (HT ou TTC selon price_base_type)
537
+	 *  @param      double		$qty            	Quantity
538
+	 *  @param      double		$remise_percent  	Remise effectuee sur le produit
539
+	 *  @param      double		$txtva	          	Taux de TVA
540
+	 * 	@param	  	double		$txlocaltax1		Local tax 1 rate
541
+	 *  @param	  	double		$txlocaltax2		Local tax 2 rate
542
+	 *  @param      string		$desc            	Description
543
+	 *	@param	  	double		$price_base_type	HT ou TTC
544
+	 *	@param      int			$info_bits        	Miscellaneous informations
545
+	 *	@param		int			$special_code		Special code (also used by externals modules!)
546
+	 * 	@param		int			$fk_parent_line		Id of parent line (0 in most cases, used by modules adding sublevels into lines).
547
+	 * 	@param		int			$skip_update_total	Keep fields total_xxx to 0 (used for special lines by some modules)
548
+	 *  @param		int			$fk_fournprice		Id of origin supplier price
549
+	 *  @param		int			$pa_ht				Price (without tax) of product when it was bought
550
+	 *  @param		string		$label				???
551
+	 *  @param		int			$type				0/1=Product/service
552 552
 	 *  @param		array		$array_option		extrafields array
553 553
 	 * 	@param		string		$ref_fourn			Supplier price reference
554 554
 	 *	@param		int			$fk_unit			Id of the unit to use.
555
-     *  @return     int     		        		0 if OK, <0 if KO
556
-     */
555
+	 *  @return     int     		        		0 if OK, <0 if KO
556
+	 */
557 557
 	function updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0, $txlocaltax2=0, $desc='', $price_base_type='HT', $info_bits=0, $special_code=0, $fk_parent_line=0, $skip_update_total=0, $fk_fournprice=0, $pa_ht=0, $label='', $type=0, $array_option=0, $ref_fourn='', $fk_unit='')
558
-    {
559
-        global $conf,$user,$langs, $mysoc;
560
-
561
-        dol_syslog(get_class($this)."::updateLine $rowid, $pu, $qty, $remise_percent, $txtva, $desc, $price_base_type, $info_bits");
562
-        include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
563
-
564
-        // Clean parameters
565
-        $remise_percent=price2num($remise_percent);
566
-        $qty=price2num($qty);
567
-        $pu = price2num($pu);
568
-        $txtva = price2num($txtva);
569
-        $txlocaltax1=price2num($txlocaltax1);
570
-        $txlocaltax2=price2num($txlocaltax2);
571
-    	$pa_ht=price2num($pa_ht);
572
-        if (empty($qty) && empty($special_code)) $special_code=3;    // Set option tag
573
-        if (! empty($qty) && $special_code == 3) $special_code=0;    // Remove option tag
574
-
575
-        if ($this->statut == 0)
576
-        {
577
-            $this->db->begin();
578
-
579
-            // Calcul du total TTC et de la TVA pour la ligne a partir de
580
-            // qty, pu, remise_percent et txtva
581
-            // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
582
-            // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
583
-
584
-            $localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc);
585
-            $txtva = preg_replace('/\s*\(.*\)/','',$txtva);  // Remove code into vatrate.
586
-
587
-            $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx);
588
-            $total_ht  = $tabprice[0];
589
-            $total_tva = $tabprice[1];
590
-            $total_ttc = $tabprice[2];
591
-            $total_localtax1 = $tabprice[9];
592
-            $total_localtax2 = $tabprice[10];
558
+	{
559
+		global $conf,$user,$langs, $mysoc;
560
+
561
+		dol_syslog(get_class($this)."::updateLine $rowid, $pu, $qty, $remise_percent, $txtva, $desc, $price_base_type, $info_bits");
562
+		include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
563
+
564
+		// Clean parameters
565
+		$remise_percent=price2num($remise_percent);
566
+		$qty=price2num($qty);
567
+		$pu = price2num($pu);
568
+		$txtva = price2num($txtva);
569
+		$txlocaltax1=price2num($txlocaltax1);
570
+		$txlocaltax2=price2num($txlocaltax2);
571
+		$pa_ht=price2num($pa_ht);
572
+		if (empty($qty) && empty($special_code)) $special_code=3;    // Set option tag
573
+		if (! empty($qty) && $special_code == 3) $special_code=0;    // Remove option tag
574
+
575
+		if ($this->statut == 0)
576
+		{
577
+			$this->db->begin();
578
+
579
+			// Calcul du total TTC et de la TVA pour la ligne a partir de
580
+			// qty, pu, remise_percent et txtva
581
+			// TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
582
+			// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
583
+
584
+			$localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc);
585
+			$txtva = preg_replace('/\s*\(.*\)/','',$txtva);  // Remove code into vatrate.
586
+
587
+			$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx);
588
+			$total_ht  = $tabprice[0];
589
+			$total_tva = $tabprice[1];
590
+			$total_ttc = $tabprice[2];
591
+			$total_localtax1 = $tabprice[9];
592
+			$total_localtax2 = $tabprice[10];
593 593
 
594 594
 			// MultiCurrency
595 595
 			$multicurrency_total_ht  = $tabprice[16];
596
-            $multicurrency_total_tva = $tabprice[17];
597
-            $multicurrency_total_ttc = $tabprice[18];
598
-
599
-            // Anciens indicateurs: $price, $remise (a ne plus utiliser)
600
-            $price = $pu;
601
-            if ($remise_percent > 0)
602
-            {
603
-                $remise = round(($pu * $remise_percent / 100), 2);
604
-                $price = $pu - $remise;
605
-            }
606
-
607
-            // Update line
608
-            $this->line=new SupplierProposalLine($this->db);
609
-
610
-            // Stock previous line records
611
-            $staticline=new SupplierProposalLine($this->db);
612
-            $staticline->fetch($rowid);
613
-            $this->line->oldline = $staticline;
614
-
615
-            // Reorder if fk_parent_line change
616
-            if (! empty($fk_parent_line) && ! empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line)
617
-            {
618
-                $rangmax = $this->line_max($fk_parent_line);
619
-                $this->line->rang = $rangmax + 1;
620
-            }
621
-
622
-            $this->line->rowid				= $rowid;
623
-            $this->line->label				= $label;
624
-            $this->line->desc				= $desc;
625
-            $this->line->qty				= $qty;
626
-            $this->line->product_type			= $type;
627
-            $this->line->tva_tx				= $txtva;
628
-            $this->line->localtax1_tx		= $txlocaltax1;
629
-            $this->line->localtax2_tx		= $txlocaltax2;
596
+			$multicurrency_total_tva = $tabprice[17];
597
+			$multicurrency_total_ttc = $tabprice[18];
598
+
599
+			// Anciens indicateurs: $price, $remise (a ne plus utiliser)
600
+			$price = $pu;
601
+			if ($remise_percent > 0)
602
+			{
603
+				$remise = round(($pu * $remise_percent / 100), 2);
604
+				$price = $pu - $remise;
605
+			}
606
+
607
+			// Update line
608
+			$this->line=new SupplierProposalLine($this->db);
609
+
610
+			// Stock previous line records
611
+			$staticline=new SupplierProposalLine($this->db);
612
+			$staticline->fetch($rowid);
613
+			$this->line->oldline = $staticline;
614
+
615
+			// Reorder if fk_parent_line change
616
+			if (! empty($fk_parent_line) && ! empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line)
617
+			{
618
+				$rangmax = $this->line_max($fk_parent_line);
619
+				$this->line->rang = $rangmax + 1;
620
+			}
621
+
622
+			$this->line->rowid				= $rowid;
623
+			$this->line->label				= $label;
624
+			$this->line->desc				= $desc;
625
+			$this->line->qty				= $qty;
626
+			$this->line->product_type			= $type;
627
+			$this->line->tva_tx				= $txtva;
628
+			$this->line->localtax1_tx		= $txlocaltax1;
629
+			$this->line->localtax2_tx		= $txlocaltax2;
630 630
 			$this->line->localtax1_type		= $localtaxes_type[0];
631 631
 			$this->line->localtax2_type		= $localtaxes_type[2];
632
-            $this->line->remise_percent		= $remise_percent;
633
-            $this->line->subprice			= $pu;
634
-            $this->line->info_bits			= $info_bits;
635
-            $this->line->total_ht			= $total_ht;
636
-            $this->line->total_tva			= $total_tva;
637
-            $this->line->total_localtax1	= $total_localtax1;
638
-            $this->line->total_localtax2	= $total_localtax2;
639
-            $this->line->total_ttc			= $total_ttc;
640
-            $this->line->special_code		= $special_code;
641
-            $this->line->fk_parent_line		= $fk_parent_line;
642
-            $this->line->skip_update_total	= $skip_update_total;
643
-            $this->line->ref_fourn			= $ref_fourn;
632
+			$this->line->remise_percent		= $remise_percent;
633
+			$this->line->subprice			= $pu;
634
+			$this->line->info_bits			= $info_bits;
635
+			$this->line->total_ht			= $total_ht;
636
+			$this->line->total_tva			= $total_tva;
637
+			$this->line->total_localtax1	= $total_localtax1;
638
+			$this->line->total_localtax2	= $total_localtax2;
639
+			$this->line->total_ttc			= $total_ttc;
640
+			$this->line->special_code		= $special_code;
641
+			$this->line->fk_parent_line		= $fk_parent_line;
642
+			$this->line->skip_update_total	= $skip_update_total;
643
+			$this->line->ref_fourn			= $ref_fourn;
644 644
 			$this->line->fk_unit			= $fk_unit;
645 645
 
646
-            // infos marge
647
-            if (!empty($fk_product) && empty($fk_fournprice) && empty($pa_ht)) {
648
-                // by external module, take lowest buying price
649
-                include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
650
-			    $productFournisseur = new ProductFournisseur($this->db);
651
-			    $productFournisseur->find_min_price_product_fournisseur($fk_product);
652
-			    $this->line->fk_fournprice = $productFournisseur->product_fourn_price_id;
646
+			// infos marge
647
+			if (!empty($fk_product) && empty($fk_fournprice) && empty($pa_ht)) {
648
+				// by external module, take lowest buying price
649
+				include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
650
+				$productFournisseur = new ProductFournisseur($this->db);
651
+				$productFournisseur->find_min_price_product_fournisseur($fk_product);
652
+				$this->line->fk_fournprice = $productFournisseur->product_fourn_price_id;
653 653
 			} else {
654
-			    $this->line->fk_fournprice = $fk_fournprice;
654
+				$this->line->fk_fournprice = $fk_fournprice;
655 655
 			}
656
-            $this->line->pa_ht = $pa_ht;
656
+			$this->line->pa_ht = $pa_ht;
657 657
 
658
-            // TODO deprecated
659
-            $this->line->price=$price;
660
-            $this->line->remise=$remise;
658
+			// TODO deprecated
659
+			$this->line->price=$price;
660
+			$this->line->remise=$remise;
661 661
 
662
-            if (is_array($array_option) && count($array_option)>0) {
663
-            	$this->line->array_options=$array_option;
664
-            }
662
+			if (is_array($array_option) && count($array_option)>0) {
663
+				$this->line->array_options=$array_option;
664
+			}
665 665
 
666 666
 			// Multicurrency
667 667
 			$this->line->multicurrency_subprice		= price2num($pu * $this->multicurrency_tx);
668 668
 			$this->line->multicurrency_total_ht 	= $multicurrency_total_ht;
669
-            $this->line->multicurrency_total_tva 	= $multicurrency_total_tva;
670
-            $this->line->multicurrency_total_ttc 	= $multicurrency_total_ttc;
671
-
672
-            $result=$this->line->update();
673
-            if ($result > 0)
674
-            {
675
-                // Reorder if child line
676
-                if (! empty($fk_parent_line)) $this->line_order(true,'DESC');
677
-
678
-                $this->update_price(1);
679
-
680
-                $this->fk_supplier_proposal = $this->id;
681
-                $this->rowid = $rowid;
682
-
683
-                $this->db->commit();
684
-                return $result;
685
-            }
686
-            else
687
-            {
688
-                $this->error=$this->db->error();
689
-                $this->db->rollback();
690
-                return -1;
691
-            }
692
-        }
693
-        else
694
-        {
695
-            dol_syslog(get_class($this)."::updateline Erreur -2 SupplierProposal en mode incompatible pour cette action");
696
-            return -2;
697
-        }
698
-    }
699
-
700
-
701
-    /**
702
-     *  Delete detail line
703
-     *
704
-     *  @param		int		$lineid			Id of line to delete
705
-     *  @return     int         			>0 if OK, <0 if KO
706
-     */
707
-    function deleteline($lineid)
708
-    {
709
-        if ($this->statut == 0)
710
-        {
711
-            $line=new SupplierProposalLine($this->db);
712
-
713
-            // For triggers
714
-            $line->fetch($lineid);
715
-
716
-            if ($line->delete() > 0)
717
-            {
718
-                $this->update_price(1);
719
-
720
-                return 1;
721
-            }
722
-            else
723
-            {
724
-                return -1;
725
-            }
726
-        }
727
-        else
728
-        {
729
-            return -2;
730
-        }
731
-    }
732
-
733
-
734
-    /**
735
-     *  Create commercial proposal into database
736
-     * 	this->ref can be set or empty. If empty, we will use "(PROVid)"
737
-     *
738
-     * 	@param		User	$user		User that create
739
-     * 	@param		int		$notrigger	1=Does not execute triggers, 0= execute triggers
740
-     *  @return     int     			<0 if KO, >=0 if OK
741
-     */
742
-    function create($user, $notrigger=0)
743
-    {
744
-        global $langs,$conf,$mysoc,$hookmanager;
745
-        $error=0;
746
-
747
-        $now=dol_now();
748
-
749
-        dol_syslog(get_class($this)."::create");
750
-
751
-        // Check parameters
752
-        $result=$this->fetch_thirdparty();
753
-        if ($result < 0)
754
-        {
755
-            $this->error="Failed to fetch company";
756
-            dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
757
-            return -3;
758
-        }
759
-
760
-        // Check parameters
669
+			$this->line->multicurrency_total_tva 	= $multicurrency_total_tva;
670
+			$this->line->multicurrency_total_ttc 	= $multicurrency_total_ttc;
671
+
672
+			$result=$this->line->update();
673
+			if ($result > 0)
674
+			{
675
+				// Reorder if child line
676
+				if (! empty($fk_parent_line)) $this->line_order(true,'DESC');
677
+
678
+				$this->update_price(1);
679
+
680
+				$this->fk_supplier_proposal = $this->id;
681
+				$this->rowid = $rowid;
682
+
683
+				$this->db->commit();
684
+				return $result;
685
+			}
686
+			else
687
+			{
688
+				$this->error=$this->db->error();
689
+				$this->db->rollback();
690
+				return -1;
691
+			}
692
+		}
693
+		else
694
+		{
695
+			dol_syslog(get_class($this)."::updateline Erreur -2 SupplierProposal en mode incompatible pour cette action");
696
+			return -2;
697
+		}
698
+	}
699
+
700
+
701
+	/**
702
+	 *  Delete detail line
703
+	 *
704
+	 *  @param		int		$lineid			Id of line to delete
705
+	 *  @return     int         			>0 if OK, <0 if KO
706
+	 */
707
+	function deleteline($lineid)
708
+	{
709
+		if ($this->statut == 0)
710
+		{
711
+			$line=new SupplierProposalLine($this->db);
712
+
713
+			// For triggers
714
+			$line->fetch($lineid);
715
+
716
+			if ($line->delete() > 0)
717
+			{
718
+				$this->update_price(1);
719
+
720
+				return 1;
721
+			}
722
+			else
723
+			{
724
+				return -1;
725
+			}
726
+		}
727
+		else
728
+		{
729
+			return -2;
730
+		}
731
+	}
732
+
733
+
734
+	/**
735
+	 *  Create commercial proposal into database
736
+	 * 	this->ref can be set or empty. If empty, we will use "(PROVid)"
737
+	 *
738
+	 * 	@param		User	$user		User that create
739
+	 * 	@param		int		$notrigger	1=Does not execute triggers, 0= execute triggers
740
+	 *  @return     int     			<0 if KO, >=0 if OK
741
+	 */
742
+	function create($user, $notrigger=0)
743
+	{
744
+		global $langs,$conf,$mysoc,$hookmanager;
745
+		$error=0;
746
+
747
+		$now=dol_now();
748
+
749
+		dol_syslog(get_class($this)."::create");
750
+
751
+		// Check parameters
752
+		$result=$this->fetch_thirdparty();
753
+		if ($result < 0)
754
+		{
755
+			$this->error="Failed to fetch company";
756
+			dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
757
+			return -3;
758
+		}
759
+
760
+		// Check parameters
761 761
 		if (! empty($this->ref))	// We check that ref is not already used
762 762
 		{
763 763
 			$result=self::isExistingObject($this->element, 0, $this->ref);	// Check ref is not yet used
@@ -779,89 +779,89 @@  discard block
 block discarded – undo
779 779
 			$this->multicurrency_tx = 1;
780 780
 		}
781 781
 
782
-        $this->db->begin();
783
-
784
-        // Insert into database
785
-        $sql = "INSERT INTO ".MAIN_DB_PREFIX."supplier_proposal (";
786
-        $sql.= "fk_soc";
787
-        $sql.= ", price";
788
-        $sql.= ", remise";
789
-        $sql.= ", remise_percent";
790
-        $sql.= ", remise_absolue";
791
-        $sql.= ", tva";
792
-        $sql.= ", total";
793
-        $sql.= ", datec";
794
-        $sql.= ", ref";
795
-        $sql.= ", fk_user_author";
796
-        $sql.= ", note_private";
797
-        $sql.= ", note_public";
798
-        $sql.= ", model_pdf";
799
-        $sql.= ", fk_cond_reglement";
800
-        $sql.= ", fk_mode_reglement";
801
-        $sql.= ", fk_account";
802
-        $sql.= ", date_livraison";
803
-        $sql.= ", fk_shipping_method";
804
-        $sql.= ", fk_projet";
805
-        $sql.= ", entity";
806
-        $sql.= ", fk_multicurrency";
807
-        $sql.= ", multicurrency_code";
808
-        $sql.= ", multicurrency_tx";
809
-        $sql.= ") ";
810
-        $sql.= " VALUES (";
811
-        $sql.= $this->socid;
812
-        $sql.= ", 0";
813
-        $sql.= ", ".$this->remise;
814
-        $sql.= ", ".($this->remise_percent?$this->db->escape($this->remise_percent):'null');
815
-        $sql.= ", ".($this->remise_absolue?$this->db->escape($this->remise_absolue):'null');
816
-        $sql.= ", 0";
817
-        $sql.= ", 0";
818
-        $sql.= ", '".$this->db->idate($now)."'";
819
-        $sql.= ", '(PROV)'";
820
-        $sql.= ", ".($user->id > 0 ? "'".$user->id."'":"null");
821
-        $sql.= ", '".$this->db->escape($this->note_private)."'";
822
-        $sql.= ", '".$this->db->escape($this->note_public)."'";
823
-        $sql.= ", '".$this->db->escape($this->modelpdf)."'";
824
-        $sql.= ", ".$this->cond_reglement_id;
825
-        $sql.= ", ".$this->mode_reglement_id;
826
-        $sql.= ", ".($this->fk_account>0?$this->fk_account:'NULL');
827
-        $sql.= ", ".($this->date_livraison!=''?"'".$this->db->idate($this->date_livraison)."'":"null");
828
-        $sql.= ", ".($this->shipping_method_id>0?$this->shipping_method_id:'NULL');
829
-        $sql.= ", ".($this->fk_project?$this->fk_project:"null");
830
-        $sql.= ", ".$conf->entity;
782
+		$this->db->begin();
783
+
784
+		// Insert into database
785
+		$sql = "INSERT INTO ".MAIN_DB_PREFIX."supplier_proposal (";
786
+		$sql.= "fk_soc";
787
+		$sql.= ", price";
788
+		$sql.= ", remise";
789
+		$sql.= ", remise_percent";
790
+		$sql.= ", remise_absolue";
791
+		$sql.= ", tva";
792
+		$sql.= ", total";
793
+		$sql.= ", datec";
794
+		$sql.= ", ref";
795
+		$sql.= ", fk_user_author";
796
+		$sql.= ", note_private";
797
+		$sql.= ", note_public";
798
+		$sql.= ", model_pdf";
799
+		$sql.= ", fk_cond_reglement";
800
+		$sql.= ", fk_mode_reglement";
801
+		$sql.= ", fk_account";
802
+		$sql.= ", date_livraison";
803
+		$sql.= ", fk_shipping_method";
804
+		$sql.= ", fk_projet";
805
+		$sql.= ", entity";
806
+		$sql.= ", fk_multicurrency";
807
+		$sql.= ", multicurrency_code";
808
+		$sql.= ", multicurrency_tx";
809
+		$sql.= ") ";
810
+		$sql.= " VALUES (";
811
+		$sql.= $this->socid;
812
+		$sql.= ", 0";
813
+		$sql.= ", ".$this->remise;
814
+		$sql.= ", ".($this->remise_percent?$this->db->escape($this->remise_percent):'null');
815
+		$sql.= ", ".($this->remise_absolue?$this->db->escape($this->remise_absolue):'null');
816
+		$sql.= ", 0";
817
+		$sql.= ", 0";
818
+		$sql.= ", '".$this->db->idate($now)."'";
819
+		$sql.= ", '(PROV)'";
820
+		$sql.= ", ".($user->id > 0 ? "'".$user->id."'":"null");
821
+		$sql.= ", '".$this->db->escape($this->note_private)."'";
822
+		$sql.= ", '".$this->db->escape($this->note_public)."'";
823
+		$sql.= ", '".$this->db->escape($this->modelpdf)."'";
824
+		$sql.= ", ".$this->cond_reglement_id;
825
+		$sql.= ", ".$this->mode_reglement_id;
826
+		$sql.= ", ".($this->fk_account>0?$this->fk_account:'NULL');
827
+		$sql.= ", ".($this->date_livraison!=''?"'".$this->db->idate($this->date_livraison)."'":"null");
828
+		$sql.= ", ".($this->shipping_method_id>0?$this->shipping_method_id:'NULL');
829
+		$sql.= ", ".($this->fk_project?$this->fk_project:"null");
830
+		$sql.= ", ".$conf->entity;
831 831
 		$sql.= ", ".(int) $this->fk_multicurrency;
832 832
 		$sql.= ", '".$this->db->escape($this->multicurrency_code)."'";
833 833
 		$sql.= ", ".(double) $this->multicurrency_tx;
834
-        $sql.= ")";
834
+		$sql.= ")";
835 835
 
836
-        dol_syslog(get_class($this)."::create", LOG_DEBUG);
837
-        $resql=$this->db->query($sql);
838
-        if ($resql)
839
-        {
840
-            $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."supplier_proposal");
836
+		dol_syslog(get_class($this)."::create", LOG_DEBUG);
837
+		$resql=$this->db->query($sql);
838
+		if ($resql)
839
+		{
840
+			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."supplier_proposal");
841 841
 
842
-            if ($this->id)
843
-            {
844
-                $this->ref='(PROV'.$this->id.')';
845
-                $sql = 'UPDATE '.MAIN_DB_PREFIX."supplier_proposal SET ref='".$this->db->escape($this->ref)."' WHERE rowid=".$this->id;
842
+			if ($this->id)
843
+			{
844
+				$this->ref='(PROV'.$this->id.')';
845
+				$sql = 'UPDATE '.MAIN_DB_PREFIX."supplier_proposal SET ref='".$this->db->escape($this->ref)."' WHERE rowid=".$this->id;
846 846
 
847
-                dol_syslog(get_class($this)."::create", LOG_DEBUG);
848
-                $resql=$this->db->query($sql);
849
-                if (! $resql) $error++;
847
+				dol_syslog(get_class($this)."::create", LOG_DEBUG);
848
+				$resql=$this->db->query($sql);
849
+				if (! $resql) $error++;
850 850
 
851
-                /*
851
+				/*
852 852
                  *  Insertion du detail des produits dans la base
853 853
                 */
854
-                if (! $error)
855
-                {
856
-                    $fk_parent_line=0;
857
-                    $num=count($this->lines);
858
-
859
-                    for ($i=0;$i<$num;$i++)
860
-                    {
861
-                        // Reset fk_parent_line for no child products and special product
862
-                        if (($this->lines[$i]->product_type != 9 && empty($this->lines[$i]->fk_parent_line)) || $this->lines[$i]->product_type == 9) {
863
-                            $fk_parent_line = 0;
864
-                        }
854
+				if (! $error)
855
+				{
856
+					$fk_parent_line=0;
857
+					$num=count($this->lines);
858
+
859
+					for ($i=0;$i<$num;$i++)
860
+					{
861
+						// Reset fk_parent_line for no child products and special product
862
+						if (($this->lines[$i]->product_type != 9 && empty($this->lines[$i]->fk_parent_line)) || $this->lines[$i]->product_type == 9) {
863
+							$fk_parent_line = 0;
864
+						}
865 865
 
866 866
 						$result = $this->addline(
867 867
 							$this->lines[$i]->desc,
@@ -889,122 +889,122 @@  discard block
 block discarded – undo
889 889
 							$this->lines[$i]->rowid
890 890
 						);
891 891
 
892
-                        if ($result < 0)
893
-                        {
894
-                            $error++;
895
-                            $this->error=$this->db->error;
896
-                            dol_print_error($this->db);
897
-                            break;
898
-                        }
899
-                        // Defined the new fk_parent_line
900
-                        if ($result > 0 && $this->lines[$i]->product_type == 9) {
901
-                            $fk_parent_line = $result;
902
-                        }
903
-                    }
904
-                }
905
-
906
-                // Add linked object
907
-                if (! $error && $this->origin && $this->origin_id)
908
-                {
909
-                    $ret = $this->add_object_linked();
910
-                    if (! $ret)	dol_print_error($this->db);
911
-                }
912
-
913
-                if (! $error)
914
-                {
915
-                    // Mise a jour infos denormalisees
916
-                    $resql=$this->update_price(1);
917
-                    if ($resql)
918
-                    {
919
-                    	$action='update';
920
-
921
-                    	// Actions on extra fields (by external module or standard code)
922
-                    	$hookmanager->initHooks(array('supplier_proposaldao'));
923
-                    	$parameters=array('socid'=>$this->id);
924
-                    	$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
925
-                    	if (empty($reshook))
926
-                    	{
927
-                    		if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
928
-                    		{
929
-                    			$result=$this->insertExtraFields();
930
-                    			if ($result < 0)
931
-                    			{
932
-                    				$error++;
933
-                    			}
934
-                    		}
935
-                    	}
936
-                    	else if ($reshook < 0) $error++;
937
-
938
-                        if (! $notrigger)
939
-                        {
940
-                            // Call trigger
941
-                            $result=$this->call_trigger('PROPAL_SUPPLIER_CREATE',$user);
942
-                            if ($result < 0) { $error++; }
943
-                            // End call triggers
944
-                        }
945
-                    }
946
-                    else
892
+						if ($result < 0)
893
+						{
894
+							$error++;
895
+							$this->error=$this->db->error;
896
+							dol_print_error($this->db);
897
+							break;
898
+						}
899
+						// Defined the new fk_parent_line
900
+						if ($result > 0 && $this->lines[$i]->product_type == 9) {
901
+							$fk_parent_line = $result;
902
+						}
903
+					}
904
+				}
905
+
906
+				// Add linked object
907
+				if (! $error && $this->origin && $this->origin_id)
908
+				{
909
+					$ret = $this->add_object_linked();
910
+					if (! $ret)	dol_print_error($this->db);
911
+				}
912
+
913
+				if (! $error)
914
+				{
915
+					// Mise a jour infos denormalisees
916
+					$resql=$this->update_price(1);
917
+					if ($resql)
918
+					{
919
+						$action='update';
920
+
921
+						// Actions on extra fields (by external module or standard code)
922
+						$hookmanager->initHooks(array('supplier_proposaldao'));
923
+						$parameters=array('socid'=>$this->id);
924
+						$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
925
+						if (empty($reshook))
926
+						{
927
+							if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
928
+							{
929
+								$result=$this->insertExtraFields();
930
+								if ($result < 0)
931
+								{
932
+									$error++;
933
+								}
934
+							}
935
+						}
936
+						else if ($reshook < 0) $error++;
937
+
938
+						if (! $notrigger)
939
+						{
940
+							// Call trigger
941
+							$result=$this->call_trigger('PROPAL_SUPPLIER_CREATE',$user);
942
+							if ($result < 0) { $error++; }
943
+							// End call triggers
944
+						}
945
+					}
946
+					else
947 947
 					{
948
-                        $this->error=$this->db->lasterror();
949
-                        $error++;
950
-                    }
951
-                }
952
-            }
953
-            else
954
-			{
955
-                $this->error=$this->db->lasterror();
956
-                $error++;
957
-            }
958
-
959
-            if (! $error)
960
-            {
961
-                $this->db->commit();
962
-                dol_syslog(get_class($this)."::create done id=".$this->id);
963
-                return $this->id;
964
-            }
965
-            else
966
-            {
967
-                $this->db->rollback();
968
-                return -2;
969
-            }
970
-        }
971
-        else
972
-        {
973
-            $this->error=$this->db->lasterror();
974
-            $this->db->rollback();
975
-            return -1;
976
-        }
977
-    }
978
-
979
-
980
-    /**
981
-     *	Insert into DB a supplier_proposal object completely defined by its data members (ex, results from copy).
982
-     *
983
-     *	@param 		User	$user	User that create
984
-     *	@return    	int				Id of the new object if ok, <0 if ko
985
-     *	@see       	create
986
-     */
987
-    function create_from($user)
988
-    {
989
-        $this->products=$this->lines;
990
-
991
-        return $this->create($user);
992
-    }
993
-
994
-    /**
995
-     *		Load an object from its id and create a new one in database
996
-     *
997
-     *		@param		int				$socid			Id of thirdparty
998
-     * 	 	@return		int								New id of clone
999
-     */
1000
-    function createFromClone($socid=0)
1001
-    {
1002
-        global $user,$langs,$conf,$hookmanager;
1003
-
1004
-        $error=0;
1005
-        $now=dol_now();
1006
-
1007
-        $this->db->begin();
948
+						$this->error=$this->db->lasterror();
949
+						$error++;
950
+					}
951
+				}
952
+			}
953
+			else
954
+			{
955
+				$this->error=$this->db->lasterror();
956
+				$error++;
957
+			}
958
+
959
+			if (! $error)
960
+			{
961
+				$this->db->commit();
962
+				dol_syslog(get_class($this)."::create done id=".$this->id);
963
+				return $this->id;
964
+			}
965
+			else
966
+			{
967
+				$this->db->rollback();
968
+				return -2;
969
+			}
970
+		}
971
+		else
972
+		{
973
+			$this->error=$this->db->lasterror();
974
+			$this->db->rollback();
975
+			return -1;
976
+		}
977
+	}
978
+
979
+
980
+	/**
981
+	 *	Insert into DB a supplier_proposal object completely defined by its data members (ex, results from copy).
982
+	 *
983
+	 *	@param 		User	$user	User that create
984
+	 *	@return    	int				Id of the new object if ok, <0 if ko
985
+	 *	@see       	create
986
+	 */
987
+	function create_from($user)
988
+	{
989
+		$this->products=$this->lines;
990
+
991
+		return $this->create($user);
992
+	}
993
+
994
+	/**
995
+	 *		Load an object from its id and create a new one in database
996
+	 *
997
+	 *		@param		int				$socid			Id of thirdparty
998
+	 * 	 	@return		int								New id of clone
999
+	 */
1000
+	function createFromClone($socid=0)
1001
+	{
1002
+		global $user,$langs,$conf,$hookmanager;
1003
+
1004
+		$error=0;
1005
+		$now=dol_now();
1006
+
1007
+		$this->db->begin();
1008 1008
 
1009 1009
 		// get extrafields so they will be clone
1010 1010
 		foreach($this->lines as $line)
@@ -1013,258 +1013,258 @@  discard block
 block discarded – undo
1013 1013
 		// Load source object
1014 1014
 		$objFrom = clone $this;
1015 1015
 
1016
-        $objsoc=new Societe($this->db);
1017
-
1018
-        // Change socid if needed
1019
-        if (! empty($socid) && $socid != $this->socid)
1020
-        {
1021
-            if ($objsoc->fetch($socid) > 0)
1022
-            {
1023
-                $this->socid 				= $objsoc->id;
1024
-                $this->cond_reglement_id	= (! empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1025
-                $this->mode_reglement_id	= (! empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1026
-                $this->fk_project			= '';
1027
-            }
1028
-
1029
-            // TODO Change product price if multi-prices
1030
-        }
1031
-        else
1032
-        {
1033
-            $objsoc->fetch($this->socid);
1034
-        }
1035
-
1036
-        $this->id=0;
1037
-        $this->statut=0;
1038
-
1039
-        if (empty($conf->global->SUPPLIER_PROPOSAL_ADDON) || ! is_readable(DOL_DOCUMENT_ROOT ."/core/modules/supplier_proposal/".$conf->global->SUPPLIER_PROPOSAL_ADDON.".php"))
1040
-        {
1041
-            $this->error='ErrorSetupNotComplete';
1042
-            return -1;
1043
-        }
1044
-
1045
-        // Clear fields
1046
-        $this->user_author	= $user->id;
1047
-        $this->user_valid	= '';
1048
-        $this->date			= $now;
1049
-
1050
-        // Set ref
1051
-        require_once DOL_DOCUMENT_ROOT ."/core/modules/supplier_proposal/".$conf->global->SUPPLIER_PROPOSAL_ADDON.'.php';
1052
-        $obj = $conf->global->SUPPLIER_PROPOSAL_ADDON;
1053
-        $modSupplierProposal = new $obj;
1054
-        $this->ref = $modSupplierProposal->getNextValue($objsoc,$this);
1055
-
1056
-        // Create clone
1057
-        $result=$this->create($user);
1058
-        if ($result < 0) $error++;
1059
-
1060
-        if (! $error)
1061
-        {
1062
-            // Hook of thirdparty module
1063
-            if (is_object($hookmanager))
1064
-            {
1065
-                $parameters=array('objFrom'=>$objFrom);
1066
-                $action='';
1067
-                $reshook=$hookmanager->executeHooks('createFrom',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
1068
-                if ($reshook < 0) $error++;
1069
-            }
1070
-
1071
-            // Call trigger
1072
-            $result=$this->call_trigger('SUPPLIER_PROPOSAL_CLONE',$user);
1073
-            if ($result < 0) { $error++; }
1074
-            // End call triggers
1075
-        }
1076
-
1077
-        // End
1078
-        if (! $error)
1079
-        {
1080
-            $this->db->commit();
1081
-            return $this->id;
1082
-        }
1083
-        else
1084
-        {
1085
-            $this->db->rollback();
1086
-            return -1;
1087
-        }
1088
-    }
1089
-
1090
-    /**
1091
-     *	Load a proposal from database and its ligne array
1092
-     *
1093
-     *	@param      int			$rowid		id of object to load
1094
-     *	@param		string		$ref		Ref of proposal
1095
-     *	@return     int         			>0 if OK, <0 if KO
1096
-     */
1097
-    function fetch($rowid,$ref='')
1098
-    {
1099
-        global $conf;
1100
-
1101
-        $sql = "SELECT p.rowid, p.ref, p.remise, p.remise_percent, p.remise_absolue, p.fk_soc";
1102
-        $sql.= ", p.total, p.tva, p.localtax1, p.localtax2, p.total_ht";
1103
-        $sql.= ", p.datec";
1104
-        $sql.= ", p.date_valid as datev";
1105
-        $sql.= ", p.date_livraison as date_livraison";
1106
-        $sql.= ", p.model_pdf, p.extraparams";
1107
-        $sql.= ", p.note_private, p.note_public";
1108
-        $sql.= ", p.fk_projet, p.fk_statut";
1109
-        $sql.= ", p.fk_user_author, p.fk_user_valid, p.fk_user_cloture";
1110
-        $sql.= ", p.fk_cond_reglement";
1111
-        $sql.= ", p.fk_mode_reglement";
1112
-        $sql.= ', p.fk_account';
1113
-        $sql.= ", p.fk_shipping_method";
1114
-		$sql.= ", p.fk_multicurrency, p.multicurrency_code, p.multicurrency_tx, p.multicurrency_total_ht, p.multicurrency_total_tva, p.multicurrency_total_ttc";
1115
-        $sql.= ", c.label as statut_label";
1116
-        $sql.= ", cr.code as cond_reglement_code, cr.libelle as cond_reglement, cr.libelle_facture as cond_reglement_libelle_doc";
1117
-        $sql.= ", cp.code as mode_reglement_code, cp.libelle as mode_reglement";
1118
-        $sql.= " FROM ".MAIN_DB_PREFIX."c_propalst as c, ".MAIN_DB_PREFIX."supplier_proposal as p";
1119
-        $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_mode_reglement = cp.id AND cp.entity IN (' . getEntity('c_paiement').')';
1120
-        $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON p.fk_cond_reglement = cr.rowid AND cr.entity IN (' . getEntity('c_payment_term').')';
1121
-        $sql.= " WHERE p.fk_statut = c.id";
1122
-        $sql.= " AND p.entity = ".$conf->entity;
1123
-        if ($ref) $sql.= " AND p.ref='".$ref."'";
1124
-        else $sql.= " AND p.rowid=".$rowid;
1125
-
1126
-        dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
1127
-        $resql=$this->db->query($sql);
1128
-        if ($resql)
1129
-        {
1130
-            if ($this->db->num_rows($resql))
1131
-            {
1132
-                $obj = $this->db->fetch_object($resql);
1133
-
1134
-                $this->id                   = $obj->rowid;
1135
-
1136
-                $this->ref                  = $obj->ref;
1137
-                $this->remise               = $obj->remise;
1138
-                $this->remise_percent       = $obj->remise_percent;
1139
-                $this->remise_absolue       = $obj->remise_absolue;
1140
-                $this->total                = $obj->total; // TODO deprecated
1141
-                $this->total_ht             = $obj->total_ht;
1142
-                $this->total_tva            = $obj->tva;
1143
-                $this->total_localtax1		= $obj->localtax1;
1144
-                $this->total_localtax2		= $obj->localtax2;
1145
-                $this->total_ttc            = $obj->total;
1146
-                $this->socid                = $obj->fk_soc;
1147
-                $this->fk_project           = $obj->fk_projet;
1148
-                $this->modelpdf             = $obj->model_pdf;
1149
-                $this->note                 = $obj->note_private; // TODO deprecated
1150
-                $this->note_private         = $obj->note_private;
1151
-                $this->note_public          = $obj->note_public;
1152
-                $this->statut               = (int) $obj->fk_statut;
1153
-                $this->statut_libelle       = $obj->statut_label;
1154
-                $this->datec                = $this->db->jdate($obj->datec); // TODO deprecated
1155
-                $this->datev                = $this->db->jdate($obj->datev); // TODO deprecated
1156
-                $this->date_creation		= $this->db->jdate($obj->datec); //Creation date
1157
-                $this->date_validation		= $this->db->jdate($obj->datev); //Validation date
1158
-                $this->date_livraison       = $this->db->jdate($obj->date_livraison);
1159
-                $this->shipping_method_id   = ($obj->fk_shipping_method>0)?$obj->fk_shipping_method:null;
1160
-
1161
-                $this->mode_reglement_id    = $obj->fk_mode_reglement;
1162
-                $this->mode_reglement_code  = $obj->mode_reglement_code;
1163
-                $this->mode_reglement       = $obj->mode_reglement;
1164
-                $this->fk_account           = ($obj->fk_account>0)?$obj->fk_account:null;
1165
-                $this->cond_reglement_id    = $obj->fk_cond_reglement;
1166
-                $this->cond_reglement_code  = $obj->cond_reglement_code;
1167
-                $this->cond_reglement       = $obj->cond_reglement;
1168
-                $this->cond_reglement_doc   = $obj->cond_reglement_libelle_doc;
1169
-
1170
-                $this->extraparams			= (array) json_decode($obj->extraparams, true);
1171
-
1172
-                $this->user_author_id = $obj->fk_user_author;
1173
-                $this->user_valid_id  = $obj->fk_user_valid;
1174
-                $this->user_close_id  = $obj->fk_user_cloture;
1016
+		$objsoc=new Societe($this->db);
1175 1017
 
1176
-				// Multicurrency
1177
-				$this->fk_multicurrency 		= $obj->fk_multicurrency;
1178
-				$this->multicurrency_code 		= $obj->multicurrency_code;
1179
-				$this->multicurrency_tx 		= $obj->multicurrency_tx;
1180
-				$this->multicurrency_total_ht 	= $obj->multicurrency_total_ht;
1181
-				$this->multicurrency_total_tva 	= $obj->multicurrency_total_tva;
1182
-				$this->multicurrency_total_ttc 	= $obj->multicurrency_total_ttc;
1018
+		// Change socid if needed
1019
+		if (! empty($socid) && $socid != $this->socid)
1020
+		{
1021
+			if ($objsoc->fetch($socid) > 0)
1022
+			{
1023
+				$this->socid 				= $objsoc->id;
1024
+				$this->cond_reglement_id	= (! empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1025
+				$this->mode_reglement_id	= (! empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1026
+				$this->fk_project			= '';
1027
+			}
1183 1028
 
1184
-                if ($obj->fk_statut == 0)
1185
-                {
1186
-                    $this->brouillon = 1;
1187
-                }
1029
+			// TODO Change product price if multi-prices
1030
+		}
1031
+		else
1032
+		{
1033
+			$objsoc->fetch($this->socid);
1034
+		}
1188 1035
 
1189
-                // Retreive all extrafield for invoice
1190
-                // fetch optionals attributes and labels
1191
-                require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
1192
-                $extrafields=new ExtraFields($this->db);
1193
-                $extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
1194
-                $this->fetch_optionals($this->id,$extralabels);
1036
+		$this->id=0;
1037
+		$this->statut=0;
1195 1038
 
1196
-                $this->db->free($resql);
1039
+		if (empty($conf->global->SUPPLIER_PROPOSAL_ADDON) || ! is_readable(DOL_DOCUMENT_ROOT ."/core/modules/supplier_proposal/".$conf->global->SUPPLIER_PROPOSAL_ADDON.".php"))
1040
+		{
1041
+			$this->error='ErrorSetupNotComplete';
1042
+			return -1;
1043
+		}
1197 1044
 
1198
-                $this->lines = array();
1045
+		// Clear fields
1046
+		$this->user_author	= $user->id;
1047
+		$this->user_valid	= '';
1048
+		$this->date			= $now;
1199 1049
 
1200
-                /*
1201
-                 * Lignes askprice liees a un produit ou non
1202
-                 */
1203
-                $sql = "SELECT d.rowid, d.fk_supplier_proposal, d.fk_parent_line, d.label as custom_label, d.description, d.price, d.tva_tx, d.localtax1_tx, d.localtax2_tx, d.qty, d.fk_remise_except, d.remise_percent, d.subprice, d.fk_product,";
1204
-				$sql.= " d.info_bits, d.total_ht, d.total_tva, d.total_localtax1, d.total_localtax2, d.total_ttc, d.fk_product_fournisseur_price as fk_fournprice, d.buy_price_ht as pa_ht, d.special_code, d.rang, d.product_type,";
1205
-                $sql.= ' p.ref as product_ref, p.description as product_desc, p.fk_product_type, p.label as product_label,';
1206
-                $sql.= ' d.ref_fourn as ref_produit_fourn,';
1207
-				$sql.= ' d.fk_multicurrency, d.multicurrency_code, d.multicurrency_subprice, d.multicurrency_total_ht, d.multicurrency_total_tva, d.multicurrency_total_ttc, d.fk_unit';
1208
-                $sql.= " FROM ".MAIN_DB_PREFIX."supplier_proposaldet as d";
1209
-                $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON d.fk_product = p.rowid";
1210
-                $sql.= " WHERE d.fk_supplier_proposal = ".$this->id;
1211
-                $sql.= " ORDER by d.rang";
1212
-
1213
-                $result = $this->db->query($sql);
1214
-                if ($result)
1215
-                {
1216
-                    $num = $this->db->num_rows($result);
1217
-                    $i = 0;
1218
-
1219
-                    while ($i < $num)
1220
-                    {
1221
-                        $objp                   = $this->db->fetch_object($result);
1222
-
1223
-                        $line                   = new SupplierProposalLine($this->db);
1224
-
1225
-                        $line->rowid			= $objp->rowid; // deprecated
1226
-                        $line->id				= $objp->rowid;
1227
-                        $line->fk_supplier_proposal		= $objp->fk_supplier_proposal;
1228
-                        $line->fk_parent_line	= $objp->fk_parent_line;
1229
-                        $line->product_type     = $objp->product_type;
1230
-                        $line->label            = $objp->custom_label;
1231
-                        $line->desc             = $objp->description;  // Description ligne
1232
-                        $line->qty              = $objp->qty;
1233
-                        $line->tva_tx           = $objp->tva_tx;
1234
-                        $line->localtax1_tx		= $objp->localtax1_tx;
1235
-                        $line->localtax2_tx		= $objp->localtax2_tx;
1236
-                        $line->subprice         = $objp->subprice;
1237
-                        $line->fk_remise_except = $objp->fk_remise_except;
1238
-                        $line->remise_percent   = $objp->remise_percent;
1239
-                        $line->price            = $objp->price;		// TODO deprecated
1240
-
1241
-                        $line->info_bits        = $objp->info_bits;
1242
-                        $line->total_ht         = $objp->total_ht;
1243
-                        $line->total_tva        = $objp->total_tva;
1244
-                        $line->total_localtax1	= $objp->total_localtax1;
1245
-                        $line->total_localtax2	= $objp->total_localtax2;
1246
-                        $line->total_ttc        = $objp->total_ttc;
1247
-      					$line->fk_fournprice 	= $objp->fk_fournprice;
1248
-						$marginInfos			= getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $line->fk_fournprice, $objp->pa_ht);
1249
-						$line->pa_ht 			= $marginInfos[0];
1250
-						$line->marge_tx			= $marginInfos[1];
1251
-						$line->marque_tx		= $marginInfos[2];
1252
-                        $line->special_code     = $objp->special_code;
1253
-                        $line->rang             = $objp->rang;
1050
+		// Set ref
1051
+		require_once DOL_DOCUMENT_ROOT ."/core/modules/supplier_proposal/".$conf->global->SUPPLIER_PROPOSAL_ADDON.'.php';
1052
+		$obj = $conf->global->SUPPLIER_PROPOSAL_ADDON;
1053
+		$modSupplierProposal = new $obj;
1054
+		$this->ref = $modSupplierProposal->getNextValue($objsoc,$this);
1254 1055
 
1255
-                        $line->fk_product       = $objp->fk_product;
1056
+		// Create clone
1057
+		$result=$this->create($user);
1058
+		if ($result < 0) $error++;
1256 1059
 
1257
-                        $line->ref				= $objp->product_ref;		// TODO deprecated
1258
-                        $line->product_ref		= $objp->product_ref;
1259
-                        $line->libelle			= $objp->product_label;		// TODO deprecated
1260
-                        $line->product_label	= $objp->product_label;
1261
-                        $line->product_desc     = $objp->product_desc; 		// Description produit
1262
-                        $line->fk_product_type  = $objp->fk_product_type;
1060
+		if (! $error)
1061
+		{
1062
+			// Hook of thirdparty module
1063
+			if (is_object($hookmanager))
1064
+			{
1065
+				$parameters=array('objFrom'=>$objFrom);
1066
+				$action='';
1067
+				$reshook=$hookmanager->executeHooks('createFrom',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
1068
+				if ($reshook < 0) $error++;
1069
+			}
1263 1070
 
1264
-						$line->ref_fourn		= $objp->ref_produit_fourn;
1071
+			// Call trigger
1072
+			$result=$this->call_trigger('SUPPLIER_PROPOSAL_CLONE',$user);
1073
+			if ($result < 0) { $error++; }
1074
+			// End call triggers
1075
+		}
1265 1076
 
1266
-						// Multicurrency
1267
-						$line->fk_multicurrency 		= $objp->fk_multicurrency;
1077
+		// End
1078
+		if (! $error)
1079
+		{
1080
+			$this->db->commit();
1081
+			return $this->id;
1082
+		}
1083
+		else
1084
+		{
1085
+			$this->db->rollback();
1086
+			return -1;
1087
+		}
1088
+	}
1089
+
1090
+	/**
1091
+	 *	Load a proposal from database and its ligne array
1092
+	 *
1093
+	 *	@param      int			$rowid		id of object to load
1094
+	 *	@param		string		$ref		Ref of proposal
1095
+	 *	@return     int         			>0 if OK, <0 if KO
1096
+	 */
1097
+	function fetch($rowid,$ref='')
1098
+	{
1099
+		global $conf;
1100
+
1101
+		$sql = "SELECT p.rowid, p.ref, p.remise, p.remise_percent, p.remise_absolue, p.fk_soc";
1102
+		$sql.= ", p.total, p.tva, p.localtax1, p.localtax2, p.total_ht";
1103
+		$sql.= ", p.datec";
1104
+		$sql.= ", p.date_valid as datev";
1105
+		$sql.= ", p.date_livraison as date_livraison";
1106
+		$sql.= ", p.model_pdf, p.extraparams";
1107
+		$sql.= ", p.note_private, p.note_public";
1108
+		$sql.= ", p.fk_projet, p.fk_statut";
1109
+		$sql.= ", p.fk_user_author, p.fk_user_valid, p.fk_user_cloture";
1110
+		$sql.= ", p.fk_cond_reglement";
1111
+		$sql.= ", p.fk_mode_reglement";
1112
+		$sql.= ', p.fk_account';
1113
+		$sql.= ", p.fk_shipping_method";
1114
+		$sql.= ", p.fk_multicurrency, p.multicurrency_code, p.multicurrency_tx, p.multicurrency_total_ht, p.multicurrency_total_tva, p.multicurrency_total_ttc";
1115
+		$sql.= ", c.label as statut_label";
1116
+		$sql.= ", cr.code as cond_reglement_code, cr.libelle as cond_reglement, cr.libelle_facture as cond_reglement_libelle_doc";
1117
+		$sql.= ", cp.code as mode_reglement_code, cp.libelle as mode_reglement";
1118
+		$sql.= " FROM ".MAIN_DB_PREFIX."c_propalst as c, ".MAIN_DB_PREFIX."supplier_proposal as p";
1119
+		$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_mode_reglement = cp.id AND cp.entity IN (' . getEntity('c_paiement').')';
1120
+		$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON p.fk_cond_reglement = cr.rowid AND cr.entity IN (' . getEntity('c_payment_term').')';
1121
+		$sql.= " WHERE p.fk_statut = c.id";
1122
+		$sql.= " AND p.entity = ".$conf->entity;
1123
+		if ($ref) $sql.= " AND p.ref='".$ref."'";
1124
+		else $sql.= " AND p.rowid=".$rowid;
1125
+
1126
+		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
1127
+		$resql=$this->db->query($sql);
1128
+		if ($resql)
1129
+		{
1130
+			if ($this->db->num_rows($resql))
1131
+			{
1132
+				$obj = $this->db->fetch_object($resql);
1133
+
1134
+				$this->id                   = $obj->rowid;
1135
+
1136
+				$this->ref                  = $obj->ref;
1137
+				$this->remise               = $obj->remise;
1138
+				$this->remise_percent       = $obj->remise_percent;
1139
+				$this->remise_absolue       = $obj->remise_absolue;
1140
+				$this->total                = $obj->total; // TODO deprecated
1141
+				$this->total_ht             = $obj->total_ht;
1142
+				$this->total_tva            = $obj->tva;
1143
+				$this->total_localtax1		= $obj->localtax1;
1144
+				$this->total_localtax2		= $obj->localtax2;
1145
+				$this->total_ttc            = $obj->total;
1146
+				$this->socid                = $obj->fk_soc;
1147
+				$this->fk_project           = $obj->fk_projet;
1148
+				$this->modelpdf             = $obj->model_pdf;
1149
+				$this->note                 = $obj->note_private; // TODO deprecated
1150
+				$this->note_private         = $obj->note_private;
1151
+				$this->note_public          = $obj->note_public;
1152
+				$this->statut               = (int) $obj->fk_statut;
1153
+				$this->statut_libelle       = $obj->statut_label;
1154
+				$this->datec                = $this->db->jdate($obj->datec); // TODO deprecated
1155
+				$this->datev                = $this->db->jdate($obj->datev); // TODO deprecated
1156
+				$this->date_creation		= $this->db->jdate($obj->datec); //Creation date
1157
+				$this->date_validation		= $this->db->jdate($obj->datev); //Validation date
1158
+				$this->date_livraison       = $this->db->jdate($obj->date_livraison);
1159
+				$this->shipping_method_id   = ($obj->fk_shipping_method>0)?$obj->fk_shipping_method:null;
1160
+
1161
+				$this->mode_reglement_id    = $obj->fk_mode_reglement;
1162
+				$this->mode_reglement_code  = $obj->mode_reglement_code;
1163
+				$this->mode_reglement       = $obj->mode_reglement;
1164
+				$this->fk_account           = ($obj->fk_account>0)?$obj->fk_account:null;
1165
+				$this->cond_reglement_id    = $obj->fk_cond_reglement;
1166
+				$this->cond_reglement_code  = $obj->cond_reglement_code;
1167
+				$this->cond_reglement       = $obj->cond_reglement;
1168
+				$this->cond_reglement_doc   = $obj->cond_reglement_libelle_doc;
1169
+
1170
+				$this->extraparams			= (array) json_decode($obj->extraparams, true);
1171
+
1172
+				$this->user_author_id = $obj->fk_user_author;
1173
+				$this->user_valid_id  = $obj->fk_user_valid;
1174
+				$this->user_close_id  = $obj->fk_user_cloture;
1175
+
1176
+				// Multicurrency
1177
+				$this->fk_multicurrency 		= $obj->fk_multicurrency;
1178
+				$this->multicurrency_code 		= $obj->multicurrency_code;
1179
+				$this->multicurrency_tx 		= $obj->multicurrency_tx;
1180
+				$this->multicurrency_total_ht 	= $obj->multicurrency_total_ht;
1181
+				$this->multicurrency_total_tva 	= $obj->multicurrency_total_tva;
1182
+				$this->multicurrency_total_ttc 	= $obj->multicurrency_total_ttc;
1183
+
1184
+				if ($obj->fk_statut == 0)
1185
+				{
1186
+					$this->brouillon = 1;
1187
+				}
1188
+
1189
+				// Retreive all extrafield for invoice
1190
+				// fetch optionals attributes and labels
1191
+				require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
1192
+				$extrafields=new ExtraFields($this->db);
1193
+				$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
1194
+				$this->fetch_optionals($this->id,$extralabels);
1195
+
1196
+				$this->db->free($resql);
1197
+
1198
+				$this->lines = array();
1199
+
1200
+				/*
1201
+                 * Lignes askprice liees a un produit ou non
1202
+                 */
1203
+				$sql = "SELECT d.rowid, d.fk_supplier_proposal, d.fk_parent_line, d.label as custom_label, d.description, d.price, d.tva_tx, d.localtax1_tx, d.localtax2_tx, d.qty, d.fk_remise_except, d.remise_percent, d.subprice, d.fk_product,";
1204
+				$sql.= " d.info_bits, d.total_ht, d.total_tva, d.total_localtax1, d.total_localtax2, d.total_ttc, d.fk_product_fournisseur_price as fk_fournprice, d.buy_price_ht as pa_ht, d.special_code, d.rang, d.product_type,";
1205
+				$sql.= ' p.ref as product_ref, p.description as product_desc, p.fk_product_type, p.label as product_label,';
1206
+				$sql.= ' d.ref_fourn as ref_produit_fourn,';
1207
+				$sql.= ' d.fk_multicurrency, d.multicurrency_code, d.multicurrency_subprice, d.multicurrency_total_ht, d.multicurrency_total_tva, d.multicurrency_total_ttc, d.fk_unit';
1208
+				$sql.= " FROM ".MAIN_DB_PREFIX."supplier_proposaldet as d";
1209
+				$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON d.fk_product = p.rowid";
1210
+				$sql.= " WHERE d.fk_supplier_proposal = ".$this->id;
1211
+				$sql.= " ORDER by d.rang";
1212
+
1213
+				$result = $this->db->query($sql);
1214
+				if ($result)
1215
+				{
1216
+					$num = $this->db->num_rows($result);
1217
+					$i = 0;
1218
+
1219
+					while ($i < $num)
1220
+					{
1221
+						$objp                   = $this->db->fetch_object($result);
1222
+
1223
+						$line                   = new SupplierProposalLine($this->db);
1224
+
1225
+						$line->rowid			= $objp->rowid; // deprecated
1226
+						$line->id				= $objp->rowid;
1227
+						$line->fk_supplier_proposal		= $objp->fk_supplier_proposal;
1228
+						$line->fk_parent_line	= $objp->fk_parent_line;
1229
+						$line->product_type     = $objp->product_type;
1230
+						$line->label            = $objp->custom_label;
1231
+						$line->desc             = $objp->description;  // Description ligne
1232
+						$line->qty              = $objp->qty;
1233
+						$line->tva_tx           = $objp->tva_tx;
1234
+						$line->localtax1_tx		= $objp->localtax1_tx;
1235
+						$line->localtax2_tx		= $objp->localtax2_tx;
1236
+						$line->subprice         = $objp->subprice;
1237
+						$line->fk_remise_except = $objp->fk_remise_except;
1238
+						$line->remise_percent   = $objp->remise_percent;
1239
+						$line->price            = $objp->price;		// TODO deprecated
1240
+
1241
+						$line->info_bits        = $objp->info_bits;
1242
+						$line->total_ht         = $objp->total_ht;
1243
+						$line->total_tva        = $objp->total_tva;
1244
+						$line->total_localtax1	= $objp->total_localtax1;
1245
+						$line->total_localtax2	= $objp->total_localtax2;
1246
+						$line->total_ttc        = $objp->total_ttc;
1247
+	  					$line->fk_fournprice 	= $objp->fk_fournprice;
1248
+						$marginInfos			= getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $line->fk_fournprice, $objp->pa_ht);
1249
+						$line->pa_ht 			= $marginInfos[0];
1250
+						$line->marge_tx			= $marginInfos[1];
1251
+						$line->marque_tx		= $marginInfos[2];
1252
+						$line->special_code     = $objp->special_code;
1253
+						$line->rang             = $objp->rang;
1254
+
1255
+						$line->fk_product       = $objp->fk_product;
1256
+
1257
+						$line->ref				= $objp->product_ref;		// TODO deprecated
1258
+						$line->product_ref		= $objp->product_ref;
1259
+						$line->libelle			= $objp->product_label;		// TODO deprecated
1260
+						$line->product_label	= $objp->product_label;
1261
+						$line->product_desc     = $objp->product_desc; 		// Description produit
1262
+						$line->fk_product_type  = $objp->fk_product_type;
1263
+
1264
+						$line->ref_fourn		= $objp->ref_produit_fourn;
1265
+
1266
+						// Multicurrency
1267
+						$line->fk_multicurrency 		= $objp->fk_multicurrency;
1268 1268
 						$line->multicurrency_code 		= $objp->multicurrency_code;
1269 1269
 						$line->multicurrency_subprice 	= $objp->multicurrency_subprice;
1270 1270
 						$line->multicurrency_total_ht 	= $objp->multicurrency_total_ht;
@@ -1272,118 +1272,118 @@  discard block
 block discarded – undo
1272 1272
 						$line->multicurrency_total_ttc 	= $objp->multicurrency_total_ttc;
1273 1273
 						$line->fk_unit					= $objp->fk_unit;
1274 1274
 
1275
-                        $this->lines[$i]        = $line;
1276
-
1277
-                        $i++;
1278
-                    }
1279
-                    $this->db->free($result);
1280
-                }
1281
-                else
1282
-                {
1283
-                    $this->error=$this->db->error();
1284
-                    return -1;
1285
-                }
1286
-
1287
-                // Retreive all extrafield for askprice
1288
-                // fetch optionals attributes and labels
1289
-                require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
1290
-                $extrafields=new ExtraFields($this->db);
1291
-                $extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
1292
-                $this->fetch_optionals($this->id,$extralabels);
1293
-
1294
-                return 1;
1295
-            }
1296
-
1297
-            $this->error="Record Not Found";
1298
-            return 0;
1299
-        }
1300
-        else
1301
-        {
1302
-            $this->error=$this->db->error();
1303
-            return -1;
1304
-        }
1305
-    }
1306
-
1307
-    /**
1308
-     *	Update value of extrafields on the proposal
1309
-     *
1310
-     *	@param      User	$user       Object user that modify
1311
-     *	@return     int         		<0 if ko, >0 if ok
1312
-     */
1313
-    function update_extrafields($user)
1314
-    {
1315
-    	$action='update';
1316
-
1317
-    	// Actions on extra fields (by external module or standard code)
1318
-    	$hookmanager->initHooks(array('supplier_proposaldao'));
1319
-    	$parameters=array('id'=>$this->id);
1320
-    	$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
1321
-    	if (empty($reshook))
1322
-    	{
1323
-    		if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
1324
-    		{
1325
-    			$result=$this->insertExtraFields();
1326
-    			if ($result < 0)
1327
-    			{
1328
-    				$error++;
1329
-    			}
1330
-    		}
1331
-    	}
1332
-    	else if ($reshook < 0) $error++;
1275
+						$this->lines[$i]        = $line;
1276
+
1277
+						$i++;
1278
+					}
1279
+					$this->db->free($result);
1280
+				}
1281
+				else
1282
+				{
1283
+					$this->error=$this->db->error();
1284
+					return -1;
1285
+				}
1286
+
1287
+				// Retreive all extrafield for askprice
1288
+				// fetch optionals attributes and labels
1289
+				require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
1290
+				$extrafields=new ExtraFields($this->db);
1291
+				$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
1292
+				$this->fetch_optionals($this->id,$extralabels);
1293
+
1294
+				return 1;
1295
+			}
1296
+
1297
+			$this->error="Record Not Found";
1298
+			return 0;
1299
+		}
1300
+		else
1301
+		{
1302
+			$this->error=$this->db->error();
1303
+			return -1;
1304
+		}
1305
+	}
1306
+
1307
+	/**
1308
+	 *	Update value of extrafields on the proposal
1309
+	 *
1310
+	 *	@param      User	$user       Object user that modify
1311
+	 *	@return     int         		<0 if ko, >0 if ok
1312
+	 */
1313
+	function update_extrafields($user)
1314
+	{
1315
+		$action='update';
1316
+
1317
+		// Actions on extra fields (by external module or standard code)
1318
+		$hookmanager->initHooks(array('supplier_proposaldao'));
1319
+		$parameters=array('id'=>$this->id);
1320
+		$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
1321
+		if (empty($reshook))
1322
+		{
1323
+			if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
1324
+			{
1325
+				$result=$this->insertExtraFields();
1326
+				if ($result < 0)
1327
+				{
1328
+					$error++;
1329
+				}
1330
+			}
1331
+		}
1332
+		else if ($reshook < 0) $error++;
1333 1333
 
1334 1334
 		if (!$error)
1335
-	    {
1336
-	    	return 1;
1337
-	    }
1338
-	    else
1339
-	    {
1340
-	    	return -1;
1341
-	    }
1342
-
1343
-    }
1344
-
1345
-    /**
1346
-     *  Set status to validated
1347
-     *
1348
-     *  @param	User	$user       Object user that validate
1349
-     *  @param	int		$notrigger	1=Does not execute triggers, 0= execute triggers
1350
-     *  @return int         		<0 if KO, >=0 if OK
1351
-     */
1352
-    function valid($user, $notrigger=0)
1353
-    {
1354
-    	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1355
-
1356
-    	global $conf,$langs;
1357
-
1358
-        $error=0;
1359
-        $now=dol_now();
1360
-
1361
-        if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->supplier_proposal->creer))
1362
-       	|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->supplier_proposal->validate_advance)))
1363
-        {
1364
-            $this->db->begin();
1365
-
1366
-            // Numbering module definition
1367
-            $soc = new Societe($this->db);
1368
-            $soc->fetch($this->socid);
1369
-
1370
-            // Define new ref
1371
-            if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life
1372
-            {
1373
-            	$num = $this->getNextNumRef($soc);
1374
-            }
1375
-            else
1376
-            {
1377
-            	$num = $this->ref;
1378
-            }
1379
-            $this->newref = $num;
1380
-
1381
-            $sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal";
1382
-            $sql.= " SET ref = '".$num."',";
1383
-            $sql.= " fk_statut = 1, date_valid='".$this->db->idate($now)."', fk_user_valid=".$user->id;
1384
-            $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0";
1385
-
1386
-            dol_syslog(get_class($this)."::valid", LOG_DEBUG);
1335
+		{
1336
+			return 1;
1337
+		}
1338
+		else
1339
+		{
1340
+			return -1;
1341
+		}
1342
+
1343
+	}
1344
+
1345
+	/**
1346
+	 *  Set status to validated
1347
+	 *
1348
+	 *  @param	User	$user       Object user that validate
1349
+	 *  @param	int		$notrigger	1=Does not execute triggers, 0= execute triggers
1350
+	 *  @return int         		<0 if KO, >=0 if OK
1351
+	 */
1352
+	function valid($user, $notrigger=0)
1353
+	{
1354
+		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1355
+
1356
+		global $conf,$langs;
1357
+
1358
+		$error=0;
1359
+		$now=dol_now();
1360
+
1361
+		if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->supplier_proposal->creer))
1362
+	   	|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->supplier_proposal->validate_advance)))
1363
+		{
1364
+			$this->db->begin();
1365
+
1366
+			// Numbering module definition
1367
+			$soc = new Societe($this->db);
1368
+			$soc->fetch($this->socid);
1369
+
1370
+			// Define new ref
1371
+			if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life
1372
+			{
1373
+				$num = $this->getNextNumRef($soc);
1374
+			}
1375
+			else
1376
+			{
1377
+				$num = $this->ref;
1378
+			}
1379
+			$this->newref = $num;
1380
+
1381
+			$sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal";
1382
+			$sql.= " SET ref = '".$num."',";
1383
+			$sql.= " fk_statut = 1, date_valid='".$this->db->idate($now)."', fk_user_valid=".$user->id;
1384
+			$sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0";
1385
+
1386
+			dol_syslog(get_class($this)."::valid", LOG_DEBUG);
1387 1387
 			$resql=$this->db->query($sql);
1388 1388
 			if (! $resql)
1389 1389
 			{
@@ -1394,1107 +1394,1107 @@  discard block
 block discarded – undo
1394 1394
    			// Trigger calls
1395 1395
 			if (! $error && ! $notrigger)
1396 1396
 			{
1397
-                // Call trigger
1398
-                $result=$this->call_trigger('SUPPLIER_PROPOSAL_VALIDATE',$user);
1399
-                if ($result < 0) { $error++; }
1400
-                // End call triggers
1401
-            }
1402
-
1403
-            if (! $error)
1404
-            {
1405
-            	$this->oldref = $this->ref;
1406
-
1407
-            	// Rename directory if dir was a temporary ref
1408
-            	if (preg_match('/^[\(]?PROV/i', $this->ref))
1409
-            	{
1410
-            		// Rename of propal directory ($this->ref = old ref, $num = new ref)
1411
-            		// to  not lose the linked files
1412
-            		$oldref = dol_sanitizeFileName($this->ref);
1413
-            		$newref = dol_sanitizeFileName($num);
1414
-            		$dirsource = $conf->supplier_proposal->dir_output.'/'.$oldref;
1415
-            		$dirdest = $conf->supplier_proposal->dir_output.'/'.$newref;
1416
-
1417
-            		if (file_exists($dirsource))
1418
-            		{
1419
-            			dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest);
1420
-            			if (@rename($dirsource, $dirdest))
1421
-            			{
1422
-            				dol_syslog("Rename ok");
1423
-            				// Rename docs starting with $oldref with $newref
1424
-            				$listoffiles=dol_dir_list($conf->supplier_proposal->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref,'/'));
1425
-            				foreach($listoffiles as $fileentry)
1426
-            				{
1427
-            					$dirsource=$fileentry['name'];
1428
-            					$dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource);
1429
-            					$dirsource=$fileentry['path'].'/'.$dirsource;
1430
-            					$dirdest=$fileentry['path'].'/'.$dirdest;
1431
-            					@rename($dirsource, $dirdest);
1432
-            				}
1433
-            			}
1434
-            		}
1435
-            	}
1436
-
1437
-            	$this->ref=$num;
1438
-            	$this->brouillon=0;
1439
-            	$this->statut = 1;
1440
-            	$this->user_valid_id=$user->id;
1441
-            	$this->datev=$now;
1442
-
1443
-            	$this->db->commit();
1444
-            	return 1;
1445
-            }
1446
-            else
1447
-			{
1448
-            	$this->db->rollback();
1449
-            	return -1;
1450
-            }
1451
-        }
1452
-    }
1453
-
1454
-    /**
1455
-     *	Set delivery date
1456
-     *
1457
-     *	@param      User 		$user        		Object user that modify
1458
-     *	@param      int			$date_livraison     Delivery date
1459
-     *	@return     int         					<0 if ko, >0 if ok
1460
-     */
1461
-    function set_date_livraison($user, $date_livraison)
1462
-    {
1463
-        if (! empty($user->rights->supplier_proposal->creer))
1464
-        {
1465
-            $sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal ";
1466
-            $sql.= " SET date_livraison = ".($date_livraison!=''?"'".$this->db->idate($date_livraison)."'":'null');
1467
-            $sql.= " WHERE rowid = ".$this->id;
1468
-
1469
-            if ($this->db->query($sql))
1470
-            {
1471
-                $this->date_livraison = $date_livraison;
1472
-                return 1;
1473
-            }
1474
-            else
1475
-            {
1476
-                $this->error=$this->db->error();
1477
-                dol_syslog(get_class($this)."::set_date_livraison Erreur SQL");
1478
-                return -1;
1479
-            }
1480
-        }
1481
-    }
1482
-
1483
-    /**
1484
-     *	Set an overall discount on the proposal
1485
-     *
1486
-     *	@param      User	$user       Object user that modify
1487
-     *	@param      double	$remise      Amount discount
1488
-     *	@return     int         		<0 if ko, >0 if ok
1489
-     */
1490
-    function set_remise_percent($user, $remise)
1491
-    {
1492
-        $remise=trim($remise)?trim($remise):0;
1493
-
1494
-        if (! empty($user->rights->supplier_proposal->creer))
1495
-        {
1496
-            $remise = price2num($remise);
1497
-
1498
-            $sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal SET remise_percent = ".$remise;
1499
-            $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0";
1500
-
1501
-            if ($this->db->query($sql) )
1502
-            {
1503
-                $this->remise_percent = $remise;
1504
-                $this->update_price(1);
1505
-                return 1;
1506
-            }
1507
-            else
1508
-            {
1509
-                $this->error=$this->db->error();
1510
-                return -1;
1511
-            }
1512
-        }
1513
-    }
1514
-
1515
-
1516
-    /**
1517
-     *	Set an absolute overall discount on the proposal
1518
-     *
1519
-     *	@param      User	$user        Object user that modify
1520
-     *	@param      double	$remise      Amount discount
1521
-     *	@return     int         		<0 if ko, >0 if ok
1522
-     */
1523
-    function set_remise_absolue($user, $remise)
1524
-    {
1525
-        $remise=trim($remise)?trim($remise):0;
1526
-
1527
-        if (! empty($user->rights->supplier_proposal->creer))
1528
-        {
1529
-            $remise = price2num($remise);
1530
-
1531
-            $sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal ";
1532
-            $sql.= " SET remise_absolue = ".$remise;
1533
-            $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0";
1534
-
1535
-            if ($this->db->query($sql) )
1536
-            {
1537
-                $this->remise_absolue = $remise;
1538
-                $this->update_price(1);
1539
-                return 1;
1540
-            }
1541
-            else
1542
-            {
1543
-                $this->error=$this->db->error();
1544
-                return -1;
1545
-            }
1546
-        }
1547
-    }
1548
-
1549
-
1550
-
1551
-    /**
1552
-     *	Reopen the commercial proposal
1553
-     *
1554
-     *	@param      User	$user		Object user that close
1555
-     *	@param      int		$statut		Statut
1556
-     *	@param      string	$note		Comment
1557
-     *  @param		int		$notrigger	1=Does not execute triggers, 0= execute triggers
1558
-     *	@return     int         		<0 if KO, >0 if OK
1559
-     */
1560
-    function reopen($user, $statut, $note='', $notrigger=0)
1561
-    {
1562
-        global $langs,$conf;
1563
-
1564
-        $this->statut = $statut;
1565
-        $error=0;
1566
-
1567
-        $sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal";
1568
-        $sql.= " SET fk_statut = ".$this->statut.",";
1397
+				// Call trigger
1398
+				$result=$this->call_trigger('SUPPLIER_PROPOSAL_VALIDATE',$user);
1399
+				if ($result < 0) { $error++; }
1400
+				// End call triggers
1401
+			}
1402
+
1403
+			if (! $error)
1404
+			{
1405
+				$this->oldref = $this->ref;
1406
+
1407
+				// Rename directory if dir was a temporary ref
1408
+				if (preg_match('/^[\(]?PROV/i', $this->ref))
1409
+				{
1410
+					// Rename of propal directory ($this->ref = old ref, $num = new ref)
1411
+					// to  not lose the linked files
1412
+					$oldref = dol_sanitizeFileName($this->ref);
1413
+					$newref = dol_sanitizeFileName($num);
1414
+					$dirsource = $conf->supplier_proposal->dir_output.'/'.$oldref;
1415
+					$dirdest = $conf->supplier_proposal->dir_output.'/'.$newref;
1416
+
1417
+					if (file_exists($dirsource))
1418
+					{
1419
+						dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest);
1420
+						if (@rename($dirsource, $dirdest))
1421
+						{
1422
+							dol_syslog("Rename ok");
1423
+							// Rename docs starting with $oldref with $newref
1424
+							$listoffiles=dol_dir_list($conf->supplier_proposal->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref,'/'));
1425
+							foreach($listoffiles as $fileentry)
1426
+							{
1427
+								$dirsource=$fileentry['name'];
1428
+								$dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource);
1429
+								$dirsource=$fileentry['path'].'/'.$dirsource;
1430
+								$dirdest=$fileentry['path'].'/'.$dirdest;
1431
+								@rename($dirsource, $dirdest);
1432
+							}
1433
+						}
1434
+					}
1435
+				}
1436
+
1437
+				$this->ref=$num;
1438
+				$this->brouillon=0;
1439
+				$this->statut = 1;
1440
+				$this->user_valid_id=$user->id;
1441
+				$this->datev=$now;
1442
+
1443
+				$this->db->commit();
1444
+				return 1;
1445
+			}
1446
+			else
1447
+			{
1448
+				$this->db->rollback();
1449
+				return -1;
1450
+			}
1451
+		}
1452
+	}
1453
+
1454
+	/**
1455
+	 *	Set delivery date
1456
+	 *
1457
+	 *	@param      User 		$user        		Object user that modify
1458
+	 *	@param      int			$date_livraison     Delivery date
1459
+	 *	@return     int         					<0 if ko, >0 if ok
1460
+	 */
1461
+	function set_date_livraison($user, $date_livraison)
1462
+	{
1463
+		if (! empty($user->rights->supplier_proposal->creer))
1464
+		{
1465
+			$sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal ";
1466
+			$sql.= " SET date_livraison = ".($date_livraison!=''?"'".$this->db->idate($date_livraison)."'":'null');
1467
+			$sql.= " WHERE rowid = ".$this->id;
1468
+
1469
+			if ($this->db->query($sql))
1470
+			{
1471
+				$this->date_livraison = $date_livraison;
1472
+				return 1;
1473
+			}
1474
+			else
1475
+			{
1476
+				$this->error=$this->db->error();
1477
+				dol_syslog(get_class($this)."::set_date_livraison Erreur SQL");
1478
+				return -1;
1479
+			}
1480
+		}
1481
+	}
1482
+
1483
+	/**
1484
+	 *	Set an overall discount on the proposal
1485
+	 *
1486
+	 *	@param      User	$user       Object user that modify
1487
+	 *	@param      double	$remise      Amount discount
1488
+	 *	@return     int         		<0 if ko, >0 if ok
1489
+	 */
1490
+	function set_remise_percent($user, $remise)
1491
+	{
1492
+		$remise=trim($remise)?trim($remise):0;
1493
+
1494
+		if (! empty($user->rights->supplier_proposal->creer))
1495
+		{
1496
+			$remise = price2num($remise);
1497
+
1498
+			$sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal SET remise_percent = ".$remise;
1499
+			$sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0";
1500
+
1501
+			if ($this->db->query($sql) )
1502
+			{
1503
+				$this->remise_percent = $remise;
1504
+				$this->update_price(1);
1505
+				return 1;
1506
+			}
1507
+			else
1508
+			{
1509
+				$this->error=$this->db->error();
1510
+				return -1;
1511
+			}
1512
+		}
1513
+	}
1514
+
1515
+
1516
+	/**
1517
+	 *	Set an absolute overall discount on the proposal
1518
+	 *
1519
+	 *	@param      User	$user        Object user that modify
1520
+	 *	@param      double	$remise      Amount discount
1521
+	 *	@return     int         		<0 if ko, >0 if ok
1522
+	 */
1523
+	function set_remise_absolue($user, $remise)
1524
+	{
1525
+		$remise=trim($remise)?trim($remise):0;
1526
+
1527
+		if (! empty($user->rights->supplier_proposal->creer))
1528
+		{
1529
+			$remise = price2num($remise);
1530
+
1531
+			$sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal ";
1532
+			$sql.= " SET remise_absolue = ".$remise;
1533
+			$sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0";
1534
+
1535
+			if ($this->db->query($sql) )
1536
+			{
1537
+				$this->remise_absolue = $remise;
1538
+				$this->update_price(1);
1539
+				return 1;
1540
+			}
1541
+			else
1542
+			{
1543
+				$this->error=$this->db->error();
1544
+				return -1;
1545
+			}
1546
+		}
1547
+	}
1548
+
1549
+
1550
+
1551
+	/**
1552
+	 *	Reopen the commercial proposal
1553
+	 *
1554
+	 *	@param      User	$user		Object user that close
1555
+	 *	@param      int		$statut		Statut
1556
+	 *	@param      string	$note		Comment
1557
+	 *  @param		int		$notrigger	1=Does not execute triggers, 0= execute triggers
1558
+	 *	@return     int         		<0 if KO, >0 if OK
1559
+	 */
1560
+	function reopen($user, $statut, $note='', $notrigger=0)
1561
+	{
1562
+		global $langs,$conf;
1563
+
1564
+		$this->statut = $statut;
1565
+		$error=0;
1566
+
1567
+		$sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal";
1568
+		$sql.= " SET fk_statut = ".$this->statut.",";
1569 1569
 		if (! empty($note)) $sql.= " note_private = '".$this->db->escape($note)."',";
1570
-        $sql.= " date_cloture=NULL, fk_user_cloture=NULL";
1571
-        $sql.= " WHERE rowid = ".$this->id;
1570
+		$sql.= " date_cloture=NULL, fk_user_cloture=NULL";
1571
+		$sql.= " WHERE rowid = ".$this->id;
1572
+
1573
+		$this->db->begin();
1574
+
1575
+		dol_syslog(get_class($this)."::reopen", LOG_DEBUG);
1576
+		$resql = $this->db->query($sql);
1577
+		if (! $resql) {
1578
+			$error++; $this->errors[]="Error ".$this->db->lasterror();
1579
+		}
1580
+		if (! $error)
1581
+		{
1582
+			if (! $notrigger)
1583
+			{
1584
+				// Call trigger
1585
+				$result=$this->call_trigger('SUPPLIER_PROPOSAL_REOPEN',$user);
1586
+				if ($result < 0) { $error++; }
1587
+				// End call triggers
1588
+			}
1589
+		}
1590
+
1591
+		// Commit or rollback
1592
+		if ($error)
1593
+		{
1594
+			if (!empty($this->errors))
1595
+			{
1596
+				foreach($this->errors as $errmsg)
1597
+				{
1598
+					dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
1599
+					$this->error.=($this->error?', '.$errmsg:$errmsg);
1600
+				}
1601
+			}
1602
+			$this->db->rollback();
1603
+			return -1*$error;
1604
+		}
1605
+		else
1606
+		{
1607
+			$this->db->commit();
1608
+			return 1;
1609
+		}
1610
+	}
1611
+
1612
+
1613
+	/**
1614
+	 *	Close the askprice
1615
+	 *
1616
+	 *	@param      User	$user		Object user that close
1617
+	 *	@param      int		$statut		Statut
1618
+	 *	@param      string	$note		Comment
1619
+	 *	@return     int         		<0 if KO, >0 if OK
1620
+	 */
1621
+	function cloture($user, $statut, $note)
1622
+	{
1623
+		global $langs,$conf;
1624
+
1625
+		$this->statut = $statut;
1626
+		$error=0;
1627
+		$now=dol_now();
1628
+
1629
+		$this->db->begin();
1630
+
1631
+		$sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal";
1632
+		$sql.= " SET fk_statut = ".$statut.", note_private = '".$this->db->escape($note)."', date_cloture='".$this->db->idate($now)."', fk_user_cloture=".$user->id;
1633
+		$sql.= " WHERE rowid = ".$this->id;
1634
+
1635
+		$resql=$this->db->query($sql);
1636
+		if ($resql)
1637
+		{
1638
+			$modelpdf=$conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_CLOSED?$conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_CLOSED:$this->modelpdf;
1639
+			$trigger_name='SUPPLIER_PROPOSAL_CLOSE_REFUSED';
1640
+
1641
+			if ($statut == 2)
1642
+			{
1643
+				$trigger_name='SUPPLIER_PROPOSAL_CLOSE_SIGNED';
1644
+				$modelpdf=$conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL?$conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL:$this->modelpdf;
1645
+
1646
+				if (! empty($conf->global->SUPPLIER_PROPOSAL_UPDATE_PRICE_ON_SUPPlIER_PROPOSAL))     // TODO This option was not tested correctly. Error if product ref does not exists
1647
+				{
1648
+					$result = $this->updateOrCreatePriceFournisseur($user);
1649
+				}
1650
+
1651
+			}
1652
+			if ($statut == 4)
1653
+			{
1654
+				$trigger_name='SUPPLIER_PROPOSAL_CLASSIFY_BILLED';
1655
+			}
1656
+
1657
+			if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
1658
+			{
1659
+			 	// Define output language
1660
+			  	$outputlangs = $langs;
1661
+			   	if (! empty($conf->global->MAIN_MULTILANGS))
1662
+			   	{
1663
+			   		$outputlangs = new Translate("",$conf);
1664
+			   		$newlang=(GETPOST('lang_id','aZ09') ? GETPOST('lang_id','aZ09') : $this->thirdparty->default_lang);
1665
+			   		$outputlangs->setDefaultLang($newlang);
1666
+			   	}
1667
+			   	//$ret=$object->fetch($id);    // Reload to get new records
1668
+				   $this->generateDocument($modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1669
+			}
1670
+
1671
+			// Call trigger
1672
+			$result=$this->call_trigger($trigger_name,$user);
1673
+			if ($result < 0) { $error++; }
1674
+			// End call triggers
1675
+
1676
+			if ( ! $error )
1677
+			{
1678
+				$this->db->commit();
1679
+				return 1;
1680
+			}
1681
+			else
1682
+			{
1683
+				$this->db->rollback();
1684
+				return -1;
1685
+			}
1686
+		}
1687
+		else
1688
+		{
1689
+			$this->error=$this->db->lasterror();
1690
+			$this->errors[]=$this->db->lasterror();
1691
+			$this->db->rollback();
1692
+			return -1;
1693
+		}
1694
+	}
1695
+
1696
+	/**
1697
+	 *	Add or update supplier price according to result of proposal
1698
+	 *
1699
+	 *	@param     User	    $user       Object user
1700
+	 *  @return    int                  > 0 if OK
1701
+	 */
1702
+	function updateOrCreatePriceFournisseur($user)
1703
+	{
1704
+		$productsupplier = new ProductFournisseur($this->db);
1705
+
1706
+		dol_syslog(get_class($this)."::updateOrCreatePriceFournisseur", LOG_DEBUG);
1707
+		foreach ($this->lines as $product)
1708
+		{
1709
+			if ($product->subprice <= 0) continue;
1710
+
1711
+			$idProductFourn = $productsupplier->find_min_price_product_fournisseur($product->fk_product, $product->qty);
1712
+			$res = $productsupplier->fetch($idProductFourn);
1713
+
1714
+			if ($productsupplier->id) {
1715
+				if ($productsupplier->fourn_qty == $product->qty) {
1716
+					$this->updatePriceFournisseur($productsupplier->product_fourn_price_id, $product, $user);
1717
+				} else {
1718
+					$this->createPriceFournisseur($product, $user);
1719
+				}
1720
+			} else {
1721
+				$this->createPriceFournisseur($product, $user);
1722
+			}
1723
+		}
1724
+
1725
+		return 1;
1726
+	}
1727
+
1728
+	/**
1729
+	 *	Upate ProductFournisseur
1730
+	 *
1731
+	 * 	@param		int 	$idProductFournPrice	id of llx_product_fournisseur_price
1732
+	 * 	@param		int 	$product				contain informations to update
1733
+	 *	@param      User	$user					Object user
1734
+	 *	@return     int         					<0 if KO, >0 if OK
1735
+	 */
1736
+	 function updatePriceFournisseur($idProductFournPrice, $product, $user) {
1737
+		$price=price2num($product->subprice*$product->qty,'MU');
1738
+		$unitPrice = price2num($product->subprice,'MU');
1739
+
1740
+		$sql = 'UPDATE '.MAIN_DB_PREFIX.'product_fournisseur_price SET '.(!empty($product->ref_fourn) ? 'ref_fourn = "'.$product->ref_fourn.'", ' : '').' price ='.$price.', unitprice ='.$unitPrice.' WHERE rowid = '.$idProductFournPrice;
1741
+
1742
+		$resql = $this->db->query($sql);
1743
+		if (!$resql) {
1744
+			$this->error=$this->db->error();
1745
+			$this->db->rollback();
1746
+			return -1;
1747
+		}
1748
+	 }
1749
+
1750
+	 /**
1751
+	  *	Create ProductFournisseur
1752
+	  *
1753
+	  *	@param		Product 	$product	Object Product
1754
+	  *	@param      User		$user		Object user
1755
+	  *	@return     int         			<0 if KO, >0 if OK
1756
+	  */
1757
+	 function createPriceFournisseur($product, $user) {
1758
+	 	$price=price2num($product->subprice*$product->qty,'MU');
1759
+		$qty=price2num($product->qty);
1760
+		$unitPrice = price2num($product->subprice,'MU');
1761
+		$now=dol_now();
1762
+
1763
+		$values = array(
1764
+			"'".$this->db->idate($now)."'",
1765
+			$product->fk_product,
1766
+			$this->thirdparty->id,
1767
+			"'".$product->ref_fourn."'",
1768
+			$price,
1769
+			$qty,
1770
+			$unitPrice,
1771
+			$product->tva_tx,
1772
+			$user->id
1773
+		);
1774
+
1775
+		$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'product_fournisseur_price ';
1776
+		$sql .= '(datec, fk_product, fk_soc, ref_fourn, price, quantity, unitprice, tva_tx, fk_user) VALUES ('.implode(',', $values).')';
1777
+
1778
+		$resql = $this->db->query($sql);
1779
+		if (!$resql) {
1780
+			$this->error=$this->db->error();
1781
+			$this->db->rollback();
1782
+			return -1;
1783
+		}
1784
+	 }
1785
+
1786
+	/**
1787
+	 *	Set draft status
1788
+	 *
1789
+	 *	@param		User	$user		Object user that modify
1790
+	 *	@return		int					<0 if KO, >0 if OK
1791
+	 */
1792
+	function set_draft($user)
1793
+	{
1794
+		global $conf,$langs;
1795
+
1796
+		$sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal SET fk_statut = 0";
1797
+		$sql.= " WHERE rowid = ".$this->id;
1798
+
1799
+		if ($this->db->query($sql))
1800
+		{
1801
+			$this->statut = 0;
1802
+			$this->brouillon = 1;
1803
+			return 1;
1804
+		}
1805
+		else
1806
+		{
1807
+			return -1;
1808
+		}
1809
+	}
1810
+
1811
+
1812
+	/**
1813
+	 *    Return list of askprice (eventually filtered on user) into an array
1814
+	 *
1815
+	 *    @param	int		$shortlist			0=Return array[id]=ref, 1=Return array[](id=>id,ref=>ref,name=>name)
1816
+	 *    @param	int		$draft				0=not draft, 1=draft
1817
+	 *    @param	int		$notcurrentuser		0=all user, 1=not current user
1818
+	 *    @param    int		$socid				Id third pary
1819
+	 *    @param    int		$limit				For pagination
1820
+	 *    @param    int		$offset				For pagination
1821
+	 *    @param    string	$sortfield			Sort criteria
1822
+	 *    @param    string	$sortorder			Sort order
1823
+	 *    @return	int		       				-1 if KO, array with result if OK
1824
+	 */
1825
+	function liste_array($shortlist=0, $draft=0, $notcurrentuser=0, $socid=0, $limit=0, $offset=0, $sortfield='p.datec', $sortorder='DESC')
1826
+	{
1827
+		global $conf,$user;
1828
+
1829
+		$ga = array();
1830
+
1831
+		$sql = "SELECT s.rowid, s.nom as name, s.client,";
1832
+		$sql.= " p.rowid as supplier_proposalid, p.fk_statut, p.total_ht, p.ref, p.remise, ";
1833
+		$sql.= " p.datep as dp, p.fin_validite as datelimite";
1834
+		if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", sc.fk_soc, sc.fk_user";
1835
+		$sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."supplier_proposal as p, ".MAIN_DB_PREFIX."c_propalst as c";
1836
+		if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1837
+		$sql.= " WHERE p.entity = ".$conf->entity;
1838
+		$sql.= " AND p.fk_soc = s.rowid";
1839
+		$sql.= " AND p.fk_statut = c.id";
1840
+		if (! $user->rights->societe->client->voir && ! $socid) //restriction
1841
+		{
1842
+			$sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
1843
+		}
1844
+		if ($socid) $sql.= " AND s.rowid = ".$socid;
1845
+		if ($draft)	$sql.= " AND p.fk_statut = 0";
1846
+		if ($notcurrentuser > 0) $sql.= " AND p.fk_user_author <> ".$user->id;
1847
+		$sql.= $this->db->order($sortfield,$sortorder);
1848
+		$sql.= $this->db->plimit($limit,$offset);
1849
+
1850
+		$result=$this->db->query($sql);
1851
+		if ($result)
1852
+		{
1853
+			$num = $this->db->num_rows($result);
1854
+			if ($num)
1855
+			{
1856
+				$i = 0;
1857
+				while ($i < $num)
1858
+				{
1859
+					$obj = $this->db->fetch_object($result);
1860
+
1861
+					if ($shortlist == 1)
1862
+					{
1863
+						$ga[$obj->supplier_proposalid] = $obj->ref;
1864
+					}
1865
+					else if ($shortlist == 2)
1866
+					{
1867
+						$ga[$obj->supplier_proposalid] = $obj->ref.' ('.$obj->name.')';
1868
+					}
1869
+					else
1870
+					{
1871
+						$ga[$i]['id']	= $obj->supplier_proposalid;
1872
+						$ga[$i]['ref'] 	= $obj->ref;
1873
+						$ga[$i]['name'] = $obj->name;
1874
+					}
1875
+
1876
+					$i++;
1877
+				}
1878
+			}
1879
+			return $ga;
1880
+		}
1881
+		else
1882
+		{
1883
+			dol_print_error($this->db);
1884
+			return -1;
1885
+		}
1886
+	}
1887
+
1888
+	/**
1889
+	 *	Delete askprice
1890
+	 *
1891
+	 *	@param	User	$user        	Object user that delete
1892
+	 *	@param	int		$notrigger		1=Does not execute triggers, 0= execute triggers
1893
+	 *	@return	int						1 if ok, otherwise if error
1894
+	 */
1895
+	function delete($user, $notrigger=0)
1896
+	{
1897
+		global $conf,$langs;
1898
+		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1899
+
1900
+		$error=0;
1901
+
1902
+		$this->db->begin();
1903
+
1904
+		if (! $notrigger)
1905
+		{
1906
+			// Call trigger
1907
+			$result=$this->call_trigger('SUPPLIER_PROPOSAL_DELETE',$user);
1908
+			if ($result < 0) { $error++; }
1909
+			// End call triggers
1910
+		}
1911
+
1912
+		if (! $error)
1913
+		{
1914
+			$sql = "DELETE FROM ".MAIN_DB_PREFIX."supplier_proposaldet WHERE fk_supplier_proposal = ".$this->id;
1915
+			if ($this->db->query($sql))
1916
+			{
1917
+				$sql = "DELETE FROM ".MAIN_DB_PREFIX."supplier_proposal WHERE rowid = ".$this->id;
1918
+				if ($this->db->query($sql))
1919
+				{
1920
+					// Delete linked object
1921
+					$res = $this->deleteObjectLinked();
1922
+					if ($res < 0) $error++;
1923
+
1924
+					if (! $error)
1925
+					{
1926
+						// We remove directory
1927
+						$ref = dol_sanitizeFileName($this->ref);
1928
+						if ($conf->supplier_proposal->dir_output && !empty($this->ref))
1929
+						{
1930
+							$dir = $conf->supplier_proposal->dir_output . "/" . $ref ;
1931
+							$file = $dir . "/" . $ref . ".pdf";
1932
+							if (file_exists($file))
1933
+							{
1934
+								dol_delete_preview($this);
1935
+
1936
+								if (! dol_delete_file($file,0,0,0,$this)) // For triggers
1937
+								{
1938
+									$this->error='ErrorFailToDeleteFile';
1939
+									$this->errors=array('ErrorFailToDeleteFile');
1940
+									$this->db->rollback();
1941
+									return 0;
1942
+								}
1943
+							}
1944
+							if (file_exists($dir))
1945
+							{
1946
+								$res=@dol_delete_dir_recursive($dir);
1947
+								if (! $res)
1948
+								{
1949
+									$this->error='ErrorFailToDeleteDir';
1950
+									$this->errors=array('ErrorFailToDeleteDir');
1951
+									$this->db->rollback();
1952
+									return 0;
1953
+								}
1954
+							}
1955
+						}
1956
+					}
1957
+
1958
+					// Removed extrafields
1959
+					if (! $error)
1960
+					{
1961
+						if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
1962
+						{
1963
+							$result=$this->deleteExtraFields();
1964
+							if ($result < 0)
1965
+							{
1966
+								$error++;
1967
+								$errorflag=-4;
1968
+								dol_syslog(get_class($this)."::delete erreur ".$errorflag." ".$this->error, LOG_ERR);
1969
+							}
1970
+						}
1971
+					}
1972
+
1973
+					if (! $error)
1974
+					{
1975
+						dol_syslog(get_class($this)."::delete ".$this->id." by ".$user->id, LOG_DEBUG);
1976
+						$this->db->commit();
1977
+						return 1;
1978
+					}
1979
+					else
1980
+					{
1981
+						$this->error=$this->db->lasterror();
1982
+						$this->db->rollback();
1983
+						return 0;
1984
+					}
1985
+				}
1986
+				else
1987
+				{
1988
+					$this->error=$this->db->lasterror();
1989
+					$this->db->rollback();
1990
+					return -3;
1991
+				}
1992
+			}
1993
+			else
1994
+			{
1995
+				$this->error=$this->db->lasterror();
1996
+				$this->db->rollback();
1997
+				return -2;
1998
+			}
1999
+		}
2000
+		else
2001
+		{
2002
+			$this->db->rollback();
2003
+			return -1;
2004
+		}
2005
+	}
2006
+
2007
+	/**
2008
+	 *	Object SupplierProposal Information
2009
+	 *
2010
+	 * 	@param	int		$id		Proposal id
2011
+	 *  @return	void
2012
+	 */
2013
+	function info($id)
2014
+	{
2015
+		$sql = "SELECT c.rowid, ";
2016
+		$sql.= " c.datec, c.date_valid as datev, c.date_cloture as dateo,";
2017
+		$sql.= " c.fk_user_author, c.fk_user_valid, c.fk_user_cloture";
2018
+		$sql.= " FROM ".MAIN_DB_PREFIX."supplier_proposal as c";
2019
+		$sql.= " WHERE c.rowid = ".$id;
2020
+
2021
+		$result = $this->db->query($sql);
2022
+
2023
+		if ($result)
2024
+		{
2025
+			if ($this->db->num_rows($result))
2026
+			{
2027
+				$obj = $this->db->fetch_object($result);
2028
+
2029
+				$this->id                = $obj->rowid;
2030
+
2031
+				$this->date_creation     = $this->db->jdate($obj->datec);
2032
+				$this->date_validation   = $this->db->jdate($obj->datev);
2033
+				$this->date_cloture      = $this->db->jdate($obj->dateo);
2034
+
2035
+				$cuser = new User($this->db);
2036
+				$cuser->fetch($obj->fk_user_author);
2037
+				$this->user_creation     = $cuser;
2038
+
2039
+				if ($obj->fk_user_valid)
2040
+				{
2041
+					$vuser = new User($this->db);
2042
+					$vuser->fetch($obj->fk_user_valid);
2043
+					$this->user_validation     = $vuser;
2044
+				}
2045
+
2046
+				if ($obj->fk_user_cloture)
2047
+				{
2048
+					$cluser = new User($this->db);
2049
+					$cluser->fetch($obj->fk_user_cloture);
2050
+					$this->user_cloture     = $cluser;
2051
+				}
2052
+
2053
+
2054
+			}
2055
+			$this->db->free($result);
2056
+
2057
+		}
2058
+		else
2059
+		{
2060
+			dol_print_error($this->db);
2061
+		}
2062
+	}
2063
+
2064
+
2065
+	/**
2066
+	 *    	Return label of status of proposal (draft, validated, ...)
2067
+	 *
2068
+	 *    	@param      int			$mode        0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
2069
+	 *    	@return     string		Label
2070
+	 */
2071
+	function getLibStatut($mode=0)
2072
+	{
2073
+		return $this->LibStatut($this->statut,$mode);
2074
+	}
2075
+
2076
+	/**
2077
+	 *    	Return label of a status (draft, validated, ...)
2078
+	 *
2079
+	 *    	@param      int			$statut		id statut
2080
+	 *    	@param      int			$mode      	0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
2081
+	 *    	@return     string		Label
2082
+	 */
2083
+	function LibStatut($statut,$mode=1)
2084
+	{
2085
+		global $langs;
2086
+		$langs->load("supplier_proposal");
2087
+
2088
+		if ($statut==0) $statuttrans='statut0';
2089
+		if ($statut==1) $statuttrans='statut1';
2090
+		if ($statut==2) $statuttrans='statut3';
2091
+		if ($statut==3) $statuttrans='statut5';
2092
+		if ($statut==4) $statuttrans='statut6';
2093
+
2094
+		if ($mode == 0)	return $this->labelstatut[$statut];
2095
+		if ($mode == 1)	return $this->labelstatut_short[$statut];
2096
+		if ($mode == 2)	return img_picto($this->labelstatut[$statut], $statuttrans).' '.$this->labelstatut_short[$statut];
2097
+		if ($mode == 3)	return img_picto($this->labelstatut[$statut], $statuttrans);
2098
+		if ($mode == 4)	return img_picto($this->labelstatut[$statut],$statuttrans).' '.$this->labelstatut[$statut];
2099
+		if ($mode == 5)	return '<span class="hideonsmartphone">'.$this->labelstatut_short[$statut].' </span>'.img_picto($this->labelstatut[$statut],$statuttrans);
2100
+		if ($mode == 6)	return '<span class="hideonsmartphone">'.$this->labelstatut[$statut].' </span>'.img_picto($this->labelstatut[$statut],$statuttrans);
2101
+	}
2102
+
2103
+
2104
+	/**
2105
+	 *      Load indicators for dashboard (this->nbtodo and this->nbtodolate)
2106
+	 *
2107
+	 *      @param          User	$user   Object user
2108
+	 *      @param          int		$mode   "opened" for askprice to close, "signed" for proposal to invoice
2109
+	 *      @return         int     		<0 if KO, >0 if OK
2110
+	 */
2111
+	function load_board($user,$mode)
2112
+	{
2113
+		global $conf, $user, $langs;
2114
+
2115
+		$now=dol_now();
2116
+
2117
+		$this->nbtodo=$this->nbtodolate=0;
2118
+		$clause = " WHERE";
2119
+
2120
+		$sql = "SELECT p.rowid, p.ref, p.datec as datec";
2121
+		$sql.= " FROM ".MAIN_DB_PREFIX."supplier_proposal as p";
2122
+		if (!$user->rights->societe->client->voir && !$user->societe_id)
2123
+		{
2124
+			$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc";
2125
+			$sql.= " WHERE sc.fk_user = " .$user->id;
2126
+			$clause = " AND";
2127
+		}
2128
+		$sql.= $clause." p.entity = ".$conf->entity;
2129
+		if ($mode == 'opened') $sql.= " AND p.fk_statut = 1";
2130
+		if ($mode == 'signed') $sql.= " AND p.fk_statut = 2";
2131
+		if ($user->societe_id) $sql.= " AND p.fk_soc = ".$user->societe_id;
2132
+
2133
+		$resql=$this->db->query($sql);
2134
+		if ($resql)
2135
+		{
2136
+			if ($mode == 'opened') {
2137
+				$delay_warning=$conf->supplier_proposal->cloture->warning_delay;
2138
+				$statut = self::STATUS_VALIDATED;
2139
+				$label = $langs->trans("SupplierProposalsToClose");
2140
+			}
2141
+			if ($mode == 'signed') {
2142
+				$delay_warning=$conf->supplier_proposal->facturation->warning_delay;
2143
+				$statut = self::STATUS_SIGNED;
2144
+				$label = $langs->trans("SupplierProposalsToProcess");      // May be billed or ordered
2145
+			}
2146
+
2147
+			$response = new WorkboardResponse();
2148
+			$response->warning_delay = $delay_warning/60/60/24;
2149
+			$response->label = $label;
2150
+			$response->url = DOL_URL_ROOT.'/supplier_proposal/list.php?viewstatut='.$statut;
2151
+			$response->img = img_object('',"propal");
2152
+
2153
+			// This assignment in condition is not a bug. It allows walking the results.
2154
+			while ($obj=$this->db->fetch_object($resql))
2155
+			{
2156
+				$response->nbtodo++;
2157
+				if ($mode == 'opened')
2158
+				{
2159
+					$datelimit = $this->db->jdate($obj->datefin);
2160
+					if ($datelimit < ($now - $delay_warning))
2161
+					{
2162
+						$response->nbtodolate++;
2163
+					}
2164
+				}
2165
+				// TODO Definir regle des propales a facturer en retard
2166
+				// if ($mode == 'signed' && ! count($this->FactureListeArray($obj->rowid))) $this->nbtodolate++;
2167
+			}
2168
+			return $response;
2169
+		}
2170
+		else
2171
+		{
2172
+			$this->error=$this->db->lasterror();
2173
+			return -1;
2174
+		}
2175
+	}
2176
+
2177
+
2178
+	/**
2179
+	 *  Initialise an instance with random values.
2180
+	 *  Used to build previews or test instances.
2181
+	 *	id must be 0 if object instance is a specimen.
2182
+	 *
2183
+	 *  @return	void
2184
+	 */
2185
+	function initAsSpecimen()
2186
+	{
2187
+		global $user,$langs,$conf;
2188
+
2189
+		// Load array of products prodids
2190
+		$num_prods = 0;
2191
+		$prodids = array();
2192
+		$sql = "SELECT rowid";
2193
+		$sql.= " FROM ".MAIN_DB_PREFIX."product";
2194
+		$sql.= " WHERE entity IN (".getEntity('product').")";
2195
+		$resql = $this->db->query($sql);
2196
+		if ($resql)
2197
+		{
2198
+			$num_prods = $this->db->num_rows($resql);
2199
+			$i = 0;
2200
+			while ($i < $num_prods)
2201
+			{
2202
+				$i++;
2203
+				$row = $this->db->fetch_row($resql);
2204
+				$prodids[$i] = $row[0];
2205
+			}
2206
+		}
2207
+
2208
+		// Initialise parametres
2209
+		$this->id=0;
2210
+		$this->ref = 'SPECIMEN';
2211
+		$this->specimen=1;
2212
+		$this->socid = 1;
2213
+		$this->date = time();
2214
+		$this->cond_reglement_id   = 1;
2215
+		$this->cond_reglement_code = 'RECEP';
2216
+		$this->mode_reglement_id   = 7;
2217
+		$this->mode_reglement_code = 'CHQ';
2218
+		$this->note_public='This is a comment (public)';
2219
+		$this->note_private='This is a comment (private)';
2220
+		// Lines
2221
+		$nbp = 5;
2222
+		$xnbp = 0;
2223
+		while ($xnbp < $nbp)
2224
+		{
2225
+			$line=new SupplierProposalLine($this->db);
2226
+			$line->desc=$langs->trans("Description")." ".$xnbp;
2227
+			$line->qty=1;
2228
+			$line->subprice=100;
2229
+			$line->price=100;
2230
+			$line->tva_tx=19.6;
2231
+			$line->localtax1_tx=0;
2232
+			$line->localtax2_tx=0;
2233
+			if ($xnbp == 2)
2234
+			{
2235
+				$line->total_ht=50;
2236
+				$line->total_ttc=59.8;
2237
+				$line->total_tva=9.8;
2238
+				$line->remise_percent=50;
2239
+			}
2240
+			else
2241
+			{
2242
+				$line->total_ht=100;
2243
+				$line->total_ttc=119.6;
2244
+				$line->total_tva=19.6;
2245
+				$line->remise_percent=00;
2246
+			}
2247
+
2248
+			if ($num_prods > 0)
2249
+			{
2250
+				$prodid = mt_rand(1, $num_prods);
2251
+				$line->fk_product=$prodids[$prodid];
2252
+			}
2253
+
2254
+			$this->lines[$xnbp]=$line;
2255
+
2256
+			$this->total_ht       += $line->total_ht;
2257
+			$this->total_tva      += $line->total_tva;
2258
+			$this->total_ttc      += $line->total_ttc;
2259
+
2260
+			$xnbp++;
2261
+		}
2262
+	}
2263
+
2264
+	/**
2265
+	 *      Charge indicateurs this->nb de tableau de bord
2266
+	 *
2267
+	 *      @return     int         <0 if ko, >0 if ok
2268
+	 */
2269
+	function load_state_board()
2270
+	{
2271
+		global $conf, $user;
1572 2272
 
1573
-    	$this->db->begin();
2273
+		$this->nb=array();
2274
+		$clause = "WHERE";
1574 2275
 
1575
-		dol_syslog(get_class($this)."::reopen", LOG_DEBUG);
1576
-		$resql = $this->db->query($sql);
1577
-		if (! $resql) {
1578
-			$error++; $this->errors[]="Error ".$this->db->lasterror();
1579
-		}
1580
-		if (! $error)
2276
+		$sql = "SELECT count(p.rowid) as nb";
2277
+		$sql.= " FROM ".MAIN_DB_PREFIX."supplier_proposal as p";
2278
+		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON p.fk_soc = s.rowid";
2279
+		if (!$user->rights->societe->client->voir && !$user->societe_id)
1581 2280
 		{
1582
-			if (! $notrigger)
1583
-			{
1584
-                // Call trigger
1585
-                $result=$this->call_trigger('SUPPLIER_PROPOSAL_REOPEN',$user);
1586
-                if ($result < 0) { $error++; }
1587
-                // End call triggers
1588
-			}
2281
+			$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
2282
+			$sql.= " WHERE sc.fk_user = " .$user->id;
2283
+			$clause = "AND";
1589 2284
 		}
2285
+		$sql.= " ".$clause." p.entity = ".$conf->entity;
1590 2286
 
1591
-		// Commit or rollback
1592
-		if ($error)
2287
+		$resql=$this->db->query($sql);
2288
+		if ($resql)
1593 2289
 		{
1594
-		    if (!empty($this->errors))
1595
-		    {
1596
-    			foreach($this->errors as $errmsg)
1597
-    			{
1598
-    				dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
1599
-    				$this->error.=($this->error?', '.$errmsg:$errmsg);
1600
-    			}
1601
-		    }
1602
-			$this->db->rollback();
1603
-			return -1*$error;
2290
+			// This assignment in condition is not a bug. It allows walking the results.
2291
+			while ($obj=$this->db->fetch_object($resql))
2292
+			{
2293
+				$this->nb["askprice"]=$obj->nb;
2294
+			}
2295
+			$this->db->free($resql);
2296
+			return 1;
1604 2297
 		}
1605 2298
 		else
1606 2299
 		{
1607
-			$this->db->commit();
1608
-			return 1;
2300
+			dol_print_error($this->db);
2301
+			$this->error=$this->db->lasterror();
2302
+			return -1;
1609 2303
 		}
1610
-    }
1611
-
1612
-
1613
-    /**
1614
-     *	Close the askprice
1615
-     *
1616
-     *	@param      User	$user		Object user that close
1617
-     *	@param      int		$statut		Statut
1618
-     *	@param      string	$note		Comment
1619
-     *	@return     int         		<0 if KO, >0 if OK
1620
-     */
1621
-    function cloture($user, $statut, $note)
1622
-    {
1623
-        global $langs,$conf;
2304
+	}
1624 2305
 
1625
-        $this->statut = $statut;
1626
-        $error=0;
1627
-        $now=dol_now();
1628 2306
 
1629
-        $this->db->begin();
2307
+	/**
2308
+	 *  Returns the reference to the following non used Proposal used depending on the active numbering module
2309
+	 *  defined into SUPPLIER_PROPOSAL_ADDON
2310
+	 *
2311
+	 *  @param	Societe		$soc  	Object thirdparty
2312
+	 *  @return string      		Reference libre pour la propale
2313
+	 */
2314
+	function getNextNumRef($soc)
2315
+	{
2316
+		global $conf, $db, $langs;
2317
+		$langs->load("supplier_proposal");
1630 2318
 
1631
-        $sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal";
1632
-        $sql.= " SET fk_statut = ".$statut.", note_private = '".$this->db->escape($note)."', date_cloture='".$this->db->idate($now)."', fk_user_cloture=".$user->id;
1633
-        $sql.= " WHERE rowid = ".$this->id;
2319
+		if (! empty($conf->global->SUPPLIER_PROPOSAL_ADDON))
2320
+		{
2321
+			$mybool=false;
1634 2322
 
1635
-        $resql=$this->db->query($sql);
1636
-        if ($resql)
1637
-        {
1638
-        	$modelpdf=$conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_CLOSED?$conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_CLOSED:$this->modelpdf;
1639
-        	$trigger_name='SUPPLIER_PROPOSAL_CLOSE_REFUSED';
2323
+			$file = $conf->global->SUPPLIER_PROPOSAL_ADDON.".php";
2324
+			$classname = $conf->global->SUPPLIER_PROPOSAL_ADDON;
1640 2325
 
1641
-            if ($statut == 2)
1642
-            {
1643
-            	$trigger_name='SUPPLIER_PROPOSAL_CLOSE_SIGNED';
1644
-				$modelpdf=$conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL?$conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL:$this->modelpdf;
2326
+			// Include file with class
2327
+			$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
2328
+			foreach ($dirmodels as $reldir) {
1645 2329
 
1646
-                if (! empty($conf->global->SUPPLIER_PROPOSAL_UPDATE_PRICE_ON_SUPPlIER_PROPOSAL))     // TODO This option was not tested correctly. Error if product ref does not exists
1647
-                {
1648
-                    $result = $this->updateOrCreatePriceFournisseur($user);
1649
-                }
1650
-
1651
-            }
1652
-            if ($statut == 4)
1653
-            {
1654
-            	$trigger_name='SUPPLIER_PROPOSAL_CLASSIFY_BILLED';
1655
-            }
1656
-
1657
-            if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
1658
-            {
1659
-             	// Define output language
1660
-              	$outputlangs = $langs;
1661
-               	if (! empty($conf->global->MAIN_MULTILANGS))
1662
-               	{
1663
-               		$outputlangs = new Translate("",$conf);
1664
-               		$newlang=(GETPOST('lang_id','aZ09') ? GETPOST('lang_id','aZ09') : $this->thirdparty->default_lang);
1665
-               		$outputlangs->setDefaultLang($newlang);
1666
-               	}
1667
-               	//$ret=$object->fetch($id);    // Reload to get new records
1668
-	               $this->generateDocument($modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1669
-            }
1670
-
1671
-            // Call trigger
1672
-            $result=$this->call_trigger($trigger_name,$user);
1673
-            if ($result < 0) { $error++; }
1674
-            // End call triggers
1675
-
1676
-            if ( ! $error )
1677
-            {
1678
-                $this->db->commit();
1679
-                return 1;
1680
-            }
1681
-            else
1682
-            {
1683
-                $this->db->rollback();
1684
-                return -1;
1685
-            }
1686
-        }
1687
-        else
1688
-        {
1689
-            $this->error=$this->db->lasterror();
1690
-            $this->errors[]=$this->db->lasterror();
1691
-            $this->db->rollback();
1692
-            return -1;
1693
-        }
1694
-    }
2330
+				$dir = dol_buildpath($reldir."core/modules/supplier_proposal/");
1695 2331
 
1696
-	/**
1697
-     *	Add or update supplier price according to result of proposal
1698
-     *
1699
-	 *	@param     User	    $user       Object user
1700
-	 *  @return    int                  > 0 if OK
1701
-     */
1702
-	function updateOrCreatePriceFournisseur($user)
1703
-	{
1704
-		$productsupplier = new ProductFournisseur($this->db);
2332
+				// Load file with numbering class (if found)
2333
+				$mybool|=@include_once $dir.$file;
2334
+			}
1705 2335
 
1706
-		dol_syslog(get_class($this)."::updateOrCreatePriceFournisseur", LOG_DEBUG);
1707
-		foreach ($this->lines as $product)
1708
-		{
1709
-			if ($product->subprice <= 0) continue;
2336
+			if (! $mybool)
2337
+			{
2338
+				dol_print_error('',"Failed to include file ".$file);
2339
+				return '';
2340
+			}
1710 2341
 
1711
-			$idProductFourn = $productsupplier->find_min_price_product_fournisseur($product->fk_product, $product->qty);
1712
-			$res = $productsupplier->fetch($idProductFourn);
2342
+			$obj = new $classname();
2343
+			$numref = "";
2344
+			$numref = $obj->getNextValue($soc,$this);
1713 2345
 
1714
-			if ($productsupplier->id) {
1715
-				if ($productsupplier->fourn_qty == $product->qty) {
1716
-					$this->updatePriceFournisseur($productsupplier->product_fourn_price_id, $product, $user);
1717
-				} else {
1718
-					$this->createPriceFournisseur($product, $user);
1719
-				}
1720
-			} else {
1721
-				$this->createPriceFournisseur($product, $user);
2346
+			if ($numref != "")
2347
+			{
2348
+				return $numref;
2349
+			}
2350
+			else
2351
+			{
2352
+				$this->error=$obj->error;
2353
+				return "";
1722 2354
 			}
1723 2355
 		}
1724
-
1725
-		return 1;
2356
+		else
2357
+		{
2358
+			$langs->load("errors");
2359
+			print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete");
2360
+			return "";
2361
+		}
1726 2362
 	}
1727 2363
 
1728 2364
 	/**
1729
-     *	Upate ProductFournisseur
1730
-     *
1731
-	 * 	@param		int 	$idProductFournPrice	id of llx_product_fournisseur_price
1732
-	 * 	@param		int 	$product				contain informations to update
1733
-	 *	@param      User	$user					Object user
1734
-     *	@return     int         					<0 if KO, >0 if OK
1735
-     */
1736
-     function updatePriceFournisseur($idProductFournPrice, $product, $user) {
1737
-		$price=price2num($product->subprice*$product->qty,'MU');
1738
-		$unitPrice = price2num($product->subprice,'MU');
1739
-
1740
-		$sql = 'UPDATE '.MAIN_DB_PREFIX.'product_fournisseur_price SET '.(!empty($product->ref_fourn) ? 'ref_fourn = "'.$product->ref_fourn.'", ' : '').' price ='.$price.', unitprice ='.$unitPrice.' WHERE rowid = '.$idProductFournPrice;
1741
-
1742
-		$resql = $this->db->query($sql);
1743
-		if (!$resql) {
1744
-			$this->error=$this->db->error();
1745
-            $this->db->rollback();
1746
-            return -1;
1747
-		}
1748
-	 }
1749
-
1750
-	 /**
1751
-     *	Create ProductFournisseur
2365
+	 *	Return clicable link of object (with eventually picto)
1752 2366
 	 *
1753
-     *	@param		Product 	$product	Object Product
1754
-	 *	@param      User		$user		Object user
1755
-     *	@return     int         			<0 if KO, >0 if OK
1756
-     */
1757
-	 function createPriceFournisseur($product, $user) {
1758
-	 	$price=price2num($product->subprice*$product->qty,'MU');
1759
-	    $qty=price2num($product->qty);
1760
-		$unitPrice = price2num($product->subprice,'MU');
1761
-		$now=dol_now();
1762
-
1763
-		$values = array(
1764
-			"'".$this->db->idate($now)."'",
1765
-			$product->fk_product,
1766
-			$this->thirdparty->id,
1767
-			"'".$product->ref_fourn."'",
1768
-			$price,
1769
-			$qty,
1770
-			$unitPrice,
1771
-			$product->tva_tx,
1772
-			$user->id
1773
-		);
2367
+	 *	@param      int		$withpicto					Add picto into link
2368
+	 *	@param      string	$option						Where point the link ('compta', 'expedition', 'document', ...)
2369
+	 *	@param      string	$get_params    				Parametres added to url
2370
+	 *  @param	    int   	$notooltip					1=Disable tooltip
2371
+	 *  @param      int     $save_lastsearch_value		-1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
2372
+	 *	@return     string          					String with URL
2373
+	 */
2374
+	function getNomUrl($withpicto=0, $option='', $get_params='', $notooltip=0, $save_lastsearch_value=-1)
2375
+	{
2376
+		global $langs, $conf, $user;
2377
+
2378
+		if (! empty($conf->dol_no_mouse_hover)) $notooltip=1;   // Force disable tooltips
2379
+
2380
+		$url='';
2381
+		$result='';
2382
+
2383
+		$label='<u>'.$langs->trans("ShowSupplierProposal").'</u>';
2384
+		if (! empty($this->ref))
2385
+		$label.= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
2386
+		if (! empty($this->ref_fourn))
2387
+			$label.= '<br><b>'.$langs->trans('RefSupplier').':</b> '.$this->ref_fourn;
2388
+		if (! empty($this->total_ht))
2389
+			$label.= '<br><b>' . $langs->trans('AmountHT') . ':</b> ' . price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
2390
+		if (! empty($this->total_tva))
2391
+			$label.= '<br><b>' . $langs->trans('VAT') . ':</b> ' . price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
2392
+		if (! empty($this->total_ttc))
2393
+			$label.= '<br><b>' . $langs->trans('AmountTTC') . ':</b> ' . price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
2394
+		if ($option == '') {
2395
+			$url = DOL_URL_ROOT.'/supplier_proposal/card.php?id='.$this->id. $get_params;
2396
+		}
2397
+		if ($option == 'document') {
2398
+			$url = DOL_URL_ROOT.'/supplier_proposal/document.php?id='.$this->id. $get_params;
2399
+		}
1774 2400
 
1775
-		$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'product_fournisseur_price ';
1776
-		$sql .= '(datec, fk_product, fk_soc, ref_fourn, price, quantity, unitprice, tva_tx, fk_user) VALUES ('.implode(',', $values).')';
2401
+		if ($option !== 'nolink')
2402
+		{
2403
+			// Add param to save lastsearch_values or not
2404
+			$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
2405
+			if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
2406
+			if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
2407
+		}
1777 2408
 
1778
-		$resql = $this->db->query($sql);
1779
-		if (!$resql) {
1780
-			$this->error=$this->db->error();
1781
-            $this->db->rollback();
1782
-            return -1;
2409
+		$linkclose='';
2410
+		if (empty($notooltip) && $user->rights->propal->lire)
2411
+		{
2412
+			if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
2413
+			{
2414
+				$label=$langs->trans("ShowSupplierProposal");
2415
+				$linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
2416
+			}
2417
+			$linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
2418
+			$linkclose.=' class="classfortooltip"';
1783 2419
 		}
1784
-	 }
1785 2420
 
1786
-    /**
1787
-     *	Set draft status
1788
-     *
1789
-     *	@param		User	$user		Object user that modify
1790
-     *	@return		int					<0 if KO, >0 if OK
1791
-     */
1792
-    function set_draft($user)
1793
-    {
1794
-        global $conf,$langs;
1795
-
1796
-        $sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal SET fk_statut = 0";
1797
-        $sql.= " WHERE rowid = ".$this->id;
1798
-
1799
-        if ($this->db->query($sql))
1800
-        {
1801
-            $this->statut = 0;
1802
-            $this->brouillon = 1;
1803
-            return 1;
1804
-        }
1805
-        else
1806
-        {
1807
-            return -1;
1808
-        }
1809
-    }
1810
-
1811
-
1812
-    /**
1813
-     *    Return list of askprice (eventually filtered on user) into an array
1814
-     *
1815
-     *    @param	int		$shortlist			0=Return array[id]=ref, 1=Return array[](id=>id,ref=>ref,name=>name)
1816
-     *    @param	int		$draft				0=not draft, 1=draft
1817
-     *    @param	int		$notcurrentuser		0=all user, 1=not current user
1818
-     *    @param    int		$socid				Id third pary
1819
-     *    @param    int		$limit				For pagination
1820
-     *    @param    int		$offset				For pagination
1821
-     *    @param    string	$sortfield			Sort criteria
1822
-     *    @param    string	$sortorder			Sort order
1823
-     *    @return	int		       				-1 if KO, array with result if OK
1824
-     */
1825
-    function liste_array($shortlist=0, $draft=0, $notcurrentuser=0, $socid=0, $limit=0, $offset=0, $sortfield='p.datec', $sortorder='DESC')
1826
-    {
1827
-        global $conf,$user;
1828
-
1829
-        $ga = array();
1830
-
1831
-        $sql = "SELECT s.rowid, s.nom as name, s.client,";
1832
-        $sql.= " p.rowid as supplier_proposalid, p.fk_statut, p.total_ht, p.ref, p.remise, ";
1833
-        $sql.= " p.datep as dp, p.fin_validite as datelimite";
1834
-        if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", sc.fk_soc, sc.fk_user";
1835
-        $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."supplier_proposal as p, ".MAIN_DB_PREFIX."c_propalst as c";
1836
-		if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1837
-        $sql.= " WHERE p.entity = ".$conf->entity;
1838
-        $sql.= " AND p.fk_soc = s.rowid";
1839
-        $sql.= " AND p.fk_statut = c.id";
1840
-        if (! $user->rights->societe->client->voir && ! $socid) //restriction
1841
-        {
1842
-        	$sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
1843
-        }
1844
-        if ($socid) $sql.= " AND s.rowid = ".$socid;
1845
-        if ($draft)	$sql.= " AND p.fk_statut = 0";
1846
-        if ($notcurrentuser > 0) $sql.= " AND p.fk_user_author <> ".$user->id;
1847
-        $sql.= $this->db->order($sortfield,$sortorder);
1848
-        $sql.= $this->db->plimit($limit,$offset);
1849
-
1850
-        $result=$this->db->query($sql);
1851
-        if ($result)
1852
-        {
1853
-            $num = $this->db->num_rows($result);
1854
-            if ($num)
1855
-            {
1856
-                $i = 0;
1857
-                while ($i < $num)
1858
-                {
1859
-                    $obj = $this->db->fetch_object($result);
1860
-
1861
-                    if ($shortlist == 1)
1862
-                    {
1863
-                        $ga[$obj->supplier_proposalid] = $obj->ref;
1864
-                    }
1865
-                    else if ($shortlist == 2)
1866
-                    {
1867
-                        $ga[$obj->supplier_proposalid] = $obj->ref.' ('.$obj->name.')';
1868
-                    }
1869
-                    else
1870
-					{
1871
-                        $ga[$i]['id']	= $obj->supplier_proposalid;
1872
-                        $ga[$i]['ref'] 	= $obj->ref;
1873
-                        $ga[$i]['name'] = $obj->name;
1874
-                    }
1875
-
1876
-                    $i++;
1877
-                }
1878
-            }
1879
-            return $ga;
1880
-        }
1881
-        else
1882
-        {
1883
-            dol_print_error($this->db);
1884
-            return -1;
1885
-        }
1886
-    }
1887
-
1888
-    /**
1889
-     *	Delete askprice
1890
-     *
1891
-     *	@param	User	$user        	Object user that delete
1892
-     *	@param	int		$notrigger		1=Does not execute triggers, 0= execute triggers
1893
-     *	@return	int						1 if ok, otherwise if error
1894
-     */
1895
-    function delete($user, $notrigger=0)
1896
-    {
1897
-        global $conf,$langs;
1898
-        require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1899
-
1900
-        $error=0;
1901
-
1902
-        $this->db->begin();
1903
-
1904
-        if (! $notrigger)
1905
-        {
1906
-            // Call trigger
1907
-            $result=$this->call_trigger('SUPPLIER_PROPOSAL_DELETE',$user);
1908
-            if ($result < 0) { $error++; }
1909
-            // End call triggers
1910
-        }
1911
-
1912
-        if (! $error)
1913
-        {
1914
-            $sql = "DELETE FROM ".MAIN_DB_PREFIX."supplier_proposaldet WHERE fk_supplier_proposal = ".$this->id;
1915
-            if ($this->db->query($sql))
1916
-            {
1917
-                $sql = "DELETE FROM ".MAIN_DB_PREFIX."supplier_proposal WHERE rowid = ".$this->id;
1918
-                if ($this->db->query($sql))
1919
-                {
1920
-                    // Delete linked object
1921
-                    $res = $this->deleteObjectLinked();
1922
-                    if ($res < 0) $error++;
1923
-
1924
-                    if (! $error)
1925
-                    {
1926
-                        // We remove directory
1927
-                        $ref = dol_sanitizeFileName($this->ref);
1928
-                        if ($conf->supplier_proposal->dir_output && !empty($this->ref))
1929
-                        {
1930
-                            $dir = $conf->supplier_proposal->dir_output . "/" . $ref ;
1931
-                            $file = $dir . "/" . $ref . ".pdf";
1932
-                            if (file_exists($file))
1933
-                            {
1934
-                                dol_delete_preview($this);
1935
-
1936
-                                if (! dol_delete_file($file,0,0,0,$this)) // For triggers
1937
-                                {
1938
-                                    $this->error='ErrorFailToDeleteFile';
1939
-                                    $this->errors=array('ErrorFailToDeleteFile');
1940
-                                	$this->db->rollback();
1941
-                                    return 0;
1942
-                                }
1943
-                            }
1944
-                            if (file_exists($dir))
1945
-                            {
1946
-                                $res=@dol_delete_dir_recursive($dir);
1947
-                                if (! $res)
1948
-                                {
1949
-                                    $this->error='ErrorFailToDeleteDir';
1950
-                                    $this->errors=array('ErrorFailToDeleteDir');
1951
-                                    $this->db->rollback();
1952
-                                    return 0;
1953
-                                }
1954
-                            }
1955
-                        }
1956
-                    }
1957
-
1958
-                    // Removed extrafields
1959
-                    if (! $error)
1960
-                    {
1961
-                    	if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
1962
-                    	{
1963
-                    		$result=$this->deleteExtraFields();
1964
-                    		if ($result < 0)
1965
-                    		{
1966
-                    			$error++;
1967
-                    			$errorflag=-4;
1968
-                    			dol_syslog(get_class($this)."::delete erreur ".$errorflag." ".$this->error, LOG_ERR);
1969
-                    		}
1970
-                    	}
1971
-                    }
1972
-
1973
-                    if (! $error)
1974
-                    {
1975
-                        dol_syslog(get_class($this)."::delete ".$this->id." by ".$user->id, LOG_DEBUG);
1976
-                        $this->db->commit();
1977
-                        return 1;
1978
-                    }
1979
-                    else
1980
-                    {
1981
-                        $this->error=$this->db->lasterror();
1982
-                        $this->db->rollback();
1983
-                        return 0;
1984
-                    }
1985
-                }
1986
-                else
1987
-                {
1988
-                    $this->error=$this->db->lasterror();
1989
-                    $this->db->rollback();
1990
-                    return -3;
1991
-                }
1992
-            }
1993
-            else
1994
-            {
1995
-                $this->error=$this->db->lasterror();
1996
-                $this->db->rollback();
1997
-                return -2;
1998
-            }
1999
-        }
2000
-        else
2001
-        {
2002
-            $this->db->rollback();
2003
-            return -1;
2004
-        }
2005
-    }
2006
-
2007
-    /**
2008
-     *	Object SupplierProposal Information
2009
-     *
2010
-     * 	@param	int		$id		Proposal id
2011
-     *  @return	void
2012
-     */
2013
-    function info($id)
2014
-    {
2015
-        $sql = "SELECT c.rowid, ";
2016
-        $sql.= " c.datec, c.date_valid as datev, c.date_cloture as dateo,";
2017
-        $sql.= " c.fk_user_author, c.fk_user_valid, c.fk_user_cloture";
2018
-        $sql.= " FROM ".MAIN_DB_PREFIX."supplier_proposal as c";
2019
-        $sql.= " WHERE c.rowid = ".$id;
2020
-
2021
-        $result = $this->db->query($sql);
2022
-
2023
-        if ($result)
2024
-        {
2025
-            if ($this->db->num_rows($result))
2026
-            {
2027
-                $obj = $this->db->fetch_object($result);
2028
-
2029
-                $this->id                = $obj->rowid;
2030
-
2031
-                $this->date_creation     = $this->db->jdate($obj->datec);
2032
-                $this->date_validation   = $this->db->jdate($obj->datev);
2033
-                $this->date_cloture      = $this->db->jdate($obj->dateo);
2034
-
2035
-                $cuser = new User($this->db);
2036
-                $cuser->fetch($obj->fk_user_author);
2037
-                $this->user_creation     = $cuser;
2038
-
2039
-                if ($obj->fk_user_valid)
2040
-                {
2041
-                    $vuser = new User($this->db);
2042
-                    $vuser->fetch($obj->fk_user_valid);
2043
-                    $this->user_validation     = $vuser;
2044
-                }
2045
-
2046
-                if ($obj->fk_user_cloture)
2047
-                {
2048
-                    $cluser = new User($this->db);
2049
-                    $cluser->fetch($obj->fk_user_cloture);
2050
-                    $this->user_cloture     = $cluser;
2051
-                }
2052
-
2053
-
2054
-            }
2055
-            $this->db->free($result);
2056
-
2057
-        }
2058
-        else
2059
-        {
2060
-            dol_print_error($this->db);
2061
-        }
2062
-    }
2063
-
2064
-
2065
-    /**
2066
-     *    	Return label of status of proposal (draft, validated, ...)
2067
-     *
2068
-     *    	@param      int			$mode        0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
2069
-     *    	@return     string		Label
2070
-     */
2071
-    function getLibStatut($mode=0)
2072
-    {
2073
-        return $this->LibStatut($this->statut,$mode);
2074
-    }
2075
-
2076
-    /**
2077
-     *    	Return label of a status (draft, validated, ...)
2078
-     *
2079
-     *    	@param      int			$statut		id statut
2080
-     *    	@param      int			$mode      	0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
2081
-     *    	@return     string		Label
2082
-     */
2083
-	function LibStatut($statut,$mode=1)
2084
-    {
2085
-		global $langs;
2086
-		$langs->load("supplier_proposal");
2421
+		$linkstart = '<a href="'.$url.'"';
2422
+		$linkstart.=$linkclose.'>';
2423
+		$linkend='</a>';
2087 2424
 
2088
-		if ($statut==0) $statuttrans='statut0';
2089
-		if ($statut==1) $statuttrans='statut1';
2090
-		if ($statut==2) $statuttrans='statut3';
2091
-		if ($statut==3) $statuttrans='statut5';
2092
-		if ($statut==4) $statuttrans='statut6';
2425
+		$picto='supplier_proposal';
2093 2426
 
2094
-		if ($mode == 0)	return $this->labelstatut[$statut];
2095
-		if ($mode == 1)	return $this->labelstatut_short[$statut];
2096
-		if ($mode == 2)	return img_picto($this->labelstatut[$statut], $statuttrans).' '.$this->labelstatut_short[$statut];
2097
-		if ($mode == 3)	return img_picto($this->labelstatut[$statut], $statuttrans);
2098
-		if ($mode == 4)	return img_picto($this->labelstatut[$statut],$statuttrans).' '.$this->labelstatut[$statut];
2099
-		if ($mode == 5)	return '<span class="hideonsmartphone">'.$this->labelstatut_short[$statut].' </span>'.img_picto($this->labelstatut[$statut],$statuttrans);
2100
-		if ($mode == 6)	return '<span class="hideonsmartphone">'.$this->labelstatut[$statut].' </span>'.img_picto($this->labelstatut[$statut],$statuttrans);
2101
-	}
2102 2427
 
2428
+		if ($withpicto)
2429
+			$result.=($linkstart.img_object(($notooltip?'':$label), $picto, ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend);
2430
+		if ($withpicto && $withpicto != 2)
2431
+			$result.=' ';
2432
+		$result.=$linkstart.$this->ref.$linkend;
2433
+		return $result;
2434
+	}
2103 2435
 
2104
-    /**
2105
-     *      Load indicators for dashboard (this->nbtodo and this->nbtodolate)
2106
-     *
2107
-     *      @param          User	$user   Object user
2108
-     *      @param          int		$mode   "opened" for askprice to close, "signed" for proposal to invoice
2109
-     *      @return         int     		<0 if KO, >0 if OK
2110
-     */
2111
-    function load_board($user,$mode)
2112
-    {
2113
-        global $conf, $user, $langs;
2114
-
2115
-        $now=dol_now();
2116
-
2117
-        $this->nbtodo=$this->nbtodolate=0;
2118
-        $clause = " WHERE";
2119
-
2120
-        $sql = "SELECT p.rowid, p.ref, p.datec as datec";
2121
-        $sql.= " FROM ".MAIN_DB_PREFIX."supplier_proposal as p";
2122
-        if (!$user->rights->societe->client->voir && !$user->societe_id)
2123
-        {
2124
-            $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc";
2125
-            $sql.= " WHERE sc.fk_user = " .$user->id;
2126
-            $clause = " AND";
2127
-        }
2128
-        $sql.= $clause." p.entity = ".$conf->entity;
2129
-        if ($mode == 'opened') $sql.= " AND p.fk_statut = 1";
2130
-        if ($mode == 'signed') $sql.= " AND p.fk_statut = 2";
2131
-        if ($user->societe_id) $sql.= " AND p.fk_soc = ".$user->societe_id;
2132
-
2133
-        $resql=$this->db->query($sql);
2134
-        if ($resql)
2135
-        {
2136
-            if ($mode == 'opened') {
2137
-	            $delay_warning=$conf->supplier_proposal->cloture->warning_delay;
2138
-	            $statut = self::STATUS_VALIDATED;
2139
-	            $label = $langs->trans("SupplierProposalsToClose");
2140
-            }
2141
-            if ($mode == 'signed') {
2142
-	            $delay_warning=$conf->supplier_proposal->facturation->warning_delay;
2143
-	            $statut = self::STATUS_SIGNED;
2144
-	            $label = $langs->trans("SupplierProposalsToProcess");      // May be billed or ordered
2145
-            }
2146
-
2147
-	        $response = new WorkboardResponse();
2148
-	        $response->warning_delay = $delay_warning/60/60/24;
2149
-	        $response->label = $label;
2150
-	        $response->url = DOL_URL_ROOT.'/supplier_proposal/list.php?viewstatut='.$statut;
2151
-	        $response->img = img_object('',"propal");
2152
-
2153
-            // This assignment in condition is not a bug. It allows walking the results.
2154
-            while ($obj=$this->db->fetch_object($resql))
2155
-            {
2156
-                $response->nbtodo++;
2157
-                if ($mode == 'opened')
2158
-                {
2159
-                    $datelimit = $this->db->jdate($obj->datefin);
2160
-                    if ($datelimit < ($now - $delay_warning))
2161
-                    {
2162
-                        $response->nbtodolate++;
2163
-                    }
2164
-                }
2165
-                // TODO Definir regle des propales a facturer en retard
2166
-                // if ($mode == 'signed' && ! count($this->FactureListeArray($obj->rowid))) $this->nbtodolate++;
2167
-            }
2168
-            return $response;
2169
-        }
2170
-        else
2171
-        {
2172
-            $this->error=$this->db->lasterror();
2173
-            return -1;
2174
-        }
2175
-    }
2176
-
2177
-
2178
-    /**
2179
-     *  Initialise an instance with random values.
2180
-     *  Used to build previews or test instances.
2181
-     *	id must be 0 if object instance is a specimen.
2182
-     *
2183
-     *  @return	void
2184
-     */
2185
-    function initAsSpecimen()
2186
-    {
2187
-        global $user,$langs,$conf;
2188
-
2189
-        // Load array of products prodids
2190
-        $num_prods = 0;
2191
-        $prodids = array();
2192
-        $sql = "SELECT rowid";
2193
-        $sql.= " FROM ".MAIN_DB_PREFIX."product";
2194
-        $sql.= " WHERE entity IN (".getEntity('product').")";
2195
-        $resql = $this->db->query($sql);
2196
-        if ($resql)
2197
-        {
2198
-            $num_prods = $this->db->num_rows($resql);
2199
-            $i = 0;
2200
-            while ($i < $num_prods)
2201
-            {
2202
-                $i++;
2203
-                $row = $this->db->fetch_row($resql);
2204
-                $prodids[$i] = $row[0];
2205
-            }
2206
-        }
2207
-
2208
-        // Initialise parametres
2209
-        $this->id=0;
2210
-        $this->ref = 'SPECIMEN';
2211
-        $this->specimen=1;
2212
-        $this->socid = 1;
2213
-        $this->date = time();
2214
-        $this->cond_reglement_id   = 1;
2215
-        $this->cond_reglement_code = 'RECEP';
2216
-        $this->mode_reglement_id   = 7;
2217
-        $this->mode_reglement_code = 'CHQ';
2218
-        $this->note_public='This is a comment (public)';
2219
-        $this->note_private='This is a comment (private)';
2220
-        // Lines
2221
-        $nbp = 5;
2222
-        $xnbp = 0;
2223
-        while ($xnbp < $nbp)
2224
-        {
2225
-            $line=new SupplierProposalLine($this->db);
2226
-            $line->desc=$langs->trans("Description")." ".$xnbp;
2227
-            $line->qty=1;
2228
-            $line->subprice=100;
2229
-            $line->price=100;
2230
-            $line->tva_tx=19.6;
2231
-            $line->localtax1_tx=0;
2232
-            $line->localtax2_tx=0;
2233
-            if ($xnbp == 2)
2234
-            {
2235
-                $line->total_ht=50;
2236
-                $line->total_ttc=59.8;
2237
-                $line->total_tva=9.8;
2238
-                $line->remise_percent=50;
2239
-            }
2240
-            else
2241
-            {
2242
-                $line->total_ht=100;
2243
-                $line->total_ttc=119.6;
2244
-                $line->total_tva=19.6;
2245
-                $line->remise_percent=00;
2246
-            }
2247
-
2248
-            if ($num_prods > 0)
2249
-            {
2250
-            	$prodid = mt_rand(1, $num_prods);
2251
-            	$line->fk_product=$prodids[$prodid];
2252
-            }
2253
-
2254
-            $this->lines[$xnbp]=$line;
2255
-
2256
-            $this->total_ht       += $line->total_ht;
2257
-            $this->total_tva      += $line->total_tva;
2258
-            $this->total_ttc      += $line->total_ttc;
2259
-
2260
-            $xnbp++;
2261
-        }
2262
-    }
2263
-
2264
-    /**
2265
-     *      Charge indicateurs this->nb de tableau de bord
2266
-     *
2267
-     *      @return     int         <0 if ko, >0 if ok
2268
-     */
2269
-    function load_state_board()
2270
-    {
2271
-        global $conf, $user;
2272
-
2273
-        $this->nb=array();
2274
-        $clause = "WHERE";
2275
-
2276
-        $sql = "SELECT count(p.rowid) as nb";
2277
-        $sql.= " FROM ".MAIN_DB_PREFIX."supplier_proposal as p";
2278
-        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON p.fk_soc = s.rowid";
2279
-        if (!$user->rights->societe->client->voir && !$user->societe_id)
2280
-        {
2281
-            $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
2282
-            $sql.= " WHERE sc.fk_user = " .$user->id;
2283
-            $clause = "AND";
2284
-        }
2285
-        $sql.= " ".$clause." p.entity = ".$conf->entity;
2286
-
2287
-        $resql=$this->db->query($sql);
2288
-        if ($resql)
2289
-        {
2290
-            // This assignment in condition is not a bug. It allows walking the results.
2291
-            while ($obj=$this->db->fetch_object($resql))
2292
-            {
2293
-                $this->nb["askprice"]=$obj->nb;
2294
-            }
2295
-            $this->db->free($resql);
2296
-            return 1;
2297
-        }
2298
-        else
2299
-        {
2300
-            dol_print_error($this->db);
2301
-            $this->error=$this->db->lasterror();
2302
-            return -1;
2303
-        }
2304
-    }
2305
-
2306
-
2307
-    /**
2308
-     *  Returns the reference to the following non used Proposal used depending on the active numbering module
2309
-     *  defined into SUPPLIER_PROPOSAL_ADDON
2310
-     *
2311
-     *  @param	Societe		$soc  	Object thirdparty
2312
-     *  @return string      		Reference libre pour la propale
2313
-     */
2314
-    function getNextNumRef($soc)
2315
-    {
2316
-        global $conf, $db, $langs;
2317
-        $langs->load("supplier_proposal");
2318
-
2319
-        if (! empty($conf->global->SUPPLIER_PROPOSAL_ADDON))
2320
-        {
2321
-        	$mybool=false;
2322
-
2323
-            $file = $conf->global->SUPPLIER_PROPOSAL_ADDON.".php";
2324
-            $classname = $conf->global->SUPPLIER_PROPOSAL_ADDON;
2325
-
2326
-            // Include file with class
2327
-            $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
2328
-            foreach ($dirmodels as $reldir) {
2329
-
2330
-                $dir = dol_buildpath($reldir."core/modules/supplier_proposal/");
2331
-
2332
-                // Load file with numbering class (if found)
2333
-                $mybool|=@include_once $dir.$file;
2334
-            }
2335
-
2336
-            if (! $mybool)
2337
-            {
2338
-            	dol_print_error('',"Failed to include file ".$file);
2339
-            	return '';
2340
-            }
2341
-
2342
-            $obj = new $classname();
2343
-            $numref = "";
2344
-            $numref = $obj->getNextValue($soc,$this);
2345
-
2346
-            if ($numref != "")
2347
-            {
2348
-                return $numref;
2349
-            }
2350
-            else
2351
-			{
2352
-                $this->error=$obj->error;
2353
-                return "";
2354
-            }
2355
-        }
2356
-        else
2357
-		{
2358
-            $langs->load("errors");
2359
-            print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete");
2360
-            return "";
2361
-        }
2362
-    }
2363
-
2364
-    /**
2365
-     *	Return clicable link of object (with eventually picto)
2366
-     *
2367
-     *	@param      int		$withpicto					Add picto into link
2368
-     *	@param      string	$option						Where point the link ('compta', 'expedition', 'document', ...)
2369
-     *	@param      string	$get_params    				Parametres added to url
2370
-     *  @param	    int   	$notooltip					1=Disable tooltip
2371
-     *  @param      int     $save_lastsearch_value		-1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
2372
-     *	@return     string          					String with URL
2373
-     */
2374
-    function getNomUrl($withpicto=0, $option='', $get_params='', $notooltip=0, $save_lastsearch_value=-1)
2375
-    {
2376
-        global $langs, $conf, $user;
2377
-
2378
-        if (! empty($conf->dol_no_mouse_hover)) $notooltip=1;   // Force disable tooltips
2379
-
2380
-        $url='';
2381
-        $result='';
2382
-
2383
-        $label='<u>'.$langs->trans("ShowSupplierProposal").'</u>';
2384
-        if (! empty($this->ref))
2385
-        $label.= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
2386
-        if (! empty($this->ref_fourn))
2387
-            $label.= '<br><b>'.$langs->trans('RefSupplier').':</b> '.$this->ref_fourn;
2388
-        if (! empty($this->total_ht))
2389
-            $label.= '<br><b>' . $langs->trans('AmountHT') . ':</b> ' . price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
2390
-        if (! empty($this->total_tva))
2391
-            $label.= '<br><b>' . $langs->trans('VAT') . ':</b> ' . price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
2392
-        if (! empty($this->total_ttc))
2393
-            $label.= '<br><b>' . $langs->trans('AmountTTC') . ':</b> ' . price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
2394
-        if ($option == '') {
2395
-            $url = DOL_URL_ROOT.'/supplier_proposal/card.php?id='.$this->id. $get_params;
2396
-        }
2397
-        if ($option == 'document') {
2398
-            $url = DOL_URL_ROOT.'/supplier_proposal/document.php?id='.$this->id. $get_params;
2399
-        }
2400
-
2401
-        if ($option !== 'nolink')
2402
-        {
2403
-        	// Add param to save lastsearch_values or not
2404
-        	$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
2405
-        	if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
2406
-        	if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
2407
-        }
2408
-
2409
-        $linkclose='';
2410
-        if (empty($notooltip) && $user->rights->propal->lire)
2411
-        {
2412
-            if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
2413
-            {
2414
-                $label=$langs->trans("ShowSupplierProposal");
2415
-                $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
2416
-            }
2417
-            $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
2418
-            $linkclose.=' class="classfortooltip"';
2419
-        }
2420
-
2421
-        $linkstart = '<a href="'.$url.'"';
2422
-        $linkstart.=$linkclose.'>';
2423
-        $linkend='</a>';
2424
-
2425
-        $picto='supplier_proposal';
2426
-
2427
-
2428
-        if ($withpicto)
2429
-            $result.=($linkstart.img_object(($notooltip?'':$label), $picto, ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend);
2430
-        if ($withpicto && $withpicto != 2)
2431
-            $result.=' ';
2432
-        $result.=$linkstart.$this->ref.$linkend;
2433
-        return $result;
2434
-    }
2435
-
2436
-    /**
2437
-     * 	Retrieve an array of supplier proposal lines
2436
+	/**
2437
+	 * 	Retrieve an array of supplier proposal lines
2438 2438
 	 *
2439 2439
 	 * 	@return int		>0 if OK, <0 if KO
2440
-     */
2441
-    function getLinesArray()
2442
-    {
2443
-        // For other object, here we call fetch_lines. But fetch_lines does not exists on supplier proposal
2444
-
2445
-        $sql = 'SELECT pt.rowid, pt.label as custom_label, pt.description, pt.fk_product, pt.fk_remise_except,';
2446
-        $sql.= ' pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, pt.info_bits,';
2447
-        $sql.= ' pt.total_ht, pt.total_tva, pt.total_ttc, pt.fk_product_fournisseur_price as fk_fournprice, pt.buy_price_ht as pa_ht, pt.special_code, pt.localtax1_tx, pt.localtax2_tx,';
2448
-        $sql.= ' pt.product_type, pt.rang, pt.fk_parent_line,';
2449
-        $sql.= ' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid,';
2450
-        $sql.= ' p.description as product_desc, pt.ref_fourn as ref_produit_fourn,';
2440
+	 */
2441
+	function getLinesArray()
2442
+	{
2443
+		// For other object, here we call fetch_lines. But fetch_lines does not exists on supplier proposal
2444
+
2445
+		$sql = 'SELECT pt.rowid, pt.label as custom_label, pt.description, pt.fk_product, pt.fk_remise_except,';
2446
+		$sql.= ' pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, pt.info_bits,';
2447
+		$sql.= ' pt.total_ht, pt.total_tva, pt.total_ttc, pt.fk_product_fournisseur_price as fk_fournprice, pt.buy_price_ht as pa_ht, pt.special_code, pt.localtax1_tx, pt.localtax2_tx,';
2448
+		$sql.= ' pt.product_type, pt.rang, pt.fk_parent_line,';
2449
+		$sql.= ' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid,';
2450
+		$sql.= ' p.description as product_desc, pt.ref_fourn as ref_produit_fourn,';
2451 2451
 		$sql.= ' pt.fk_multicurrency, pt.multicurrency_code, pt.multicurrency_subprice, pt.multicurrency_total_ht, pt.multicurrency_total_tva, pt.multicurrency_total_ttc, pt.fk_unit';
2452
-        $sql.= ' FROM '.MAIN_DB_PREFIX.'supplier_proposaldet as pt';
2453
-        $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product=p.rowid';
2454
-        $sql.= ' WHERE pt.fk_supplier_proposal = '.$this->id;
2455
-        $sql.= ' ORDER BY pt.rang ASC, pt.rowid';
2456
-
2457
-        dol_syslog(get_class($this).'::getLinesArray', LOG_DEBUG);
2458
-        $resql = $this->db->query($sql);
2459
-        if ($resql)
2460
-        {
2461
-            $num = $this->db->num_rows($resql);
2462
-            $i = 0;
2463
-
2464
-            while ($i < $num)
2465
-            {
2466
-                $obj = $this->db->fetch_object($resql);
2467
-
2468
-                $this->lines[$i]					= new SupplierProposalLine($this->db);
2469
-                $this->lines[$i]->id				= $obj->rowid; // for backward compatibility
2470
-                $this->lines[$i]->rowid				= $obj->rowid;
2471
-                $this->lines[$i]->label 			= $obj->custom_label;
2472
-                $this->lines[$i]->description 		= $obj->description;
2473
-                $this->lines[$i]->fk_product		= $obj->fk_product;
2474
-                $this->lines[$i]->ref				= $obj->ref;
2475
-                $this->lines[$i]->product_label		= $obj->product_label;
2476
-                $this->lines[$i]->product_desc		= $obj->product_desc;
2477
-                $this->lines[$i]->fk_product_type	= $obj->fk_product_type;  // deprecated
2478
-                $this->lines[$i]->product_type		= $obj->product_type;
2479
-                $this->lines[$i]->qty				= $obj->qty;
2480
-                $this->lines[$i]->subprice			= $obj->subprice;
2481
-                $this->lines[$i]->fk_remise_except 	= $obj->fk_remise_except;
2482
-                $this->lines[$i]->remise_percent	= $obj->remise_percent;
2483
-                $this->lines[$i]->tva_tx			= $obj->tva_tx;
2484
-                $this->lines[$i]->info_bits			= $obj->info_bits;
2485
-                $this->lines[$i]->total_ht			= $obj->total_ht;
2486
-                $this->lines[$i]->total_tva			= $obj->total_tva;
2487
-                $this->lines[$i]->total_ttc			= $obj->total_ttc;
2452
+		$sql.= ' FROM '.MAIN_DB_PREFIX.'supplier_proposaldet as pt';
2453
+		$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product=p.rowid';
2454
+		$sql.= ' WHERE pt.fk_supplier_proposal = '.$this->id;
2455
+		$sql.= ' ORDER BY pt.rang ASC, pt.rowid';
2456
+
2457
+		dol_syslog(get_class($this).'::getLinesArray', LOG_DEBUG);
2458
+		$resql = $this->db->query($sql);
2459
+		if ($resql)
2460
+		{
2461
+			$num = $this->db->num_rows($resql);
2462
+			$i = 0;
2463
+
2464
+			while ($i < $num)
2465
+			{
2466
+				$obj = $this->db->fetch_object($resql);
2467
+
2468
+				$this->lines[$i]					= new SupplierProposalLine($this->db);
2469
+				$this->lines[$i]->id				= $obj->rowid; // for backward compatibility
2470
+				$this->lines[$i]->rowid				= $obj->rowid;
2471
+				$this->lines[$i]->label 			= $obj->custom_label;
2472
+				$this->lines[$i]->description 		= $obj->description;
2473
+				$this->lines[$i]->fk_product		= $obj->fk_product;
2474
+				$this->lines[$i]->ref				= $obj->ref;
2475
+				$this->lines[$i]->product_label		= $obj->product_label;
2476
+				$this->lines[$i]->product_desc		= $obj->product_desc;
2477
+				$this->lines[$i]->fk_product_type	= $obj->fk_product_type;  // deprecated
2478
+				$this->lines[$i]->product_type		= $obj->product_type;
2479
+				$this->lines[$i]->qty				= $obj->qty;
2480
+				$this->lines[$i]->subprice			= $obj->subprice;
2481
+				$this->lines[$i]->fk_remise_except 	= $obj->fk_remise_except;
2482
+				$this->lines[$i]->remise_percent	= $obj->remise_percent;
2483
+				$this->lines[$i]->tva_tx			= $obj->tva_tx;
2484
+				$this->lines[$i]->info_bits			= $obj->info_bits;
2485
+				$this->lines[$i]->total_ht			= $obj->total_ht;
2486
+				$this->lines[$i]->total_tva			= $obj->total_tva;
2487
+				$this->lines[$i]->total_ttc			= $obj->total_ttc;
2488 2488
 				$this->lines[$i]->fk_fournprice		= $obj->fk_fournprice;
2489 2489
 				$marginInfos						= getMarginInfos($obj->subprice, $obj->remise_percent, $obj->tva_tx, $obj->localtax1_tx, $obj->localtax2_tx, $this->lines[$i]->fk_fournprice, $obj->pa_ht);
2490 2490
 				$this->lines[$i]->pa_ht				= $marginInfos[0];
2491 2491
 				$this->lines[$i]->marge_tx			= $marginInfos[1];
2492 2492
 				$this->lines[$i]->marque_tx			= $marginInfos[2];
2493 2493
 				$this->lines[$i]->fk_parent_line	= $obj->fk_parent_line;
2494
-                $this->lines[$i]->special_code		= $obj->special_code;
2495
-                $this->lines[$i]->rang				= $obj->rang;
2494
+				$this->lines[$i]->special_code		= $obj->special_code;
2495
+				$this->lines[$i]->rang				= $obj->rang;
2496 2496
 
2497
-                $this->lines[$i]->ref_fourn				= $obj->ref_produit_fourn;
2497
+				$this->lines[$i]->ref_fourn				= $obj->ref_produit_fourn;
2498 2498
 
2499 2499
 				// Multicurrency
2500 2500
 				$this->lines[$i]->fk_multicurrency 			= $obj->fk_multicurrency;
@@ -2505,18 +2505,18 @@  discard block
 block discarded – undo
2505 2505
 				$this->lines[$i]->multicurrency_total_ttc 	= $obj->multicurrency_total_ttc;
2506 2506
 				$this->lines[$i]->fk_unit				 	= $obj->fk_unit;
2507 2507
 
2508
-                $i++;
2509
-            }
2510
-            $this->db->free($resql);
2508
+				$i++;
2509
+			}
2510
+			$this->db->free($resql);
2511 2511
 
2512
-            return 1;
2513
-        }
2514
-        else
2515
-        {
2516
-            $this->error=$this->db->error();
2517
-            return -1;
2518
-        }
2519
-    }
2512
+			return 1;
2513
+		}
2514
+		else
2515
+		{
2516
+			$this->error=$this->db->error();
2517
+			return -1;
2518
+		}
2519
+	}
2520 2520
 
2521 2521
 	/**
2522 2522
 	 *  Create a document onto disk according to template module.
@@ -2561,11 +2561,11 @@  discard block
 block discarded – undo
2561 2561
 	 */
2562 2562
 	public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
2563 2563
 	{
2564
-	    $tables = array(
2565
-	        'supplier_proposal'
2566
-	    );
2564
+		$tables = array(
2565
+			'supplier_proposal'
2566
+		);
2567 2567
 
2568
-	    return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
2568
+		return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
2569 2569
 	}
2570 2570
 
2571 2571
 }
@@ -2576,21 +2576,21 @@  discard block
 block discarded – undo
2576 2576
  */
2577 2577
 class SupplierProposalLine extends CommonObjectLine
2578 2578
 {
2579
-    var $db;
2580
-    var $error;
2579
+	var $db;
2580
+	var $error;
2581 2581
 
2582
-    public $element='supplier_proposaldet';
2583
-    public $table_element='supplier_proposaldet';
2582
+	public $element='supplier_proposaldet';
2583
+	public $table_element='supplier_proposaldet';
2584 2584
 
2585
-    var $oldline;
2585
+	var $oldline;
2586 2586
 
2587
-    // From llx_supplier_proposaldet
2588
-    var $rowid; // deprecated
2589
-    var $id;
2590
-    var $fk_supplier_proposal;
2591
-    var $fk_parent_line;
2592
-    var $desc;          	// Description ligne
2593
-    var $fk_product;		// Id produit predefini
2587
+	// From llx_supplier_proposaldet
2588
+	var $rowid; // deprecated
2589
+	var $id;
2590
+	var $fk_supplier_proposal;
2591
+	var $fk_parent_line;
2592
+	var $desc;          	// Description ligne
2593
+	var $fk_product;		// Id produit predefini
2594 2594
 	/**
2595 2595
 	 * @deprecated
2596 2596
 	 * @see product_type
@@ -2601,46 +2601,46 @@  discard block
 block discarded – undo
2601 2601
 	 * @var int
2602 2602
 	 * @see Product::TYPE_PRODUCT, Product::TYPE_SERVICE
2603 2603
 	 */
2604
-    public $product_type = Product::TYPE_PRODUCT;
2604
+	public $product_type = Product::TYPE_PRODUCT;
2605 2605
 
2606
-    var $qty;
2607
-    var $tva_tx;
2608
-    var $subprice;
2609
-    var $remise_percent;
2610
-    var $fk_remise_except;
2606
+	var $qty;
2607
+	var $tva_tx;
2608
+	var $subprice;
2609
+	var $remise_percent;
2610
+	var $fk_remise_except;
2611 2611
 
2612
-    var $rang = 0;
2612
+	var $rang = 0;
2613 2613
 
2614 2614
 	var $fk_fournprice;
2615 2615
 	var $pa_ht;
2616 2616
 	var $marge_tx;
2617 2617
 	var $marque_tx;
2618 2618
 
2619
-    var $special_code;	// Tag for special lines (exlusive tags)
2620
-    // 1: frais de port
2621
-    // 2: ecotaxe
2622
-    // 3: option line (when qty = 0)
2619
+	var $special_code;	// Tag for special lines (exlusive tags)
2620
+	// 1: frais de port
2621
+	// 2: ecotaxe
2622
+	// 3: option line (when qty = 0)
2623 2623
 
2624
-    var $info_bits = 0;	// Liste d'options cumulables:
2625
-    // Bit 0: 	0 si TVA normal - 1 si TVA NPR
2626
-    // Bit 1:	0 ligne normale - 1 si ligne de remise fixe
2624
+	var $info_bits = 0;	// Liste d'options cumulables:
2625
+	// Bit 0: 	0 si TVA normal - 1 si TVA NPR
2626
+	// Bit 1:	0 ligne normale - 1 si ligne de remise fixe
2627 2627
 
2628
-    var $total_ht;			// Total HT  de la ligne toute quantite et incluant la remise ligne
2629
-    var $total_tva;			// Total TVA  de la ligne toute quantite et incluant la remise ligne
2630
-    var $total_ttc;			// Total TTC de la ligne toute quantite et incluant la remise ligne
2628
+	var $total_ht;			// Total HT  de la ligne toute quantite et incluant la remise ligne
2629
+	var $total_tva;			// Total TVA  de la ligne toute quantite et incluant la remise ligne
2630
+	var $total_ttc;			// Total TTC de la ligne toute quantite et incluant la remise ligne
2631 2631
 
2632 2632
 	/**
2633 2633
 	 * @deprecated
2634 2634
 	 * @see remise_percent, fk_remise_except
2635 2635
 	 */
2636
-    var $remise;
2636
+	var $remise;
2637 2637
 	/**
2638 2638
 	 * @deprecated
2639 2639
 	 * @see subprice
2640 2640
 	 */
2641
-    var $price;
2641
+	var $price;
2642 2642
 
2643
-    // From llx_product
2643
+	// From llx_product
2644 2644
 	/**
2645 2645
 	 * @deprecated
2646 2646
 	 * @see product_ref
@@ -2667,14 +2667,14 @@  discard block
 block discarded – undo
2667 2667
 	 */
2668 2668
 	public $product_desc;
2669 2669
 
2670
-    var $localtax1_tx;		// Local tax 1
2671
-    var $localtax2_tx;		// Local tax 2
2672
-    var $localtax1_type;	// Local tax 1 type
2670
+	var $localtax1_tx;		// Local tax 1
2671
+	var $localtax2_tx;		// Local tax 2
2672
+	var $localtax1_type;	// Local tax 1 type
2673 2673
 	var $localtax2_type;	// Local tax 2 type
2674
-    var $total_localtax1;  	// Line total local tax 1
2675
-    var $total_localtax2;	// Line total local tax 2
2674
+	var $total_localtax1;  	// Line total local tax 1
2675
+	var $total_localtax2;	// Line total local tax 2
2676 2676
 
2677
-    var $skip_update_total; // Skip update price total for special lines
2677
+	var $skip_update_total; // Skip update price total for special lines
2678 2678
 
2679 2679
 	var $ref_fourn;
2680 2680
 
@@ -2686,22 +2686,22 @@  discard block
 block discarded – undo
2686 2686
 	var $multicurrency_total_tva;
2687 2687
 	var $multicurrency_total_ttc;
2688 2688
 
2689
-    /**
2690
-     * 	Class line Contructor
2691
-     *
2692
-     * 	@param	DoliDB	$db	Database handler
2693
-     */
2694
-    function __construct($db)
2695
-    {
2696
-        $this->db= $db;
2697
-    }
2698
-
2699
-    /**
2700
-     *	Retrieve the propal line object
2701
-     *
2702
-     *	@param	int		$rowid		Propal line id
2703
-     *	@return	int					<0 if KO, >0 if OK
2704
-     */
2689
+	/**
2690
+	 * 	Class line Contructor
2691
+	 *
2692
+	 * 	@param	DoliDB	$db	Database handler
2693
+	 */
2694
+	function __construct($db)
2695
+	{
2696
+		$this->db= $db;
2697
+	}
2698
+
2699
+	/**
2700
+	 *	Retrieve the propal line object
2701
+	 *
2702
+	 *	@param	int		$rowid		Propal line id
2703
+	 *	@return	int					<0 if KO, >0 if OK
2704
+	 */
2705 2705
 	function fetch($rowid)
2706 2706
 	{
2707 2707
 		$sql = 'SELECT pd.rowid, pd.fk_supplier_proposal, pd.fk_parent_line, pd.fk_product, pd.label as custom_label, pd.description, pd.price, pd.qty, pd.tva_tx,';
@@ -2776,39 +2776,39 @@  discard block
 block discarded – undo
2776 2776
 		}
2777 2777
 	}
2778 2778
 
2779
-    /**
2780
-     *  Insert object line propal in database
2781
-     *
2782
-     *	@param		int		$notrigger		1=Does not execute triggers, 0= execute triggers
2783
-     *	@return		int						<0 if KO, >0 if OK
2784
-     */
2785
-    function insert($notrigger=0)
2786
-    {
2787
-        global $conf,$langs,$user;
2788
-
2789
-        $error=0;
2790
-
2791
-        dol_syslog(get_class($this)."::insert rang=".$this->rang);
2792
-
2793
-        // Clean parameters
2794
-        if (empty($this->tva_tx)) $this->tva_tx=0;
2795
-        if (empty($this->localtax1_tx)) $this->localtax1_tx=0;
2796
-        if (empty($this->localtax2_tx)) $this->localtax2_tx=0;
2797
-        if (empty($this->localtax1_type)) $this->localtax1_type=0;
2779
+	/**
2780
+	 *  Insert object line propal in database
2781
+	 *
2782
+	 *	@param		int		$notrigger		1=Does not execute triggers, 0= execute triggers
2783
+	 *	@return		int						<0 if KO, >0 if OK
2784
+	 */
2785
+	function insert($notrigger=0)
2786
+	{
2787
+		global $conf,$langs,$user;
2788
+
2789
+		$error=0;
2790
+
2791
+		dol_syslog(get_class($this)."::insert rang=".$this->rang);
2792
+
2793
+		// Clean parameters
2794
+		if (empty($this->tva_tx)) $this->tva_tx=0;
2795
+		if (empty($this->localtax1_tx)) $this->localtax1_tx=0;
2796
+		if (empty($this->localtax2_tx)) $this->localtax2_tx=0;
2797
+		if (empty($this->localtax1_type)) $this->localtax1_type=0;
2798 2798
 		if (empty($this->localtax2_type)) $this->localtax2_type=0;
2799
-        if (empty($this->total_localtax1)) $this->total_localtax1=0;
2800
-        if (empty($this->total_localtax2)) $this->total_localtax2=0;
2801
-        if (empty($this->rang)) $this->rang=0;
2802
-        if (empty($this->remise)) $this->remise=0;
2803
-        if (empty($this->remise_percent)) $this->remise_percent=0;
2804
-        if (empty($this->info_bits)) $this->info_bits=0;
2805
-        if (empty($this->special_code)) $this->special_code=0;
2806
-        if (empty($this->fk_parent_line)) $this->fk_parent_line=0;
2807
-        if (empty($this->fk_fournprice)) $this->fk_fournprice=0;
2808
-        if (empty($this->fk_unit)) $this->fk_unit=0;
2809
-        if (empty($this->subprice)) $this->subprice=0;
2810
-
2811
-        if (empty($this->pa_ht)) $this->pa_ht=0;
2799
+		if (empty($this->total_localtax1)) $this->total_localtax1=0;
2800
+		if (empty($this->total_localtax2)) $this->total_localtax2=0;
2801
+		if (empty($this->rang)) $this->rang=0;
2802
+		if (empty($this->remise)) $this->remise=0;
2803
+		if (empty($this->remise_percent)) $this->remise_percent=0;
2804
+		if (empty($this->info_bits)) $this->info_bits=0;
2805
+		if (empty($this->special_code)) $this->special_code=0;
2806
+		if (empty($this->fk_parent_line)) $this->fk_parent_line=0;
2807
+		if (empty($this->fk_fournprice)) $this->fk_fournprice=0;
2808
+		if (empty($this->fk_unit)) $this->fk_unit=0;
2809
+		if (empty($this->subprice)) $this->subprice=0;
2810
+
2811
+		if (empty($this->pa_ht)) $this->pa_ht=0;
2812 2812
 
2813 2813
 		// if buy price not defined, define buyprice as configured in margin admin
2814 2814
 		if ($this->pa_ht == 0)
@@ -2823,175 +2823,175 @@  discard block
 block discarded – undo
2823 2823
 			}
2824 2824
 		}
2825 2825
 
2826
-        // Check parameters
2827
-        if ($this->product_type < 0) return -1;
2826
+		// Check parameters
2827
+		if ($this->product_type < 0) return -1;
2828 2828
 
2829
-        $this->db->begin();
2829
+		$this->db->begin();
2830 2830
 
2831
-        // Insert line into database
2832
-        $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'supplier_proposaldet';
2833
-        $sql.= ' (fk_supplier_proposal, fk_parent_line, label, description, fk_product, product_type,';
2831
+		// Insert line into database
2832
+		$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'supplier_proposaldet';
2833
+		$sql.= ' (fk_supplier_proposal, fk_parent_line, label, description, fk_product, product_type,';
2834 2834
 		$sql.= ' fk_remise_except, qty, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,';
2835
-        $sql.= ' subprice, remise_percent, ';
2836
-        $sql.= ' info_bits, ';
2837
-        $sql.= ' total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_product_fournisseur_price, buy_price_ht, special_code, rang,';
2838
-        $sql.= ' ref_fourn,';
2835
+		$sql.= ' subprice, remise_percent, ';
2836
+		$sql.= ' info_bits, ';
2837
+		$sql.= ' total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_product_fournisseur_price, buy_price_ht, special_code, rang,';
2838
+		$sql.= ' ref_fourn,';
2839 2839
 		$sql.= ' fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc, fk_unit)';
2840
-        $sql.= " VALUES (".$this->fk_supplier_proposal.",";
2841
-        $sql.= " ".($this->fk_parent_line>0?"'".$this->db->escape($this->fk_parent_line)."'":"null").",";
2842
-        $sql.= " ".(! empty($this->label)?"'".$this->db->escape($this->label)."'":"null").",";
2843
-        $sql.= " '".$this->db->escape($this->desc)."',";
2844
-        $sql.= " ".($this->fk_product?"'".$this->db->escape($this->fk_product)."'":"null").",";
2845
-        $sql.= " '".$this->db->escape($this->product_type)."',";
2846
-        $sql.= " ".($this->fk_remise_except?"'".$this->db->escape($this->fk_remise_except)."'":"null").",";
2847
-        $sql.= " ".price2num($this->qty).",";
2848
-        $sql.= " ".price2num($this->tva_tx).",";
2849
-        $sql.= " ".price2num($this->localtax1_tx).",";
2850
-        $sql.= " ".price2num($this->localtax2_tx).",";
2840
+		$sql.= " VALUES (".$this->fk_supplier_proposal.",";
2841
+		$sql.= " ".($this->fk_parent_line>0?"'".$this->db->escape($this->fk_parent_line)."'":"null").",";
2842
+		$sql.= " ".(! empty($this->label)?"'".$this->db->escape($this->label)."'":"null").",";
2843
+		$sql.= " '".$this->db->escape($this->desc)."',";
2844
+		$sql.= " ".($this->fk_product?"'".$this->db->escape($this->fk_product)."'":"null").",";
2845
+		$sql.= " '".$this->db->escape($this->product_type)."',";
2846
+		$sql.= " ".($this->fk_remise_except?"'".$this->db->escape($this->fk_remise_except)."'":"null").",";
2847
+		$sql.= " ".price2num($this->qty).",";
2848
+		$sql.= " ".price2num($this->tva_tx).",";
2849
+		$sql.= " ".price2num($this->localtax1_tx).",";
2850
+		$sql.= " ".price2num($this->localtax2_tx).",";
2851 2851
 		$sql.= " '".$this->db->escape($this->localtax1_type)."',";
2852 2852
 		$sql.= " '".$this->db->escape($this->localtax2_type)."',";
2853
-        $sql.= " ".(!empty($this->subprice)?price2num($this->subprice):"null").",";
2854
-        $sql.= " ".price2num($this->remise_percent).",";
2855
-        $sql.= " ".(isset($this->info_bits)?"'".$this->db->escape($this->info_bits)."'":"null").",";
2856
-        $sql.= " ".price2num($this->total_ht).",";
2857
-        $sql.= " ".price2num($this->total_tva).",";
2858
-        $sql.= " ".price2num($this->total_localtax1).",";
2859
-        $sql.= " ".price2num($this->total_localtax2).",";
2860
-        $sql.= " ".price2num($this->total_ttc).",";
2861
-        $sql.= " ".(!empty($this->fk_fournprice)?"'".$this->db->escape($this->fk_fournprice)."'":"null").",";
2862
-        $sql.= " ".(isset($this->pa_ht)?"'".price2num($this->pa_ht)."'":"null").",";
2863
-        $sql.= ' '.$this->special_code.',';
2864
-        $sql.= ' '.$this->rang.',';
2865
-        $sql.= " '".$this->db->escape($this->ref_fourn)."'";
2853
+		$sql.= " ".(!empty($this->subprice)?price2num($this->subprice):"null").",";
2854
+		$sql.= " ".price2num($this->remise_percent).",";
2855
+		$sql.= " ".(isset($this->info_bits)?"'".$this->db->escape($this->info_bits)."'":"null").",";
2856
+		$sql.= " ".price2num($this->total_ht).",";
2857
+		$sql.= " ".price2num($this->total_tva).",";
2858
+		$sql.= " ".price2num($this->total_localtax1).",";
2859
+		$sql.= " ".price2num($this->total_localtax2).",";
2860
+		$sql.= " ".price2num($this->total_ttc).",";
2861
+		$sql.= " ".(!empty($this->fk_fournprice)?"'".$this->db->escape($this->fk_fournprice)."'":"null").",";
2862
+		$sql.= " ".(isset($this->pa_ht)?"'".price2num($this->pa_ht)."'":"null").",";
2863
+		$sql.= ' '.$this->special_code.',';
2864
+		$sql.= ' '.$this->rang.',';
2865
+		$sql.= " '".$this->db->escape($this->ref_fourn)."'";
2866 2866
 		$sql.= ", ".($this->fk_multicurrency > 0?$this->fk_multicurrency:'null');
2867 2867
 		$sql.= ", '".$this->db->escape($this->multicurrency_code)."'";
2868 2868
 		$sql.= ", ".$this->multicurrency_subprice;
2869 2869
 		$sql.= ", ".$this->multicurrency_total_ht;
2870 2870
 		$sql.= ", ".$this->multicurrency_total_tva;
2871 2871
 		$sql.= ", ".$this->multicurrency_total_ttc;
2872
-        $sql.= ", ".($this->fk_unit?$this->fk_unit:'null');
2872
+		$sql.= ", ".($this->fk_unit?$this->fk_unit:'null');
2873 2873
 		$sql.= ')';
2874 2874
 
2875
-        dol_syslog(get_class($this).'::insert', LOG_DEBUG);
2876
-        $resql=$this->db->query($sql);
2877
-        if ($resql)
2878
-        {
2879
-            $this->rowid=$this->db->last_insert_id(MAIN_DB_PREFIX.'supplier_proposaldet');
2875
+		dol_syslog(get_class($this).'::insert', LOG_DEBUG);
2876
+		$resql=$this->db->query($sql);
2877
+		if ($resql)
2878
+		{
2879
+			$this->rowid=$this->db->last_insert_id(MAIN_DB_PREFIX.'supplier_proposaldet');
2880 2880
 			$this->id=$this->rowid;
2881 2881
 
2882
-            if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
2883
-            {
2884
-            	$result=$this->insertExtraFields();
2885
-            	if ($result < 0)
2886
-            	{
2887
-            		$error++;
2888
-            	}
2889
-            }
2890
-
2891
-            if (! $notrigger)
2892
-            {
2893
-                // Call trigger
2894
-                $result=$this->call_trigger('LINESUPPLIER_PROPOSAL_INSERT',$user);
2895
-                if ($result < 0)
2896
-                {
2897
-                    $this->db->rollback();
2898
-                    return -1;
2899
-                }
2900
-                // End call triggers
2901
-            }
2902
-
2903
-            $this->db->commit();
2904
-            return 1;
2905
-        }
2906
-        else
2907
-        {
2908
-            $this->error=$this->db->error()." sql=".$sql;
2909
-            $this->db->rollback();
2910
-            return -1;
2911
-        }
2912
-    }
2913
-
2914
-    /**
2915
-     * 	Delete line in database
2916
-     *
2917
-     *	@return	 int  <0 if ko, >0 if ok
2918
-     */
2919
-    function delete()
2920
-    {
2921
-        global $conf,$langs,$user;
2922
-
2923
-        $error=0;
2924
-        $this->db->begin();
2925
-
2926
-        $sql = "DELETE FROM ".MAIN_DB_PREFIX."supplier_proposaldet WHERE rowid = ".$this->rowid;
2927
-        dol_syslog("SupplierProposalLine::delete", LOG_DEBUG);
2928
-        if ($this->db->query($sql) )
2929
-        {
2930
-
2931
-        	// Remove extrafields
2932
-        	if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
2933
-        	{
2934
-        		$this->id=$this->rowid;
2935
-        		$result=$this->deleteExtraFields();
2936
-        		if ($result < 0)
2937
-        		{
2938
-        			$error++;
2939
-        			dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR);
2940
-        		}
2941
-        	}
2942
-
2943
-            // Call trigger
2944
-            $result=$this->call_trigger('LINESUPPLIER_PROPOSAL_DELETE',$user);
2945
-            if ($result < 0)
2946
-            {
2947
-                $this->db->rollback();
2948
-                return -1;
2949
-            }
2950
-            // End call triggers
2951
-
2952
-            $this->db->commit();
2953
-
2954
-            return 1;
2955
-        }
2956
-        else
2957
-        {
2958
-            $this->error=$this->db->error()." sql=".$sql;
2959
-            $this->db->rollback();
2960
-            return -1;
2961
-        }
2962
-    }
2963
-
2964
-    /**
2965
-     *	Update propal line object into DB
2966
-     *
2967
-     *	@param 	int		$notrigger	1=Does not execute triggers, 0= execute triggers
2968
-     *	@return	int					<0 if ko, >0 if ok
2969
-     */
2970
-    function update($notrigger=0)
2971
-    {
2972
-        global $conf,$langs,$user;
2973
-
2974
-        $error=0;
2975
-
2976
-        // Clean parameters
2977
-        if (empty($this->tva_tx)) $this->tva_tx=0;
2978
-        if (empty($this->localtax1_tx)) $this->localtax1_tx=0;
2979
-        if (empty($this->localtax2_tx)) $this->localtax2_tx=0;
2980
-        if (empty($this->total_localtax1)) $this->total_localtax1=0;
2981
-        if (empty($this->total_localtax2)) $this->total_localtax2=0;
2882
+			if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
2883
+			{
2884
+				$result=$this->insertExtraFields();
2885
+				if ($result < 0)
2886
+				{
2887
+					$error++;
2888
+				}
2889
+			}
2890
+
2891
+			if (! $notrigger)
2892
+			{
2893
+				// Call trigger
2894
+				$result=$this->call_trigger('LINESUPPLIER_PROPOSAL_INSERT',$user);
2895
+				if ($result < 0)
2896
+				{
2897
+					$this->db->rollback();
2898
+					return -1;
2899
+				}
2900
+				// End call triggers
2901
+			}
2902
+
2903
+			$this->db->commit();
2904
+			return 1;
2905
+		}
2906
+		else
2907
+		{
2908
+			$this->error=$this->db->error()." sql=".$sql;
2909
+			$this->db->rollback();
2910
+			return -1;
2911
+		}
2912
+	}
2913
+
2914
+	/**
2915
+	 * 	Delete line in database
2916
+	 *
2917
+	 *	@return	 int  <0 if ko, >0 if ok
2918
+	 */
2919
+	function delete()
2920
+	{
2921
+		global $conf,$langs,$user;
2922
+
2923
+		$error=0;
2924
+		$this->db->begin();
2925
+
2926
+		$sql = "DELETE FROM ".MAIN_DB_PREFIX."supplier_proposaldet WHERE rowid = ".$this->rowid;
2927
+		dol_syslog("SupplierProposalLine::delete", LOG_DEBUG);
2928
+		if ($this->db->query($sql) )
2929
+		{
2930
+
2931
+			// Remove extrafields
2932
+			if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
2933
+			{
2934
+				$this->id=$this->rowid;
2935
+				$result=$this->deleteExtraFields();
2936
+				if ($result < 0)
2937
+				{
2938
+					$error++;
2939
+					dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR);
2940
+				}
2941
+			}
2942
+
2943
+			// Call trigger
2944
+			$result=$this->call_trigger('LINESUPPLIER_PROPOSAL_DELETE',$user);
2945
+			if ($result < 0)
2946
+			{
2947
+				$this->db->rollback();
2948
+				return -1;
2949
+			}
2950
+			// End call triggers
2951
+
2952
+			$this->db->commit();
2953
+
2954
+			return 1;
2955
+		}
2956
+		else
2957
+		{
2958
+			$this->error=$this->db->error()." sql=".$sql;
2959
+			$this->db->rollback();
2960
+			return -1;
2961
+		}
2962
+	}
2963
+
2964
+	/**
2965
+	 *	Update propal line object into DB
2966
+	 *
2967
+	 *	@param 	int		$notrigger	1=Does not execute triggers, 0= execute triggers
2968
+	 *	@return	int					<0 if ko, >0 if ok
2969
+	 */
2970
+	function update($notrigger=0)
2971
+	{
2972
+		global $conf,$langs,$user;
2973
+
2974
+		$error=0;
2975
+
2976
+		// Clean parameters
2977
+		if (empty($this->tva_tx)) $this->tva_tx=0;
2978
+		if (empty($this->localtax1_tx)) $this->localtax1_tx=0;
2979
+		if (empty($this->localtax2_tx)) $this->localtax2_tx=0;
2980
+		if (empty($this->total_localtax1)) $this->total_localtax1=0;
2981
+		if (empty($this->total_localtax2)) $this->total_localtax2=0;
2982 2982
 		if (empty($this->localtax1_type)) $this->localtax1_type=0;
2983 2983
 		if (empty($this->localtax2_type)) $this->localtax2_type=0;
2984
-        if (empty($this->marque_tx)) $this->marque_tx=0;
2985
-        if (empty($this->marge_tx)) $this->marge_tx=0;
2986
-        if (empty($this->price)) $this->price=0;	// TODO A virer
2987
-        if (empty($this->remise)) $this->remise=0;	// TODO A virer
2988
-        if (empty($this->remise_percent)) $this->remise_percent=0;
2989
-        if (empty($this->info_bits)) $this->info_bits=0;
2990
-        if (empty($this->special_code)) $this->special_code=0;
2991
-        if (empty($this->fk_parent_line)) $this->fk_parent_line=0;
2992
-        if (empty($this->fk_fournprice)) $this->fk_fournprice=0;
2993
-        if (empty($this->fk_unit)) $this->fk_unit=0;
2994
-        if (empty($this->subprice)) $this->subprice=0;
2984
+		if (empty($this->marque_tx)) $this->marque_tx=0;
2985
+		if (empty($this->marge_tx)) $this->marge_tx=0;
2986
+		if (empty($this->price)) $this->price=0;	// TODO A virer
2987
+		if (empty($this->remise)) $this->remise=0;	// TODO A virer
2988
+		if (empty($this->remise_percent)) $this->remise_percent=0;
2989
+		if (empty($this->info_bits)) $this->info_bits=0;
2990
+		if (empty($this->special_code)) $this->special_code=0;
2991
+		if (empty($this->fk_parent_line)) $this->fk_parent_line=0;
2992
+		if (empty($this->fk_fournprice)) $this->fk_fournprice=0;
2993
+		if (empty($this->fk_unit)) $this->fk_unit=0;
2994
+		if (empty($this->subprice)) $this->subprice=0;
2995 2995
 
2996 2996
 		if (empty($this->pa_ht)) $this->pa_ht=0;
2997 2997
 
@@ -3008,117 +3008,117 @@  discard block
 block discarded – undo
3008 3008
 			}
3009 3009
 		}
3010 3010
 
3011
-        $this->db->begin();
3011
+		$this->db->begin();
3012 3012
 
3013
-        // Mise a jour ligne en base
3014
-        $sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposaldet SET";
3015
-        $sql.= " description='".$this->db->escape($this->desc)."'";
3016
-        $sql.= " , label=".(! empty($this->label)?"'".$this->db->escape($this->label)."'":"null");
3017
-        $sql.= " , product_type=".$this->product_type;
3018
-        $sql.= " , tva_tx='".price2num($this->tva_tx)."'";
3019
-        $sql.= " , localtax1_tx=".price2num($this->localtax1_tx);
3020
-        $sql.= " , localtax2_tx=".price2num($this->localtax2_tx);
3013
+		// Mise a jour ligne en base
3014
+		$sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposaldet SET";
3015
+		$sql.= " description='".$this->db->escape($this->desc)."'";
3016
+		$sql.= " , label=".(! empty($this->label)?"'".$this->db->escape($this->label)."'":"null");
3017
+		$sql.= " , product_type=".$this->product_type;
3018
+		$sql.= " , tva_tx='".price2num($this->tva_tx)."'";
3019
+		$sql.= " , localtax1_tx=".price2num($this->localtax1_tx);
3020
+		$sql.= " , localtax2_tx=".price2num($this->localtax2_tx);
3021 3021
 		$sql.= " , localtax1_type='".$this->db->escape($this->localtax1_type)."'";
3022 3022
 		$sql.= " , localtax2_type='".$this->db->escape($this->localtax2_type)."'";
3023
-        $sql.= " , qty='".price2num($this->qty)."'";
3024
-        $sql.= " , subprice=".price2num($this->subprice)."";
3025
-        $sql.= " , remise_percent=".price2num($this->remise_percent)."";
3026
-        $sql.= " , price=".price2num($this->price)."";					// TODO A virer
3027
-        $sql.= " , remise=".price2num($this->remise)."";				// TODO A virer
3028
-        $sql.= " , info_bits='".$this->db->escape($this->info_bits)."'";
3029
-        if (empty($this->skip_update_total))
3030
-        {
3031
-            $sql.= " , total_ht=".price2num($this->total_ht)."";
3032
-            $sql.= " , total_tva=".price2num($this->total_tva)."";
3033
-            $sql.= " , total_ttc=".price2num($this->total_ttc)."";
3034
-            $sql.= " , total_localtax1=".price2num($this->total_localtax1)."";
3035
-            $sql.= " , total_localtax2=".price2num($this->total_localtax2)."";
3036
-        }
3023
+		$sql.= " , qty='".price2num($this->qty)."'";
3024
+		$sql.= " , subprice=".price2num($this->subprice)."";
3025
+		$sql.= " , remise_percent=".price2num($this->remise_percent)."";
3026
+		$sql.= " , price=".price2num($this->price)."";					// TODO A virer
3027
+		$sql.= " , remise=".price2num($this->remise)."";				// TODO A virer
3028
+		$sql.= " , info_bits='".$this->db->escape($this->info_bits)."'";
3029
+		if (empty($this->skip_update_total))
3030
+		{
3031
+			$sql.= " , total_ht=".price2num($this->total_ht)."";
3032
+			$sql.= " , total_tva=".price2num($this->total_tva)."";
3033
+			$sql.= " , total_ttc=".price2num($this->total_ttc)."";
3034
+			$sql.= " , total_localtax1=".price2num($this->total_localtax1)."";
3035
+			$sql.= " , total_localtax2=".price2num($this->total_localtax2)."";
3036
+		}
3037 3037
 		$sql.= " , fk_product_fournisseur_price=".(! empty($this->fk_fournprice)?"'".$this->db->escape($this->fk_fournprice)."'":"null");
3038 3038
 		$sql.= " , buy_price_ht=".price2num($this->pa_ht);
3039
-        if (strlen($this->special_code)) $sql.= " , special_code=".$this->special_code;
3040
-        $sql.= " , fk_parent_line=".($this->fk_parent_line>0?$this->fk_parent_line:"null");
3041
-        if (! empty($this->rang)) $sql.= ", rang=".$this->rang;
3042
-        $sql.= " , ref_fourn=".(! empty($this->ref_fourn)?"'".$this->db->escape($this->ref_fourn)."'":"null");
3043
-        $sql.= " , fk_unit=".($this->fk_unit?$this->fk_unit:'null');
3039
+		if (strlen($this->special_code)) $sql.= " , special_code=".$this->special_code;
3040
+		$sql.= " , fk_parent_line=".($this->fk_parent_line>0?$this->fk_parent_line:"null");
3041
+		if (! empty($this->rang)) $sql.= ", rang=".$this->rang;
3042
+		$sql.= " , ref_fourn=".(! empty($this->ref_fourn)?"'".$this->db->escape($this->ref_fourn)."'":"null");
3043
+		$sql.= " , fk_unit=".($this->fk_unit?$this->fk_unit:'null');
3044 3044
 
3045 3045
 		// Multicurrency
3046 3046
 		$sql.= " , multicurrency_subprice=".price2num($this->multicurrency_subprice)."";
3047
-        $sql.= " , multicurrency_total_ht=".price2num($this->multicurrency_total_ht)."";
3048
-        $sql.= " , multicurrency_total_tva=".price2num($this->multicurrency_total_tva)."";
3049
-        $sql.= " , multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc)."";
3047
+		$sql.= " , multicurrency_total_ht=".price2num($this->multicurrency_total_ht)."";
3048
+		$sql.= " , multicurrency_total_tva=".price2num($this->multicurrency_total_tva)."";
3049
+		$sql.= " , multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc)."";
3050
+
3051
+		$sql.= " WHERE rowid = ".$this->rowid;
3052
+
3053
+		dol_syslog(get_class($this)."::update", LOG_DEBUG);
3054
+		$resql=$this->db->query($sql);
3055
+		if ($resql)
3056
+		{
3057
+			if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
3058
+			{
3059
+				$this->id=$this->rowid;
3060
+				$result=$this->insertExtraFields();
3061
+				if ($result < 0)
3062
+				{
3063
+					$error++;
3064
+				}
3065
+			}
3066
+
3067
+			if (! $notrigger)
3068
+			{
3069
+				// Call trigger
3070
+				$result=$this->call_trigger('LINESUPPLIER_PROPOSAL_UPDATE',$user);
3071
+				if ($result < 0)
3072
+				{
3073
+					$this->db->rollback();
3074
+					return -1;
3075
+				}
3076
+				// End call triggers
3077
+			}
3078
+
3079
+			$this->db->commit();
3080
+			return 1;
3081
+		}
3082
+		else
3083
+		{
3084
+			$this->error=$this->db->error();
3085
+			$this->db->rollback();
3086
+			return -2;
3087
+		}
3088
+	}
3050 3089
 
3090
+	/**
3091
+	 *	Update DB line fields total_xxx
3092
+	 *	Used by migration
3093
+	 *
3094
+	 *	@return		int		<0 if ko, >0 if ok
3095
+	 */
3096
+	function update_total()
3097
+	{
3098
+		$this->db->begin();
3099
+
3100
+		// Mise a jour ligne en base
3101
+		$sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposaldet SET";
3102
+		$sql.= " total_ht=".price2num($this->total_ht,'MT')."";
3103
+		$sql.= ",total_tva=".price2num($this->total_tva,'MT')."";
3104
+		$sql.= ",total_ttc=".price2num($this->total_ttc,'MT')."";
3051 3105
 		$sql.= " WHERE rowid = ".$this->rowid;
3052 3106
 
3053
-        dol_syslog(get_class($this)."::update", LOG_DEBUG);
3054
-        $resql=$this->db->query($sql);
3055
-        if ($resql)
3056
-        {
3057
-        	if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
3058
-        	{
3059
-        		$this->id=$this->rowid;
3060
-        		$result=$this->insertExtraFields();
3061
-        		if ($result < 0)
3062
-        		{
3063
-        			$error++;
3064
-        		}
3065
-        	}
3066
-
3067
-            if (! $notrigger)
3068
-            {
3069
-                // Call trigger
3070
-                $result=$this->call_trigger('LINESUPPLIER_PROPOSAL_UPDATE',$user);
3071
-                if ($result < 0)
3072
-                {
3073
-                    $this->db->rollback();
3074
-                    return -1;
3075
-                }
3076
-                // End call triggers
3077
-            }
3078
-
3079
-            $this->db->commit();
3080
-            return 1;
3081
-        }
3082
-        else
3083
-        {
3084
-            $this->error=$this->db->error();
3085
-            $this->db->rollback();
3086
-            return -2;
3087
-        }
3088
-    }
3089
-
3090
-    /**
3091
-     *	Update DB line fields total_xxx
3092
-     *	Used by migration
3093
-     *
3094
-     *	@return		int		<0 if ko, >0 if ok
3095
-     */
3096
-    function update_total()
3097
-    {
3098
-        $this->db->begin();
3099
-
3100
-        // Mise a jour ligne en base
3101
-        $sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposaldet SET";
3102
-        $sql.= " total_ht=".price2num($this->total_ht,'MT')."";
3103
-        $sql.= ",total_tva=".price2num($this->total_tva,'MT')."";
3104
-        $sql.= ",total_ttc=".price2num($this->total_ttc,'MT')."";
3105
-        $sql.= " WHERE rowid = ".$this->rowid;
3106
-
3107
-        dol_syslog("SupplierProposalLine::update_total", LOG_DEBUG);
3108
-
3109
-        $resql=$this->db->query($sql);
3110
-        if ($resql)
3111
-        {
3112
-            $this->db->commit();
3113
-            return 1;
3114
-        }
3115
-        else
3116
-        {
3117
-            $this->error=$this->db->error();
3118
-            $this->db->rollback();
3119
-            return -2;
3120
-        }
3121
-    }
3107
+		dol_syslog("SupplierProposalLine::update_total", LOG_DEBUG);
3108
+
3109
+		$resql=$this->db->query($sql);
3110
+		if ($resql)
3111
+		{
3112
+			$this->db->commit();
3113
+			return 1;
3114
+		}
3115
+		else
3116
+		{
3117
+			$this->error=$this->db->error();
3118
+			$this->db->rollback();
3119
+			return -2;
3120
+		}
3121
+	}
3122 3122
 
3123 3123
 }
3124 3124
 
Please login to merge, or discard this patch.
Spacing   +805 added lines, -805 removed lines patch added patch discarded remove patch
@@ -32,40 +32,40 @@  discard block
 block discarded – undo
32 32
  *	\brief      File of class to manage supplier proposals
33 33
  */
34 34
 
35
-require_once DOL_DOCUMENT_ROOT .'/fourn/class/fournisseur.product.class.php';
36
-require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php';
37
-require_once DOL_DOCUMENT_ROOT .'/product/class/product.class.php';
38
-require_once DOL_DOCUMENT_ROOT .'/contact/class/contact.class.php';
39
-require_once DOL_DOCUMENT_ROOT .'/margin/lib/margins.lib.php';
40
-require_once DOL_DOCUMENT_ROOT .'/multicurrency/class/multicurrency.class.php';
35
+require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
36
+require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
37
+require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
38
+require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
39
+require_once DOL_DOCUMENT_ROOT.'/margin/lib/margins.lib.php';
40
+require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
41 41
 
42 42
 /**
43 43
  *	Class to manage price ask supplier
44 44
  */
45 45
 class SupplierProposal extends CommonObject
46 46
 {
47
-    public $element='supplier_proposal';
48
-    public $table_element='supplier_proposal';
49
-    public $table_element_line='supplier_proposaldet';
50
-    public $fk_element='fk_supplier_proposal';
51
-    protected $ismultientitymanaged = 1;	// 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
52
-    public $picto='propal';
47
+    public $element = 'supplier_proposal';
48
+    public $table_element = 'supplier_proposal';
49
+    public $table_element_line = 'supplier_proposaldet';
50
+    public $fk_element = 'fk_supplier_proposal';
51
+    protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
52
+    public $picto = 'propal';
53 53
 
54 54
     /**
55 55
      * {@inheritdoc}
56 56
      */
57 57
     protected $table_ref_field = 'ref';
58 58
 
59
-    var $socid;		// Id client
59
+    var $socid; // Id client
60 60
 
61 61
 	/**
62 62
 	 * @deprecated
63 63
 	 * @see user_author_id
64 64
 	 */
65 65
     var $author;
66
-	var $ref_fourn;  //Reference saisie lors de l'ajout d'une ligne à la demande
67
-    var $statut;					// 0 (draft), 1 (validated), 2 (signed), 3 (not signed), 4 (processed/billed)
68
-    var $date;						// Date of proposal
66
+	var $ref_fourn; //Reference saisie lors de l'ajout d'une ligne à la demande
67
+    var $statut; // 0 (draft), 1 (validated), 2 (signed), 3 (not signed), 4 (processed/billed)
68
+    var $date; // Date of proposal
69 69
     var $date_livraison;
70 70
 
71 71
 	/**
@@ -119,14 +119,14 @@  discard block
 block discarded – undo
119 119
     var $remise_percent;
120 120
     var $remise_absolue;
121 121
 
122
-    var $products=array();
123
-    var $extraparams=array();
122
+    var $products = array();
123
+    var $extraparams = array();
124 124
 
125 125
     var $lines = array();
126 126
     var $line;
127 127
 
128
-    var $labelstatut=array();
129
-    var $labelstatut_short=array();
128
+    var $labelstatut = array();
129
+    var $labelstatut_short = array();
130 130
 
131 131
     var $nbtodo;
132 132
     var $nbtodolate;
@@ -171,9 +171,9 @@  discard block
 block discarded – undo
171 171
      *	@param      int		$socid		Id third party
172 172
      *	@param      int		$supplier_proposalid   Id supplier_proposal
173 173
      */
174
-    function __construct($db, $socid="", $supplier_proposalid=0)
174
+    function __construct($db, $socid = "", $supplier_proposalid = 0)
175 175
     {
176
-        global $conf,$langs;
176
+        global $conf, $langs;
177 177
 
178 178
         $this->db = $db;
179 179
         $this->socid = $socid;
@@ -184,16 +184,16 @@  discard block
 block discarded – undo
184 184
         $this->remise_absolue = 0;
185 185
 
186 186
         $langs->load("supplier_proposal");
187
-        $this->labelstatut[0]=$langs->trans("SupplierProposalStatusDraft");
188
-        $this->labelstatut[1]=$langs->trans("SupplierProposalStatusValidated");
189
-        $this->labelstatut[2]=$langs->trans("SupplierProposalStatusSigned");
190
-        $this->labelstatut[3]=$langs->trans("SupplierProposalStatusNotSigned");
191
-        $this->labelstatut[4]=$langs->trans("SupplierProposalStatusClosed");
192
-        $this->labelstatut_short[0]=$langs->trans("SupplierProposalStatusDraftShort");
193
-        $this->labelstatut_short[1]=$langs->trans("Opened");
194
-        $this->labelstatut_short[2]=$langs->trans("SupplierProposalStatusSignedShort");
195
-        $this->labelstatut_short[3]=$langs->trans("SupplierProposalStatusNotSignedShort");
196
-        $this->labelstatut_short[4]=$langs->trans("SupplierProposalStatusClosedShort");
187
+        $this->labelstatut[0] = $langs->trans("SupplierProposalStatusDraft");
188
+        $this->labelstatut[1] = $langs->trans("SupplierProposalStatusValidated");
189
+        $this->labelstatut[2] = $langs->trans("SupplierProposalStatusSigned");
190
+        $this->labelstatut[3] = $langs->trans("SupplierProposalStatusNotSigned");
191
+        $this->labelstatut[4] = $langs->trans("SupplierProposalStatusClosed");
192
+        $this->labelstatut_short[0] = $langs->trans("SupplierProposalStatusDraftShort");
193
+        $this->labelstatut_short[1] = $langs->trans("Opened");
194
+        $this->labelstatut_short[2] = $langs->trans("SupplierProposalStatusSignedShort");
195
+        $this->labelstatut_short[3] = $langs->trans("SupplierProposalStatusNotSignedShort");
196
+        $this->labelstatut_short[4] = $langs->trans("SupplierProposalStatusClosedShort");
197 197
     }
198 198
 
199 199
 
@@ -209,28 +209,28 @@  discard block
 block discarded – undo
209 209
      *	TODO	Remplacer les appels a cette fonction par generation objet Ligne
210 210
      *			insere dans tableau $this->products
211 211
      */
212
-    function add_product($idproduct, $qty, $remise_percent=0)
212
+    function add_product($idproduct, $qty, $remise_percent = 0)
213 213
     {
214 214
         global $conf, $mysoc;
215 215
 
216
-        if (! $qty) $qty = 1;
216
+        if (!$qty) $qty = 1;
217 217
 
218 218
         dol_syslog(get_class($this)."::add_product $idproduct, $qty, $remise_percent");
219 219
         if ($idproduct > 0)
220 220
         {
221
-            $prod=new Product($this->db);
221
+            $prod = new Product($this->db);
222 222
             $prod->fetch($idproduct);
223 223
 
224 224
             $productdesc = $prod->description;
225 225
 
226
-            $tva_tx = get_default_tva($mysoc,$this->thirdparty,$prod->id);
227
-            $tva_npr = get_default_npr($mysoc,$this->thirdparty,$prod->id);
228
-            if (empty($tva_tx)) $tva_npr=0;
229
-            $localtax1_tx = get_localtax($tva_tx,1,$mysoc,$this->thirdparty,$tva_npr);
230
-            $localtax2_tx = get_localtax($tva_tx,2,$mysoc,$this->thirdparty,$tva_npr);
226
+            $tva_tx = get_default_tva($mysoc, $this->thirdparty, $prod->id);
227
+            $tva_npr = get_default_npr($mysoc, $this->thirdparty, $prod->id);
228
+            if (empty($tva_tx)) $tva_npr = 0;
229
+            $localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $this->thirdparty, $tva_npr);
230
+            $localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $this->thirdparty, $tva_npr);
231 231
 
232 232
             // multiprix
233
-            if($conf->global->PRODUIT_MULTIPRICES && $this->thirdparty->price_level)
233
+            if ($conf->global->PRODUIT_MULTIPRICES && $this->thirdparty->price_level)
234 234
             {
235 235
                 $price = $prod->multiprices[$this->thirdparty->price_level];
236 236
             }
@@ -241,14 +241,14 @@  discard block
 block discarded – undo
241 241
 
242 242
             $line = new SupplierProposalLine($this->db);
243 243
 
244
-            $line->fk_product=$idproduct;
245
-            $line->desc=$productdesc;
246
-            $line->qty=$qty;
247
-            $line->subprice=$price;
248
-            $line->remise_percent=$remise_percent;
249
-            $line->tva_tx=$tva_tx;
244
+            $line->fk_product = $idproduct;
245
+            $line->desc = $productdesc;
246
+            $line->qty = $qty;
247
+            $line->subprice = $price;
248
+            $line->remise_percent = $remise_percent;
249
+            $line->tva_tx = $tva_tx;
250 250
 
251
-            $this->lines[]=$line;
251
+            $this->lines[] = $line;
252 252
         }
253 253
     }
254 254
 
@@ -267,42 +267,42 @@  discard block
 block discarded – undo
267 267
 
268 268
         $this->db->begin();
269 269
 
270
-        $remise=new DiscountAbsolute($this->db);
271
-        $result=$remise->fetch($idremise);
270
+        $remise = new DiscountAbsolute($this->db);
271
+        $result = $remise->fetch($idremise);
272 272
 
273 273
         if ($result > 0)
274 274
         {
275 275
             if ($remise->fk_facture)	// Protection against multiple submission
276 276
             {
277
-                $this->error=$langs->trans("ErrorDiscountAlreadyUsed");
277
+                $this->error = $langs->trans("ErrorDiscountAlreadyUsed");
278 278
                 $this->db->rollback();
279 279
                 return -5;
280 280
             }
281 281
 
282
-            $supplier_proposalligne=new SupplierProposalLine($this->db);
283
-            $supplier_proposalligne->fk_supplier_proposal=$this->id;
284
-            $supplier_proposalligne->fk_remise_except=$remise->id;
285
-            $supplier_proposalligne->desc=$remise->description;   	// Description ligne
286
-            $supplier_proposalligne->tva_tx=$remise->tva_tx;
287
-            $supplier_proposalligne->subprice=-$remise->amount_ht;
288
-            $supplier_proposalligne->fk_product=0;					// Id produit predefini
289
-            $supplier_proposalligne->qty=1;
290
-            $supplier_proposalligne->remise=0;
291
-            $supplier_proposalligne->remise_percent=0;
292
-            $supplier_proposalligne->rang=-1;
293
-            $supplier_proposalligne->info_bits=2;
282
+            $supplier_proposalligne = new SupplierProposalLine($this->db);
283
+            $supplier_proposalligne->fk_supplier_proposal = $this->id;
284
+            $supplier_proposalligne->fk_remise_except = $remise->id;
285
+            $supplier_proposalligne->desc = $remise->description; // Description ligne
286
+            $supplier_proposalligne->tva_tx = $remise->tva_tx;
287
+            $supplier_proposalligne->subprice = -$remise->amount_ht;
288
+            $supplier_proposalligne->fk_product = 0; // Id produit predefini
289
+            $supplier_proposalligne->qty = 1;
290
+            $supplier_proposalligne->remise = 0;
291
+            $supplier_proposalligne->remise_percent = 0;
292
+            $supplier_proposalligne->rang = -1;
293
+            $supplier_proposalligne->info_bits = 2;
294 294
 
295 295
             // TODO deprecated
296
-            $supplier_proposalligne->price=-$remise->amount_ht;
296
+            $supplier_proposalligne->price = -$remise->amount_ht;
297 297
 
298 298
             $supplier_proposalligne->total_ht  = -$remise->amount_ht;
299 299
             $supplier_proposalligne->total_tva = -$remise->amount_tva;
300 300
             $supplier_proposalligne->total_ttc = -$remise->amount_ttc;
301 301
 
302
-            $result=$supplier_proposalligne->insert();
302
+            $result = $supplier_proposalligne->insert();
303 303
             if ($result > 0)
304 304
             {
305
-                $result=$this->update_price(1);
305
+                $result = $this->update_price(1);
306 306
                 if ($result > 0)
307 307
                 {
308 308
                     $this->db->commit();
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
             }
317 317
             else
318 318
             {
319
-                $this->error=$supplier_proposalligne->error;
319
+                $this->error = $supplier_proposalligne->error;
320 320
                 $this->db->rollback();
321 321
                 return -2;
322 322
             }
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
      *
363 363
      *    	@see       	add_product
364 364
      */
365
-    function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $pu_ttc=0, $info_bits=0, $type=0, $rang=-1, $special_code=0, $fk_parent_line=0, $fk_fournprice=0, $pa_ht=0, $label='',$array_option=0, $ref_fourn='', $fk_unit='', $origin='', $origin_id=0)
365
+    function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $fk_product = 0, $remise_percent = 0, $price_base_type = 'HT', $pu_ttc = 0, $info_bits = 0, $type = 0, $rang = -1, $special_code = 0, $fk_parent_line = 0, $fk_fournprice = 0, $pa_ht = 0, $label = '', $array_option = 0, $ref_fourn = '', $fk_unit = '', $origin = '', $origin_id = 0)
366 366
     {
367 367
     	global $mysoc;
368 368
 
@@ -370,27 +370,27 @@  discard block
 block discarded – undo
370 370
         include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
371 371
 
372 372
         // Clean parameters
373
-        if (empty($remise_percent)) $remise_percent=0;
374
-        if (empty($qty)) $qty=0;
375
-        if (empty($info_bits)) $info_bits=0;
376
-        if (empty($rang)) $rang=0;
377
-        if (empty($fk_parent_line) || $fk_parent_line < 0) $fk_parent_line=0;
378
-
379
-        $remise_percent=price2num($remise_percent);
380
-        $qty=price2num($qty);
381
-        $pu_ht=price2num($pu_ht);
382
-        $pu_ttc=price2num($pu_ttc);
383
-        $txtva=price2num($txtva);
384
-        $txlocaltax1=price2num($txlocaltax1);
385
-        $txlocaltax2=price2num($txlocaltax2);
386
-    		$pa_ht=price2num($pa_ht);
387
-        if ($price_base_type=='HT')
373
+        if (empty($remise_percent)) $remise_percent = 0;
374
+        if (empty($qty)) $qty = 0;
375
+        if (empty($info_bits)) $info_bits = 0;
376
+        if (empty($rang)) $rang = 0;
377
+        if (empty($fk_parent_line) || $fk_parent_line < 0) $fk_parent_line = 0;
378
+
379
+        $remise_percent = price2num($remise_percent);
380
+        $qty = price2num($qty);
381
+        $pu_ht = price2num($pu_ht);
382
+        $pu_ttc = price2num($pu_ttc);
383
+        $txtva = price2num($txtva);
384
+        $txlocaltax1 = price2num($txlocaltax1);
385
+        $txlocaltax2 = price2num($txlocaltax2);
386
+    		$pa_ht = price2num($pa_ht);
387
+        if ($price_base_type == 'HT')
388 388
         {
389
-            $pu=$pu_ht;
389
+            $pu = $pu_ht;
390 390
         }
391 391
         else
392 392
         {
393
-            $pu=$pu_ttc;
393
+            $pu = $pu_ttc;
394 394
         }
395 395
 
396 396
         // Check parameters
@@ -405,10 +405,10 @@  discard block
 block discarded – undo
405 405
             // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
406 406
             // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
407 407
 
408
-            $localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc);
409
-            $txtva = preg_replace('/\s*\(.*\)/','',$txtva);  // Remove code into vatrate.
408
+            $localtaxes_type = getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc);
409
+            $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
410 410
 
411
-            $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx);
411
+            $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx);
412 412
             $total_ht  = $tabprice[0];
413 413
             $total_tva = $tabprice[1];
414 414
             $total_ttc = $tabprice[2];
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
             $total_localtax2 = $tabprice[10];
417 417
 
418 418
 			// MultiCurrency
419
-			$multicurrency_total_ht  = $tabprice[16];
419
+			$multicurrency_total_ht = $tabprice[16];
420 420
             $multicurrency_total_tva = $tabprice[17];
421 421
             $multicurrency_total_ttc = $tabprice[18];
422 422
 
@@ -439,33 +439,33 @@  discard block
 block discarded – undo
439 439
             }
440 440
 
441 441
             // Insert line
442
-            $this->line=new SupplierProposalLine($this->db);
443
-
444
-            $this->line->fk_supplier_proposal=$this->id;
445
-            $this->line->label=$label;
446
-            $this->line->desc=$desc;
447
-            $this->line->qty=$qty;
448
-            $this->line->tva_tx=$txtva;
449
-            $this->line->localtax1_tx=$txlocaltax1;
450
-            $this->line->localtax2_tx=$txlocaltax2;
442
+            $this->line = new SupplierProposalLine($this->db);
443
+
444
+            $this->line->fk_supplier_proposal = $this->id;
445
+            $this->line->label = $label;
446
+            $this->line->desc = $desc;
447
+            $this->line->qty = $qty;
448
+            $this->line->tva_tx = $txtva;
449
+            $this->line->localtax1_tx = $txlocaltax1;
450
+            $this->line->localtax2_tx = $txlocaltax2;
451 451
 			$this->line->localtax1_type = $localtaxes_type[0];
452 452
 			$this->line->localtax2_type = $localtaxes_type[2];
453
-            $this->line->fk_product=$fk_product;
454
-            $this->line->remise_percent=$remise_percent;
455
-            $this->line->subprice=$pu_ht;
456
-            $this->line->rang=$rangtouse;
457
-            $this->line->info_bits=$info_bits;
458
-            $this->line->total_ht=$total_ht;
459
-            $this->line->total_tva=$total_tva;
460
-            $this->line->total_localtax1=$total_localtax1;
461
-            $this->line->total_localtax2=$total_localtax2;
462
-            $this->line->total_ttc=$total_ttc;
463
-            $this->line->product_type=$type;
464
-            $this->line->special_code=$special_code;
465
-            $this->line->fk_parent_line=$fk_parent_line;
466
-            $this->line->fk_unit=$fk_unit;
467
-            $this->line->origin=$origin;
468
-            $this->line->origin_id=$origin_id;
453
+            $this->line->fk_product = $fk_product;
454
+            $this->line->remise_percent = $remise_percent;
455
+            $this->line->subprice = $pu_ht;
456
+            $this->line->rang = $rangtouse;
457
+            $this->line->info_bits = $info_bits;
458
+            $this->line->total_ht = $total_ht;
459
+            $this->line->total_tva = $total_tva;
460
+            $this->line->total_localtax1 = $total_localtax1;
461
+            $this->line->total_localtax2 = $total_localtax2;
462
+            $this->line->total_ttc = $total_ttc;
463
+            $this->line->product_type = $type;
464
+            $this->line->special_code = $special_code;
465
+            $this->line->fk_parent_line = $fk_parent_line;
466
+            $this->line->fk_unit = $fk_unit;
467
+            $this->line->origin = $origin;
468
+            $this->line->origin_id = $origin_id;
469 469
 			$this->line->ref_fourn = $this->db->escape($ref_fourn);
470 470
 
471 471
 			// infos marge
@@ -481,32 +481,32 @@  discard block
 block discarded – undo
481 481
 			$this->line->pa_ht = $pa_ht;
482 482
 
483 483
 			// Multicurrency
484
-			$this->line->fk_multicurrency			= $this->fk_multicurrency;
485
-			$this->line->multicurrency_code			= $this->multicurrency_code;
484
+			$this->line->fk_multicurrency = $this->fk_multicurrency;
485
+			$this->line->multicurrency_code = $this->multicurrency_code;
486 486
 			$this->line->multicurrency_subprice		= price2num($pu_ht * $this->multicurrency_tx);
487 487
 			$this->line->multicurrency_total_ht 	= $multicurrency_total_ht;
488 488
             $this->line->multicurrency_total_tva 	= $multicurrency_total_tva;
489 489
             $this->line->multicurrency_total_ttc 	= $multicurrency_total_ttc;
490 490
 
491 491
             // Mise en option de la ligne
492
-            if (empty($qty) && empty($special_code)) $this->line->special_code=3;
492
+            if (empty($qty) && empty($special_code)) $this->line->special_code = 3;
493 493
 
494 494
             // TODO deprecated
495
-            $this->line->price=$price;
496
-            $this->line->remise=$remise;
495
+            $this->line->price = $price;
496
+            $this->line->remise = $remise;
497 497
 
498
-            if (is_array($array_option) && count($array_option)>0) {
499
-            	$this->line->array_options=$array_option;
498
+            if (is_array($array_option) && count($array_option) > 0) {
499
+            	$this->line->array_options = $array_option;
500 500
             }
501 501
 
502
-            $result=$this->line->insert();
502
+            $result = $this->line->insert();
503 503
             if ($result > 0)
504 504
             {
505 505
                 // Reorder if child line
506
-                if (! empty($fk_parent_line)) $this->line_order(true,'DESC');
506
+                if (!empty($fk_parent_line)) $this->line_order(true, 'DESC');
507 507
 
508 508
                 // Mise a jour informations denormalisees au niveau de la propale meme
509
-                $result=$this->update_price(1,'auto',0,$this->thirdparty);	// This method is designed to add line from user input so total calculation must be done using 'auto' mode.
509
+                $result = $this->update_price(1, 'auto', 0, $this->thirdparty); // This method is designed to add line from user input so total calculation must be done using 'auto' mode.
510 510
                 if ($result > 0)
511 511
                 {
512 512
                     $this->db->commit();
@@ -514,14 +514,14 @@  discard block
 block discarded – undo
514 514
                 }
515 515
                 else
516 516
                 {
517
-                    $this->error=$this->db->error();
517
+                    $this->error = $this->db->error();
518 518
                     $this->db->rollback();
519 519
                     return -1;
520 520
                 }
521 521
             }
522 522
             else
523 523
             {
524
-                $this->error=$this->line->error;
524
+                $this->error = $this->line->error;
525 525
                 $this->db->rollback();
526 526
                 return -2;
527 527
             }
@@ -554,23 +554,23 @@  discard block
 block discarded – undo
554 554
 	 *	@param		int			$fk_unit			Id of the unit to use.
555 555
      *  @return     int     		        		0 if OK, <0 if KO
556 556
      */
557
-	function updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0, $txlocaltax2=0, $desc='', $price_base_type='HT', $info_bits=0, $special_code=0, $fk_parent_line=0, $skip_update_total=0, $fk_fournprice=0, $pa_ht=0, $label='', $type=0, $array_option=0, $ref_fourn='', $fk_unit='')
557
+	function updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $desc = '', $price_base_type = 'HT', $info_bits = 0, $special_code = 0, $fk_parent_line = 0, $skip_update_total = 0, $fk_fournprice = 0, $pa_ht = 0, $label = '', $type = 0, $array_option = 0, $ref_fourn = '', $fk_unit = '')
558 558
     {
559
-        global $conf,$user,$langs, $mysoc;
559
+        global $conf, $user, $langs, $mysoc;
560 560
 
561 561
         dol_syslog(get_class($this)."::updateLine $rowid, $pu, $qty, $remise_percent, $txtva, $desc, $price_base_type, $info_bits");
562 562
         include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
563 563
 
564 564
         // Clean parameters
565
-        $remise_percent=price2num($remise_percent);
566
-        $qty=price2num($qty);
565
+        $remise_percent = price2num($remise_percent);
566
+        $qty = price2num($qty);
567 567
         $pu = price2num($pu);
568 568
         $txtva = price2num($txtva);
569
-        $txlocaltax1=price2num($txlocaltax1);
570
-        $txlocaltax2=price2num($txlocaltax2);
571
-    	$pa_ht=price2num($pa_ht);
572
-        if (empty($qty) && empty($special_code)) $special_code=3;    // Set option tag
573
-        if (! empty($qty) && $special_code == 3) $special_code=0;    // Remove option tag
569
+        $txlocaltax1 = price2num($txlocaltax1);
570
+        $txlocaltax2 = price2num($txlocaltax2);
571
+    	$pa_ht = price2num($pa_ht);
572
+        if (empty($qty) && empty($special_code)) $special_code = 3; // Set option tag
573
+        if (!empty($qty) && $special_code == 3) $special_code = 0; // Remove option tag
574 574
 
575 575
         if ($this->statut == 0)
576 576
         {
@@ -581,10 +581,10 @@  discard block
 block discarded – undo
581 581
             // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
582 582
             // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
583 583
 
584
-            $localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc);
585
-            $txtva = preg_replace('/\s*\(.*\)/','',$txtva);  // Remove code into vatrate.
584
+            $localtaxes_type = getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc);
585
+            $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
586 586
 
587
-            $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx);
587
+            $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx);
588 588
             $total_ht  = $tabprice[0];
589 589
             $total_tva = $tabprice[1];
590 590
             $total_ttc = $tabprice[2];
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
             $total_localtax2 = $tabprice[10];
593 593
 
594 594
 			// MultiCurrency
595
-			$multicurrency_total_ht  = $tabprice[16];
595
+			$multicurrency_total_ht = $tabprice[16];
596 596
             $multicurrency_total_tva = $tabprice[17];
597 597
             $multicurrency_total_ttc = $tabprice[18];
598 598
 
@@ -605,15 +605,15 @@  discard block
 block discarded – undo
605 605
             }
606 606
 
607 607
             // Update line
608
-            $this->line=new SupplierProposalLine($this->db);
608
+            $this->line = new SupplierProposalLine($this->db);
609 609
 
610 610
             // Stock previous line records
611
-            $staticline=new SupplierProposalLine($this->db);
611
+            $staticline = new SupplierProposalLine($this->db);
612 612
             $staticline->fetch($rowid);
613 613
             $this->line->oldline = $staticline;
614 614
 
615 615
             // Reorder if fk_parent_line change
616
-            if (! empty($fk_parent_line) && ! empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line)
616
+            if (!empty($fk_parent_line) && !empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line)
617 617
             {
618 618
                 $rangmax = $this->line_max($fk_parent_line);
619 619
                 $this->line->rang = $rangmax + 1;
@@ -621,15 +621,15 @@  discard block
 block discarded – undo
621 621
 
622 622
             $this->line->rowid				= $rowid;
623 623
             $this->line->label				= $label;
624
-            $this->line->desc				= $desc;
625
-            $this->line->qty				= $qty;
626
-            $this->line->product_type			= $type;
627
-            $this->line->tva_tx				= $txtva;
624
+            $this->line->desc = $desc;
625
+            $this->line->qty = $qty;
626
+            $this->line->product_type = $type;
627
+            $this->line->tva_tx = $txtva;
628 628
             $this->line->localtax1_tx		= $txlocaltax1;
629 629
             $this->line->localtax2_tx		= $txlocaltax2;
630 630
 			$this->line->localtax1_type		= $localtaxes_type[0];
631 631
 			$this->line->localtax2_type		= $localtaxes_type[2];
632
-            $this->line->remise_percent		= $remise_percent;
632
+            $this->line->remise_percent = $remise_percent;
633 633
             $this->line->subprice			= $pu;
634 634
             $this->line->info_bits			= $info_bits;
635 635
             $this->line->total_ht			= $total_ht;
@@ -637,11 +637,11 @@  discard block
 block discarded – undo
637 637
             $this->line->total_localtax1	= $total_localtax1;
638 638
             $this->line->total_localtax2	= $total_localtax2;
639 639
             $this->line->total_ttc			= $total_ttc;
640
-            $this->line->special_code		= $special_code;
640
+            $this->line->special_code = $special_code;
641 641
             $this->line->fk_parent_line		= $fk_parent_line;
642
-            $this->line->skip_update_total	= $skip_update_total;
643
-            $this->line->ref_fourn			= $ref_fourn;
644
-			$this->line->fk_unit			= $fk_unit;
642
+            $this->line->skip_update_total = $skip_update_total;
643
+            $this->line->ref_fourn = $ref_fourn;
644
+			$this->line->fk_unit = $fk_unit;
645 645
 
646 646
             // infos marge
647 647
             if (!empty($fk_product) && empty($fk_fournprice) && empty($pa_ht)) {
@@ -656,11 +656,11 @@  discard block
 block discarded – undo
656 656
             $this->line->pa_ht = $pa_ht;
657 657
 
658 658
             // TODO deprecated
659
-            $this->line->price=$price;
660
-            $this->line->remise=$remise;
659
+            $this->line->price = $price;
660
+            $this->line->remise = $remise;
661 661
 
662
-            if (is_array($array_option) && count($array_option)>0) {
663
-            	$this->line->array_options=$array_option;
662
+            if (is_array($array_option) && count($array_option) > 0) {
663
+            	$this->line->array_options = $array_option;
664 664
             }
665 665
 
666 666
 			// Multicurrency
@@ -669,11 +669,11 @@  discard block
 block discarded – undo
669 669
             $this->line->multicurrency_total_tva 	= $multicurrency_total_tva;
670 670
             $this->line->multicurrency_total_ttc 	= $multicurrency_total_ttc;
671 671
 
672
-            $result=$this->line->update();
672
+            $result = $this->line->update();
673 673
             if ($result > 0)
674 674
             {
675 675
                 // Reorder if child line
676
-                if (! empty($fk_parent_line)) $this->line_order(true,'DESC');
676
+                if (!empty($fk_parent_line)) $this->line_order(true, 'DESC');
677 677
 
678 678
                 $this->update_price(1);
679 679
 
@@ -685,7 +685,7 @@  discard block
 block discarded – undo
685 685
             }
686 686
             else
687 687
             {
688
-                $this->error=$this->db->error();
688
+                $this->error = $this->db->error();
689 689
                 $this->db->rollback();
690 690
                 return -1;
691 691
             }
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
     {
709 709
         if ($this->statut == 0)
710 710
         {
711
-            $line=new SupplierProposalLine($this->db);
711
+            $line = new SupplierProposalLine($this->db);
712 712
 
713 713
             // For triggers
714 714
             $line->fetch($lineid);
@@ -739,39 +739,39 @@  discard block
 block discarded – undo
739 739
      * 	@param		int		$notrigger	1=Does not execute triggers, 0= execute triggers
740 740
      *  @return     int     			<0 if KO, >=0 if OK
741 741
      */
742
-    function create($user, $notrigger=0)
742
+    function create($user, $notrigger = 0)
743 743
     {
744
-        global $langs,$conf,$mysoc,$hookmanager;
745
-        $error=0;
744
+        global $langs, $conf, $mysoc, $hookmanager;
745
+        $error = 0;
746 746
 
747
-        $now=dol_now();
747
+        $now = dol_now();
748 748
 
749 749
         dol_syslog(get_class($this)."::create");
750 750
 
751 751
         // Check parameters
752
-        $result=$this->fetch_thirdparty();
752
+        $result = $this->fetch_thirdparty();
753 753
         if ($result < 0)
754 754
         {
755
-            $this->error="Failed to fetch company";
755
+            $this->error = "Failed to fetch company";
756 756
             dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
757 757
             return -3;
758 758
         }
759 759
 
760 760
         // Check parameters
761
-		if (! empty($this->ref))	// We check that ref is not already used
761
+		if (!empty($this->ref))	// We check that ref is not already used
762 762
 		{
763
-			$result=self::isExistingObject($this->element, 0, $this->ref);	// Check ref is not yet used
763
+			$result = self::isExistingObject($this->element, 0, $this->ref); // Check ref is not yet used
764 764
 			if ($result > 0)
765 765
 			{
766
-				$this->error='ErrorRefAlreadyExists';
767
-				dol_syslog(get_class($this)."::create ".$this->error,LOG_WARNING);
766
+				$this->error = 'ErrorRefAlreadyExists';
767
+				dol_syslog(get_class($this)."::create ".$this->error, LOG_WARNING);
768 768
 				$this->db->rollback();
769 769
 				return -1;
770 770
 			}
771 771
 		}
772 772
 
773 773
 		// Multicurrency
774
-		if (!empty($this->multicurrency_code)) list($this->fk_multicurrency,$this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code);
774
+		if (!empty($this->multicurrency_code)) list($this->fk_multicurrency, $this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code);
775 775
 		if (empty($this->fk_multicurrency))
776 776
 		{
777 777
 			$this->multicurrency_code = $conf->currency;
@@ -783,80 +783,80 @@  discard block
 block discarded – undo
783 783
 
784 784
         // Insert into database
785 785
         $sql = "INSERT INTO ".MAIN_DB_PREFIX."supplier_proposal (";
786
-        $sql.= "fk_soc";
787
-        $sql.= ", price";
788
-        $sql.= ", remise";
789
-        $sql.= ", remise_percent";
790
-        $sql.= ", remise_absolue";
791
-        $sql.= ", tva";
792
-        $sql.= ", total";
793
-        $sql.= ", datec";
794
-        $sql.= ", ref";
795
-        $sql.= ", fk_user_author";
796
-        $sql.= ", note_private";
797
-        $sql.= ", note_public";
798
-        $sql.= ", model_pdf";
799
-        $sql.= ", fk_cond_reglement";
800
-        $sql.= ", fk_mode_reglement";
801
-        $sql.= ", fk_account";
802
-        $sql.= ", date_livraison";
803
-        $sql.= ", fk_shipping_method";
804
-        $sql.= ", fk_projet";
805
-        $sql.= ", entity";
806
-        $sql.= ", fk_multicurrency";
807
-        $sql.= ", multicurrency_code";
808
-        $sql.= ", multicurrency_tx";
809
-        $sql.= ") ";
810
-        $sql.= " VALUES (";
811
-        $sql.= $this->socid;
812
-        $sql.= ", 0";
813
-        $sql.= ", ".$this->remise;
814
-        $sql.= ", ".($this->remise_percent?$this->db->escape($this->remise_percent):'null');
815
-        $sql.= ", ".($this->remise_absolue?$this->db->escape($this->remise_absolue):'null');
816
-        $sql.= ", 0";
817
-        $sql.= ", 0";
818
-        $sql.= ", '".$this->db->idate($now)."'";
819
-        $sql.= ", '(PROV)'";
820
-        $sql.= ", ".($user->id > 0 ? "'".$user->id."'":"null");
821
-        $sql.= ", '".$this->db->escape($this->note_private)."'";
822
-        $sql.= ", '".$this->db->escape($this->note_public)."'";
823
-        $sql.= ", '".$this->db->escape($this->modelpdf)."'";
824
-        $sql.= ", ".$this->cond_reglement_id;
825
-        $sql.= ", ".$this->mode_reglement_id;
826
-        $sql.= ", ".($this->fk_account>0?$this->fk_account:'NULL');
827
-        $sql.= ", ".($this->date_livraison!=''?"'".$this->db->idate($this->date_livraison)."'":"null");
828
-        $sql.= ", ".($this->shipping_method_id>0?$this->shipping_method_id:'NULL');
829
-        $sql.= ", ".($this->fk_project?$this->fk_project:"null");
830
-        $sql.= ", ".$conf->entity;
831
-		$sql.= ", ".(int) $this->fk_multicurrency;
832
-		$sql.= ", '".$this->db->escape($this->multicurrency_code)."'";
833
-		$sql.= ", ".(double) $this->multicurrency_tx;
834
-        $sql.= ")";
786
+        $sql .= "fk_soc";
787
+        $sql .= ", price";
788
+        $sql .= ", remise";
789
+        $sql .= ", remise_percent";
790
+        $sql .= ", remise_absolue";
791
+        $sql .= ", tva";
792
+        $sql .= ", total";
793
+        $sql .= ", datec";
794
+        $sql .= ", ref";
795
+        $sql .= ", fk_user_author";
796
+        $sql .= ", note_private";
797
+        $sql .= ", note_public";
798
+        $sql .= ", model_pdf";
799
+        $sql .= ", fk_cond_reglement";
800
+        $sql .= ", fk_mode_reglement";
801
+        $sql .= ", fk_account";
802
+        $sql .= ", date_livraison";
803
+        $sql .= ", fk_shipping_method";
804
+        $sql .= ", fk_projet";
805
+        $sql .= ", entity";
806
+        $sql .= ", fk_multicurrency";
807
+        $sql .= ", multicurrency_code";
808
+        $sql .= ", multicurrency_tx";
809
+        $sql .= ") ";
810
+        $sql .= " VALUES (";
811
+        $sql .= $this->socid;
812
+        $sql .= ", 0";
813
+        $sql .= ", ".$this->remise;
814
+        $sql .= ", ".($this->remise_percent ? $this->db->escape($this->remise_percent) : 'null');
815
+        $sql .= ", ".($this->remise_absolue ? $this->db->escape($this->remise_absolue) : 'null');
816
+        $sql .= ", 0";
817
+        $sql .= ", 0";
818
+        $sql .= ", '".$this->db->idate($now)."'";
819
+        $sql .= ", '(PROV)'";
820
+        $sql .= ", ".($user->id > 0 ? "'".$user->id."'" : "null");
821
+        $sql .= ", '".$this->db->escape($this->note_private)."'";
822
+        $sql .= ", '".$this->db->escape($this->note_public)."'";
823
+        $sql .= ", '".$this->db->escape($this->modelpdf)."'";
824
+        $sql .= ", ".$this->cond_reglement_id;
825
+        $sql .= ", ".$this->mode_reglement_id;
826
+        $sql .= ", ".($this->fk_account > 0 ? $this->fk_account : 'NULL');
827
+        $sql .= ", ".($this->date_livraison != '' ? "'".$this->db->idate($this->date_livraison)."'" : "null");
828
+        $sql .= ", ".($this->shipping_method_id > 0 ? $this->shipping_method_id : 'NULL');
829
+        $sql .= ", ".($this->fk_project ? $this->fk_project : "null");
830
+        $sql .= ", ".$conf->entity;
831
+		$sql .= ", ".(int) $this->fk_multicurrency;
832
+		$sql .= ", '".$this->db->escape($this->multicurrency_code)."'";
833
+		$sql .= ", ".(double) $this->multicurrency_tx;
834
+        $sql .= ")";
835 835
 
836 836
         dol_syslog(get_class($this)."::create", LOG_DEBUG);
837
-        $resql=$this->db->query($sql);
837
+        $resql = $this->db->query($sql);
838 838
         if ($resql)
839 839
         {
840 840
             $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."supplier_proposal");
841 841
 
842 842
             if ($this->id)
843 843
             {
844
-                $this->ref='(PROV'.$this->id.')';
844
+                $this->ref = '(PROV'.$this->id.')';
845 845
                 $sql = 'UPDATE '.MAIN_DB_PREFIX."supplier_proposal SET ref='".$this->db->escape($this->ref)."' WHERE rowid=".$this->id;
846 846
 
847 847
                 dol_syslog(get_class($this)."::create", LOG_DEBUG);
848
-                $resql=$this->db->query($sql);
849
-                if (! $resql) $error++;
848
+                $resql = $this->db->query($sql);
849
+                if (!$resql) $error++;
850 850
 
851 851
                 /*
852 852
                  *  Insertion du detail des produits dans la base
853 853
                 */
854
-                if (! $error)
854
+                if (!$error)
855 855
                 {
856
-                    $fk_parent_line=0;
857
-                    $num=count($this->lines);
856
+                    $fk_parent_line = 0;
857
+                    $num = count($this->lines);
858 858
 
859
-                    for ($i=0;$i<$num;$i++)
859
+                    for ($i = 0; $i < $num; $i++)
860 860
                     {
861 861
                         // Reset fk_parent_line for no child products and special product
862 862
                         if (($this->lines[$i]->product_type != 9 && empty($this->lines[$i]->fk_parent_line)) || $this->lines[$i]->product_type == 9) {
@@ -892,7 +892,7 @@  discard block
 block discarded – undo
892 892
                         if ($result < 0)
893 893
                         {
894 894
                             $error++;
895
-                            $this->error=$this->db->error;
895
+                            $this->error = $this->db->error;
896 896
                             dol_print_error($this->db);
897 897
                             break;
898 898
                         }
@@ -904,29 +904,29 @@  discard block
 block discarded – undo
904 904
                 }
905 905
 
906 906
                 // Add linked object
907
-                if (! $error && $this->origin && $this->origin_id)
907
+                if (!$error && $this->origin && $this->origin_id)
908 908
                 {
909 909
                     $ret = $this->add_object_linked();
910
-                    if (! $ret)	dol_print_error($this->db);
910
+                    if (!$ret)	dol_print_error($this->db);
911 911
                 }
912 912
 
913
-                if (! $error)
913
+                if (!$error)
914 914
                 {
915 915
                     // Mise a jour infos denormalisees
916
-                    $resql=$this->update_price(1);
916
+                    $resql = $this->update_price(1);
917 917
                     if ($resql)
918 918
                     {
919
-                    	$action='update';
919
+                    	$action = 'update';
920 920
 
921 921
                     	// Actions on extra fields (by external module or standard code)
922 922
                     	$hookmanager->initHooks(array('supplier_proposaldao'));
923
-                    	$parameters=array('socid'=>$this->id);
924
-                    	$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
923
+                    	$parameters = array('socid'=>$this->id);
924
+                    	$reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
925 925
                     	if (empty($reshook))
926 926
                     	{
927 927
                     		if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
928 928
                     		{
929
-                    			$result=$this->insertExtraFields();
929
+                    			$result = $this->insertExtraFields();
930 930
                     			if ($result < 0)
931 931
                     			{
932 932
                     				$error++;
@@ -935,28 +935,28 @@  discard block
 block discarded – undo
935 935
                     	}
936 936
                     	else if ($reshook < 0) $error++;
937 937
 
938
-                        if (! $notrigger)
938
+                        if (!$notrigger)
939 939
                         {
940 940
                             // Call trigger
941
-                            $result=$this->call_trigger('PROPAL_SUPPLIER_CREATE',$user);
941
+                            $result = $this->call_trigger('PROPAL_SUPPLIER_CREATE', $user);
942 942
                             if ($result < 0) { $error++; }
943 943
                             // End call triggers
944 944
                         }
945 945
                     }
946 946
                     else
947 947
 					{
948
-                        $this->error=$this->db->lasterror();
948
+                        $this->error = $this->db->lasterror();
949 949
                         $error++;
950 950
                     }
951 951
                 }
952 952
             }
953 953
             else
954 954
 			{
955
-                $this->error=$this->db->lasterror();
955
+                $this->error = $this->db->lasterror();
956 956
                 $error++;
957 957
             }
958 958
 
959
-            if (! $error)
959
+            if (!$error)
960 960
             {
961 961
                 $this->db->commit();
962 962
                 dol_syslog(get_class($this)."::create done id=".$this->id);
@@ -970,7 +970,7 @@  discard block
 block discarded – undo
970 970
         }
971 971
         else
972 972
         {
973
-            $this->error=$this->db->lasterror();
973
+            $this->error = $this->db->lasterror();
974 974
             $this->db->rollback();
975 975
             return -1;
976 976
         }
@@ -986,7 +986,7 @@  discard block
 block discarded – undo
986 986
      */
987 987
     function create_from($user)
988 988
     {
989
-        $this->products=$this->lines;
989
+        $this->products = $this->lines;
990 990
 
991 991
         return $this->create($user);
992 992
     }
@@ -997,33 +997,33 @@  discard block
 block discarded – undo
997 997
      *		@param		int				$socid			Id of thirdparty
998 998
      * 	 	@return		int								New id of clone
999 999
      */
1000
-    function createFromClone($socid=0)
1000
+    function createFromClone($socid = 0)
1001 1001
     {
1002
-        global $user,$langs,$conf,$hookmanager;
1002
+        global $user, $langs, $conf, $hookmanager;
1003 1003
 
1004
-        $error=0;
1005
-        $now=dol_now();
1004
+        $error = 0;
1005
+        $now = dol_now();
1006 1006
 
1007 1007
         $this->db->begin();
1008 1008
 
1009 1009
 		// get extrafields so they will be clone
1010
-		foreach($this->lines as $line)
1010
+		foreach ($this->lines as $line)
1011 1011
 			$line->fetch_optionals($line->rowid);
1012 1012
 
1013 1013
 		// Load source object
1014 1014
 		$objFrom = clone $this;
1015 1015
 
1016
-        $objsoc=new Societe($this->db);
1016
+        $objsoc = new Societe($this->db);
1017 1017
 
1018 1018
         // Change socid if needed
1019
-        if (! empty($socid) && $socid != $this->socid)
1019
+        if (!empty($socid) && $socid != $this->socid)
1020 1020
         {
1021 1021
             if ($objsoc->fetch($socid) > 0)
1022 1022
             {
1023
-                $this->socid 				= $objsoc->id;
1024
-                $this->cond_reglement_id	= (! empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1025
-                $this->mode_reglement_id	= (! empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1026
-                $this->fk_project			= '';
1023
+                $this->socid = $objsoc->id;
1024
+                $this->cond_reglement_id	= (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1025
+                $this->mode_reglement_id	= (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1026
+                $this->fk_project = '';
1027 1027
             }
1028 1028
 
1029 1029
             // TODO Change product price if multi-prices
@@ -1033,49 +1033,49 @@  discard block
 block discarded – undo
1033 1033
             $objsoc->fetch($this->socid);
1034 1034
         }
1035 1035
 
1036
-        $this->id=0;
1037
-        $this->statut=0;
1036
+        $this->id = 0;
1037
+        $this->statut = 0;
1038 1038
 
1039
-        if (empty($conf->global->SUPPLIER_PROPOSAL_ADDON) || ! is_readable(DOL_DOCUMENT_ROOT ."/core/modules/supplier_proposal/".$conf->global->SUPPLIER_PROPOSAL_ADDON.".php"))
1039
+        if (empty($conf->global->SUPPLIER_PROPOSAL_ADDON) || !is_readable(DOL_DOCUMENT_ROOT."/core/modules/supplier_proposal/".$conf->global->SUPPLIER_PROPOSAL_ADDON.".php"))
1040 1040
         {
1041
-            $this->error='ErrorSetupNotComplete';
1041
+            $this->error = 'ErrorSetupNotComplete';
1042 1042
             return -1;
1043 1043
         }
1044 1044
 
1045 1045
         // Clear fields
1046
-        $this->user_author	= $user->id;
1047
-        $this->user_valid	= '';
1048
-        $this->date			= $now;
1046
+        $this->user_author = $user->id;
1047
+        $this->user_valid = '';
1048
+        $this->date = $now;
1049 1049
 
1050 1050
         // Set ref
1051
-        require_once DOL_DOCUMENT_ROOT ."/core/modules/supplier_proposal/".$conf->global->SUPPLIER_PROPOSAL_ADDON.'.php';
1051
+        require_once DOL_DOCUMENT_ROOT."/core/modules/supplier_proposal/".$conf->global->SUPPLIER_PROPOSAL_ADDON.'.php';
1052 1052
         $obj = $conf->global->SUPPLIER_PROPOSAL_ADDON;
1053 1053
         $modSupplierProposal = new $obj;
1054
-        $this->ref = $modSupplierProposal->getNextValue($objsoc,$this);
1054
+        $this->ref = $modSupplierProposal->getNextValue($objsoc, $this);
1055 1055
 
1056 1056
         // Create clone
1057
-        $result=$this->create($user);
1057
+        $result = $this->create($user);
1058 1058
         if ($result < 0) $error++;
1059 1059
 
1060
-        if (! $error)
1060
+        if (!$error)
1061 1061
         {
1062 1062
             // Hook of thirdparty module
1063 1063
             if (is_object($hookmanager))
1064 1064
             {
1065
-                $parameters=array('objFrom'=>$objFrom);
1066
-                $action='';
1067
-                $reshook=$hookmanager->executeHooks('createFrom',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
1065
+                $parameters = array('objFrom'=>$objFrom);
1066
+                $action = '';
1067
+                $reshook = $hookmanager->executeHooks('createFrom', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1068 1068
                 if ($reshook < 0) $error++;
1069 1069
             }
1070 1070
 
1071 1071
             // Call trigger
1072
-            $result=$this->call_trigger('SUPPLIER_PROPOSAL_CLONE',$user);
1072
+            $result = $this->call_trigger('SUPPLIER_PROPOSAL_CLONE', $user);
1073 1073
             if ($result < 0) { $error++; }
1074 1074
             // End call triggers
1075 1075
         }
1076 1076
 
1077 1077
         // End
1078
-        if (! $error)
1078
+        if (!$error)
1079 1079
         {
1080 1080
             $this->db->commit();
1081 1081
             return $this->id;
@@ -1094,37 +1094,37 @@  discard block
 block discarded – undo
1094 1094
      *	@param		string		$ref		Ref of proposal
1095 1095
      *	@return     int         			>0 if OK, <0 if KO
1096 1096
      */
1097
-    function fetch($rowid,$ref='')
1097
+    function fetch($rowid, $ref = '')
1098 1098
     {
1099 1099
         global $conf;
1100 1100
 
1101 1101
         $sql = "SELECT p.rowid, p.ref, p.remise, p.remise_percent, p.remise_absolue, p.fk_soc";
1102
-        $sql.= ", p.total, p.tva, p.localtax1, p.localtax2, p.total_ht";
1103
-        $sql.= ", p.datec";
1104
-        $sql.= ", p.date_valid as datev";
1105
-        $sql.= ", p.date_livraison as date_livraison";
1106
-        $sql.= ", p.model_pdf, p.extraparams";
1107
-        $sql.= ", p.note_private, p.note_public";
1108
-        $sql.= ", p.fk_projet, p.fk_statut";
1109
-        $sql.= ", p.fk_user_author, p.fk_user_valid, p.fk_user_cloture";
1110
-        $sql.= ", p.fk_cond_reglement";
1111
-        $sql.= ", p.fk_mode_reglement";
1112
-        $sql.= ', p.fk_account';
1113
-        $sql.= ", p.fk_shipping_method";
1114
-		$sql.= ", p.fk_multicurrency, p.multicurrency_code, p.multicurrency_tx, p.multicurrency_total_ht, p.multicurrency_total_tva, p.multicurrency_total_ttc";
1115
-        $sql.= ", c.label as statut_label";
1116
-        $sql.= ", cr.code as cond_reglement_code, cr.libelle as cond_reglement, cr.libelle_facture as cond_reglement_libelle_doc";
1117
-        $sql.= ", cp.code as mode_reglement_code, cp.libelle as mode_reglement";
1118
-        $sql.= " FROM ".MAIN_DB_PREFIX."c_propalst as c, ".MAIN_DB_PREFIX."supplier_proposal as p";
1119
-        $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_mode_reglement = cp.id AND cp.entity IN (' . getEntity('c_paiement').')';
1120
-        $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON p.fk_cond_reglement = cr.rowid AND cr.entity IN (' . getEntity('c_payment_term').')';
1121
-        $sql.= " WHERE p.fk_statut = c.id";
1122
-        $sql.= " AND p.entity = ".$conf->entity;
1123
-        if ($ref) $sql.= " AND p.ref='".$ref."'";
1124
-        else $sql.= " AND p.rowid=".$rowid;
1102
+        $sql .= ", p.total, p.tva, p.localtax1, p.localtax2, p.total_ht";
1103
+        $sql .= ", p.datec";
1104
+        $sql .= ", p.date_valid as datev";
1105
+        $sql .= ", p.date_livraison as date_livraison";
1106
+        $sql .= ", p.model_pdf, p.extraparams";
1107
+        $sql .= ", p.note_private, p.note_public";
1108
+        $sql .= ", p.fk_projet, p.fk_statut";
1109
+        $sql .= ", p.fk_user_author, p.fk_user_valid, p.fk_user_cloture";
1110
+        $sql .= ", p.fk_cond_reglement";
1111
+        $sql .= ", p.fk_mode_reglement";
1112
+        $sql .= ', p.fk_account';
1113
+        $sql .= ", p.fk_shipping_method";
1114
+		$sql .= ", p.fk_multicurrency, p.multicurrency_code, p.multicurrency_tx, p.multicurrency_total_ht, p.multicurrency_total_tva, p.multicurrency_total_ttc";
1115
+        $sql .= ", c.label as statut_label";
1116
+        $sql .= ", cr.code as cond_reglement_code, cr.libelle as cond_reglement, cr.libelle_facture as cond_reglement_libelle_doc";
1117
+        $sql .= ", cp.code as mode_reglement_code, cp.libelle as mode_reglement";
1118
+        $sql .= " FROM ".MAIN_DB_PREFIX."c_propalst as c, ".MAIN_DB_PREFIX."supplier_proposal as p";
1119
+        $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_mode_reglement = cp.id AND cp.entity IN ('.getEntity('c_paiement').')';
1120
+        $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON p.fk_cond_reglement = cr.rowid AND cr.entity IN ('.getEntity('c_payment_term').')';
1121
+        $sql .= " WHERE p.fk_statut = c.id";
1122
+        $sql .= " AND p.entity = ".$conf->entity;
1123
+        if ($ref) $sql .= " AND p.ref='".$ref."'";
1124
+        else $sql .= " AND p.rowid=".$rowid;
1125 1125
 
1126 1126
         dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
1127
-        $resql=$this->db->query($sql);
1127
+        $resql = $this->db->query($sql);
1128 1128
         if ($resql)
1129 1129
         {
1130 1130
             if ($this->db->num_rows($resql))
@@ -1153,21 +1153,21 @@  discard block
 block discarded – undo
1153 1153
                 $this->statut_libelle       = $obj->statut_label;
1154 1154
                 $this->datec                = $this->db->jdate($obj->datec); // TODO deprecated
1155 1155
                 $this->datev                = $this->db->jdate($obj->datev); // TODO deprecated
1156
-                $this->date_creation		= $this->db->jdate($obj->datec); //Creation date
1157
-                $this->date_validation		= $this->db->jdate($obj->datev); //Validation date
1156
+                $this->date_creation = $this->db->jdate($obj->datec); //Creation date
1157
+                $this->date_validation = $this->db->jdate($obj->datev); //Validation date
1158 1158
                 $this->date_livraison       = $this->db->jdate($obj->date_livraison);
1159
-                $this->shipping_method_id   = ($obj->fk_shipping_method>0)?$obj->fk_shipping_method:null;
1159
+                $this->shipping_method_id   = ($obj->fk_shipping_method > 0) ? $obj->fk_shipping_method : null;
1160 1160
 
1161 1161
                 $this->mode_reglement_id    = $obj->fk_mode_reglement;
1162 1162
                 $this->mode_reglement_code  = $obj->mode_reglement_code;
1163 1163
                 $this->mode_reglement       = $obj->mode_reglement;
1164
-                $this->fk_account           = ($obj->fk_account>0)?$obj->fk_account:null;
1164
+                $this->fk_account           = ($obj->fk_account > 0) ? $obj->fk_account : null;
1165 1165
                 $this->cond_reglement_id    = $obj->fk_cond_reglement;
1166 1166
                 $this->cond_reglement_code  = $obj->cond_reglement_code;
1167 1167
                 $this->cond_reglement       = $obj->cond_reglement;
1168 1168
                 $this->cond_reglement_doc   = $obj->cond_reglement_libelle_doc;
1169 1169
 
1170
-                $this->extraparams			= (array) json_decode($obj->extraparams, true);
1170
+                $this->extraparams = (array) json_decode($obj->extraparams, true);
1171 1171
 
1172 1172
                 $this->user_author_id = $obj->fk_user_author;
1173 1173
                 $this->user_valid_id  = $obj->fk_user_valid;
@@ -1175,9 +1175,9 @@  discard block
 block discarded – undo
1175 1175
 
1176 1176
 				// Multicurrency
1177 1177
 				$this->fk_multicurrency 		= $obj->fk_multicurrency;
1178
-				$this->multicurrency_code 		= $obj->multicurrency_code;
1178
+				$this->multicurrency_code = $obj->multicurrency_code;
1179 1179
 				$this->multicurrency_tx 		= $obj->multicurrency_tx;
1180
-				$this->multicurrency_total_ht 	= $obj->multicurrency_total_ht;
1180
+				$this->multicurrency_total_ht = $obj->multicurrency_total_ht;
1181 1181
 				$this->multicurrency_total_tva 	= $obj->multicurrency_total_tva;
1182 1182
 				$this->multicurrency_total_ttc 	= $obj->multicurrency_total_ttc;
1183 1183
 
@@ -1189,9 +1189,9 @@  discard block
 block discarded – undo
1189 1189
                 // Retreive all extrafield for invoice
1190 1190
                 // fetch optionals attributes and labels
1191 1191
                 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
1192
-                $extrafields=new ExtraFields($this->db);
1193
-                $extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
1194
-                $this->fetch_optionals($this->id,$extralabels);
1192
+                $extrafields = new ExtraFields($this->db);
1193
+                $extralabels = $extrafields->fetch_name_optionals_label($this->table_element, true);
1194
+                $this->fetch_optionals($this->id, $extralabels);
1195 1195
 
1196 1196
                 $this->db->free($resql);
1197 1197
 
@@ -1201,14 +1201,14 @@  discard block
 block discarded – undo
1201 1201
                  * Lignes askprice liees a un produit ou non
1202 1202
                  */
1203 1203
                 $sql = "SELECT d.rowid, d.fk_supplier_proposal, d.fk_parent_line, d.label as custom_label, d.description, d.price, d.tva_tx, d.localtax1_tx, d.localtax2_tx, d.qty, d.fk_remise_except, d.remise_percent, d.subprice, d.fk_product,";
1204
-				$sql.= " d.info_bits, d.total_ht, d.total_tva, d.total_localtax1, d.total_localtax2, d.total_ttc, d.fk_product_fournisseur_price as fk_fournprice, d.buy_price_ht as pa_ht, d.special_code, d.rang, d.product_type,";
1205
-                $sql.= ' p.ref as product_ref, p.description as product_desc, p.fk_product_type, p.label as product_label,';
1206
-                $sql.= ' d.ref_fourn as ref_produit_fourn,';
1207
-				$sql.= ' d.fk_multicurrency, d.multicurrency_code, d.multicurrency_subprice, d.multicurrency_total_ht, d.multicurrency_total_tva, d.multicurrency_total_ttc, d.fk_unit';
1208
-                $sql.= " FROM ".MAIN_DB_PREFIX."supplier_proposaldet as d";
1209
-                $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON d.fk_product = p.rowid";
1210
-                $sql.= " WHERE d.fk_supplier_proposal = ".$this->id;
1211
-                $sql.= " ORDER by d.rang";
1204
+				$sql .= " d.info_bits, d.total_ht, d.total_tva, d.total_localtax1, d.total_localtax2, d.total_ttc, d.fk_product_fournisseur_price as fk_fournprice, d.buy_price_ht as pa_ht, d.special_code, d.rang, d.product_type,";
1205
+                $sql .= ' p.ref as product_ref, p.description as product_desc, p.fk_product_type, p.label as product_label,';
1206
+                $sql .= ' d.ref_fourn as ref_produit_fourn,';
1207
+				$sql .= ' d.fk_multicurrency, d.multicurrency_code, d.multicurrency_subprice, d.multicurrency_total_ht, d.multicurrency_total_tva, d.multicurrency_total_ttc, d.fk_unit';
1208
+                $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposaldet as d";
1209
+                $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON d.fk_product = p.rowid";
1210
+                $sql .= " WHERE d.fk_supplier_proposal = ".$this->id;
1211
+                $sql .= " ORDER by d.rang";
1212 1212
 
1213 1213
                 $result = $this->db->query($sql);
1214 1214
                 if ($result)
@@ -1222,13 +1222,13 @@  discard block
 block discarded – undo
1222 1222
 
1223 1223
                         $line                   = new SupplierProposalLine($this->db);
1224 1224
 
1225
-                        $line->rowid			= $objp->rowid; // deprecated
1226
-                        $line->id				= $objp->rowid;
1227
-                        $line->fk_supplier_proposal		= $objp->fk_supplier_proposal;
1228
-                        $line->fk_parent_line	= $objp->fk_parent_line;
1225
+                        $line->rowid = $objp->rowid; // deprecated
1226
+                        $line->id = $objp->rowid;
1227
+                        $line->fk_supplier_proposal = $objp->fk_supplier_proposal;
1228
+                        $line->fk_parent_line = $objp->fk_parent_line;
1229 1229
                         $line->product_type     = $objp->product_type;
1230 1230
                         $line->label            = $objp->custom_label;
1231
-                        $line->desc             = $objp->description;  // Description ligne
1231
+                        $line->desc             = $objp->description; // Description ligne
1232 1232
                         $line->qty              = $objp->qty;
1233 1233
                         $line->tva_tx           = $objp->tva_tx;
1234 1234
                         $line->localtax1_tx		= $objp->localtax1_tx;
@@ -1236,7 +1236,7 @@  discard block
 block discarded – undo
1236 1236
                         $line->subprice         = $objp->subprice;
1237 1237
                         $line->fk_remise_except = $objp->fk_remise_except;
1238 1238
                         $line->remise_percent   = $objp->remise_percent;
1239
-                        $line->price            = $objp->price;		// TODO deprecated
1239
+                        $line->price            = $objp->price; // TODO deprecated
1240 1240
 
1241 1241
                         $line->info_bits        = $objp->info_bits;
1242 1242
                         $line->total_ht         = $objp->total_ht;
@@ -1244,9 +1244,9 @@  discard block
 block discarded – undo
1244 1244
                         $line->total_localtax1	= $objp->total_localtax1;
1245 1245
                         $line->total_localtax2	= $objp->total_localtax2;
1246 1246
                         $line->total_ttc        = $objp->total_ttc;
1247
-      					$line->fk_fournprice 	= $objp->fk_fournprice;
1248
-						$marginInfos			= getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $line->fk_fournprice, $objp->pa_ht);
1249
-						$line->pa_ht 			= $marginInfos[0];
1247
+      					$line->fk_fournprice = $objp->fk_fournprice;
1248
+						$marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $line->fk_fournprice, $objp->pa_ht);
1249
+						$line->pa_ht = $marginInfos[0];
1250 1250
 						$line->marge_tx			= $marginInfos[1];
1251 1251
 						$line->marque_tx		= $marginInfos[2];
1252 1252
                         $line->special_code     = $objp->special_code;
@@ -1254,25 +1254,25 @@  discard block
 block discarded – undo
1254 1254
 
1255 1255
                         $line->fk_product       = $objp->fk_product;
1256 1256
 
1257
-                        $line->ref				= $objp->product_ref;		// TODO deprecated
1258
-                        $line->product_ref		= $objp->product_ref;
1259
-                        $line->libelle			= $objp->product_label;		// TODO deprecated
1260
-                        $line->product_label	= $objp->product_label;
1261
-                        $line->product_desc     = $objp->product_desc; 		// Description produit
1257
+                        $line->ref = $objp->product_ref; // TODO deprecated
1258
+                        $line->product_ref = $objp->product_ref;
1259
+                        $line->libelle = $objp->product_label; // TODO deprecated
1260
+                        $line->product_label = $objp->product_label;
1261
+                        $line->product_desc     = $objp->product_desc; // Description produit
1262 1262
                         $line->fk_product_type  = $objp->fk_product_type;
1263 1263
 
1264
-						$line->ref_fourn		= $objp->ref_produit_fourn;
1264
+						$line->ref_fourn = $objp->ref_produit_fourn;
1265 1265
 
1266 1266
 						// Multicurrency
1267
-						$line->fk_multicurrency 		= $objp->fk_multicurrency;
1268
-						$line->multicurrency_code 		= $objp->multicurrency_code;
1267
+						$line->fk_multicurrency = $objp->fk_multicurrency;
1268
+						$line->multicurrency_code = $objp->multicurrency_code;
1269 1269
 						$line->multicurrency_subprice 	= $objp->multicurrency_subprice;
1270 1270
 						$line->multicurrency_total_ht 	= $objp->multicurrency_total_ht;
1271 1271
 						$line->multicurrency_total_tva 	= $objp->multicurrency_total_tva;
1272 1272
 						$line->multicurrency_total_ttc 	= $objp->multicurrency_total_ttc;
1273
-						$line->fk_unit					= $objp->fk_unit;
1273
+						$line->fk_unit = $objp->fk_unit;
1274 1274
 
1275
-                        $this->lines[$i]        = $line;
1275
+                        $this->lines[$i] = $line;
1276 1276
 
1277 1277
                         $i++;
1278 1278
                     }
@@ -1280,26 +1280,26 @@  discard block
 block discarded – undo
1280 1280
                 }
1281 1281
                 else
1282 1282
                 {
1283
-                    $this->error=$this->db->error();
1283
+                    $this->error = $this->db->error();
1284 1284
                     return -1;
1285 1285
                 }
1286 1286
 
1287 1287
                 // Retreive all extrafield for askprice
1288 1288
                 // fetch optionals attributes and labels
1289 1289
                 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
1290
-                $extrafields=new ExtraFields($this->db);
1291
-                $extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
1292
-                $this->fetch_optionals($this->id,$extralabels);
1290
+                $extrafields = new ExtraFields($this->db);
1291
+                $extralabels = $extrafields->fetch_name_optionals_label($this->table_element, true);
1292
+                $this->fetch_optionals($this->id, $extralabels);
1293 1293
 
1294 1294
                 return 1;
1295 1295
             }
1296 1296
 
1297
-            $this->error="Record Not Found";
1297
+            $this->error = "Record Not Found";
1298 1298
             return 0;
1299 1299
         }
1300 1300
         else
1301 1301
         {
1302
-            $this->error=$this->db->error();
1302
+            $this->error = $this->db->error();
1303 1303
             return -1;
1304 1304
         }
1305 1305
     }
@@ -1312,17 +1312,17 @@  discard block
 block discarded – undo
1312 1312
      */
1313 1313
     function update_extrafields($user)
1314 1314
     {
1315
-    	$action='update';
1315
+    	$action = 'update';
1316 1316
 
1317 1317
     	// Actions on extra fields (by external module or standard code)
1318 1318
     	$hookmanager->initHooks(array('supplier_proposaldao'));
1319
-    	$parameters=array('id'=>$this->id);
1320
-    	$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
1319
+    	$parameters = array('id'=>$this->id);
1320
+    	$reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1321 1321
     	if (empty($reshook))
1322 1322
     	{
1323 1323
     		if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
1324 1324
     		{
1325
-    			$result=$this->insertExtraFields();
1325
+    			$result = $this->insertExtraFields();
1326 1326
     			if ($result < 0)
1327 1327
     			{
1328 1328
     				$error++;
@@ -1349,17 +1349,17 @@  discard block
 block discarded – undo
1349 1349
      *  @param	int		$notrigger	1=Does not execute triggers, 0= execute triggers
1350 1350
      *  @return int         		<0 if KO, >=0 if OK
1351 1351
      */
1352
-    function valid($user, $notrigger=0)
1352
+    function valid($user, $notrigger = 0)
1353 1353
     {
1354 1354
     	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1355 1355
 
1356
-    	global $conf,$langs;
1356
+    	global $conf, $langs;
1357 1357
 
1358
-        $error=0;
1359
-        $now=dol_now();
1358
+        $error = 0;
1359
+        $now = dol_now();
1360 1360
 
1361
-        if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->supplier_proposal->creer))
1362
-       	|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->supplier_proposal->validate_advance)))
1361
+        if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->supplier_proposal->creer))
1362
+       	|| (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->supplier_proposal->validate_advance)))
1363 1363
         {
1364 1364
             $this->db->begin();
1365 1365
 
@@ -1368,7 +1368,7 @@  discard block
 block discarded – undo
1368 1368
             $soc->fetch($this->socid);
1369 1369
 
1370 1370
             // Define new ref
1371
-            if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life
1371
+            if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life
1372 1372
             {
1373 1373
             	$num = $this->getNextNumRef($soc);
1374 1374
             }
@@ -1379,28 +1379,28 @@  discard block
 block discarded – undo
1379 1379
             $this->newref = $num;
1380 1380
 
1381 1381
             $sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal";
1382
-            $sql.= " SET ref = '".$num."',";
1383
-            $sql.= " fk_statut = 1, date_valid='".$this->db->idate($now)."', fk_user_valid=".$user->id;
1384
-            $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0";
1382
+            $sql .= " SET ref = '".$num."',";
1383
+            $sql .= " fk_statut = 1, date_valid='".$this->db->idate($now)."', fk_user_valid=".$user->id;
1384
+            $sql .= " WHERE rowid = ".$this->id." AND fk_statut = 0";
1385 1385
 
1386 1386
             dol_syslog(get_class($this)."::valid", LOG_DEBUG);
1387
-			$resql=$this->db->query($sql);
1388
-			if (! $resql)
1387
+			$resql = $this->db->query($sql);
1388
+			if (!$resql)
1389 1389
 			{
1390 1390
 				dol_print_error($this->db);
1391 1391
 				$error++;
1392 1392
 			}
1393 1393
 
1394 1394
    			// Trigger calls
1395
-			if (! $error && ! $notrigger)
1395
+			if (!$error && !$notrigger)
1396 1396
 			{
1397 1397
                 // Call trigger
1398
-                $result=$this->call_trigger('SUPPLIER_PROPOSAL_VALIDATE',$user);
1398
+                $result = $this->call_trigger('SUPPLIER_PROPOSAL_VALIDATE', $user);
1399 1399
                 if ($result < 0) { $error++; }
1400 1400
                 // End call triggers
1401 1401
             }
1402 1402
 
1403
-            if (! $error)
1403
+            if (!$error)
1404 1404
             {
1405 1405
             	$this->oldref = $this->ref;
1406 1406
 
@@ -1421,24 +1421,24 @@  discard block
 block discarded – undo
1421 1421
             			{
1422 1422
             				dol_syslog("Rename ok");
1423 1423
             				// Rename docs starting with $oldref with $newref
1424
-            				$listoffiles=dol_dir_list($conf->supplier_proposal->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref,'/'));
1425
-            				foreach($listoffiles as $fileentry)
1424
+            				$listoffiles = dol_dir_list($conf->supplier_proposal->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
1425
+            				foreach ($listoffiles as $fileentry)
1426 1426
             				{
1427
-            					$dirsource=$fileentry['name'];
1428
-            					$dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource);
1429
-            					$dirsource=$fileentry['path'].'/'.$dirsource;
1430
-            					$dirdest=$fileentry['path'].'/'.$dirdest;
1427
+            					$dirsource = $fileentry['name'];
1428
+            					$dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
1429
+            					$dirsource = $fileentry['path'].'/'.$dirsource;
1430
+            					$dirdest = $fileentry['path'].'/'.$dirdest;
1431 1431
             					@rename($dirsource, $dirdest);
1432 1432
             				}
1433 1433
             			}
1434 1434
             		}
1435 1435
             	}
1436 1436
 
1437
-            	$this->ref=$num;
1438
-            	$this->brouillon=0;
1437
+            	$this->ref = $num;
1438
+            	$this->brouillon = 0;
1439 1439
             	$this->statut = 1;
1440
-            	$this->user_valid_id=$user->id;
1441
-            	$this->datev=$now;
1440
+            	$this->user_valid_id = $user->id;
1441
+            	$this->datev = $now;
1442 1442
 
1443 1443
             	$this->db->commit();
1444 1444
             	return 1;
@@ -1460,11 +1460,11 @@  discard block
 block discarded – undo
1460 1460
      */
1461 1461
     function set_date_livraison($user, $date_livraison)
1462 1462
     {
1463
-        if (! empty($user->rights->supplier_proposal->creer))
1463
+        if (!empty($user->rights->supplier_proposal->creer))
1464 1464
         {
1465 1465
             $sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal ";
1466
-            $sql.= " SET date_livraison = ".($date_livraison!=''?"'".$this->db->idate($date_livraison)."'":'null');
1467
-            $sql.= " WHERE rowid = ".$this->id;
1466
+            $sql .= " SET date_livraison = ".($date_livraison != '' ? "'".$this->db->idate($date_livraison)."'" : 'null');
1467
+            $sql .= " WHERE rowid = ".$this->id;
1468 1468
 
1469 1469
             if ($this->db->query($sql))
1470 1470
             {
@@ -1473,7 +1473,7 @@  discard block
 block discarded – undo
1473 1473
             }
1474 1474
             else
1475 1475
             {
1476
-                $this->error=$this->db->error();
1476
+                $this->error = $this->db->error();
1477 1477
                 dol_syslog(get_class($this)."::set_date_livraison Erreur SQL");
1478 1478
                 return -1;
1479 1479
             }
@@ -1489,16 +1489,16 @@  discard block
 block discarded – undo
1489 1489
      */
1490 1490
     function set_remise_percent($user, $remise)
1491 1491
     {
1492
-        $remise=trim($remise)?trim($remise):0;
1492
+        $remise = trim($remise) ?trim($remise) : 0;
1493 1493
 
1494
-        if (! empty($user->rights->supplier_proposal->creer))
1494
+        if (!empty($user->rights->supplier_proposal->creer))
1495 1495
         {
1496 1496
             $remise = price2num($remise);
1497 1497
 
1498 1498
             $sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal SET remise_percent = ".$remise;
1499
-            $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0";
1499
+            $sql .= " WHERE rowid = ".$this->id." AND fk_statut = 0";
1500 1500
 
1501
-            if ($this->db->query($sql) )
1501
+            if ($this->db->query($sql))
1502 1502
             {
1503 1503
                 $this->remise_percent = $remise;
1504 1504
                 $this->update_price(1);
@@ -1506,7 +1506,7 @@  discard block
 block discarded – undo
1506 1506
             }
1507 1507
             else
1508 1508
             {
1509
-                $this->error=$this->db->error();
1509
+                $this->error = $this->db->error();
1510 1510
                 return -1;
1511 1511
             }
1512 1512
         }
@@ -1522,17 +1522,17 @@  discard block
 block discarded – undo
1522 1522
      */
1523 1523
     function set_remise_absolue($user, $remise)
1524 1524
     {
1525
-        $remise=trim($remise)?trim($remise):0;
1525
+        $remise = trim($remise) ?trim($remise) : 0;
1526 1526
 
1527
-        if (! empty($user->rights->supplier_proposal->creer))
1527
+        if (!empty($user->rights->supplier_proposal->creer))
1528 1528
         {
1529 1529
             $remise = price2num($remise);
1530 1530
 
1531 1531
             $sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal ";
1532
-            $sql.= " SET remise_absolue = ".$remise;
1533
-            $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0";
1532
+            $sql .= " SET remise_absolue = ".$remise;
1533
+            $sql .= " WHERE rowid = ".$this->id." AND fk_statut = 0";
1534 1534
 
1535
-            if ($this->db->query($sql) )
1535
+            if ($this->db->query($sql))
1536 1536
             {
1537 1537
                 $this->remise_absolue = $remise;
1538 1538
                 $this->update_price(1);
@@ -1540,7 +1540,7 @@  discard block
 block discarded – undo
1540 1540
             }
1541 1541
             else
1542 1542
             {
1543
-                $this->error=$this->db->error();
1543
+                $this->error = $this->db->error();
1544 1544
                 return -1;
1545 1545
             }
1546 1546
         }
@@ -1557,32 +1557,32 @@  discard block
 block discarded – undo
1557 1557
      *  @param		int		$notrigger	1=Does not execute triggers, 0= execute triggers
1558 1558
      *	@return     int         		<0 if KO, >0 if OK
1559 1559
      */
1560
-    function reopen($user, $statut, $note='', $notrigger=0)
1560
+    function reopen($user, $statut, $note = '', $notrigger = 0)
1561 1561
     {
1562
-        global $langs,$conf;
1562
+        global $langs, $conf;
1563 1563
 
1564 1564
         $this->statut = $statut;
1565
-        $error=0;
1565
+        $error = 0;
1566 1566
 
1567 1567
         $sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal";
1568
-        $sql.= " SET fk_statut = ".$this->statut.",";
1569
-		if (! empty($note)) $sql.= " note_private = '".$this->db->escape($note)."',";
1570
-        $sql.= " date_cloture=NULL, fk_user_cloture=NULL";
1571
-        $sql.= " WHERE rowid = ".$this->id;
1568
+        $sql .= " SET fk_statut = ".$this->statut.",";
1569
+		if (!empty($note)) $sql .= " note_private = '".$this->db->escape($note)."',";
1570
+        $sql .= " date_cloture=NULL, fk_user_cloture=NULL";
1571
+        $sql .= " WHERE rowid = ".$this->id;
1572 1572
 
1573 1573
     	$this->db->begin();
1574 1574
 
1575 1575
 		dol_syslog(get_class($this)."::reopen", LOG_DEBUG);
1576 1576
 		$resql = $this->db->query($sql);
1577
-		if (! $resql) {
1578
-			$error++; $this->errors[]="Error ".$this->db->lasterror();
1577
+		if (!$resql) {
1578
+			$error++; $this->errors[] = "Error ".$this->db->lasterror();
1579 1579
 		}
1580
-		if (! $error)
1580
+		if (!$error)
1581 1581
 		{
1582
-			if (! $notrigger)
1582
+			if (!$notrigger)
1583 1583
 			{
1584 1584
                 // Call trigger
1585
-                $result=$this->call_trigger('SUPPLIER_PROPOSAL_REOPEN',$user);
1585
+                $result = $this->call_trigger('SUPPLIER_PROPOSAL_REOPEN', $user);
1586 1586
                 if ($result < 0) { $error++; }
1587 1587
                 // End call triggers
1588 1588
 			}
@@ -1593,14 +1593,14 @@  discard block
 block discarded – undo
1593 1593
 		{
1594 1594
 		    if (!empty($this->errors))
1595 1595
 		    {
1596
-    			foreach($this->errors as $errmsg)
1596
+    			foreach ($this->errors as $errmsg)
1597 1597
     			{
1598 1598
     				dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
1599
-    				$this->error.=($this->error?', '.$errmsg:$errmsg);
1599
+    				$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
1600 1600
     			}
1601 1601
 		    }
1602 1602
 			$this->db->rollback();
1603
-			return -1*$error;
1603
+			return -1 * $error;
1604 1604
 		}
1605 1605
 		else
1606 1606
 		{
@@ -1620,30 +1620,30 @@  discard block
 block discarded – undo
1620 1620
      */
1621 1621
     function cloture($user, $statut, $note)
1622 1622
     {
1623
-        global $langs,$conf;
1623
+        global $langs, $conf;
1624 1624
 
1625 1625
         $this->statut = $statut;
1626
-        $error=0;
1627
-        $now=dol_now();
1626
+        $error = 0;
1627
+        $now = dol_now();
1628 1628
 
1629 1629
         $this->db->begin();
1630 1630
 
1631 1631
         $sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal";
1632
-        $sql.= " SET fk_statut = ".$statut.", note_private = '".$this->db->escape($note)."', date_cloture='".$this->db->idate($now)."', fk_user_cloture=".$user->id;
1633
-        $sql.= " WHERE rowid = ".$this->id;
1632
+        $sql .= " SET fk_statut = ".$statut.", note_private = '".$this->db->escape($note)."', date_cloture='".$this->db->idate($now)."', fk_user_cloture=".$user->id;
1633
+        $sql .= " WHERE rowid = ".$this->id;
1634 1634
 
1635
-        $resql=$this->db->query($sql);
1635
+        $resql = $this->db->query($sql);
1636 1636
         if ($resql)
1637 1637
         {
1638
-        	$modelpdf=$conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_CLOSED?$conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_CLOSED:$this->modelpdf;
1639
-        	$trigger_name='SUPPLIER_PROPOSAL_CLOSE_REFUSED';
1638
+        	$modelpdf = $conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_CLOSED ? $conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_CLOSED : $this->modelpdf;
1639
+        	$trigger_name = 'SUPPLIER_PROPOSAL_CLOSE_REFUSED';
1640 1640
 
1641 1641
             if ($statut == 2)
1642 1642
             {
1643
-            	$trigger_name='SUPPLIER_PROPOSAL_CLOSE_SIGNED';
1644
-				$modelpdf=$conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL?$conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL:$this->modelpdf;
1643
+            	$trigger_name = 'SUPPLIER_PROPOSAL_CLOSE_SIGNED';
1644
+				$modelpdf = $conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL ? $conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL : $this->modelpdf;
1645 1645
 
1646
-                if (! empty($conf->global->SUPPLIER_PROPOSAL_UPDATE_PRICE_ON_SUPPlIER_PROPOSAL))     // TODO This option was not tested correctly. Error if product ref does not exists
1646
+                if (!empty($conf->global->SUPPLIER_PROPOSAL_UPDATE_PRICE_ON_SUPPlIER_PROPOSAL))     // TODO This option was not tested correctly. Error if product ref does not exists
1647 1647
                 {
1648 1648
                     $result = $this->updateOrCreatePriceFournisseur($user);
1649 1649
                 }
@@ -1651,17 +1651,17 @@  discard block
 block discarded – undo
1651 1651
             }
1652 1652
             if ($statut == 4)
1653 1653
             {
1654
-            	$trigger_name='SUPPLIER_PROPOSAL_CLASSIFY_BILLED';
1654
+            	$trigger_name = 'SUPPLIER_PROPOSAL_CLASSIFY_BILLED';
1655 1655
             }
1656 1656
 
1657 1657
             if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
1658 1658
             {
1659 1659
              	// Define output language
1660 1660
               	$outputlangs = $langs;
1661
-               	if (! empty($conf->global->MAIN_MULTILANGS))
1661
+               	if (!empty($conf->global->MAIN_MULTILANGS))
1662 1662
                	{
1663
-               		$outputlangs = new Translate("",$conf);
1664
-               		$newlang=(GETPOST('lang_id','aZ09') ? GETPOST('lang_id','aZ09') : $this->thirdparty->default_lang);
1663
+               		$outputlangs = new Translate("", $conf);
1664
+               		$newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $this->thirdparty->default_lang);
1665 1665
                		$outputlangs->setDefaultLang($newlang);
1666 1666
                	}
1667 1667
                	//$ret=$object->fetch($id);    // Reload to get new records
@@ -1669,11 +1669,11 @@  discard block
 block discarded – undo
1669 1669
             }
1670 1670
 
1671 1671
             // Call trigger
1672
-            $result=$this->call_trigger($trigger_name,$user);
1672
+            $result = $this->call_trigger($trigger_name, $user);
1673 1673
             if ($result < 0) { $error++; }
1674 1674
             // End call triggers
1675 1675
 
1676
-            if ( ! $error )
1676
+            if (!$error)
1677 1677
             {
1678 1678
                 $this->db->commit();
1679 1679
                 return 1;
@@ -1686,8 +1686,8 @@  discard block
 block discarded – undo
1686 1686
         }
1687 1687
         else
1688 1688
         {
1689
-            $this->error=$this->db->lasterror();
1690
-            $this->errors[]=$this->db->lasterror();
1689
+            $this->error = $this->db->lasterror();
1690
+            $this->errors[] = $this->db->lasterror();
1691 1691
             $this->db->rollback();
1692 1692
             return -1;
1693 1693
         }
@@ -1734,14 +1734,14 @@  discard block
 block discarded – undo
1734 1734
      *	@return     int         					<0 if KO, >0 if OK
1735 1735
      */
1736 1736
      function updatePriceFournisseur($idProductFournPrice, $product, $user) {
1737
-		$price=price2num($product->subprice*$product->qty,'MU');
1738
-		$unitPrice = price2num($product->subprice,'MU');
1737
+		$price = price2num($product->subprice * $product->qty, 'MU');
1738
+		$unitPrice = price2num($product->subprice, 'MU');
1739 1739
 
1740 1740
 		$sql = 'UPDATE '.MAIN_DB_PREFIX.'product_fournisseur_price SET '.(!empty($product->ref_fourn) ? 'ref_fourn = "'.$product->ref_fourn.'", ' : '').' price ='.$price.', unitprice ='.$unitPrice.' WHERE rowid = '.$idProductFournPrice;
1741 1741
 
1742 1742
 		$resql = $this->db->query($sql);
1743 1743
 		if (!$resql) {
1744
-			$this->error=$this->db->error();
1744
+			$this->error = $this->db->error();
1745 1745
             $this->db->rollback();
1746 1746
             return -1;
1747 1747
 		}
@@ -1755,10 +1755,10 @@  discard block
 block discarded – undo
1755 1755
      *	@return     int         			<0 if KO, >0 if OK
1756 1756
      */
1757 1757
 	 function createPriceFournisseur($product, $user) {
1758
-	 	$price=price2num($product->subprice*$product->qty,'MU');
1759
-	    $qty=price2num($product->qty);
1760
-		$unitPrice = price2num($product->subprice,'MU');
1761
-		$now=dol_now();
1758
+	 	$price = price2num($product->subprice * $product->qty, 'MU');
1759
+	    $qty = price2num($product->qty);
1760
+		$unitPrice = price2num($product->subprice, 'MU');
1761
+		$now = dol_now();
1762 1762
 
1763 1763
 		$values = array(
1764 1764
 			"'".$this->db->idate($now)."'",
@@ -1777,7 +1777,7 @@  discard block
 block discarded – undo
1777 1777
 
1778 1778
 		$resql = $this->db->query($sql);
1779 1779
 		if (!$resql) {
1780
-			$this->error=$this->db->error();
1780
+			$this->error = $this->db->error();
1781 1781
             $this->db->rollback();
1782 1782
             return -1;
1783 1783
 		}
@@ -1791,10 +1791,10 @@  discard block
 block discarded – undo
1791 1791
      */
1792 1792
     function set_draft($user)
1793 1793
     {
1794
-        global $conf,$langs;
1794
+        global $conf, $langs;
1795 1795
 
1796 1796
         $sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal SET fk_statut = 0";
1797
-        $sql.= " WHERE rowid = ".$this->id;
1797
+        $sql .= " WHERE rowid = ".$this->id;
1798 1798
 
1799 1799
         if ($this->db->query($sql))
1800 1800
         {
@@ -1822,32 +1822,32 @@  discard block
 block discarded – undo
1822 1822
      *    @param    string	$sortorder			Sort order
1823 1823
      *    @return	int		       				-1 if KO, array with result if OK
1824 1824
      */
1825
-    function liste_array($shortlist=0, $draft=0, $notcurrentuser=0, $socid=0, $limit=0, $offset=0, $sortfield='p.datec', $sortorder='DESC')
1825
+    function liste_array($shortlist = 0, $draft = 0, $notcurrentuser = 0, $socid = 0, $limit = 0, $offset = 0, $sortfield = 'p.datec', $sortorder = 'DESC')
1826 1826
     {
1827
-        global $conf,$user;
1827
+        global $conf, $user;
1828 1828
 
1829 1829
         $ga = array();
1830 1830
 
1831 1831
         $sql = "SELECT s.rowid, s.nom as name, s.client,";
1832
-        $sql.= " p.rowid as supplier_proposalid, p.fk_statut, p.total_ht, p.ref, p.remise, ";
1833
-        $sql.= " p.datep as dp, p.fin_validite as datelimite";
1834
-        if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", sc.fk_soc, sc.fk_user";
1835
-        $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."supplier_proposal as p, ".MAIN_DB_PREFIX."c_propalst as c";
1836
-		if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1837
-        $sql.= " WHERE p.entity = ".$conf->entity;
1838
-        $sql.= " AND p.fk_soc = s.rowid";
1839
-        $sql.= " AND p.fk_statut = c.id";
1840
-        if (! $user->rights->societe->client->voir && ! $socid) //restriction
1832
+        $sql .= " p.rowid as supplier_proposalid, p.fk_statut, p.total_ht, p.ref, p.remise, ";
1833
+        $sql .= " p.datep as dp, p.fin_validite as datelimite";
1834
+        if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
1835
+        $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."supplier_proposal as p, ".MAIN_DB_PREFIX."c_propalst as c";
1836
+		if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1837
+        $sql .= " WHERE p.entity = ".$conf->entity;
1838
+        $sql .= " AND p.fk_soc = s.rowid";
1839
+        $sql .= " AND p.fk_statut = c.id";
1840
+        if (!$user->rights->societe->client->voir && !$socid) //restriction
1841 1841
         {
1842
-        	$sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
1842
+        	$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
1843 1843
         }
1844
-        if ($socid) $sql.= " AND s.rowid = ".$socid;
1845
-        if ($draft)	$sql.= " AND p.fk_statut = 0";
1846
-        if ($notcurrentuser > 0) $sql.= " AND p.fk_user_author <> ".$user->id;
1847
-        $sql.= $this->db->order($sortfield,$sortorder);
1848
-        $sql.= $this->db->plimit($limit,$offset);
1844
+        if ($socid) $sql .= " AND s.rowid = ".$socid;
1845
+        if ($draft)	$sql .= " AND p.fk_statut = 0";
1846
+        if ($notcurrentuser > 0) $sql .= " AND p.fk_user_author <> ".$user->id;
1847
+        $sql .= $this->db->order($sortfield, $sortorder);
1848
+        $sql .= $this->db->plimit($limit, $offset);
1849 1849
 
1850
-        $result=$this->db->query($sql);
1850
+        $result = $this->db->query($sql);
1851 1851
         if ($result)
1852 1852
         {
1853 1853
             $num = $this->db->num_rows($result);
@@ -1868,7 +1868,7 @@  discard block
 block discarded – undo
1868 1868
                     }
1869 1869
                     else
1870 1870
 					{
1871
-                        $ga[$i]['id']	= $obj->supplier_proposalid;
1871
+                        $ga[$i]['id'] = $obj->supplier_proposalid;
1872 1872
                         $ga[$i]['ref'] 	= $obj->ref;
1873 1873
                         $ga[$i]['name'] = $obj->name;
1874 1874
                     }
@@ -1892,24 +1892,24 @@  discard block
 block discarded – undo
1892 1892
      *	@param	int		$notrigger		1=Does not execute triggers, 0= execute triggers
1893 1893
      *	@return	int						1 if ok, otherwise if error
1894 1894
      */
1895
-    function delete($user, $notrigger=0)
1895
+    function delete($user, $notrigger = 0)
1896 1896
     {
1897
-        global $conf,$langs;
1897
+        global $conf, $langs;
1898 1898
         require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1899 1899
 
1900
-        $error=0;
1900
+        $error = 0;
1901 1901
 
1902 1902
         $this->db->begin();
1903 1903
 
1904
-        if (! $notrigger)
1904
+        if (!$notrigger)
1905 1905
         {
1906 1906
             // Call trigger
1907
-            $result=$this->call_trigger('SUPPLIER_PROPOSAL_DELETE',$user);
1907
+            $result = $this->call_trigger('SUPPLIER_PROPOSAL_DELETE', $user);
1908 1908
             if ($result < 0) { $error++; }
1909 1909
             // End call triggers
1910 1910
         }
1911 1911
 
1912
-        if (! $error)
1912
+        if (!$error)
1913 1913
         {
1914 1914
             $sql = "DELETE FROM ".MAIN_DB_PREFIX."supplier_proposaldet WHERE fk_supplier_proposal = ".$this->id;
1915 1915
             if ($this->db->query($sql))
@@ -1921,33 +1921,33 @@  discard block
 block discarded – undo
1921 1921
                     $res = $this->deleteObjectLinked();
1922 1922
                     if ($res < 0) $error++;
1923 1923
 
1924
-                    if (! $error)
1924
+                    if (!$error)
1925 1925
                     {
1926 1926
                         // We remove directory
1927 1927
                         $ref = dol_sanitizeFileName($this->ref);
1928 1928
                         if ($conf->supplier_proposal->dir_output && !empty($this->ref))
1929 1929
                         {
1930
-                            $dir = $conf->supplier_proposal->dir_output . "/" . $ref ;
1931
-                            $file = $dir . "/" . $ref . ".pdf";
1930
+                            $dir = $conf->supplier_proposal->dir_output."/".$ref;
1931
+                            $file = $dir."/".$ref.".pdf";
1932 1932
                             if (file_exists($file))
1933 1933
                             {
1934 1934
                                 dol_delete_preview($this);
1935 1935
 
1936
-                                if (! dol_delete_file($file,0,0,0,$this)) // For triggers
1936
+                                if (!dol_delete_file($file, 0, 0, 0, $this)) // For triggers
1937 1937
                                 {
1938
-                                    $this->error='ErrorFailToDeleteFile';
1939
-                                    $this->errors=array('ErrorFailToDeleteFile');
1938
+                                    $this->error = 'ErrorFailToDeleteFile';
1939
+                                    $this->errors = array('ErrorFailToDeleteFile');
1940 1940
                                 	$this->db->rollback();
1941 1941
                                     return 0;
1942 1942
                                 }
1943 1943
                             }
1944 1944
                             if (file_exists($dir))
1945 1945
                             {
1946
-                                $res=@dol_delete_dir_recursive($dir);
1947
-                                if (! $res)
1946
+                                $res = @dol_delete_dir_recursive($dir);
1947
+                                if (!$res)
1948 1948
                                 {
1949
-                                    $this->error='ErrorFailToDeleteDir';
1950
-                                    $this->errors=array('ErrorFailToDeleteDir');
1949
+                                    $this->error = 'ErrorFailToDeleteDir';
1950
+                                    $this->errors = array('ErrorFailToDeleteDir');
1951 1951
                                     $this->db->rollback();
1952 1952
                                     return 0;
1953 1953
                                 }
@@ -1956,21 +1956,21 @@  discard block
 block discarded – undo
1956 1956
                     }
1957 1957
 
1958 1958
                     // Removed extrafields
1959
-                    if (! $error)
1959
+                    if (!$error)
1960 1960
                     {
1961 1961
                     	if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
1962 1962
                     	{
1963
-                    		$result=$this->deleteExtraFields();
1963
+                    		$result = $this->deleteExtraFields();
1964 1964
                     		if ($result < 0)
1965 1965
                     		{
1966 1966
                     			$error++;
1967
-                    			$errorflag=-4;
1967
+                    			$errorflag = -4;
1968 1968
                     			dol_syslog(get_class($this)."::delete erreur ".$errorflag." ".$this->error, LOG_ERR);
1969 1969
                     		}
1970 1970
                     	}
1971 1971
                     }
1972 1972
 
1973
-                    if (! $error)
1973
+                    if (!$error)
1974 1974
                     {
1975 1975
                         dol_syslog(get_class($this)."::delete ".$this->id." by ".$user->id, LOG_DEBUG);
1976 1976
                         $this->db->commit();
@@ -1978,21 +1978,21 @@  discard block
 block discarded – undo
1978 1978
                     }
1979 1979
                     else
1980 1980
                     {
1981
-                        $this->error=$this->db->lasterror();
1981
+                        $this->error = $this->db->lasterror();
1982 1982
                         $this->db->rollback();
1983 1983
                         return 0;
1984 1984
                     }
1985 1985
                 }
1986 1986
                 else
1987 1987
                 {
1988
-                    $this->error=$this->db->lasterror();
1988
+                    $this->error = $this->db->lasterror();
1989 1989
                     $this->db->rollback();
1990 1990
                     return -3;
1991 1991
                 }
1992 1992
             }
1993 1993
             else
1994 1994
             {
1995
-                $this->error=$this->db->lasterror();
1995
+                $this->error = $this->db->lasterror();
1996 1996
                 $this->db->rollback();
1997 1997
                 return -2;
1998 1998
             }
@@ -2013,10 +2013,10 @@  discard block
 block discarded – undo
2013 2013
     function info($id)
2014 2014
     {
2015 2015
         $sql = "SELECT c.rowid, ";
2016
-        $sql.= " c.datec, c.date_valid as datev, c.date_cloture as dateo,";
2017
-        $sql.= " c.fk_user_author, c.fk_user_valid, c.fk_user_cloture";
2018
-        $sql.= " FROM ".MAIN_DB_PREFIX."supplier_proposal as c";
2019
-        $sql.= " WHERE c.rowid = ".$id;
2016
+        $sql .= " c.datec, c.date_valid as datev, c.date_cloture as dateo,";
2017
+        $sql .= " c.fk_user_author, c.fk_user_valid, c.fk_user_cloture";
2018
+        $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal as c";
2019
+        $sql .= " WHERE c.rowid = ".$id;
2020 2020
 
2021 2021
         $result = $this->db->query($sql);
2022 2022
 
@@ -2034,20 +2034,20 @@  discard block
 block discarded – undo
2034 2034
 
2035 2035
                 $cuser = new User($this->db);
2036 2036
                 $cuser->fetch($obj->fk_user_author);
2037
-                $this->user_creation     = $cuser;
2037
+                $this->user_creation = $cuser;
2038 2038
 
2039 2039
                 if ($obj->fk_user_valid)
2040 2040
                 {
2041 2041
                     $vuser = new User($this->db);
2042 2042
                     $vuser->fetch($obj->fk_user_valid);
2043
-                    $this->user_validation     = $vuser;
2043
+                    $this->user_validation = $vuser;
2044 2044
                 }
2045 2045
 
2046 2046
                 if ($obj->fk_user_cloture)
2047 2047
                 {
2048 2048
                     $cluser = new User($this->db);
2049 2049
                     $cluser->fetch($obj->fk_user_cloture);
2050
-                    $this->user_cloture     = $cluser;
2050
+                    $this->user_cloture = $cluser;
2051 2051
                 }
2052 2052
 
2053 2053
 
@@ -2068,9 +2068,9 @@  discard block
 block discarded – undo
2068 2068
      *    	@param      int			$mode        0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
2069 2069
      *    	@return     string		Label
2070 2070
      */
2071
-    function getLibStatut($mode=0)
2071
+    function getLibStatut($mode = 0)
2072 2072
     {
2073
-        return $this->LibStatut($this->statut,$mode);
2073
+        return $this->LibStatut($this->statut, $mode);
2074 2074
     }
2075 2075
 
2076 2076
     /**
@@ -2080,24 +2080,24 @@  discard block
 block discarded – undo
2080 2080
      *    	@param      int			$mode      	0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
2081 2081
      *    	@return     string		Label
2082 2082
      */
2083
-	function LibStatut($statut,$mode=1)
2083
+	function LibStatut($statut, $mode = 1)
2084 2084
     {
2085 2085
 		global $langs;
2086 2086
 		$langs->load("supplier_proposal");
2087 2087
 
2088
-		if ($statut==0) $statuttrans='statut0';
2089
-		if ($statut==1) $statuttrans='statut1';
2090
-		if ($statut==2) $statuttrans='statut3';
2091
-		if ($statut==3) $statuttrans='statut5';
2092
-		if ($statut==4) $statuttrans='statut6';
2088
+		if ($statut == 0) $statuttrans = 'statut0';
2089
+		if ($statut == 1) $statuttrans = 'statut1';
2090
+		if ($statut == 2) $statuttrans = 'statut3';
2091
+		if ($statut == 3) $statuttrans = 'statut5';
2092
+		if ($statut == 4) $statuttrans = 'statut6';
2093 2093
 
2094 2094
 		if ($mode == 0)	return $this->labelstatut[$statut];
2095 2095
 		if ($mode == 1)	return $this->labelstatut_short[$statut];
2096 2096
 		if ($mode == 2)	return img_picto($this->labelstatut[$statut], $statuttrans).' '.$this->labelstatut_short[$statut];
2097 2097
 		if ($mode == 3)	return img_picto($this->labelstatut[$statut], $statuttrans);
2098
-		if ($mode == 4)	return img_picto($this->labelstatut[$statut],$statuttrans).' '.$this->labelstatut[$statut];
2099
-		if ($mode == 5)	return '<span class="hideonsmartphone">'.$this->labelstatut_short[$statut].' </span>'.img_picto($this->labelstatut[$statut],$statuttrans);
2100
-		if ($mode == 6)	return '<span class="hideonsmartphone">'.$this->labelstatut[$statut].' </span>'.img_picto($this->labelstatut[$statut],$statuttrans);
2098
+		if ($mode == 4)	return img_picto($this->labelstatut[$statut], $statuttrans).' '.$this->labelstatut[$statut];
2099
+		if ($mode == 5)	return '<span class="hideonsmartphone">'.$this->labelstatut_short[$statut].' </span>'.img_picto($this->labelstatut[$statut], $statuttrans);
2100
+		if ($mode == 6)	return '<span class="hideonsmartphone">'.$this->labelstatut[$statut].' </span>'.img_picto($this->labelstatut[$statut], $statuttrans);
2101 2101
 	}
2102 2102
 
2103 2103
 
@@ -2108,50 +2108,50 @@  discard block
 block discarded – undo
2108 2108
      *      @param          int		$mode   "opened" for askprice to close, "signed" for proposal to invoice
2109 2109
      *      @return         int     		<0 if KO, >0 if OK
2110 2110
      */
2111
-    function load_board($user,$mode)
2111
+    function load_board($user, $mode)
2112 2112
     {
2113 2113
         global $conf, $user, $langs;
2114 2114
 
2115
-        $now=dol_now();
2115
+        $now = dol_now();
2116 2116
 
2117
-        $this->nbtodo=$this->nbtodolate=0;
2117
+        $this->nbtodo = $this->nbtodolate = 0;
2118 2118
         $clause = " WHERE";
2119 2119
 
2120 2120
         $sql = "SELECT p.rowid, p.ref, p.datec as datec";
2121
-        $sql.= " FROM ".MAIN_DB_PREFIX."supplier_proposal as p";
2121
+        $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal as p";
2122 2122
         if (!$user->rights->societe->client->voir && !$user->societe_id)
2123 2123
         {
2124
-            $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc";
2125
-            $sql.= " WHERE sc.fk_user = " .$user->id;
2124
+            $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc";
2125
+            $sql .= " WHERE sc.fk_user = ".$user->id;
2126 2126
             $clause = " AND";
2127 2127
         }
2128
-        $sql.= $clause." p.entity = ".$conf->entity;
2129
-        if ($mode == 'opened') $sql.= " AND p.fk_statut = 1";
2130
-        if ($mode == 'signed') $sql.= " AND p.fk_statut = 2";
2131
-        if ($user->societe_id) $sql.= " AND p.fk_soc = ".$user->societe_id;
2128
+        $sql .= $clause." p.entity = ".$conf->entity;
2129
+        if ($mode == 'opened') $sql .= " AND p.fk_statut = 1";
2130
+        if ($mode == 'signed') $sql .= " AND p.fk_statut = 2";
2131
+        if ($user->societe_id) $sql .= " AND p.fk_soc = ".$user->societe_id;
2132 2132
 
2133
-        $resql=$this->db->query($sql);
2133
+        $resql = $this->db->query($sql);
2134 2134
         if ($resql)
2135 2135
         {
2136 2136
             if ($mode == 'opened') {
2137
-	            $delay_warning=$conf->supplier_proposal->cloture->warning_delay;
2137
+	            $delay_warning = $conf->supplier_proposal->cloture->warning_delay;
2138 2138
 	            $statut = self::STATUS_VALIDATED;
2139 2139
 	            $label = $langs->trans("SupplierProposalsToClose");
2140 2140
             }
2141 2141
             if ($mode == 'signed') {
2142
-	            $delay_warning=$conf->supplier_proposal->facturation->warning_delay;
2142
+	            $delay_warning = $conf->supplier_proposal->facturation->warning_delay;
2143 2143
 	            $statut = self::STATUS_SIGNED;
2144
-	            $label = $langs->trans("SupplierProposalsToProcess");      // May be billed or ordered
2144
+	            $label = $langs->trans("SupplierProposalsToProcess"); // May be billed or ordered
2145 2145
             }
2146 2146
 
2147 2147
 	        $response = new WorkboardResponse();
2148
-	        $response->warning_delay = $delay_warning/60/60/24;
2148
+	        $response->warning_delay = $delay_warning / 60 / 60 / 24;
2149 2149
 	        $response->label = $label;
2150 2150
 	        $response->url = DOL_URL_ROOT.'/supplier_proposal/list.php?viewstatut='.$statut;
2151
-	        $response->img = img_object('',"propal");
2151
+	        $response->img = img_object('', "propal");
2152 2152
 
2153 2153
             // This assignment in condition is not a bug. It allows walking the results.
2154
-            while ($obj=$this->db->fetch_object($resql))
2154
+            while ($obj = $this->db->fetch_object($resql))
2155 2155
             {
2156 2156
                 $response->nbtodo++;
2157 2157
                 if ($mode == 'opened')
@@ -2169,7 +2169,7 @@  discard block
 block discarded – undo
2169 2169
         }
2170 2170
         else
2171 2171
         {
2172
-            $this->error=$this->db->lasterror();
2172
+            $this->error = $this->db->lasterror();
2173 2173
             return -1;
2174 2174
         }
2175 2175
     }
@@ -2184,14 +2184,14 @@  discard block
 block discarded – undo
2184 2184
      */
2185 2185
     function initAsSpecimen()
2186 2186
     {
2187
-        global $user,$langs,$conf;
2187
+        global $user, $langs, $conf;
2188 2188
 
2189 2189
         // Load array of products prodids
2190 2190
         $num_prods = 0;
2191 2191
         $prodids = array();
2192 2192
         $sql = "SELECT rowid";
2193
-        $sql.= " FROM ".MAIN_DB_PREFIX."product";
2194
-        $sql.= " WHERE entity IN (".getEntity('product').")";
2193
+        $sql .= " FROM ".MAIN_DB_PREFIX."product";
2194
+        $sql .= " WHERE entity IN (".getEntity('product').")";
2195 2195
         $resql = $this->db->query($sql);
2196 2196
         if ($resql)
2197 2197
         {
@@ -2206,52 +2206,52 @@  discard block
 block discarded – undo
2206 2206
         }
2207 2207
 
2208 2208
         // Initialise parametres
2209
-        $this->id=0;
2209
+        $this->id = 0;
2210 2210
         $this->ref = 'SPECIMEN';
2211
-        $this->specimen=1;
2211
+        $this->specimen = 1;
2212 2212
         $this->socid = 1;
2213 2213
         $this->date = time();
2214 2214
         $this->cond_reglement_id   = 1;
2215 2215
         $this->cond_reglement_code = 'RECEP';
2216 2216
         $this->mode_reglement_id   = 7;
2217 2217
         $this->mode_reglement_code = 'CHQ';
2218
-        $this->note_public='This is a comment (public)';
2219
-        $this->note_private='This is a comment (private)';
2218
+        $this->note_public = 'This is a comment (public)';
2219
+        $this->note_private = 'This is a comment (private)';
2220 2220
         // Lines
2221 2221
         $nbp = 5;
2222 2222
         $xnbp = 0;
2223 2223
         while ($xnbp < $nbp)
2224 2224
         {
2225
-            $line=new SupplierProposalLine($this->db);
2226
-            $line->desc=$langs->trans("Description")." ".$xnbp;
2227
-            $line->qty=1;
2228
-            $line->subprice=100;
2229
-            $line->price=100;
2230
-            $line->tva_tx=19.6;
2231
-            $line->localtax1_tx=0;
2232
-            $line->localtax2_tx=0;
2225
+            $line = new SupplierProposalLine($this->db);
2226
+            $line->desc = $langs->trans("Description")." ".$xnbp;
2227
+            $line->qty = 1;
2228
+            $line->subprice = 100;
2229
+            $line->price = 100;
2230
+            $line->tva_tx = 19.6;
2231
+            $line->localtax1_tx = 0;
2232
+            $line->localtax2_tx = 0;
2233 2233
             if ($xnbp == 2)
2234 2234
             {
2235
-                $line->total_ht=50;
2236
-                $line->total_ttc=59.8;
2237
-                $line->total_tva=9.8;
2238
-                $line->remise_percent=50;
2235
+                $line->total_ht = 50;
2236
+                $line->total_ttc = 59.8;
2237
+                $line->total_tva = 9.8;
2238
+                $line->remise_percent = 50;
2239 2239
             }
2240 2240
             else
2241 2241
             {
2242
-                $line->total_ht=100;
2243
-                $line->total_ttc=119.6;
2244
-                $line->total_tva=19.6;
2245
-                $line->remise_percent=00;
2242
+                $line->total_ht = 100;
2243
+                $line->total_ttc = 119.6;
2244
+                $line->total_tva = 19.6;
2245
+                $line->remise_percent = 00;
2246 2246
             }
2247 2247
 
2248 2248
             if ($num_prods > 0)
2249 2249
             {
2250 2250
             	$prodid = mt_rand(1, $num_prods);
2251
-            	$line->fk_product=$prodids[$prodid];
2251
+            	$line->fk_product = $prodids[$prodid];
2252 2252
             }
2253 2253
 
2254
-            $this->lines[$xnbp]=$line;
2254
+            $this->lines[$xnbp] = $line;
2255 2255
 
2256 2256
             $this->total_ht       += $line->total_ht;
2257 2257
             $this->total_tva      += $line->total_tva;
@@ -2270,27 +2270,27 @@  discard block
 block discarded – undo
2270 2270
     {
2271 2271
         global $conf, $user;
2272 2272
 
2273
-        $this->nb=array();
2273
+        $this->nb = array();
2274 2274
         $clause = "WHERE";
2275 2275
 
2276 2276
         $sql = "SELECT count(p.rowid) as nb";
2277
-        $sql.= " FROM ".MAIN_DB_PREFIX."supplier_proposal as p";
2278
-        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON p.fk_soc = s.rowid";
2277
+        $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal as p";
2278
+        $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON p.fk_soc = s.rowid";
2279 2279
         if (!$user->rights->societe->client->voir && !$user->societe_id)
2280 2280
         {
2281
-            $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
2282
-            $sql.= " WHERE sc.fk_user = " .$user->id;
2281
+            $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
2282
+            $sql .= " WHERE sc.fk_user = ".$user->id;
2283 2283
             $clause = "AND";
2284 2284
         }
2285
-        $sql.= " ".$clause." p.entity = ".$conf->entity;
2285
+        $sql .= " ".$clause." p.entity = ".$conf->entity;
2286 2286
 
2287
-        $resql=$this->db->query($sql);
2287
+        $resql = $this->db->query($sql);
2288 2288
         if ($resql)
2289 2289
         {
2290 2290
             // This assignment in condition is not a bug. It allows walking the results.
2291
-            while ($obj=$this->db->fetch_object($resql))
2291
+            while ($obj = $this->db->fetch_object($resql))
2292 2292
             {
2293
-                $this->nb["askprice"]=$obj->nb;
2293
+                $this->nb["askprice"] = $obj->nb;
2294 2294
             }
2295 2295
             $this->db->free($resql);
2296 2296
             return 1;
@@ -2298,7 +2298,7 @@  discard block
 block discarded – undo
2298 2298
         else
2299 2299
         {
2300 2300
             dol_print_error($this->db);
2301
-            $this->error=$this->db->lasterror();
2301
+            $this->error = $this->db->lasterror();
2302 2302
             return -1;
2303 2303
         }
2304 2304
     }
@@ -2316,9 +2316,9 @@  discard block
 block discarded – undo
2316 2316
         global $conf, $db, $langs;
2317 2317
         $langs->load("supplier_proposal");
2318 2318
 
2319
-        if (! empty($conf->global->SUPPLIER_PROPOSAL_ADDON))
2319
+        if (!empty($conf->global->SUPPLIER_PROPOSAL_ADDON))
2320 2320
         {
2321
-        	$mybool=false;
2321
+        	$mybool = false;
2322 2322
 
2323 2323
             $file = $conf->global->SUPPLIER_PROPOSAL_ADDON.".php";
2324 2324
             $classname = $conf->global->SUPPLIER_PROPOSAL_ADDON;
@@ -2330,18 +2330,18 @@  discard block
 block discarded – undo
2330 2330
                 $dir = dol_buildpath($reldir."core/modules/supplier_proposal/");
2331 2331
 
2332 2332
                 // Load file with numbering class (if found)
2333
-                $mybool|=@include_once $dir.$file;
2333
+                $mybool |= @include_once $dir.$file;
2334 2334
             }
2335 2335
 
2336
-            if (! $mybool)
2336
+            if (!$mybool)
2337 2337
             {
2338
-            	dol_print_error('',"Failed to include file ".$file);
2338
+            	dol_print_error('', "Failed to include file ".$file);
2339 2339
             	return '';
2340 2340
             }
2341 2341
 
2342 2342
             $obj = new $classname();
2343 2343
             $numref = "";
2344
-            $numref = $obj->getNextValue($soc,$this);
2344
+            $numref = $obj->getNextValue($soc, $this);
2345 2345
 
2346 2346
             if ($numref != "")
2347 2347
             {
@@ -2349,7 +2349,7 @@  discard block
 block discarded – undo
2349 2349
             }
2350 2350
             else
2351 2351
 			{
2352
-                $this->error=$obj->error;
2352
+                $this->error = $obj->error;
2353 2353
                 return "";
2354 2354
             }
2355 2355
         }
@@ -2371,65 +2371,65 @@  discard block
 block discarded – undo
2371 2371
      *  @param      int     $save_lastsearch_value		-1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
2372 2372
      *	@return     string          					String with URL
2373 2373
      */
2374
-    function getNomUrl($withpicto=0, $option='', $get_params='', $notooltip=0, $save_lastsearch_value=-1)
2374
+    function getNomUrl($withpicto = 0, $option = '', $get_params = '', $notooltip = 0, $save_lastsearch_value = -1)
2375 2375
     {
2376 2376
         global $langs, $conf, $user;
2377 2377
 
2378
-        if (! empty($conf->dol_no_mouse_hover)) $notooltip=1;   // Force disable tooltips
2379
-
2380
-        $url='';
2381
-        $result='';
2382
-
2383
-        $label='<u>'.$langs->trans("ShowSupplierProposal").'</u>';
2384
-        if (! empty($this->ref))
2385
-        $label.= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
2386
-        if (! empty($this->ref_fourn))
2387
-            $label.= '<br><b>'.$langs->trans('RefSupplier').':</b> '.$this->ref_fourn;
2388
-        if (! empty($this->total_ht))
2389
-            $label.= '<br><b>' . $langs->trans('AmountHT') . ':</b> ' . price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
2390
-        if (! empty($this->total_tva))
2391
-            $label.= '<br><b>' . $langs->trans('VAT') . ':</b> ' . price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
2392
-        if (! empty($this->total_ttc))
2393
-            $label.= '<br><b>' . $langs->trans('AmountTTC') . ':</b> ' . price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
2378
+        if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
2379
+
2380
+        $url = '';
2381
+        $result = '';
2382
+
2383
+        $label = '<u>'.$langs->trans("ShowSupplierProposal").'</u>';
2384
+        if (!empty($this->ref))
2385
+        $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
2386
+        if (!empty($this->ref_fourn))
2387
+            $label .= '<br><b>'.$langs->trans('RefSupplier').':</b> '.$this->ref_fourn;
2388
+        if (!empty($this->total_ht))
2389
+            $label .= '<br><b>'.$langs->trans('AmountHT').':</b> '.price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
2390
+        if (!empty($this->total_tva))
2391
+            $label .= '<br><b>'.$langs->trans('VAT').':</b> '.price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
2392
+        if (!empty($this->total_ttc))
2393
+            $label .= '<br><b>'.$langs->trans('AmountTTC').':</b> '.price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
2394 2394
         if ($option == '') {
2395
-            $url = DOL_URL_ROOT.'/supplier_proposal/card.php?id='.$this->id. $get_params;
2395
+            $url = DOL_URL_ROOT.'/supplier_proposal/card.php?id='.$this->id.$get_params;
2396 2396
         }
2397 2397
         if ($option == 'document') {
2398
-            $url = DOL_URL_ROOT.'/supplier_proposal/document.php?id='.$this->id. $get_params;
2398
+            $url = DOL_URL_ROOT.'/supplier_proposal/document.php?id='.$this->id.$get_params;
2399 2399
         }
2400 2400
 
2401 2401
         if ($option !== 'nolink')
2402 2402
         {
2403 2403
         	// Add param to save lastsearch_values or not
2404
-        	$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
2405
-        	if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
2406
-        	if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
2404
+        	$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2405
+        	if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
2406
+        	if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
2407 2407
         }
2408 2408
 
2409
-        $linkclose='';
2409
+        $linkclose = '';
2410 2410
         if (empty($notooltip) && $user->rights->propal->lire)
2411 2411
         {
2412
-            if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
2412
+            if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
2413 2413
             {
2414
-                $label=$langs->trans("ShowSupplierProposal");
2415
-                $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
2414
+                $label = $langs->trans("ShowSupplierProposal");
2415
+                $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
2416 2416
             }
2417
-            $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
2418
-            $linkclose.=' class="classfortooltip"';
2417
+            $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
2418
+            $linkclose .= ' class="classfortooltip"';
2419 2419
         }
2420 2420
 
2421 2421
         $linkstart = '<a href="'.$url.'"';
2422
-        $linkstart.=$linkclose.'>';
2423
-        $linkend='</a>';
2422
+        $linkstart .= $linkclose.'>';
2423
+        $linkend = '</a>';
2424 2424
 
2425
-        $picto='supplier_proposal';
2425
+        $picto = 'supplier_proposal';
2426 2426
 
2427 2427
 
2428 2428
         if ($withpicto)
2429
-            $result.=($linkstart.img_object(($notooltip?'':$label), $picto, ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend);
2429
+            $result .= ($linkstart.img_object(($notooltip ? '' : $label), $picto, ($notooltip ? '' : 'class="classfortooltip"'), 0, 0, $notooltip ? 0 : 1).$linkend);
2430 2430
         if ($withpicto && $withpicto != 2)
2431
-            $result.=' ';
2432
-        $result.=$linkstart.$this->ref.$linkend;
2431
+            $result .= ' ';
2432
+        $result .= $linkstart.$this->ref.$linkend;
2433 2433
         return $result;
2434 2434
     }
2435 2435
 
@@ -2443,16 +2443,16 @@  discard block
 block discarded – undo
2443 2443
         // For other object, here we call fetch_lines. But fetch_lines does not exists on supplier proposal
2444 2444
 
2445 2445
         $sql = 'SELECT pt.rowid, pt.label as custom_label, pt.description, pt.fk_product, pt.fk_remise_except,';
2446
-        $sql.= ' pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, pt.info_bits,';
2447
-        $sql.= ' pt.total_ht, pt.total_tva, pt.total_ttc, pt.fk_product_fournisseur_price as fk_fournprice, pt.buy_price_ht as pa_ht, pt.special_code, pt.localtax1_tx, pt.localtax2_tx,';
2448
-        $sql.= ' pt.product_type, pt.rang, pt.fk_parent_line,';
2449
-        $sql.= ' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid,';
2450
-        $sql.= ' p.description as product_desc, pt.ref_fourn as ref_produit_fourn,';
2451
-		$sql.= ' pt.fk_multicurrency, pt.multicurrency_code, pt.multicurrency_subprice, pt.multicurrency_total_ht, pt.multicurrency_total_tva, pt.multicurrency_total_ttc, pt.fk_unit';
2452
-        $sql.= ' FROM '.MAIN_DB_PREFIX.'supplier_proposaldet as pt';
2453
-        $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product=p.rowid';
2454
-        $sql.= ' WHERE pt.fk_supplier_proposal = '.$this->id;
2455
-        $sql.= ' ORDER BY pt.rang ASC, pt.rowid';
2446
+        $sql .= ' pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, pt.info_bits,';
2447
+        $sql .= ' pt.total_ht, pt.total_tva, pt.total_ttc, pt.fk_product_fournisseur_price as fk_fournprice, pt.buy_price_ht as pa_ht, pt.special_code, pt.localtax1_tx, pt.localtax2_tx,';
2448
+        $sql .= ' pt.product_type, pt.rang, pt.fk_parent_line,';
2449
+        $sql .= ' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid,';
2450
+        $sql .= ' p.description as product_desc, pt.ref_fourn as ref_produit_fourn,';
2451
+		$sql .= ' pt.fk_multicurrency, pt.multicurrency_code, pt.multicurrency_subprice, pt.multicurrency_total_ht, pt.multicurrency_total_tva, pt.multicurrency_total_ttc, pt.fk_unit';
2452
+        $sql .= ' FROM '.MAIN_DB_PREFIX.'supplier_proposaldet as pt';
2453
+        $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product=p.rowid';
2454
+        $sql .= ' WHERE pt.fk_supplier_proposal = '.$this->id;
2455
+        $sql .= ' ORDER BY pt.rang ASC, pt.rowid';
2456 2456
 
2457 2457
         dol_syslog(get_class($this).'::getLinesArray', LOG_DEBUG);
2458 2458
         $resql = $this->db->query($sql);
@@ -2465,45 +2465,45 @@  discard block
 block discarded – undo
2465 2465
             {
2466 2466
                 $obj = $this->db->fetch_object($resql);
2467 2467
 
2468
-                $this->lines[$i]					= new SupplierProposalLine($this->db);
2469
-                $this->lines[$i]->id				= $obj->rowid; // for backward compatibility
2468
+                $this->lines[$i] = new SupplierProposalLine($this->db);
2469
+                $this->lines[$i]->id = $obj->rowid; // for backward compatibility
2470 2470
                 $this->lines[$i]->rowid				= $obj->rowid;
2471 2471
                 $this->lines[$i]->label 			= $obj->custom_label;
2472
-                $this->lines[$i]->description 		= $obj->description;
2473
-                $this->lines[$i]->fk_product		= $obj->fk_product;
2474
-                $this->lines[$i]->ref				= $obj->ref;
2475
-                $this->lines[$i]->product_label		= $obj->product_label;
2472
+                $this->lines[$i]->description = $obj->description;
2473
+                $this->lines[$i]->fk_product = $obj->fk_product;
2474
+                $this->lines[$i]->ref = $obj->ref;
2475
+                $this->lines[$i]->product_label = $obj->product_label;
2476 2476
                 $this->lines[$i]->product_desc		= $obj->product_desc;
2477
-                $this->lines[$i]->fk_product_type	= $obj->fk_product_type;  // deprecated
2477
+                $this->lines[$i]->fk_product_type = $obj->fk_product_type; // deprecated
2478 2478
                 $this->lines[$i]->product_type		= $obj->product_type;
2479
-                $this->lines[$i]->qty				= $obj->qty;
2480
-                $this->lines[$i]->subprice			= $obj->subprice;
2481
-                $this->lines[$i]->fk_remise_except 	= $obj->fk_remise_except;
2482
-                $this->lines[$i]->remise_percent	= $obj->remise_percent;
2483
-                $this->lines[$i]->tva_tx			= $obj->tva_tx;
2479
+                $this->lines[$i]->qty = $obj->qty;
2480
+                $this->lines[$i]->subprice = $obj->subprice;
2481
+                $this->lines[$i]->fk_remise_except = $obj->fk_remise_except;
2482
+                $this->lines[$i]->remise_percent = $obj->remise_percent;
2483
+                $this->lines[$i]->tva_tx = $obj->tva_tx;
2484 2484
                 $this->lines[$i]->info_bits			= $obj->info_bits;
2485
-                $this->lines[$i]->total_ht			= $obj->total_ht;
2485
+                $this->lines[$i]->total_ht = $obj->total_ht;
2486 2486
                 $this->lines[$i]->total_tva			= $obj->total_tva;
2487 2487
                 $this->lines[$i]->total_ttc			= $obj->total_ttc;
2488
-				$this->lines[$i]->fk_fournprice		= $obj->fk_fournprice;
2489
-				$marginInfos						= getMarginInfos($obj->subprice, $obj->remise_percent, $obj->tva_tx, $obj->localtax1_tx, $obj->localtax2_tx, $this->lines[$i]->fk_fournprice, $obj->pa_ht);
2490
-				$this->lines[$i]->pa_ht				= $marginInfos[0];
2491
-				$this->lines[$i]->marge_tx			= $marginInfos[1];
2492
-				$this->lines[$i]->marque_tx			= $marginInfos[2];
2493
-				$this->lines[$i]->fk_parent_line	= $obj->fk_parent_line;
2494
-                $this->lines[$i]->special_code		= $obj->special_code;
2495
-                $this->lines[$i]->rang				= $obj->rang;
2488
+				$this->lines[$i]->fk_fournprice = $obj->fk_fournprice;
2489
+				$marginInfos = getMarginInfos($obj->subprice, $obj->remise_percent, $obj->tva_tx, $obj->localtax1_tx, $obj->localtax2_tx, $this->lines[$i]->fk_fournprice, $obj->pa_ht);
2490
+				$this->lines[$i]->pa_ht = $marginInfos[0];
2491
+				$this->lines[$i]->marge_tx = $marginInfos[1];
2492
+				$this->lines[$i]->marque_tx = $marginInfos[2];
2493
+				$this->lines[$i]->fk_parent_line = $obj->fk_parent_line;
2494
+                $this->lines[$i]->special_code = $obj->special_code;
2495
+                $this->lines[$i]->rang = $obj->rang;
2496 2496
 
2497
-                $this->lines[$i]->ref_fourn				= $obj->ref_produit_fourn;
2497
+                $this->lines[$i]->ref_fourn = $obj->ref_produit_fourn;
2498 2498
 
2499 2499
 				// Multicurrency
2500
-				$this->lines[$i]->fk_multicurrency 			= $obj->fk_multicurrency;
2501
-				$this->lines[$i]->multicurrency_code 		= $obj->multicurrency_code;
2500
+				$this->lines[$i]->fk_multicurrency = $obj->fk_multicurrency;
2501
+				$this->lines[$i]->multicurrency_code = $obj->multicurrency_code;
2502 2502
 				$this->lines[$i]->multicurrency_subprice 	= $obj->multicurrency_subprice;
2503 2503
 				$this->lines[$i]->multicurrency_total_ht 	= $obj->multicurrency_total_ht;
2504 2504
 				$this->lines[$i]->multicurrency_total_tva 	= $obj->multicurrency_total_tva;
2505 2505
 				$this->lines[$i]->multicurrency_total_ttc 	= $obj->multicurrency_total_ttc;
2506
-				$this->lines[$i]->fk_unit				 	= $obj->fk_unit;
2506
+				$this->lines[$i]->fk_unit = $obj->fk_unit;
2507 2507
 
2508 2508
                 $i++;
2509 2509
             }
@@ -2513,7 +2513,7 @@  discard block
 block discarded – undo
2513 2513
         }
2514 2514
         else
2515 2515
         {
2516
-            $this->error=$this->db->error();
2516
+            $this->error = $this->db->error();
2517 2517
             return -1;
2518 2518
         }
2519 2519
     }
@@ -2528,19 +2528,19 @@  discard block
 block discarded – undo
2528 2528
 	 *  @param      int			$hideref        Hide ref
2529 2529
 	 * 	@return     int         				0 if KO, 1 if OK
2530 2530
 	 */
2531
-	public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
2531
+	public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2532 2532
 	{
2533 2533
 		global $conf, $langs;
2534 2534
 
2535 2535
 		$langs->load("supplier_proposal");
2536 2536
 
2537
-		if (! dol_strlen($modele)) {
2537
+		if (!dol_strlen($modele)) {
2538 2538
 
2539 2539
 			$modele = 'aurore';
2540 2540
 
2541 2541
 			if ($this->modelpdf) {
2542 2542
 				$modele = $this->modelpdf;
2543
-			} elseif (! empty($conf->global->SUPPLIER_PROPOSAL_ADDON_PDF)) {
2543
+			} elseif (!empty($conf->global->SUPPLIER_PROPOSAL_ADDON_PDF)) {
2544 2544
 				$modele = $conf->global->SUPPLIER_PROPOSAL_ADDON_PDF;
2545 2545
 			}
2546 2546
 		}
@@ -2579,8 +2579,8 @@  discard block
 block discarded – undo
2579 2579
     var $db;
2580 2580
     var $error;
2581 2581
 
2582
-    public $element='supplier_proposaldet';
2583
-    public $table_element='supplier_proposaldet';
2582
+    public $element = 'supplier_proposaldet';
2583
+    public $table_element = 'supplier_proposaldet';
2584 2584
 
2585 2585
     var $oldline;
2586 2586
 
@@ -2589,8 +2589,8 @@  discard block
 block discarded – undo
2589 2589
     var $id;
2590 2590
     var $fk_supplier_proposal;
2591 2591
     var $fk_parent_line;
2592
-    var $desc;          	// Description ligne
2593
-    var $fk_product;		// Id produit predefini
2592
+    var $desc; // Description ligne
2593
+    var $fk_product; // Id produit predefini
2594 2594
 	/**
2595 2595
 	 * @deprecated
2596 2596
 	 * @see product_type
@@ -2616,18 +2616,18 @@  discard block
 block discarded – undo
2616 2616
 	var $marge_tx;
2617 2617
 	var $marque_tx;
2618 2618
 
2619
-    var $special_code;	// Tag for special lines (exlusive tags)
2619
+    var $special_code; // Tag for special lines (exlusive tags)
2620 2620
     // 1: frais de port
2621 2621
     // 2: ecotaxe
2622 2622
     // 3: option line (when qty = 0)
2623 2623
 
2624
-    var $info_bits = 0;	// Liste d'options cumulables:
2624
+    var $info_bits = 0; // Liste d'options cumulables:
2625 2625
     // Bit 0: 	0 si TVA normal - 1 si TVA NPR
2626 2626
     // Bit 1:	0 ligne normale - 1 si ligne de remise fixe
2627 2627
 
2628
-    var $total_ht;			// Total HT  de la ligne toute quantite et incluant la remise ligne
2629
-    var $total_tva;			// Total TVA  de la ligne toute quantite et incluant la remise ligne
2630
-    var $total_ttc;			// Total TTC de la ligne toute quantite et incluant la remise ligne
2628
+    var $total_ht; // Total HT  de la ligne toute quantite et incluant la remise ligne
2629
+    var $total_tva; // Total TVA  de la ligne toute quantite et incluant la remise ligne
2630
+    var $total_ttc; // Total TTC de la ligne toute quantite et incluant la remise ligne
2631 2631
 
2632 2632
 	/**
2633 2633
 	 * @deprecated
@@ -2667,12 +2667,12 @@  discard block
 block discarded – undo
2667 2667
 	 */
2668 2668
 	public $product_desc;
2669 2669
 
2670
-    var $localtax1_tx;		// Local tax 1
2671
-    var $localtax2_tx;		// Local tax 2
2672
-    var $localtax1_type;	// Local tax 1 type
2673
-	var $localtax2_type;	// Local tax 2 type
2674
-    var $total_localtax1;  	// Line total local tax 1
2675
-    var $total_localtax2;	// Line total local tax 2
2670
+    var $localtax1_tx; // Local tax 1
2671
+    var $localtax2_tx; // Local tax 2
2672
+    var $localtax1_type; // Local tax 1 type
2673
+	var $localtax2_type; // Local tax 2 type
2674
+    var $total_localtax1; // Line total local tax 1
2675
+    var $total_localtax2; // Line total local tax 2
2676 2676
 
2677 2677
     var $skip_update_total; // Skip update price total for special lines
2678 2678
 
@@ -2693,7 +2693,7 @@  discard block
 block discarded – undo
2693 2693
      */
2694 2694
     function __construct($db)
2695 2695
     {
2696
-        $this->db= $db;
2696
+        $this->db = $db;
2697 2697
     }
2698 2698
 
2699 2699
     /**
@@ -2705,42 +2705,42 @@  discard block
 block discarded – undo
2705 2705
 	function fetch($rowid)
2706 2706
 	{
2707 2707
 		$sql = 'SELECT pd.rowid, pd.fk_supplier_proposal, pd.fk_parent_line, pd.fk_product, pd.label as custom_label, pd.description, pd.price, pd.qty, pd.tva_tx,';
2708
-		$sql.= ' pd.remise, pd.remise_percent, pd.fk_remise_except, pd.subprice,';
2709
-		$sql.= ' pd.info_bits, pd.total_ht, pd.total_tva, pd.total_ttc, pd.fk_product_fournisseur_price as fk_fournprice, pd.buy_price_ht as pa_ht, pd.special_code, pd.rang,';
2710
-		$sql.= ' pd.localtax1_tx, pd.localtax2_tx, pd.total_localtax1, pd.total_localtax2,';
2711
-		$sql.= ' p.ref as product_ref, p.label as product_label, p.description as product_desc,';
2712
-		$sql.= ' pd.product_type, pd.ref_fourn as ref_produit_fourn,';
2713
-		$sql.= ' pd.fk_multicurrency, pd.multicurrency_code, pd.multicurrency_subprice, pd.multicurrency_total_ht, pd.multicurrency_total_tva, pd.multicurrency_total_ttc, pd.fk_unit';
2714
-		$sql.= ' FROM '.MAIN_DB_PREFIX.'supplier_proposaldet as pd';
2715
-		$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pd.fk_product = p.rowid';
2716
-		$sql.= ' WHERE pd.rowid = '.$rowid;
2708
+		$sql .= ' pd.remise, pd.remise_percent, pd.fk_remise_except, pd.subprice,';
2709
+		$sql .= ' pd.info_bits, pd.total_ht, pd.total_tva, pd.total_ttc, pd.fk_product_fournisseur_price as fk_fournprice, pd.buy_price_ht as pa_ht, pd.special_code, pd.rang,';
2710
+		$sql .= ' pd.localtax1_tx, pd.localtax2_tx, pd.total_localtax1, pd.total_localtax2,';
2711
+		$sql .= ' p.ref as product_ref, p.label as product_label, p.description as product_desc,';
2712
+		$sql .= ' pd.product_type, pd.ref_fourn as ref_produit_fourn,';
2713
+		$sql .= ' pd.fk_multicurrency, pd.multicurrency_code, pd.multicurrency_subprice, pd.multicurrency_total_ht, pd.multicurrency_total_tva, pd.multicurrency_total_ttc, pd.fk_unit';
2714
+		$sql .= ' FROM '.MAIN_DB_PREFIX.'supplier_proposaldet as pd';
2715
+		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pd.fk_product = p.rowid';
2716
+		$sql .= ' WHERE pd.rowid = '.$rowid;
2717 2717
 
2718 2718
 		$result = $this->db->query($sql);
2719 2719
 		if ($result)
2720 2720
 		{
2721 2721
 			$objp = $this->db->fetch_object($result);
2722 2722
 
2723
-			$this->rowid			= $objp->rowid; // deprecated
2724
-			$this->id				= $objp->rowid;
2725
-			$this->fk_supplier_proposal		= $objp->fk_supplier_proposal;
2726
-			$this->fk_parent_line	= $objp->fk_parent_line;
2723
+			$this->rowid = $objp->rowid; // deprecated
2724
+			$this->id = $objp->rowid;
2725
+			$this->fk_supplier_proposal = $objp->fk_supplier_proposal;
2726
+			$this->fk_parent_line = $objp->fk_parent_line;
2727 2727
 			$this->label			= $objp->custom_label;
2728 2728
 			$this->desc				= $objp->description;
2729
-			$this->qty				= $objp->qty;
2730
-			$this->price			= $objp->price;		// deprecated
2731
-			$this->subprice			= $objp->subprice;
2729
+			$this->qty = $objp->qty;
2730
+			$this->price			= $objp->price; // deprecated
2731
+			$this->subprice = $objp->subprice;
2732 2732
 			$this->tva_tx			= $objp->tva_tx;
2733 2733
 			$this->remise			= $objp->remise;
2734
-			$this->remise_percent	= $objp->remise_percent;
2734
+			$this->remise_percent = $objp->remise_percent;
2735 2735
 			$this->fk_remise_except = $objp->fk_remise_except;
2736
-			$this->fk_product		= $objp->fk_product;
2736
+			$this->fk_product = $objp->fk_product;
2737 2737
 			$this->info_bits		= $objp->info_bits;
2738 2738
 
2739 2739
 			$this->total_ht			= $objp->total_ht;
2740 2740
 			$this->total_tva		= $objp->total_tva;
2741 2741
 			$this->total_ttc		= $objp->total_ttc;
2742 2742
 
2743
-			$this->fk_fournprice	= $objp->fk_fournprice;
2743
+			$this->fk_fournprice = $objp->fk_fournprice;
2744 2744
 
2745 2745
 			$marginInfos			= getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $this->fk_fournprice, $objp->pa_ht);
2746 2746
 			$this->pa_ht			= $marginInfos[0];
@@ -2749,24 +2749,24 @@  discard block
 block discarded – undo
2749 2749
 
2750 2750
 			$this->special_code		= $objp->special_code;
2751 2751
 			$this->product_type		= $objp->product_type;
2752
-			$this->rang				= $objp->rang;
2752
+			$this->rang = $objp->rang;
2753 2753
 
2754
-			$this->ref				= $objp->product_ref;      // deprecated
2755
-			$this->product_ref		= $objp->product_ref;
2756
-			$this->libelle			= $objp->product_label;  // deprecated
2754
+			$this->ref = $objp->product_ref; // deprecated
2755
+			$this->product_ref = $objp->product_ref;
2756
+			$this->libelle = $objp->product_label; // deprecated
2757 2757
 			$this->product_label	= $objp->product_label;
2758 2758
 			$this->product_desc		= $objp->product_desc;
2759 2759
 
2760
-			$this->ref_fourn		= $objp->ref_produit_forun;
2760
+			$this->ref_fourn = $objp->ref_produit_forun;
2761 2761
 
2762 2762
 			// Multicurrency
2763
-			$this->fk_multicurrency 		= $objp->fk_multicurrency;
2764
-			$this->multicurrency_code 		= $objp->multicurrency_code;
2763
+			$this->fk_multicurrency = $objp->fk_multicurrency;
2764
+			$this->multicurrency_code = $objp->multicurrency_code;
2765 2765
 			$this->multicurrency_subprice 	= $objp->multicurrency_subprice;
2766 2766
 			$this->multicurrency_total_ht 	= $objp->multicurrency_total_ht;
2767 2767
 			$this->multicurrency_total_tva 	= $objp->multicurrency_total_tva;
2768 2768
 			$this->multicurrency_total_ttc 	= $objp->multicurrency_total_ttc;
2769
-			$this->fk_unit				 	= $objp->fk_unit;
2769
+			$this->fk_unit = $objp->fk_unit;
2770 2770
 
2771 2771
 			$this->db->free($result);
2772 2772
 		}
@@ -2782,33 +2782,33 @@  discard block
 block discarded – undo
2782 2782
      *	@param		int		$notrigger		1=Does not execute triggers, 0= execute triggers
2783 2783
      *	@return		int						<0 if KO, >0 if OK
2784 2784
      */
2785
-    function insert($notrigger=0)
2785
+    function insert($notrigger = 0)
2786 2786
     {
2787
-        global $conf,$langs,$user;
2787
+        global $conf, $langs, $user;
2788 2788
 
2789
-        $error=0;
2789
+        $error = 0;
2790 2790
 
2791 2791
         dol_syslog(get_class($this)."::insert rang=".$this->rang);
2792 2792
 
2793 2793
         // Clean parameters
2794
-        if (empty($this->tva_tx)) $this->tva_tx=0;
2795
-        if (empty($this->localtax1_tx)) $this->localtax1_tx=0;
2796
-        if (empty($this->localtax2_tx)) $this->localtax2_tx=0;
2797
-        if (empty($this->localtax1_type)) $this->localtax1_type=0;
2798
-		if (empty($this->localtax2_type)) $this->localtax2_type=0;
2799
-        if (empty($this->total_localtax1)) $this->total_localtax1=0;
2800
-        if (empty($this->total_localtax2)) $this->total_localtax2=0;
2801
-        if (empty($this->rang)) $this->rang=0;
2802
-        if (empty($this->remise)) $this->remise=0;
2803
-        if (empty($this->remise_percent)) $this->remise_percent=0;
2804
-        if (empty($this->info_bits)) $this->info_bits=0;
2805
-        if (empty($this->special_code)) $this->special_code=0;
2806
-        if (empty($this->fk_parent_line)) $this->fk_parent_line=0;
2807
-        if (empty($this->fk_fournprice)) $this->fk_fournprice=0;
2808
-        if (empty($this->fk_unit)) $this->fk_unit=0;
2809
-        if (empty($this->subprice)) $this->subprice=0;
2810
-
2811
-        if (empty($this->pa_ht)) $this->pa_ht=0;
2794
+        if (empty($this->tva_tx)) $this->tva_tx = 0;
2795
+        if (empty($this->localtax1_tx)) $this->localtax1_tx = 0;
2796
+        if (empty($this->localtax2_tx)) $this->localtax2_tx = 0;
2797
+        if (empty($this->localtax1_type)) $this->localtax1_type = 0;
2798
+		if (empty($this->localtax2_type)) $this->localtax2_type = 0;
2799
+        if (empty($this->total_localtax1)) $this->total_localtax1 = 0;
2800
+        if (empty($this->total_localtax2)) $this->total_localtax2 = 0;
2801
+        if (empty($this->rang)) $this->rang = 0;
2802
+        if (empty($this->remise)) $this->remise = 0;
2803
+        if (empty($this->remise_percent)) $this->remise_percent = 0;
2804
+        if (empty($this->info_bits)) $this->info_bits = 0;
2805
+        if (empty($this->special_code)) $this->special_code = 0;
2806
+        if (empty($this->fk_parent_line)) $this->fk_parent_line = 0;
2807
+        if (empty($this->fk_fournprice)) $this->fk_fournprice = 0;
2808
+        if (empty($this->fk_unit)) $this->fk_unit = 0;
2809
+        if (empty($this->subprice)) $this->subprice = 0;
2810
+
2811
+        if (empty($this->pa_ht)) $this->pa_ht = 0;
2812 2812
 
2813 2813
 		// if buy price not defined, define buyprice as configured in margin admin
2814 2814
 		if ($this->pa_ht == 0)
@@ -2830,68 +2830,68 @@  discard block
 block discarded – undo
2830 2830
 
2831 2831
         // Insert line into database
2832 2832
         $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'supplier_proposaldet';
2833
-        $sql.= ' (fk_supplier_proposal, fk_parent_line, label, description, fk_product, product_type,';
2834
-		$sql.= ' fk_remise_except, qty, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,';
2835
-        $sql.= ' subprice, remise_percent, ';
2836
-        $sql.= ' info_bits, ';
2837
-        $sql.= ' total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_product_fournisseur_price, buy_price_ht, special_code, rang,';
2838
-        $sql.= ' ref_fourn,';
2839
-		$sql.= ' fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc, fk_unit)';
2840
-        $sql.= " VALUES (".$this->fk_supplier_proposal.",";
2841
-        $sql.= " ".($this->fk_parent_line>0?"'".$this->db->escape($this->fk_parent_line)."'":"null").",";
2842
-        $sql.= " ".(! empty($this->label)?"'".$this->db->escape($this->label)."'":"null").",";
2843
-        $sql.= " '".$this->db->escape($this->desc)."',";
2844
-        $sql.= " ".($this->fk_product?"'".$this->db->escape($this->fk_product)."'":"null").",";
2845
-        $sql.= " '".$this->db->escape($this->product_type)."',";
2846
-        $sql.= " ".($this->fk_remise_except?"'".$this->db->escape($this->fk_remise_except)."'":"null").",";
2847
-        $sql.= " ".price2num($this->qty).",";
2848
-        $sql.= " ".price2num($this->tva_tx).",";
2849
-        $sql.= " ".price2num($this->localtax1_tx).",";
2850
-        $sql.= " ".price2num($this->localtax2_tx).",";
2851
-		$sql.= " '".$this->db->escape($this->localtax1_type)."',";
2852
-		$sql.= " '".$this->db->escape($this->localtax2_type)."',";
2853
-        $sql.= " ".(!empty($this->subprice)?price2num($this->subprice):"null").",";
2854
-        $sql.= " ".price2num($this->remise_percent).",";
2855
-        $sql.= " ".(isset($this->info_bits)?"'".$this->db->escape($this->info_bits)."'":"null").",";
2856
-        $sql.= " ".price2num($this->total_ht).",";
2857
-        $sql.= " ".price2num($this->total_tva).",";
2858
-        $sql.= " ".price2num($this->total_localtax1).",";
2859
-        $sql.= " ".price2num($this->total_localtax2).",";
2860
-        $sql.= " ".price2num($this->total_ttc).",";
2861
-        $sql.= " ".(!empty($this->fk_fournprice)?"'".$this->db->escape($this->fk_fournprice)."'":"null").",";
2862
-        $sql.= " ".(isset($this->pa_ht)?"'".price2num($this->pa_ht)."'":"null").",";
2863
-        $sql.= ' '.$this->special_code.',';
2864
-        $sql.= ' '.$this->rang.',';
2865
-        $sql.= " '".$this->db->escape($this->ref_fourn)."'";
2866
-		$sql.= ", ".($this->fk_multicurrency > 0?$this->fk_multicurrency:'null');
2867
-		$sql.= ", '".$this->db->escape($this->multicurrency_code)."'";
2868
-		$sql.= ", ".$this->multicurrency_subprice;
2869
-		$sql.= ", ".$this->multicurrency_total_ht;
2870
-		$sql.= ", ".$this->multicurrency_total_tva;
2871
-		$sql.= ", ".$this->multicurrency_total_ttc;
2872
-        $sql.= ", ".($this->fk_unit?$this->fk_unit:'null');
2873
-		$sql.= ')';
2833
+        $sql .= ' (fk_supplier_proposal, fk_parent_line, label, description, fk_product, product_type,';
2834
+		$sql .= ' fk_remise_except, qty, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,';
2835
+        $sql .= ' subprice, remise_percent, ';
2836
+        $sql .= ' info_bits, ';
2837
+        $sql .= ' total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_product_fournisseur_price, buy_price_ht, special_code, rang,';
2838
+        $sql .= ' ref_fourn,';
2839
+		$sql .= ' fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc, fk_unit)';
2840
+        $sql .= " VALUES (".$this->fk_supplier_proposal.",";
2841
+        $sql .= " ".($this->fk_parent_line > 0 ? "'".$this->db->escape($this->fk_parent_line)."'" : "null").",";
2842
+        $sql .= " ".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null").",";
2843
+        $sql .= " '".$this->db->escape($this->desc)."',";
2844
+        $sql .= " ".($this->fk_product ? "'".$this->db->escape($this->fk_product)."'" : "null").",";
2845
+        $sql .= " '".$this->db->escape($this->product_type)."',";
2846
+        $sql .= " ".($this->fk_remise_except ? "'".$this->db->escape($this->fk_remise_except)."'" : "null").",";
2847
+        $sql .= " ".price2num($this->qty).",";
2848
+        $sql .= " ".price2num($this->tva_tx).",";
2849
+        $sql .= " ".price2num($this->localtax1_tx).",";
2850
+        $sql .= " ".price2num($this->localtax2_tx).",";
2851
+		$sql .= " '".$this->db->escape($this->localtax1_type)."',";
2852
+		$sql .= " '".$this->db->escape($this->localtax2_type)."',";
2853
+        $sql .= " ".(!empty($this->subprice) ?price2num($this->subprice) : "null").",";
2854
+        $sql .= " ".price2num($this->remise_percent).",";
2855
+        $sql .= " ".(isset($this->info_bits) ? "'".$this->db->escape($this->info_bits)."'" : "null").",";
2856
+        $sql .= " ".price2num($this->total_ht).",";
2857
+        $sql .= " ".price2num($this->total_tva).",";
2858
+        $sql .= " ".price2num($this->total_localtax1).",";
2859
+        $sql .= " ".price2num($this->total_localtax2).",";
2860
+        $sql .= " ".price2num($this->total_ttc).",";
2861
+        $sql .= " ".(!empty($this->fk_fournprice) ? "'".$this->db->escape($this->fk_fournprice)."'" : "null").",";
2862
+        $sql .= " ".(isset($this->pa_ht) ? "'".price2num($this->pa_ht)."'" : "null").",";
2863
+        $sql .= ' '.$this->special_code.',';
2864
+        $sql .= ' '.$this->rang.',';
2865
+        $sql .= " '".$this->db->escape($this->ref_fourn)."'";
2866
+		$sql .= ", ".($this->fk_multicurrency > 0 ? $this->fk_multicurrency : 'null');
2867
+		$sql .= ", '".$this->db->escape($this->multicurrency_code)."'";
2868
+		$sql .= ", ".$this->multicurrency_subprice;
2869
+		$sql .= ", ".$this->multicurrency_total_ht;
2870
+		$sql .= ", ".$this->multicurrency_total_tva;
2871
+		$sql .= ", ".$this->multicurrency_total_ttc;
2872
+        $sql .= ", ".($this->fk_unit ? $this->fk_unit : 'null');
2873
+		$sql .= ')';
2874 2874
 
2875 2875
         dol_syslog(get_class($this).'::insert', LOG_DEBUG);
2876
-        $resql=$this->db->query($sql);
2876
+        $resql = $this->db->query($sql);
2877 2877
         if ($resql)
2878 2878
         {
2879
-            $this->rowid=$this->db->last_insert_id(MAIN_DB_PREFIX.'supplier_proposaldet');
2880
-			$this->id=$this->rowid;
2879
+            $this->rowid = $this->db->last_insert_id(MAIN_DB_PREFIX.'supplier_proposaldet');
2880
+			$this->id = $this->rowid;
2881 2881
 
2882 2882
             if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
2883 2883
             {
2884
-            	$result=$this->insertExtraFields();
2884
+            	$result = $this->insertExtraFields();
2885 2885
             	if ($result < 0)
2886 2886
             	{
2887 2887
             		$error++;
2888 2888
             	}
2889 2889
             }
2890 2890
 
2891
-            if (! $notrigger)
2891
+            if (!$notrigger)
2892 2892
             {
2893 2893
                 // Call trigger
2894
-                $result=$this->call_trigger('LINESUPPLIER_PROPOSAL_INSERT',$user);
2894
+                $result = $this->call_trigger('LINESUPPLIER_PROPOSAL_INSERT', $user);
2895 2895
                 if ($result < 0)
2896 2896
                 {
2897 2897
                     $this->db->rollback();
@@ -2905,7 +2905,7 @@  discard block
 block discarded – undo
2905 2905
         }
2906 2906
         else
2907 2907
         {
2908
-            $this->error=$this->db->error()." sql=".$sql;
2908
+            $this->error = $this->db->error()." sql=".$sql;
2909 2909
             $this->db->rollback();
2910 2910
             return -1;
2911 2911
         }
@@ -2918,21 +2918,21 @@  discard block
 block discarded – undo
2918 2918
      */
2919 2919
     function delete()
2920 2920
     {
2921
-        global $conf,$langs,$user;
2921
+        global $conf, $langs, $user;
2922 2922
 
2923
-        $error=0;
2923
+        $error = 0;
2924 2924
         $this->db->begin();
2925 2925
 
2926 2926
         $sql = "DELETE FROM ".MAIN_DB_PREFIX."supplier_proposaldet WHERE rowid = ".$this->rowid;
2927 2927
         dol_syslog("SupplierProposalLine::delete", LOG_DEBUG);
2928
-        if ($this->db->query($sql) )
2928
+        if ($this->db->query($sql))
2929 2929
         {
2930 2930
 
2931 2931
         	// Remove extrafields
2932
-        	if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
2932
+        	if ((!$error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
2933 2933
         	{
2934
-        		$this->id=$this->rowid;
2935
-        		$result=$this->deleteExtraFields();
2934
+        		$this->id = $this->rowid;
2935
+        		$result = $this->deleteExtraFields();
2936 2936
         		if ($result < 0)
2937 2937
         		{
2938 2938
         			$error++;
@@ -2941,7 +2941,7 @@  discard block
 block discarded – undo
2941 2941
         	}
2942 2942
 
2943 2943
             // Call trigger
2944
-            $result=$this->call_trigger('LINESUPPLIER_PROPOSAL_DELETE',$user);
2944
+            $result = $this->call_trigger('LINESUPPLIER_PROPOSAL_DELETE', $user);
2945 2945
             if ($result < 0)
2946 2946
             {
2947 2947
                 $this->db->rollback();
@@ -2955,7 +2955,7 @@  discard block
 block discarded – undo
2955 2955
         }
2956 2956
         else
2957 2957
         {
2958
-            $this->error=$this->db->error()." sql=".$sql;
2958
+            $this->error = $this->db->error()." sql=".$sql;
2959 2959
             $this->db->rollback();
2960 2960
             return -1;
2961 2961
         }
@@ -2967,33 +2967,33 @@  discard block
 block discarded – undo
2967 2967
      *	@param 	int		$notrigger	1=Does not execute triggers, 0= execute triggers
2968 2968
      *	@return	int					<0 if ko, >0 if ok
2969 2969
      */
2970
-    function update($notrigger=0)
2970
+    function update($notrigger = 0)
2971 2971
     {
2972
-        global $conf,$langs,$user;
2972
+        global $conf, $langs, $user;
2973 2973
 
2974
-        $error=0;
2974
+        $error = 0;
2975 2975
 
2976 2976
         // Clean parameters
2977
-        if (empty($this->tva_tx)) $this->tva_tx=0;
2978
-        if (empty($this->localtax1_tx)) $this->localtax1_tx=0;
2979
-        if (empty($this->localtax2_tx)) $this->localtax2_tx=0;
2980
-        if (empty($this->total_localtax1)) $this->total_localtax1=0;
2981
-        if (empty($this->total_localtax2)) $this->total_localtax2=0;
2982
-		if (empty($this->localtax1_type)) $this->localtax1_type=0;
2983
-		if (empty($this->localtax2_type)) $this->localtax2_type=0;
2984
-        if (empty($this->marque_tx)) $this->marque_tx=0;
2985
-        if (empty($this->marge_tx)) $this->marge_tx=0;
2986
-        if (empty($this->price)) $this->price=0;	// TODO A virer
2987
-        if (empty($this->remise)) $this->remise=0;	// TODO A virer
2988
-        if (empty($this->remise_percent)) $this->remise_percent=0;
2989
-        if (empty($this->info_bits)) $this->info_bits=0;
2990
-        if (empty($this->special_code)) $this->special_code=0;
2991
-        if (empty($this->fk_parent_line)) $this->fk_parent_line=0;
2992
-        if (empty($this->fk_fournprice)) $this->fk_fournprice=0;
2993
-        if (empty($this->fk_unit)) $this->fk_unit=0;
2994
-        if (empty($this->subprice)) $this->subprice=0;
2995
-
2996
-		if (empty($this->pa_ht)) $this->pa_ht=0;
2977
+        if (empty($this->tva_tx)) $this->tva_tx = 0;
2978
+        if (empty($this->localtax1_tx)) $this->localtax1_tx = 0;
2979
+        if (empty($this->localtax2_tx)) $this->localtax2_tx = 0;
2980
+        if (empty($this->total_localtax1)) $this->total_localtax1 = 0;
2981
+        if (empty($this->total_localtax2)) $this->total_localtax2 = 0;
2982
+		if (empty($this->localtax1_type)) $this->localtax1_type = 0;
2983
+		if (empty($this->localtax2_type)) $this->localtax2_type = 0;
2984
+        if (empty($this->marque_tx)) $this->marque_tx = 0;
2985
+        if (empty($this->marge_tx)) $this->marge_tx = 0;
2986
+        if (empty($this->price)) $this->price = 0; // TODO A virer
2987
+        if (empty($this->remise)) $this->remise = 0; // TODO A virer
2988
+        if (empty($this->remise_percent)) $this->remise_percent = 0;
2989
+        if (empty($this->info_bits)) $this->info_bits = 0;
2990
+        if (empty($this->special_code)) $this->special_code = 0;
2991
+        if (empty($this->fk_parent_line)) $this->fk_parent_line = 0;
2992
+        if (empty($this->fk_fournprice)) $this->fk_fournprice = 0;
2993
+        if (empty($this->fk_unit)) $this->fk_unit = 0;
2994
+        if (empty($this->subprice)) $this->subprice = 0;
2995
+
2996
+		if (empty($this->pa_ht)) $this->pa_ht = 0;
2997 2997
 
2998 2998
 		// if buy price not defined, define buyprice as configured in margin admin
2999 2999
 		if ($this->pa_ht == 0)
@@ -3012,62 +3012,62 @@  discard block
 block discarded – undo
3012 3012
 
3013 3013
         // Mise a jour ligne en base
3014 3014
         $sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposaldet SET";
3015
-        $sql.= " description='".$this->db->escape($this->desc)."'";
3016
-        $sql.= " , label=".(! empty($this->label)?"'".$this->db->escape($this->label)."'":"null");
3017
-        $sql.= " , product_type=".$this->product_type;
3018
-        $sql.= " , tva_tx='".price2num($this->tva_tx)."'";
3019
-        $sql.= " , localtax1_tx=".price2num($this->localtax1_tx);
3020
-        $sql.= " , localtax2_tx=".price2num($this->localtax2_tx);
3021
-		$sql.= " , localtax1_type='".$this->db->escape($this->localtax1_type)."'";
3022
-		$sql.= " , localtax2_type='".$this->db->escape($this->localtax2_type)."'";
3023
-        $sql.= " , qty='".price2num($this->qty)."'";
3024
-        $sql.= " , subprice=".price2num($this->subprice)."";
3025
-        $sql.= " , remise_percent=".price2num($this->remise_percent)."";
3026
-        $sql.= " , price=".price2num($this->price)."";					// TODO A virer
3027
-        $sql.= " , remise=".price2num($this->remise)."";				// TODO A virer
3028
-        $sql.= " , info_bits='".$this->db->escape($this->info_bits)."'";
3015
+        $sql .= " description='".$this->db->escape($this->desc)."'";
3016
+        $sql .= " , label=".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null");
3017
+        $sql .= " , product_type=".$this->product_type;
3018
+        $sql .= " , tva_tx='".price2num($this->tva_tx)."'";
3019
+        $sql .= " , localtax1_tx=".price2num($this->localtax1_tx);
3020
+        $sql .= " , localtax2_tx=".price2num($this->localtax2_tx);
3021
+		$sql .= " , localtax1_type='".$this->db->escape($this->localtax1_type)."'";
3022
+		$sql .= " , localtax2_type='".$this->db->escape($this->localtax2_type)."'";
3023
+        $sql .= " , qty='".price2num($this->qty)."'";
3024
+        $sql .= " , subprice=".price2num($this->subprice)."";
3025
+        $sql .= " , remise_percent=".price2num($this->remise_percent)."";
3026
+        $sql .= " , price=".price2num($this->price).""; // TODO A virer
3027
+        $sql .= " , remise=".price2num($this->remise).""; // TODO A virer
3028
+        $sql .= " , info_bits='".$this->db->escape($this->info_bits)."'";
3029 3029
         if (empty($this->skip_update_total))
3030 3030
         {
3031
-            $sql.= " , total_ht=".price2num($this->total_ht)."";
3032
-            $sql.= " , total_tva=".price2num($this->total_tva)."";
3033
-            $sql.= " , total_ttc=".price2num($this->total_ttc)."";
3034
-            $sql.= " , total_localtax1=".price2num($this->total_localtax1)."";
3035
-            $sql.= " , total_localtax2=".price2num($this->total_localtax2)."";
3031
+            $sql .= " , total_ht=".price2num($this->total_ht)."";
3032
+            $sql .= " , total_tva=".price2num($this->total_tva)."";
3033
+            $sql .= " , total_ttc=".price2num($this->total_ttc)."";
3034
+            $sql .= " , total_localtax1=".price2num($this->total_localtax1)."";
3035
+            $sql .= " , total_localtax2=".price2num($this->total_localtax2)."";
3036 3036
         }
3037
-		$sql.= " , fk_product_fournisseur_price=".(! empty($this->fk_fournprice)?"'".$this->db->escape($this->fk_fournprice)."'":"null");
3038
-		$sql.= " , buy_price_ht=".price2num($this->pa_ht);
3039
-        if (strlen($this->special_code)) $sql.= " , special_code=".$this->special_code;
3040
-        $sql.= " , fk_parent_line=".($this->fk_parent_line>0?$this->fk_parent_line:"null");
3041
-        if (! empty($this->rang)) $sql.= ", rang=".$this->rang;
3042
-        $sql.= " , ref_fourn=".(! empty($this->ref_fourn)?"'".$this->db->escape($this->ref_fourn)."'":"null");
3043
-        $sql.= " , fk_unit=".($this->fk_unit?$this->fk_unit:'null');
3037
+		$sql .= " , fk_product_fournisseur_price=".(!empty($this->fk_fournprice) ? "'".$this->db->escape($this->fk_fournprice)."'" : "null");
3038
+		$sql .= " , buy_price_ht=".price2num($this->pa_ht);
3039
+        if (strlen($this->special_code)) $sql .= " , special_code=".$this->special_code;
3040
+        $sql .= " , fk_parent_line=".($this->fk_parent_line > 0 ? $this->fk_parent_line : "null");
3041
+        if (!empty($this->rang)) $sql .= ", rang=".$this->rang;
3042
+        $sql .= " , ref_fourn=".(!empty($this->ref_fourn) ? "'".$this->db->escape($this->ref_fourn)."'" : "null");
3043
+        $sql .= " , fk_unit=".($this->fk_unit ? $this->fk_unit : 'null');
3044 3044
 
3045 3045
 		// Multicurrency
3046
-		$sql.= " , multicurrency_subprice=".price2num($this->multicurrency_subprice)."";
3047
-        $sql.= " , multicurrency_total_ht=".price2num($this->multicurrency_total_ht)."";
3048
-        $sql.= " , multicurrency_total_tva=".price2num($this->multicurrency_total_tva)."";
3049
-        $sql.= " , multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc)."";
3046
+		$sql .= " , multicurrency_subprice=".price2num($this->multicurrency_subprice)."";
3047
+        $sql .= " , multicurrency_total_ht=".price2num($this->multicurrency_total_ht)."";
3048
+        $sql .= " , multicurrency_total_tva=".price2num($this->multicurrency_total_tva)."";
3049
+        $sql .= " , multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc)."";
3050 3050
 
3051
-		$sql.= " WHERE rowid = ".$this->rowid;
3051
+		$sql .= " WHERE rowid = ".$this->rowid;
3052 3052
 
3053 3053
         dol_syslog(get_class($this)."::update", LOG_DEBUG);
3054
-        $resql=$this->db->query($sql);
3054
+        $resql = $this->db->query($sql);
3055 3055
         if ($resql)
3056 3056
         {
3057 3057
         	if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
3058 3058
         	{
3059
-        		$this->id=$this->rowid;
3060
-        		$result=$this->insertExtraFields();
3059
+        		$this->id = $this->rowid;
3060
+        		$result = $this->insertExtraFields();
3061 3061
         		if ($result < 0)
3062 3062
         		{
3063 3063
         			$error++;
3064 3064
         		}
3065 3065
         	}
3066 3066
 
3067
-            if (! $notrigger)
3067
+            if (!$notrigger)
3068 3068
             {
3069 3069
                 // Call trigger
3070
-                $result=$this->call_trigger('LINESUPPLIER_PROPOSAL_UPDATE',$user);
3070
+                $result = $this->call_trigger('LINESUPPLIER_PROPOSAL_UPDATE', $user);
3071 3071
                 if ($result < 0)
3072 3072
                 {
3073 3073
                     $this->db->rollback();
@@ -3081,7 +3081,7 @@  discard block
 block discarded – undo
3081 3081
         }
3082 3082
         else
3083 3083
         {
3084
-            $this->error=$this->db->error();
3084
+            $this->error = $this->db->error();
3085 3085
             $this->db->rollback();
3086 3086
             return -2;
3087 3087
         }
@@ -3099,14 +3099,14 @@  discard block
 block discarded – undo
3099 3099
 
3100 3100
         // Mise a jour ligne en base
3101 3101
         $sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposaldet SET";
3102
-        $sql.= " total_ht=".price2num($this->total_ht,'MT')."";
3103
-        $sql.= ",total_tva=".price2num($this->total_tva,'MT')."";
3104
-        $sql.= ",total_ttc=".price2num($this->total_ttc,'MT')."";
3105
-        $sql.= " WHERE rowid = ".$this->rowid;
3102
+        $sql .= " total_ht=".price2num($this->total_ht, 'MT')."";
3103
+        $sql .= ",total_tva=".price2num($this->total_tva, 'MT')."";
3104
+        $sql .= ",total_ttc=".price2num($this->total_ttc, 'MT')."";
3105
+        $sql .= " WHERE rowid = ".$this->rowid;
3106 3106
 
3107 3107
         dol_syslog("SupplierProposalLine::update_total", LOG_DEBUG);
3108 3108
 
3109
-        $resql=$this->db->query($sql);
3109
+        $resql = $this->db->query($sql);
3110 3110
         if ($resql)
3111 3111
         {
3112 3112
             $this->db->commit();
@@ -3114,7 +3114,7 @@  discard block
 block discarded – undo
3114 3114
         }
3115 3115
         else
3116 3116
         {
3117
-            $this->error=$this->db->error();
3117
+            $this->error = $this->db->error();
3118 3118
             $this->db->rollback();
3119 3119
             return -2;
3120 3120
         }
Please login to merge, or discard this patch.
Braces   +377 added lines, -218 removed lines patch added patch discarded remove patch
@@ -213,7 +213,9 @@  discard block
 block discarded – undo
213 213
     {
214 214
         global $conf, $mysoc;
215 215
 
216
-        if (! $qty) $qty = 1;
216
+        if (! $qty) {
217
+        	$qty = 1;
218
+        }
217 219
 
218 220
         dol_syslog(get_class($this)."::add_product $idproduct, $qty, $remise_percent");
219 221
         if ($idproduct > 0)
@@ -225,7 +227,9 @@  discard block
 block discarded – undo
225 227
 
226 228
             $tva_tx = get_default_tva($mysoc,$this->thirdparty,$prod->id);
227 229
             $tva_npr = get_default_npr($mysoc,$this->thirdparty,$prod->id);
228
-            if (empty($tva_tx)) $tva_npr=0;
230
+            if (empty($tva_tx)) {
231
+            	$tva_npr=0;
232
+            }
229 233
             $localtax1_tx = get_localtax($tva_tx,1,$mysoc,$this->thirdparty,$tva_npr);
230 234
             $localtax2_tx = get_localtax($tva_tx,2,$mysoc,$this->thirdparty,$tva_npr);
231 235
 
@@ -233,8 +237,7 @@  discard block
 block discarded – undo
233 237
             if($conf->global->PRODUIT_MULTIPRICES && $this->thirdparty->price_level)
234 238
             {
235 239
                 $price = $prod->multiprices[$this->thirdparty->price_level];
236
-            }
237
-            else
240
+            } else
238 241
             {
239 242
                 $price = $prod->price;
240 243
             }
@@ -272,9 +275,11 @@  discard block
 block discarded – undo
272 275
 
273 276
         if ($result > 0)
274 277
         {
275
-            if ($remise->fk_facture)	// Protection against multiple submission
278
+            if ($remise->fk_facture) {
279
+            	// Protection against multiple submission
276 280
             {
277 281
                 $this->error=$langs->trans("ErrorDiscountAlreadyUsed");
282
+            }
278 283
                 $this->db->rollback();
279 284
                 return -5;
280 285
             }
@@ -307,21 +312,18 @@  discard block
 block discarded – undo
307 312
                 {
308 313
                     $this->db->commit();
309 314
                     return 1;
310
-                }
311
-                else
315
+                } else
312 316
                 {
313 317
                     $this->db->rollback();
314 318
                     return -1;
315 319
                 }
316
-            }
317
-            else
320
+            } else
318 321
             {
319 322
                 $this->error=$supplier_proposalligne->error;
320 323
                 $this->db->rollback();
321 324
                 return -2;
322 325
             }
323
-        }
324
-        else
326
+        } else
325 327
         {
326 328
             $this->db->rollback();
327 329
             return -2;
@@ -370,11 +372,21 @@  discard block
 block discarded – undo
370 372
         include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
371 373
 
372 374
         // Clean parameters
373
-        if (empty($remise_percent)) $remise_percent=0;
374
-        if (empty($qty)) $qty=0;
375
-        if (empty($info_bits)) $info_bits=0;
376
-        if (empty($rang)) $rang=0;
377
-        if (empty($fk_parent_line) || $fk_parent_line < 0) $fk_parent_line=0;
375
+        if (empty($remise_percent)) {
376
+        	$remise_percent=0;
377
+        }
378
+        if (empty($qty)) {
379
+        	$qty=0;
380
+        }
381
+        if (empty($info_bits)) {
382
+        	$info_bits=0;
383
+        }
384
+        if (empty($rang)) {
385
+        	$rang=0;
386
+        }
387
+        if (empty($fk_parent_line) || $fk_parent_line < 0) {
388
+        	$fk_parent_line=0;
389
+        }
378 390
 
379 391
         $remise_percent=price2num($remise_percent);
380 392
         $qty=price2num($qty);
@@ -387,14 +399,15 @@  discard block
 block discarded – undo
387 399
         if ($price_base_type=='HT')
388 400
         {
389 401
             $pu=$pu_ht;
390
-        }
391
-        else
402
+        } else
392 403
         {
393 404
             $pu=$pu_ttc;
394 405
         }
395 406
 
396 407
         // Check parameters
397
-        if ($type < 0) return -1;
408
+        if ($type < 0) {
409
+        	return -1;
410
+        }
398 411
 
399 412
         if ($this->statut == 0)
400 413
         {
@@ -489,7 +502,9 @@  discard block
 block discarded – undo
489 502
             $this->line->multicurrency_total_ttc 	= $multicurrency_total_ttc;
490 503
 
491 504
             // Mise en option de la ligne
492
-            if (empty($qty) && empty($special_code)) $this->line->special_code=3;
505
+            if (empty($qty) && empty($special_code)) {
506
+            	$this->line->special_code=3;
507
+            }
493 508
 
494 509
             // TODO deprecated
495 510
             $this->line->price=$price;
@@ -503,7 +518,9 @@  discard block
 block discarded – undo
503 518
             if ($result > 0)
504 519
             {
505 520
                 // Reorder if child line
506
-                if (! empty($fk_parent_line)) $this->line_order(true,'DESC');
521
+                if (! empty($fk_parent_line)) {
522
+                	$this->line_order(true,'DESC');
523
+                }
507 524
 
508 525
                 // Mise a jour informations denormalisees au niveau de la propale meme
509 526
                 $result=$this->update_price(1,'auto',0,$this->thirdparty);	// This method is designed to add line from user input so total calculation must be done using 'auto' mode.
@@ -511,15 +528,13 @@  discard block
 block discarded – undo
511 528
                 {
512 529
                     $this->db->commit();
513 530
                     return $this->line->rowid;
514
-                }
515
-                else
531
+                } else
516 532
                 {
517 533
                     $this->error=$this->db->error();
518 534
                     $this->db->rollback();
519 535
                     return -1;
520 536
                 }
521
-            }
522
-            else
537
+            } else
523 538
             {
524 539
                 $this->error=$this->line->error;
525 540
                 $this->db->rollback();
@@ -569,8 +584,14 @@  discard block
 block discarded – undo
569 584
         $txlocaltax1=price2num($txlocaltax1);
570 585
         $txlocaltax2=price2num($txlocaltax2);
571 586
     	$pa_ht=price2num($pa_ht);
572
-        if (empty($qty) && empty($special_code)) $special_code=3;    // Set option tag
573
-        if (! empty($qty) && $special_code == 3) $special_code=0;    // Remove option tag
587
+        if (empty($qty) && empty($special_code)) {
588
+        	$special_code=3;
589
+        }
590
+        // Set option tag
591
+        if (! empty($qty) && $special_code == 3) {
592
+        	$special_code=0;
593
+        }
594
+        // Remove option tag
574 595
 
575 596
         if ($this->statut == 0)
576 597
         {
@@ -673,7 +694,9 @@  discard block
 block discarded – undo
673 694
             if ($result > 0)
674 695
             {
675 696
                 // Reorder if child line
676
-                if (! empty($fk_parent_line)) $this->line_order(true,'DESC');
697
+                if (! empty($fk_parent_line)) {
698
+                	$this->line_order(true,'DESC');
699
+                }
677 700
 
678 701
                 $this->update_price(1);
679 702
 
@@ -682,15 +705,13 @@  discard block
 block discarded – undo
682 705
 
683 706
                 $this->db->commit();
684 707
                 return $result;
685
-            }
686
-            else
708
+            } else
687 709
             {
688 710
                 $this->error=$this->db->error();
689 711
                 $this->db->rollback();
690 712
                 return -1;
691 713
             }
692
-        }
693
-        else
714
+        } else
694 715
         {
695 716
             dol_syslog(get_class($this)."::updateline Erreur -2 SupplierProposal en mode incompatible pour cette action");
696 717
             return -2;
@@ -718,13 +739,11 @@  discard block
 block discarded – undo
718 739
                 $this->update_price(1);
719 740
 
720 741
                 return 1;
721
-            }
722
-            else
742
+            } else
723 743
             {
724 744
                 return -1;
725 745
             }
726
-        }
727
-        else
746
+        } else
728 747
         {
729 748
             return -2;
730 749
         }
@@ -758,9 +777,12 @@  discard block
 block discarded – undo
758 777
         }
759 778
 
760 779
         // Check parameters
761
-		if (! empty($this->ref))	// We check that ref is not already used
780
+		if (! empty($this->ref)) {
781
+			// We check that ref is not already used
762 782
 		{
763
-			$result=self::isExistingObject($this->element, 0, $this->ref);	// Check ref is not yet used
783
+			$result=self::isExistingObject($this->element, 0, $this->ref);
784
+		}
785
+		// Check ref is not yet used
764 786
 			if ($result > 0)
765 787
 			{
766 788
 				$this->error='ErrorRefAlreadyExists';
@@ -771,7 +793,9 @@  discard block
 block discarded – undo
771 793
 		}
772 794
 
773 795
 		// Multicurrency
774
-		if (!empty($this->multicurrency_code)) list($this->fk_multicurrency,$this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code);
796
+		if (!empty($this->multicurrency_code)) {
797
+			list($this->fk_multicurrency,$this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code);
798
+		}
775 799
 		if (empty($this->fk_multicurrency))
776 800
 		{
777 801
 			$this->multicurrency_code = $conf->currency;
@@ -846,7 +870,9 @@  discard block
 block discarded – undo
846 870
 
847 871
                 dol_syslog(get_class($this)."::create", LOG_DEBUG);
848 872
                 $resql=$this->db->query($sql);
849
-                if (! $resql) $error++;
873
+                if (! $resql) {
874
+                	$error++;
875
+                }
850 876
 
851 877
                 /*
852 878
                  *  Insertion du detail des produits dans la base
@@ -907,7 +933,9 @@  discard block
 block discarded – undo
907 933
                 if (! $error && $this->origin && $this->origin_id)
908 934
                 {
909 935
                     $ret = $this->add_object_linked();
910
-                    if (! $ret)	dol_print_error($this->db);
936
+                    if (! $ret) {
937
+                    	dol_print_error($this->db);
938
+                    }
911 939
                 }
912 940
 
913 941
                 if (! $error)
@@ -924,16 +952,19 @@  discard block
 block discarded – undo
924 952
                     	$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
925 953
                     	if (empty($reshook))
926 954
                     	{
927
-                    		if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
955
+                    		if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
956
+                    			// For avoid conflicts if trigger used
928 957
                     		{
929 958
                     			$result=$this->insertExtraFields();
959
+                    		}
930 960
                     			if ($result < 0)
931 961
                     			{
932 962
                     				$error++;
933 963
                     			}
934 964
                     		}
965
+                    	} else if ($reshook < 0) {
966
+                    		$error++;
935 967
                     	}
936
-                    	else if ($reshook < 0) $error++;
937 968
 
938 969
                         if (! $notrigger)
939 970
                         {
@@ -942,15 +973,13 @@  discard block
 block discarded – undo
942 973
                             if ($result < 0) { $error++; }
943 974
                             // End call triggers
944 975
                         }
945
-                    }
946
-                    else
976
+                    } else
947 977
 					{
948 978
                         $this->error=$this->db->lasterror();
949 979
                         $error++;
950 980
                     }
951 981
                 }
952
-            }
953
-            else
982
+            } else
954 983
 			{
955 984
                 $this->error=$this->db->lasterror();
956 985
                 $error++;
@@ -961,14 +990,12 @@  discard block
 block discarded – undo
961 990
                 $this->db->commit();
962 991
                 dol_syslog(get_class($this)."::create done id=".$this->id);
963 992
                 return $this->id;
964
-            }
965
-            else
993
+            } else
966 994
             {
967 995
                 $this->db->rollback();
968 996
                 return -2;
969 997
             }
970
-        }
971
-        else
998
+        } else
972 999
         {
973 1000
             $this->error=$this->db->lasterror();
974 1001
             $this->db->rollback();
@@ -1007,8 +1034,9 @@  discard block
 block discarded – undo
1007 1034
         $this->db->begin();
1008 1035
 
1009 1036
 		// get extrafields so they will be clone
1010
-		foreach($this->lines as $line)
1011
-			$line->fetch_optionals($line->rowid);
1037
+		foreach($this->lines as $line) {
1038
+					$line->fetch_optionals($line->rowid);
1039
+		}
1012 1040
 
1013 1041
 		// Load source object
1014 1042
 		$objFrom = clone $this;
@@ -1027,8 +1055,7 @@  discard block
 block discarded – undo
1027 1055
             }
1028 1056
 
1029 1057
             // TODO Change product price if multi-prices
1030
-        }
1031
-        else
1058
+        } else
1032 1059
         {
1033 1060
             $objsoc->fetch($this->socid);
1034 1061
         }
@@ -1055,7 +1082,9 @@  discard block
 block discarded – undo
1055 1082
 
1056 1083
         // Create clone
1057 1084
         $result=$this->create($user);
1058
-        if ($result < 0) $error++;
1085
+        if ($result < 0) {
1086
+        	$error++;
1087
+        }
1059 1088
 
1060 1089
         if (! $error)
1061 1090
         {
@@ -1065,7 +1094,9 @@  discard block
 block discarded – undo
1065 1094
                 $parameters=array('objFrom'=>$objFrom);
1066 1095
                 $action='';
1067 1096
                 $reshook=$hookmanager->executeHooks('createFrom',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
1068
-                if ($reshook < 0) $error++;
1097
+                if ($reshook < 0) {
1098
+                	$error++;
1099
+                }
1069 1100
             }
1070 1101
 
1071 1102
             // Call trigger
@@ -1079,8 +1110,7 @@  discard block
 block discarded – undo
1079 1110
         {
1080 1111
             $this->db->commit();
1081 1112
             return $this->id;
1082
-        }
1083
-        else
1113
+        } else
1084 1114
         {
1085 1115
             $this->db->rollback();
1086 1116
             return -1;
@@ -1120,8 +1150,11 @@  discard block
 block discarded – undo
1120 1150
         $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON p.fk_cond_reglement = cr.rowid AND cr.entity IN (' . getEntity('c_payment_term').')';
1121 1151
         $sql.= " WHERE p.fk_statut = c.id";
1122 1152
         $sql.= " AND p.entity = ".$conf->entity;
1123
-        if ($ref) $sql.= " AND p.ref='".$ref."'";
1124
-        else $sql.= " AND p.rowid=".$rowid;
1153
+        if ($ref) {
1154
+        	$sql.= " AND p.ref='".$ref."'";
1155
+        } else {
1156
+        	$sql.= " AND p.rowid=".$rowid;
1157
+        }
1125 1158
 
1126 1159
         dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
1127 1160
         $resql=$this->db->query($sql);
@@ -1277,8 +1310,7 @@  discard block
 block discarded – undo
1277 1310
                         $i++;
1278 1311
                     }
1279 1312
                     $this->db->free($result);
1280
-                }
1281
-                else
1313
+                } else
1282 1314
                 {
1283 1315
                     $this->error=$this->db->error();
1284 1316
                     return -1;
@@ -1296,8 +1328,7 @@  discard block
 block discarded – undo
1296 1328
 
1297 1329
             $this->error="Record Not Found";
1298 1330
             return 0;
1299
-        }
1300
-        else
1331
+        } else
1301 1332
         {
1302 1333
             $this->error=$this->db->error();
1303 1334
             return -1;
@@ -1320,22 +1351,24 @@  discard block
 block discarded – undo
1320 1351
     	$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
1321 1352
     	if (empty($reshook))
1322 1353
     	{
1323
-    		if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
1354
+    		if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
1355
+    			// For avoid conflicts if trigger used
1324 1356
     		{
1325 1357
     			$result=$this->insertExtraFields();
1358
+    		}
1326 1359
     			if ($result < 0)
1327 1360
     			{
1328 1361
     				$error++;
1329 1362
     			}
1330 1363
     		}
1364
+    	} else if ($reshook < 0) {
1365
+    		$error++;
1331 1366
     	}
1332
-    	else if ($reshook < 0) $error++;
1333 1367
 
1334 1368
 		if (!$error)
1335 1369
 	    {
1336 1370
 	    	return 1;
1337
-	    }
1338
-	    else
1371
+	    } else
1339 1372
 	    {
1340 1373
 	    	return -1;
1341 1374
 	    }
@@ -1368,11 +1401,12 @@  discard block
 block discarded – undo
1368 1401
             $soc->fetch($this->socid);
1369 1402
 
1370 1403
             // Define new ref
1371
-            if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life
1404
+            if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) {
1405
+            	// empty should not happened, but when it occurs, the test save life
1372 1406
             {
1373 1407
             	$num = $this->getNextNumRef($soc);
1374 1408
             }
1375
-            else
1409
+            } else
1376 1410
             {
1377 1411
             	$num = $this->ref;
1378 1412
             }
@@ -1442,8 +1476,7 @@  discard block
 block discarded – undo
1442 1476
 
1443 1477
             	$this->db->commit();
1444 1478
             	return 1;
1445
-            }
1446
-            else
1479
+            } else
1447 1480
 			{
1448 1481
             	$this->db->rollback();
1449 1482
             	return -1;
@@ -1470,8 +1503,7 @@  discard block
 block discarded – undo
1470 1503
             {
1471 1504
                 $this->date_livraison = $date_livraison;
1472 1505
                 return 1;
1473
-            }
1474
-            else
1506
+            } else
1475 1507
             {
1476 1508
                 $this->error=$this->db->error();
1477 1509
                 dol_syslog(get_class($this)."::set_date_livraison Erreur SQL");
@@ -1503,8 +1535,7 @@  discard block
 block discarded – undo
1503 1535
                 $this->remise_percent = $remise;
1504 1536
                 $this->update_price(1);
1505 1537
                 return 1;
1506
-            }
1507
-            else
1538
+            } else
1508 1539
             {
1509 1540
                 $this->error=$this->db->error();
1510 1541
                 return -1;
@@ -1537,8 +1568,7 @@  discard block
 block discarded – undo
1537 1568
                 $this->remise_absolue = $remise;
1538 1569
                 $this->update_price(1);
1539 1570
                 return 1;
1540
-            }
1541
-            else
1571
+            } else
1542 1572
             {
1543 1573
                 $this->error=$this->db->error();
1544 1574
                 return -1;
@@ -1566,7 +1596,9 @@  discard block
 block discarded – undo
1566 1596
 
1567 1597
         $sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal";
1568 1598
         $sql.= " SET fk_statut = ".$this->statut.",";
1569
-		if (! empty($note)) $sql.= " note_private = '".$this->db->escape($note)."',";
1599
+		if (! empty($note)) {
1600
+			$sql.= " note_private = '".$this->db->escape($note)."',";
1601
+		}
1570 1602
         $sql.= " date_cloture=NULL, fk_user_cloture=NULL";
1571 1603
         $sql.= " WHERE rowid = ".$this->id;
1572 1604
 
@@ -1601,8 +1633,7 @@  discard block
 block discarded – undo
1601 1633
 		    }
1602 1634
 			$this->db->rollback();
1603 1635
 			return -1*$error;
1604
-		}
1605
-		else
1636
+		} else
1606 1637
 		{
1607 1638
 			$this->db->commit();
1608 1639
 			return 1;
@@ -1643,10 +1674,12 @@  discard block
 block discarded – undo
1643 1674
             	$trigger_name='SUPPLIER_PROPOSAL_CLOSE_SIGNED';
1644 1675
 				$modelpdf=$conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL?$conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL:$this->modelpdf;
1645 1676
 
1646
-                if (! empty($conf->global->SUPPLIER_PROPOSAL_UPDATE_PRICE_ON_SUPPlIER_PROPOSAL))     // TODO This option was not tested correctly. Error if product ref does not exists
1677
+                if (! empty($conf->global->SUPPLIER_PROPOSAL_UPDATE_PRICE_ON_SUPPlIER_PROPOSAL)) {
1678
+                	// TODO This option was not tested correctly. Error if product ref does not exists
1647 1679
                 {
1648 1680
                     $result = $this->updateOrCreatePriceFournisseur($user);
1649 1681
                 }
1682
+                }
1650 1683
 
1651 1684
             }
1652 1685
             if ($statut == 4)
@@ -1677,14 +1710,12 @@  discard block
 block discarded – undo
1677 1710
             {
1678 1711
                 $this->db->commit();
1679 1712
                 return 1;
1680
-            }
1681
-            else
1713
+            } else
1682 1714
             {
1683 1715
                 $this->db->rollback();
1684 1716
                 return -1;
1685 1717
             }
1686
-        }
1687
-        else
1718
+        } else
1688 1719
         {
1689 1720
             $this->error=$this->db->lasterror();
1690 1721
             $this->errors[]=$this->db->lasterror();
@@ -1706,7 +1737,9 @@  discard block
 block discarded – undo
1706 1737
 		dol_syslog(get_class($this)."::updateOrCreatePriceFournisseur", LOG_DEBUG);
1707 1738
 		foreach ($this->lines as $product)
1708 1739
 		{
1709
-			if ($product->subprice <= 0) continue;
1740
+			if ($product->subprice <= 0) {
1741
+				continue;
1742
+			}
1710 1743
 
1711 1744
 			$idProductFourn = $productsupplier->find_min_price_product_fournisseur($product->fk_product, $product->qty);
1712 1745
 			$res = $productsupplier->fetch($idProductFourn);
@@ -1801,8 +1834,7 @@  discard block
 block discarded – undo
1801 1834
             $this->statut = 0;
1802 1835
             $this->brouillon = 1;
1803 1836
             return 1;
1804
-        }
1805
-        else
1837
+        } else
1806 1838
         {
1807 1839
             return -1;
1808 1840
         }
@@ -1831,19 +1863,31 @@  discard block
 block discarded – undo
1831 1863
         $sql = "SELECT s.rowid, s.nom as name, s.client,";
1832 1864
         $sql.= " p.rowid as supplier_proposalid, p.fk_statut, p.total_ht, p.ref, p.remise, ";
1833 1865
         $sql.= " p.datep as dp, p.fin_validite as datelimite";
1834
-        if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", sc.fk_soc, sc.fk_user";
1866
+        if (! $user->rights->societe->client->voir && ! $socid) {
1867
+        	$sql .= ", sc.fk_soc, sc.fk_user";
1868
+        }
1835 1869
         $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."supplier_proposal as p, ".MAIN_DB_PREFIX."c_propalst as c";
1836
-		if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1870
+		if (! $user->rights->societe->client->voir && ! $socid) {
1871
+			$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1872
+		}
1837 1873
         $sql.= " WHERE p.entity = ".$conf->entity;
1838 1874
         $sql.= " AND p.fk_soc = s.rowid";
1839 1875
         $sql.= " AND p.fk_statut = c.id";
1840
-        if (! $user->rights->societe->client->voir && ! $socid) //restriction
1876
+        if (! $user->rights->societe->client->voir && ! $socid) {
1877
+        	//restriction
1841 1878
         {
1842 1879
         	$sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
1843 1880
         }
1844
-        if ($socid) $sql.= " AND s.rowid = ".$socid;
1845
-        if ($draft)	$sql.= " AND p.fk_statut = 0";
1846
-        if ($notcurrentuser > 0) $sql.= " AND p.fk_user_author <> ".$user->id;
1881
+        }
1882
+        if ($socid) {
1883
+        	$sql.= " AND s.rowid = ".$socid;
1884
+        }
1885
+        if ($draft) {
1886
+        	$sql.= " AND p.fk_statut = 0";
1887
+        }
1888
+        if ($notcurrentuser > 0) {
1889
+        	$sql.= " AND p.fk_user_author <> ".$user->id;
1890
+        }
1847 1891
         $sql.= $this->db->order($sortfield,$sortorder);
1848 1892
         $sql.= $this->db->plimit($limit,$offset);
1849 1893
 
@@ -1861,12 +1905,10 @@  discard block
 block discarded – undo
1861 1905
                     if ($shortlist == 1)
1862 1906
                     {
1863 1907
                         $ga[$obj->supplier_proposalid] = $obj->ref;
1864
-                    }
1865
-                    else if ($shortlist == 2)
1908
+                    } else if ($shortlist == 2)
1866 1909
                     {
1867 1910
                         $ga[$obj->supplier_proposalid] = $obj->ref.' ('.$obj->name.')';
1868
-                    }
1869
-                    else
1911
+                    } else
1870 1912
 					{
1871 1913
                         $ga[$i]['id']	= $obj->supplier_proposalid;
1872 1914
                         $ga[$i]['ref'] 	= $obj->ref;
@@ -1877,8 +1919,7 @@  discard block
 block discarded – undo
1877 1919
                 }
1878 1920
             }
1879 1921
             return $ga;
1880
-        }
1881
-        else
1922
+        } else
1882 1923
         {
1883 1924
             dol_print_error($this->db);
1884 1925
             return -1;
@@ -1919,7 +1960,9 @@  discard block
 block discarded – undo
1919 1960
                 {
1920 1961
                     // Delete linked object
1921 1962
                     $res = $this->deleteObjectLinked();
1922
-                    if ($res < 0) $error++;
1963
+                    if ($res < 0) {
1964
+                    	$error++;
1965
+                    }
1923 1966
 
1924 1967
                     if (! $error)
1925 1968
                     {
@@ -1933,9 +1976,11 @@  discard block
 block discarded – undo
1933 1976
                             {
1934 1977
                                 dol_delete_preview($this);
1935 1978
 
1936
-                                if (! dol_delete_file($file,0,0,0,$this)) // For triggers
1979
+                                if (! dol_delete_file($file,0,0,0,$this)) {
1980
+                                	// For triggers
1937 1981
                                 {
1938 1982
                                     $this->error='ErrorFailToDeleteFile';
1983
+                                }
1939 1984
                                     $this->errors=array('ErrorFailToDeleteFile');
1940 1985
                                 	$this->db->rollback();
1941 1986
                                     return 0;
@@ -1958,9 +2003,11 @@  discard block
 block discarded – undo
1958 2003
                     // Removed extrafields
1959 2004
                     if (! $error)
1960 2005
                     {
1961
-                    	if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
2006
+                    	if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
2007
+                    		// For avoid conflicts if trigger used
1962 2008
                     	{
1963 2009
                     		$result=$this->deleteExtraFields();
2010
+                    	}
1964 2011
                     		if ($result < 0)
1965 2012
                     		{
1966 2013
                     			$error++;
@@ -1975,29 +2022,25 @@  discard block
 block discarded – undo
1975 2022
                         dol_syslog(get_class($this)."::delete ".$this->id." by ".$user->id, LOG_DEBUG);
1976 2023
                         $this->db->commit();
1977 2024
                         return 1;
1978
-                    }
1979
-                    else
2025
+                    } else
1980 2026
                     {
1981 2027
                         $this->error=$this->db->lasterror();
1982 2028
                         $this->db->rollback();
1983 2029
                         return 0;
1984 2030
                     }
1985
-                }
1986
-                else
2031
+                } else
1987 2032
                 {
1988 2033
                     $this->error=$this->db->lasterror();
1989 2034
                     $this->db->rollback();
1990 2035
                     return -3;
1991 2036
                 }
1992
-            }
1993
-            else
2037
+            } else
1994 2038
             {
1995 2039
                 $this->error=$this->db->lasterror();
1996 2040
                 $this->db->rollback();
1997 2041
                 return -2;
1998 2042
             }
1999
-        }
2000
-        else
2043
+        } else
2001 2044
         {
2002 2045
             $this->db->rollback();
2003 2046
             return -1;
@@ -2054,8 +2097,7 @@  discard block
 block discarded – undo
2054 2097
             }
2055 2098
             $this->db->free($result);
2056 2099
 
2057
-        }
2058
-        else
2100
+        } else
2059 2101
         {
2060 2102
             dol_print_error($this->db);
2061 2103
         }
@@ -2085,19 +2127,43 @@  discard block
 block discarded – undo
2085 2127
 		global $langs;
2086 2128
 		$langs->load("supplier_proposal");
2087 2129
 
2088
-		if ($statut==0) $statuttrans='statut0';
2089
-		if ($statut==1) $statuttrans='statut1';
2090
-		if ($statut==2) $statuttrans='statut3';
2091
-		if ($statut==3) $statuttrans='statut5';
2092
-		if ($statut==4) $statuttrans='statut6';
2093
-
2094
-		if ($mode == 0)	return $this->labelstatut[$statut];
2095
-		if ($mode == 1)	return $this->labelstatut_short[$statut];
2096
-		if ($mode == 2)	return img_picto($this->labelstatut[$statut], $statuttrans).' '.$this->labelstatut_short[$statut];
2097
-		if ($mode == 3)	return img_picto($this->labelstatut[$statut], $statuttrans);
2098
-		if ($mode == 4)	return img_picto($this->labelstatut[$statut],$statuttrans).' '.$this->labelstatut[$statut];
2099
-		if ($mode == 5)	return '<span class="hideonsmartphone">'.$this->labelstatut_short[$statut].' </span>'.img_picto($this->labelstatut[$statut],$statuttrans);
2100
-		if ($mode == 6)	return '<span class="hideonsmartphone">'.$this->labelstatut[$statut].' </span>'.img_picto($this->labelstatut[$statut],$statuttrans);
2130
+		if ($statut==0) {
2131
+			$statuttrans='statut0';
2132
+		}
2133
+		if ($statut==1) {
2134
+			$statuttrans='statut1';
2135
+		}
2136
+		if ($statut==2) {
2137
+			$statuttrans='statut3';
2138
+		}
2139
+		if ($statut==3) {
2140
+			$statuttrans='statut5';
2141
+		}
2142
+		if ($statut==4) {
2143
+			$statuttrans='statut6';
2144
+		}
2145
+
2146
+		if ($mode == 0) {
2147
+			return $this->labelstatut[$statut];
2148
+		}
2149
+		if ($mode == 1) {
2150
+			return $this->labelstatut_short[$statut];
2151
+		}
2152
+		if ($mode == 2) {
2153
+			return img_picto($this->labelstatut[$statut], $statuttrans).' '.$this->labelstatut_short[$statut];
2154
+		}
2155
+		if ($mode == 3) {
2156
+			return img_picto($this->labelstatut[$statut], $statuttrans);
2157
+		}
2158
+		if ($mode == 4) {
2159
+			return img_picto($this->labelstatut[$statut],$statuttrans).' '.$this->labelstatut[$statut];
2160
+		}
2161
+		if ($mode == 5) {
2162
+			return '<span class="hideonsmartphone">'.$this->labelstatut_short[$statut].' </span>'.img_picto($this->labelstatut[$statut],$statuttrans);
2163
+		}
2164
+		if ($mode == 6) {
2165
+			return '<span class="hideonsmartphone">'.$this->labelstatut[$statut].' </span>'.img_picto($this->labelstatut[$statut],$statuttrans);
2166
+		}
2101 2167
 	}
2102 2168
 
2103 2169
 
@@ -2126,9 +2192,15 @@  discard block
 block discarded – undo
2126 2192
             $clause = " AND";
2127 2193
         }
2128 2194
         $sql.= $clause." p.entity = ".$conf->entity;
2129
-        if ($mode == 'opened') $sql.= " AND p.fk_statut = 1";
2130
-        if ($mode == 'signed') $sql.= " AND p.fk_statut = 2";
2131
-        if ($user->societe_id) $sql.= " AND p.fk_soc = ".$user->societe_id;
2195
+        if ($mode == 'opened') {
2196
+        	$sql.= " AND p.fk_statut = 1";
2197
+        }
2198
+        if ($mode == 'signed') {
2199
+        	$sql.= " AND p.fk_statut = 2";
2200
+        }
2201
+        if ($user->societe_id) {
2202
+        	$sql.= " AND p.fk_soc = ".$user->societe_id;
2203
+        }
2132 2204
 
2133 2205
         $resql=$this->db->query($sql);
2134 2206
         if ($resql)
@@ -2166,8 +2238,7 @@  discard block
 block discarded – undo
2166 2238
                 // if ($mode == 'signed' && ! count($this->FactureListeArray($obj->rowid))) $this->nbtodolate++;
2167 2239
             }
2168 2240
             return $response;
2169
-        }
2170
-        else
2241
+        } else
2171 2242
         {
2172 2243
             $this->error=$this->db->lasterror();
2173 2244
             return -1;
@@ -2236,8 +2307,7 @@  discard block
 block discarded – undo
2236 2307
                 $line->total_ttc=59.8;
2237 2308
                 $line->total_tva=9.8;
2238 2309
                 $line->remise_percent=50;
2239
-            }
2240
-            else
2310
+            } else
2241 2311
             {
2242 2312
                 $line->total_ht=100;
2243 2313
                 $line->total_ttc=119.6;
@@ -2294,8 +2364,7 @@  discard block
 block discarded – undo
2294 2364
             }
2295 2365
             $this->db->free($resql);
2296 2366
             return 1;
2297
-        }
2298
-        else
2367
+        } else
2299 2368
         {
2300 2369
             dol_print_error($this->db);
2301 2370
             $this->error=$this->db->lasterror();
@@ -2346,14 +2415,12 @@  discard block
 block discarded – undo
2346 2415
             if ($numref != "")
2347 2416
             {
2348 2417
                 return $numref;
2349
-            }
2350
-            else
2418
+            } else
2351 2419
 			{
2352 2420
                 $this->error=$obj->error;
2353 2421
                 return "";
2354 2422
             }
2355
-        }
2356
-        else
2423
+        } else
2357 2424
 		{
2358 2425
             $langs->load("errors");
2359 2426
             print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete");
@@ -2375,22 +2442,30 @@  discard block
 block discarded – undo
2375 2442
     {
2376 2443
         global $langs, $conf, $user;
2377 2444
 
2378
-        if (! empty($conf->dol_no_mouse_hover)) $notooltip=1;   // Force disable tooltips
2445
+        if (! empty($conf->dol_no_mouse_hover)) {
2446
+        	$notooltip=1;
2447
+        }
2448
+        // Force disable tooltips
2379 2449
 
2380 2450
         $url='';
2381 2451
         $result='';
2382 2452
 
2383 2453
         $label='<u>'.$langs->trans("ShowSupplierProposal").'</u>';
2384
-        if (! empty($this->ref))
2385
-        $label.= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
2386
-        if (! empty($this->ref_fourn))
2387
-            $label.= '<br><b>'.$langs->trans('RefSupplier').':</b> '.$this->ref_fourn;
2388
-        if (! empty($this->total_ht))
2389
-            $label.= '<br><b>' . $langs->trans('AmountHT') . ':</b> ' . price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
2390
-        if (! empty($this->total_tva))
2391
-            $label.= '<br><b>' . $langs->trans('VAT') . ':</b> ' . price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
2392
-        if (! empty($this->total_ttc))
2393
-            $label.= '<br><b>' . $langs->trans('AmountTTC') . ':</b> ' . price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
2454
+        if (! empty($this->ref)) {
2455
+                $label.= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
2456
+        }
2457
+        if (! empty($this->ref_fourn)) {
2458
+                    $label.= '<br><b>'.$langs->trans('RefSupplier').':</b> '.$this->ref_fourn;
2459
+        }
2460
+        if (! empty($this->total_ht)) {
2461
+                    $label.= '<br><b>' . $langs->trans('AmountHT') . ':</b> ' . price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
2462
+        }
2463
+        if (! empty($this->total_tva)) {
2464
+                    $label.= '<br><b>' . $langs->trans('VAT') . ':</b> ' . price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
2465
+        }
2466
+        if (! empty($this->total_ttc)) {
2467
+                    $label.= '<br><b>' . $langs->trans('AmountTTC') . ':</b> ' . price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
2468
+        }
2394 2469
         if ($option == '') {
2395 2470
             $url = DOL_URL_ROOT.'/supplier_proposal/card.php?id='.$this->id. $get_params;
2396 2471
         }
@@ -2402,8 +2477,12 @@  discard block
 block discarded – undo
2402 2477
         {
2403 2478
         	// Add param to save lastsearch_values or not
2404 2479
         	$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
2405
-        	if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
2406
-        	if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
2480
+        	if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) {
2481
+        		$add_save_lastsearch_values=1;
2482
+        	}
2483
+        	if ($add_save_lastsearch_values) {
2484
+        		$url.='&save_lastsearch_values=1';
2485
+        	}
2407 2486
         }
2408 2487
 
2409 2488
         $linkclose='';
@@ -2425,10 +2504,12 @@  discard block
 block discarded – undo
2425 2504
         $picto='supplier_proposal';
2426 2505
 
2427 2506
 
2428
-        if ($withpicto)
2429
-            $result.=($linkstart.img_object(($notooltip?'':$label), $picto, ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend);
2430
-        if ($withpicto && $withpicto != 2)
2431
-            $result.=' ';
2507
+        if ($withpicto) {
2508
+                    $result.=($linkstart.img_object(($notooltip?'':$label), $picto, ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend);
2509
+        }
2510
+        if ($withpicto && $withpicto != 2) {
2511
+                    $result.=' ';
2512
+        }
2432 2513
         $result.=$linkstart.$this->ref.$linkend;
2433 2514
         return $result;
2434 2515
     }
@@ -2510,8 +2591,7 @@  discard block
 block discarded – undo
2510 2591
             $this->db->free($resql);
2511 2592
 
2512 2593
             return 1;
2513
-        }
2514
-        else
2594
+        } else
2515 2595
         {
2516 2596
             $this->error=$this->db->error();
2517 2597
             return -1;
@@ -2769,8 +2849,7 @@  discard block
 block discarded – undo
2769 2849
 			$this->fk_unit				 	= $objp->fk_unit;
2770 2850
 
2771 2851
 			$this->db->free($result);
2772
-		}
2773
-		else
2852
+		} else
2774 2853
 		{
2775 2854
 			dol_print_error($this->db);
2776 2855
 		}
@@ -2791,24 +2870,58 @@  discard block
 block discarded – undo
2791 2870
         dol_syslog(get_class($this)."::insert rang=".$this->rang);
2792 2871
 
2793 2872
         // Clean parameters
2794
-        if (empty($this->tva_tx)) $this->tva_tx=0;
2795
-        if (empty($this->localtax1_tx)) $this->localtax1_tx=0;
2796
-        if (empty($this->localtax2_tx)) $this->localtax2_tx=0;
2797
-        if (empty($this->localtax1_type)) $this->localtax1_type=0;
2798
-		if (empty($this->localtax2_type)) $this->localtax2_type=0;
2799
-        if (empty($this->total_localtax1)) $this->total_localtax1=0;
2800
-        if (empty($this->total_localtax2)) $this->total_localtax2=0;
2801
-        if (empty($this->rang)) $this->rang=0;
2802
-        if (empty($this->remise)) $this->remise=0;
2803
-        if (empty($this->remise_percent)) $this->remise_percent=0;
2804
-        if (empty($this->info_bits)) $this->info_bits=0;
2805
-        if (empty($this->special_code)) $this->special_code=0;
2806
-        if (empty($this->fk_parent_line)) $this->fk_parent_line=0;
2807
-        if (empty($this->fk_fournprice)) $this->fk_fournprice=0;
2808
-        if (empty($this->fk_unit)) $this->fk_unit=0;
2809
-        if (empty($this->subprice)) $this->subprice=0;
2810
-
2811
-        if (empty($this->pa_ht)) $this->pa_ht=0;
2873
+        if (empty($this->tva_tx)) {
2874
+        	$this->tva_tx=0;
2875
+        }
2876
+        if (empty($this->localtax1_tx)) {
2877
+        	$this->localtax1_tx=0;
2878
+        }
2879
+        if (empty($this->localtax2_tx)) {
2880
+        	$this->localtax2_tx=0;
2881
+        }
2882
+        if (empty($this->localtax1_type)) {
2883
+        	$this->localtax1_type=0;
2884
+        }
2885
+		if (empty($this->localtax2_type)) {
2886
+			$this->localtax2_type=0;
2887
+		}
2888
+        if (empty($this->total_localtax1)) {
2889
+        	$this->total_localtax1=0;
2890
+        }
2891
+        if (empty($this->total_localtax2)) {
2892
+        	$this->total_localtax2=0;
2893
+        }
2894
+        if (empty($this->rang)) {
2895
+        	$this->rang=0;
2896
+        }
2897
+        if (empty($this->remise)) {
2898
+        	$this->remise=0;
2899
+        }
2900
+        if (empty($this->remise_percent)) {
2901
+        	$this->remise_percent=0;
2902
+        }
2903
+        if (empty($this->info_bits)) {
2904
+        	$this->info_bits=0;
2905
+        }
2906
+        if (empty($this->special_code)) {
2907
+        	$this->special_code=0;
2908
+        }
2909
+        if (empty($this->fk_parent_line)) {
2910
+        	$this->fk_parent_line=0;
2911
+        }
2912
+        if (empty($this->fk_fournprice)) {
2913
+        	$this->fk_fournprice=0;
2914
+        }
2915
+        if (empty($this->fk_unit)) {
2916
+        	$this->fk_unit=0;
2917
+        }
2918
+        if (empty($this->subprice)) {
2919
+        	$this->subprice=0;
2920
+        }
2921
+
2922
+        if (empty($this->pa_ht)) {
2923
+        	$this->pa_ht=0;
2924
+        }
2812 2925
 
2813 2926
 		// if buy price not defined, define buyprice as configured in margin admin
2814 2927
 		if ($this->pa_ht == 0)
@@ -2816,15 +2929,16 @@  discard block
 block discarded – undo
2816 2929
 			if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0)
2817 2930
 			{
2818 2931
 				return $result;
2819
-			}
2820
-			else
2932
+			} else
2821 2933
 			{
2822 2934
 				$this->pa_ht = $result;
2823 2935
 			}
2824 2936
 		}
2825 2937
 
2826 2938
         // Check parameters
2827
-        if ($this->product_type < 0) return -1;
2939
+        if ($this->product_type < 0) {
2940
+        	return -1;
2941
+        }
2828 2942
 
2829 2943
         $this->db->begin();
2830 2944
 
@@ -2879,9 +2993,11 @@  discard block
 block discarded – undo
2879 2993
             $this->rowid=$this->db->last_insert_id(MAIN_DB_PREFIX.'supplier_proposaldet');
2880 2994
 			$this->id=$this->rowid;
2881 2995
 
2882
-            if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
2996
+            if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
2997
+            	// For avoid conflicts if trigger used
2883 2998
             {
2884 2999
             	$result=$this->insertExtraFields();
3000
+            }
2885 3001
             	if ($result < 0)
2886 3002
             	{
2887 3003
             		$error++;
@@ -2902,8 +3018,7 @@  discard block
 block discarded – undo
2902 3018
 
2903 3019
             $this->db->commit();
2904 3020
             return 1;
2905
-        }
2906
-        else
3021
+        } else
2907 3022
         {
2908 3023
             $this->error=$this->db->error()." sql=".$sql;
2909 3024
             $this->db->rollback();
@@ -2929,9 +3044,11 @@  discard block
 block discarded – undo
2929 3044
         {
2930 3045
 
2931 3046
         	// Remove extrafields
2932
-        	if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
3047
+        	if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) {
3048
+        		// For avoid conflicts if trigger used
2933 3049
         	{
2934 3050
         		$this->id=$this->rowid;
3051
+        	}
2935 3052
         		$result=$this->deleteExtraFields();
2936 3053
         		if ($result < 0)
2937 3054
         		{
@@ -2952,8 +3069,7 @@  discard block
 block discarded – undo
2952 3069
             $this->db->commit();
2953 3070
 
2954 3071
             return 1;
2955
-        }
2956
-        else
3072
+        } else
2957 3073
         {
2958 3074
             $this->error=$this->db->error()." sql=".$sql;
2959 3075
             $this->db->rollback();
@@ -2974,26 +3090,66 @@  discard block
 block discarded – undo
2974 3090
         $error=0;
2975 3091
 
2976 3092
         // Clean parameters
2977
-        if (empty($this->tva_tx)) $this->tva_tx=0;
2978
-        if (empty($this->localtax1_tx)) $this->localtax1_tx=0;
2979
-        if (empty($this->localtax2_tx)) $this->localtax2_tx=0;
2980
-        if (empty($this->total_localtax1)) $this->total_localtax1=0;
2981
-        if (empty($this->total_localtax2)) $this->total_localtax2=0;
2982
-		if (empty($this->localtax1_type)) $this->localtax1_type=0;
2983
-		if (empty($this->localtax2_type)) $this->localtax2_type=0;
2984
-        if (empty($this->marque_tx)) $this->marque_tx=0;
2985
-        if (empty($this->marge_tx)) $this->marge_tx=0;
2986
-        if (empty($this->price)) $this->price=0;	// TODO A virer
2987
-        if (empty($this->remise)) $this->remise=0;	// TODO A virer
2988
-        if (empty($this->remise_percent)) $this->remise_percent=0;
2989
-        if (empty($this->info_bits)) $this->info_bits=0;
2990
-        if (empty($this->special_code)) $this->special_code=0;
2991
-        if (empty($this->fk_parent_line)) $this->fk_parent_line=0;
2992
-        if (empty($this->fk_fournprice)) $this->fk_fournprice=0;
2993
-        if (empty($this->fk_unit)) $this->fk_unit=0;
2994
-        if (empty($this->subprice)) $this->subprice=0;
2995
-
2996
-		if (empty($this->pa_ht)) $this->pa_ht=0;
3093
+        if (empty($this->tva_tx)) {
3094
+        	$this->tva_tx=0;
3095
+        }
3096
+        if (empty($this->localtax1_tx)) {
3097
+        	$this->localtax1_tx=0;
3098
+        }
3099
+        if (empty($this->localtax2_tx)) {
3100
+        	$this->localtax2_tx=0;
3101
+        }
3102
+        if (empty($this->total_localtax1)) {
3103
+        	$this->total_localtax1=0;
3104
+        }
3105
+        if (empty($this->total_localtax2)) {
3106
+        	$this->total_localtax2=0;
3107
+        }
3108
+		if (empty($this->localtax1_type)) {
3109
+			$this->localtax1_type=0;
3110
+		}
3111
+		if (empty($this->localtax2_type)) {
3112
+			$this->localtax2_type=0;
3113
+		}
3114
+        if (empty($this->marque_tx)) {
3115
+        	$this->marque_tx=0;
3116
+        }
3117
+        if (empty($this->marge_tx)) {
3118
+        	$this->marge_tx=0;
3119
+        }
3120
+        if (empty($this->price)) {
3121
+        	$this->price=0;
3122
+        }
3123
+        // TODO A virer
3124
+        if (empty($this->remise)) {
3125
+        	$this->remise=0;
3126
+        }
3127
+        // TODO A virer
3128
+        if (empty($this->remise_percent)) {
3129
+        	$this->remise_percent=0;
3130
+        }
3131
+        if (empty($this->info_bits)) {
3132
+        	$this->info_bits=0;
3133
+        }
3134
+        if (empty($this->special_code)) {
3135
+        	$this->special_code=0;
3136
+        }
3137
+        if (empty($this->fk_parent_line)) {
3138
+        	$this->fk_parent_line=0;
3139
+        }
3140
+        if (empty($this->fk_fournprice)) {
3141
+        	$this->fk_fournprice=0;
3142
+        }
3143
+        if (empty($this->fk_unit)) {
3144
+        	$this->fk_unit=0;
3145
+        }
3146
+        if (empty($this->subprice)) {
3147
+        	$this->subprice=0;
3148
+        }
3149
+
3150
+		if (empty($this->pa_ht)) {
3151
+			$this->pa_ht=0;
3152
+		}
2997 3153
 
2998 3154
 		// if buy price not defined, define buyprice as configured in margin admin
2999 3155
 		if ($this->pa_ht == 0)
@@ -3001,8 +3157,7 @@  discard block
 block discarded – undo
3001 3157
 			if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0)
3002 3158
 			{
3003 3159
 				return $result;
3004
-			}
3005
-			else
3160
+			} else
3006 3161
 			{
3007 3162
 				$this->pa_ht = $result;
3008 3163
 			}
@@ -3036,9 +3191,13 @@  discard block
 block discarded – undo
3036 3191
         }
3037 3192
 		$sql.= " , fk_product_fournisseur_price=".(! empty($this->fk_fournprice)?"'".$this->db->escape($this->fk_fournprice)."'":"null");
3038 3193
 		$sql.= " , buy_price_ht=".price2num($this->pa_ht);
3039
-        if (strlen($this->special_code)) $sql.= " , special_code=".$this->special_code;
3194
+        if (strlen($this->special_code)) {
3195
+        	$sql.= " , special_code=".$this->special_code;
3196
+        }
3040 3197
         $sql.= " , fk_parent_line=".($this->fk_parent_line>0?$this->fk_parent_line:"null");
3041
-        if (! empty($this->rang)) $sql.= ", rang=".$this->rang;
3198
+        if (! empty($this->rang)) {
3199
+        	$sql.= ", rang=".$this->rang;
3200
+        }
3042 3201
         $sql.= " , ref_fourn=".(! empty($this->ref_fourn)?"'".$this->db->escape($this->ref_fourn)."'":"null");
3043 3202
         $sql.= " , fk_unit=".($this->fk_unit?$this->fk_unit:'null');
3044 3203
 
@@ -3054,9 +3213,11 @@  discard block
 block discarded – undo
3054 3213
         $resql=$this->db->query($sql);
3055 3214
         if ($resql)
3056 3215
         {
3057
-        	if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
3216
+        	if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
3217
+        		// For avoid conflicts if trigger used
3058 3218
         	{
3059 3219
         		$this->id=$this->rowid;
3220
+        	}
3060 3221
         		$result=$this->insertExtraFields();
3061 3222
         		if ($result < 0)
3062 3223
         		{
@@ -3078,8 +3239,7 @@  discard block
 block discarded – undo
3078 3239
 
3079 3240
             $this->db->commit();
3080 3241
             return 1;
3081
-        }
3082
-        else
3242
+        } else
3083 3243
         {
3084 3244
             $this->error=$this->db->error();
3085 3245
             $this->db->rollback();
@@ -3111,8 +3271,7 @@  discard block
 block discarded – undo
3111 3271
         {
3112 3272
             $this->db->commit();
3113 3273
             return 1;
3114
-        }
3115
-        else
3274
+        } else
3116 3275
         {
3117 3276
             $this->error=$this->db->error();
3118 3277
             $this->db->rollback();
Please login to merge, or discard this patch.
htdocs/blockedlog/class/blockedlog.class.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -423,7 +423,7 @@
 block discarded – undo
423 423
 	 *	@param	string $element      	element to search
424 424
 	 *	@param	int $fk_object			id of object to search
425 425
 	 *	@param	int $limit      		max number of element, 0 for all
426
-	 *	@param	string $order      		sort of query
426
+	 *	@param	integer $order      		sort of query
427 427
 	 *	@return	array					array of object log
428 428
 	 */
429 429
 	public function getLog($element, $fk_object, $limit = 0, $order = -1) {
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -126,7 +126,7 @@
 block discarded – undo
126 126
 
127 127
 	/**
128 128
 	 *      try to retrieve user author
129
-	*/
129
+	 */
130 130
 	public function getUser() {
131 131
 		global $langs, $cachedUser;
132 132
 
Please login to merge, or discard this patch.
Spacing   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -97,25 +97,25 @@  discard block
 block discarded – undo
97 97
 	public function getObjectLink() {
98 98
 		global $langs;
99 99
 
100
-		if($this->element === 'facture') {
100
+		if ($this->element === 'facture') {
101 101
 			require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
102 102
 
103 103
 			$object = new Facture($this->db);
104
-			if($object->fetch($this->fk_object)>0) {
104
+			if ($object->fetch($this->fk_object) > 0) {
105 105
 				return $object->getNomUrl(1);
106 106
 			}
107
-			else{
107
+			else {
108 108
 				$this->error++;
109 109
 			}
110 110
 		}
111
-		else if($this->element === 'payment') {
111
+		else if ($this->element === 'payment') {
112 112
 			require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
113 113
 
114 114
 			$object = new Paiement($this->db);
115
-			if($object->fetch($this->fk_object)>0) {
115
+			if ($object->fetch($this->fk_object) > 0) {
116 116
 				return $object->getNomUrl(1);
117 117
 			}
118
-			else{
118
+			else {
119 119
 				$this->error++;
120 120
 			}
121 121
 		}
@@ -130,16 +130,16 @@  discard block
 block discarded – undo
130 130
 	public function getUser() {
131 131
 		global $langs, $cachedUser;
132 132
 
133
-		if(empty($cachedUser))$cachedUser=array();
133
+		if (empty($cachedUser))$cachedUser = array();
134 134
 
135
-		if(empty($cachedUser[$this->fk_user])) {
136
-			$u=new User($this->db);
137
-			if($u->fetch($this->fk_user)>0) {
135
+		if (empty($cachedUser[$this->fk_user])) {
136
+			$u = new User($this->db);
137
+			if ($u->fetch($this->fk_user) > 0) {
138 138
 				$cachedUser[$this->fk_user] = $u;
139 139
 			}
140 140
 		}
141 141
 
142
-		if(!empty($cachedUser[$this->fk_user])) {
142
+		if (!empty($cachedUser[$this->fk_user])) {
143 143
 			return $cachedUser[$this->fk_user]->getNomUrl(1);
144 144
 		}
145 145
 
@@ -153,10 +153,10 @@  discard block
 block discarded – undo
153 153
 	 */
154 154
 	public function setObjectData(&$object) {
155 155
 
156
-		if($object->element=='payment') {
156
+		if ($object->element == 'payment') {
157 157
 			$this->date_object = $object->datepaye;
158 158
 		}
159
-		else{
159
+		else {
160 160
 			$this->date_object = $object->date;
161 161
 		}
162 162
 
@@ -164,26 +164,26 @@  discard block
 block discarded – undo
164 164
 		$this->element = $object->element;
165 165
 		$this->fk_object = $object->id;
166 166
 
167
-		$this->object_data=new stdClass();
167
+		$this->object_data = new stdClass();
168 168
 
169
-		if($this->element === 'facture') {
170
-			if(empty($object->thirdparty))$object->fetch_thirdparty();
169
+		if ($this->element === 'facture') {
170
+			if (empty($object->thirdparty))$object->fetch_thirdparty();
171 171
 			$this->object_data->thirdparty = new stdClass();
172 172
 
173
-			foreach($object->thirdparty as $key=>$value) {
174
-				if(!is_object($value)) $this->object_data->thirdparty->{$key} = $value;
173
+			foreach ($object->thirdparty as $key=>$value) {
174
+				if (!is_object($value)) $this->object_data->thirdparty->{$key} = $value;
175 175
 			}
176 176
 
177 177
 			$this->object_data->total_ht 	= (double) $object->total_ht;
178 178
 			$this->object_data->total_tva	= (double) $object->total_tva;
179 179
 			$this->object_data->total_ttc	= (double) $object->total_ttc;
180
-			$this->object_data->total_localtax1= (double) $object->total_localtax1;
181
-			$this->object_data->total_localtax2= (double) $object->total_localtax2;
180
+			$this->object_data->total_localtax1 = (double) $object->total_localtax1;
181
+			$this->object_data->total_localtax2 = (double) $object->total_localtax2;
182 182
 			$this->object_data->note_public	= (double) $object->note_public;
183
-			$this->object_data->note_private= (double) $object->note_private;
183
+			$this->object_data->note_private = (double) $object->note_private;
184 184
 
185 185
 		}
186
-		elseif($this->element==='payment'){
186
+		elseif ($this->element === 'payment') {
187 187
 
188 188
 			$this->object_data->amounts = $object->amounts;
189 189
 
@@ -206,54 +206,54 @@  discard block
 block discarded – undo
206 206
 
207 207
 		if (empty($id))
208 208
 		{
209
-			$this->error='BadParameter';
209
+			$this->error = 'BadParameter';
210 210
 			return -1;
211 211
 		}
212 212
 
213 213
 		$langs->load("blockedlog");
214 214
 
215 215
 		$sql = "SELECT b.rowid, b.signature, b.amounts, b.action, b.element, b.fk_object, b.certified, b.tms, b.fk_user, b.date_object, b.ref_object, b.object_data";
216
-		$sql.= " FROM ".MAIN_DB_PREFIX."blockedlog as b";
217
-		if ($id) $sql.= " WHERE b.rowid = ". $id;
216
+		$sql .= " FROM ".MAIN_DB_PREFIX."blockedlog as b";
217
+		if ($id) $sql .= " WHERE b.rowid = ".$id;
218 218
 
219
-		$resql=$this->db->query($sql);
219
+		$resql = $this->db->query($sql);
220 220
 		if ($resql)
221 221
 		{
222 222
 			if ($this->db->num_rows($resql))
223 223
 			{
224 224
 				$obj = $this->db->fetch_object($resql);
225 225
 
226
-				$this->id				= $obj->rowid;
227
-				$this->ref				= $obj->rowid;
226
+				$this->id = $obj->rowid;
227
+				$this->ref = $obj->rowid;
228 228
 
229
-				$this->signature		= $obj->signature;
229
+				$this->signature = $obj->signature;
230 230
 				$this->amounts			= (double) $obj->amounts;
231
-				$this->action			= $obj->action;
231
+				$this->action = $obj->action;
232 232
 				$this->element			= $obj->element;
233 233
 
234
-				$this->fk_object		= trim($obj->fk_object);
235
-				$this->date_object		= $this->db->jdate($obj->date_object);
236
-				$this->ref_object		= $obj->ref_object;
234
+				$this->fk_object = trim($obj->fk_object);
235
+				$this->date_object = $this->db->jdate($obj->date_object);
236
+				$this->ref_object = $obj->ref_object;
237 237
 
238 238
 				$this->certified		= ($obj->certified == 1);
239 239
 
240 240
 				$this->fk_user 			= $obj->fk_user;
241 241
 
242
-				$this->tms				= $this->db->jdate($obj->tms);
242
+				$this->tms = $this->db->jdate($obj->tms);
243 243
 
244
-				$this->object_data		= unserialize($obj->object_data);
244
+				$this->object_data = unserialize($obj->object_data);
245 245
 
246 246
 				return 1;
247 247
 			}
248 248
 			else
249 249
 			{
250
-				$this->error=$langs->trans("RecordNotFound");
250
+				$this->error = $langs->trans("RecordNotFound");
251 251
 				return 0;
252 252
 			}
253 253
 		}
254 254
 		else
255 255
 		{
256
-			$this->error=$this->db->error();
256
+			$this->error = $this->db->error();
257 257
 			return -1;
258 258
 		}
259 259
 
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 	public function setCertified() {
268 268
 
269 269
 		$res = $this->db->query("UPDATE ".MAIN_DB_PREFIX."blockedlog SET certified=1 WHERE rowid=".$this->id);
270
-		if($res===false) return false;
270
+		if ($res === false) return false;
271 271
 
272 272
 		return true;
273 273
 
@@ -282,11 +282,11 @@  discard block
 block discarded – undo
282 282
 	 */
283 283
 	public function create($user) {
284 284
 
285
-		global $conf,$langs,$hookmanager;
285
+		global $conf, $langs, $hookmanager;
286 286
 
287 287
 		$langs->load('blockedlog');
288 288
 
289
-		$error=0;
289
+		$error = 0;
290 290
 
291 291
 		dol_syslog(get_class($this).'::create', LOG_DEBUG);
292 292
 
@@ -295,19 +295,19 @@  discard block
 block discarded – undo
295 295
 
296 296
 		if (is_null($this->amounts))
297 297
 		{
298
-			$this->error=$langs->trans("BlockLogNeedAmountsValue");
298
+			$this->error = $langs->trans("BlockLogNeedAmountsValue");
299 299
 			dol_syslog($this->error, LOG_WARNING);
300 300
 			return -1;
301 301
 		}
302 302
 
303
-		if(empty($this->element)) {
304
-			$this->error=$langs->trans("BlockLogNeedElement");
303
+		if (empty($this->element)) {
304
+			$this->error = $langs->trans("BlockLogNeedElement");
305 305
 			dol_syslog($this->error, LOG_WARNING);
306 306
 			return -2;
307 307
 		}
308 308
 
309
-		if(empty($this->action)) {
310
-			$this->error=$langs->trans("BlockLogNeedAction");
309
+		if (empty($this->action)) {
310
+			$this->error = $langs->trans("BlockLogNeedAction");
311 311
 			dol_syslog($this->error, LOG_WARNING);
312 312
 			return -3;
313 313
 		}
@@ -317,32 +317,32 @@  discard block
 block discarded – undo
317 317
 		$this->db->begin();
318 318
 
319 319
 		$sql = "INSERT INTO ".MAIN_DB_PREFIX."blockedlog (";
320
-		$sql.= "action,";
321
-		$sql.= " amounts,";
322
-		$sql.= " signature,";
323
-		$sql.= " signature_line,";
324
-		$sql.= " element,";
325
-		$sql.= " fk_object,";
326
-		$sql.= " date_object,";
327
-		$sql.= " ref_object,";
328
-		$sql.= " object_data,";
329
-		$sql.= " certified,";
330
-		$sql.= " fk_user,";
331
-		$sql.= " entity";
332
-		$sql.= ") VALUES (";
333
-		$sql.= "'".$this->db->escape($this->action)."',";
334
-		$sql.= "".$this->amounts.",";
335
-		$sql.= "'".$this->db->escape($this->signature)."',";
336
-		$sql.= "'".$this->db->escape($this->signature_line)."',";
337
-		$sql.= "'".$this->db->escape($this->element)."',";
338
-		$sql.= "".$this->fk_object.",";
339
-		$sql.= "'".$this->db->idate($this->date_object)."',";
340
-		$sql.= "'".$this->db->escape($this->ref_object)."',";
341
-		$sql.= "'".$this->db->escape(serialize($this->object_data))."',";
342
-		$sql.= "0,";
343
-		$sql.= "".$user->id.",";
344
-		$sql.= $conf->entity;
345
-		$sql.= ")";
320
+		$sql .= "action,";
321
+		$sql .= " amounts,";
322
+		$sql .= " signature,";
323
+		$sql .= " signature_line,";
324
+		$sql .= " element,";
325
+		$sql .= " fk_object,";
326
+		$sql .= " date_object,";
327
+		$sql .= " ref_object,";
328
+		$sql .= " object_data,";
329
+		$sql .= " certified,";
330
+		$sql .= " fk_user,";
331
+		$sql .= " entity";
332
+		$sql .= ") VALUES (";
333
+		$sql .= "'".$this->db->escape($this->action)."',";
334
+		$sql .= "".$this->amounts.",";
335
+		$sql .= "'".$this->db->escape($this->signature)."',";
336
+		$sql .= "'".$this->db->escape($this->signature_line)."',";
337
+		$sql .= "'".$this->db->escape($this->element)."',";
338
+		$sql .= "".$this->fk_object.",";
339
+		$sql .= "'".$this->db->idate($this->date_object)."',";
340
+		$sql .= "'".$this->db->escape($this->ref_object)."',";
341
+		$sql .= "'".$this->db->escape(serialize($this->object_data))."',";
342
+		$sql .= "0,";
343
+		$sql .= "".$user->id.",";
344
+		$sql .= $conf->entity;
345
+		$sql .= ")";
346 346
 
347 347
 		$res = $this->db->query($sql);
348 348
 		if ($res)
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 		}
366 366
 		else
367 367
 		{
368
-			$this->error=$this->db->error();
368
+			$this->error = $this->db->error();
369 369
 			$this->db->rollback();
370 370
 			return -1;
371 371
 		}
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
 	 */
381 381
 	private function crypt($value) {
382 382
 
383
-		return hash('sha256',$value);
383
+		return hash('sha256', $value);
384 384
 
385 385
 	}
386 386
 
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
 
398 398
 		$res = ($signature_to_test === $this->signature);
399 399
 
400
-		if(!$res) {
400
+		if (!$res) {
401 401
 			$this->error++;
402 402
 		}
403 403
 
@@ -407,23 +407,23 @@  discard block
 block discarded – undo
407 407
 	/**
408 408
 	 *	set current signatures
409 409
 	 */
410
-	 private function getSignatureRecursive(){
410
+	 private function getSignatureRecursive() {
411 411
 
412
-		$this->signature_line = $this->crypt( $this->action . $this->getSignature() . $this->amounts . print_r($this->object_data, true) );
412
+		$this->signature_line = $this->crypt($this->action.$this->getSignature().$this->amounts.print_r($this->object_data, true));
413 413
 		/*if($this->signature=='d6320580a02c1ab67fcc0a6d49d453c7d96dda0148901736f7f55725bfe1b900' || $this->signature=='ea65d435ff12ca929936a406aa9d707d99fb334c127878d256b602a5541bbbc9') {
414 414
 			var_dump($this->signature_line,$this->action ,$this->getSignature() , $this->amounts , $this->object_data);
415 415
 		}*/
416 416
 		$this->signature = $this->signature_line;
417 417
 
418
-		$logs = $this->getLog('all', 0, 0, 1) ;
419
-		if($logs!==false) {
420
-			foreach($logs as &$b) {
418
+		$logs = $this->getLog('all', 0, 0, 1);
419
+		if ($logs !== false) {
420
+			foreach ($logs as &$b) {
421 421
 
422
-				if($this->id>0 && $b->id == $this->id) break; // on arrête sur un enregistrement précis pour recalculer une signature
422
+				if ($this->id > 0 && $b->id == $this->id) break; // on arrête sur un enregistrement précis pour recalculer une signature
423 423
 
424 424
 				$b->getCurrentValue(); // on récupère la valeur actuelle en base de l'élément enregistré
425 425
 
426
-				$this->signature = $this->crypt($this->signature. $this->action . $b->signature . $b->amounts);
426
+				$this->signature = $this->crypt($this->signature.$this->action.$b->signature.$b->amounts);
427 427
 			}
428 428
 		}
429 429
 
@@ -439,48 +439,48 @@  discard block
 block discarded – undo
439 439
 	 *	@return	array					array of object log
440 440
 	 */
441 441
 	public function getLog($element, $fk_object, $limit = 0, $order = -1) {
442
-		global $conf,$cachedlogs ;
442
+		global $conf, $cachedlogs;
443 443
 
444 444
 		/* $cachedlogs allow fastest search */
445
-		if(empty($cachedlogs)) $cachedlogs=array();
445
+		if (empty($cachedlogs)) $cachedlogs = array();
446 446
 
447 447
 
448
-		if($element=='all') {
448
+		if ($element == 'all') {
449 449
 
450
-	 		$sql="SELECT rowid FROM ".MAIN_DB_PREFIX."blockedlog
450
+	 		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."blockedlog
451 451
 	         WHERE entity=".$conf->entity;
452 452
 
453 453
 		}
454
-		else if($element=='not_certified') {
455
-			$sql="SELECT rowid FROM ".MAIN_DB_PREFIX."blockedlog
454
+		else if ($element == 'not_certified') {
455
+			$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."blockedlog
456 456
 	         WHERE entity=".$conf->entity." AND certified = 0";
457 457
 
458 458
 		}
459
-		else if($element=='just_certified') {
460
-			$sql="SELECT rowid FROM ".MAIN_DB_PREFIX."blockedlog
459
+		else if ($element == 'just_certified') {
460
+			$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."blockedlog
461 461
 	         WHERE entity=".$conf->entity." AND certified = 1";
462 462
 
463 463
 		}
464
-		else{
465
-			$sql="SELECT rowid FROM ".MAIN_DB_PREFIX."blockedlog
464
+		else {
465
+			$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."blockedlog
466 466
 	         WHERE element='".$element."' AND fk_object=".(int) $fk_object;
467 467
 
468 468
 		}
469 469
 
470
-		$sql.=($order<0 ? ' ORDER BY rowid DESC ' : ' ORDER BY rowid ASC ');
470
+		$sql .= ($order < 0 ? ' ORDER BY rowid DESC ' : ' ORDER BY rowid ASC ');
471 471
 
472
-		if($limit > 0 )$sql.=' LIMIT '.$limit;
472
+		if ($limit > 0)$sql .= ' LIMIT '.$limit;
473 473
 
474 474
 		$res = $this->db->query($sql);
475 475
 
476
-		if($res) {
476
+		if ($res) {
477 477
 
478
-			$results=array();
478
+			$results = array();
479 479
 
480
-			while($obj = $this->db->fetch_object($res)) {
480
+			while ($obj = $this->db->fetch_object($res)) {
481 481
 
482
-				if(!isset($cachedlogs[$obj->rowid])) {
483
-					$b=new BlockedLog($this->db);
482
+				if (!isset($cachedlogs[$obj->rowid])) {
483
+					$b = new BlockedLog($this->db);
484 484
 					$b->fetch($obj->rowid);
485 485
 
486 486
 					$cachedlogs[$obj->rowid] = $b;
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
 
493 493
 			return $results;
494 494
 		}
495
-		else{
495
+		else {
496 496
 			return false;
497 497
 		}
498 498
 	}
@@ -502,20 +502,20 @@  discard block
 block discarded – undo
502 502
 	 */
503 503
 	private function getCurrentValue() {
504 504
 
505
-		if($this->element === 'payment') {
506
-			$sql="SELECT amount FROM ".MAIN_DB_PREFIX."paiement WHERE rowid=".$this->fk_object;
505
+		if ($this->element === 'payment') {
506
+			$sql = "SELECT amount FROM ".MAIN_DB_PREFIX."paiement WHERE rowid=".$this->fk_object;
507 507
 
508 508
 			$res = $this->db->query($sql);
509 509
 
510
-			if($res && $obj = $this->db->fetch_object($res)) {
510
+			if ($res && $obj = $this->db->fetch_object($res)) {
511 511
 				$this->amounts = (double) $obj->amount;
512 512
 			}
513 513
 		}
514
-		elseif($this->element === 'facture') {
515
-			$sql="SELECT total_ttc FROM ".MAIN_DB_PREFIX."facture WHERE rowid=".$this->fk_object;
514
+		elseif ($this->element === 'facture') {
515
+			$sql = "SELECT total_ttc FROM ".MAIN_DB_PREFIX."facture WHERE rowid=".$this->fk_object;
516 516
 
517 517
 			$res = $this->db->query($sql);
518
-			if($res && $obj = $this->db->fetch_object($res)) {
518
+			if ($res && $obj = $this->db->fetch_object($res)) {
519 519
 				$this->amounts = (double) $obj->total_ttc;
520 520
 			}
521 521
 		}
@@ -528,17 +528,17 @@  discard block
 block discarded – undo
528 528
 	 *	@return	string					current entity signature
529 529
 	 */
530 530
 	public function getSignature() {
531
-		global $db,$conf,$mysoc;
531
+		global $db, $conf, $mysoc;
532 532
 
533 533
 		if (empty($conf->global->BLOCKEDLOG_ENTITY_FINGERPRINT)) { // creation of a unique fingerprint
534 534
 
535 535
 			require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
536 536
 
537
-			$fingerprint = $this->crypt(print_r($mysoc,true).time().rand(0,1000));
537
+			$fingerprint = $this->crypt(print_r($mysoc, true).time().rand(0, 1000));
538 538
 
539
-			dolibarr_set_const($db, 'BLOCKEDLOG_ENTITY_FINGERPRINT', $fingerprint, 'chaine',0,'Numeric Unique Fingerprint', $conf->entity);
539
+			dolibarr_set_const($db, 'BLOCKEDLOG_ENTITY_FINGERPRINT', $fingerprint, 'chaine', 0, 'Numeric Unique Fingerprint', $conf->entity);
540 540
 
541
-			$conf->global->BLOCKEDLOG_ENTITY_FINGERPRINT=$fingerprint;
541
+			$conf->global->BLOCKEDLOG_ENTITY_FINGERPRINT = $fingerprint;
542 542
 		}
543 543
 
544 544
 		return $conf->global->BLOCKEDLOG_ENTITY_FINGERPRINT;
Please login to merge, or discard this patch.
Braces   +39 added lines, -36 removed lines patch added patch discarded remove patch
@@ -103,19 +103,16 @@  discard block
 block discarded – undo
103 103
 			$object = new Facture($this->db);
104 104
 			if($object->fetch($this->fk_object)>0) {
105 105
 				return $object->getNomUrl(1);
106
-			}
107
-			else{
106
+			} else{
108 107
 				$this->error++;
109 108
 			}
110
-		}
111
-		else if($this->element === 'payment') {
109
+		} else if($this->element === 'payment') {
112 110
 			require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
113 111
 
114 112
 			$object = new Paiement($this->db);
115 113
 			if($object->fetch($this->fk_object)>0) {
116 114
 				return $object->getNomUrl(1);
117
-			}
118
-			else{
115
+			} else{
119 116
 				$this->error++;
120 117
 			}
121 118
 		}
@@ -130,7 +127,9 @@  discard block
 block discarded – undo
130 127
 	public function getUser() {
131 128
 		global $langs, $cachedUser;
132 129
 
133
-		if(empty($cachedUser))$cachedUser=array();
130
+		if(empty($cachedUser)) {
131
+			$cachedUser=array();
132
+		}
134 133
 
135 134
 		if(empty($cachedUser[$this->fk_user])) {
136 135
 			$u=new User($this->db);
@@ -155,8 +154,7 @@  discard block
 block discarded – undo
155 154
 
156 155
 		if($object->element=='payment') {
157 156
 			$this->date_object = $object->datepaye;
158
-		}
159
-		else{
157
+		} else{
160 158
 			$this->date_object = $object->date;
161 159
 		}
162 160
 
@@ -167,11 +165,15 @@  discard block
 block discarded – undo
167 165
 		$this->object_data=new stdClass();
168 166
 
169 167
 		if($this->element === 'facture') {
170
-			if(empty($object->thirdparty))$object->fetch_thirdparty();
168
+			if(empty($object->thirdparty)) {
169
+				$object->fetch_thirdparty();
170
+			}
171 171
 			$this->object_data->thirdparty = new stdClass();
172 172
 
173 173
 			foreach($object->thirdparty as $key=>$value) {
174
-				if(!is_object($value)) $this->object_data->thirdparty->{$key} = $value;
174
+				if(!is_object($value)) {
175
+					$this->object_data->thirdparty->{$key} = $value;
176
+				}
175 177
 			}
176 178
 
177 179
 			$this->object_data->total_ht 	= (double) $object->total_ht;
@@ -182,8 +184,7 @@  discard block
 block discarded – undo
182 184
 			$this->object_data->note_public	= (double) $object->note_public;
183 185
 			$this->object_data->note_private= (double) $object->note_private;
184 186
 
185
-		}
186
-		elseif($this->element==='payment'){
187
+		} elseif($this->element==='payment'){
187 188
 
188 189
 			$this->object_data->amounts = $object->amounts;
189 190
 
@@ -214,7 +215,9 @@  discard block
 block discarded – undo
214 215
 
215 216
 		$sql = "SELECT b.rowid, b.signature, b.amounts, b.action, b.element, b.fk_object, b.certified, b.tms, b.fk_user, b.date_object, b.ref_object, b.object_data";
216 217
 		$sql.= " FROM ".MAIN_DB_PREFIX."blockedlog as b";
217
-		if ($id) $sql.= " WHERE b.rowid = ". $id;
218
+		if ($id) {
219
+			$sql.= " WHERE b.rowid = ". $id;
220
+		}
218 221
 
219 222
 		$resql=$this->db->query($sql);
220 223
 		if ($resql)
@@ -244,14 +247,12 @@  discard block
 block discarded – undo
244 247
 				$this->object_data		= unserialize($obj->object_data);
245 248
 
246 249
 				return 1;
247
-			}
248
-			else
250
+			} else
249 251
 			{
250 252
 				$this->error=$langs->trans("RecordNotFound");
251 253
 				return 0;
252 254
 			}
253
-		}
254
-		else
255
+		} else
255 256
 		{
256 257
 			$this->error=$this->db->error();
257 258
 			return -1;
@@ -267,7 +268,9 @@  discard block
 block discarded – undo
267 268
 	public function setCertified() {
268 269
 
269 270
 		$res = $this->db->query("UPDATE ".MAIN_DB_PREFIX."blockedlog SET certified=1 WHERE rowid=".$this->id);
270
-		if($res===false) return false;
271
+		if($res===false) {
272
+			return false;
273
+		}
271 274
 
272 275
 		return true;
273 276
 
@@ -356,14 +359,12 @@  discard block
 block discarded – undo
356 359
 				$this->db->commit();
357 360
 
358 361
 				return $this->id;
359
-			}
360
-			else
362
+			} else
361 363
 			{
362 364
 				$this->db->rollback();
363 365
 				return -2;
364 366
 			}
365
-		}
366
-		else
367
+		} else
367 368
 		{
368 369
 			$this->error=$this->db->error();
369 370
 			$this->db->rollback();
@@ -419,7 +420,10 @@  discard block
 block discarded – undo
419 420
 		if($logs!==false) {
420 421
 			foreach($logs as &$b) {
421 422
 
422
-				if($this->id>0 && $b->id == $this->id) break; // on arrête sur un enregistrement précis pour recalculer une signature
423
+				if($this->id>0 && $b->id == $this->id) {
424
+					break;
425
+				}
426
+				// on arrête sur un enregistrement précis pour recalculer une signature
423 427
 
424 428
 				$b->getCurrentValue(); // on récupère la valeur actuelle en base de l'élément enregistré
425 429
 
@@ -442,7 +446,9 @@  discard block
 block discarded – undo
442 446
 		global $conf,$cachedlogs ;
443 447
 
444 448
 		/* $cachedlogs allow fastest search */
445
-		if(empty($cachedlogs)) $cachedlogs=array();
449
+		if(empty($cachedlogs)) {
450
+			$cachedlogs=array();
451
+		}
446 452
 
447 453
 
448 454
 		if($element=='all') {
@@ -450,18 +456,15 @@  discard block
 block discarded – undo
450 456
 	 		$sql="SELECT rowid FROM ".MAIN_DB_PREFIX."blockedlog
451 457
 	         WHERE entity=".$conf->entity;
452 458
 
453
-		}
454
-		else if($element=='not_certified') {
459
+		} else if($element=='not_certified') {
455 460
 			$sql="SELECT rowid FROM ".MAIN_DB_PREFIX."blockedlog
456 461
 	         WHERE entity=".$conf->entity." AND certified = 0";
457 462
 
458
-		}
459
-		else if($element=='just_certified') {
463
+		} else if($element=='just_certified') {
460 464
 			$sql="SELECT rowid FROM ".MAIN_DB_PREFIX."blockedlog
461 465
 	         WHERE entity=".$conf->entity." AND certified = 1";
462 466
 
463
-		}
464
-		else{
467
+		} else{
465 468
 			$sql="SELECT rowid FROM ".MAIN_DB_PREFIX."blockedlog
466 469
 	         WHERE element='".$element."' AND fk_object=".(int) $fk_object;
467 470
 
@@ -469,7 +472,9 @@  discard block
 block discarded – undo
469 472
 
470 473
 		$sql.=($order<0 ? ' ORDER BY rowid DESC ' : ' ORDER BY rowid ASC ');
471 474
 
472
-		if($limit > 0 )$sql.=' LIMIT '.$limit;
475
+		if($limit > 0 ) {
476
+			$sql.=' LIMIT '.$limit;
477
+		}
473 478
 
474 479
 		$res = $this->db->query($sql);
475 480
 
@@ -491,8 +496,7 @@  discard block
 block discarded – undo
491 496
 			}
492 497
 
493 498
 			return $results;
494
-		}
495
-		else{
499
+		} else{
496 500
 			return false;
497 501
 		}
498 502
 	}
@@ -510,8 +514,7 @@  discard block
 block discarded – undo
510 514
 			if($res && $obj = $this->db->fetch_object($res)) {
511 515
 				$this->amounts = (double) $obj->amount;
512 516
 			}
513
-		}
514
-		elseif($this->element === 'facture') {
517
+		} elseif($this->element === 'facture') {
515 518
 			$sql="SELECT total_ttc FROM ".MAIN_DB_PREFIX."facture WHERE rowid=".$this->fk_object;
516 519
 
517 520
 			$res = $this->db->query($sql);
Please login to merge, or discard this patch.