list.php 25 KB

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