30require
'../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcategory.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
38require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
43$langs->loadLangs(array(
"companies",
"compta",
"accountancy",
"products"));
46$action =
GETPOST(
'action',
'aZ09');
47$massaction =
GETPOST(
'massaction',
'alpha');
48$confirm =
GETPOST(
'confirm',
'alpha');
49$contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') : str_replace(
'_',
'', basename(dirname(__FILE__)).basename(__FILE__,
'.php'));
50$optioncss =
GETPOST(
'optioncss',
'alpha');
52$toselect =
GETPOST(
'chk_prod',
'array:int');
53'@phan-var-force string[] $toselect';
54$default_account =
GETPOSTINT(
'default_account');
55$searchCategoryProductOperator =
GETPOSTINT(
'search_category_product_operator');
56$searchCategoryProductList =
GETPOST(
'search_category_product_list',
'array:int');
57'@phan-var-force string[] $searchCategoryProductList';
58$search_ref =
GETPOST(
'search_ref',
'alpha');
59$search_label =
GETPOST(
'search_label',
'alpha');
60$search_desc =
GETPOST(
'search_desc',
'alpha');
61$search_vat =
GETPOST(
'search_vat',
'alpha');
62$search_current_account =
GETPOST(
'search_current_account',
'alpha');
63$search_current_account_valid =
GETPOST(
'search_current_account_valid',
'alpha');
64if ($search_current_account_valid ==
'') {
65 $search_current_account_valid =
'withoutvalidaccount';
67$search_onsell =
GETPOST(
'search_onsell',
'alpha');
68$search_onpurchase =
GETPOST(
'search_onpurchase',
'alpha');
70if (!is_array($toselect)) {
74$accounting_product_mode =
GETPOST(
'accounting_product_mode',
'alpha');
75$btn_changetype =
GETPOST(
'changetype',
'alpha');
78$show_childproducts = 0;
79if (isModEnabled(
'variants')) {
80 $show_childproducts =
GETPOST(
'search_show_childproducts');
83if (empty($accounting_product_mode)) {
84 $accounting_product_mode =
'ACCOUNTANCY_SELL';
88$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
89$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
91if (empty($page) || $page < 0 ||
GETPOST(
'button_search',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
95$offset = $limit * $page;
109$arrayfields = array();
111$accounting_product_modes = array(
113 'ACCOUNTANCY_SELL_INTRA',
114 'ACCOUNTANCY_SELL_EXPORT',
116 'ACCOUNTANCY_BUY_INTRA',
117 'ACCOUNTANCY_BUY_EXPORT'
120if ($accounting_product_mode ==
'ACCOUNTANCY_BUY') {
121 $accountancy_field_name =
"accountancy_code_buy";
122} elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_INTRA') {
123 $accountancy_field_name =
"accountancy_code_buy_intra";
124} elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_EXPORT') {
125 $accountancy_field_name =
"accountancy_code_buy_export";
126} elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL') {
127 $accountancy_field_name =
"accountancy_code_sell";
128} elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA') {
129 $accountancy_field_name =
"accountancy_code_sell_intra";
131 $accountancy_field_name =
"accountancy_code_sell_export";
135if (!isModEnabled(
'accounting')) {
138if (!$user->hasRight(
'accounting',
'bind',
'write')) {
142$permissiontobind = $user->hasRight(
'accounting',
'bind',
'write');
149if (
GETPOST(
'cancel',
'alpha')) {
153if (!
GETPOST(
'confirmmassaction',
'alpha') && $massaction !=
'presend' && $massaction !=
'confirm_presend') {
157$parameters = array();
158$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
164if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
165 $searchCategoryProductOperator = 0;
166 $searchCategoryProductList = array();
172 $search_onpurchase =
'';
173 $search_current_account =
'';
174 $search_current_account_valid =
'-1';
179if ($action ==
'update' && $permissiontobind) {
180 if (!empty($btn_changetype)) {
183 if (in_array($accounting_product_mode, $accounting_product_modes)) {
184 if (!
dolibarr_set_const($db,
'ACCOUNTING_PRODUCT_MODE', $accounting_product_mode,
'chaine', 0,
'', $conf->entity)) {
192 if (!empty($toselect) && $massaction ===
'changeaccount') {
198 if (!empty($toselect) && in_array($accounting_product_mode, $accounting_product_modes)) {
202 $arrayofdifferentselectedvalues = array();
205 foreach ($toselect as $productid) {
206 $accounting_account_id =
GETPOST(
'codeventil_'.$productid);
209 if ($accounting_account_id > 0) {
210 $arrayofdifferentselectedvalues[$accounting_account_id] = $accounting_account_id;
211 $result = $accounting->fetch($accounting_account_id,
null, 1);
215 $msg .=
'<div><span class="error">'.$langs->trans(
"ErrorDB").
' : '.$langs->trans(
"Product").
' '.$productid.
' '.$langs->trans(
"NotVentilatedinAccount").
' : id='.$accounting_account_id.
'<br> <pre>'.$sql.
'</pre></span></div>';
219 $sql_exists =
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"product_perentity";
220 $sql_exists .=
" WHERE fk_product = " . ((int) $productid) .
" AND entity = " . ((int) $conf->entity);
221 $resql_exists = $db->query($sql_exists);
222 if (!$resql_exists) {
223 $msg .=
'<div><span class="error">'.$langs->trans(
"ErrorDB").
' : '.$langs->trans(
"Product").
' '.$productid.
' '.$langs->trans(
"NotVentilatedinAccount").
' : id='.$accounting_account_id.
'<br> <pre>'.json_encode($resql_exists).
'</pre></span></div>';
226 $nb_exists = $db->num_rows($resql_exists);
227 if ($nb_exists <= 0) {
229 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"product_perentity (fk_product, entity, " . $db->sanitize($accountancy_field_name) .
")";
230 $sql .=
" VALUES (" . ((int) $productid) .
", " . ((int) $conf->entity) .
", '" . $db->escape($accounting->account_number) .
"')";
232 $obj_exists = $db->fetch_object($resql_exists);
234 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"product_perentity";
235 $sql .=
" SET " . $db->sanitize($accountancy_field_name) .
" = '" . $db->escape($accounting->account_number) .
"'";
236 $sql .=
" WHERE rowid = " . ((int) $obj_exists->rowid);
240 $sql =
" UPDATE ".MAIN_DB_PREFIX.
"product";
241 $sql .=
" SET ".$db->sanitize($accountancy_field_name).
" = '".$db->escape($accounting->account_number).
"'";
242 $sql .=
" WHERE rowid = ".((int) $productid);
245 dol_syslog(
"/accountancy/admin/productaccount.php", LOG_DEBUG);
249 if ($db->query($sql)) {
263 setEventMessages($langs->trans(
"XLineFailedToBeBinded", $ko),
null,
'errors');
266 setEventMessages($langs->trans(
"XLineSuccessfullyBinded", $ok),
null,
'mesgs');
278'@phan-var-force string[] $toselect';
285$aarowid_servbuy = $accounting->fetch(0,
getDolGlobalString(
'ACCOUNTING_SERVICE_BUY_ACCOUNT'), 1);
286$aarowid_servbuy_intra = $accounting->fetch(0,
getDolGlobalString(
'ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT'), 1);
287$aarowid_servbuy_export = $accounting->fetch(0,
getDolGlobalString(
'ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT'), 1);
288$aarowid_prodbuy = $accounting->fetch(0,
getDolGlobalString(
'ACCOUNTING_PRODUCT_BUY_ACCOUNT'), 1);
289$aarowid_prodbuy_intra = $accounting->fetch(0,
getDolGlobalString(
'ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT'), 1);
290$aarowid_prodbuy_export = $accounting->fetch(0,
getDolGlobalString(
'ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT'), 1);
291$aarowid_servsell = $accounting->fetch(0,
getDolGlobalString(
'ACCOUNTING_SERVICE_SOLD_ACCOUNT'), 1);
292$aarowid_servsell_intra = $accounting->fetch(0,
getDolGlobalString(
'ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT'), 1);
293$aarowid_servsell_export = $accounting->fetch(0,
getDolGlobalString(
'ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT'), 1);
294$aarowid_prodsell = $accounting->fetch(0,
getDolGlobalString(
'ACCOUNTING_PRODUCT_SOLD_ACCOUNT'), 1);
295$aarowid_prodsell_intra = $accounting->fetch(0,
getDolGlobalString(
'ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT'), 1);
296$aarowid_prodsell_export = $accounting->fetch(0,
getDolGlobalString(
'ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT'), 1);
298$aacompta_servbuy =
getDolGlobalString(
'ACCOUNTING_SERVICE_BUY_ACCOUNT', $langs->trans(
"CodeNotDef"));
299$aacompta_servbuy_intra =
getDolGlobalString(
'ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT', $langs->trans(
"CodeNotDef"));
300$aacompta_servbuy_export =
getDolGlobalString(
'ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT', $langs->trans(
"CodeNotDef"));
301$aacompta_prodbuy =
getDolGlobalString(
'ACCOUNTING_PRODUCT_BUY_ACCOUNT', $langs->trans(
"CodeNotDef"));
302$aacompta_prodbuy_intra =
getDolGlobalString(
'ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT', $langs->trans(
"CodeNotDef"));
303$aacompta_prodbuy_export =
getDolGlobalString(
'ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT', $langs->trans(
"CodeNotDef"));
304$aacompta_servsell =
getDolGlobalString(
'ACCOUNTING_SERVICE_SOLD_ACCOUNT', $langs->trans(
"CodeNotDef"));
305$aacompta_servsell_intra =
getDolGlobalString(
'ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT', $langs->trans(
"CodeNotDef"));
306$aacompta_servsell_export =
getDolGlobalString(
'ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT', $langs->trans(
"CodeNotDef"));
307$aacompta_prodsell =
getDolGlobalString(
'ACCOUNTING_PRODUCT_SOLD_ACCOUNT', $langs->trans(
"CodeNotDef"));
308$aacompta_prodsell_intra =
getDolGlobalString(
'ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT', $langs->trans(
"CodeNotDef"));
309$aacompta_prodsell_export =
getDolGlobalString(
'ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT', $langs->trans(
"CodeNotDef"));
312$title = $langs->trans(
"ProductsBinding");
313$help_url =
'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilité_en_Partie_Double#Configuration';
316foreach ($searchCategoryProductList as $searchCategoryProduct) {
317 $paramsCat .=
"&search_category_product_list[]=".urlencode($searchCategoryProduct);
320llxHeader(
'', $title, $help_url,
'', 0, 0, array(), array(), $paramsCat,
'');
323$pcgvercode =
dol_getIdFromCode($db, $pcgverid,
'accounting_system',
'rowid',
'pcg_version');
324if (empty($pcgvercode)) {
325 $pcgvercode = $pcgverid;
328$sql =
"SELECT p.rowid, p.ref, p.label, p.description, p.tosell, p.tobuy, p.tva_tx,";
330 $sql .=
" ppe.accountancy_code_sell, ppe.accountancy_code_sell_intra, ppe.accountancy_code_sell_export,";
331 $sql .=
" ppe.accountancy_code_buy, ppe.accountancy_code_buy_intra, ppe.accountancy_code_buy_export,";
333 $sql .=
" p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export,";
334 $sql .=
" p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export,";
336$sql .=
" p.tms, p.fk_product_type as product_type,";
337$sql .=
" aa.rowid as aaid";
338$sql .=
" FROM ".MAIN_DB_PREFIX.
"product as p";
340 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
341 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"accounting_account as aa ON aa.account_number = ppe." . $db->sanitize($accountancy_field_name) .
" AND aa.fk_pcg_version = '" . $db->escape($pcgvercode) .
"'";
343 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"accounting_account as aa ON aa.account_number = p." . $db->sanitize($accountancy_field_name) .
" AND aa.fk_pcg_version = '" . $db->escape($pcgvercode) .
"'";
345if (!empty($searchCategoryProductList)) {
346 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
"categorie_product as cp ON p.rowid = cp.fk_product";
348$sql .=
' WHERE p.entity IN ('.getEntity(
'product').
')';
349if (strlen(trim($search_current_account))) {
350 $sql .=
natural_search((!
getDolGlobalString(
'MAIN_PRODUCT_PERENTITY_SHARED') ?
"p." :
"ppe.") . $db->sanitize($accountancy_field_name), $search_current_account);
352if ($search_current_account_valid ==
'withoutvalidaccount') {
353 $sql .=
" AND aa.account_number IS NULL";
355if ($search_current_account_valid ==
'withvalidaccount') {
356 $sql .=
" AND aa.account_number IS NOT NULL";
358$searchCategoryProductSqlList = array();
359if ($searchCategoryProductOperator == 1) {
360 foreach ($searchCategoryProductList as $searchCategoryProduct) {
361 if (intval($searchCategoryProduct) == -2) {
362 $searchCategoryProductSqlList[] =
"cp.fk_categorie IS NULL";
363 } elseif (intval($searchCategoryProduct) > 0) {
364 $searchCategoryProductSqlList[] =
"cp.fk_categorie = ".((int) $searchCategoryProduct);
367 if (!empty($searchCategoryProductSqlList)) {
368 $sql .=
" AND (".implode(
' OR ', $searchCategoryProductSqlList).
")";
371 foreach ($searchCategoryProductList as $searchCategoryProduct) {
372 if (intval($searchCategoryProduct) == -2) {
373 $searchCategoryProductSqlList[] =
"cp.fk_categorie IS NULL";
374 } elseif (intval($searchCategoryProduct) > 0) {
375 $searchCategoryProductSqlList[] =
"p.rowid IN (SELECT fk_product FROM ".MAIN_DB_PREFIX.
"categorie_product WHERE fk_categorie = ".((int) $searchCategoryProduct).
")";
378 if (!empty($searchCategoryProductSqlList)) {
379 $sql .=
" AND (".implode(
' AND ', $searchCategoryProductSqlList).
")";
383if (strlen(trim($search_ref))) {
386if (strlen(trim($search_label))) {
389if (strlen(trim($search_desc))) {
392if (strlen(trim($search_vat))) {
395if ($search_onsell !=
'' && $search_onsell !=
'-1') {
398if ($search_onpurchase !=
'' && $search_onpurchase !=
'-1') {
402$sql .=
" GROUP BY p.rowid, p.ref, p.label, p.description, p.tosell, p.tobuy, p.tva_tx,";
403$sql .=
" p.fk_product_type,";
407 $sql .=
" p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export, p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export";
409 $sql .=
" ppe.accountancy_code_sell, ppe.accountancy_code_sell_intra, ppe.accountancy_code_sell_export, ppe.accountancy_code_buy, ppe.accountancy_code_buy_intra, ppe.accountancy_code_buy_export";
412$sql .= $db->order($sortfield, $sortorder);
414$nbtotalofrecords =
'';
416 $resql = $db->query($sql);
417 $nbtotalofrecords = $db->num_rows($resql);
418 if (($page * $limit) > $nbtotalofrecords) {
424$sql .= $db->plimit($limit + 1, $offset);
426dol_syslog(
"/accountancy/admin/productaccount.php", LOG_DEBUG);
427$resql = $db->query($sql);
429 $num = $db->num_rows($resql);
433 if (!empty($contextpage) && $contextpage != $_SERVER[
"PHP_SELF"]) {
434 $param .=
'&contextpage='.urlencode($contextpage);
436 if ($limit > 0 && $limit != $conf->liste_limit) {
437 $param .=
'&limit='.((int) $limit);
439 if ($searchCategoryProductOperator == 1) {
440 $param .=
"&search_category_product_operator=".urlencode((
string) ($searchCategoryProductOperator));
442 foreach ($searchCategoryProductList as $searchCategoryProduct) {
443 $param .=
"&search_category_product_list[]=".urlencode($searchCategoryProduct);
445 if ($search_ref > 0) {
446 $param .=
"&search_ref=".urlencode($search_ref);
448 if ($search_label > 0) {
449 $param .=
"&search_label=".urlencode($search_label);
451 if ($search_desc > 0) {
452 $param .=
"&search_desc=".urlencode($search_desc);
454 if ($search_vat > 0) {
455 $param .=
'&search_vat='.urlencode($search_vat);
457 if ($search_current_account > 0) {
458 $param .=
"&search_current_account=".urlencode($search_current_account);
460 if ($search_current_account_valid && $search_current_account_valid !=
'-1') {
461 $param .=
"&search_current_account_valid=".urlencode($search_current_account_valid);
463 if ($accounting_product_mode) {
464 $param .=
'&accounting_product_mode='.urlencode($accounting_product_mode);
467 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
468 if ($optioncss !=
'') {
469 print
'<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
471 print
'<input type="hidden" name="token" value="'.newToken().
'">';
472 print
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
473 print
'<input type="hidden" name="action" value="update">';
474 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
475 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
476 print
'<input type="hidden" name="page_y" value="">';
478 print
load_fiche_titre($langs->trans(
"ProductsBinding"),
'',
'title_accountancy');
481 print
'<span class="opacitymedium">'.$langs->trans(
"InitAccountancyDesc").
'</span><br>';
485 print
'<table class="noborder centpercent">';
486 print
'<tr class="liste_titre">';
487 print
'<td>'.$langs->trans(
'Options').
'</td><td>'.$langs->trans(
'Description').
'</td>';
489 print
'<tr class="oddeven"><td><input type="radio" id="accounting_product_mode1" name="accounting_product_mode" value="ACCOUNTANCY_SELL"'.($accounting_product_mode ==
'ACCOUNTANCY_SELL' ?
' checked' :
'').
'> <label for="accounting_product_mode1">'.$langs->trans(
'OptionModeProductSell').
'</label></td>';
490 print
'<td>'.$langs->trans(
'OptionModeProductSellDesc');
491 print
"</td></tr>\n";
492 if ($mysoc->isInEEC()) {
493 print
'<tr class="oddeven"><td><input type="radio" id="accounting_product_mode2" name="accounting_product_mode" value="ACCOUNTANCY_SELL_INTRA"'.($accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA' ?
' checked' :
'').
'> <label for="accounting_product_mode2">'.$langs->trans(
'OptionModeProductSellIntra').
'</label></td>';
494 print
'<td>'.$langs->trans(
'OptionModeProductSellIntraDesc');
495 print
"</td></tr>\n";
497 print
'<tr class="oddeven"><td><input type="radio" id="accounting_product_mode3" name="accounting_product_mode" value="ACCOUNTANCY_SELL_EXPORT"'.($accounting_product_mode ==
'ACCOUNTANCY_SELL_EXPORT' ?
' checked' :
'').
'> <label for="accounting_product_mode3">'.$langs->trans(
'OptionModeProductSellExport').
'</label></td>';
498 print
'<td>'.$langs->trans(
'OptionModeProductSellExportDesc');
499 print
"</td></tr>\n";
500 print
'<tr class="oddeven"><td><input type="radio" id="accounting_product_mode4" name="accounting_product_mode" value="ACCOUNTANCY_BUY"'.($accounting_product_mode ==
'ACCOUNTANCY_BUY' ?
' checked' :
'').
'> <label for="accounting_product_mode4">'.$langs->trans(
'OptionModeProductBuy').
'</label></td>';
501 print
'<td>'.$langs->trans(
'OptionModeProductBuyDesc').
"</td></tr>\n";
502 if ($mysoc->isInEEC()) {
503 print
'<tr class="oddeven"><td><input type="radio" id="accounting_product_mode5" name="accounting_product_mode" value="ACCOUNTANCY_BUY_INTRA"'.($accounting_product_mode ==
'ACCOUNTANCY_BUY_INTRA' ?
' checked' :
'').
'> <label for="accounting_product_mode5">'.$langs->trans(
'OptionModeProductBuyIntra').
'</label></td>';
504 print
'<td>'.$langs->trans(
'OptionModeProductBuyDesc').
"</td></tr>\n";
506 print
'<tr class="oddeven"><td><input type="radio" id="accounting_product_mode6" name="accounting_product_mode" value="ACCOUNTANCY_BUY_EXPORT"'.($accounting_product_mode ==
'ACCOUNTANCY_BUY_EXPORT' ?
' checked' :
'').
'> <label for="accounting_product_mode6">'.$langs->trans(
'OptionModeProductBuyExport').
'</label></td>';
507 print
'<td>'.$langs->trans(
'OptionModeProductBuyDesc').
"</td></tr>\n";
510 print
'<div class="center"><input type="submit" class="button" value="'.$langs->trans(
'Refresh').
'" name="changetype"></div>';
517 $varpage = empty($contextpage) ? $_SERVER[
"PHP_SELF"] : $contextpage;
518 $selectedfields = $form->multiSelectArrayWithCheckbox(
'selectedfields', $arrayfields, $varpage);
520 $massactionbutton =
'';
522 $nbselected = count($toselect);
523 if ($massaction ==
'set_default_account') {
524 if ($nbselected <= 0) {
525 $langs->load(
"errors");
532 if ($massaction !==
'set_default_account') {
533 $arrayofmassactions = array(
534 'set_default_account' =>
img_picto(
'',
'check',
'class="pictofixedwidth"').$langs->trans(
"ConfirmPreselectAccount"),
535 'changeaccount' =>
img_picto(
'',
'check',
'class="pictofixedwidth"').$langs->trans(
"Save")
537 $massactionbutton = $form->selectMassAction(
'', $arrayofmassactions, 1);
543 $texte = $langs->trans(
"ListOfProductsServices");
544 print_barre_liste($texte, $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords,
'', 0,
'',
'', $limit, 0, 0, 1);
546 if ($massaction ==
'set_default_account') {
547 $formquestion = array();
548 $formquestion[] = array(
'type' =>
'other',
549 'name' =>
'set_default_account',
550 'label' => $langs->trans(
"AccountancyCode"),
551 'value' => $form->select_account(
'',
'default_account', 1, array(), 0, 0,
'maxwidth200 maxwidthonsmartphone',
'cachewithshowemptyone'));
552 print $form->formconfirm($_SERVER[
"PHP_SELF"], $langs->trans(
"ConfirmPreselectAccount"), $langs->trans(
"ConfirmPreselectAccountQuestion", $nbselected),
"confirm_set_default_account", $formquestion, 1, 0, 200, 500, 1);
557 if (isModEnabled(
'category') && $user->hasRight(
'categorie',
'lire')) {
559 $moreforfilter .= $formcategory->getFilterBox(Categorie::TYPE_PRODUCT, $searchCategoryProductList,
'minwidth300', $searchCategoryProductList ? $searchCategoryProductList : 0);
563 if (isModEnabled(
'variants') &&
getDolGlobalInt(
'PRODUIT_ATTRIBUTES_HIDECHILD')) {
564 $moreforfilter .=
'<div class="divsearchfield">';
565 $moreforfilter .=
'<input type="checkbox" id="search_show_childproducts" name="search_show_childproducts"'.($show_childproducts ?
'checked="checked"' :
'').
'>';
566 $moreforfilter .=
' <label for="search_show_childproducts">'.$langs->trans(
'ShowChildProducts').
'</label>';
567 $moreforfilter .=
'</div>';
570 $parameters = array();
571 $reshook = $hookmanager->executeHooks(
'printFieldPreListTitle', $parameters,
$object, $action);
572 if (empty($reshook)) {
573 $moreforfilter .= $hookmanager->resPrint;
575 $moreforfilter = $hookmanager->resPrint;
578 if ($moreforfilter) {
579 print
'<div class="liste_titre liste_titre_bydiv centpercent">';
580 print $moreforfilter;
584 print
'<div class="div-table-responsive">';
585 print
'<table class="liste '.($moreforfilter ?
"listwithfilterbefore" :
"").
'">';
587 print
'<tr class="liste_titre_filter">';
590 print
'<td class="center liste_titre">';
591 $searchpicto = $form->showFilterButtons();
595 print
'<td class="liste_titre"><input type="text" class="flat" size="8" name="search_ref" value="'.dol_escape_htmltag($search_ref).
'"></td>';
596 print
'<td class="liste_titre"><input type="text" class="flat" size="10" name="search_label" value="'.dol_escape_htmltag($search_label).
'"></td>';
597 print
'<td class="liste_titre right"><input type="text" class="flat maxwidth50 right" name="search_vat" placeholder="%" value="'.dol_escape_htmltag($search_vat).
'"></td>';
600 print
'<td class="liste_titre"><input type="text" class="flat" size="20" name="search_desc" value="'.dol_escape_htmltag($search_desc).
'"></td>';
603 if ($accounting_product_mode ==
'ACCOUNTANCY_SELL' || $accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA' || $accounting_product_mode ==
'ACCOUNTANCY_SELL_EXPORT') {
604 print
'<td class="liste_titre center">'.$form->selectyesno(
'search_onsell', $search_onsell, 1,
false, 1, 1).
'</td>';
607 print
'<td class="liste_titre center">'.$form->selectyesno(
'search_onpurchase', $search_onpurchase, 1,
false, 1, 1).
'</td>';
610 print
'<td class="liste_titre">';
611 print
'<input type="text" class="flat" size="6" name="search_current_account" id="search_current_account" value="'.dol_escape_htmltag($search_current_account).
'">';
612 $listofvals = array(
'withoutvalidaccount' => $langs->trans(
"WithoutValidAccount"),
'withvalidaccount' => $langs->trans(
"WithValidAccount"));
613 print
' '.$langs->trans(
"or").
' '.$form->selectarray(
'search_current_account_valid', $listofvals, $search_current_account_valid, 1);
615 print
'<td class="liste_titre"> </td>';
618 print
'<td class="center liste_titre">';
619 $searchpicto = $form->showFilterButtons();
625 print
'<tr class="liste_titre">';
628 $clickpitco = $form->showCheckAddButtons(
'checkforselect', 1);
634 print_liste_field_titre(
"Description", $_SERVER[
"PHP_SELF"],
"p.description",
"", $param,
'', $sortfield, $sortorder);
636 print_liste_field_titre(
"VATRate", $_SERVER[
"PHP_SELF"],
"p.tva_tx",
"", $param,
'', $sortfield, $sortorder,
'right ');
638 if ($accounting_product_mode ==
'ACCOUNTANCY_SELL' || $accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA' || $accounting_product_mode ==
'ACCOUNTANCY_SELL_EXPORT') {
639 print_liste_field_titre(
"OnSell", $_SERVER[
"PHP_SELF"],
"p.tosell",
"", $param,
'', $sortfield, $sortorder,
'center ');
641 print_liste_field_titre(
"OnBuy", $_SERVER[
"PHP_SELF"],
"p.tobuy",
"", $param,
'', $sortfield, $sortorder,
'center ');
643 print_liste_field_titre(
"CurrentDedicatedAccountingAccount", $_SERVER[
"PHP_SELF"], (!
getDolGlobalString(
'MAIN_PRODUCT_PERENTITY_SHARED') ?
"p." :
"ppe.") . $accountancy_field_name,
"", $param,
'', $sortfield, $sortorder);
647 $clickpitco = $form->showCheckAddButtons(
'checkforselect', 1);
652 $product_static =
new Product($db);
655 while ($i < min($num, $limit)) {
656 $obj = $db->fetch_object($resql);
659 $product_static->ref = $obj->ref;
660 $product_static->id = $obj->rowid;
661 $product_static->type = $obj->product_type;
662 $product_static->label = $obj->label;
663 $product_static->description = $obj->description;
664 $product_static->status = $obj->tosell;
665 $product_static->status_buy = $obj->tobuy;
668 if ($obj->product_type == 0) {
669 if ($accounting_product_mode ==
'ACCOUNTANCY_SELL') {
670 $compta_prodsell =
getDolGlobalString(
'ACCOUNTING_PRODUCT_SOLD_ACCOUNT', $langs->trans(
"CodeNotDef"));
671 $compta_prodsell_id = $aarowid_prodsell;
672 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA') {
673 $compta_prodsell =
getDolGlobalString(
'ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT', $langs->trans(
"CodeNotDef"));
674 $compta_prodsell_id = $aarowid_prodsell_intra;
675 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL_EXPORT') {
676 $compta_prodsell =
getDolGlobalString(
'ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT', $langs->trans(
"CodeNotDef"));
677 $compta_prodsell_id = $aarowid_prodsell_export;
679 $compta_prodsell =
getDolGlobalString(
'ACCOUNTING_PRODUCT_SOLD_ACCOUNT', $langs->trans(
"CodeNotDef"));
680 $compta_prodsell_id = $aarowid_prodsell;
683 if ($accounting_product_mode ==
'ACCOUNTANCY_SELL') {
684 $compta_prodsell =
getDolGlobalString(
'ACCOUNTING_SERVICE_SOLD_ACCOUNT', $langs->trans(
"CodeNotDef"));
685 $compta_prodsell_id = $aarowid_servsell;
686 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA') {
687 $compta_prodsell =
getDolGlobalString(
'ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT', $langs->trans(
"CodeNotDef"));
688 $compta_prodsell_id = $aarowid_servsell_intra;
689 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL_EXPORT') {
690 $compta_prodsell =
getDolGlobalString(
'ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT', $langs->trans(
"CodeNotDef"));
692 $compta_prodsell_id = $aarowid_servsell_export;
694 $compta_prodsell =
getDolGlobalString(
'ACCOUNTING_SERVICE_SOLD_ACCOUNT', $langs->trans(
"CodeNotDef"));
695 $compta_prodsell_id = $aarowid_servsell;
700 if ($obj->product_type == 0) {
701 if ($accounting_product_mode ==
'ACCOUNTANCY_BUY') {
702 $compta_prodbuy =
getDolGlobalString(
'ACCOUNTING_PRODUCT_BUY_ACCOUNT', $langs->trans(
"CodeNotDef"));
703 $compta_prodbuy_id = $aarowid_prodbuy;
704 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_INTRA') {
705 $compta_prodbuy =
getDolGlobalString(
'ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT', $langs->trans(
"CodeNotDef"));
706 $compta_prodbuy_id = $aarowid_prodbuy_intra;
707 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_EXPORT') {
708 $compta_prodbuy =
getDolGlobalString(
'ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT', $langs->trans(
"CodeNotDef"));
709 $compta_prodbuy_id = $aarowid_prodbuy_export;
711 $compta_prodbuy =
getDolGlobalString(
'ACCOUNTING_PRODUCT_BUY_ACCOUNT', $langs->trans(
"CodeNotDef"));
712 $compta_prodbuy_id = $aarowid_prodbuy;
715 if ($accounting_product_mode ==
'ACCOUNTANCY_BUY') {
716 $compta_prodbuy =
getDolGlobalString(
'ACCOUNTING_SERVICE_BUY_ACCOUNT', $langs->trans(
"CodeNotDef"));
717 $compta_prodbuy_id = $aarowid_servbuy;
718 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_INTRA') {
719 $compta_prodbuy =
getDolGlobalString(
'ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT', $langs->trans(
"CodeNotDef"));
720 $compta_prodbuy_id = $aarowid_servbuy_intra;
721 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_EXPORT') {
722 $compta_prodbuy =
getDolGlobalString(
'ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT', $langs->trans(
"CodeNotDef"));
723 $compta_prodbuy_id = $aarowid_servbuy_export;
725 $compta_prodbuy =
getDolGlobalString(
'ACCOUNTING_SERVICE_BUY_ACCOUNT', $langs->trans(
"CodeNotDef"));
726 $compta_prodbuy_id = $aarowid_servbuy;
731 if (in_array($product_static->id, $toselect)) {
735 print
'<tr class="oddeven">';
739 print
'<td class="center">';
740 print
'<input type="checkbox" class="checkforselect productforselectcodeventil_'.$product_static->id.
'" name="chk_prod[]" '.($selected ?
"checked" :
"").
' value="'.$obj->rowid.
'"/>';
745 print $product_static->getNomUrl(1);
748 print
'<td class="left">'.$obj->label.
'</td>';
755 print
'<td>'.nl2br(
dol_trunc($obj->description, $trunclength)).
'</td>';
759 print
'<td class="right">';
764 if ($accounting_product_mode ==
'ACCOUNTANCY_SELL' || $accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA' || $accounting_product_mode ==
'ACCOUNTANCY_SELL_EXPORT') {
765 print
'<td class="center">'.$product_static->getLibStatut(3, 0).
'</td>';
767 print
'<td class="center">'.$product_static->getLibStatut(3, 1).
'</td>';
771 print
'<td class="left">';
772 if ($accounting_product_mode ==
'ACCOUNTANCY_BUY') {
774 if ($obj->accountancy_code_buy && empty($obj->aaid)) {
775 print
' '.img_warning($langs->trans(
"ValueNotIntoChartOfAccount"));
777 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_INTRA') {
779 if ($obj->accountancy_code_buy_intra && empty($obj->aaid)) {
780 print
' '.img_warning($langs->trans(
"ValueNotIntoChartOfAccount"));
782 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_EXPORT') {
784 if ($obj->accountancy_code_buy_export && empty($obj->aaid)) {
785 print
' '.img_warning($langs->trans(
"ValueNotIntoChartOfAccount"));
787 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL') {
789 if ($obj->accountancy_code_sell && empty($obj->aaid)) {
790 print
' '.img_warning($langs->trans(
"ValueNotIntoChartOfAccount"));
792 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA') {
794 if ($obj->accountancy_code_sell_intra && empty($obj->aaid)) {
795 print
' '.img_warning($langs->trans(
"ValueNotIntoChartOfAccount"));
799 if ($obj->accountancy_code_sell_export && empty($obj->aaid)) {
800 print
' '.img_warning($langs->trans(
"ValueNotIntoChartOfAccount"));
807 if ($accounting_product_mode ==
'ACCOUNTANCY_BUY') {
809 print
'<td class="left">';
811 if (empty($defaultvalue)) {
812 $defaultvalue = $compta_prodbuy;
815 if (!empty($obj->aaid)) {
818 print $form->select_account(($default_account > 0 && $confirm ===
'yes' && in_array($product_static->id, $toselect)) ? $default_account : $defaultvalue,
'codeventil_'.$product_static->id, 1, array(), 1, 0,
'maxwidth300 maxwidthonsmartphone productforselect');
820 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_INTRA') {
822 print
'<td class="left">';
824 if (empty($defaultvalue)) {
825 $defaultvalue = $compta_prodbuy;
829 if (!empty($obj->aaid)) {
832 print $form->select_account(($default_account > 0 && $confirm ===
'yes' && in_array($product_static->id, $toselect)) ? $default_account : $defaultvalue,
'codeventil_'.$product_static->id, 1, array(), 1, 0,
'maxwidth300 maxwidthonsmartphone productforselect');
834 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_EXPORT') {
836 print
'<td class="left">';
838 if (empty($defaultvalue)) {
839 $defaultvalue = $compta_prodbuy;
843 if (!empty($obj->aaid)) {
846 print $form->select_account(($default_account > 0 && $confirm ===
'yes' && in_array($product_static->id, $toselect)) ? $default_account : $defaultvalue,
'codeventil_'.$product_static->id, 1, array(), 1, 0,
'maxwidth300 maxwidthonsmartphone productforselect');
848 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL') {
850 print
'<td class="left">';
852 if (empty($defaultvalue)) {
853 $defaultvalue = $compta_prodsell;
857 if (!empty($obj->aaid)) {
860 print $form->select_account(($default_account > 0 && $confirm ===
'yes' && in_array($product_static->id, $toselect)) ? $default_account : $defaultvalue,
'codeventil_'.$product_static->id, 1, array(), 1, 0,
'maxwidth300 maxwidthonsmartphone productforselect');
862 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA') {
864 print
'<td class="left">';
866 if (empty($defaultvalue)) {
867 $defaultvalue = $compta_prodsell;
871 if (!empty($obj->aaid)) {
874 print $form->select_account(($default_account > 0 && $confirm ===
'yes' && in_array($product_static->id, $toselect)) ? $default_account : $defaultvalue,
'codeventil_'.$product_static->id, 1, array(), 1, 0,
'maxwidth300 maxwidthonsmartphone productforselect');
878 print
'<td class="left">';
880 if (empty($defaultvalue)) {
881 $defaultvalue = $compta_prodsell;
884 if (!empty($obj->aaid)) {
887 print $form->select_account(($default_account > 0 && $confirm ===
'yes' && in_array($product_static->id, $toselect)) ? $default_account : $defaultvalue,
'codeventil_'.$product_static->id, 1, array(), 1, 0,
'maxwidth300 maxwidthonsmartphone productforselect');
893 print
'<td class="center">';
894 print
'<input type="checkbox" class="checkforselect productforselectcodeventil_'.$product_static->id.
'" name="chk_prod[]" '.($selected ?
"checked" :
"").
' value="'.$obj->rowid.
'"/>';
904 print
'<script type="text/javascript">
905 jQuery(document).ready(function() {
906 function init_savebutton()
908 console.log("We check if at least one line is checked")
910 atleastoneselected=0;
911 jQuery(".checkforselect").each(function( index ) {
912 /* console.log( index + ": " + $( this ).text() ); */
913 if ($(this).is(\':checked\')) atleastoneselected++;
916 if (atleastoneselected) jQuery("#changeaccount").removeAttr(\'disabled\');
917 else jQuery("#changeaccount").attr(\'disabled\',\'disabled\');
918 if (atleastoneselected) jQuery("#changeaccount").attr(\'class\',\'button\');
919 else jQuery("#changeaccount").attr(\'class\',\'button\');
922 jQuery(".checkforselect").change(function() {
925 jQuery(".productforselect").change(function() {
926 console.log($(this).attr("id")+" "+$(this).val());
927 if ($(this).val() && $(this).val() != -1) {
928 $(".productforselect"+$(this).attr("id")).prop(\'checked\', true);
930 $(".productforselect"+$(this).attr("id")).prop(\'checked\', false);
937 jQuery("#search_current_account").keyup(function() {
938 if (jQuery("#search_current_account").val() != \'\')
940 console.log("We set a value of account to search "+jQuery("#search_current_account").val()+", so we disable the other search criteria on account");
941 jQuery("#search_current_account_valid").val(-1);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
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).
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage accounting accounts.
Class to manage products or services.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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.