dolibarr  9.0.0
productaccount.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
3  * Copyright (C) 2013-2016 Alexandre Spangaro <aspangaro@zendsi.com>
4  * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
5  * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2015 Ari Elbaz (elarifr) <github@accedinfo.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
27 require '../../main.inc.php';
28 
29 require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
30 require_once DOL_DOCUMENT_ROOT . '/core/lib/report.lib.php';
31 require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
32 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
33 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
34 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
35 require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
36 
37 // Load translation files required by the page
38 $langs->loadLangs(array("companies","compta","accountancy","products"));
39 
40 // Security check
41 if (empty($conf->accounting->enabled)) {
43 }
44 if (! $user->rights->accounting->bind->write)
46 
47 // search & action GETPOST
48 $action = GETPOST('action', 'aZ09');
49 $codeventil_buy = GETPOST('codeventil_buy', 'array');
50 $codeventil_sell = GETPOST('codeventil_sell', 'array');
51 $chk_prod = GETPOST('chk_prod', 'array');
52 $account_number_buy = GETPOST('account_number_buy');
53 $account_number_sell = GETPOST('account_number_sell');
54 $changeaccount = GETPOST('changeaccount', 'array');
55 $changeaccount_buy = GETPOST('changeaccount_buy', 'array');
56 $changeaccount_sell = GETPOST('changeaccount_sell', 'array');
57 $search_ref = GETPOST('search_ref', 'alpha');
58 $search_label = GETPOST('search_label', 'alpha');
59 $search_desc = GETPOST('search_desc', 'alpha');
60 $search_current_account = GETPOST('search_current_account', 'alpha');
61 $search_current_account_valid = GETPOST('search_current_account_valid', 'alpha');
62 if ($search_current_account_valid == '') $search_current_account_valid='withoutvalidaccount';
63 
64 $accounting_product_mode = GETPOST('accounting_product_mode', 'alpha');
65 $btn_changeaccount = GETPOST('changeaccount', 'alpha');
66 $btn_changetype = GETPOST('changetype', 'alpha');
67 
68 $limit = GETPOST('limit','int')?GETPOST('limit','int'):(empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
69 $sortfield = GETPOST("sortfield",'alpha');
70 $sortorder = GETPOST("sortorder",'alpha');
71 $page = GETPOST("page",'int');
72 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
73 $offset = $limit * $page;
74 $pageprev = $page - 1;
75 $pagenext = $page + 1;
76 if (! $sortfield) $sortfield="p.ref";
77 if (! $sortorder) $sortorder="ASC";
78 
79 if (empty($action)) $action='list';
80 
81 $arrayfields=array();
82 
83 
84 /*
85  * Actions
86  */
87 
88 if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
89 if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
90 
91 $parameters=array();
92 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
93 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
94 
95 // Purge search criteria
96 if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All test are required to be compatible with all browsers
97 {
98  $search_ref = '';
99  $search_label = '';
100  $search_desc = '';
101  $search_current_account = '';
102  $search_current_account_valid = '-1';
103 }
104 
105 // Sales or Purchase mode ?
106 if ($action == 'update') {
107  if (! empty($btn_changetype)) {
108  $error = 0;
109 
110  $accounting_product_modes = array (
111  'ACCOUNTANCY_SELL',
112  'ACCOUNTANCY_BUY'
113  );
114 
115  $accounting_product_mode = GETPOST('accounting_product_mode', 'alpha');
116 
117  if (in_array($accounting_product_mode, $accounting_product_modes)) {
118 
119  if (! dolibarr_set_const($db, 'ACCOUNTING_PRODUCT_MODE', $accounting_product_mode, 'chaine', 0, '', $conf->entity)) {
120  $error ++;
121  }
122  } else {
123  $error ++;
124  }
125  }
126 
127  if (! empty($btn_changeaccount)) {
128  //$msg = '<div><span class="accountingprocessing">' . $langs->trans("Processing") . '...</span></div>';
129  if (! empty($chk_prod)) {
130 
131  $accounting = new AccountingAccount($db);
132 
133  //$msg .= '<div><span class="accountingprocessing">' . count($chk_prod) . ' ' . $langs->trans("SelectedLines") . '</span></div>';
134  $arrayofdifferentselectedvalues = array();
135 
136  $cpt = 0; $ok = 0; $ko = 0;
137  foreach ( $chk_prod as $productid )
138  {
139  $accounting_account_id = GETPOST('codeventil_' . $productid);
140 
141  $result = 0;
142  if ($accounting_account_id > 0)
143  {
144  $arrayofdifferentselectedvalues[$accounting_account_id]=$accounting_account_id;
145  $result = $accounting->fetch($accounting_account_id, null, 1);
146  }
147  if ($result <= 0) {
148  // setEventMessages(null, $accounting->errors, 'errors');
149  $msg .= '<div><font color="red">' . $langs->trans("ErrorDB") . ' : ' . $langs->trans("Product") . ' ' . $productid . ' ' . $langs->trans("NotVentilatedinAccount") . ' : id=' . $accounting_account_id . '<br/> <pre>' . $sql . '</pre></font></div>';
150  $ko++;
151  } else {
152  $db->begin();
153 
154  $sql = " UPDATE " . MAIN_DB_PREFIX . "product";
155  if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
156  $sql .= " SET accountancy_code_buy = " . $accounting->account_number;
157  }
158  if ($accounting_product_mode == 'ACCOUNTANCY_SELL') {
159  $sql .= " SET accountancy_code_sell = " . $accounting->account_number;
160  }
161  $sql .= " WHERE rowid = " . $productid;
162 
163  dol_syslog("/accountancy/admin/productaccount.php sql=" . $sql, LOG_DEBUG);
164  if ($db->query($sql))
165  {
166  $ok++;
167  $db->commit();
168  } else {
169  $ko++;
170  $db->rollback();
171  }
172  }
173 
174  $cpt++;
175  }
176  }
177 
178  if ($ko) setEventMessages($langs->trans("XLineFailedToBeBinded", $ko), null, 'errors');
179  if ($ok) setEventMessages($langs->trans("XLineSuccessfullyBinded", $ok), null, 'mesgs');
180  }
181 }
182 
183 
184 
185 /*
186  * View
187  */
188 
189 $form = new FormAccounting($db);
190 
191 // Defaut AccountingAccount RowId Product / Service
192 // at this time ACCOUNTING_SERVICE_SOLD_ACCOUNT & ACCOUNTING_PRODUCT_SOLD_ACCOUNT are account number not accountingacount rowid
193 // so we need to get those default value rowid first
194 $accounting = new AccountingAccount($db);
195 // TODO: we should need to check if result is a really exist accountaccount rowid.....
196 $aarowid_servbuy = $accounting->fetch('', $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT, 1);
197 $aarowid_prodbuy = $accounting->fetch('', $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT, 1);
198 $aarowid_servsell = $accounting->fetch('', $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT, 1);
199 $aarowid_prodsell = $accounting->fetch('', $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT, 1);
200 
201 $aacompta_servbuy = (! empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
202 $aacompta_prodbuy = (! empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
203 $aacompta_servsell = (! empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans("CodeNotDef"));
204 $aacompta_prodsell = (! empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans("CodeNotDef"));
205 
206 llxHeader('', $langs->trans("ProductsBinding"));
207 
208 $pcgverid = $conf->global->CHARTOFACCOUNTS;
209 $pcgvercode = dol_getIdFromCode($db, $pcgverid, 'accounting_system', 'rowid', 'pcg_version');
210 if (empty($pcgvercode)) $pcgvercode=$pcgverid;
211 
212 $sql = "SELECT p.rowid, p.ref, p.label, p.description, p.tosell, p.tobuy, p.accountancy_code_sell, p.accountancy_code_buy, p.tms, p.fk_product_type as product_type,";
213 $sql.= " aa.rowid as aaid";
214 $sql.= " FROM " . MAIN_DB_PREFIX . "product as p";
215 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON";
216 if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
217  $sql.=" p.accountancy_code_buy = aa.account_number AND aa.fk_pcg_version = '" . $pcgvercode . "'";
218 }
219 else
220 {
221  $sql.=" p.accountancy_code_sell = aa.account_number AND aa.fk_pcg_version = '" . $pcgvercode . "'";
222 }
223 $sql.= ' WHERE p.entity IN ('.getEntity('product').')';
224 if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
225  if (strlen(trim($search_current_account))) {
226  $sql .= natural_search("p.accountancy_code_buy",$search_current_account);
227  }
228 } else {
229  if (strlen(trim($search_current_account))) {
230  $sql .= natural_search("p.accountancy_code_sell",$search_current_account);
231  }
232 }
233 if ($search_current_account_valid == 'withoutvalidaccount')
234 {
235  $sql .= " AND aa.account_number IS NULL";
236 }
237 if ($search_current_account_valid == 'withvalidaccount')
238 {
239  $sql .= " AND aa.account_number IS NOT NULL";
240 }
241 // Add search filter like
242 if (strlen(trim($search_ref))) {
243  $sql .= natural_search("p.ref",$search_ref);
244 }
245 if (strlen(trim($search_label))) {
246  $sql .= natural_search("p.label",$search_label);
247 }
248 if (strlen(trim($search_desc))) {
249  $sql .= natural_search("p.description",$search_desc);
250 }
251 $sql .= $db->order($sortfield, $sortorder);
252 
253 $nbtotalofrecords = '';
254 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
255 {
256  $result = $db->query($sql);
257  $nbtotalofrecords = $db->num_rows($result);
258  if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
259  {
260  $page = 0;
261  $offset = 0;
262  }
263 }
264 
265 $sql .= $db->plimit($limit + 1, $offset);
266 
267 dol_syslog("/accountancy/admin/productaccount.php:: sql=" . $sql, LOG_DEBUG);
268 $result = $db->query($sql);
269 if ($result)
270 {
271  $num = $db->num_rows($result);
272  $i = 0;
273 
274  $param='';
275  if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
276  if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit);
277  if ($search_ref > 0) $param.="&search_desc=".urlencode($search_ref);
278  if ($search_label > 0) $param.="&search_desc=".urlencode($search_label);
279  if ($search_desc > 0) $param.="&search_desc=".urlencode($search_desc);
280  if ($search_current_account > 0) $param.="&search_current_account=".urlencode($search_current_account);
281  if ($search_current_account_valid && $search_current_account_valid != '-1') $param.="&search_current_account_valid=".urlencode($search_current_account_valid);
282 
283  print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">';
284  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
285  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
286  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
287  print '<input type="hidden" name="action" value="update">';
288  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
289  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
290  print '<input type="hidden" name="page" value="'.$page.'">';
291 
292  print load_fiche_titre($langs->trans("ProductsBinding"), '', 'title_accountancy');
293  print '<br>';
294 
295  print $langs->trans("InitAccountancyDesc") . '<br>';
296  print '<br>';
297 
298  // Select mode
299  print '<table class="noborder" width="100%">';
300  print '<tr class="liste_titre">';
301  print '<td>' . $langs->trans('Options') . '</td><td>' . $langs->trans('Description') . '</td>';
302  print "</tr>\n";
303  print '<tr class="oddeven"><td class="titlefield"><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_SELL"' . ($accounting_product_mode != 'ACCOUNTANCY_BUY' ? ' checked' : '') . '> ' . $langs->trans('OptionModeProductSell') . '</td>';
304  print '<td>'.$langs->trans('OptionModeProductSellDesc');
305  print "</td></tr>\n";
306  print '<tr class="oddeven"><td class="titlefield"><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_BUY"' . ($accounting_product_mode == 'ACCOUNTANCY_BUY' ? ' checked' : '') . '> ' . $langs->trans('OptionModeProductBuy') . '</td>';
307  print '<td>'.$langs->trans('OptionModeProductBuyDesc')."</td></tr>\n";
308  print "</table>\n";
309 
310  print '<div align="center"><input type="submit" class="button" value="' . $langs->trans('Refresh') . '" name="changetype"></div>';
311 
312  print "<br>\n";
313 
314 
315  // Filter on categories
316  $moreforfilter='';
317  $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
318  $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
319 
320  $texte=$langs->trans("ListOfProductsServices");
321  print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '', 0, '', '', $limit);
322 
323  print '<div class="div-table-responsive">';
324  print '<table class="liste '.($moreforfilter?"listwithfilterbefore":"").'">';
325 
326  print '<tr class="liste_titre_filter">';
327  print '<td class="liste_titre"><input type="text" class="flat" size="8" name="search_ref" value="' . dol_escape_htmltag($search_ref) . '"></td>';
328  print '<td class="liste_titre"><input type="text" class="flat" size="10" name="search_label" value="' . dol_escape_htmltag($search_label) . '"></td>';
329  if (! empty($conf->global->ACCOUNTANCY_SHOW_PROD_DESC)) print '<td class="liste_titre"><input type="text" class="flat" size="20" name="search_desc" value="' . dol_escape_htmltag($search_desc) . '"></td>';
330  // On sell
331  if ($accounting_product_mode == 'ACCOUNTANCY_SELL') print '<td class="liste_titre"></td>';
332  // On buy
333  if ($accounting_product_mode == 'ACCOUNTANCY_BUY') print '<td class="liste_titre"></td>';
334  // Current account
335  print '<td class="liste_titre">';
336  print '<input type="text" class="flat" size="6" name="search_current_account" value="' . dol_escape_htmltag($search_current_account) . '">';
337  $listofvals=array('withoutvalidaccount'=>$langs->trans("WithoutValidAccount"), 'withvalidaccount'=>$langs->trans("WithValidAccount"));
338  print ' '.$langs->trans("or").' '.$form->selectarray('search_current_account_valid', $listofvals, $search_current_account_valid, 1);
339  print '</td>';
340  print '<td class="liste_titre">&nbsp;</td>';
341  print '<td align="center" class="liste_titre">';
342  $searchpicto=$form->showFilterButtons();
343  print $searchpicto;
344  print '</td>';
345  print '</tr>';
346 
347  print '<tr class="liste_titre">';
348  print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
349  print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "p.label", "", $param, '', $sortfield, $sortorder);
350  if (! empty($conf->global->ACCOUNTANCY_SHOW_PROD_DESC)) print_liste_field_titre("Description", $_SERVER["PHP_SELF"], "p.description", "", $param, '', $sortfield, $sortorder);
351  if ($accounting_product_mode == 'ACCOUNTANCY_SELL') print_liste_field_titre("OnSell", $_SERVER["PHP_SELF"], "p.tosell", "", $param, 'align="center"', $sortfield, $sortorder);
352  if ($accounting_product_mode == 'ACCOUNTANCY_BUY') print_liste_field_titre("OnBuy", $_SERVER["PHP_SELF"], "p.tobuy", "", $param, 'align="center"', $sortfield, $sortorder);
353  if ($accounting_product_mode == 'ACCOUNTANCY_BUY') $fieldtosortaccount="p.accountancy_code_buy";
354  else $fieldtosortaccount="p.accountancy_code_sell";
355  print_liste_field_titre("CurrentDedicatedAccountingAccount", $_SERVER["PHP_SELF"], $fieldtosortaccount, "", $param, '', $sortfield, $sortorder);
356  print_liste_field_titre("AssignDedicatedAccountingAccount");
357  $clickpitco=$form->showCheckAddButtons('checkforselect', 1);
358  print_liste_field_titre($clickpitco, '', '', '', '', 'align="center"');
359  print '</tr>';
360 
361  $product_static = new Product($db);
362 
363  $i=0;
364  while ($i < min($num,$limit))
365  {
366  $obj = $db->fetch_object($result);
367 
368  // Ref produit as link
369  $product_static->ref = $obj->ref;
370  $product_static->id = $obj->rowid;
371  $product_static->type = $obj->product_type;
372  $product_static->label = $obj->label;
373  $product_static->description = $obj->description;
374  $product_static->status = $obj->tosell;
375  $product_static->status_buy = $obj->tobuy;
376 
377  if ($obj->product_type == 0) {
378  $compta_prodsell = (! empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans("CodeNotDef"));
379  $compta_prodsell_id = $aarowid_prodsell;
380  } else {
381  $compta_prodsell = (! empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans("CodeNotDef"));
382  $compta_prodsell_id = $aarowid_servsell;
383  }
384 
385  if ($obj->product_type == 0) {
386  $compta_prodbuy = (! empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
387  $compta_prodbuy_id = $aarowid_prodbuy;
388  } else {
389  $compta_prodbuy = (! empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
390  $compta_prodbuy_id = $aarowid_servbuy;
391  }
392 
393  print '<tr class="oddeven">';
394 
395  print '<td>';
396  print $product_static->getNomUrl(1);
397  print '</td>';
398 
399  print '<td align="left">'.$obj->label.'</td>';
400 
401  if (! empty($conf->global->ACCOUNTANCY_SHOW_PROD_DESC))
402  {
403  // TODO ADJUST DESCRIPTION SIZE
404  // print '<td align="left">' . $obj->description . '</td>';
405  // TODO: we shoul set a user defined value to adjust user square / wide screen size
406  $trunclengh = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
407  print '<td style="' . $code_sell_p_l_differ . '">' . nl2br(dol_trunc($obj->description, $trunclengh)) . '</td>';
408  }
409 
410  if ($accounting_product_mode == 'ACCOUNTANCY_SELL')
411  print '<td align="center">'.$product_static->getLibStatut(3, 0).'</td>';
412 
413  if ($accounting_product_mode == 'ACCOUNTANCY_BUY')
414  print '<td align="center">'.$product_static->getLibStatut(3, 1).'</td>';
415 
416  // Current accounting account
417  print '<td align="left">';
418  if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
419  print length_accountg($obj->accountancy_code_buy);
420  if ($obj->accountancy_code_buy && empty($obj->aaid)) print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount"));
421  }
422  else
423  {
424  print length_accountg($obj->accountancy_code_sell);
425  if ($obj->accountancy_code_sell && empty($obj->aaid)) print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount"));
426  }
427  print '</td>';
428 
429  // Dedicated account
430  $defaultvalue='';
431  if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
432  // Accounting account buy
433  print '<td align="left">';
434  //$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code
435  if (empty($defaultvalue)) $defaultvalue=$compta_prodbuy;
436  $codesell=length_accountg($obj->accountancy_code_buy);
437  if (! empty($obj->aaid)) $defaultvalue = ''; // Do not suggest default new value is code is already valid
438  print $form->select_account($defaultvalue, 'codeventil_' . $product_static->id, 1, array(), 1);
439  print '</td>';
440  } else {
441  // Accounting account sell
442  print '<td align="left">';
443  //$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code
444  if (empty($defaultvalue)) $defaultvalue=$compta_prodsell;
445  $codesell=length_accountg($obj->accountancy_code_sell);
446  //var_dump($defaultvalue.' - '.$codesell.' - '.$compta_prodsell);
447  if (! empty($obj->aaid)) $defaultvalue = ''; // Do not suggest default new value is code is already valid
448  print $form->select_account($defaultvalue, 'codeventil_' . $product_static->id, 1, array(), 1);
449  print '</td>';
450  }
451 
452  // Checkbox select
453  print '<td align="center">';
454  print '<input type="checkbox" class="checkforselect" name="chk_prod[]" value="' . $obj->rowid . '"/></td>';
455  print "</tr>";
456  $i ++;
457  }
458  print '</table>';
459  print '</div>';
460 
461  // Example : Adding jquery code
462  print '<script type="text/javascript" language="javascript">
463  jQuery(document).ready(function() {
464  function init_savebutton()
465  {
466  console.log("We check if at least one line is checked")
467 
468  atleastoneselected=0;
469  jQuery(".checkforselect").each(function( index ) {
470  /* console.log( index + ": " + $( this ).text() ); */
471  if ($(this).is(\':checked\')) atleastoneselected++;
472  });
473 
474  if (atleastoneselected) jQuery("#changeaccount").removeAttr(\'disabled\');
475  else jQuery("#changeaccount").attr(\'disabled\',\'disabled\');
476  if (atleastoneselected) jQuery("#changeaccount").attr(\'class\',\'butAction\');
477  else jQuery("#changeaccount").attr(\'class\',\'butActionRefused\');
478  }
479  jQuery(".checkforselect, #checkallactions").click(function() {
480  init_savebutton();
481  });
482 
483  init_savebutton();
484  });
485  </script>';
486 
487 
488  print '<br><div align="center"><input type="submit" class="butAction" id="changeaccount" name="changeaccount" value="' . $langs->trans("Save") . '"></div>';
489 
490  print '</form>';
491 
492  $db->free($result);
493 } else {
494  dol_print_error($db);
495 }
496 
497 // End of page
498 llxFooter();
499 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding &#39;...&#39; if string larger than length.
Class to manage products or services.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0)
Return an id or code from a code or id.
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Definition: admin.lib.php:510
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='title_generic.png', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0)
Print a title with navigation controls for pagination.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
llxHeader()
Empty header.
Definition: wrapper.php:44
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
Class to manage generation of HTML components for accounting management.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.
Class to manage accounting accounts.
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous) ...