list.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. <?php
  2. /* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
  3. * Copyright (C) 2013-2017 Alexandre Spangaro <aspangaro@zendsi.com>
  4. * Copyright (C) 2014-2015 Ari Elbaz (elarifr) <github@accedinfo.com>
  5. * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
  6. * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>s
  7. * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
  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 <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/accountancy/supplier/list.php
  24. * \ingroup Advanced accountancy
  25. * \brief Ventilation page from suppliers invoices
  26. */
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';
  29. require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.product.class.php';
  30. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
  31. require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
  32. require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
  33. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
  34. require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
  35. // Load translation files required by the page
  36. $langs->loadLangs(array("bills","compta","accountancy","other","productbatch"));
  37. $action=GETPOST('action','alpha');
  38. $massaction=GETPOST('massaction','alpha');
  39. $show_files=GETPOST('show_files','int');
  40. $confirm=GETPOST('confirm','alpha');
  41. $toselect = GETPOST('toselect', 'array');
  42. // Select Box
  43. $mesCasesCochees = GETPOST('toselect', 'array');
  44. // Search Getpost
  45. $search_lineid = GETPOST('search_lineid', 'int');
  46. $search_invoice = GETPOST('search_invoice', 'alpha');
  47. $search_ref = GETPOST('search_ref', 'alpha');
  48. $search_label = GETPOST('search_label', 'alpha');
  49. $search_desc = GETPOST('search_desc', 'alpha');
  50. $search_amount = GETPOST('search_amount', 'alpha');
  51. $search_account = GETPOST('search_account', 'alpha');
  52. $search_vat = GETPOST('search_vat', 'alpha');
  53. $search_day=GETPOST("search_day","int");
  54. $search_month=GETPOST("search_month","int");
  55. $search_year=GETPOST("search_year","int");
  56. $search_country = GETPOST('search_country', 'alpha');
  57. $search_tvaintra = GETPOST('search_tvaintra', 'alpha');
  58. $btn_ventil = GETPOST('ventil', 'alpha');
  59. // Load variable for pagination
  60. $limit = GETPOST('limit','int')?GETPOST('limit', 'int'):(empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
  61. $sortfield = GETPOST('sortfield', 'alpha');
  62. $sortorder = GETPOST('sortorder', 'alpha');
  63. $page = GETPOST('page','int');
  64. if (empty($page) || $page < 0) { $page = 0; }
  65. $offset = $limit * $page;
  66. $pageprev = $page - 1;
  67. $pagenext = $page + 1;
  68. if (! $sortfield)
  69. $sortfield = "f.datef, f.ref, l.rowid";
  70. if (! $sortorder) {
  71. if ($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_TODO > 0) {
  72. $sortorder = "DESC";
  73. }
  74. }
  75. // Security check
  76. if ($user->societe_id > 0)
  77. accessforbidden();
  78. if (! $user->rights->accounting->bind->write)
  79. accessforbidden();
  80. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  81. $hookmanager->initHooks(array('accountancysupplierlist'));
  82. $formaccounting = new FormAccounting($db);
  83. $accounting = new AccountingAccount($db);
  84. // TODO: we should need to check if result is a really exist accountaccount rowid.....
  85. $aarowid_s = $accounting->fetch('', $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT, 1);
  86. $aarowid_p = $accounting->fetch('', $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT, 1);
  87. $chartaccountcode = dol_getIdFromCode($db, $conf->global->CHARTOFACCOUNTS, 'accounting_system', 'rowid', 'pcg_version');
  88. /*
  89. * Actions
  90. */
  91. if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
  92. if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
  93. $parameters=array();
  94. $reshook=$hookmanager->executeHooks('doActions',$parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  95. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  96. if (empty($reshook))
  97. {
  98. // Purge search criteria
  99. 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
  100. {
  101. $search_lineid = '';
  102. $search_ref = '';
  103. $search_invoice = '';
  104. $search_label = '';
  105. $search_desc = '';
  106. $search_amount = '';
  107. $search_account = '';
  108. $search_vat = '';
  109. $search_day = '';
  110. $search_month = '';
  111. $search_year = '';
  112. $search_country = '';
  113. $search_tvaintra = '';
  114. }
  115. // Mass actions
  116. $objectclass='AccountingAccount';
  117. $permtoread = $user->rights->accounting->read;
  118. $permtodelete = $user->rights->accounting->delete;
  119. $uploaddir = $conf->accounting->dir_output;
  120. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  121. }
  122. if ($massaction == 'ventil') {
  123. $msg='';
  124. //print '<div><font color="red">' . $langs->trans("Processing") . '...</font></div>';
  125. if (! empty($mesCasesCochees)) {
  126. $msg = '<div>' . $langs->trans("SelectedLines") . ': '.count($mesCasesCochees).'</div>';
  127. $msg.='<div class="detail">';
  128. $cpt = 0;
  129. $ok=0;
  130. $ko=0;
  131. foreach ($mesCasesCochees as $maLigneCochee) {
  132. $maLigneCourante = explode("_", $maLigneCochee);
  133. $monId = $maLigneCourante[0];
  134. $monCompte = GETPOST('codeventil'.$monId);
  135. if ($monCompte <= 0)
  136. {
  137. $msg.= '<div><font color="red">' . $langs->trans("Lineofinvoice") . ' ' . $monId . ' - ' . $langs->trans("NoAccountSelected") . '</font></div>';
  138. $ko++;
  139. }
  140. else
  141. {
  142. $sql = " UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det";
  143. $sql .= " SET fk_code_ventilation = " . $monCompte;
  144. $sql .= " WHERE rowid = " . $monId;
  145. $accountventilated = new AccountingAccount($db);
  146. $accountventilated->fetch($monCompte, '');
  147. dol_syslog('accountancy/supplier/list.php:: sql=' . $sql, LOG_DEBUG);
  148. if ($db->query($sql)) {
  149. $msg.= '<div><font color="green">' . $langs->trans("Lineofinvoice") . ' ' . $monId . ' - ' . $langs->trans("VentilatedinAccount") . ' : ' . length_accountg($accountventilated->account_number) . '</font></div>';
  150. $ok++;
  151. } else {
  152. $msg.= '<div><font color="red">' . $langs->trans("ErrorDB") . ' : ' . $langs->trans("Lineofinvoice") . ' ' . $monId . ' - ' . $langs->trans("NotVentilatedinAccount") . ' : ' . length_accountg($accountventilated->account_number) . '<br/> <pre>' . $sql . '</pre></font></div>';
  153. $ko++;
  154. }
  155. }
  156. $cpt++;
  157. }
  158. $msg.='</div>';
  159. $msg.= '<div>' . $langs->trans("EndProcessing") . '</div>';
  160. //} else {
  161. // setEventMessages($langs->trans("NoRecordSelected"), null, 'warnings');
  162. }
  163. }
  164. /*
  165. * View
  166. */
  167. $form = new Form($db);
  168. $formother = new FormOther($db);
  169. llxHeader('', $langs->trans("SuppliersVentilation"));
  170. if (empty($chartaccountcode))
  171. {
  172. print $langs->trans("ErrorChartOfAccountSystemNotSelected");
  173. // End of page
  174. llxFooter();
  175. $db->close();
  176. exit;
  177. }
  178. // Supplier Invoice Lines
  179. $sql = "SELECT f.rowid as facid, f.ref, f.ref_supplier, f.libelle as invoice_label, f.datef, f.type as ftype,";
  180. $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,";
  181. $sql.= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.fk_product_type as type, p.accountancy_code_buy as code_buy, p.tva_tx as tva_tx_prod,";
  182. $sql.= " aa.rowid as aarowid,";
  183. $sql.= " co.code as country_code, co.label as country,";
  184. $sql.= " s.tva_intra";
  185. $parameters=array();
  186. $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
  187. $sql.=$hookmanager->resPrint;
  188. $sql.= " FROM " . MAIN_DB_PREFIX . "facture_fourn as f";
  189. $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = f.fk_soc";
  190. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_country as co ON co.rowid = s.fk_pays ";
  191. $sql.= " INNER JOIN " . MAIN_DB_PREFIX . "facture_fourn_det as l ON f.rowid = l.fk_facture_fourn";
  192. $sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = l.fk_product";
  193. $sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON p.accountancy_code_buy = aa.account_number AND aa.fk_pcg_version = '" . $chartaccountcode."' AND aa.entity = " . $conf->entity;
  194. $sql.= " WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0";
  195. $sql.= " AND l.product_type <= 2";
  196. // Add search filter like
  197. if ($search_lineid) {
  198. $sql .= natural_search("l.rowid", $search_lineid, 1);
  199. }
  200. if (strlen(trim($search_invoice))) {
  201. $sql .= natural_search("f.ref", $search_invoice);
  202. }
  203. if (strlen(trim($search_ref))) {
  204. $sql .= natural_search("p.ref", $search_ref);
  205. }
  206. if (strlen(trim($search_label))) {
  207. $sql .= natural_search("p.label", $search_label);
  208. }
  209. if (strlen(trim($search_desc))) {
  210. $sql .= natural_search("l.description", $search_desc);
  211. }
  212. if (strlen(trim($search_amount))) {
  213. $sql .= natural_search("l.total_ht", $search_amount, 1);
  214. }
  215. if (strlen(trim($search_account))) {
  216. $sql .= natural_search("aa.account_number", $search_account);
  217. }
  218. if (strlen(trim($search_vat))) {
  219. $sql .= natural_search("l.tva_tx", price2num($search_vat), 1);
  220. }
  221. if ($search_month > 0)
  222. {
  223. if ($search_year > 0 && empty($search_day))
  224. $sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($search_year,$search_month,false))."' AND '".$db->idate(dol_get_last_day($search_year,$search_month,false))."'";
  225. else if ($search_year > 0 && ! empty($search_day))
  226. $sql.= " AND f.datef BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $search_month, $search_day, $search_year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $search_month, $search_day, $search_year))."'";
  227. else
  228. $sql.= " AND date_format(f.datef, '%m') = '".$db->escape($search_month)."'";
  229. }
  230. else if ($search_year > 0)
  231. {
  232. $sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($search_year,1,false))."' AND '".$db->idate(dol_get_last_day($search_year,12,false))."'";
  233. }
  234. if (strlen(trim($search_country))) {
  235. $sql .= natural_search("co.label", $search_country);
  236. }
  237. if (strlen(trim($search_tvaintra))) {
  238. $sql .= natural_search("s.tva_intra", $search_tvaintra);
  239. }
  240. if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
  241. $sql .= " AND f.type IN (" . FactureFournisseur::TYPE_STANDARD . "," . FactureFournisseur::TYPE_REPLACEMENT . "," . FactureFournisseur::TYPE_CREDIT_NOTE . "," . FactureFournisseur::TYPE_SITUATION . ")";
  242. } else {
  243. $sql .= " AND f.type IN (" . FactureFournisseur::TYPE_STANDARD . "," . FactureFournisseur::TYPE_REPLACEMENT . "," . FactureFournisseur::TYPE_CREDIT_NOTE . "," . FactureFournisseur::TYPE_DEPOSIT . "," . FactureFournisseur::TYPE_SITUATION . ")";
  244. }
  245. $sql .= " AND f.entity IN (" . getEntity('facture_fourn', 0) . ")"; // We don't share object for accountancy
  246. // Add where from hooks
  247. $parameters=array();
  248. $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
  249. $sql.=$hookmanager->resPrint;
  250. $sql .= $db->order($sortfield, $sortorder);
  251. // Count total nb of records
  252. $nbtotalofrecords = '';
  253. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  254. {
  255. $result = $db->query($sql);
  256. $nbtotalofrecords = $db->num_rows($result);
  257. if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
  258. {
  259. $page = 0;
  260. $offset = 0;
  261. }
  262. }
  263. $sql .= $db->plimit($limit + 1, $offset);
  264. dol_syslog('accountancy/supplier/list.php');
  265. $result = $db->query($sql);
  266. if ($result) {
  267. $num_lines = $db->num_rows($result);
  268. $i = 0;
  269. $arrayofselected=is_array($toselect)?$toselect:array();
  270. $param='';
  271. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
  272. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  273. if ($search_lineid) $param.='&search_lineid='.urlencode($search_lineid);
  274. if ($search_day) $param.='&search_day='.urlencode($search_day);
  275. if ($search_month) $param.='&search_month='.urlencode($search_month);
  276. if ($search_year) $param.='&search_year='.urlencode($search_year);
  277. if ($search_invoice) $param.='&search_invoice='.urlencode($search_invoice);
  278. if ($search_ref) $param.='&search_ref='.urlencode($search_ref);
  279. if ($search_desc) $param.='&search_desc='.urlencode($search_desc);
  280. if ($search_amount) $param.='&search_amount='.urlencode($search_amount);
  281. if ($search_vat) $param.='&search_vat='.urlencode($search_vat);
  282. if ($search_country) $param .= "&search_country=" . urlencode($search_country);
  283. if ($search_tvaintra) $param .= "&search_tvaintra=" . urlencode($search_tvaintra);
  284. $arrayofmassactions = array(
  285. 'ventil'=>$langs->trans("Ventilate")
  286. //'presend'=>$langs->trans("SendByMail"),
  287. //'builddoc'=>$langs->trans("PDFMerge"),
  288. );
  289. //if ($user->rights->mymodule->supprimer) $arrayofmassactions['predelete']=$langs->trans("Delete");
  290. //if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array();
  291. $massactionbutton=$form->selectMassAction('ventil', $arrayofmassactions, 1);
  292. print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">' . "\n";
  293. print '<input type="hidden" name="action" value="ventil">';
  294. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  295. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  296. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  297. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  298. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  299. print '<input type="hidden" name="page" value="'.$page.'">';
  300. print_barre_liste($langs->trans("InvoiceLines"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num_lines, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit);
  301. print $langs->trans("DescVentilTodoCustomer") . '</br><br>';
  302. /*$topicmail="Information";
  303. $modelmail="project";
  304. $objecttmp=new Project($db);
  305. $trackid='prj'.$object->id;
  306. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';*/
  307. if ($msg) print $msg.'<br>';
  308. $moreforfilter = '';
  309. print '<div class="div-table-responsive">';
  310. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  311. // We add search filter
  312. print '<tr class="liste_titre_filter">';
  313. print '<td class="liste_titre"><input type="text" class="flat maxwidth25" name="search_lineid" value="' . dol_escape_htmltag($search_lineid) . '""></td>';
  314. print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_invoice" value="' . dol_escape_htmltag($search_invoice) . '"></td>';
  315. print '<td class="liste_titre"></td>';
  316. print '<td class="liste_titre center nowraponall">';
  317. if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_day" value="'.$search_day.'">';
  318. print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_month" value="'.$search_month.'">';
  319. $formother->select_year($search_year,'search_year',1, 20, 5);
  320. print '</td>';
  321. print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_ref" value="' . dol_escape_htmltag($search_ref) . '"></td>';
  322. //print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_label" value="' . dol_escape_htmltag($search_label) . '"></td>';
  323. print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_desc" value="' . dol_escape_htmltag($search_desc) . '"></td>';
  324. print '<td class="liste_titre" align="right"><input type="text" class="right flat maxwidth50" name="search_amount" value="' . dol_escape_htmltag($search_amount) . '"></td>';
  325. print '<td class="liste_titre" align="right"><input type="text" class="right flat maxwidth50" name="search_vat" placeholder="%" size="1" value="' . dol_escape_htmltag($search_vat) . '"></td>';
  326. print '<td class="liste_titre">';
  327. print $form->select_country($search_country, 'search_country', '', 0, 'maxwidth200', 'code2');
  328. //print '<input type="text" class="flat maxwidth50" name="search_country" value="' . dol_escape_htmltag($search_country) . '">';
  329. print '</td>';
  330. print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_tvaintra" value="' . dol_escape_htmltag($search_tvaintra) . '"></td>';
  331. print '<td class="liste_titre"></td>';
  332. print '<td class="liste_titre"></td>';
  333. print '<td align="center" class="liste_titre">';
  334. $searchpicto=$form->showFilterButtons();
  335. print $searchpicto;
  336. print '</td>';
  337. print "</tr>\n";
  338. print '<tr class="liste_titre">';
  339. print_liste_field_titre("LineId", $_SERVER["PHP_SELF"], "l.rowid", "", $param, '', $sortfield, $sortorder);
  340. print_liste_field_titre("Invoice", $_SERVER["PHP_SELF"], "f.ref", "", $param, '', $sortfield, $sortorder);
  341. print_liste_field_titre("InvoiceLabel", $_SERVER["PHP_SELF"], "f.libelle", "", $param, '', $sortfield, $sortorder);
  342. print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "f.datef, f.ref, l.rowid", "", $param, 'align="center"', $sortfield, $sortorder);
  343. print_liste_field_titre("ProductRef", $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
  344. //print_liste_field_titre("ProductLabel", $_SERVER["PHP_SELF"], "p.label", "", $param, '', $sortfield, $sortorder);
  345. print_liste_field_titre("Description", $_SERVER["PHP_SELF"], "l.description", "", $param, '', $sortfield, $sortorder);
  346. print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "l.total_ht", "", $param, 'align="right"', $sortfield, $sortorder);
  347. print_liste_field_titre("VATRate", $_SERVER["PHP_SELF"], "l.tva_tx", "", $param, 'align="right"', $sortfield, $sortorder);
  348. print_liste_field_titre("Country", $_SERVER["PHP_SELF"], "co.label", "", $param, '', $sortfield, $sortorder);
  349. print_liste_field_titre("VATIntra", $_SERVER["PHP_SELF"], "s.tva_intra", "", $param, '', $sortfield, $sortorder);
  350. print_liste_field_titre("AccountAccountingSuggest", '', '', '', '', 'align="center"');
  351. print_liste_field_titre("IntoAccount", '', '', '', '', 'align="center"');
  352. $checkpicto='';
  353. if ($massactionbutton) $checkpicto=$form->showCheckAddButtons('checkforselect', 1);
  354. print_liste_field_titre($checkpicto, '', '', '', '', 'align="center"');
  355. print "</tr>\n";
  356. $facturefourn_static = new FactureFournisseur($db);
  357. $productfourn_static = new ProductFournisseur($db);
  358. while ($i < min($num_lines, $limit)) {
  359. $objp = $db->fetch_object($result);
  360. // product_type: 0 = service ? 1 = product
  361. // if product does not exist we use the value of product_type provided in facturedet to define if this is a product or service
  362. // issue : if we change product_type value in product DB it should differ from the value stored in facturedet DB !
  363. $objp->code_buy_l = '';
  364. $objp->code_buy_p = '';
  365. $objp->aarowid_suggest = '';
  366. $productfourn_static->ref = $objp->product_ref;
  367. $productfourn_static->id = $objp->product_id;
  368. $productfourn_static->type = $objp->type;
  369. $productfourn_static->label = $objp->product_label;
  370. $facturefourn_static->ref = $objp->ref;
  371. $facturefourn_static->id = $objp->facid;
  372. $facturefourn_static->type = $objp->type;
  373. $code_buy_p_notset = '';
  374. $objp->aarowid_suggest = $objp->aarowid;
  375. if ($objp->type_l == 1) {
  376. $objp->code_buy_l = (! empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : '');
  377. if ($objp->aarowid == '')
  378. $objp->aarowid_suggest = $aarowid_s;
  379. } elseif ($objp->type_l == 0) {
  380. $objp->code_buy_l = (! empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : '');
  381. if ($objp->aarowid == '')
  382. $objp->aarowid_suggest = $aarowid_p;
  383. }
  384. if ($objp->code_buy_l == -1) $objp->code_buy_l='';
  385. if (! empty($objp->code_buy)) {
  386. $objp->code_buy_p = $objp->code_buy; // Code on product
  387. } else {
  388. $code_buy_p_notset = 'color:orange';
  389. }
  390. if (empty($objp->code_buy_l) && empty($objp->code_buy_p)) $code_buy_p_notset = 'color:red';
  391. // $objp->code_buy_p is now code of product/service
  392. // $objp->code_buy_l is now default code of product/service
  393. print '<tr class="oddeven">';
  394. // Line id
  395. print '<td>' . $objp->rowid . '</td>';
  396. // Ref Invoice
  397. print '<td>' . $facturefourn_static->getNomUrl(1) . '</td>';
  398. print '<td class="tdoverflowonsmartphone">';
  399. print $objp->invoice_label;
  400. print '</td>';
  401. print '<td align="center">' . dol_print_date($db->jdate($objp->datef), 'day') . '</td>';
  402. // Ref product
  403. print '<td>';
  404. if ($productfourn_static->id)
  405. print $productfourn_static->getNomUrl(1);
  406. if ($objp->product_label) print '<br>'.$objp->product_label;
  407. print '</td>';
  408. // Description
  409. print '<td>';
  410. $text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->description));
  411. $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
  412. print $form->textwithtooltip(dol_trunc($text,$trunclength), $objp->description);
  413. print '</td>';
  414. print '<td align="right">';
  415. print price($objp->total_ht);
  416. print '</td>';
  417. // Vat rate
  418. if ($objp->vat_tx_l != $objp->vat_tx_p)
  419. $code_vat_differ = 'font-weight:bold; text-decoration:blink; color:red';
  420. print '<td style="' . $code_vat_differ . '" align="right">';
  421. print vatrate($objp->tva_tx_line.($objp->vat_src_code?' ('.$objp->vat_src_code.')':''));
  422. print '</td>';
  423. print '<td>' . $objp->country .'</td>';
  424. print '<td>' . $objp->tva_intra . '</td>';
  425. // Current account
  426. print '<td align="center" style="' . $code_buy_p_notset . '">';
  427. print (($objp->type_l == 1)?$langs->trans("DefaultForService"):$langs->trans("DefaultForProduct")) . ' = ' . ($objp->code_buy_l > 0 ? length_accountg($objp->code_buy_l) : $langs->trans("Unknown"));
  428. if ($objp->product_id > 0)
  429. {
  430. print '<br>';
  431. print (($objp->type_l == 1)?$langs->trans("ThisService"):$langs->trans("ThisProduct")) . ' = ' . (empty($objp->code_buy_p) ? $langs->trans("Unknown") : length_accountg($objp->code_buy_p));
  432. }
  433. print '</td>';
  434. // Suggested accounting account
  435. print '<td align="center">';
  436. print $formaccounting->select_account($objp->aarowid_suggest, 'codeventil'.$objp->rowid, 1, array(), 0, 0, 'codeventil maxwidth300 maxwidthonsmartphone', 'cachewithshowemptyone');
  437. print '</td>';
  438. // Column with checkbox
  439. print '<td align="center">';
  440. print '<input type="checkbox" class="flat checkforselect checkforselect'.$objp->rowid.'" name="toselect[]" value="' . $objp->rowid . "_" . $i . '"' . ($objp->aarowid ? "checked" : "") . '/>';
  441. print '</td>';
  442. print '</tr>';
  443. $i ++;
  444. }
  445. print '</table>';
  446. print "</div>";
  447. print '</form>';
  448. } else {
  449. print $db->error();
  450. }
  451. // Add code to auto check the box when we select an account
  452. print '<script type="text/javascript" language="javascript">
  453. jQuery(document).ready(function() {
  454. jQuery(".codeventil").change(function() {
  455. var s=$(this).attr("id").replace("codeventil", "")
  456. console.log(s+" "+$(this).val());
  457. if ($(this).val() == -1) jQuery(".checkforselect"+s).prop("checked", false);
  458. else jQuery(".checkforselect"+s).prop("checked", true);
  459. });
  460. });
  461. </script>';
  462. // End of page
  463. llxFooter();
  464. $db->close();