list.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  1. <?php
  2. /* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
  3. * Copyright (C) 2013-2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
  4. * Copyright (C) 2014-2015 Ari Elbaz (elarifr) <github@accedinfo.com>
  5. * Copyright (C) 2013-2021 Florian Henry <florian.henry@open-concept.pro>
  6. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  7. * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>s
  8. * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/accountancy/supplier/list.php
  25. * \ingroup Accountancy (Double entries)
  26. * \brief Ventilation page from suppliers invoices
  27. */
  28. require '../../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  39. // Load translation files required by the page
  40. $langs->loadLangs(array("bills", "companies", "compta", "accountancy", "other", "productbatch", "products"));
  41. $action = GETPOST('action', 'aZ09');
  42. $massaction = GETPOST('massaction', 'alpha');
  43. $confirm = GETPOST('confirm', 'alpha');
  44. $toselect = GETPOST('toselect', 'array');
  45. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'accountancysupplierlist'; // To manage different context of search
  46. $optioncss = GETPOST('optioncss', 'alpha');
  47. $default_account = GETPOST('default_account', 'int');
  48. // Select Box
  49. $mesCasesCochees = GETPOST('toselect', 'array');
  50. // Search Getpost
  51. $search_societe = GETPOST('search_societe', 'alpha');
  52. $search_lineid = GETPOST('search_lineid', 'int');
  53. $search_ref = GETPOST('search_ref', 'alpha');
  54. $search_ref_supplier = GETPOST('search_ref_supplier', 'alpha');
  55. $search_invoice = GETPOST('search_invoice', 'alpha');
  56. $search_label = GETPOST('search_label', 'alpha');
  57. $search_desc = GETPOST('search_desc', 'alpha');
  58. $search_amount = GETPOST('search_amount', 'alpha');
  59. $search_account = GETPOST('search_account', 'alpha');
  60. $search_vat = GETPOST('search_vat', 'alpha');
  61. $search_date_startday = GETPOST('search_date_startday', 'int');
  62. $search_date_startmonth = GETPOST('search_date_startmonth', 'int');
  63. $search_date_startyear = GETPOST('search_date_startyear', 'int');
  64. $search_date_endday = GETPOST('search_date_endday', 'int');
  65. $search_date_endmonth = GETPOST('search_date_endmonth', 'int');
  66. $search_date_endyear = GETPOST('search_date_endyear', 'int');
  67. $search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver
  68. $search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
  69. $search_country = GETPOST('search_country', 'alpha');
  70. $search_tvaintra = GETPOST('search_tvaintra', 'alpha');
  71. // Load variable for pagination
  72. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION) ? $conf->liste_limit : $conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
  73. $sortfield = GETPOST('sortfield', 'aZ09comma');
  74. $sortorder = GETPOST('sortorder', 'aZ09comma');
  75. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  76. if (empty($page) || $page < 0) {
  77. $page = 0;
  78. }
  79. $offset = $limit * $page;
  80. $pageprev = $page - 1;
  81. $pagenext = $page + 1;
  82. if (!$sortfield) {
  83. $sortfield = "f.datef, f.ref, l.rowid";
  84. }
  85. if (!$sortorder) {
  86. if ($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_TODO > 0) {
  87. $sortorder = "DESC";
  88. } else {
  89. $sortorder = "ASC";
  90. }
  91. }
  92. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  93. $hookmanager->initHooks(array('accountancysupplierlist'));
  94. $formaccounting = new FormAccounting($db);
  95. $accountingAccount = new AccountingAccount($db);
  96. $chartaccountcode = dol_getIdFromCode($db, getDolGlobalInt('CHARTOFACCOUNTS'), 'accounting_system', 'rowid', 'pcg_version');
  97. // Security check
  98. if (!isModEnabled('accounting')) {
  99. accessforbidden();
  100. }
  101. if ($user->socid > 0) {
  102. accessforbidden();
  103. }
  104. if (!$user->hasRight('accounting', 'mouvements', 'lire')) {
  105. accessforbidden();
  106. }
  107. /*
  108. * Actions
  109. */
  110. if (GETPOST('cancel', 'alpha')) {
  111. $action = 'list'; $massaction = '';
  112. }
  113. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  114. $massaction = '';
  115. }
  116. $parameters = array();
  117. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  118. if ($reshook < 0) {
  119. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  120. }
  121. if (empty($reshook)) {
  122. // Purge search criteria
  123. 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
  124. $search_societe = '';
  125. $search_lineid = '';
  126. $search_ref = '';
  127. $search_ref_supplier = '';
  128. $search_invoice = '';
  129. $search_label = '';
  130. $search_desc = '';
  131. $search_amount = '';
  132. $search_account = '';
  133. $search_vat = '';
  134. $search_date_startday = '';
  135. $search_date_startmonth = '';
  136. $search_date_startyear = '';
  137. $search_date_endday = '';
  138. $search_date_endmonth = '';
  139. $search_date_endyear = '';
  140. $search_date_start = '';
  141. $search_date_end = '';
  142. $search_country = '';
  143. $search_tvaintra = '';
  144. }
  145. // Mass actions
  146. $objectclass = 'AccountingAccount';
  147. $permissiontoread = $user->hasRight('accounting', 'read');
  148. $permissiontodelete = $user->hasRight('accounting', 'delete');
  149. $uploaddir = $conf->accounting->dir_output;
  150. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  151. }
  152. if ($massaction == 'ventil' && $user->rights->accounting->bind->write) {
  153. $msg = '';
  154. if (!empty($mesCasesCochees)) {
  155. $msg = '<div>'.$langs->trans("SelectedLines").': '.count($mesCasesCochees).'</div>';
  156. $msg .= '<div class="detail">';
  157. $cpt = 0;
  158. $ok = 0;
  159. $ko = 0;
  160. foreach ($mesCasesCochees as $maLigneCochee) {
  161. $maLigneCourante = explode("_", $maLigneCochee);
  162. $monId = $maLigneCourante[0];
  163. $monCompte = GETPOST('codeventil'.$monId);
  164. if ($monCompte <= 0) {
  165. $msg .= '<div><span class="error">'.$langs->trans("Lineofinvoice").' '.$monId.' - '.$langs->trans("NoAccountSelected").'</span></div>';
  166. $ko++;
  167. } else {
  168. $sql = " UPDATE ".MAIN_DB_PREFIX."facture_fourn_det";
  169. $sql .= " SET fk_code_ventilation = ".((int) $monCompte);
  170. $sql .= " WHERE rowid = ".((int) $monId);
  171. $accountventilated = new AccountingAccount($db);
  172. $accountventilated->fetch($monCompte, '', 1);
  173. dol_syslog('accountancy/supplier/list.php', LOG_DEBUG);
  174. if ($db->query($sql)) {
  175. $msg .= '<div><span class="green">'.$langs->trans("Lineofinvoice").' '.$monId.' - '.$langs->trans("VentilatedinAccount").' : '.length_accountg($accountventilated->account_number).'</span></div>';
  176. $ok++;
  177. } else {
  178. $msg .= '<div><span class="error">'.$langs->trans("ErrorDB").' : '.$langs->trans("Lineofinvoice").' '.$monId.' - '.$langs->trans("NotVentilatedinAccount").' : '.length_accountg($accountventilated->account_number).'<br> <pre>'.$sql.'</pre></span></div>';
  179. $ko++;
  180. }
  181. }
  182. $cpt++;
  183. }
  184. $msg .= '</div>';
  185. $msg .= '<div>'.$langs->trans("EndProcessing").'</div>';
  186. }
  187. }
  188. if (GETPOST('sortfield') == 'f.datef, f.ref, l.rowid') {
  189. $value = (GETPOST('sortorder') == 'asc,asc,asc' ? 0 : 1);
  190. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  191. $res = dolibarr_set_const($db, "ACCOUNTING_LIST_SORT_VENTILATION_TODO", $value, 'yesno', 0, '', $conf->entity);
  192. }
  193. /*
  194. * View
  195. */
  196. $form = new Form($db);
  197. $formother = new FormOther($db);
  198. llxHeader('', $langs->trans("SuppliersVentilation"));
  199. if (empty($chartaccountcode)) {
  200. print $langs->trans("ErrorChartOfAccountSystemNotSelected");
  201. // End of page
  202. llxFooter();
  203. $db->close();
  204. exit;
  205. }
  206. // Supplier Invoice Lines
  207. $sql = "SELECT f.rowid as facid, f.ref, f.ref_supplier, f.libelle as invoice_label, f.datef, f.type as ftype, f.fk_facture_source,";
  208. $sql .= " l.rowid, l.fk_product, l.description, l.total_ht, l.fk_code_ventilation, l.product_type as type_l, l.tva_tx as tva_tx_line, l.vat_src_code,";
  209. $sql .= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.fk_product_type as type, p.tva_tx as tva_tx_prod,";
  210. if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
  211. $sql .= " ppe.accountancy_code_sell as code_sell, ppe.accountancy_code_sell_intra as code_sell_intra, ppe.accountancy_code_sell_export as code_sell_export,";
  212. $sql .= " ppe.accountancy_code_buy as code_buy, ppe.accountancy_code_buy_intra as code_buy_intra, ppe.accountancy_code_buy_export as code_buy_export,";
  213. } else {
  214. $sql .= " p.accountancy_code_sell as code_sell, p.accountancy_code_sell_intra as code_sell_intra, p.accountancy_code_sell_export as code_sell_export,";
  215. $sql .= " p.accountancy_code_buy as code_buy, p.accountancy_code_buy_intra as code_buy_intra, p.accountancy_code_buy_export as code_buy_export,";
  216. }
  217. $sql .= " p.tosell as status, p.tobuy as status_buy,";
  218. $sql .= " aa.rowid as aarowid, aa2.rowid as aarowid_intra, aa3.rowid as aarowid_export, aa4.rowid as aarowid_thirdparty,";
  219. $sql .= " co.code as country_code, co.label as country_label,";
  220. $sql .= " s.rowid as socid, s.nom as name, s.tva_intra, s.email, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.code_fournisseur,";
  221. if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
  222. $sql .= " spe.accountancy_code_customer as code_compta_client,";
  223. $sql .= " spe.accountancy_code_supplier as code_compta_fournisseur,";
  224. $sql .= " spe.accountancy_code_buy as company_code_buy";
  225. } else {
  226. $sql .= " s.code_compta as code_compta_client,";
  227. $sql .= " s.code_compta_fournisseur,";
  228. $sql .= " s.accountancy_code_buy as company_code_buy";
  229. }
  230. $parameters = array();
  231. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
  232. $sql .= $hookmanager->resPrint;
  233. $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
  234. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
  235. if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
  236. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
  237. }
  238. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON co.rowid = s.fk_pays ";
  239. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."facture_fourn_det as l ON f.rowid = l.fk_facture_fourn";
  240. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = l.fk_product";
  241. if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
  242. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
  243. }
  244. $alias_societe_perentity = empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED) ? "s" : "spe";
  245. $alias_product_perentity = empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED) ? "p" : "ppe";
  246. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON " . $alias_product_perentity . ".accountancy_code_buy = aa.account_number AND aa.active = 1 AND aa.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa.entity = ".$conf->entity;
  247. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa2 ON " . $alias_product_perentity . ".accountancy_code_buy_intra = aa2.account_number AND aa2.active = 1 AND aa2.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa2.entity = ".$conf->entity;
  248. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa3 ON " . $alias_product_perentity . ".accountancy_code_buy_export = aa3.account_number AND aa3.active = 1 AND aa3.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa3.entity = ".$conf->entity;
  249. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa4 ON " . $alias_societe_perentity . ".accountancy_code_buy = aa4.account_number AND aa4.active = 1 AND aa4.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa4.entity = ".$conf->entity;
  250. $sql .= " WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0";
  251. $sql .= " AND l.product_type <= 2";
  252. // Define begin binding date
  253. if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
  254. $sql .= " AND f.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING)."'";
  255. }
  256. // Add search filter like
  257. if ($search_societe) {
  258. $sql .= natural_search('s.nom', $search_societe);
  259. }
  260. if ($search_lineid) {
  261. $sql .= natural_search("l.rowid", $search_lineid, 1);
  262. }
  263. if (strlen(trim($search_invoice))) {
  264. $sql .= natural_search(array("f.ref", "f.ref_supplier"), $search_invoice);
  265. }
  266. if (strlen(trim($search_ref))) {
  267. $sql .= natural_search("p.ref", $search_ref);
  268. }
  269. /*if (strlen(trim($search_ref_supplier))) {
  270. $sql .= natural_search("f.ref_supplier", $search_ref_supplier);
  271. }*/
  272. if (strlen(trim($search_label))) {
  273. $sql .= natural_search(array("p.label", "f.libelle"), $search_label);
  274. }
  275. if (strlen(trim($search_desc))) {
  276. $sql .= natural_search("l.description", $search_desc);
  277. }
  278. if (strlen(trim($search_amount))) {
  279. $sql .= natural_search("l.total_ht", $search_amount, 1);
  280. }
  281. if (strlen(trim($search_account))) {
  282. $sql .= natural_search("aa.account_number", $search_account);
  283. }
  284. if (strlen(trim($search_vat))) {
  285. $sql .= natural_search("l.tva_tx", price2num($search_vat), 1);
  286. }
  287. if ($search_date_start) {
  288. $sql .= " AND f.datef >= '".$db->idate($search_date_start)."'";
  289. }
  290. if ($search_date_end) {
  291. $sql .= " AND f.datef <= '".$db->idate($search_date_end)."'";
  292. }
  293. if (strlen(trim($search_country))) {
  294. $arrayofcode = getCountriesInEEC();
  295. $country_code_in_EEC = $country_code_in_EEC_without_me = '';
  296. foreach ($arrayofcode as $key => $value) {
  297. $country_code_in_EEC .= ($country_code_in_EEC ? "," : "")."'".$value."'";
  298. if ($value != $mysoc->country_code) {
  299. $country_code_in_EEC_without_me .= ($country_code_in_EEC_without_me ? "," : "")."'".$value."'";
  300. }
  301. }
  302. if ($search_country == 'special_allnotme') {
  303. $sql .= " AND co.code <> '".$db->escape($mysoc->country_code)."'";
  304. } elseif ($search_country == 'special_eec') {
  305. $sql .= " AND co.code IN (".$db->sanitize($country_code_in_EEC, 1).")";
  306. } elseif ($search_country == 'special_eecnotme') {
  307. $sql .= " AND co.code IN (".$db->sanitize($country_code_in_EEC_without_me, 1).")";
  308. } elseif ($search_country == 'special_noteec') {
  309. $sql .= " AND co.code NOT IN (".$db->sanitize($country_code_in_EEC, 1).")";
  310. } else {
  311. $sql .= natural_search("co.code", $search_country);
  312. }
  313. }
  314. if (strlen(trim($search_tvaintra))) {
  315. $sql .= natural_search("s.tva_intra", $search_tvaintra);
  316. }
  317. if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
  318. $sql .= " AND f.type IN (".FactureFournisseur::TYPE_STANDARD.",".FactureFournisseur::TYPE_REPLACEMENT.",".FactureFournisseur::TYPE_CREDIT_NOTE.",".FactureFournisseur::TYPE_SITUATION.")";
  319. } else {
  320. $sql .= " AND f.type IN (".FactureFournisseur::TYPE_STANDARD.",".FactureFournisseur::TYPE_REPLACEMENT.",".FactureFournisseur::TYPE_CREDIT_NOTE.",".FactureFournisseur::TYPE_DEPOSIT.",".FactureFournisseur::TYPE_SITUATION.")";
  321. }
  322. $sql .= " AND f.entity IN (".getEntity('facture_fourn', 0).")"; // We don't share object for accountancy
  323. // Add where from hooks
  324. $parameters = array();
  325. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
  326. $sql .= $hookmanager->resPrint;
  327. $sql .= $db->order($sortfield, $sortorder);
  328. // Count total nb of records
  329. $nbtotalofrecords = '';
  330. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  331. $result = $db->query($sql);
  332. $nbtotalofrecords = $db->num_rows($result);
  333. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  334. $page = 0;
  335. $offset = 0;
  336. }
  337. }
  338. $sql .= $db->plimit($limit + 1, $offset);
  339. dol_syslog('accountancy/supplier/list.php', LOG_DEBUG);
  340. // MAX_JOIN_SIZE can be very low (ex: 300000) on some limited configurations (ex: https://www.online.net/fr/hosting/online-perso)
  341. // This big SELECT command may exceed the MAX_JOIN_SIZE limit => Therefore we use SQL_BIG_SELECTS=1 to disable the MAX_JOIN_SIZE security
  342. if ($db->type == 'mysqli') {
  343. $db->query("SET SQL_BIG_SELECTS=1");
  344. }
  345. $result = $db->query($sql);
  346. if ($result) {
  347. $num_lines = $db->num_rows($result);
  348. $i = 0;
  349. $arrayofselected = is_array($toselect) ? $toselect : array();
  350. $param = '';
  351. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  352. $param .= '&contextpage='.urlencode($contextpage);
  353. }
  354. if ($limit > 0 && $limit != $conf->liste_limit) {
  355. $param .= '&limit='.((int) $limit);
  356. }
  357. if ($search_societe) {
  358. $param .= '&search_societe='.urlencode($search_societe);
  359. }
  360. if ($search_lineid) {
  361. $param .= '&search_lineid='.urlencode($search_lineid);
  362. }
  363. if ($search_date_startday) {
  364. $param .= '&search_date_startday='.urlencode($search_date_startday);
  365. }
  366. if ($search_date_startmonth) {
  367. $param .= '&search_date_startmonth='.urlencode($search_date_startmonth);
  368. }
  369. if ($search_date_startyear) {
  370. $param .= '&search_date_startyear='.urlencode($search_date_startyear);
  371. }
  372. if ($search_date_endday) {
  373. $param .= '&search_date_endday='.urlencode($search_date_endday);
  374. }
  375. if ($search_date_endmonth) {
  376. $param .= '&search_date_endmonth='.urlencode($search_date_endmonth);
  377. }
  378. if ($search_date_endyear) {
  379. $param .= '&search_date_endyear='.urlencode($search_date_endyear);
  380. }
  381. if ($search_invoice) {
  382. $param .= '&search_invoice='.urlencode($search_invoice);
  383. }
  384. if ($search_ref) {
  385. $param .= '&search_ref='.urlencode($search_ref);
  386. }
  387. if ($search_ref_supplier) {
  388. $param .= '&search_ref_supplier='.urlencode($search_ref_supplier);
  389. }
  390. if ($search_label) {
  391. $param .= '&search_label='.urlencode($search_label);
  392. }
  393. if ($search_desc) {
  394. $param .= '&search_desc='.urlencode($search_desc);
  395. }
  396. if ($search_amount) {
  397. $param .= '&search_amount='.urlencode($search_amount);
  398. }
  399. if ($search_vat) {
  400. $param .= '&search_vat='.urlencode($search_vat);
  401. }
  402. if ($search_country) {
  403. $param .= "&search_country=".urlencode($search_country);
  404. }
  405. if ($search_tvaintra) {
  406. $param .= "&search_tvaintra=".urlencode($search_tvaintra);
  407. }
  408. $arrayofmassactions = array(
  409. 'ventil'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Ventilate")
  410. ,'set_default_account'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("ConfirmPreselectAccount")
  411. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  412. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  413. );
  414. //if ($user->rights->mymodule->supprimer) $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  415. //if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array();
  416. if ($massaction !== 'set_default_account') {
  417. $massactionbutton = $form->selectMassAction('ventil', $arrayofmassactions, 1);
  418. }
  419. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">'."\n";
  420. print '<input type="hidden" name="action" value="ventil">';
  421. if ($optioncss != '') {
  422. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  423. }
  424. print '<input type="hidden" name="token" value="'.newToken().'">';
  425. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  426. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  427. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  428. print '<input type="hidden" name="page" value="'.$page.'">';
  429. print_barre_liste($langs->trans("InvoiceLines"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num_lines, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit);
  430. if ($massaction == 'set_default_account') {
  431. $formquestion[]=array('type' => 'other',
  432. 'name' => 'set_default_account',
  433. 'label' => $langs->trans("AccountancyCode"),
  434. 'value' => $formaccounting->select_account('', 'default_account', 1, array(), 0, 0, 'maxwidth200 maxwidthonsmartphone', 'cachewithshowemptyone'));
  435. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmPreselectAccount"), $langs->trans("ConfirmPreselectAccountQuestion", count($toselect)), "confirm_set_default_account", $formquestion, 1, 0, 200, 500, 1);
  436. }
  437. print '<span class="opacitymedium">'.$langs->trans("DescVentilTodoCustomer").'</span></br><br>';
  438. if (!empty($msg)) {
  439. print $msg.'<br>';
  440. }
  441. $moreforfilter = '';
  442. print '<div class="div-table-responsive">';
  443. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  444. // We add search filter
  445. print '<tr class="liste_titre_filter">';
  446. print '<td class="liste_titre"><input type="text" class="flat maxwidth25" name="search_lineid" value="'.dol_escape_htmltag($search_lineid).'"></td>';
  447. print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_invoice" value="'.dol_escape_htmltag($search_invoice).'"></td>';
  448. //print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_ref_supplier" value="'.dol_escape_htmltag($search_ref_supplier).'"></td>';
  449. print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_label" value="'.dol_escape_htmltag($search_label).'"></td>';
  450. print '<td class="liste_titre center">';
  451. print '<div class="nowrap">';
  452. print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  453. print '</div>';
  454. print '<div class="nowrap">';
  455. print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  456. print '</div>';
  457. print '</td>';
  458. print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>';
  459. print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_desc" value="'.dol_escape_htmltag($search_desc).'"></td>';
  460. print '<td class="liste_titre right"><input type="text" class="flat maxwidth50 right" name="search_amount" value="'.dol_escape_htmltag($search_amount).'"></td>';
  461. print '<td class="liste_titre right"><input type="text" class="flat maxwidth50 right" name="search_vat" placeholder="%" size="1" value="'.dol_escape_htmltag($search_vat).'"></td>';
  462. print '<td class="liste_titre"><input type="text" class="flat maxwidth75imp" name="search_societe" value="'.dol_escape_htmltag($search_societe).'"></td>';
  463. print '<td class="liste_titre">';
  464. print $form->select_country($search_country, 'search_country', '', 0, 'maxwidth100', 'code2', 1, 0, 1);
  465. //print '<input type="text" class="flat maxwidth50" name="search_country" value="' . dol_escape_htmltag($search_country) . '">';
  466. print '</td>';
  467. print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_tvaintra" value="'.dol_escape_htmltag($search_tvaintra).'"></td>';
  468. print '<td class="liste_titre"></td>';
  469. print '<td class="liste_titre"></td>';
  470. print '<td class="center liste_titre">';
  471. $searchpicto = $form->showFilterButtons();
  472. print $searchpicto;
  473. print '</td>';
  474. print "</tr>\n";
  475. print '<tr class="liste_titre">';
  476. print_liste_field_titre("LineId", $_SERVER["PHP_SELF"], "l.rowid", "", $param, '', $sortfield, $sortorder);
  477. print_liste_field_titre("Invoice", $_SERVER["PHP_SELF"], "f.ref", "", $param, '', $sortfield, $sortorder);
  478. //print_liste_field_titre("RefSupplier", $_SERVER["PHP_SELF"], "f.ref_supplier", "", $param, '', $sortfield, $sortorder);
  479. print_liste_field_titre("InvoiceLabel", $_SERVER["PHP_SELF"], "f.libelle", "", $param, '', $sortfield, $sortorder);
  480. print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "f.datef, f.ref, l.rowid", "", $param, '', $sortfield, $sortorder, 'center ');
  481. print_liste_field_titre("ProductRef", $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
  482. //print_liste_field_titre("ProductLabel", $_SERVER["PHP_SELF"], "p.label", "", $param, '', $sortfield, $sortorder);
  483. print_liste_field_titre("ProductDescription", $_SERVER["PHP_SELF"], "l.description", "", $param, '', $sortfield, $sortorder);
  484. print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "l.total_ht", "", $param, '', $sortfield, $sortorder, 'right maxwidth50 ');
  485. print_liste_field_titre("VATRate", $_SERVER["PHP_SELF"], "l.tva_tx", "", $param, '', $sortfield, $sortorder, 'right ', '', 1);
  486. print_liste_field_titre("ThirdParty", $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder);
  487. print_liste_field_titre("Country", $_SERVER["PHP_SELF"], "co.label", "", $param, '', $sortfield, $sortorder);
  488. print_liste_field_titre("VATIntraShort", $_SERVER["PHP_SELF"], "s.tva_intra", "", $param, '', $sortfield, $sortorder);
  489. print_liste_field_titre("DataUsedToSuggestAccount", '', '', '', '', '', '', '', 'nowraponall ');
  490. print_liste_field_titre("AccountAccountingSuggest", '', '', '', '', '', '', '', 'center ');
  491. $checkpicto = '';
  492. if ($massactionbutton) {
  493. $checkpicto = $form->showCheckAddButtons('checkforselect', 1);
  494. }
  495. print_liste_field_titre($checkpicto, '', '', '', '', '', '', '', 'center ');
  496. print "</tr>\n";
  497. $thirdpartystatic = new Societe($db);
  498. $facturefourn_static = new FactureFournisseur($db);
  499. $facturefourn_static_det = new SupplierInvoiceLine($db);
  500. $product_static = new Product($db);
  501. $accountingaccount_codetotid_cache = array();
  502. while ($i < min($num_lines, $limit)) {
  503. $objp = $db->fetch_object($result);
  504. // product_type: 0 = service, 1 = product
  505. // if product does not exist we use the value of product_type provided in facturedet to define if this is a product or service
  506. // issue : if we change product_type value in product DB it should differ from the value stored in facturedet DB !
  507. $code_buy_l = '';
  508. $code_buy_p = '';
  509. $code_buy_t = '';
  510. $thirdpartystatic->id = $objp->socid;
  511. $thirdpartystatic->name = $objp->name;
  512. $thirdpartystatic->client = $objp->client;
  513. $thirdpartystatic->fournisseur = $objp->fournisseur;
  514. $thirdpartystatic->code_client = $objp->code_client;
  515. $thirdpartystatic->code_compta_client = $objp->code_compta_client;
  516. $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
  517. $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
  518. $thirdpartystatic->email = $objp->email;
  519. $thirdpartystatic->country_code = $objp->country_code;
  520. $thirdpartystatic->tva_intra = $objp->tva_intra;
  521. $thirdpartystatic->code_compta_product = $objp->company_code_buy; // The accounting account for product stored on thirdparty object (for level3 suggestion)
  522. $product_static->ref = $objp->product_ref;
  523. $product_static->id = $objp->product_id;
  524. $product_static->type = $objp->type;
  525. $product_static->label = $objp->product_label;
  526. $product_static->status = $objp->status;
  527. $product_static->status_buy = $objp->status_buy;
  528. $product_static->accountancy_code_sell = $objp->code_sell;
  529. $product_static->accountancy_code_sell_intra = $objp->code_sell_intra;
  530. $product_static->accountancy_code_sell_export = $objp->code_sell_export;
  531. $product_static->accountancy_code_buy = $objp->code_buy;
  532. $product_static->accountancy_code_buy_intra = $objp->code_buy_intra;
  533. $product_static->accountancy_code_buy_export = $objp->code_buy_export;
  534. $product_static->tva_tx = $objp->tva_tx_prod;
  535. $facturefourn_static->ref = $objp->ref;
  536. $facturefourn_static->id = $objp->facid;
  537. $facturefourn_static->type = $objp->ftype;
  538. $facturefourn_static->ref_supplier = $objp->ref_supplier;
  539. $facturefourn_static->label = $objp->invoice_label;
  540. $facturefourn_static->date = $db->jdate($objp->datef);
  541. $facturefourn_static->fk_facture_source = $objp->fk_facture_source;
  542. $facturefourn_static_det->id = $objp->rowid;
  543. $facturefourn_static_det->total_ht = $objp->total_ht;
  544. $facturefourn_static_det->tva_tx = $objp->tva_tx_line;
  545. $facturefourn_static_det->vat_src_code = $objp->vat_src_code;
  546. $facturefourn_static_det->product_type = $objp->type_l;
  547. $facturefourn_static_det->desc = $objp->description;
  548. $accountingAccountArray = array(
  549. 'dom'=>$objp->aarowid,
  550. 'intra'=>$objp->aarowid_intra,
  551. 'export'=>$objp->aarowid_export,
  552. 'thirdparty' =>$objp->aarowid_thirdparty);
  553. $code_buy_p_notset = '';
  554. $code_buy_t_notset = '';
  555. $suggestedid = 0;
  556. $return=$accountingAccount->getAccountingCodeToBind($mysoc, $thirdpartystatic, $product_static, $facturefourn_static, $facturefourn_static_det, $accountingAccountArray, 'supplier');
  557. if (!is_array($return) && $return<0) {
  558. setEventMessage($accountingAccount->error, 'errors');
  559. } else {
  560. $suggestedid=$return['suggestedid'];
  561. $suggestedaccountingaccountfor=$return['suggestedaccountingaccountfor'];
  562. $suggestedaccountingaccountbydefaultfor=$return['suggestedaccountingaccountbydefaultfor'];
  563. $code_buy_l=$return['code_l'];
  564. $code_buy_p=$return['code_p'];
  565. $code_buy_t=$return['code_t'];
  566. }
  567. //var_dump($return);
  568. if (!empty($code_buy_p)) {
  569. // Value was defined previously
  570. } else {
  571. $code_buy_p_notset = 'color:orange';
  572. }
  573. if (empty($code_buy_l) && empty($code_buy_p)) {
  574. $code_buy_p_notset = 'color:red';
  575. }
  576. /*if ($suggestedaccountingaccountfor == 'eecwithoutvatnumber' && empty($code_sell_p_notset)) {
  577. $code_sell_p_notset = 'color:orange';
  578. }*/
  579. // $code_buy_l is now default code of product/service
  580. // $code_buy_p is now code of product/service
  581. // $code_buy_t is now code of thirdparty
  582. //var_dump($code_buy_l.' - '.$code_buy_p.' - '.$code_buy_t.' -> '.$suggestedid.' ('.$suggestedaccountingaccountbydefaultfor.' '.$suggestedaccountingaccountfor.')');
  583. print '<tr class="oddeven">';
  584. // Line id
  585. print '<td>'.$facturefourn_static_det->id.'</td>';
  586. // Ref Invoice
  587. print '<td class="nowraponall">'.$facturefourn_static->getNomUrl(1);
  588. if ($objp->ref_supplier) {
  589. print '<br><span class="opacitymedium small">'.dol_escape_htmltag($objp->ref_supplier).'</span>';
  590. }
  591. print '</td>';
  592. // Ref supplier invoice
  593. /*print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($objp->ref_supplier).'">';
  594. print $objp->ref_supplier;
  595. print '</td>';*/
  596. // Supplier invoice label
  597. print '<td class="tdoverflowmax100 small" title="'.dol_escape_htmltag($objp->invoice_label).'">';
  598. print dol_escape_htmltag($objp->invoice_label);
  599. print '</td>';
  600. // Date
  601. print '<td class="center">'.dol_print_date($facturefourn_static->date, 'day').'</td>';
  602. // Ref Product
  603. print '<td class="tdoverflowmax100">';
  604. if ($product_static->id > 0) {
  605. print $product_static->getNomUrl(1);
  606. }
  607. if ($product_static->label) {
  608. print '<br><span class="opacitymedium small">'.dol_escape_htmltag($product_static->label).'</span>';
  609. }
  610. print '</td>';
  611. // Description of line
  612. print '<td class="tdoverflowonsmartphone small">';
  613. $text = dolGetFirstLineOfText(dol_string_nohtmltag($facturefourn_static_det->desc, 1));
  614. $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
  615. print $form->textwithtooltip(dol_trunc($text, $trunclength), $facturefourn_static_det->desc);
  616. print '</td>';
  617. print '<td class="right nowraponall amount">';
  618. print price($objp->total_ht);
  619. print '</td>';
  620. // Vat rate
  621. $code_vat_differ = '';
  622. //if ($objp->vat_tx_l != $objp->vat_tx_p && price2num($objp->vat_tx_p) && price2num($objp->vat_tx_l)) { // Note: having a vat rate of 0 is often the normal case when sells is intra b2b or to export
  623. // $code_vat_differ = 'warning bold';
  624. //}
  625. print '<td class="right'.($code_vat_differ?' '.$code_vat_differ:'').'">';
  626. print vatrate($facturefourn_static_det->tva_tx.($facturefourn_static_det->vat_src_code ? ' ('.$facturefourn_static_det->vat_src_code.')' : ''), false, 0, 0, 1);
  627. print '</td>';
  628. // Thirdparty
  629. print '<td class="tdoverflowmax100">'.$thirdpartystatic->getNomUrl(1, 'supplier').'</td>';
  630. // Country
  631. $labelcountry = ($objp->country_code && ($langs->trans("Country".$objp->country_code) != "Country".$objp->country_code)) ? $langs->trans("Country".$objp->country_code) : $objp->country_label;
  632. print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($labelcountry).'">';
  633. print dol_escape_htmltag($labelcountry);
  634. print '</td>';
  635. // VAT Num
  636. print '<td class="tdoverflowmax80" title="'.dol_escape_htmltag($objp->tva_intra).'">'.dol_escape_htmltag($objp->tva_intra).'</td>';
  637. // Found accounts
  638. print '<td class="small">';
  639. $s = '1. '.(($facturefourn_static_det->product_type == 1) ? $langs->trans("DefaultForService") : $langs->trans("DefaultForProduct")).': ';
  640. $shelp = ''; $ttype = 'help';
  641. if ($suggestedaccountingaccountbydefaultfor == 'eec') {
  642. $shelp .= $langs->trans("SaleEEC");
  643. } elseif ($suggestedaccountingaccountbydefaultfor == 'eecwithvat') {
  644. $shelp = $langs->trans("SaleEECWithVAT");
  645. } elseif ($suggestedaccountingaccountbydefaultfor == 'eecwithoutvatnumber') {
  646. $shelp = $langs->trans("SaleEECWithoutVATNumber");
  647. $ttype = 'warning';
  648. } elseif ($suggestedaccountingaccountbydefaultfor == 'export') {
  649. $shelp .= $langs->trans("SaleExport");
  650. }
  651. $s .= ($code_buy_l > 0 ? length_accountg($code_buy_l) : '<span style="'.$code_buy_p_notset.'">'.$langs->trans("NotDefined").'</span>');
  652. print $form->textwithpicto($s, $shelp, 1, $ttype, '', 0, 2, '', 1);
  653. if ($product_static->id > 0) {
  654. print '<br>';
  655. $s = '2. '.(($facturefourn_static_det->product_type == 1) ? $langs->trans("ThisService") : $langs->trans("ThisProduct")).': ';
  656. $shelp = ''; $ttype = 'help';
  657. if ($suggestedaccountingaccountfor == 'eec') {
  658. $shelp = $langs->trans("SaleEEC");
  659. } elseif ($suggestedaccountingaccountfor == 'eecwithvat') {
  660. $shelp = $langs->trans("SaleEECWithVAT");
  661. } elseif ($suggestedaccountingaccountfor == 'eecwithoutvatnumber') {
  662. $shelp = $langs->trans("SaleEECWithoutVATNumber");
  663. $ttype = 'warning';
  664. } elseif ($suggestedaccountingaccountfor == 'export') {
  665. $shelp = $langs->trans("SaleExport");
  666. }
  667. $s .= (empty($code_buy_p) ? '<span style="'.$code_buy_p_notset.'">'.$langs->trans("NotDefined").'</span>' : length_accountg($code_buy_p));
  668. print $form->textwithpicto($s, $shelp, 1, $ttype, '', 0, 2, '', 1);
  669. } else {
  670. print '<br>';
  671. $s = '2. '.(($objp->type_l == 1) ? $langs->trans("ThisService") : $langs->trans("ThisProduct")).': ';
  672. $shelp = '';
  673. $s .= $langs->trans("NotDefined");
  674. print $form->textwithpicto($s, $shelp, 1, 'help', '', 0, 2, '', 1);
  675. }
  676. if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) {
  677. print '<br>';
  678. $s = '3. '.(($facturefourn_static_det->product_type == 1) ? $langs->trans("ServiceForThisThirdparty") : $langs->trans("ProductForThisThirdparty")).': ';
  679. $shelp = '';
  680. $s .= ($code_buy_t > 0 ? length_accountg($code_buy_t) : '<span style="'.$code_buy_t_notset.'">'.$langs->trans("NotDefined").'</span>');
  681. print $form->textwithpicto($s, $shelp, 1, 'help', '', 0, 2, '', 1);
  682. }
  683. print '</td>';
  684. // Suggested accounting account
  685. print '<td>';
  686. print $formaccounting->select_account(($default_account > 0 && $confirm === 'yes' && in_array($objp->rowid."_".$i, $toselect)) ? $default_account : $suggestedid, 'codeventil'.$facturefourn_static_det->id, 1, array(), 0, 0, 'codeventil maxwidth150 maxwidthonsmartphone', 'cachewithshowemptyone');
  687. print '</td>';
  688. // Column with checkbox
  689. print '<td class="center">';
  690. $ischecked = 0;
  691. if (!empty($suggestedid) && $suggestedaccountingaccountfor != '' && $suggestedaccountingaccountfor != 'eecwithoutvatnumber') {
  692. $ischecked = 1;
  693. }
  694. if (!empty($toselect)) {
  695. $ischecked = 0;
  696. if (in_array($objp->rowid."_".$i, $toselect)) {
  697. $ischecked=1;
  698. }
  699. }
  700. print '<input type="checkbox" class="flat checkforselect checkforselect'.$facturefourn_static_det->id.'" name="toselect[]" value="'.$facturefourn_static_det->id."_".$i.'"'.($ischecked ? " checked" : "").'/>';
  701. print '</td>';
  702. print '</tr>';
  703. $i++;
  704. }
  705. if ($num_lines == 0) {
  706. print '<tr><td colspan="14"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  707. }
  708. print '</table>';
  709. print "</div>";
  710. print '</form>';
  711. } else {
  712. print $db->error();
  713. }
  714. if ($db->type == 'mysqli') {
  715. $db->query("SET SQL_BIG_SELECTS=0"); // Enable MAX_JOIN_SIZE limitation
  716. }
  717. // Add code to auto check the box when we select an account
  718. print '<script type="text/javascript">
  719. jQuery(document).ready(function() {
  720. jQuery(".codeventil").change(function() {
  721. var s=$(this).attr("id").replace("codeventil", "")
  722. console.log(s+" "+$(this).val());
  723. if ($(this).val() == -1) jQuery(".checkforselect"+s).prop("checked", false);
  724. else jQuery(".checkforselect"+s).prop("checked", true);
  725. });
  726. });
  727. </script>';
  728. // End of page
  729. llxFooter();
  730. $db->close();