27 require
'../../main.inc.php';
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';
38 $langs->loadLangs(array(
"companies",
"compta",
"accountancy",
"products"));
41 if (empty($conf->accounting->enabled)) {
44 if (!$user->rights->accounting->bind->write)
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_vat =
GETPOST(
'search_vat',
'alpha');
61 $search_current_account =
GETPOST(
'search_current_account',
'alpha');
62 $search_current_account_valid =
GETPOST(
'search_current_account_valid',
'alpha');
63 if ($search_current_account_valid ==
'') $search_current_account_valid =
'withoutvalidaccount';
64 $search_onsell =
GETPOST(
'search_onsell',
'alpha');
65 $search_onpurchase =
GETPOST(
'search_onpurchase',
'alpha');
67 $accounting_product_mode =
GETPOST(
'accounting_product_mode',
'alpha');
68 $btn_changeaccount =
GETPOST(
'changeaccount',
'alpha');
69 $btn_changetype =
GETPOST(
'changetype',
'alpha');
71 if (empty($accounting_product_mode)) $accounting_product_mode =
'ACCOUNTANCY_SELL';
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');
77 if (empty($page) || $page == -1) { $page = 0; }
78 $offset = $limit * $page;
79 $pageprev = $page - 1;
80 $pagenext = $page + 1;
81 if (!$sortfield) $sortfield =
"p.ref";
82 if (!$sortorder) $sortorder =
"ASC";
84 if (empty($action)) $action =
'list';
86 $arrayfields = array();
93 if (
GETPOST(
'cancel',
'alpha')) { $action =
'list'; $massaction =
''; }
94 if (!
GETPOST(
'confirmmassaction',
'alpha') && $massaction !=
'presend' && $massaction !=
'confirm_presend') { $massaction =
''; }
96 $parameters = array();
97 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
98 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
101 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha'))
108 $search_onpurchase =
'';
109 $search_current_account =
'';
110 $search_current_account_valid =
'-1';
114 if ($action ==
'update') {
115 if (!empty($btn_changetype)) {
118 $accounting_product_modes = array(
120 'ACCOUNTANCY_SELL_INTRA',
121 'ACCOUNTANCY_SELL_EXPORT',
123 'ACCOUNTANCY_BUY_INTRA',
124 'ACCOUNTANCY_BUY_EXPORT'
127 if (in_array($accounting_product_mode, $accounting_product_modes)) {
128 if (!
dolibarr_set_const($db,
'ACCOUNTING_PRODUCT_MODE', $accounting_product_mode,
'chaine', 0,
'', $conf->entity)) {
136 if (!empty($btn_changeaccount)) {
138 if (!empty($chk_prod)) {
142 $arrayofdifferentselectedvalues = array();
144 $cpt = 0; $ok = 0; $ko = 0;
145 foreach ($chk_prod as $productid)
147 $accounting_account_id =
GETPOST(
'codeventil_'.$productid);
150 if ($accounting_account_id > 0)
152 $arrayofdifferentselectedvalues[$accounting_account_id] = $accounting_account_id;
153 $result = $accounting->fetch($accounting_account_id, null, 1);
157 $msg .=
'<div><span style="color:red">'.$langs->trans(
"ErrorDB").
' : '.$langs->trans(
"Product").
' '.$productid.
' '.$langs->trans(
"NotVentilatedinAccount").
' : id='.$accounting_account_id.
'<br/> <pre>'.$sql.
'</pre></span></div>';
162 $sql =
" UPDATE ".MAIN_DB_PREFIX.
"product";
163 if ($accounting_product_mode ==
'ACCOUNTANCY_BUY') {
164 $sql .=
" SET accountancy_code_buy = ".$accounting->account_number;
166 if ($accounting_product_mode ==
'ACCOUNTANCY_BUY_INTRA') {
167 $sql .=
" SET accountancy_code_buy_intra = ".$accounting->account_number;
169 if ($accounting_product_mode ==
'ACCOUNTANCY_BUY_EXPORT') {
170 $sql .=
" SET accountancy_code_buy_export = ".$accounting->account_number;
172 if ($accounting_product_mode ==
'ACCOUNTANCY_SELL') {
173 $sql .=
" SET accountancy_code_sell = ".$accounting->account_number;
175 if ($accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA') {
176 $sql .=
" SET accountancy_code_sell_intra = ".$accounting->account_number;
178 if ($accounting_product_mode ==
'ACCOUNTANCY_SELL_EXPORT') {
179 $sql .=
" SET accountancy_code_sell_export = ".$accounting->account_number;
181 $sql .=
" WHERE rowid = ".((int) $productid);
183 dol_syslog(
"/accountancy/admin/productaccount.php sql=".$sql, LOG_DEBUG);
184 if ($db->query($sql))
198 if ($ko)
setEventMessages($langs->trans(
"XLineFailedToBeBinded", $ko), null,
'errors');
199 if ($ok)
setEventMessages($langs->trans(
"XLineSuccessfullyBinded", $ok), null,
'mesgs');
216 $aarowid_servbuy = $accounting->fetch(
'', $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT, 1);
217 $aarowid_servbuy_intra = $accounting->fetch(
'', $conf->global->ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT, 1);
218 $aarowid_servbuy_export = $accounting->fetch(
'', $conf->global->ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT, 1);
219 $aarowid_prodbuy = $accounting->fetch(
'', $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT, 1);
220 $aarowid_prodbuy_intra = $accounting->fetch(
'', $conf->global->ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT, 1);
221 $aarowid_prodbuy_export = $accounting->fetch(
'', $conf->global->ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT, 1);
222 $aarowid_servsell = $accounting->fetch(
'', $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT, 1);
223 $aarowid_servsell_intra = $accounting->fetch(
'', $conf->global->ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT, 1);
224 $aarowid_servsell_export = $accounting->fetch(
'', $conf->global->ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT, 1);
225 $aarowid_prodsell = $accounting->fetch(
'', $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT, 1);
226 $aarowid_prodsell_intra = $accounting->fetch(
'', $conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT, 1);
227 $aarowid_prodsell_export = $accounting->fetch(
'', $conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT, 1);
229 $aacompta_servbuy = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : $langs->trans(
"CodeNotDef"));
230 $aacompta_servbuy_intra = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT : $langs->trans(
"CodeNotDef"));
231 $aacompta_servbuy_export = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT : $langs->trans(
"CodeNotDef"));
232 $aacompta_prodbuy = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : $langs->trans(
"CodeNotDef"));
233 $aacompta_prodbuy_intra = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT : $langs->trans(
"CodeNotDef"));
234 $aacompta_prodbuy_export = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT : $langs->trans(
"CodeNotDef"));
235 $aacompta_servsell = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans(
"CodeNotDef"));
236 $aacompta_servsell_intra = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT : $langs->trans(
"CodeNotDef"));
237 $aacompta_servsell_export = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT : $langs->trans(
"CodeNotDef"));
238 $aacompta_prodsell = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans(
"CodeNotDef"));
239 $aacompta_prodsell_intra = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT : $langs->trans(
"CodeNotDef"));
240 $aacompta_prodsell_export = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT : $langs->trans(
"CodeNotDef"));
242 llxHeader(
'', $langs->trans(
"ProductsBinding"));
244 $pcgverid = $conf->global->CHARTOFACCOUNTS;
245 $pcgvercode =
dol_getIdFromCode($db, $pcgverid,
'accounting_system',
'rowid',
'pcg_version');
246 if (empty($pcgvercode)) $pcgvercode = $pcgverid;
248 $sql =
"SELECT p.rowid, p.ref, p.label, p.description, p.tosell, p.tobuy, p.tva_tx,";
249 $sql .=
" p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export,";
250 $sql .=
" p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export,";
251 $sql .=
" p.tms, p.fk_product_type as product_type,";
252 $sql .=
" aa.rowid as aaid";
253 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product as p";
254 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON";
255 if ($accounting_product_mode ==
'ACCOUNTANCY_BUY') {
256 $sql .=
" p.accountancy_code_buy = aa.account_number AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
257 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_INTRA')
259 $sql .=
" p.accountancy_code_buy_intra = aa.account_number AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
260 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_EXPORT')
262 $sql .=
" p.accountancy_code_buy_export = aa.account_number AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
263 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL')
265 $sql .=
" p.accountancy_code_sell = aa.account_number AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
266 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA')
268 $sql .=
" p.accountancy_code_sell_intra = aa.account_number AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
270 $sql .=
" p.accountancy_code_sell_export = aa.account_number AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
272 $sql .=
' WHERE p.entity IN ('.getEntity(
'product').
')';
273 if ($accounting_product_mode ==
'ACCOUNTANCY_BUY') {
274 if (strlen(trim($search_current_account))) {
275 $sql .=
natural_search(
"p.accountancy_code_buy", $search_current_account);
277 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_INTRA') {
278 if (strlen(trim($search_current_account))) {
279 $sql .=
natural_search(
"p.accountancy_code_buy_intra", $search_current_account);
281 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_EXPORT') {
282 if (strlen(trim($search_current_account))) {
283 $sql .=
natural_search(
"p.accountancy_code_buy_export", $search_current_account);
285 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL') {
286 if (strlen(trim($search_current_account))) {
287 $sql .=
natural_search(
"p.accountancy_code_sell", $search_current_account);
289 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA') {
290 if (strlen(trim($search_current_account))) {
291 $sql .=
natural_search(
"p.accountancy_code_sell_intra", $search_current_account);
294 if (strlen(trim($search_current_account))) {
295 $sql .=
natural_search(
"p.accountancy_code_sell_export", $search_current_account);
298 if ($search_current_account_valid ==
'withoutvalidaccount')
300 $sql .=
" AND aa.account_number IS NULL";
302 if ($search_current_account_valid ==
'withvalidaccount')
304 $sql .=
" AND aa.account_number IS NOT NULL";
307 if (strlen(trim($search_ref))) {
310 if (strlen(trim($search_label))) {
313 if (strlen(trim($search_desc))) {
316 if (strlen(trim($search_vat))) {
319 if ($search_onsell !=
'' && $search_onsell !=
'-1') $sql .=
natural_search(
'p.tosell', $search_onsell, 1);
320 if ($search_onpurchase !=
'' && $search_onpurchase !=
'-1') $sql .=
natural_search(
'p.tobuy', $search_onpurchase, 1);
322 $sql .= $db->order($sortfield, $sortorder);
324 $nbtotalofrecords =
'';
325 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
327 $result = $db->query($sql);
328 $nbtotalofrecords = $db->num_rows($result);
329 if (($page * $limit) > $nbtotalofrecords)
336 $sql .= $db->plimit($limit + 1, $offset);
338 dol_syslog(
"/accountancy/admin/productaccount.php:: sql=".$sql, LOG_DEBUG);
339 $result = $db->query($sql);
342 $num = $db->num_rows($result);
346 if (!empty($contextpage) && $contextpage !=
$_SERVER[
"PHP_SELF"]) $param .=
'&contextpage='.urlencode($contextpage);
347 if ($limit > 0 && $limit != $conf->liste_limit) $param .=
'&limit='.urlencode($limit);
348 if ($search_ref > 0) $param .=
"&search_desc=".urlencode($search_ref);
349 if ($search_label > 0) $param .=
"&search_desc=".urlencode($search_label);
350 if ($search_desc > 0) $param .=
"&search_desc=".urlencode($search_desc);
351 if ($search_vat > 0) $param .=
'&search_vat='.urlencode($search_vat);
352 if ($search_current_account > 0) $param .=
"&search_current_account=".urlencode($search_current_account);
353 if ($search_current_account_valid && $search_current_account_valid !=
'-1') $param .=
"&search_current_account_valid=".urlencode($search_current_account_valid);
354 if ($accounting_product_mode) $param .=
'&accounting_product_mode='.urlencode($accounting_product_mode);
356 print '<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
357 if ($optioncss !=
'')
print '<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
358 print '<input type="hidden" name="token" value="'.newToken().
'">';
359 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
360 print '<input type="hidden" name="action" value="update">';
361 print '<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
362 print '<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
367 print
'<span class="opacitymedium">'.$langs->trans(
"InitAccountancyDesc").
'</span><br>';
371 print
'<table class="noborder centpercent">';
372 print
'<tr class="liste_titre">';
373 print
'<td>'.$langs->trans(
'Options').
'</td><td>'.$langs->trans(
'Description').
'</td>';
375 print
'<tr class="oddeven"><td><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_SELL"'.($accounting_product_mode ==
'ACCOUNTANCY_SELL' ?
' checked' :
'').
'> '.$langs->trans(
'OptionModeProductSell').
'</td>';
376 print
'<td>'.$langs->trans(
'OptionModeProductSellDesc');
377 print
"</td></tr>\n";
378 if ($mysoc->isInEEC())
380 print
'<tr class="oddeven"><td><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_SELL_INTRA"'.($accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA' ?
' checked' :
'').
'> '.$langs->trans(
'OptionModeProductSellIntra').
'</td>';
381 print
'<td>'.$langs->trans(
'OptionModeProductSellIntraDesc');
382 print
"</td></tr>\n";
384 print
'<tr class="oddeven"><td><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_SELL_EXPORT"'.($accounting_product_mode ==
'ACCOUNTANCY_SELL_EXPORT' ?
' checked' :
'').
'> '.$langs->trans(
'OptionModeProductSellExport').
'</td>';
385 print
'<td>'.$langs->trans(
'OptionModeProductSellExportDesc');
386 print
"</td></tr>\n";
387 print
'<tr class="oddeven"><td><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_BUY"'.($accounting_product_mode ==
'ACCOUNTANCY_BUY' ?
' checked' :
'').
'> '.$langs->trans(
'OptionModeProductBuy').
'</td>';
388 print
'<td>'.$langs->trans(
'OptionModeProductBuyDesc').
"</td></tr>\n";
389 if ($mysoc->isInEEC())
391 print
'<tr class="oddeven"><td><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_BUY_INTRA"'.($accounting_product_mode ==
'ACCOUNTANCY_BUY_INTRA' ?
' checked' :
'').
'> '.$langs->trans(
'OptionModeProductBuyIntra').
'</td>';
392 print
'<td>'.$langs->trans(
'OptionModeProductBuyDesc').
"</td></tr>\n";
394 print
'<tr class="oddeven"><td><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_BUY_EXPORT"'.($accounting_product_mode ==
'ACCOUNTANCY_BUY_EXPORT' ?
' checked' :
'').
'> '.$langs->trans(
'OptionModeProductBuyExport').
'</td>';
395 print
'<td>'.$langs->trans(
'OptionModeProductBuyDesc').
"</td></tr>\n";
398 print
'<div class="center"><input type="submit" class="button" value="'.$langs->trans(
'Refresh').
'" name="changetype"></div>';
405 $varpage = empty($contextpage) ?
$_SERVER[
"PHP_SELF"] : $contextpage;
406 $selectedfields = $form->multiSelectArrayWithCheckbox(
'selectedfields', $arrayfields, $varpage);
408 $buttonsave =
'<input type="submit" class="button button-save" id="changeaccount" name="changeaccount" value="'.$langs->trans(
"Save").
'">';
411 $texte = $langs->trans(
"ListOfProductsServices");
412 print_barre_liste($texte, $page,
$_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $buttonsave, $num, $nbtotalofrecords,
'', 0,
'',
'', $limit, 0, 0, 1);
414 print
'<div class="div-table-responsive">';
415 print
'<table class="liste '.($moreforfilter ?
"listwithfilterbefore" :
"").
'">';
417 print
'<tr class="liste_titre_filter">';
418 print
'<td class="liste_titre"><input type="text" class="flat" size="8" name="search_ref" value="'.dol_escape_htmltag($search_ref).
'"></td>';
419 print
'<td class="liste_titre"><input type="text" class="flat" size="10" name="search_label" value="'.dol_escape_htmltag($search_label).
'"></td>';
420 print
'<td class="liste_titre right"><input type="text" class="flat maxwidth50 right" size="5" name="search_vat" placeholder="%" value="'.dol_escape_htmltag($search_vat).
'"></td>';
422 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>';
424 if ($accounting_product_mode ==
'ACCOUNTANCY_SELL' || $accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA' || $accounting_product_mode ==
'ACCOUNTANCY_SELL_EXPORT') {
425 print
'<td class="liste_titre center">'.$form->selectyesno(
'search_onsell', $search_onsell, 1,
false, 1).
'</td>';
428 elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY' || $accounting_product_mode ==
'ACCOUNTANCY_BUY_INTRA' || $accounting_product_mode ==
'ACCOUNTANCY_BUY_EXPORT') {
429 print
'<td class="liste_titre center">'.$form->selectyesno(
'search_onpurchase', $search_onpurchase, 1,
false, 1).
'</td>';
432 print
'<td class="liste_titre">';
433 print
'<input type="text" class="flat" size="6" name="search_current_account" id="search_current_account" value="'.dol_escape_htmltag($search_current_account).
'">';
434 $listofvals = array(
'withoutvalidaccount'=>$langs->trans(
"WithoutValidAccount"),
'withvalidaccount'=>$langs->trans(
"WithValidAccount"));
435 print
' '.$langs->trans(
"or").
' '.$form->selectarray(
'search_current_account_valid', $listofvals, $search_current_account_valid, 1);
437 print
'<td class="liste_titre"> </td>';
438 print
'<td class="center liste_titre">';
439 $searchpicto = $form->showFilterButtons();
444 print
'<tr class="liste_titre">';
447 if (!empty($conf->global->ACCOUNTANCY_SHOW_PROD_DESC))
print_liste_field_titre(
"Description",
$_SERVER[
"PHP_SELF"],
"p.description",
"", $param,
'', $sortfield, $sortorder);
450 if ($accounting_product_mode ==
'ACCOUNTANCY_SELL') {
452 $fieldtosortaccount =
"p.accountancy_code_sell";
453 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA') {
455 $fieldtosortaccount =
"p.accountancy_code_sell_intra";
456 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL_EXPORT') {
458 $fieldtosortaccount =
"p.accountancy_code_sell_export";
459 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY') {
461 $fieldtosortaccount =
"p.accountancy_code_buy";
462 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_INTRA') {
464 $fieldtosortaccount =
"p.accountancy_code_buy_intra";
465 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_EXPORT') {
467 $fieldtosortaccount =
"p.accountancy_code_buy_export";
471 $clickpitco = $form->showCheckAddButtons(
'checkforselect', 1);
475 $product_static =
new Product($db);
478 while ($i < min($num, $limit))
480 $obj = $db->fetch_object($result);
483 $product_static->ref = $obj->ref;
484 $product_static->id = $obj->rowid;
485 $product_static->type = $obj->product_type;
486 $product_static->label = $obj->label;
487 $product_static->description = $obj->description;
488 $product_static->status = $obj->tosell;
489 $product_static->status_buy = $obj->tobuy;
492 if ($obj->product_type == 0) {
493 if ($accounting_product_mode ==
'ACCOUNTANCY_SELL') {
494 $compta_prodsell = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans(
"CodeNotDef"));
495 $compta_prodsell_id = $aarowid_prodsell;
496 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA') {
497 $compta_prodsell = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT : $langs->trans(
"CodeNotDef"));
498 $compta_prodsell_id = $aarowid_prodsell_intra;
499 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL_EXPORT') {
500 $compta_prodsell = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT : $langs->trans(
"CodeNotDef"));
501 $compta_prodsell_id = $aarowid_prodsell_export;
503 $compta_prodsell = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans(
"CodeNotDef"));
504 $compta_prodsell_id = $aarowid_prodsell;
507 if ($accounting_product_mode ==
'ACCOUNTANCY_SELL') {
508 $compta_prodsell = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans(
"CodeNotDef"));
509 $compta_prodsell_id = $aarowid_servsell;
510 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA') {
511 $compta_prodsell = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT : $langs->trans(
"CodeNotDef"));
512 $compta_prodsell_id = $aarowid_servsell_intra;
513 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL_EXPORT') {
514 $compta_prodsell = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT : $langs->trans(
"CodeNotDef"));
515 $compta_prodsell_id = $aarowid_servsell_export;
517 $compta_prodsell = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans(
"CodeNotDef"));
518 $compta_prodsell_id = $aarowid_servsell;
523 if ($obj->product_type == 0) {
524 if ($accounting_product_mode ==
'ACCOUNTANCY_BUY') {
525 $compta_prodbuy = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : $langs->trans(
"CodeNotDef"));
526 $compta_prodbuy_id = $aarowid_prodbuy;
527 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_INTRA') {
528 $compta_prodbuy = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT : $langs->trans(
"CodeNotDef"));
529 $compta_prodbuy_id = $aarowid_prodbuy_intra;
530 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_EXPORT') {
531 $compta_prodbuy = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT : $langs->trans(
"CodeNotDef"));
532 $compta_prodbuy_id = $aarowid_prodbuy_export;
534 $compta_prodbuy = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : $langs->trans(
"CodeNotDef"));
535 $compta_prodbuy_id = $aarowid_prodbuy;
538 if ($accounting_product_mode ==
'ACCOUNTANCY_BUY') {
539 $compta_prodbuy = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : $langs->trans(
"CodeNotDef"));
540 $compta_prodbuy_id = $aarowid_servbuy;
541 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_INTRA') {
542 $compta_prodbuy = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT : $langs->trans(
"CodeNotDef"));
543 $compta_prodbuy_id = $aarowid_servbuy_intra;
544 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_EXPORT') {
545 $compta_prodbuy = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT : $langs->trans(
"CodeNotDef"));
546 $compta_prodbuy_id = $aarowid_servbuy_export;
548 $compta_prodbuy = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : $langs->trans(
"CodeNotDef"));
549 $compta_prodbuy_id = $aarowid_servbuy;
553 print
'<tr class="oddeven">';
556 print $product_static->getNomUrl(1);
559 print
'<td class="left">'.$obj->label.
'</td>';
561 if (!empty($conf->global->ACCOUNTANCY_SHOW_PROD_DESC))
566 $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
567 print
'<td>'.nl2br(
dol_trunc($obj->description, $trunclength)).
'</td>';
571 print
'<td class="right">';
575 if ($accounting_product_mode ==
'ACCOUNTANCY_SELL' || $accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA' || $accounting_product_mode ==
'ACCOUNTANCY_SELL_EXPORT')
576 print
'<td class="center">'.$product_static->getLibStatut(3, 0).
'</td>';
578 if ($accounting_product_mode ==
'ACCOUNTANCY_BUY' || $accounting_product_mode ==
'ACCOUNTANCY_BUY_INTRA' || $accounting_product_mode ==
'ACCOUNTANCY_BUY_EXPORT')
579 print
'<td class="center">'.$product_static->getLibStatut(3, 1).
'</td>';
582 print
'<td class="left">';
583 if ($accounting_product_mode ==
'ACCOUNTANCY_BUY') {
585 if ($obj->accountancy_code_buy && empty($obj->aaid)) print
' '.img_warning($langs->trans(
"ValueNotIntoChartOfAccount"));
586 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_INTRA') {
588 if ($obj->accountancy_code_buy_intra && empty($obj->aaid)) print
' '.img_warning($langs->trans(
"ValueNotIntoChartOfAccount"));
589 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_EXPORT') {
591 if ($obj->accountancy_code_buy_export && empty($obj->aaid)) print
' '.img_warning($langs->trans(
"ValueNotIntoChartOfAccount"));
592 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL') {
594 if ($obj->accountancy_code_sell && empty($obj->aaid)) print
' '.img_warning($langs->trans(
"ValueNotIntoChartOfAccount"));
595 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA') {
597 if ($obj->accountancy_code_sell_intra && empty($obj->aaid)) print
' '.img_warning($langs->trans(
"ValueNotIntoChartOfAccount"));
600 if ($obj->accountancy_code_sell_export && empty($obj->aaid)) print
' '.img_warning($langs->trans(
"ValueNotIntoChartOfAccount"));
606 if ($accounting_product_mode ==
'ACCOUNTANCY_BUY') {
608 print
'<td class="left">';
610 if (empty($defaultvalue)) $defaultvalue = $compta_prodbuy;
612 if (!empty($obj->aaid)) $defaultvalue =
'';
613 print $form->select_account($defaultvalue,
'codeventil_'.$product_static->id, 1, array(), 1, 0,
'maxwidth300 maxwidthonsmartphone productforselect');
615 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_INTRA') {
617 print
'<td class="left">';
619 if (empty($defaultvalue)) $defaultvalue = $compta_prodbuy;
622 if (!empty($obj->aaid)) $defaultvalue =
'';
623 print $form->select_account($defaultvalue,
'codeventil_'.$product_static->id, 1, array(), 1, 0,
'maxwidth300 maxwidthonsmartphone productforselect');
625 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_EXPORT') {
627 print
'<td class="left">';
629 if (empty($defaultvalue)) $defaultvalue = $compta_prodbuy;
632 if (!empty($obj->aaid)) $defaultvalue =
'';
633 print $form->select_account($defaultvalue,
'codeventil_'.$product_static->id, 1, array(), 1, 0,
'maxwidth300 maxwidthonsmartphone productforselect');
635 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL') {
637 print
'<td class="left">';
639 if (empty($defaultvalue)) $defaultvalue = $compta_prodsell;
642 if (!empty($obj->aaid)) $defaultvalue =
'';
643 print $form->select_account($defaultvalue,
'codeventil_'.$product_static->id, 1, array(), 1, 0,
'maxwidth300 maxwidthonsmartphone productforselect');
645 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA') {
647 print
'<td class="left">';
649 if (empty($defaultvalue)) $defaultvalue = $compta_prodsell;
652 if (!empty($obj->aaid)) $defaultvalue =
'';
653 print $form->select_account($defaultvalue,
'codeventil_'.$product_static->id, 1, array(), 1, 0,
'maxwidth300 maxwidthonsmartphone productforselect');
657 print
'<td class="left">';
659 if (empty($defaultvalue)) $defaultvalue = $compta_prodsell;
661 if (!empty($obj->aaid)) $defaultvalue =
'';
662 print $form->select_account($defaultvalue,
'codeventil_'.$product_static->id, 1, array(), 1, 0,
'maxwidth300 maxwidthonsmartphone productforselect');
667 print
'<td class="center">';
668 print
'<input type="checkbox" class="checkforselect productforselectcodeventil_'.$product_static->id.
'" name="chk_prod[]" value="'.$obj->rowid.
'"/></td>';
675 print
'<script type="text/javascript" language="javascript">
676 jQuery(document).ready(function() {
677 function init_savebutton()
679 console.log("We check if at least one line is checked")
681 atleastoneselected=0;
682 jQuery(".checkforselect").each(function( index ) {
683 /* console.log( index + ": " + $( this ).text() ); */
684 if ($(this).is(\':checked\')) atleastoneselected++;
687 if (atleastoneselected) jQuery("#changeaccount").removeAttr(\'disabled\');
688 else jQuery("#changeaccount").attr(\'disabled\',\'disabled\');
689 if (atleastoneselected) jQuery("#changeaccount").attr(\'class\',\'button\');
690 else jQuery("#changeaccount").attr(\'class\',\'button\');
693 jQuery(".checkforselect").change(function() {
696 jQuery(".productforselect").change(function() {
697 console.log($(this).attr("id")+" "+$(this).val());
698 if ($(this).val() && $(this).val() != -1) {
699 $(".productforselect"+$(this).attr("id")).prop(\'checked\', true);
701 $(".productforselect"+$(this).attr("id")).prop(\'checked\', false);
708 jQuery("#search_current_account").keyup(function() {
709 if (jQuery("#search_current_account").val() != \'\')
711 console.log("We set a value of account to search "+jQuery("#search_current_account").val()+", so we disable the other search criteria on account");
712 jQuery("#search_current_account_valid").val(-1);
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage products or services.
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).
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options= '', $sortfield= '', $sortorder= '', $morehtmlcenter= '', $num=-1, $totalnboflines= '', $picto= 'generic', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow= '')
Print a title with navigation controls for pagination.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
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...
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages...
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_getIdFromCode($db, $key, $tablename, $fieldkey= 'code', $fieldid= 'id', $entityfilter=0)
Return an id or code from a code or id.
print
Draft customers invoices.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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 accounting accounts.
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous) ...