28require
'../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
37if (isModEnabled(
'categorie')) {
38 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
42$langs->loadLangs(array(
"companies",
"compta",
"accountancy",
"products"));
45if (!isModEnabled(
'accounting')) {
48if (!$user->hasRight(
'accounting',
'bind',
'write')) {
53$action =
GETPOST(
'action',
'aZ09');
54$massaction =
GETPOST(
'massaction',
'alpha');
55$confirm =
GETPOST(
'confirm',
'alpha');
56$optioncss =
GETPOST(
'optioncss',
'alpha');
58$codeventil_buy =
GETPOST(
'codeventil_buy',
'array');
59$codeventil_sell =
GETPOST(
'codeventil_sell',
'array');
60$chk_prod =
GETPOST(
'chk_prod',
'array');
61$default_account =
GETPOST(
'default_account',
'int');
62$account_number_buy =
GETPOST(
'account_number_buy');
63$account_number_sell =
GETPOST(
'account_number_sell');
64$changeaccount =
GETPOST(
'changeaccount',
'array');
65$changeaccount_buy =
GETPOST(
'changeaccount_buy',
'array');
66$changeaccount_sell =
GETPOST(
'changeaccount_sell',
'array');
67$searchCategoryProductOperator = (
GETPOST(
'search_category_product_operator',
'int') ?
GETPOST(
'search_category_product_operator',
'int') : 0);
68$searchCategoryProductList =
GETPOST(
'search_category_product_list',
'array');
69$search_ref =
GETPOST(
'search_ref',
'alpha');
70$search_label =
GETPOST(
'search_label',
'alpha');
71$search_desc =
GETPOST(
'search_desc',
'alpha');
72$search_vat =
GETPOST(
'search_vat',
'alpha');
73$search_current_account =
GETPOST(
'search_current_account',
'alpha');
74$search_current_account_valid =
GETPOST(
'search_current_account_valid',
'alpha');
75if ($search_current_account_valid ==
'') {
76 $search_current_account_valid =
'withoutvalidaccount';
78$search_onsell =
GETPOST(
'search_onsell',
'alpha');
79$search_onpurchase =
GETPOST(
'search_onpurchase',
'alpha');
81$accounting_product_mode =
GETPOST(
'accounting_product_mode',
'alpha');
82$btn_changetype =
GETPOST(
'changetype',
'alpha');
84if (empty($accounting_product_mode)) {
85 $accounting_product_mode =
'ACCOUNTANCY_SELL';
89$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
90$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
91$page = GETPOSTISSET(
'pageplusone') ? (
GETPOST(
'pageplusone') - 1) :
GETPOST(
"page",
'int');
92if (empty($page) || $page == -1) {
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";
138if (
GETPOST(
'cancel',
'alpha')) {
142if (!
GETPOST(
'confirmmassaction',
'alpha') && $massaction !=
'presend' && $massaction !=
'confirm_presend') {
146$parameters = array();
147$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
153if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
154 $searchCategoryProductOperator = 0;
155 $searchCategoryProductList = array();
161 $search_onpurchase =
'';
162 $search_current_account =
'';
163 $search_current_account_valid =
'-1';
167if ($action ==
'update') {
168 if (!empty($btn_changetype)) {
171 if (in_array($accounting_product_mode, $accounting_product_modes)) {
172 if (!
dolibarr_set_const($db,
'ACCOUNTING_PRODUCT_MODE', $accounting_product_mode,
'chaine', 0,
'', $conf->entity)) {
180 if (!empty($chk_prod) && $massaction ===
'changeaccount') {
182 if (!empty($chk_prod) && in_array($accounting_product_mode, $accounting_product_modes)) {
186 $arrayofdifferentselectedvalues = array();
191 foreach ($chk_prod as $productid) {
192 $accounting_account_id =
GETPOST(
'codeventil_'.$productid);
195 if ($accounting_account_id > 0) {
196 $arrayofdifferentselectedvalues[$accounting_account_id] = $accounting_account_id;
197 $result = $accounting->fetch($accounting_account_id,
null, 1);
201 $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>';
206 $sql_exists =
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"product_perentity";
207 $sql_exists .=
" WHERE fk_product = " . ((int) $productid) .
" AND entity = " . ((int) $conf->entity);
208 $resql_exists = $db->query($sql_exists);
209 if (!$resql_exists) {
210 $msg .=
'<div><span class="error">'.$langs->trans(
"ErrorDB").
' : '.$langs->trans(
"Product").
' '.$productid.
' '.$langs->trans(
"NotVentilatedinAccount").
' : id='.$accounting_account_id.
'<br> <pre>'.$resql_exists.
'</pre></span></div>';
213 $nb_exists = $db->num_rows($resql_exists);
214 if ($nb_exists <= 0) {
216 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"product_perentity (fk_product, entity, " . $db->escape($accountancy_field_name) .
")";
217 $sql .=
" VALUES (" . ((int) $productid) .
", " . ((int) $conf->entity) .
", '" . $db->escape($accounting->account_number) .
"')";
219 $obj_exists = $db->fetch_object($resql_exists);
221 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"product_perentity";
222 $sql .=
" SET " . $accountancy_field_name .
" = '" . $db->escape($accounting->account_number) .
"'";
223 $sql .=
" WHERE rowid = " . ((int) $obj_exists->rowid);
227 $sql =
" UPDATE ".MAIN_DB_PREFIX.
"product";
228 $sql .=
" SET ".$accountancy_field_name.
" = '".$db->escape($accounting->account_number).
"'";
229 $sql .=
" WHERE rowid = ".((int) $productid);
232 dol_syslog(
"/accountancy/admin/productaccount.php", LOG_DEBUG);
236 if ($db->query($sql)) {
250 setEventMessages($langs->trans(
"XLineFailedToBeBinded", $ko),
null,
'errors');
253 setEventMessages($langs->trans(
"XLineSuccessfullyBinded", $ok),
null,
'mesgs');
271$aarowid_servbuy = $accounting->fetch(
'',
getDolGlobalString(
'ACCOUNTING_SERVICE_BUY_ACCOUNT'), 1);
272$aarowid_servbuy_intra = $accounting->fetch(
'',
getDolGlobalString(
'ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT'), 1);
273$aarowid_servbuy_export = $accounting->fetch(
'',
getDolGlobalString(
'ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT'), 1);
274$aarowid_prodbuy = $accounting->fetch(
'',
getDolGlobalString(
'ACCOUNTING_PRODUCT_BUY_ACCOUNT'), 1);
275$aarowid_prodbuy_intra = $accounting->fetch(
'',
getDolGlobalString(
'ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT'), 1);
276$aarowid_prodbuy_export = $accounting->fetch(
'',
getDolGlobalString(
'ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT'), 1);
277$aarowid_servsell = $accounting->fetch(
'',
getDolGlobalString(
'ACCOUNTING_SERVICE_SOLD_ACCOUNT'), 1);
278$aarowid_servsell_intra = $accounting->fetch(
'',
getDolGlobalString(
'ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT'), 1);
279$aarowid_servsell_export = $accounting->fetch(
'',
getDolGlobalString(
'ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT'), 1);
280$aarowid_prodsell = $accounting->fetch(
'',
getDolGlobalString(
'ACCOUNTING_PRODUCT_SOLD_ACCOUNT'), 1);
281$aarowid_prodsell_intra = $accounting->fetch(
'',
getDolGlobalString(
'ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT'), 1);
282$aarowid_prodsell_export = $accounting->fetch(
'',
getDolGlobalString(
'ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT'), 1);
284$aacompta_servbuy =
getDolGlobalString(
'ACCOUNTING_SERVICE_BUY_ACCOUNT', $langs->trans(
"CodeNotDef"));
285$aacompta_servbuy_intra =
getDolGlobalString(
'ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT', $langs->trans(
"CodeNotDef"));
286$aacompta_servbuy_export =
getDolGlobalString(
'ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT', $langs->trans(
"CodeNotDef"));
287$aacompta_prodbuy =
getDolGlobalString(
'ACCOUNTING_PRODUCT_BUY_ACCOUNT', $langs->trans(
"CodeNotDef"));
288$aacompta_prodbuy_intra =
getDolGlobalString(
'ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT', $langs->trans(
"CodeNotDef"));
289$aacompta_prodbuy_export =
getDolGlobalString(
'ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT', $langs->trans(
"CodeNotDef"));
290$aacompta_servsell =
getDolGlobalString(
'ACCOUNTING_SERVICE_SOLD_ACCOUNT', $langs->trans(
"CodeNotDef"));
291$aacompta_servsell_intra =
getDolGlobalString(
'ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT', $langs->trans(
"CodeNotDef"));
292$aacompta_servsell_export =
getDolGlobalString(
'ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT', $langs->trans(
"CodeNotDef"));
293$aacompta_prodsell =
getDolGlobalString(
'ACCOUNTING_PRODUCT_SOLD_ACCOUNT', $langs->trans(
"CodeNotDef"));
294$aacompta_prodsell_intra =
getDolGlobalString(
'ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT', $langs->trans(
"CodeNotDef"));
295$aacompta_prodsell_export =
getDolGlobalString(
'ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT', $langs->trans(
"CodeNotDef"));
298$title = $langs->trans(
"ProductsBinding");
299$help_url =
'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilité_en_Partie_Double#Configuration';
302foreach ($searchCategoryProductList as $searchCategoryProduct) {
303 $paramsCat .=
"&search_category_product_list[]=".urlencode($searchCategoryProduct);
306llxHeader(
'', $title, $help_url,
'', 0, 0, array(), array(), $paramsCat,
'');
309$pcgvercode =
dol_getIdFromCode($db, $pcgverid,
'accounting_system',
'rowid',
'pcg_version');
310if (empty($pcgvercode)) {
311 $pcgvercode = $pcgverid;
314$sql =
"SELECT p.rowid, p.ref, p.label, p.description, p.tosell, p.tobuy, p.tva_tx,";
316 $sql .=
" ppe.accountancy_code_sell, ppe.accountancy_code_sell_intra, ppe.accountancy_code_sell_export,";
317 $sql .=
" ppe.accountancy_code_buy, ppe.accountancy_code_buy_intra, ppe.accountancy_code_buy_export,";
319 $sql .=
" p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export,";
320 $sql .=
" p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export,";
322$sql .=
" p.tms, p.fk_product_type as product_type,";
323$sql .=
" aa.rowid as aaid";
324$sql .=
" FROM ".MAIN_DB_PREFIX.
"product as p";
326 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
327 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"accounting_account as aa ON aa.account_number = ppe." . $accountancy_field_name .
" AND aa.fk_pcg_version = '" . $db->escape($pcgvercode) .
"'";
329 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"accounting_account as aa ON aa.account_number = p." . $accountancy_field_name .
" AND aa.fk_pcg_version = '" . $db->escape($pcgvercode) .
"'";
331if (!empty($searchCategoryProductList)) {
332 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
"categorie_product as cp ON p.rowid = cp.fk_product";
334$sql .=
' WHERE p.entity IN ('.getEntity(
'product').
')';
335if (strlen(trim($search_current_account))) {
338if ($search_current_account_valid ==
'withoutvalidaccount') {
339 $sql .=
" AND aa.account_number IS NULL";
341if ($search_current_account_valid ==
'withvalidaccount') {
342 $sql .=
" AND aa.account_number IS NOT NULL";
344$searchCategoryProductSqlList = array();
345if ($searchCategoryProductOperator == 1) {
346 foreach ($searchCategoryProductList as $searchCategoryProduct) {
347 if (intval($searchCategoryProduct) == -2) {
348 $searchCategoryProductSqlList[] =
"cp.fk_categorie IS NULL";
349 } elseif (intval($searchCategoryProduct) > 0) {
350 $searchCategoryProductSqlList[] =
"cp.fk_categorie = ".$db->escape($searchCategoryProduct);
353 if (!empty($searchCategoryProductSqlList)) {
354 $sql .=
" AND (".implode(
' OR ', $searchCategoryProductSqlList).
")";
357 foreach ($searchCategoryProductList as $searchCategoryProduct) {
358 if (intval($searchCategoryProduct) == -2) {
359 $searchCategoryProductSqlList[] =
"cp.fk_categorie IS NULL";
360 } elseif (intval($searchCategoryProduct) > 0) {
361 $searchCategoryProductSqlList[] =
"p.rowid IN (SELECT fk_product FROM ".MAIN_DB_PREFIX.
"categorie_product WHERE fk_categorie = ".((int) $searchCategoryProduct).
")";
364 if (!empty($searchCategoryProductSqlList)) {
365 $sql .=
" AND (".implode(
' AND ', $searchCategoryProductSqlList).
")";
369if (strlen(trim($search_ref))) {
372if (strlen(trim($search_label))) {
375if (strlen(trim($search_desc))) {
378if (strlen(trim($search_vat))) {
381if ($search_onsell !=
'' && $search_onsell !=
'-1') {
384if ($search_onpurchase !=
'' && $search_onpurchase !=
'-1') {
388$sql .=
" GROUP BY p.rowid, p.ref, p.label, p.description, p.tosell, p.tobuy, p.tva_tx,";
389$sql .=
" p.fk_product_type,";
393 $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";
395 $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";
398$sql .= $db->order($sortfield, $sortorder);
400$nbtotalofrecords =
'';
402 $resql = $db->query($sql);
403 $nbtotalofrecords = $db->num_rows($resql);
404 if (($page * $limit) > $nbtotalofrecords) {
410$sql .= $db->plimit($limit + 1, $offset);
412dol_syslog(
"/accountancy/admin/productaccount.php", LOG_DEBUG);
413$resql = $db->query($sql);
415 $num = $db->num_rows($resql);
419 if (!empty($contextpage) && $contextpage != $_SERVER[
"PHP_SELF"]) {
420 $param .=
'&contextpage='.urlencode($contextpage);
422 if ($limit > 0 && $limit != $conf->liste_limit) {
423 $param .=
'&limit='.((int) $limit);
425 if ($searchCategoryProductOperator == 1) {
426 $param .=
"&search_category_product_operator=".urlencode($searchCategoryProductOperator);
428 foreach ($searchCategoryProductList as $searchCategoryProduct) {
429 $param .=
"&search_category_product_list[]=".urlencode($searchCategoryProduct);
431 if ($search_ref > 0) {
432 $param .=
"&search_ref=".urlencode($search_ref);
434 if ($search_label > 0) {
435 $param .=
"&search_label=".urlencode($search_label);
437 if ($search_desc > 0) {
438 $param .=
"&search_desc=".urlencode($search_desc);
440 if ($search_vat > 0) {
441 $param .=
'&search_vat='.urlencode($search_vat);
443 if ($search_current_account > 0) {
444 $param .=
"&search_current_account=".urlencode($search_current_account);
446 if ($search_current_account_valid && $search_current_account_valid !=
'-1') {
447 $param .=
"&search_current_account_valid=".urlencode($search_current_account_valid);
449 if ($accounting_product_mode) {
450 $param .=
'&accounting_product_mode='.urlencode($accounting_product_mode);
453 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
454 if ($optioncss !=
'') {
455 print
'<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
457 print
'<input type="hidden" name="token" value="'.newToken().
'">';
458 print
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
459 print
'<input type="hidden" name="action" value="update">';
460 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
461 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
463 print
load_fiche_titre($langs->trans(
"ProductsBinding"),
'',
'title_accountancy');
466 print
'<span class="opacitymedium">'.$langs->trans(
"InitAccountancyDesc").
'</span><br>';
470 print
'<table class="noborder centpercent">';
471 print
'<tr class="liste_titre">';
472 print
'<td>'.$langs->trans(
'Options').
'</td><td>'.$langs->trans(
'Description').
'</td>';
474 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>';
475 print
'<td>'.$langs->trans(
'OptionModeProductSellDesc');
476 print
"</td></tr>\n";
477 if ($mysoc->isInEEC()) {
478 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>';
479 print
'<td>'.$langs->trans(
'OptionModeProductSellIntraDesc');
480 print
"</td></tr>\n";
482 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>';
483 print
'<td>'.$langs->trans(
'OptionModeProductSellExportDesc');
484 print
"</td></tr>\n";
485 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>';
486 print
'<td>'.$langs->trans(
'OptionModeProductBuyDesc').
"</td></tr>\n";
487 if ($mysoc->isInEEC()) {
488 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>';
489 print
'<td>'.$langs->trans(
'OptionModeProductBuyDesc').
"</td></tr>\n";
491 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>';
492 print
'<td>'.$langs->trans(
'OptionModeProductBuyDesc').
"</td></tr>\n";
495 print
'<div class="center"><input type="submit" class="button" value="'.$langs->trans(
'Refresh').
'" name="changetype"></div>';
502 $varpage = empty($contextpage) ? $_SERVER[
"PHP_SELF"] : $contextpage;
503 $selectedfields = $form->multiSelectArrayWithCheckbox(
'selectedfields', $arrayfields, $varpage);
505 if ($massaction !==
'set_default_account') {
506 $arrayofmassactions = array(
507 'changeaccount'=>
img_picto(
'',
'check',
'class="pictofixedwidth"').$langs->trans(
"Save")
508 ,
'set_default_account'=>
img_picto(
'',
'check',
'class="pictofixedwidth"').$langs->trans(
"ConfirmPreselectAccount")
510 $massactionbutton = $form->selectMassAction(
'', $arrayofmassactions, 1);
513 $buttonsave =
'<input type="submit" class="button button-save" id="changeaccount" name="changeaccount" value="'.$langs->trans(
"Save").
'">';
516 $texte = $langs->trans(
"ListOfProductsServices");
517 print_barre_liste($texte, $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords,
'', 0,
'',
'', $limit, 0, 0, 1);
519 if ($massaction ==
'set_default_account') {
520 $formquestion[]=array(
'type' =>
'other',
521 'name' =>
'set_default_account',
522 'label' => $langs->trans(
"AccountancyCode"),
523 'value' => $form->select_account(
'',
'default_account', 1, array(), 0, 0,
'maxwidth200 maxwidthonsmartphone',
'cachewithshowemptyone'));
524 print $form->formconfirm($_SERVER[
"PHP_SELF"], $langs->trans(
"ConfirmPreselectAccount"), $langs->trans(
"ConfirmPreselectAccountQuestion", count($chk_prod)),
"confirm_set_default_account", $formquestion, 1, 0, 200, 500, 1);
529 if (isModEnabled(
'categorie') && $user->hasRight(
'categorie',
'lire')) {
530 $moreforfilter .=
'<div class="divsearchfield">';
531 $moreforfilter .=
img_picto($langs->trans(
'Categories'),
'category',
'class="pictofixedwidth"');
532 $categoriesProductArr = $form->select_all_categories(Categorie::TYPE_PRODUCT,
'',
'', 64, 0, 1);
533 $categoriesProductArr[-2] =
'- '.$langs->trans(
'NotCategorized').
' -';
534 $moreforfilter .=
Form::multiselectarray(
'search_category_product_list', $categoriesProductArr, $searchCategoryProductList, 0, 0,
'minwidth300');
535 $moreforfilter .=
' <input type="checkbox" class="valignmiddle" id="search_category_product_operator" name="search_category_product_operator" value="1"'.($searchCategoryProductOperator == 1 ?
' checked="checked"' :
'').
'/> <label for="search_category_product_operator"><span class="none">'.$langs->trans(
'UseOrOperatorForCategories').
'</span></label>';
536 $moreforfilter .=
'</div>';
540 if (isModEnabled(
'variants') &&
getDolGlobalInt(
'PRODUIT_ATTRIBUTES_HIDECHILD')) {
541 $moreforfilter .=
'<div class="divsearchfield">';
542 $moreforfilter .=
'<input type="checkbox" id="search_show_childproducts" name="search_show_childproducts"'.($show_childproducts ?
'checked="checked"' :
'').
'>';
543 $moreforfilter .=
' <label for="search_show_childproducts">'.$langs->trans(
'ShowChildProducts').
'</label>';
544 $moreforfilter .=
'</div>';
547 $parameters = array();
548 $reshook = $hookmanager->executeHooks(
'printFieldPreListTitle', $parameters);
549 if (empty($reshook)) {
550 $moreforfilter .= $hookmanager->resPrint;
552 $moreforfilter = $hookmanager->resPrint;
555 if ($moreforfilter) {
556 print
'<div class="liste_titre liste_titre_bydiv centpercent">';
557 print $moreforfilter;
561 print
'<div class="div-table-responsive">';
562 print
'<table class="liste '.($moreforfilter ?
"listwithfilterbefore" :
"").
'">';
564 print
'<tr class="liste_titre_filter">';
567 print
'<td class="center liste_titre">';
568 $searchpicto = $form->showFilterButtons();
572 print
'<td class="liste_titre"><input type="text" class="flat" size="8" name="search_ref" value="'.dol_escape_htmltag($search_ref).
'"></td>';
573 print
'<td class="liste_titre"><input type="text" class="flat" size="10" name="search_label" value="'.dol_escape_htmltag($search_label).
'"></td>';
574 print
'<td class="liste_titre right"><input type="text" class="flat maxwidth50 right" name="search_vat" placeholder="%" value="'.dol_escape_htmltag($search_vat).
'"></td>';
577 print
'<td class="liste_titre"><input type="text" class="flat" size="20" name="search_desc" value="'.dol_escape_htmltag($search_desc).
'"></td>';
580 if ($accounting_product_mode ==
'ACCOUNTANCY_SELL' || $accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA' || $accounting_product_mode ==
'ACCOUNTANCY_SELL_EXPORT') {
581 print
'<td class="liste_titre center">'.$form->selectyesno(
'search_onsell', $search_onsell, 1,
false, 1).
'</td>';
584 print
'<td class="liste_titre center">'.$form->selectyesno(
'search_onpurchase', $search_onpurchase, 1,
false, 1).
'</td>';
587 print
'<td class="liste_titre">';
588 print
'<input type="text" class="flat" size="6" name="search_current_account" id="search_current_account" value="'.dol_escape_htmltag($search_current_account).
'">';
589 $listofvals = array(
'withoutvalidaccount'=>$langs->trans(
"WithoutValidAccount"),
'withvalidaccount'=>$langs->trans(
"WithValidAccount"));
590 print
' '.$langs->trans(
"or").
' '.$form->selectarray(
'search_current_account_valid', $listofvals, $search_current_account_valid, 1);
592 print
'<td class="liste_titre"> </td>';
595 print
'<td class="center liste_titre">';
596 $searchpicto = $form->showFilterButtons();
602 print
'<tr class="liste_titre">';
605 $clickpitco = $form->showCheckAddButtons(
'checkforselect', 1);
611 print_liste_field_titre(
"Description", $_SERVER[
"PHP_SELF"],
"p.description",
"", $param,
'', $sortfield, $sortorder);
613 print_liste_field_titre(
"VATRate", $_SERVER[
"PHP_SELF"],
"p.tva_tx",
"", $param,
'', $sortfield, $sortorder,
'right ');
615 if ($accounting_product_mode ==
'ACCOUNTANCY_SELL' || $accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA' || $accounting_product_mode ==
'ACCOUNTANCY_SELL_EXPORT') {
616 print_liste_field_titre(
"OnSell", $_SERVER[
"PHP_SELF"],
"p.tosell",
"", $param,
'', $sortfield, $sortorder,
'center ');
618 print_liste_field_titre(
"OnBuy", $_SERVER[
"PHP_SELF"],
"p.tobuy",
"", $param,
'', $sortfield, $sortorder,
'center ');
620 print_liste_field_titre(
"CurrentDedicatedAccountingAccount", $_SERVER[
"PHP_SELF"], (!
getDolGlobalString(
'MAIN_PRODUCT_PERENTITY_SHARED') ?
"p." :
"ppe.") . $accountancy_field_name,
"", $param,
'', $sortfield, $sortorder);
624 $clickpitco = $form->showCheckAddButtons(
'checkforselect', 1);
629 $product_static =
new Product($db);
632 while ($i < min($num, $limit)) {
633 $obj = $db->fetch_object($resql);
636 $product_static->ref = $obj->ref;
637 $product_static->id = $obj->rowid;
638 $product_static->type = $obj->product_type;
639 $product_static->label = $obj->label;
640 $product_static->description = $obj->description;
641 $product_static->status = $obj->tosell;
642 $product_static->status_buy = $obj->tobuy;
645 if ($obj->product_type == 0) {
646 if ($accounting_product_mode ==
'ACCOUNTANCY_SELL') {
647 $compta_prodsell =
getDolGlobalString(
'ACCOUNTING_PRODUCT_SOLD_ACCOUNT', $langs->trans(
"CodeNotDef"));
648 $compta_prodsell_id = $aarowid_prodsell;
649 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA') {
650 $compta_prodsell =
getDolGlobalString(
'ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT', $langs->trans(
"CodeNotDef"));
651 $compta_prodsell_id = $aarowid_prodsell_intra;
652 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL_EXPORT') {
653 $compta_prodsell =
getDolGlobalString(
'ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT', $langs->trans(
"CodeNotDef"));
654 $compta_prodsell_id = $aarowid_prodsell_export;
656 $compta_prodsell =
getDolGlobalString(
'ACCOUNTING_PRODUCT_SOLD_ACCOUNT', $langs->trans(
"CodeNotDef"));
657 $compta_prodsell_id = $aarowid_prodsell;
660 if ($accounting_product_mode ==
'ACCOUNTANCY_SELL') {
661 $compta_prodsell =
getDolGlobalString(
'ACCOUNTING_SERVICE_SOLD_ACCOUNT', $langs->trans(
"CodeNotDef"));
662 $compta_prodsell_id = $aarowid_servsell;
663 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA') {
664 $compta_prodsell =
getDolGlobalString(
'ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT', $langs->trans(
"CodeNotDef"));
665 $compta_prodsell_id = $aarowid_servsell_intra;
666 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL_EXPORT') {
667 $compta_prodsell =
getDolGlobalString(
'ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT', $langs->trans(
"CodeNotDef"));
669 $compta_prodsell_id = $aarowid_servsell_export;
671 $compta_prodsell =
getDolGlobalString(
'ACCOUNTING_SERVICE_SOLD_ACCOUNT', $langs->trans(
"CodeNotDef"));
672 $compta_prodsell_id = $aarowid_servsell;
677 if ($obj->product_type == 0) {
678 if ($accounting_product_mode ==
'ACCOUNTANCY_BUY') {
679 $compta_prodbuy =
getDolGlobalString(
'ACCOUNTING_PRODUCT_BUY_ACCOUNT', $langs->trans(
"CodeNotDef"));
680 $compta_prodbuy_id = $aarowid_prodbuy;
681 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_INTRA') {
682 $compta_prodbuy =
getDolGlobalString(
'ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT', $langs->trans(
"CodeNotDef"));
683 $compta_prodbuy_id = $aarowid_prodbuy_intra;
684 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_EXPORT') {
685 $compta_prodbuy =
getDolGlobalString(
'ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT', $langs->trans(
"CodeNotDef"));
686 $compta_prodbuy_id = $aarowid_prodbuy_export;
688 $compta_prodbuy =
getDolGlobalString(
'ACCOUNTING_PRODUCT_BUY_ACCOUNT', $langs->trans(
"CodeNotDef"));
689 $compta_prodbuy_id = $aarowid_prodbuy;
692 if ($accounting_product_mode ==
'ACCOUNTANCY_BUY') {
693 $compta_prodbuy =
getDolGlobalString(
'ACCOUNTING_SERVICE_BUY_ACCOUNT', $langs->trans(
"CodeNotDef"));
694 $compta_prodbuy_id = $aarowid_servbuy;
695 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_INTRA') {
696 $compta_prodbuy =
getDolGlobalString(
'ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT', $langs->trans(
"CodeNotDef"));
697 $compta_prodbuy_id = $aarowid_servbuy_intra;
698 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_EXPORT') {
699 $compta_prodbuy =
getDolGlobalString(
'ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT', $langs->trans(
"CodeNotDef"));
700 $compta_prodbuy_id = $aarowid_servbuy_export;
702 $compta_prodbuy =
getDolGlobalString(
'ACCOUNTING_SERVICE_BUY_ACCOUNT', $langs->trans(
"CodeNotDef"));
703 $compta_prodbuy_id = $aarowid_servbuy;
708 if (!empty($chk_prod)) {
709 if (in_array($product_static->id, $chk_prod)) {
714 print
'<tr class="oddeven">';
718 print
'<td class="center">';
719 print
'<input type="checkbox" class="checkforselect productforselectcodeventil_'.$product_static->id.
'" name="chk_prod[]" '.($selected ?
"checked" :
"").
' value="'.$obj->rowid.
'"/>';
724 print $product_static->getNomUrl(1);
727 print
'<td class="left">'.$obj->label.
'</td>';
734 print
'<td>'.nl2br(
dol_trunc($obj->description, $trunclength)).
'</td>';
738 print
'<td class="right">';
743 if ($accounting_product_mode ==
'ACCOUNTANCY_SELL' || $accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA' || $accounting_product_mode ==
'ACCOUNTANCY_SELL_EXPORT') {
744 print
'<td class="center">'.$product_static->getLibStatut(3, 0).
'</td>';
746 print
'<td class="center">'.$product_static->getLibStatut(3, 1).
'</td>';
750 print
'<td class="left">';
751 if ($accounting_product_mode ==
'ACCOUNTANCY_BUY') {
753 if ($obj->accountancy_code_buy && empty($obj->aaid)) {
754 print
' '.img_warning($langs->trans(
"ValueNotIntoChartOfAccount"));
756 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_INTRA') {
758 if ($obj->accountancy_code_buy_intra && empty($obj->aaid)) {
759 print
' '.img_warning($langs->trans(
"ValueNotIntoChartOfAccount"));
761 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_EXPORT') {
763 if ($obj->accountancy_code_buy_export && empty($obj->aaid)) {
764 print
' '.img_warning($langs->trans(
"ValueNotIntoChartOfAccount"));
766 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL') {
768 if ($obj->accountancy_code_sell && empty($obj->aaid)) {
769 print
' '.img_warning($langs->trans(
"ValueNotIntoChartOfAccount"));
771 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA') {
773 if ($obj->accountancy_code_sell_intra && empty($obj->aaid)) {
774 print
' '.img_warning($langs->trans(
"ValueNotIntoChartOfAccount"));
778 if ($obj->accountancy_code_sell_export && empty($obj->aaid)) {
779 print
' '.img_warning($langs->trans(
"ValueNotIntoChartOfAccount"));
786 if ($accounting_product_mode ==
'ACCOUNTANCY_BUY') {
788 print
'<td class="left">';
790 if (empty($defaultvalue)) {
791 $defaultvalue = $compta_prodbuy;
794 if (!empty($obj->aaid)) {
797 print $form->select_account(($default_account > 0 && $confirm ===
'yes' && in_array($product_static->id, $chk_prod)) ? $default_account : $defaultvalue,
'codeventil_'.$product_static->id, 1, array(), 1, 0,
'maxwidth300 maxwidthonsmartphone productforselect');
799 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_INTRA') {
801 print
'<td class="left">';
803 if (empty($defaultvalue)) {
804 $defaultvalue = $compta_prodbuy;
808 if (!empty($obj->aaid)) {
811 print $form->select_account(($default_account > 0 && $confirm ===
'yes' && in_array($product_static->id, $chk_prod)) ? $default_account : $defaultvalue,
'codeventil_'.$product_static->id, 1, array(), 1, 0,
'maxwidth300 maxwidthonsmartphone productforselect');
813 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_EXPORT') {
815 print
'<td class="left">';
817 if (empty($defaultvalue)) {
818 $defaultvalue = $compta_prodbuy;
822 if (!empty($obj->aaid)) {
825 print $form->select_account(($default_account > 0 && $confirm ===
'yes' && in_array($product_static->id, $chk_prod)) ? $default_account : $defaultvalue,
'codeventil_'.$product_static->id, 1, array(), 1, 0,
'maxwidth300 maxwidthonsmartphone productforselect');
827 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL') {
829 print
'<td class="left">';
831 if (empty($defaultvalue)) {
832 $defaultvalue = $compta_prodsell;
836 if (!empty($obj->aaid)) {
839 print $form->select_account(($default_account > 0 && $confirm ===
'yes' && in_array($product_static->id, $chk_prod)) ? $default_account : $defaultvalue,
'codeventil_'.$product_static->id, 1, array(), 1, 0,
'maxwidth300 maxwidthonsmartphone productforselect');
841 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA') {
843 print
'<td class="left">';
845 if (empty($defaultvalue)) {
846 $defaultvalue = $compta_prodsell;
850 if (!empty($obj->aaid)) {
853 print $form->select_account(($default_account > 0 && $confirm ===
'yes' && in_array($product_static->id, $chk_prod)) ? $default_account : $defaultvalue,
'codeventil_'.$product_static->id, 1, array(), 1, 0,
'maxwidth300 maxwidthonsmartphone productforselect');
857 print
'<td class="left">';
859 if (empty($defaultvalue)) {
860 $defaultvalue = $compta_prodsell;
863 if (!empty($obj->aaid)) {
866 print $form->select_account(($default_account > 0 && $confirm ===
'yes' && in_array($product_static->id, $chk_prod)) ? $default_account : $defaultvalue,
'codeventil_'.$product_static->id, 1, array(), 1, 0,
'maxwidth300 maxwidthonsmartphone productforselect');
872 print
'<td class="center">';
873 print
'<input type="checkbox" class="checkforselect productforselectcodeventil_'.$product_static->id.
'" name="chk_prod[]" '.($selected ?
"checked" :
"").
' value="'.$obj->rowid.
'"/>';
883 print
'<script type="text/javascript">
884 jQuery(document).ready(function() {
885 function init_savebutton()
887 console.log("We check if at least one line is checked")
889 atleastoneselected=0;
890 jQuery(".checkforselect").each(function( index ) {
891 /* console.log( index + ": " + $( this ).text() ); */
892 if ($(this).is(\':checked\')) atleastoneselected++;
895 if (atleastoneselected) jQuery("#changeaccount").removeAttr(\'disabled\');
896 else jQuery("#changeaccount").attr(\'disabled\',\'disabled\');
897 if (atleastoneselected) jQuery("#changeaccount").attr(\'class\',\'button\');
898 else jQuery("#changeaccount").attr(\'class\',\'button\');
901 jQuery(".checkforselect").change(function() {
904 jQuery(".productforselect").change(function() {
905 console.log($(this).attr("id")+" "+$(this).val());
906 if ($(this).val() && $(this).val() != -1) {
907 $(".productforselect"+$(this).attr("id")).prop(\'checked\', true);
909 $(".productforselect"+$(this).attr("id")).prop(\'checked\', false);
916 jQuery("#search_current_account").keyup(function() {
917 if (jQuery("#search_current_account").val() != \'\')
919 console.log("We set a value of account to search "+jQuery("#search_current_account").val()+", so we disable the other search criteria on account");
920 jQuery("#search_current_account_valid").val(-1);
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()
Empty header.
Class to manage accounting accounts.
Class to manage products or services.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages.
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
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.
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 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.