dolibarr  7.0.0-beta
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 // Class
30 require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
31 require_once DOL_DOCUMENT_ROOT . '/core/lib/report.lib.php';
32 require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
33 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
34 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
35 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
36 require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
37 
38 // Langs
39 $langs->load("companies");
40 $langs->load("compta");
41 $langs->load("main");
42 $langs->load("accountancy");
43 $langs->load("products");
44 
45 // Security check
46 if (empty($conf->accounting->enabled)) {
48 }
49 if (! $user->rights->accounting->bind->write)
51 
52 // search & action GETPOST
53 $action = GETPOST('action', 'alpha');
54 $codeventil_buy = GETPOST('codeventil_buy', 'array');
55 $codeventil_sell = GETPOST('codeventil_sell', 'array');
56 $chk_prod = GETPOST('chk_prod', 'array');
57 $account_number_buy = GETPOST('account_number_buy');
58 $account_number_sell = GETPOST('account_number_sell');
59 $changeaccount = GETPOST('changeaccount', 'array');
60 $changeaccount_buy = GETPOST('changeaccount_buy', 'array');
61 $changeaccount_sell = GETPOST('changeaccount_sell', 'array');
62 $search_ref = GETPOST('search_ref', 'alpha');
63 $search_label = GETPOST('search_label', 'alpha');
64 $search_desc = GETPOST('search_desc', 'alpha');
65 $search_current_account = GETPOST('search_current_account', 'alpha');
66 $search_current_account_valid = GETPOST('search_current_account_valid', 'alpha');
67 if ($search_current_account_valid == '') $search_current_account_valid='withoutvalidaccount';
68 
69 $accounting_product_mode = GETPOST('accounting_product_mode', 'alpha');
70 $btn_changeaccount = GETPOST('changeaccount');
71 $btn_changetype = GETPOST('changetype');
72 
73 $limit = GETPOST('limit','int')?GETPOST('limit','int'):(empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
74 $sortfield = GETPOST("sortfield",'alpha');
75 $sortorder = GETPOST("sortorder",'alpha');
76 $page = GETPOST("page",'int');
77 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
78 $offset = $limit * $page;
79 $pageprev = $page - 1;
80 $pagenext = $page + 1;
81 if (! $sortfield) $sortfield="p.ref";
82 if (! $sortorder) $sortorder="ASC";
83 
84 if (empty($action)) $action='list';
85 
86 $arrayfields=array();
87 
88 
89 /*
90  * Actions
91  */
92 
93 if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
94 if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
95 
96 $parameters=array();
97 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
98 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
99 
100 // Purge search criteria
101 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
102 {
103  $search_ref = '';
104  $search_label = '';
105  $search_desc = '';
106  $search_current_account = '';
107  $search_current_account_valid = '-1';
108 }
109 
110 // Sales or Purchase mode ?
111 if ($action == 'update') {
112  if (! empty($btn_changetype)) {
113  $error = 0;
114 
115  $accounting_product_modes = array (
116  'ACCOUNTANCY_SELL',
117  'ACCOUNTANCY_BUY'
118  );
119 
120  $accounting_product_mode = GETPOST('accounting_product_mode', 'alpha');
121 
122  if (in_array($accounting_product_mode, $accounting_product_modes)) {
123 
124  if (! dolibarr_set_const($db, 'ACCOUNTING_PRODUCT_MODE', $accounting_product_mode, 'chaine', 0, '', $conf->entity)) {
125  $error ++;
126  }
127  } else {
128  $error ++;
129  }
130  }
131 
132  if (! empty($btn_changeaccount)) {
133  //$msg = '<div><span class="accountingprocessing">' . $langs->trans("Processing") . '...</span></div>';
134  if (! empty($chk_prod)) {
135 
136  $accounting = new AccountingAccount($db);
137 
138  //$msg .= '<div><span class="accountingprocessing">' . count($chk_prod) . ' ' . $langs->trans("SelectedLines") . '</span></div>';
139 
140  $cpt = 0; $ok = 0; $ko = 0;
141  foreach ( $chk_prod as $productid ) {
142 
143  $accounting_account_id = GETPOST('codeventil_' . $productid);
144 
145  $result = $accounting->fetch($accounting_account_id, null, 1);
146  if ($result < 0) {
147  // setEventMessages(null, $accounting->errors, 'errors');
148  $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>';
149  } else {
150 
151  $sql = " UPDATE " . MAIN_DB_PREFIX . "product";
152  if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
153  $sql .= " SET accountancy_code_buy = " . $accounting->account_number;
154  }
155  if ($accounting_product_mode == 'ACCOUNTANCY_SELL') {
156  $sql .= " SET accountancy_code_sell = " . $accounting->account_number;
157  }
158  $sql .= " WHERE rowid = " . $productid;
159 
160  dol_syslog("/accountancy/admin/productaccount.php sql=" . $sql, LOG_DEBUG);
161  if ($db->query($sql)) {
162  $ok++;
163  //$msg .= '<div><font color="green">' . $langs->trans("Product") . ' ' . $productid . ' - ' . $langs->trans("VentilatedinAccount") . ' : ' . length_accountg($accounting->account_number) . '</font></div>';
164  } else {
165  $ko++;
166  //$msg .= '<div><font color="red">' . $langs->trans("ErrorDB") . ' : ' . $langs->trans("Product") . ' ' . $productid . ' ' . $langs->trans("NotVentilatedinAccount") . ' : ' . length_accountg($accounting->account_number) . '<br/> <pre>' . $sql . '</pre></font></div>';
167  }
168  }
169 
170  $cpt ++;
171  }
172  } else {
173  //$msg .= '<div><span class="accountingprocessing">' . $langs->trans("AnyLineVentilate") . '</span></div>';
174  }
175  if ($ko) setEventMessages($langs->trans("XLineFailedToBeBinded", $ko), null, 'errors');
176  if ($ok) setEventMessages($langs->trans("XLineSuccessfullyBinded", $ok), null, 'mesgs');
177  //$msg .= '<div><span class="accountingprocessing">' . $langs->trans("EndProcessing") . '</span></div>';
178  }
179 }
180 
181 
182 
183 /*
184  * View
185  */
186 
187 $form = new FormAccounting($db);
188 
189 // Defaut AccountingAccount RowId Product / Service
190 // at this time ACCOUNTING_SERVICE_SOLD_ACCOUNT & ACCOUNTING_PRODUCT_SOLD_ACCOUNT are account number not accountingacount rowid
191 // so we need to get those default value rowid first
192 $accounting = new AccountingAccount($db);
193 // TODO: we should need to check if result is a really exist accountaccount rowid.....
194 $aarowid_servbuy = $accounting->fetch('', $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT, 1);
195 $aarowid_prodbuy = $accounting->fetch('', $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT, 1);
196 $aarowid_servsell = $accounting->fetch('', $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT, 1);
197 $aarowid_prodsell = $accounting->fetch('', $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT, 1);
198 
199 $aacompta_servbuy = (! empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
200 $aacompta_prodbuy = (! empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
201 $aacompta_servsell = (! empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans("CodeNotDef"));
202 $aacompta_prodsell = (! empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans("CodeNotDef"));
203 
204 llxHeader('', $langs->trans("ProductsBinding"));
205 
206 $pcgverid = $conf->global->CHARTOFACCOUNTS;
207 $pcgvercode = dol_getIdFromCode($db, $pcgverid, 'accounting_system', 'rowid', 'pcg_version');
208 if (empty($pcgvercode)) $pcgvercode=$pcgverid;
209 
210 $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,";
211 $sql.= " aa.rowid as aaid";
212 $sql.= " FROM " . MAIN_DB_PREFIX . "product as p";
213 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON";
214 if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
215  $sql.=" p.accountancy_code_buy = aa.account_number AND aa.fk_pcg_version = '" . $pcgvercode . "'";
216 }
217 else
218 {
219  $sql.=" p.accountancy_code_sell = aa.account_number AND aa.fk_pcg_version = '" . $pcgvercode . "'";
220 }
221 $sql.= ' WHERE p.entity IN ('.getEntity('product').')';
222 if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
223  if (strlen(trim($search_current_account))) {
224  $sql .= natural_search("p.accountancy_code_buy",$search_current_account);
225  }
226 } else {
227  if (strlen(trim($search_current_account))) {
228  $sql .= natural_search("p.accountancy_code_sell",$search_current_account);
229  }
230 }
231 if ($search_current_account_valid == 'withoutvalidaccount')
232 {
233  $sql .= " AND aa.account_number IS NULL";
234 }
235 if ($search_current_account_valid == 'withvalidaccount')
236 {
237  $sql .= " AND aa.account_number IS NOT NULL";
238 }
239 // Add search filter like
240 if (strlen(trim($search_ref))) {
241  $sql .= natural_search("p.ref",$search_ref);
242 }
243 if (strlen(trim($search_label))) {
244  $sql .= natural_search("p.label",$search_label);
245 }
246 if (strlen(trim($search_desc))) {
247  $sql .= natural_search("p.description",$search_desc);
248 }
249 $sql .= $db->order($sortfield, $sortorder);
250 
251 $nbtotalofrecords = '';
252 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
253 {
254  $result = $db->query($sql);
255  $nbtotalofrecords = $db->num_rows($result);
256 }
257 $sql .= $db->plimit($limit + 1, $offset);
258 
259 dol_syslog("/accountancy/admin/productaccount.php:: sql=" . $sql, LOG_DEBUG);
260 $result = $db->query($sql);
261 if ($result)
262 {
263  $num = $db->num_rows($result);
264  $i = 0;
265 
266  $param='';
267  if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
268  if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
269  if ($search_ref > 0) $param.="&search_desc=".urlencode($search_ref);
270  if ($search_label > 0) $param.="&search_desc=".urlencode($search_label);
271  if ($search_desc > 0) $param.="&search_desc=".urlencode($search_desc);
272  if ($search_current_account > 0) $param.="&search_current_account=".urlencode($search_current_account);
273  if ($search_current_account_valid && $search_current_account_valid != '-1') $param.="&search_current_account_valid=".urlencode($search_current_account_valid);
274 
275  print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">';
276  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
277  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
278  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
279  print '<input type="hidden" name="action" value="update">';
280  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
281  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
282  print '<input type="hidden" name="page" value="'.$page.'">';
283 
284  print load_fiche_titre($langs->trans("ProductsBinding"), '', 'title_accountancy');
285  print '<br>';
286 
287  print $langs->trans("InitAccountancyDesc") . '<br>';
288  print '<br>';
289 
290  // Select mode
291  print '<table class="noborder" width="100%">';
292  print '<tr class="liste_titre">';
293  print '<td>' . $langs->trans('Options') . '</td><td>' . $langs->trans('Description') . '</td>';
294  print "</tr>\n";
295  print '<tr ' . $bc[false] . '><td class="titlefield"><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_SELL"' . ($accounting_product_mode != 'ACCOUNTANCY_BUY' ? ' checked' : '') . '> ' . $langs->trans('OptionModeProductSell') . '</td>';
296  print '<td>'.$langs->trans('OptionModeProductSellDesc');
297  print "</td></tr>\n";
298  print '<tr ' . $bc[true] . '><td class="titlefield"><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_BUY"' . ($accounting_product_mode == 'ACCOUNTANCY_BUY' ? ' checked' : '') . '> ' . $langs->trans('OptionModeProductBuy') . '</td>';
299  print '<td>'.$langs->trans('OptionModeProductBuyDesc')."</td></tr>\n";
300  print "</table>\n";
301 
302  print '<div align="center"><input type="submit" class="button" value="' . $langs->trans('Refresh') . '" name="changetype"></div>';
303 
304  print "<br>\n";
305 
306 
307  // Filter on categories
308  $moreforfilter='';
309  $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
310  $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
311 
312  $texte=$langs->trans("ListOfProductsServices");
313  print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '', 0, '', '', $limit);
314 
315  print '<div class="div-table-responsive">';
316  print '<table class="liste '.($moreforfilter?"listwithfilterbefore":"").'">';
317 
318  print '<tr class="liste_titre_filter">';
319  print '<td class="liste_titre"><input type="text" class="flat" size="8" name="search_ref" value="' . dol_escape_htmltag($search_ref) . '"></td>';
320  print '<td class="liste_titre"><input type="text" class="flat" size="10" name="search_label" value="' . dol_escape_htmltag($search_label) . '"></td>';
321  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>';
322  // On sell
323  print '<td class="liste_titre"></td>';
324  // On buy
325  print '<td class="liste_titre"></td>';
326  // Current account
327  print '<td class="liste_titre">';
328  print '<input type="text" class="flat" size="6" name="search_current_account" value="' . dol_escape_htmltag($search_current_account) . '">';
329  $listofvals=array('withoutvalidaccount'=>$langs->trans("WithoutValidAccount"), 'withvalidaccount'=>$langs->trans("WithValidAccount"));
330  print ' '.$langs->trans("or").' '.$form->selectarray('search_current_account_valid', $listofvals, $search_current_account_valid, 1);
331  print '</td>';
332  print '<td class="liste_titre">&nbsp;</td>';
333  print '<td align="center" class="liste_titre">';
334  $searchpicto=$form->showFilterButtons();
335  print $searchpicto;
336  print '</td>';
337  print '</tr>';
338 
339  print '<tr class="liste_titre">';
340  print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
341  print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "p.label", "", $param, '', $sortfield, $sortorder);
342  if (! empty($conf->global->ACCOUNTANCY_SHOW_PROD_DESC)) print_liste_field_titre("Description", $_SERVER["PHP_SELF"], "p.description", "", $param, '', $sortfield, $sortorder);
343  print_liste_field_titre("OnSell", $_SERVER["PHP_SELF"], "p.tosell", "", $param, 'align="center"', $sortfield, $sortorder);
344  print_liste_field_titre("OnBuy", $_SERVER["PHP_SELF"], "p.tobuy", "", $param, 'align="center"', $sortfield, $sortorder);
345  if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
346  $fieldtosortaccount="p.accountancy_code_buy";
347  }
348  else $fieldtosortaccount="p.accountancy_code_sell";
349  print_liste_field_titre("CurrentDedicatedAccountingAccount", $_SERVER["PHP_SELF"], $fieldtosortaccount, "", $param, '', $sortfield, $sortorder);
350  print_liste_field_titre("AssignDedicatedAccountingAccount");
351  $clickpitco=$form->showCheckAddButtons('checkforselect', 1);
352  print_liste_field_titre($clickpitco, '', '', '', '', 'align="center"');
353  print '</tr>';
354 
355  $product_static = new Product($db);
356 
357  $var = true;
358  $i=0;
359  while ($i < min($num,$limit))
360  {
361  $obj = $db->fetch_object($result);
362 
363  // Ref produit as link
364  $product_static->ref = $obj->ref;
365  $product_static->id = $obj->rowid;
366  $product_static->type = $obj->product_type;
367  $product_static->label = $obj->label;
368  $product_static->description = $obj->description;
369  $product_static->status = $obj->tosell;
370  $product_static->status_buy = $obj->tobuy;
371 
372  if ($obj->product_type == 0) {
373  $compta_prodsell = (! empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans("CodeNotDef"));
374  $compta_prodsell_id = $aarowid_prodsell;
375  } else {
376  $compta_prodsell = (! empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans("CodeNotDef"));
377  $compta_prodsell_id = $aarowid_servsell;
378  }
379 
380  if ($obj->product_type == 0) {
381  $compta_prodbuy = (! empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
382  $compta_prodbuy_id = $aarowid_prodbuy;
383  } else {
384  $compta_prodbuy = (! empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
385  $compta_prodbuy_id = $aarowid_servbuy;
386  }
387 
388  print '<tr class="oddeven">';
389 
390  print '<td>';
391  print $product_static->getNomUrl(1);
392  print '</td>';
393 
394  print '<td align="left">'.$obj->label.'</td>';
395 
396  if (! empty($conf->global->ACCOUNTANCY_SHOW_PROD_DESC))
397  {
398  // TODO ADJUST DESCRIPTION SIZE
399  // print '<td align="left">' . $obj->description . '</td>';
400  // TODO: we shoul set a user defined value to adjust user square / wide screen size
401  $trunclengh = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
402  print '<td style="' . $code_sell_p_l_differ . '">' . nl2br(dol_trunc($obj->description, $trunclengh)) . '</td>';
403  }
404 
405  print '<td align="center">'.$product_static->getLibStatut(3, 0).'</td>';
406 
407  print '<td align="center">'.$product_static->getLibStatut(3, 1).'</td>';
408 
409  // Current accounting account
410  print '<td align="left">';
411  if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
412  print length_accountg($obj->accountancy_code_buy);
413  if ($obj->accountancy_code_buy && empty($obj->aaid)) print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount"));
414  }
415  else
416  {
417  print length_accountg($obj->accountancy_code_sell);
418  if ($obj->accountancy_code_sell && empty($obj->aaid)) print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount"));
419  }
420  print '</td>';
421 
422  // Dedicated account
423  $defaultvalue='';
424  if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
425  // Accounting account buy
426  print '<td align="left">';
427  //$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code
428  if (empty($defaultvalue)) $defaultvalue=$compta_prodbuy;
429  $codesell=length_accountg($obj->accountancy_code_buy);
430  if (! empty($obj->aaid)) $defaultvalue = ''; // Do not suggest default new value is code is already valid
431  print $form->select_account($defaultvalue, 'codeventil_' . $product_static->id, 1, array(), 1);
432  print '</td>';
433  } else {
434  // Accounting account sell
435  print '<td align="left">';
436  //$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code
437  if (empty($defaultvalue)) $defaultvalue=$compta_prodsell;
438  $codesell=length_accountg($obj->accountancy_code_sell);
439  //var_dump($defaultvalue.' - '.$codesell.' - '.$compta_prodsell);
440  if (! empty($obj->aaid)) $defaultvalue = ''; // Do not suggest default new value is code is already valid
441  print $form->select_account($defaultvalue, 'codeventil_' . $product_static->id, 1, array(), 1);
442  print '</td>';
443  }
444 
445  // Checkbox select
446  print '<td align="center">';
447  print '<input type="checkbox" class="checkforselect" name="chk_prod[]" value="' . $obj->rowid . '"/></td>';
448  print "</tr>";
449  $i ++;
450  }
451  print '</table>';
452  print '</div>';
453 
454  // Example : Adding jquery code
455  print '<script type="text/javascript" language="javascript">
456  jQuery(document).ready(function() {
457  function init_savebutton()
458  {
459  console.log("We check if at least one line is checked")
460 
461  atleastoneselected=0;
462  jQuery(".checkforselect").each(function( index ) {
463  /* console.log( index + ": " + $( this ).text() ); */
464  if ($(this).is(\':checked\')) atleastoneselected++;
465  });
466 
467  if (atleastoneselected) jQuery("#changeaccount").removeAttr(\'disabled\');
468  else jQuery("#changeaccount").attr(\'disabled\',\'disabled\');
469  if (atleastoneselected) jQuery("#changeaccount").attr(\'class\',\'butAction\');
470  else jQuery("#changeaccount").attr(\'class\',\'butActionRefused\');
471  }
472  jQuery(".checkforselect, #checkallactions").click(function() {
473  init_savebutton();
474  });
475 
476  init_savebutton();
477  });
478  </script>';
479 
480 
481  print '<br><div align="center"><input type="submit" class="butAction" id="changeaccount" name="changeaccount" value="' . $langs->trans("Save") . '"></div>';
482 
483  print '</form>';
484 
485  $db->free($result);
486 } else {
487  dol_print_error($db);
488 }
489 
490 llxFooter();
491 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
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 '...' 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:485
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
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...
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
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...
print
Draft customers invoices.
Definition: index.php:91
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) ...