28 require
'../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
42 $langs->loadLangs(array(
"companies",
"compta",
"accountancy",
"products"));
48 if (!$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');
75 if ($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');
84 if (empty($accounting_product_mode)) {
85 $accounting_product_mode =
'ACCOUNTANCY_SELL';
88 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION) ? $conf->liste_limit : $conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
89 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
90 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
92 if (empty($page) || $page == -1) {
95 $offset = $limit * $page;
96 $pageprev = $page - 1;
97 $pagenext = $page + 1;
105 if (empty($action)) {
109 $arrayfields = array();
111 $accounting_product_modes = array(
113 'ACCOUNTANCY_SELL_INTRA',
114 'ACCOUNTANCY_SELL_EXPORT',
116 'ACCOUNTANCY_BUY_INTRA',
117 'ACCOUNTANCY_BUY_EXPORT'
120 if ($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";
138 if (
GETPOST(
'cancel',
'alpha')) {
139 $action =
'list'; $massaction =
'';
141 if (!
GETPOST(
'confirmmassaction',
'alpha') && $massaction !=
'presend' && $massaction !=
'confirm_presend') {
145 $parameters = array();
146 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
152 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
153 $searchCategoryProductOperator = 0;
154 $searchCategoryProductList = array();
160 $search_onpurchase =
'';
161 $search_current_account =
'';
162 $search_current_account_valid =
'-1';
166 if ($action ==
'update') {
167 if (!empty($btn_changetype)) {
170 if (in_array($accounting_product_mode, $accounting_product_modes)) {
171 if (!
dolibarr_set_const($db,
'ACCOUNTING_PRODUCT_MODE', $accounting_product_mode,
'chaine', 0,
'', $conf->entity)) {
179 if (!empty($chk_prod) && $massaction ===
'changeaccount') {
181 if (!empty($chk_prod) && in_array($accounting_product_mode, $accounting_product_modes)) {
185 $arrayofdifferentselectedvalues = array();
187 $cpt = 0; $ok = 0; $ko = 0;
188 foreach ($chk_prod as $productid) {
189 $accounting_account_id =
GETPOST(
'codeventil_'.$productid);
192 if ($accounting_account_id > 0) {
193 $arrayofdifferentselectedvalues[$accounting_account_id] = $accounting_account_id;
194 $result = $accounting->fetch($accounting_account_id,
null, 1);
198 $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>';
202 if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
203 $sql_exists =
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"product_perentity";
204 $sql_exists .=
" WHERE fk_product = " . ((int) $productid) .
" AND entity = " . ((int) $conf->entity);
205 $resql_exists = $db->query($sql_exists);
206 if (!$resql_exists) {
207 $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>';
210 $nb_exists = $db->num_rows($resql_exists);
211 if ($nb_exists <= 0) {
213 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"product_perentity (fk_product, entity, " . $db->escape($accountancy_field_name) .
")";
214 $sql .=
" VALUES (" . ((int) $productid) .
", " . ((int) $conf->entity) .
", '" . $db->escape($accounting->account_number) .
"')";
216 $obj_exists = $db->fetch_object($resql_exists);
218 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"product_perentity";
219 $sql .=
" SET " . $accountancy_field_name .
" = '" . $db->escape($accounting->account_number) .
"'";
220 $sql .=
" WHERE rowid = " . ((int) $obj_exists->rowid);
224 $sql =
" UPDATE ".MAIN_DB_PREFIX.
"product";
225 $sql .=
" SET ".$accountancy_field_name.
" = '".$db->escape($accounting->account_number).
"'";
226 $sql .=
" WHERE rowid = ".((int) $productid);
229 dol_syslog(
"/accountancy/admin/productaccount.php", LOG_DEBUG);
233 if ($db->query(
$sql)) {
247 setEventMessages($langs->trans(
"XLineFailedToBeBinded", $ko),
null,
'errors');
250 setEventMessages($langs->trans(
"XLineSuccessfullyBinded", $ok),
null,
'mesgs');
268 $aarowid_servbuy = $accounting->fetch(
'',
getDolGlobalString(
'ACCOUNTING_SERVICE_BUY_ACCOUNT'), 1);
269 $aarowid_servbuy_intra = $accounting->fetch(
'',
getDolGlobalString(
'ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT'), 1);
270 $aarowid_servbuy_export = $accounting->fetch(
'',
getDolGlobalString(
'ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT'), 1);
271 $aarowid_prodbuy = $accounting->fetch(
'',
getDolGlobalString(
'ACCOUNTING_PRODUCT_BUY_ACCOUNT'), 1);
272 $aarowid_prodbuy_intra = $accounting->fetch(
'',
getDolGlobalString(
'ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT'), 1);
273 $aarowid_prodbuy_export = $accounting->fetch(
'',
getDolGlobalString(
'ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT'), 1);
274 $aarowid_servsell = $accounting->fetch(
'',
getDolGlobalString(
'ACCOUNTING_SERVICE_SOLD_ACCOUNT'), 1);
275 $aarowid_servsell_intra = $accounting->fetch(
'',
getDolGlobalString(
'ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT'), 1);
276 $aarowid_servsell_export = $accounting->fetch(
'',
getDolGlobalString(
'ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT'), 1);
277 $aarowid_prodsell = $accounting->fetch(
'',
getDolGlobalString(
'ACCOUNTING_PRODUCT_SOLD_ACCOUNT'), 1);
278 $aarowid_prodsell_intra = $accounting->fetch(
'',
getDolGlobalString(
'ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT'), 1);
279 $aarowid_prodsell_export = $accounting->fetch(
'',
getDolGlobalString(
'ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT'), 1);
281 $aacompta_servbuy =
getDolGlobalString(
'ACCOUNTING_SERVICE_BUY_ACCOUNT', $langs->trans(
"CodeNotDef"));
282 $aacompta_servbuy_intra =
getDolGlobalString(
'ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT', $langs->trans(
"CodeNotDef"));
283 $aacompta_servbuy_export =
getDolGlobalString(
'ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT', $langs->trans(
"CodeNotDef"));
284 $aacompta_prodbuy =
getDolGlobalString(
'ACCOUNTING_PRODUCT_BUY_ACCOUNT', $langs->trans(
"CodeNotDef"));
285 $aacompta_prodbuy_intra =
getDolGlobalString(
'ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT', $langs->trans(
"CodeNotDef"));
286 $aacompta_prodbuy_export =
getDolGlobalString(
'ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT', $langs->trans(
"CodeNotDef"));
287 $aacompta_servsell =
getDolGlobalString(
'ACCOUNTING_SERVICE_SOLD_ACCOUNT', $langs->trans(
"CodeNotDef"));
288 $aacompta_servsell_intra =
getDolGlobalString(
'ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT', $langs->trans(
"CodeNotDef"));
289 $aacompta_servsell_export =
getDolGlobalString(
'ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT', $langs->trans(
"CodeNotDef"));
290 $aacompta_prodsell =
getDolGlobalString(
'ACCOUNTING_PRODUCT_SOLD_ACCOUNT', $langs->trans(
"CodeNotDef"));
291 $aacompta_prodsell_intra =
getDolGlobalString(
'ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT', $langs->trans(
"CodeNotDef"));
292 $aacompta_prodsell_export =
getDolGlobalString(
'ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT', $langs->trans(
"CodeNotDef"));
295 $title = $langs->trans(
"ProductsBinding");
299 foreach ($searchCategoryProductList as $searchCategoryProduct) {
300 $paramsCat .=
"&search_category_product_list[]=".urlencode($searchCategoryProduct);
303 llxHeader(
'', $title, $helpurl,
'', 0, 0, array(), array(), $paramsCat,
'');
306 $pcgvercode =
dol_getIdFromCode($db, $pcgverid,
'accounting_system',
'rowid',
'pcg_version');
307 if (empty($pcgvercode)) {
308 $pcgvercode = $pcgverid;
311 $sql =
"SELECT p.rowid, p.ref, p.label, p.description, p.tosell, p.tobuy, p.tva_tx,";
312 if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
313 $sql .=
" ppe.accountancy_code_sell, ppe.accountancy_code_sell_intra, ppe.accountancy_code_sell_export,";
314 $sql .=
" ppe.accountancy_code_buy, ppe.accountancy_code_buy_intra, ppe.accountancy_code_buy_export,";
316 $sql .=
" p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export,";
317 $sql .=
" p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export,";
319 $sql .=
" p.tms, p.fk_product_type as product_type,";
320 $sql .=
" aa.rowid as aaid";
321 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product as p";
322 if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
323 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
324 $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) .
"'";
326 $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) .
"'";
328 if (!empty($searchCategoryProductList)) {
329 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
"categorie_product as cp ON p.rowid = cp.fk_product";
331 $sql .=
' WHERE p.entity IN ('.getEntity(
'product').
')';
332 if (strlen(trim($search_current_account))) {
333 $sql .=
natural_search((empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED) ?
"p." :
"ppe.") . $accountancy_field_name, $search_current_account);
335 if ($search_current_account_valid ==
'withoutvalidaccount') {
336 $sql .=
" AND aa.account_number IS NULL";
338 if ($search_current_account_valid ==
'withvalidaccount') {
339 $sql .=
" AND aa.account_number IS NOT NULL";
341 $searchCategoryProductSqlList = array();
342 if ($searchCategoryProductOperator == 1) {
343 foreach ($searchCategoryProductList as $searchCategoryProduct) {
344 if (intval($searchCategoryProduct) == -2) {
345 $searchCategoryProductSqlList[] =
"cp.fk_categorie IS NULL";
346 } elseif (intval($searchCategoryProduct) > 0) {
347 $searchCategoryProductSqlList[] =
"cp.fk_categorie = ".$db->escape($searchCategoryProduct);
350 if (!empty($searchCategoryProductSqlList)) {
351 $sql .=
" AND (".implode(
' OR ', $searchCategoryProductSqlList).
")";
354 foreach ($searchCategoryProductList as $searchCategoryProduct) {
355 if (intval($searchCategoryProduct) == -2) {
356 $searchCategoryProductSqlList[] =
"cp.fk_categorie IS NULL";
357 } elseif (intval($searchCategoryProduct) > 0) {
358 $searchCategoryProductSqlList[] =
"p.rowid IN (SELECT fk_product FROM ".MAIN_DB_PREFIX.
"categorie_product WHERE fk_categorie = ".((int) $searchCategoryProduct).
")";
361 if (!empty($searchCategoryProductSqlList)) {
362 $sql .=
" AND (".implode(
' AND ', $searchCategoryProductSqlList).
")";
366 if (strlen(trim($search_ref))) {
369 if (strlen(trim($search_label))) {
372 if (strlen(trim($search_desc))) {
375 if (strlen(trim($search_vat))) {
378 if ($search_onsell !=
'' && $search_onsell !=
'-1') {
381 if ($search_onpurchase !=
'' && $search_onpurchase !=
'-1') {
385 $sql .=
" GROUP BY p.rowid, p.ref, p.label, p.description, p.tosell, p.tobuy, p.tva_tx,";
386 $sql .=
" p.fk_product_type,";
388 $sql .=
' aa.rowid,';
389 if (empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
390 $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";
392 $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";
395 $sql .= $db->order($sortfield, $sortorder);
397 $nbtotalofrecords =
'';
399 $resql = $db->query(
$sql);
400 $nbtotalofrecords = $db->num_rows($resql);
401 if (($page * $limit) > $nbtotalofrecords) {
407 $sql .= $db->plimit($limit + 1, $offset);
409 dol_syslog(
"/accountancy/admin/productaccount.php", LOG_DEBUG);
410 $resql = $db->query(
$sql);
412 $num = $db->num_rows($resql);
416 if (!empty($contextpage) && $contextpage != $_SERVER[
"PHP_SELF"]) {
417 $param .=
'&contextpage='.urlencode($contextpage);
419 if ($limit > 0 && $limit != $conf->liste_limit) {
420 $param .=
'&limit='.((int) $limit);
422 if ($searchCategoryProductOperator == 1) {
423 $param .=
"&search_category_product_operator=".urlencode($searchCategoryProductOperator);
425 foreach ($searchCategoryProductList as $searchCategoryProduct) {
426 $param .=
"&search_category_product_list[]=".urlencode($searchCategoryProduct);
428 if ($search_ref > 0) {
429 $param .=
"&search_ref=".urlencode($search_ref);
431 if ($search_label > 0) {
432 $param .=
"&search_label=".urlencode($search_label);
434 if ($search_desc > 0) {
435 $param .=
"&search_desc=".urlencode($search_desc);
437 if ($search_vat > 0) {
438 $param .=
'&search_vat='.urlencode($search_vat);
440 if ($search_current_account > 0) {
441 $param .=
"&search_current_account=".urlencode($search_current_account);
443 if ($search_current_account_valid && $search_current_account_valid !=
'-1') {
444 $param .=
"&search_current_account_valid=".urlencode($search_current_account_valid);
446 if ($accounting_product_mode) {
447 $param .=
'&accounting_product_mode='.urlencode($accounting_product_mode);
450 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
451 if ($optioncss !=
'') {
452 print
'<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
454 print
'<input type="hidden" name="token" value="'.newToken().
'">';
455 print
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
456 print
'<input type="hidden" name="action" value="update">';
457 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
458 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
460 print
load_fiche_titre($langs->trans(
"ProductsBinding"),
'',
'title_accountancy');
463 print
'<span class="opacitymedium">'.$langs->trans(
"InitAccountancyDesc").
'</span><br>';
467 print
'<table class="noborder centpercent">';
468 print
'<tr class="liste_titre">';
469 print
'<td>'.$langs->trans(
'Options').
'</td><td>'.$langs->trans(
'Description').
'</td>';
471 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>';
472 print
'<td>'.$langs->trans(
'OptionModeProductSellDesc');
473 print
"</td></tr>\n";
474 if ($mysoc->isInEEC()) {
475 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>';
476 print
'<td>'.$langs->trans(
'OptionModeProductSellIntraDesc');
477 print
"</td></tr>\n";
479 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>';
480 print
'<td>'.$langs->trans(
'OptionModeProductSellExportDesc');
481 print
"</td></tr>\n";
482 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>';
483 print
'<td>'.$langs->trans(
'OptionModeProductBuyDesc').
"</td></tr>\n";
484 if ($mysoc->isInEEC()) {
485 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>';
486 print
'<td>'.$langs->trans(
'OptionModeProductBuyDesc').
"</td></tr>\n";
488 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>';
489 print
'<td>'.$langs->trans(
'OptionModeProductBuyDesc').
"</td></tr>\n";
492 print
'<div class="center"><input type="submit" class="button" value="'.$langs->trans(
'Refresh').
'" name="changetype"></div>';
499 $varpage = empty($contextpage) ? $_SERVER[
"PHP_SELF"] : $contextpage;
500 $selectedfields =
$form->multiSelectArrayWithCheckbox(
'selectedfields', $arrayfields, $varpage);
502 if ($massaction !==
'set_default_account') {
503 $arrayofmassactions = array(
504 'changeaccount'=>
img_picto(
'',
'check',
'class="pictofixedwidth"').$langs->trans(
"Save")
505 ,
'set_default_account'=>
img_picto(
'',
'check',
'class="pictofixedwidth"').$langs->trans(
"ConfirmPreselectAccount")
507 $massactionbutton =
$form->selectMassAction(
'', $arrayofmassactions, 1);
510 $buttonsave =
'<input type="submit" class="button button-save" id="changeaccount" name="changeaccount" value="'.$langs->trans(
"Save").
'">';
513 $texte = $langs->trans(
"ListOfProductsServices");
514 print_barre_liste($texte, $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords,
'', 0,
'',
'', $limit, 0, 0, 1);
516 if ($massaction ==
'set_default_account') {
517 $formquestion[]=array(
'type' =>
'other',
518 'name' =>
'set_default_account',
519 'label' => $langs->trans(
"AccountancyCode"),
520 'value' =>
$form->select_account(
'',
'default_account', 1, array(), 0, 0,
'maxwidth200 maxwidthonsmartphone',
'cachewithshowemptyone'));
521 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);
526 if (
isModEnabled(
'categorie') && $user->hasRight(
'categorie',
'lire')) {
527 $moreforfilter .=
'<div class="divsearchfield">';
528 $moreforfilter .=
img_picto($langs->trans(
'Categories'),
'category',
'class="pictofixedwidth"');
529 $categoriesProductArr =
$form->select_all_categories(Categorie::TYPE_PRODUCT,
'',
'', 64, 0, 1);
530 $categoriesProductArr[-2] =
'- '.$langs->trans(
'NotCategorized').
' -';
531 $moreforfilter .=
Form::multiselectarray(
'search_category_product_list', $categoriesProductArr, $searchCategoryProductList, 0, 0,
'minwidth300');
532 $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>';
533 $moreforfilter .=
'</div>';
537 if (
isModEnabled(
'variants') && !empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD)) {
538 $moreforfilter .=
'<div class="divsearchfield">';
539 $moreforfilter .=
'<input type="checkbox" id="search_show_childproducts" name="search_show_childproducts"'.($show_childproducts ?
'checked="checked"' :
'').
'>';
540 $moreforfilter .=
' <label for="search_show_childproducts">'.$langs->trans(
'ShowChildProducts').
'</label>';
541 $moreforfilter .=
'</div>';
544 $parameters = array();
545 $reshook = $hookmanager->executeHooks(
'printFieldPreListTitle', $parameters);
546 if (empty($reshook)) {
547 $moreforfilter .= $hookmanager->resPrint;
549 $moreforfilter = $hookmanager->resPrint;
552 if ($moreforfilter) {
553 print
'<div class="liste_titre liste_titre_bydiv centpercent">';
554 print $moreforfilter;
558 print
'<div class="div-table-responsive">';
559 print
'<table class="liste '.($moreforfilter ?
"listwithfilterbefore" :
"").
'">';
561 print
'<tr class="liste_titre_filter">';
564 print
'<td class="center liste_titre">';
565 $searchpicto =
$form->showFilterButtons();
569 print
'<td class="liste_titre"><input type="text" class="flat" size="8" name="search_ref" value="'.dol_escape_htmltag($search_ref).
'"></td>';
570 print
'<td class="liste_titre"><input type="text" class="flat" size="10" name="search_label" value="'.dol_escape_htmltag($search_label).
'"></td>';
571 print
'<td class="liste_titre right"><input type="text" class="flat maxwidth50 right" name="search_vat" placeholder="%" value="'.dol_escape_htmltag($search_vat).
'"></td>';
573 if (!empty($conf->global->ACCOUNTANCY_SHOW_PROD_DESC)) {
574 print
'<td class="liste_titre"><input type="text" class="flat" size="20" name="search_desc" value="'.dol_escape_htmltag($search_desc).
'"></td>';
577 if ($accounting_product_mode ==
'ACCOUNTANCY_SELL' || $accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA' || $accounting_product_mode ==
'ACCOUNTANCY_SELL_EXPORT') {
578 print
'<td class="liste_titre center">'.$form->selectyesno(
'search_onsell', $search_onsell, 1,
false, 1).
'</td>';
581 print
'<td class="liste_titre center">'.$form->selectyesno(
'search_onpurchase', $search_onpurchase, 1,
false, 1).
'</td>';
584 print
'<td class="liste_titre">';
585 print
'<input type="text" class="flat" size="6" name="search_current_account" id="search_current_account" value="'.dol_escape_htmltag($search_current_account).
'">';
586 $listofvals = array(
'withoutvalidaccount'=>$langs->trans(
"WithoutValidAccount"),
'withvalidaccount'=>$langs->trans(
"WithValidAccount"));
587 print
' '.$langs->trans(
"or").
' '.
$form->selectarray(
'search_current_account_valid', $listofvals, $search_current_account_valid, 1);
589 print
'<td class="liste_titre"> </td>';
592 print
'<td class="center liste_titre">';
593 $searchpicto =
$form->showFilterButtons();
599 print
'<tr class="liste_titre">';
602 $clickpitco =
$form->showCheckAddButtons(
'checkforselect', 1);
607 if (!empty($conf->global->ACCOUNTANCY_SHOW_PROD_DESC)) {
608 print_liste_field_titre(
"Description", $_SERVER[
"PHP_SELF"],
"p.description",
"", $param,
'', $sortfield, $sortorder);
610 print_liste_field_titre(
"VATRate", $_SERVER[
"PHP_SELF"],
"p.tva_tx",
"", $param,
'', $sortfield, $sortorder,
'right ');
612 if ($accounting_product_mode ==
'ACCOUNTANCY_SELL' || $accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA' || $accounting_product_mode ==
'ACCOUNTANCY_SELL_EXPORT') {
613 print_liste_field_titre(
"OnSell", $_SERVER[
"PHP_SELF"],
"p.tosell",
"", $param,
'', $sortfield, $sortorder,
'center ');
615 print_liste_field_titre(
"OnBuy", $_SERVER[
"PHP_SELF"],
"p.tobuy",
"", $param,
'', $sortfield, $sortorder,
'center ');
617 print_liste_field_titre(
"CurrentDedicatedAccountingAccount", $_SERVER[
"PHP_SELF"], (empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED) ?
"p." :
"ppe.") . $accountancy_field_name,
"", $param,
'', $sortfield, $sortorder);
621 $clickpitco =
$form->showCheckAddButtons(
'checkforselect', 1);
626 $product_static =
new Product($db);
629 while ($i < min($num, $limit)) {
630 $obj = $db->fetch_object($resql);
633 $product_static->ref = $obj->ref;
634 $product_static->id = $obj->rowid;
635 $product_static->type = $obj->product_type;
636 $product_static->label = $obj->label;
637 $product_static->description = $obj->description;
638 $product_static->status = $obj->tosell;
639 $product_static->status_buy = $obj->tobuy;
642 if ($obj->product_type == 0) {
643 if ($accounting_product_mode ==
'ACCOUNTANCY_SELL') {
644 $compta_prodsell = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans(
"CodeNotDef"));
645 $compta_prodsell_id = $aarowid_prodsell;
646 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA') {
647 $compta_prodsell = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT : $langs->trans(
"CodeNotDef"));
648 $compta_prodsell_id = $aarowid_prodsell_intra;
649 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL_EXPORT') {
650 $compta_prodsell = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT : $langs->trans(
"CodeNotDef"));
651 $compta_prodsell_id = $aarowid_prodsell_export;
653 $compta_prodsell = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans(
"CodeNotDef"));
654 $compta_prodsell_id = $aarowid_prodsell;
657 if ($accounting_product_mode ==
'ACCOUNTANCY_SELL') {
658 $compta_prodsell = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans(
"CodeNotDef"));
659 $compta_prodsell_id = $aarowid_servsell;
660 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA') {
661 $compta_prodsell = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT : $langs->trans(
"CodeNotDef"));
662 $compta_prodsell_id = $aarowid_servsell_intra;
663 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL_EXPORT') {
664 $compta_prodsell = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT : $langs->trans(
"CodeNotDef"));
665 $compta_prodsell_id = $aarowid_servsell_export;
667 $compta_prodsell = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans(
"CodeNotDef"));
668 $compta_prodsell_id = $aarowid_servsell;
673 if ($obj->product_type == 0) {
674 if ($accounting_product_mode ==
'ACCOUNTANCY_BUY') {
675 $compta_prodbuy = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : $langs->trans(
"CodeNotDef"));
676 $compta_prodbuy_id = $aarowid_prodbuy;
677 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_INTRA') {
678 $compta_prodbuy = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT : $langs->trans(
"CodeNotDef"));
679 $compta_prodbuy_id = $aarowid_prodbuy_intra;
680 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_EXPORT') {
681 $compta_prodbuy = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT : $langs->trans(
"CodeNotDef"));
682 $compta_prodbuy_id = $aarowid_prodbuy_export;
684 $compta_prodbuy = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : $langs->trans(
"CodeNotDef"));
685 $compta_prodbuy_id = $aarowid_prodbuy;
688 if ($accounting_product_mode ==
'ACCOUNTANCY_BUY') {
689 $compta_prodbuy = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : $langs->trans(
"CodeNotDef"));
690 $compta_prodbuy_id = $aarowid_servbuy;
691 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_INTRA') {
692 $compta_prodbuy = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT : $langs->trans(
"CodeNotDef"));
693 $compta_prodbuy_id = $aarowid_servbuy_intra;
694 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_EXPORT') {
695 $compta_prodbuy = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT : $langs->trans(
"CodeNotDef"));
696 $compta_prodbuy_id = $aarowid_servbuy_export;
698 $compta_prodbuy = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : $langs->trans(
"CodeNotDef"));
699 $compta_prodbuy_id = $aarowid_servbuy;
704 if (!empty($chk_prod)) {
705 if (in_array($product_static->id, $chk_prod)) {
710 print
'<tr class="oddeven">';
714 print
'<td class="center">';
715 print
'<input type="checkbox" class="checkforselect productforselectcodeventil_'.$product_static->id.
'" name="chk_prod[]" '.($selected ?
"checked" :
"").
' value="'.$obj->rowid.
'"/>';
720 print $product_static->getNomUrl(1);
723 print
'<td class="left">'.$obj->label.
'</td>';
725 if (!empty($conf->global->ACCOUNTANCY_SHOW_PROD_DESC)) {
729 $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
730 print
'<td>'.nl2br(
dol_trunc($obj->description, $trunclength)).
'</td>';
734 print
'<td class="right">';
739 if ($accounting_product_mode ==
'ACCOUNTANCY_SELL' || $accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA' || $accounting_product_mode ==
'ACCOUNTANCY_SELL_EXPORT') {
740 print
'<td class="center">'.$product_static->getLibStatut(3, 0).
'</td>';
742 print
'<td class="center">'.$product_static->getLibStatut(3, 1).
'</td>';
746 print
'<td class="left">';
747 if ($accounting_product_mode ==
'ACCOUNTANCY_BUY') {
749 if ($obj->accountancy_code_buy && empty($obj->aaid)) {
750 print
' '.img_warning($langs->trans(
"ValueNotIntoChartOfAccount"));
752 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_INTRA') {
754 if ($obj->accountancy_code_buy_intra && empty($obj->aaid)) {
755 print
' '.img_warning($langs->trans(
"ValueNotIntoChartOfAccount"));
757 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_EXPORT') {
759 if ($obj->accountancy_code_buy_export && empty($obj->aaid)) {
760 print
' '.img_warning($langs->trans(
"ValueNotIntoChartOfAccount"));
762 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL') {
764 if ($obj->accountancy_code_sell && empty($obj->aaid)) {
765 print
' '.img_warning($langs->trans(
"ValueNotIntoChartOfAccount"));
767 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA') {
769 if ($obj->accountancy_code_sell_intra && empty($obj->aaid)) {
770 print
' '.img_warning($langs->trans(
"ValueNotIntoChartOfAccount"));
774 if ($obj->accountancy_code_sell_export && empty($obj->aaid)) {
775 print
' '.img_warning($langs->trans(
"ValueNotIntoChartOfAccount"));
782 if ($accounting_product_mode ==
'ACCOUNTANCY_BUY') {
784 print
'<td class="left">';
786 if (empty($defaultvalue)) {
787 $defaultvalue = $compta_prodbuy;
790 if (!empty($obj->aaid)) {
793 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');
795 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_INTRA') {
797 print
'<td class="left">';
799 if (empty($defaultvalue)) {
800 $defaultvalue = $compta_prodbuy;
804 if (!empty($obj->aaid)) {
807 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');
809 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_BUY_EXPORT') {
811 print
'<td class="left">';
813 if (empty($defaultvalue)) {
814 $defaultvalue = $compta_prodbuy;
818 if (!empty($obj->aaid)) {
821 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');
823 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL') {
825 print
'<td class="left">';
827 if (empty($defaultvalue)) {
828 $defaultvalue = $compta_prodsell;
832 if (!empty($obj->aaid)) {
835 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');
837 } elseif ($accounting_product_mode ==
'ACCOUNTANCY_SELL_INTRA') {
839 print
'<td class="left">';
841 if (empty($defaultvalue)) {
842 $defaultvalue = $compta_prodsell;
846 if (!empty($obj->aaid)) {
849 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');
853 print
'<td class="left">';
855 if (empty($defaultvalue)) {
856 $defaultvalue = $compta_prodsell;
859 if (!empty($obj->aaid)) {
862 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');
868 print
'<td class="center">';
869 print
'<input type="checkbox" class="checkforselect productforselectcodeventil_'.$product_static->id.
'" name="chk_prod[]" '.($selected ?
"checked" :
"").
' value="'.$obj->rowid.
'"/>';
879 print
'<script type="text/javascript">
880 jQuery(document).ready(function() {
881 function init_savebutton()
883 console.log("We check if at least one line is checked")
885 atleastoneselected=0;
886 jQuery(".checkforselect").each(function( index ) {
887 /* console.log( index + ": " + $( this ).text() ); */
888 if ($(this).is(\':checked\')) atleastoneselected++;
891 if (atleastoneselected) jQuery("#changeaccount").removeAttr(\'disabled\');
892 else jQuery("#changeaccount").attr(\'disabled\',\'disabled\');
893 if (atleastoneselected) jQuery("#changeaccount").attr(\'class\',\'button\');
894 else jQuery("#changeaccount").attr(\'class\',\'button\');
897 jQuery(".checkforselect").change(function() {
900 jQuery(".productforselect").change(function() {
901 console.log($(this).attr("id")+" "+$(this).val());
902 if ($(this).val() && $(this).val() != -1) {
903 $(".productforselect"+$(this).attr("id")).prop(\'checked\', true);
905 $(".productforselect"+$(this).attr("id")).prop(\'checked\', false);
912 jQuery("#search_current_account").keyup(function() {
913 if (jQuery("#search_current_account").val() != \'\')
915 console.log("We set a value of account to search "+jQuery("#search_current_account").val()+", so we disable the other search criteria on account");
916 jQuery("#search_current_account_valid").val(-1);