productaccount.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. <?php
  2. /* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
  3. * Copyright (C) 2013-2019 Alexandre Spangaro <aspangaro@open-dsi.fr>
  4. * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
  5. * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2015 Ari Elbaz (elarifr) <github@accedinfo.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/accountancy/admin/productaccount.php
  23. * \ingroup Accountancy (Double entries)
  24. * \brief To define accounting account on product / service
  25. */
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
  28. require_once DOL_DOCUMENT_ROOT . '/core/lib/report.lib.php';
  29. require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
  30. require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
  31. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
  32. require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
  33. require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
  34. // Load translation files required by the page
  35. $langs->loadLangs(array("companies","compta","accountancy","products"));
  36. // Security check
  37. if (empty($conf->accounting->enabled)) {
  38. accessforbidden();
  39. }
  40. if (! $user->rights->accounting->bind->write)
  41. accessforbidden();
  42. // search & action GETPOST
  43. $action = GETPOST('action', 'aZ09');
  44. $codeventil_buy = GETPOST('codeventil_buy', 'array');
  45. $codeventil_sell = GETPOST('codeventil_sell', 'array');
  46. $chk_prod = GETPOST('chk_prod', 'array');
  47. $account_number_buy = GETPOST('account_number_buy');
  48. $account_number_sell = GETPOST('account_number_sell');
  49. $changeaccount = GETPOST('changeaccount', 'array');
  50. $changeaccount_buy = GETPOST('changeaccount_buy', 'array');
  51. $changeaccount_sell = GETPOST('changeaccount_sell', 'array');
  52. $search_ref = GETPOST('search_ref', 'alpha');
  53. $search_label = GETPOST('search_label', 'alpha');
  54. $search_desc = GETPOST('search_desc', 'alpha');
  55. $search_current_account = GETPOST('search_current_account', 'alpha');
  56. $search_current_account_valid = GETPOST('search_current_account_valid', 'alpha');
  57. if ($search_current_account_valid == '') $search_current_account_valid='withoutvalidaccount';
  58. $accounting_product_mode = GETPOST('accounting_product_mode', 'alpha');
  59. $btn_changeaccount = GETPOST('changeaccount', 'alpha');
  60. $btn_changetype = GETPOST('changetype', 'alpha');
  61. if (empty($accounting_product_mode)) $accounting_product_mode='ACCOUNTANCY_SELL';
  62. $limit = GETPOST('limit', 'int')?GETPOST('limit', 'int'):(empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
  63. $sortfield = GETPOST("sortfield", 'alpha');
  64. $sortorder = GETPOST("sortorder", 'alpha');
  65. $page = GETPOST("page", 'int');
  66. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  67. $offset = $limit * $page;
  68. $pageprev = $page - 1;
  69. $pagenext = $page + 1;
  70. if (! $sortfield) $sortfield="p.ref";
  71. if (! $sortorder) $sortorder="ASC";
  72. if (empty($action)) $action='list';
  73. $arrayfields=array();
  74. /*
  75. * Actions
  76. */
  77. if (GETPOST('cancel', 'alpha')) { $action='list'; $massaction=''; }
  78. if (! GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
  79. $parameters=array();
  80. $reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  81. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  82. // Purge search criteria
  83. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All test are required to be compatible with all browsers
  84. {
  85. $search_ref = '';
  86. $search_label = '';
  87. $search_desc = '';
  88. $search_current_account = '';
  89. $search_current_account_valid = '-1';
  90. }
  91. // Sales or Purchase mode ?
  92. if ($action == 'update') {
  93. if (! empty($btn_changetype)) {
  94. $error = 0;
  95. $accounting_product_modes = array (
  96. 'ACCOUNTANCY_SELL',
  97. 'ACCOUNTANCY_SELL_INTRA',
  98. 'ACCOUNTANCY_SELL_EXPORT',
  99. 'ACCOUNTANCY_BUY'
  100. );
  101. if (in_array($accounting_product_mode, $accounting_product_modes)) {
  102. if (! dolibarr_set_const($db, 'ACCOUNTING_PRODUCT_MODE', $accounting_product_mode, 'chaine', 0, '', $conf->entity)) {
  103. $error ++;
  104. }
  105. } else {
  106. $error ++;
  107. }
  108. }
  109. if (! empty($btn_changeaccount)) {
  110. //$msg = '<div><span class="accountingprocessing">' . $langs->trans("Processing") . '...</span></div>';
  111. if (! empty($chk_prod)) {
  112. $accounting = new AccountingAccount($db);
  113. //$msg .= '<div><span class="accountingprocessing">' . count($chk_prod) . ' ' . $langs->trans("SelectedLines") . '</span></div>';
  114. $arrayofdifferentselectedvalues = array();
  115. $cpt = 0; $ok = 0; $ko = 0;
  116. foreach ($chk_prod as $productid)
  117. {
  118. $accounting_account_id = GETPOST('codeventil_' . $productid);
  119. $result = 0;
  120. if ($accounting_account_id > 0)
  121. {
  122. $arrayofdifferentselectedvalues[$accounting_account_id]=$accounting_account_id;
  123. $result = $accounting->fetch($accounting_account_id, null, 1);
  124. }
  125. if ($result <= 0) {
  126. // setEventMessages(null, $accounting->errors, 'errors');
  127. $msg .= '<div><font color="red">' . $langs->trans("ErrorDB") . ' : ' . $langs->trans("Product") . ' ' . $productid . ' ' . $langs->trans("NotVentilatedinAccount") . ' : id=' . $accounting_account_id . '<br/> <pre>' . $sql . '</pre></font></div>';
  128. $ko++;
  129. } else {
  130. $db->begin();
  131. $sql = " UPDATE " . MAIN_DB_PREFIX . "product";
  132. if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
  133. $sql .= " SET accountancy_code_buy = " . $accounting->account_number;
  134. }
  135. if ($accounting_product_mode == 'ACCOUNTANCY_SELL') {
  136. $sql .= " SET accountancy_code_sell = " . $accounting->account_number;
  137. }
  138. if ($accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA') {
  139. $sql .= " SET accountancy_code_sell_intra = " . $accounting->account_number;
  140. }
  141. if ($accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT') {
  142. $sql .= " SET accountancy_code_sell_export = " . $accounting->account_number;
  143. }
  144. $sql .= " WHERE rowid = " . $productid;
  145. dol_syslog("/accountancy/admin/productaccount.php sql=" . $sql, LOG_DEBUG);
  146. if ($db->query($sql))
  147. {
  148. $ok++;
  149. $db->commit();
  150. } else {
  151. $ko++;
  152. $db->rollback();
  153. }
  154. }
  155. $cpt++;
  156. }
  157. }
  158. if ($ko) setEventMessages($langs->trans("XLineFailedToBeBinded", $ko), null, 'errors');
  159. if ($ok) setEventMessages($langs->trans("XLineSuccessfullyBinded", $ok), null, 'mesgs');
  160. }
  161. }
  162. /*
  163. * View
  164. */
  165. $form = new FormAccounting($db);
  166. // Default AccountingAccount RowId Product / Service
  167. // at this time ACCOUNTING_SERVICE_SOLD_ACCOUNT & ACCOUNTING_PRODUCT_SOLD_ACCOUNT are account number not accountingacount rowid
  168. // so we need to get those default value rowid first
  169. $accounting = new AccountingAccount($db);
  170. // TODO: we should need to check if result is already exists accountaccount rowid.....
  171. $aarowid_servbuy = $accounting->fetch('', $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT, 1);
  172. $aarowid_prodbuy = $accounting->fetch('', $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT, 1);
  173. $aarowid_servsell = $accounting->fetch('', $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT, 1);
  174. $aarowid_prodsell = $accounting->fetch('', $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT, 1);
  175. $aarowid_prodsell_intra = $accounting->fetch('', $conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT, 1);
  176. $aarowid_prodsell_export = $accounting->fetch('', $conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT, 1);
  177. $aacompta_servbuy = (! empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
  178. $aacompta_prodbuy = (! empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
  179. $aacompta_servsell = (! empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans("CodeNotDef"));
  180. $aacompta_prodsell = (! empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans("CodeNotDef"));
  181. $aacompta_prodsell_intra = (! empty($conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT : $langs->trans("CodeNotDef"));
  182. $aacompta_prodsell_export = (! empty($conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT : $langs->trans("CodeNotDef"));
  183. llxHeader('', $langs->trans("ProductsBinding"));
  184. $pcgverid = $conf->global->CHARTOFACCOUNTS;
  185. $pcgvercode = dol_getIdFromCode($db, $pcgverid, 'accounting_system', 'rowid', 'pcg_version');
  186. if (empty($pcgvercode)) $pcgvercode=$pcgverid;
  187. $sql = "SELECT p.rowid, p.ref, p.label, p.description, p.tosell, p.tobuy, p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export, p.accountancy_code_buy, p.tms, p.fk_product_type as product_type,";
  188. $sql.= " aa.rowid as aaid";
  189. $sql.= " FROM " . MAIN_DB_PREFIX . "product as p";
  190. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON";
  191. if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
  192. $sql.=" p.accountancy_code_buy = aa.account_number AND aa.fk_pcg_version = '" . $pcgvercode . "'";
  193. }
  194. elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL')
  195. {
  196. $sql.=" p.accountancy_code_sell = aa.account_number AND aa.fk_pcg_version = '" . $pcgvercode . "'";
  197. }
  198. elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA')
  199. {
  200. $sql.=" p.accountancy_code_sell_intra = aa.account_number AND aa.fk_pcg_version = '" . $pcgvercode . "'";
  201. }
  202. else
  203. {
  204. $sql.=" p.accountancy_code_sell_intra = aa.account_number AND aa.fk_pcg_version = '" . $pcgvercode . "'";
  205. }
  206. $sql.= ' WHERE p.entity IN ('.getEntity('product').')';
  207. if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
  208. if (strlen(trim($search_current_account))) {
  209. $sql .= natural_search("p.accountancy_code_buy", $search_current_account);
  210. }
  211. } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL') {
  212. if (strlen(trim($search_current_account))) {
  213. $sql .= natural_search("p.accountancy_code_sell", $search_current_account);
  214. }
  215. }
  216. elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA') {
  217. if (strlen(trim($search_current_account))) {
  218. $sql .= natural_search("p.accountancy_code_sell_intra", $search_current_account);
  219. }
  220. }
  221. else {
  222. if (strlen(trim($search_current_account))) {
  223. $sql .= natural_search("p.accountancy_code_sell_export", $search_current_account);
  224. }
  225. }
  226. if ($search_current_account_valid == 'withoutvalidaccount')
  227. {
  228. $sql .= " AND aa.account_number IS NULL";
  229. }
  230. if ($search_current_account_valid == 'withvalidaccount')
  231. {
  232. $sql .= " AND aa.account_number IS NOT NULL";
  233. }
  234. // Add search filter like
  235. if (strlen(trim($search_ref))) {
  236. $sql .= natural_search("p.ref", $search_ref);
  237. }
  238. if (strlen(trim($search_label))) {
  239. $sql .= natural_search("p.label", $search_label);
  240. }
  241. if (strlen(trim($search_desc))) {
  242. $sql .= natural_search("p.description", $search_desc);
  243. }
  244. $sql .= $db->order($sortfield, $sortorder);
  245. $nbtotalofrecords = '';
  246. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  247. {
  248. $result = $db->query($sql);
  249. $nbtotalofrecords = $db->num_rows($result);
  250. if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
  251. {
  252. $page = 0;
  253. $offset = 0;
  254. }
  255. }
  256. $sql .= $db->plimit($limit + 1, $offset);
  257. dol_syslog("/accountancy/admin/productaccount.php:: sql=" . $sql, LOG_DEBUG);
  258. $result = $db->query($sql);
  259. if ($result)
  260. {
  261. $num = $db->num_rows($result);
  262. $i = 0;
  263. $param='';
  264. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
  265. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit);
  266. if ($search_ref > 0) $param.="&search_desc=".urlencode($search_ref);
  267. if ($search_label > 0) $param.="&search_desc=".urlencode($search_label);
  268. if ($search_desc > 0) $param.="&search_desc=".urlencode($search_desc);
  269. if ($search_current_account > 0) $param.="&search_current_account=".urlencode($search_current_account);
  270. if ($search_current_account_valid && $search_current_account_valid != '-1') $param.="&search_current_account_valid=".urlencode($search_current_account_valid);
  271. if ($accounting_product_mode) $param.='&accounting_product_mode='.urlencode($accounting_product_mode);
  272. print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">';
  273. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  274. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  275. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  276. print '<input type="hidden" name="action" value="update">';
  277. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  278. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  279. print '<input type="hidden" name="page" value="'.$page.'">';
  280. print load_fiche_titre($langs->trans("ProductsBinding"), '', 'title_accountancy');
  281. print '<br>';
  282. print '<span class="opacitymedium">'.$langs->trans("InitAccountancyDesc") . '</span><br>';
  283. print '<br>';
  284. // Select mode
  285. print '<table class="noborder" width="100%">';
  286. print '<tr class="liste_titre">';
  287. print '<td>' . $langs->trans('Options') . '</td><td>' . $langs->trans('Description') . '</td>';
  288. print "</tr>\n";
  289. print '<tr class="oddeven"><td class="titlefield"><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_SELL"' . ($accounting_product_mode == 'ACCOUNTANCY_SELL' ? ' checked' : '') . '> ' . $langs->trans('OptionModeProductSell') . '</td>';
  290. print '<td>'.$langs->trans('OptionModeProductSellDesc');
  291. print "</td></tr>\n";
  292. if ($mysoc->isInEEC())
  293. {
  294. print '<tr class="oddeven"><td class="titlefield"><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_SELL_INTRA"' . ($accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA' ? ' checked' : '') . '> ' . $langs->trans('OptionModeProductSellIntra') . '</td>';
  295. print '<td>'.$langs->trans('OptionModeProductSellIntraDesc');
  296. print "</td></tr>\n";
  297. }
  298. print '<tr class="oddeven"><td class="titlefield"><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_SELL_EXPORT"' . ($accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT' ? ' checked' : '') . '> ' . $langs->trans('OptionModeProductSellExport') . '</td>';
  299. print '<td>'.$langs->trans('OptionModeProductSellExportDesc');
  300. print "</td></tr>\n";
  301. print '<tr class="oddeven"><td class="titlefield"><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_BUY"' . ($accounting_product_mode == 'ACCOUNTANCY_BUY' ? ' checked' : '') . '> ' . $langs->trans('OptionModeProductBuy') . '</td>';
  302. print '<td>'.$langs->trans('OptionModeProductBuyDesc')."</td></tr>\n";
  303. print "</table>\n";
  304. print '<div class="center"><input type="submit" class="button" value="' . $langs->trans('Refresh') . '" name="changetype"></div>';
  305. print "<br>\n";
  306. // Filter on categories
  307. $moreforfilter='';
  308. $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
  309. $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  310. $buttonsave = '<input type="submit" class="button" id="changeaccount" name="changeaccount" value="' . $langs->trans("Save") . '">';
  311. //print '<br><div class="center">'.$buttonsave.'</div>';
  312. $texte=$langs->trans("ListOfProductsServices");
  313. print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $buttonsave, $num, $nbtotalofrecords, '', 0, '', '', $limit);
  314. print '<div class="div-table-responsive">';
  315. print '<table class="liste '.($moreforfilter?"listwithfilterbefore":"").'">';
  316. print '<tr class="liste_titre_filter">';
  317. print '<td class="liste_titre"><input type="text" class="flat" size="8" name="search_ref" value="' . dol_escape_htmltag($search_ref) . '"></td>';
  318. print '<td class="liste_titre"><input type="text" class="flat" size="10" name="search_label" value="' . dol_escape_htmltag($search_label) . '"></td>';
  319. if (! empty($conf->global->ACCOUNTANCY_SHOW_PROD_DESC)) print '<td class="liste_titre"><input type="text" class="flat" size="20" name="search_desc" value="' . dol_escape_htmltag($search_desc) . '"></td>';
  320. // On sell
  321. if ($accounting_product_mode == 'ACCOUNTANCY_SELL' || $accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA' || $accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT') print '<td class="liste_titre"></td>';
  322. // On buy
  323. if ($accounting_product_mode == 'ACCOUNTANCY_BUY') print '<td class="liste_titre"></td>';
  324. // Current account
  325. print '<td class="liste_titre">';
  326. print '<input type="text" class="flat" size="6" name="search_current_account" id="search_current_account" value="' . dol_escape_htmltag($search_current_account) . '">';
  327. $listofvals=array('withoutvalidaccount'=>$langs->trans("WithoutValidAccount"), 'withvalidaccount'=>$langs->trans("WithValidAccount"));
  328. print ' '.$langs->trans("or").' '.$form->selectarray('search_current_account_valid', $listofvals, $search_current_account_valid, 1);
  329. print '</td>';
  330. print '<td class="liste_titre">&nbsp;</td>';
  331. print '<td class="center liste_titre">';
  332. $searchpicto=$form->showFilterButtons();
  333. print $searchpicto;
  334. print '</td>';
  335. print '</tr>';
  336. print '<tr class="liste_titre">';
  337. print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
  338. print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "p.label", "", $param, '', $sortfield, $sortorder);
  339. if (! empty($conf->global->ACCOUNTANCY_SHOW_PROD_DESC)) print_liste_field_titre("Description", $_SERVER["PHP_SELF"], "p.description", "", $param, '', $sortfield, $sortorder);
  340. if ($accounting_product_mode == 'ACCOUNTANCY_SELL') {
  341. print_liste_field_titre("OnSell", $_SERVER["PHP_SELF"], "p.tosell", "", $param, '', $sortfield, $sortorder, 'center ');
  342. $fieldtosortaccount="p.accountancy_code_sell";
  343. } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA') {
  344. print_liste_field_titre("OnSell", $_SERVER["PHP_SELF"], "p.tosell", "", $param, '', $sortfield, $sortorder, 'center ');
  345. $fieldtosortaccount="p.accountancy_code_sell_intra";
  346. } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT') {
  347. print_liste_field_titre("OnSell", $_SERVER["PHP_SELF"], "p.tosell", "", $param, '', $sortfield, $sortorder, 'center ');
  348. $fieldtosortaccount="p.accountancy_code_sell_export";
  349. } else {
  350. if ($accounting_product_mode == 'ACCOUNTANCY_BUY') print_liste_field_titre("OnBuy", $_SERVER["PHP_SELF"], "p.tobuy", "", $param, '', $sortfield, $sortorder, 'center ');
  351. $fieldtosortaccount="p.accountancy_code_buy";
  352. }
  353. print_liste_field_titre("CurrentDedicatedAccountingAccount", $_SERVER["PHP_SELF"], $fieldtosortaccount, "", $param, '', $sortfield, $sortorder);
  354. print_liste_field_titre("AssignDedicatedAccountingAccount");
  355. $clickpitco=$form->showCheckAddButtons('checkforselect', 1);
  356. print_liste_field_titre($clickpitco, '', '', '', '', '', '', '', 'center ');
  357. print '</tr>';
  358. $product_static = new Product($db);
  359. $i=0;
  360. while ($i < min($num, $limit))
  361. {
  362. $obj = $db->fetch_object($result);
  363. // Ref produit as link
  364. $product_static->ref = $obj->ref;
  365. $product_static->id = $obj->rowid;
  366. $product_static->type = $obj->product_type;
  367. $product_static->label = $obj->label;
  368. $product_static->description = $obj->description;
  369. $product_static->status = $obj->tosell;
  370. $product_static->status_buy = $obj->tobuy;
  371. if ($obj->product_type == 0 && $accounting_product_mode == 'ACCOUNTANCY_SELL') {
  372. $compta_prodsell = (! empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans("CodeNotDef"));
  373. $compta_prodsell_id = $aarowid_prodsell;
  374. } elseif ($obj->product_type == 0 && $accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA') {
  375. $compta_prodsell = (! empty($conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT : $langs->trans("CodeNotDef"));
  376. $compta_prodsell_id = $aarowid_prodsell_intra;
  377. } elseif ($obj->product_type == 0 && $accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT') {
  378. $compta_prodsell = (! empty($conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT : $langs->trans("CodeNotDef"));
  379. $compta_prodsell_id = $aarowid_prodsell_export;
  380. } else {
  381. $compta_prodsell = (! empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans("CodeNotDef"));
  382. $compta_prodsell_id = $aarowid_servsell;
  383. }
  384. if ($obj->product_type == 0) {
  385. $compta_prodbuy = (! empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
  386. $compta_prodbuy_id = $aarowid_prodbuy;
  387. } else {
  388. $compta_prodbuy = (! empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
  389. $compta_prodbuy_id = $aarowid_servbuy;
  390. }
  391. print '<tr class="oddeven">';
  392. print '<td>';
  393. print $product_static->getNomUrl(1);
  394. print '</td>';
  395. print '<td class="left">'.$obj->label.'</td>';
  396. if (! empty($conf->global->ACCOUNTANCY_SHOW_PROD_DESC))
  397. {
  398. // TODO ADJUST DESCRIPTION SIZE
  399. // print '<td class="left">' . $obj->description . '</td>';
  400. // TODO: we shoul set a user defined value to adjust user square / wide screen size
  401. $trunclengh = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
  402. print '<td>' . nl2br(dol_trunc($obj->description, $trunclengh)) . '</td>';
  403. }
  404. if ($accounting_product_mode == 'ACCOUNTANCY_SELL' || $accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA' || $accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT')
  405. print '<td class="center">'.$product_static->getLibStatut(3, 0).'</td>';
  406. if ($accounting_product_mode == 'ACCOUNTANCY_BUY')
  407. print '<td class="center">'.$product_static->getLibStatut(3, 1).'</td>';
  408. // Current accounting account
  409. print '<td class="left">';
  410. if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
  411. print length_accountg($obj->accountancy_code_buy);
  412. if ($obj->accountancy_code_buy && empty($obj->aaid)) print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount"));
  413. } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL') {
  414. print length_accountg($obj->accountancy_code_sell);
  415. if ($obj->accountancy_code_sell && empty($obj->aaid)) print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount"));
  416. } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA') {
  417. print length_accountg($obj->accountancy_code_sell_intra);
  418. if ($obj->accountancy_code_sell_intra && empty($obj->aaid)) print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount"));
  419. } else {
  420. print length_accountg($obj->accountancy_code_sell_export);
  421. if ($obj->accountancy_code_sell_export && empty($obj->aaid)) print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount"));
  422. }
  423. print '</td>';
  424. // Dedicated account
  425. $defaultvalue='';
  426. if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
  427. // Accounting account buy
  428. print '<td class="left">';
  429. //$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code
  430. if (empty($defaultvalue)) $defaultvalue=$compta_prodbuy;
  431. $codesell=length_accountg($obj->accountancy_code_buy);
  432. if (! empty($obj->aaid)) $defaultvalue = ''; // Do not suggest default new value is code is already valid
  433. print $form->select_account($defaultvalue, 'codeventil_' . $product_static->id, 1, array(), 1);
  434. print '</td>';
  435. } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL') {
  436. // Accounting account sell
  437. print '<td class="left">';
  438. //$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code
  439. if (empty($defaultvalue)) $defaultvalue=$compta_prodsell;
  440. $codesell=length_accountg($obj->accountancy_code_sell);
  441. //var_dump($defaultvalue.' - '.$codesell.' - '.$compta_prodsell);
  442. if (! empty($obj->aaid)) $defaultvalue = ''; // Do not suggest default new value is code is already valid
  443. print $form->select_account($defaultvalue, 'codeventil_' . $product_static->id, 1, array(), 1);
  444. print '</td>';
  445. } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA') {
  446. // Accounting account sell intra (In EEC)
  447. print '<td class="left">';
  448. //$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code
  449. if (empty($defaultvalue)) $defaultvalue=$compta_prodsell;
  450. $codesell=length_accountg($obj->accountancy_code_sell_intra);
  451. //var_dump($defaultvalue.' - '.$codesell.' - '.$compta_prodsell);
  452. if (! empty($obj->aaid)) $defaultvalue = ''; // Do not suggest default new value is code is already valid
  453. print $form->select_account($defaultvalue, 'codeventil_' . $product_static->id, 1, array(), 1);
  454. print '</td>';
  455. } else {
  456. // Accounting account sell export (Out of EEC)
  457. print '<td class="left">';
  458. //$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code
  459. if (empty($defaultvalue)) $defaultvalue=$compta_prodsell;
  460. $codesell=length_accountg($obj->accountancy_code_sell_export);
  461. if (! empty($obj->aaid)) $defaultvalue = ''; // Do not suggest default new value is code is already valid
  462. print $form->select_account($defaultvalue, 'codeventil_' . $product_static->id, 1, array(), 1);
  463. print '</td>';
  464. }
  465. // Checkbox select
  466. print '<td class="center">';
  467. print '<input type="checkbox" class="checkforselect" name="chk_prod[]" value="' . $obj->rowid . '"/></td>';
  468. print "</tr>";
  469. $i ++;
  470. }
  471. print '</table>';
  472. print '</div>';
  473. print '<script type="text/javascript" language="javascript">
  474. jQuery(document).ready(function() {
  475. function init_savebutton()
  476. {
  477. console.log("We check if at least one line is checked")
  478. atleastoneselected=0;
  479. jQuery(".checkforselect").each(function( index ) {
  480. /* console.log( index + ": " + $( this ).text() ); */
  481. if ($(this).is(\':checked\')) atleastoneselected++;
  482. });
  483. if (atleastoneselected) jQuery("#changeaccount").removeAttr(\'disabled\');
  484. else jQuery("#changeaccount").attr(\'disabled\',\'disabled\');
  485. if (atleastoneselected) jQuery("#changeaccount").attr(\'class\',\'button\');
  486. else jQuery("#changeaccount").attr(\'class\',\'button\');
  487. }
  488. jQuery(".checkforselect, #checkallactions").click(function() {
  489. init_savebutton();
  490. });
  491. init_savebutton();
  492. jQuery("#search_current_account").keyup(function() {
  493. if (jQuery("#search_current_account").val() != \'\')
  494. {
  495. console.log("We set a value of account to search "+jQuery("#search_current_account").val()+", so we disable the other search criteria on account");
  496. jQuery("#search_current_account_valid").val(-1);
  497. }
  498. });
  499. });
  500. </script>';
  501. print '</form>';
  502. $db->free($result);
  503. } else {
  504. dol_print_error($db);
  505. }
  506. // End of page
  507. llxFooter();
  508. $db->close();