productaccount.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. <?php
  2. /* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
  3. * Copyright (C) 2013-2021 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. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/accountancy/admin/productaccount.php
  24. * \ingroup Accountancy (Double entries)
  25. * \brief To define accounting account on product / service
  26. */
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  35. // Load translation files required by the page
  36. $langs->loadLangs(array("companies", "compta", "accountancy", "products"));
  37. // Security check
  38. if (empty($conf->accounting->enabled)) {
  39. accessforbidden();
  40. }
  41. if (empty($user->rights->accounting->bind->write)) {
  42. accessforbidden();
  43. }
  44. // search & action GETPOST
  45. $action = GETPOST('action', 'aZ09');
  46. $massaction = GETPOST('massaction', 'alpha');
  47. $codeventil_buy = GETPOST('codeventil_buy', 'array');
  48. $codeventil_sell = GETPOST('codeventil_sell', 'array');
  49. $chk_prod = GETPOST('chk_prod', 'array');
  50. $default_account = GETPOST('default_account', 'int');
  51. $confirm = GETPOST('confirm', 'alpha');
  52. $account_number_buy = GETPOST('account_number_buy');
  53. $account_number_sell = GETPOST('account_number_sell');
  54. $changeaccount = GETPOST('changeaccount', 'array');
  55. $changeaccount_buy = GETPOST('changeaccount_buy', 'array');
  56. $changeaccount_sell = GETPOST('changeaccount_sell', 'array');
  57. $search_ref = GETPOST('search_ref', 'alpha');
  58. $search_label = GETPOST('search_label', 'alpha');
  59. $search_desc = GETPOST('search_desc', 'alpha');
  60. $search_vat = GETPOST('search_vat', 'alpha');
  61. $search_current_account = GETPOST('search_current_account', 'alpha');
  62. $search_current_account_valid = GETPOST('search_current_account_valid', 'alpha');
  63. if ($search_current_account_valid == '') {
  64. $search_current_account_valid = 'withoutvalidaccount';
  65. }
  66. $search_onsell = GETPOST('search_onsell', 'alpha');
  67. $search_onpurchase = GETPOST('search_onpurchase', 'alpha');
  68. $accounting_product_mode = GETPOST('accounting_product_mode', 'alpha');
  69. $btn_changetype = GETPOST('changetype', 'alpha');
  70. $optioncss = GETPOST('optioncss', 'alpha');
  71. if (empty($accounting_product_mode)) {
  72. $accounting_product_mode = 'ACCOUNTANCY_SELL';
  73. }
  74. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION) ? $conf->liste_limit : $conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
  75. $sortfield = GETPOST('sortfield', 'aZ09comma');
  76. $sortorder = GETPOST('sortorder', 'aZ09comma');
  77. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  78. if (empty($page) || $page == -1) {
  79. $page = 0;
  80. } // If $page is not defined, or '' or -1
  81. $offset = $limit * $page;
  82. $pageprev = $page - 1;
  83. $pagenext = $page + 1;
  84. if (!$sortfield) {
  85. $sortfield = "p.ref";
  86. }
  87. if (!$sortorder) {
  88. $sortorder = "ASC";
  89. }
  90. if (empty($action)) {
  91. $action = 'list';
  92. }
  93. $arrayfields = array();
  94. $accounting_product_modes = array(
  95. 'ACCOUNTANCY_SELL',
  96. 'ACCOUNTANCY_SELL_INTRA',
  97. 'ACCOUNTANCY_SELL_EXPORT',
  98. 'ACCOUNTANCY_BUY',
  99. 'ACCOUNTANCY_BUY_INTRA',
  100. 'ACCOUNTANCY_BUY_EXPORT'
  101. );
  102. if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
  103. $accountancy_field_name = "accountancy_code_buy";
  104. } elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_INTRA') {
  105. $accountancy_field_name = "accountancy_code_buy_intra";
  106. } elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_EXPORT') {
  107. $accountancy_field_name = "accountancy_code_buy_export";
  108. } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL') {
  109. $accountancy_field_name = "accountancy_code_sell";
  110. } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA') {
  111. $accountancy_field_name = "accountancy_code_sell_intra";
  112. } else { // $accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT'
  113. $accountancy_field_name = "accountancy_code_sell_export";
  114. }
  115. /*
  116. * Actions
  117. */
  118. if (GETPOST('cancel', 'alpha')) {
  119. $action = 'list'; $massaction = '';
  120. }
  121. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  122. $massaction = '';
  123. }
  124. $parameters = array();
  125. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  126. if ($reshook < 0) {
  127. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  128. }
  129. // Purge search criteria
  130. 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
  131. $search_ref = '';
  132. $search_label = '';
  133. $search_desc = '';
  134. $search_vat = '';
  135. $search_onsell = '';
  136. $search_onpurchase = '';
  137. $search_current_account = '';
  138. $search_current_account_valid = '-1';
  139. }
  140. // Sales or Purchase mode ?
  141. if ($action == 'update') {
  142. if (!empty($btn_changetype)) {
  143. $error = 0;
  144. if (in_array($accounting_product_mode, $accounting_product_modes)) {
  145. if (!dolibarr_set_const($db, 'ACCOUNTING_PRODUCT_MODE', $accounting_product_mode, 'chaine', 0, '', $conf->entity)) {
  146. $error++;
  147. }
  148. } else {
  149. $error++;
  150. }
  151. }
  152. if (!empty($chk_prod) && $massaction === 'changeaccount') {
  153. //$msg = '<div><span class="accountingprocessing">' . $langs->trans("Processing") . '...</span></div>';
  154. if (!empty($chk_prod) && in_array($accounting_product_mode, $accounting_product_modes)) {
  155. $accounting = new AccountingAccount($db);
  156. //$msg .= '<div><span class="accountingprocessing">' . count($chk_prod) . ' ' . $langs->trans("SelectedLines") . '</span></div>';
  157. $arrayofdifferentselectedvalues = array();
  158. $cpt = 0; $ok = 0; $ko = 0;
  159. foreach ($chk_prod as $productid) {
  160. $accounting_account_id = GETPOST('codeventil_'.$productid);
  161. $result = 0;
  162. if ($accounting_account_id > 0) {
  163. $arrayofdifferentselectedvalues[$accounting_account_id] = $accounting_account_id;
  164. $result = $accounting->fetch($accounting_account_id, null, 1);
  165. }
  166. if ($result <= 0) {
  167. // setEventMessages(null, $accounting->errors, 'errors');
  168. $msg .= '<div><span style="color:red">'.$langs->trans("ErrorDB").' : '.$langs->trans("Product").' '.$productid.' '.$langs->trans("NotVentilatedinAccount").' : id='.$accounting_account_id.'<br> <pre>'.$sql.'</pre></span></div>';
  169. $ko++;
  170. } else {
  171. $sql = '';
  172. if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
  173. $sql_exists = "SELECT rowid FROM " . MAIN_DB_PREFIX . "product_perentity";
  174. $sql_exists .= " WHERE fk_product = " . ((int) $productid) . " AND entity = " . ((int) $conf->entity);
  175. $resql_exists = $db->query($sql_exists);
  176. if (!$resql_exists) {
  177. $msg .= '<div><span style="color:red">'.$langs->trans("ErrorDB").' : '.$langs->trans("Product").' '.$productid.' '.$langs->trans("NotVentilatedinAccount").' : id='.$accounting_account_id.'<br> <pre>'.$resql_exists.'</pre></span></div>';
  178. $ko++;
  179. } else {
  180. $nb_exists = $db->num_rows($resql_exists);
  181. if ($nb_exists <= 0) {
  182. // insert
  183. $sql = "INSERT INTO " . MAIN_DB_PREFIX . "product_perentity (fk_product, entity, " . $db->escape($accountancy_field_name) . ")";
  184. $sql .= " VALUES (" . ((int) $productid) . ", " . ((int) $conf->entity) . ", '" . $db->escape($accounting->account_number) . "')";
  185. } else {
  186. $obj_exists = $db->fetch_object($resql_exists);
  187. // update
  188. $sql = "UPDATE " . MAIN_DB_PREFIX . "product_perentity";
  189. $sql .= " SET " . $accountancy_field_name . " = '" . $db->escape($accounting->account_number) . "'";
  190. $sql .= " WHERE rowid = " . ((int) $obj_exists->rowid);
  191. }
  192. }
  193. } else {
  194. $sql = " UPDATE ".MAIN_DB_PREFIX."product";
  195. $sql .= " SET ".$accountancy_field_name." = '".$db->escape($accounting->account_number)."'";
  196. $sql .= " WHERE rowid = ".((int) $productid);
  197. }
  198. dol_syslog("/accountancy/admin/productaccount.php", LOG_DEBUG);
  199. $db->begin();
  200. if ($db->query($sql)) {
  201. $ok++;
  202. $db->commit();
  203. } else {
  204. $ko++;
  205. $db->rollback();
  206. }
  207. }
  208. $cpt++;
  209. }
  210. }
  211. if ($ko) {
  212. setEventMessages($langs->trans("XLineFailedToBeBinded", $ko), null, 'errors');
  213. }
  214. if ($ok) {
  215. setEventMessages($langs->trans("XLineSuccessfullyBinded", $ok), null, 'mesgs');
  216. }
  217. }
  218. }
  219. /*
  220. * View
  221. */
  222. $form = new FormAccounting($db);
  223. // Default AccountingAccount RowId Product / Service
  224. // at this time ACCOUNTING_SERVICE_SOLD_ACCOUNT & ACCOUNTING_PRODUCT_SOLD_ACCOUNT are account number not accountingacount rowid
  225. // so we need to get those the rowid of those default value first
  226. $accounting = new AccountingAccount($db);
  227. // TODO: we should need to check if result is already exists accountaccount rowid.....
  228. $aarowid_servbuy = $accounting->fetch('', getDolGlobalString('ACCOUNTING_SERVICE_BUY_ACCOUNT'), 1);
  229. $aarowid_servbuy_intra = $accounting->fetch('', getDolGlobalString('ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT'), 1);
  230. $aarowid_servbuy_export = $accounting->fetch('', getDolGlobalString('ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT'), 1);
  231. $aarowid_prodbuy = $accounting->fetch('', getDolGlobalString('ACCOUNTING_PRODUCT_BUY_ACCOUNT'), 1);
  232. $aarowid_prodbuy_intra = $accounting->fetch('', getDolGlobalString('ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT'), 1);
  233. $aarowid_prodbuy_export = $accounting->fetch('', getDolGlobalString('ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT'), 1);
  234. $aarowid_servsell = $accounting->fetch('', getDolGlobalString('ACCOUNTING_SERVICE_SOLD_ACCOUNT'), 1);
  235. $aarowid_servsell_intra = $accounting->fetch('', getDolGlobalString('ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT'), 1);
  236. $aarowid_servsell_export = $accounting->fetch('', getDolGlobalString('ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT'), 1);
  237. $aarowid_prodsell = $accounting->fetch('', getDolGlobalString('ACCOUNTING_PRODUCT_SOLD_ACCOUNT'), 1);
  238. $aarowid_prodsell_intra = $accounting->fetch('', getDolGlobalString('ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT'), 1);
  239. $aarowid_prodsell_export = $accounting->fetch('', getDolGlobalString('ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT'), 1);
  240. $aacompta_servbuy = getDolGlobalString('ACCOUNTING_SERVICE_BUY_ACCOUNT', $langs->trans("CodeNotDef"));
  241. $aacompta_servbuy_intra = getDolGlobalString('ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT', $langs->trans("CodeNotDef"));
  242. $aacompta_servbuy_export = getDolGlobalString('ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT', $langs->trans("CodeNotDef"));
  243. $aacompta_prodbuy = getDolGlobalString('ACCOUNTING_PRODUCT_BUY_ACCOUNT', $langs->trans("CodeNotDef"));
  244. $aacompta_prodbuy_intra = getDolGlobalString('ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT', $langs->trans("CodeNotDef"));
  245. $aacompta_prodbuy_export = getDolGlobalString('ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT', $langs->trans("CodeNotDef"));
  246. $aacompta_servsell = getDolGlobalString('ACCOUNTING_SERVICE_SOLD_ACCOUNT', $langs->trans("CodeNotDef"));
  247. $aacompta_servsell_intra = getDolGlobalString('ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT', $langs->trans("CodeNotDef"));
  248. $aacompta_servsell_export = getDolGlobalString('ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT', $langs->trans("CodeNotDef"));
  249. $aacompta_prodsell = getDolGlobalString('ACCOUNTING_PRODUCT_SOLD_ACCOUNT', $langs->trans("CodeNotDef"));
  250. $aacompta_prodsell_intra = getDolGlobalString('ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT', $langs->trans("CodeNotDef"));
  251. $aacompta_prodsell_export = getDolGlobalString('ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT', $langs->trans("CodeNotDef"));
  252. llxHeader('', $langs->trans("ProductsBinding"));
  253. $pcgverid = getDolGlobalString('CHARTOFACCOUNTS');
  254. $pcgvercode = dol_getIdFromCode($db, $pcgverid, 'accounting_system', 'rowid', 'pcg_version');
  255. if (empty($pcgvercode)) {
  256. $pcgvercode = $pcgverid;
  257. }
  258. $sql = "SELECT p.rowid, p.ref, p.label, p.description, p.tosell, p.tobuy, p.tva_tx,";
  259. if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
  260. $sql .= " ppe.accountancy_code_sell, ppe.accountancy_code_sell_intra, ppe.accountancy_code_sell_export,";
  261. $sql .= " ppe.accountancy_code_buy, ppe.accountancy_code_buy_intra, ppe.accountancy_code_buy_export,";
  262. } else {
  263. $sql .= " p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export,";
  264. $sql .= " p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export,";
  265. }
  266. $sql .= " p.tms, p.fk_product_type as product_type,";
  267. $sql .= " aa.rowid as aaid";
  268. $sql .= " FROM ".MAIN_DB_PREFIX."product as p";
  269. if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
  270. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
  271. $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) . "'";
  272. } else {
  273. $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) . "'";
  274. }
  275. $sql .= ' WHERE p.entity IN ('.getEntity('product').')';
  276. if (strlen(trim($search_current_account))) {
  277. $sql .= natural_search((empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED) ? "p." : "ppe.") . $accountancy_field_name, $search_current_account);
  278. }
  279. if ($search_current_account_valid == 'withoutvalidaccount') {
  280. $sql .= " AND aa.account_number IS NULL";
  281. }
  282. if ($search_current_account_valid == 'withvalidaccount') {
  283. $sql .= " AND aa.account_number IS NOT NULL";
  284. }
  285. // Add search filter like
  286. if (strlen(trim($search_ref))) {
  287. $sql .= natural_search("p.ref", $search_ref);
  288. }
  289. if (strlen(trim($search_label))) {
  290. $sql .= natural_search("p.label", $search_label);
  291. }
  292. if (strlen(trim($search_desc))) {
  293. $sql .= natural_search("p.description", $search_desc);
  294. }
  295. if (strlen(trim($search_vat))) {
  296. $sql .= natural_search("p.tva_tx", price2num($search_vat), 1);
  297. }
  298. if ($search_onsell != '' && $search_onsell != '-1') {
  299. $sql .= natural_search('p.tosell', $search_onsell, 1);
  300. }
  301. if ($search_onpurchase != '' && $search_onpurchase != '-1') {
  302. $sql .= natural_search('p.tobuy', $search_onpurchase, 1);
  303. }
  304. $sql .= $db->order($sortfield, $sortorder);
  305. $nbtotalofrecords = '';
  306. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  307. $result = $db->query($sql);
  308. $nbtotalofrecords = $db->num_rows($result);
  309. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  310. $page = 0;
  311. $offset = 0;
  312. }
  313. }
  314. $sql .= $db->plimit($limit + 1, $offset);
  315. dol_syslog("/accountancy/admin/productaccount.php", LOG_DEBUG);
  316. $result = $db->query($sql);
  317. if ($result) {
  318. $num = $db->num_rows($result);
  319. $i = 0;
  320. $param = '';
  321. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  322. $param .= '&contextpage='.urlencode($contextpage);
  323. }
  324. if ($limit > 0 && $limit != $conf->liste_limit) {
  325. $param .= '&limit='.urlencode($limit);
  326. }
  327. if ($search_ref > 0) {
  328. $param .= "&search_desc=".urlencode($search_ref);
  329. }
  330. if ($search_label > 0) {
  331. $param .= "&search_desc=".urlencode($search_label);
  332. }
  333. if ($search_desc > 0) {
  334. $param .= "&search_desc=".urlencode($search_desc);
  335. }
  336. if ($search_vat > 0) {
  337. $param .= '&search_vat='.urlencode($search_vat);
  338. }
  339. if ($search_current_account > 0) {
  340. $param .= "&search_current_account=".urlencode($search_current_account);
  341. }
  342. if ($search_current_account_valid && $search_current_account_valid != '-1') {
  343. $param .= "&search_current_account_valid=".urlencode($search_current_account_valid);
  344. }
  345. if ($accounting_product_mode) {
  346. $param .= '&accounting_product_mode='.urlencode($accounting_product_mode);
  347. }
  348. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  349. if ($optioncss != '') {
  350. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  351. }
  352. print '<input type="hidden" name="token" value="'.newToken().'">';
  353. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  354. print '<input type="hidden" name="action" value="update">';
  355. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  356. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  357. print load_fiche_titre($langs->trans("ProductsBinding"), '', 'title_accountancy');
  358. print '<br>';
  359. print '<span class="opacitymedium">'.$langs->trans("InitAccountancyDesc").'</span><br>';
  360. print '<br>';
  361. // Select mode
  362. print '<table class="noborder centpercent">';
  363. print '<tr class="liste_titre">';
  364. print '<td>'.$langs->trans('Options').'</td><td>'.$langs->trans('Description').'</td>';
  365. print "</tr>\n";
  366. print '<tr class="oddeven"><td><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_SELL"'.($accounting_product_mode == 'ACCOUNTANCY_SELL' ? ' checked' : '').'> '.$langs->trans('OptionModeProductSell').'</td>';
  367. print '<td>'.$langs->trans('OptionModeProductSellDesc');
  368. print "</td></tr>\n";
  369. if ($mysoc->isInEEC()) {
  370. print '<tr class="oddeven"><td><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_SELL_INTRA"'.($accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA' ? ' checked' : '').'> '.$langs->trans('OptionModeProductSellIntra').'</td>';
  371. print '<td>'.$langs->trans('OptionModeProductSellIntraDesc');
  372. print "</td></tr>\n";
  373. }
  374. print '<tr class="oddeven"><td><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_SELL_EXPORT"'.($accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT' ? ' checked' : '').'> '.$langs->trans('OptionModeProductSellExport').'</td>';
  375. print '<td>'.$langs->trans('OptionModeProductSellExportDesc');
  376. print "</td></tr>\n";
  377. print '<tr class="oddeven"><td><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_BUY"'.($accounting_product_mode == 'ACCOUNTANCY_BUY' ? ' checked' : '').'> '.$langs->trans('OptionModeProductBuy').'</td>';
  378. print '<td>'.$langs->trans('OptionModeProductBuyDesc')."</td></tr>\n";
  379. if ($mysoc->isInEEC()) {
  380. print '<tr class="oddeven"><td><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_BUY_INTRA"'.($accounting_product_mode == 'ACCOUNTANCY_BUY_INTRA' ? ' checked' : '').'> '.$langs->trans('OptionModeProductBuyIntra').'</td>';
  381. print '<td>'.$langs->trans('OptionModeProductBuyDesc')."</td></tr>\n";
  382. }
  383. print '<tr class="oddeven"><td><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_BUY_EXPORT"'.($accounting_product_mode == 'ACCOUNTANCY_BUY_EXPORT' ? ' checked' : '').'> '.$langs->trans('OptionModeProductBuyExport').'</td>';
  384. print '<td>'.$langs->trans('OptionModeProductBuyDesc')."</td></tr>\n";
  385. print "</table>\n";
  386. print '<div class="center"><input type="submit" class="button" value="'.$langs->trans('Refresh').'" name="changetype"></div>';
  387. print "<br>\n";
  388. // Filter on categories
  389. $moreforfilter = '';
  390. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  391. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  392. if ($massaction !== 'set_default_account') {
  393. $arrayofmassactions = array(
  394. 'changeaccount'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Save")
  395. ,'set_default_account'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("ConfirmPreselectAccount")
  396. );
  397. $massactionbutton = $form->selectMassAction('', $arrayofmassactions, 1);
  398. }
  399. $buttonsave = '<input type="submit" class="button button-save" id="changeaccount" name="changeaccount" value="'.$langs->trans("Save").'">';
  400. //print '<br><div class="center">'.$buttonsave.'</div>';
  401. $texte = $langs->trans("ListOfProductsServices");
  402. print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, '', 0, '', '', $limit, 0, 0, 1);
  403. if ($massaction == 'set_default_account') {
  404. $formquestion[]=array('type' => 'other',
  405. 'name' => 'set_default_account',
  406. 'label' => $langs->trans("AccountancyCode"),
  407. 'value' => $form->select_account('', 'default_account', 1, array(), 0, 0, 'maxwidth200 maxwidthonsmartphone', 'cachewithshowemptyone'));
  408. 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);
  409. }
  410. print '<div class="div-table-responsive">';
  411. print '<table class="liste '.($moreforfilter ? "listwithfilterbefore" : "").'">';
  412. print '<tr class="liste_titre_filter">';
  413. print '<td class="liste_titre"><input type="text" class="flat" size="8" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>';
  414. print '<td class="liste_titre"><input type="text" class="flat" size="10" name="search_label" value="'.dol_escape_htmltag($search_label).'"></td>';
  415. print '<td class="liste_titre right"><input type="text" class="flat maxwidth50 right" size="5" name="search_vat" placeholder="%" value="'.dol_escape_htmltag($search_vat).'"></td>';
  416. if (!empty($conf->global->ACCOUNTANCY_SHOW_PROD_DESC)) {
  417. print '<td class="liste_titre"><input type="text" class="flat" size="20" name="search_desc" value="'.dol_escape_htmltag($search_desc).'"></td>';
  418. }
  419. // On sell
  420. if ($accounting_product_mode == 'ACCOUNTANCY_SELL' || $accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA' || $accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT') {
  421. print '<td class="liste_titre center">'.$form->selectyesno('search_onsell', $search_onsell, 1, false, 1).'</td>';
  422. } else {
  423. // On buy
  424. print '<td class="liste_titre center">'.$form->selectyesno('search_onpurchase', $search_onpurchase, 1, false, 1).'</td>';
  425. }
  426. // Current account
  427. print '<td class="liste_titre">';
  428. print '<input type="text" class="flat" size="6" name="search_current_account" id="search_current_account" value="'.dol_escape_htmltag($search_current_account).'">';
  429. $listofvals = array('withoutvalidaccount'=>$langs->trans("WithoutValidAccount"), 'withvalidaccount'=>$langs->trans("WithValidAccount"));
  430. print ' '.$langs->trans("or").' '.$form->selectarray('search_current_account_valid', $listofvals, $search_current_account_valid, 1);
  431. print '</td>';
  432. print '<td class="liste_titre">&nbsp;</td>';
  433. print '<td class="center liste_titre">';
  434. $searchpicto = $form->showFilterButtons();
  435. print $searchpicto;
  436. print '</td>';
  437. print '</tr>';
  438. print '<tr class="liste_titre">';
  439. print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
  440. print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "p.label", "", $param, '', $sortfield, $sortorder);
  441. if (!empty($conf->global->ACCOUNTANCY_SHOW_PROD_DESC)) {
  442. print_liste_field_titre("Description", $_SERVER["PHP_SELF"], "p.description", "", $param, '', $sortfield, $sortorder);
  443. }
  444. print_liste_field_titre("VATRate", $_SERVER["PHP_SELF"], "p.tva_tx", "", $param, '', $sortfield, $sortorder, 'right ');
  445. // On sell / On purchase
  446. if ($accounting_product_mode == 'ACCOUNTANCY_SELL' || $accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA' || $accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT') {
  447. print_liste_field_titre("OnSell", $_SERVER["PHP_SELF"], "p.tosell", "", $param, '', $sortfield, $sortorder, 'center ');
  448. } else {
  449. print_liste_field_titre("OnBuy", $_SERVER["PHP_SELF"], "p.tobuy", "", $param, '', $sortfield, $sortorder, 'center ');
  450. }
  451. print_liste_field_titre("CurrentDedicatedAccountingAccount", $_SERVER["PHP_SELF"], (empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED) ? "p." : "ppe.") . $accountancy_field_name, "", $param, '', $sortfield, $sortorder);
  452. print_liste_field_titre("AssignDedicatedAccountingAccount");
  453. $clickpitco = $form->showCheckAddButtons('checkforselect', 1);
  454. print_liste_field_titre($clickpitco, '', '', '', '', '', '', '', 'center ');
  455. print '</tr>';
  456. $product_static = new Product($db);
  457. $i = 0;
  458. while ($i < min($num, $limit)) {
  459. $obj = $db->fetch_object($result);
  460. // Ref produit as link
  461. $product_static->ref = $obj->ref;
  462. $product_static->id = $obj->rowid;
  463. $product_static->type = $obj->product_type;
  464. $product_static->label = $obj->label;
  465. $product_static->description = $obj->description;
  466. $product_static->status = $obj->tosell;
  467. $product_static->status_buy = $obj->tobuy;
  468. // Sales
  469. if ($obj->product_type == 0) {
  470. if ($accounting_product_mode == 'ACCOUNTANCY_SELL') {
  471. $compta_prodsell = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans("CodeNotDef"));
  472. $compta_prodsell_id = $aarowid_prodsell;
  473. } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA') {
  474. $compta_prodsell = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT : $langs->trans("CodeNotDef"));
  475. $compta_prodsell_id = $aarowid_prodsell_intra;
  476. } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT') {
  477. $compta_prodsell = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT : $langs->trans("CodeNotDef"));
  478. $compta_prodsell_id = $aarowid_prodsell_export;
  479. } else {
  480. $compta_prodsell = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans("CodeNotDef"));
  481. $compta_prodsell_id = $aarowid_prodsell;
  482. }
  483. } else {
  484. if ($accounting_product_mode == 'ACCOUNTANCY_SELL') {
  485. $compta_prodsell = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans("CodeNotDef"));
  486. $compta_prodsell_id = $aarowid_servsell;
  487. } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA') {
  488. $compta_prodsell = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT : $langs->trans("CodeNotDef"));
  489. $compta_prodsell_id = $aarowid_servsell_intra;
  490. } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT') {
  491. $compta_prodsell = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT : $langs->trans("CodeNotDef"));
  492. $compta_prodsell_id = $aarowid_servsell_export;
  493. } else {
  494. $compta_prodsell = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans("CodeNotDef"));
  495. $compta_prodsell_id = $aarowid_servsell;
  496. }
  497. }
  498. // Purchases
  499. if ($obj->product_type == 0) {
  500. if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
  501. $compta_prodbuy = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
  502. $compta_prodbuy_id = $aarowid_prodbuy;
  503. } elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_INTRA') {
  504. $compta_prodbuy = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT : $langs->trans("CodeNotDef"));
  505. $compta_prodbuy_id = $aarowid_prodbuy_intra;
  506. } elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_EXPORT') {
  507. $compta_prodbuy = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT : $langs->trans("CodeNotDef"));
  508. $compta_prodbuy_id = $aarowid_prodbuy_export;
  509. } else {
  510. $compta_prodbuy = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
  511. $compta_prodbuy_id = $aarowid_prodbuy;
  512. }
  513. } else {
  514. if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
  515. $compta_prodbuy = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
  516. $compta_prodbuy_id = $aarowid_servbuy;
  517. } elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_INTRA') {
  518. $compta_prodbuy = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT : $langs->trans("CodeNotDef"));
  519. $compta_prodbuy_id = $aarowid_servbuy_intra;
  520. } elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_EXPORT') {
  521. $compta_prodbuy = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT : $langs->trans("CodeNotDef"));
  522. $compta_prodbuy_id = $aarowid_servbuy_export;
  523. } else {
  524. $compta_prodbuy = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
  525. $compta_prodbuy_id = $aarowid_servbuy;
  526. }
  527. }
  528. print '<tr class="oddeven">';
  529. print '<td>';
  530. print $product_static->getNomUrl(1);
  531. print '</td>';
  532. print '<td class="left">'.$obj->label.'</td>';
  533. if (!empty($conf->global->ACCOUNTANCY_SHOW_PROD_DESC)) {
  534. // TODO ADJUST DESCRIPTION SIZE
  535. // print '<td class="left">' . $obj->description . '</td>';
  536. // TODO: we should set a user defined value to adjust user square / wide screen size
  537. $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
  538. print '<td>'.nl2br(dol_trunc($obj->description, $trunclength)).'</td>';
  539. }
  540. // VAT
  541. print '<td class="right">';
  542. print vatrate($obj->tva_tx);
  543. print '</td>';
  544. // On sell / On purchase
  545. if ($accounting_product_mode == 'ACCOUNTANCY_SELL' || $accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA' || $accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT') {
  546. print '<td class="center">'.$product_static->getLibStatut(3, 0).'</td>';
  547. } else {
  548. print '<td class="center">'.$product_static->getLibStatut(3, 1).'</td>';
  549. }
  550. // Current accounting account
  551. print '<td class="left">';
  552. if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
  553. print length_accountg($obj->accountancy_code_buy);
  554. if ($obj->accountancy_code_buy && empty($obj->aaid)) {
  555. print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount"));
  556. }
  557. } elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_INTRA') {
  558. print length_accountg($obj->accountancy_code_buy_intra);
  559. if ($obj->accountancy_code_buy_intra && empty($obj->aaid)) {
  560. print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount"));
  561. }
  562. } elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_EXPORT') {
  563. print length_accountg($obj->accountancy_code_buy_export);
  564. if ($obj->accountancy_code_buy_export && empty($obj->aaid)) {
  565. print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount"));
  566. }
  567. } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL') {
  568. print length_accountg($obj->accountancy_code_sell);
  569. if ($obj->accountancy_code_sell && empty($obj->aaid)) {
  570. print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount"));
  571. }
  572. } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA') {
  573. print length_accountg($obj->accountancy_code_sell_intra);
  574. if ($obj->accountancy_code_sell_intra && empty($obj->aaid)) {
  575. print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount"));
  576. }
  577. } else {
  578. print length_accountg($obj->accountancy_code_sell_export);
  579. if ($obj->accountancy_code_sell_export && empty($obj->aaid)) {
  580. print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount"));
  581. }
  582. }
  583. print '</td>';
  584. // New account to set
  585. $defaultvalue = '';
  586. if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
  587. // Accounting account buy
  588. print '<td class="left">';
  589. //$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code
  590. if (empty($defaultvalue)) {
  591. $defaultvalue = $compta_prodbuy;
  592. }
  593. $codesell = length_accountg($obj->accountancy_code_buy);
  594. if (!empty($obj->aaid)) {
  595. $defaultvalue = ''; // Do not suggest default new value is code is already valid
  596. }
  597. 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');
  598. print '</td>';
  599. } elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_INTRA') {
  600. // Accounting account buy intra (In EEC)
  601. print '<td class="left">';
  602. //$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code
  603. if (empty($defaultvalue)) {
  604. $defaultvalue = $compta_prodbuy;
  605. }
  606. $codesell = length_accountg($obj->accountancy_code_buy_intra);
  607. //var_dump($defaultvalue.' - '.$codesell.' - '.$compta_prodsell);
  608. if (!empty($obj->aaid)) {
  609. $defaultvalue = ''; // Do not suggest default new value is code is already valid
  610. }
  611. 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');
  612. print '</td>';
  613. } elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_EXPORT') {
  614. // Accounting account buy export (Out of EEC)
  615. print '<td class="left">';
  616. //$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code
  617. if (empty($defaultvalue)) {
  618. $defaultvalue = $compta_prodbuy;
  619. }
  620. $codesell = length_accountg($obj->accountancy_code_buy_export);
  621. //var_dump($defaultvalue.' - '.$codesell.' - '.$compta_prodsell);
  622. if (!empty($obj->aaid)) {
  623. $defaultvalue = ''; // Do not suggest default new value is code is already valid
  624. }
  625. 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');
  626. print '</td>';
  627. } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL') {
  628. // Accounting account sell
  629. print '<td class="left">';
  630. //$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code
  631. if (empty($defaultvalue)) {
  632. $defaultvalue = $compta_prodsell;
  633. }
  634. $codesell = length_accountg($obj->accountancy_code_sell);
  635. //var_dump($defaultvalue.' - '.$codesell.' - '.$compta_prodsell);
  636. if (!empty($obj->aaid)) {
  637. $defaultvalue = ''; // Do not suggest default new value is code is already valid
  638. }
  639. 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');
  640. print '</td>';
  641. } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA') {
  642. // Accounting account sell intra (In EEC)
  643. print '<td class="left">';
  644. //$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code
  645. if (empty($defaultvalue)) {
  646. $defaultvalue = $compta_prodsell;
  647. }
  648. $codesell = length_accountg($obj->accountancy_code_sell_intra);
  649. //var_dump($defaultvalue.' - '.$codesell.' - '.$compta_prodsell);
  650. if (!empty($obj->aaid)) {
  651. $defaultvalue = ''; // Do not suggest default new value is code is already valid
  652. }
  653. 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');
  654. print '</td>';
  655. } else {
  656. // Accounting account sell export (Out of EEC)
  657. print '<td class="left">';
  658. //$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code
  659. if (empty($defaultvalue)) {
  660. $defaultvalue = $compta_prodsell;
  661. }
  662. $codesell = length_accountg($obj->accountancy_code_sell_export);
  663. if (!empty($obj->aaid)) {
  664. $defaultvalue = ''; // Do not suggest default new value is code is already valid
  665. }
  666. 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');
  667. print '</td>';
  668. }
  669. if (!empty($chk_prod)) {
  670. $ischecked = 0;
  671. if (in_array($product_static->id, $chk_prod)) {
  672. $ischecked=true;
  673. }
  674. }
  675. // Checkbox select
  676. print '<td class="center">';
  677. print '<input type="checkbox" class="checkforselect productforselectcodeventil_'.$product_static->id.'" name="chk_prod[]" '.($ischecked ? "checked" : "").' value="'.$obj->rowid.'"/></td>';
  678. print "</tr>";
  679. $i++;
  680. }
  681. print '</table>';
  682. print '</div>';
  683. print '<script type="text/javascript">
  684. jQuery(document).ready(function() {
  685. function init_savebutton()
  686. {
  687. console.log("We check if at least one line is checked")
  688. atleastoneselected=0;
  689. jQuery(".checkforselect").each(function( index ) {
  690. /* console.log( index + ": " + $( this ).text() ); */
  691. if ($(this).is(\':checked\')) atleastoneselected++;
  692. });
  693. if (atleastoneselected) jQuery("#changeaccount").removeAttr(\'disabled\');
  694. else jQuery("#changeaccount").attr(\'disabled\',\'disabled\');
  695. if (atleastoneselected) jQuery("#changeaccount").attr(\'class\',\'button\');
  696. else jQuery("#changeaccount").attr(\'class\',\'button\');
  697. }
  698. jQuery(".checkforselect").change(function() {
  699. init_savebutton();
  700. });
  701. jQuery(".productforselect").change(function() {
  702. console.log($(this).attr("id")+" "+$(this).val());
  703. if ($(this).val() && $(this).val() != -1) {
  704. $(".productforselect"+$(this).attr("id")).prop(\'checked\', true);
  705. } else {
  706. $(".productforselect"+$(this).attr("id")).prop(\'checked\', false);
  707. }
  708. init_savebutton();
  709. });
  710. init_savebutton();
  711. jQuery("#search_current_account").keyup(function() {
  712. if (jQuery("#search_current_account").val() != \'\')
  713. {
  714. console.log("We set a value of account to search "+jQuery("#search_current_account").val()+", so we disable the other search criteria on account");
  715. jQuery("#search_current_account_valid").val(-1);
  716. }
  717. });
  718. });
  719. </script>';
  720. print '</form>';
  721. $db->free($result);
  722. } else {
  723. dol_print_error($db);
  724. }
  725. // End of page
  726. llxFooter();
  727. $db->close();