list.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. <?php
  2. /* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
  3. * Copyright (C) 2013-2019 Alexandre Spangaro <aspangaro@open-dsi.fr>
  4. * Copyright (C) 2014-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>
  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 <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/accountancy/customer/list.php
  24. * \ingroup Accountancy (Double entries)
  25. * \brief Ventilation page from customers invoices
  26. */
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
  29. require_once DOL_DOCUMENT_ROOT . '/product/class/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_ref = GETPOST('search_ref', 'alpha');
  48. $search_invoice = GETPOST('search_invoice', '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('accountancycustomerlist'));
  83. $formaccounting = new FormAccounting($db);
  84. $chartaccountcode = dol_getIdFromCode($db, $conf->global->CHARTOFACCOUNTS, 'accounting_system', 'rowid', 'pcg_version');
  85. /*
  86. * Actions
  87. */
  88. if (GETPOST('cancel', 'alpha')) { $action='list'; $massaction=''; }
  89. if (! GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
  90. $parameters=array();
  91. $reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  92. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  93. if (empty($reshook))
  94. {
  95. // Purge search criteria
  96. 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
  97. {
  98. $search_lineid = '';
  99. $search_ref = '';
  100. $search_invoice = '';
  101. $search_label = '';
  102. $search_desc = '';
  103. $search_amount = '';
  104. $search_account = '';
  105. $search_vat = '';
  106. $search_day = '';
  107. $search_month = '';
  108. $search_year = '';
  109. $search_country = '';
  110. $search_tvaintra = '';
  111. }
  112. // Mass actions
  113. $objectclass='AccountingAccount';
  114. $permtoread = $user->rights->accounting->read;
  115. $permtodelete = $user->rights->accounting->delete;
  116. $uploaddir = $conf->accounting->dir_output;
  117. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  118. }
  119. if ($massaction == 'ventil') {
  120. $msg='';
  121. //print '<div><font color="red">' . $langs->trans("Processing") . '...</font></div>';
  122. if (! empty($mesCasesCochees)) {
  123. $msg = '<div>' . $langs->trans("SelectedLines") . ': '.count($mesCasesCochees).'</div>';
  124. $msg.='<div class="detail">';
  125. $cpt = 0;
  126. $ok=0;
  127. $ko=0;
  128. foreach ($mesCasesCochees as $maLigneCochee) {
  129. $maLigneCourante = explode("_", $maLigneCochee);
  130. $monId = $maLigneCourante[0];
  131. $monCompte = GETPOST('codeventil'.$monId);
  132. if ($monCompte <= 0)
  133. {
  134. $msg.= '<div><font color="red">' . $langs->trans("Lineofinvoice") . ' ' . $monId . ' - ' . $langs->trans("NoAccountSelected") . '</font></div>';
  135. $ko++;
  136. }
  137. else
  138. {
  139. $sql = " UPDATE " . MAIN_DB_PREFIX . "facturedet";
  140. $sql .= " SET fk_code_ventilation = " . $monCompte;
  141. $sql .= " WHERE rowid = " . $monId;
  142. $accountventilated = new AccountingAccount($db);
  143. $accountventilated->fetch($monCompte, '');
  144. dol_syslog("accountancy/customer/list.php sql=" . $sql, LOG_DEBUG);
  145. if ($db->query($sql)) {
  146. $msg.= '<div><font color="green">' . $langs->trans("Lineofinvoice") . ' ' . $monId . ' - ' . $langs->trans("VentilatedinAccount") . ' : ' . length_accountg($accountventilated->account_number) . '</font></div>';
  147. $ok++;
  148. } else {
  149. $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>';
  150. $ko++;
  151. }
  152. }
  153. $cpt++;
  154. }
  155. $msg.='</div>';
  156. $msg.= '<div>' . $langs->trans("EndProcessing") . '</div>';
  157. //} else {
  158. // setEventMessages($langs->trans("NoRecordSelected"), null, 'warnings');
  159. }
  160. }
  161. /*
  162. * View
  163. */
  164. $form = new Form($db);
  165. $formother = new FormOther($db);
  166. llxHeader('', $langs->trans("Ventilation"));
  167. if (empty($chartaccountcode))
  168. {
  169. print $langs->trans("ErrorChartOfAccountSystemNotSelected");
  170. // End of page
  171. llxFooter();
  172. $db->close();
  173. exit;
  174. }
  175. // Customer Invoice lines
  176. $sql = "SELECT f.rowid as facid, f.ref as ref, f.datef, f.type as ftype,";
  177. $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,";
  178. $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_sell as code_sell, p.tva_tx as tva_tx_prod,";
  179. $sql.= " p.accountancy_code_sell_intra as code_sell_intra, p.accountancy_code_sell_export as code_sell_export,";
  180. $sql.= " aa.rowid as aarowid, aa2.rowid as aarowid_intra, aa3.rowid as aarowid_export,";
  181. $sql.= " co.code as country_code, co.label as country_label,";
  182. $sql.= " s.tva_intra";
  183. $parameters=array();
  184. $reshook=$hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
  185. $sql.=$hookmanager->resPrint;
  186. $sql.= " FROM " . MAIN_DB_PREFIX . "facture as f";
  187. $sql.= " INNER JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = f.fk_soc";
  188. $sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "c_country as co ON co.rowid = s.fk_pays ";
  189. $sql.= " INNER JOIN " . MAIN_DB_PREFIX . "facturedet as l ON f.rowid = l.fk_facture";
  190. $sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = l.fk_product";
  191. $sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON p.accountancy_code_sell = aa.account_number AND aa.fk_pcg_version = '" . $chartaccountcode."' AND aa.entity = " . $conf->entity;
  192. $sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa2 ON p.accountancy_code_sell_intra = aa2.account_number AND aa2.fk_pcg_version = '" . $chartaccountcode."' AND aa2.entity = " . $conf->entity;
  193. $sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa3 ON p.accountancy_code_sell_export = aa3.account_number AND aa3.fk_pcg_version = '" . $chartaccountcode."' AND aa3.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", $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. elseif ($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. elseif ($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. $arrayofcode = getCountriesInEEC();
  236. $country_code_in_EEC = $country_code_in_EEC_without_me = '';
  237. foreach ($arrayofcode as $key => $value)
  238. {
  239. $country_code_in_EEC.=($country_code_in_EEC ? "," : "")."'".$value."'";
  240. if ($value != $mysoc->country_code) $country_code_in_EEC_without_me.=($country_code_in_EEC_without_me ? "," : "")."'".$value."'";
  241. }
  242. if ($search_country == 'special_allnotme') $sql .= " AND co.code <> '".$db->escape($mysoc->country_code)."'";
  243. elseif ($search_country == 'special_eec') $sql .= " AND co.code IN (".$country_code_in_EEC.")";
  244. elseif ($search_country == 'special_eecnotme') $sql .= " AND co.code IN (".$country_code_in_EEC_without_me.")";
  245. elseif ($search_country == 'special_noteec') $sql .= " AND co.code NOT IN (".$country_code_in_EEC.")";
  246. else $sql .= natural_search(array("co.code","co.label"), $search_country);
  247. }
  248. if (strlen(trim($search_tvaintra))) {
  249. $sql .= natural_search("s.tva_intra", $search_tvaintra);
  250. }
  251. if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
  252. $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_SITUATION . ")";
  253. } else {
  254. $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_DEPOSIT . "," . Facture::TYPE_SITUATION . ")";
  255. }
  256. $sql .= " AND f.entity IN (" . getEntity('invoice', 0) . ")"; // We don't share object for accountancy
  257. // Add where from hooks
  258. $parameters=array();
  259. $reshook=$hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
  260. $sql.=$hookmanager->resPrint;
  261. $sql .= $db->order($sortfield, $sortorder);
  262. // Count total nb of records
  263. $nbtotalofrecords = '';
  264. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  265. {
  266. $result = $db->query($sql);
  267. $nbtotalofrecords = $db->num_rows($result);
  268. if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
  269. {
  270. $page = 0;
  271. $offset = 0;
  272. }
  273. }
  274. $sql .= $db->plimit($limit + 1, $offset);
  275. dol_syslog("accountancy/customer/list.php", LOG_DEBUG);
  276. $result = $db->query($sql);
  277. if ($result) {
  278. $num_lines = $db->num_rows($result);
  279. $i = 0;
  280. $arrayofselected=is_array($toselect)?$toselect:array();
  281. $param='';
  282. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
  283. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit);
  284. if ($search_lineid) $param.='&search_lineid='.urlencode($search_lineid);
  285. if ($search_day) $param.='&search_day='.urlencode($search_day);
  286. if ($search_month) $param.='&search_month='.urlencode($search_month);
  287. if ($search_year) $param.='&search_year='.urlencode($search_year);
  288. if ($search_invoice) $param.='&search_invoice='.urlencode($search_invoice);
  289. if ($search_ref) $param.='&search_ref='.urlencode($search_ref);
  290. if ($search_desc) $param.='&search_desc='.urlencode($search_desc);
  291. if ($search_amount) $param.='&search_amount='.urlencode($search_amount);
  292. if ($search_vat) $param.='&search_vat='.urlencode($search_vat);
  293. if ($search_country) $param.= "&search_country=".urlencode($search_country);
  294. if ($search_tvaintra) $param.= "&search_tvaintra=".urlencode($search_tvaintra);
  295. $arrayofmassactions = array(
  296. 'ventil'=>$langs->trans("Ventilate")
  297. //'presend'=>$langs->trans("SendByMail"),
  298. //'builddoc'=>$langs->trans("PDFMerge"),
  299. );
  300. //if ($user->rights->mymodule->supprimer) $arrayofmassactions['predelete']='<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
  301. //if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array();
  302. $massactionbutton=$form->selectMassAction('ventil', $arrayofmassactions, 1);
  303. print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">' . "\n";
  304. print '<input type="hidden" name="action" value="ventil">';
  305. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  306. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  307. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  308. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  309. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  310. print '<input type="hidden" name="page" value="'.$page.'">';
  311. print_barre_liste($langs->trans("InvoiceLines"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num_lines, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit);
  312. print '<span class="opacitymedium">'.$langs->trans("DescVentilTodoCustomer") . '</span></br><br>';
  313. /*$topicmail="Information";
  314. $modelmail="project";
  315. $objecttmp=new Project($db);
  316. $trackid='prj'.$object->id;
  317. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';*/
  318. if ($msg) print $msg.'<br>';
  319. $moreforfilter = '';
  320. print '<div class="div-table-responsive">';
  321. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  322. // We add search filter
  323. print '<tr class="liste_titre_filter">';
  324. print '<td class="liste_titre"><input type="text" class="flat maxwidth25" name="search_lineid" value="' . dol_escape_htmltag($search_lineid) . '""></td>';
  325. print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_invoice" value="' . dol_escape_htmltag($search_invoice) . '"></td>';
  326. print '<td class="liste_titre center nowraponall">';
  327. if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) {
  328. print '<input class="flat valignmiddle maxwidth25" type="text" maxlength="2" name="search_day" value="'.$search_day.'">';
  329. }
  330. print '<input class="flat valignmiddle maxwidth25" type="text" 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 maxwidth100" name="search_desc" value="' . dol_escape_htmltag($search_desc) . '"></td>';
  336. print '<td class="liste_titre right"><input type="text" class="flat maxwidth50 right" name="search_amount" value="' . dol_escape_htmltag($search_amount) . '"></td>';
  337. 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>';
  338. print '<td class="liste_titre">';
  339. print $form->select_country($search_country, 'search_country', '', 0, 'maxwidth150', '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 class="center liste_titre">';
  346. $searchpicto=$form->showFilterButtons();
  347. print $searchpicto;
  348. print '</td>';
  349. print '</tr>';
  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("Date", $_SERVER["PHP_SELF"], "f.datef, f.ref, l.rowid", "", $param, '', $sortfield, $sortorder, 'center ');
  354. print_liste_field_titre("ProductRef", $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
  355. //print_liste_field_titre("ProductLabel", $_SERVER["PHP_SELF"], "p.label", "", $param, '', $sortfield, $sortorder);
  356. print_liste_field_titre("ProductDescription", $_SERVER["PHP_SELF"], "l.description", "", $param, '', $sortfield, $sortorder);
  357. print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "l.total_ht", "", $param, '', $sortfield, $sortorder, 'right maxwidth50 ');
  358. print_liste_field_titre("VATRate", $_SERVER["PHP_SELF"], "l.tva_tx", "", $param, '', $sortfield, $sortorder, 'right ');
  359. print_liste_field_titre("Country", $_SERVER["PHP_SELF"], "co.label", "", $param, '', $sortfield, $sortorder);
  360. print_liste_field_titre("VATIntra", $_SERVER["PHP_SELF"], "s.tva_intra", "", $param, '', $sortfield, $sortorder);
  361. print_liste_field_titre("AccountAccountingSuggest", '', '', '', '', '', '', '', 'center ');
  362. print_liste_field_titre("IntoAccount", '', '', '', '', '', '', '', 'center ');
  363. $checkpicto='';
  364. if ($massactionbutton) $checkpicto=$form->showCheckAddButtons('checkforselect', 1);
  365. print_liste_field_titre($checkpicto, '', '', '', '', '', '', '', 'center ');
  366. print "</tr>\n";
  367. $facture_static = new Facture($db);
  368. $product_static = new Product($db);
  369. $isSellerInEEC = isInEEC($mysoc);
  370. while ( $i < min($num_lines, $limit) ) {
  371. $objp = $db->fetch_object($result);
  372. $objp->code_sell_l = '';
  373. $objp->code_sell_p = '';
  374. $objp->aarowid_suggest = '';
  375. $product_static->ref = $objp->product_ref;
  376. $product_static->id = $objp->product_id;
  377. $product_static->type = $objp->type;
  378. $product_static->label = $objp->product_label;
  379. $facture_static->ref = $objp->ref;
  380. $facture_static->id = $objp->facid;
  381. $facture_static->type = $objp->ftype;
  382. $code_sell_p_notset = '';
  383. $objp->aarowid_suggest = $objp->aarowid;
  384. $isBuyerInEEC = isInEEC($objp);
  385. $suggestedaccountingaccountbydefaultfor = '';
  386. if ($objp->type_l == 1) {
  387. if ($objp->country_code == $mysoc->country_code || empty($objp->country_code)) { // If buyer in same country than seller (if not defined, we assume it is same country)
  388. $objp->code_sell_l = (! empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : '');
  389. $suggestedaccountingaccountbydefaultfor = '';
  390. } else {
  391. if ($isSellerInEEC && $isBuyerInEEC) { // European intravat sale
  392. $objp->code_sell_l = (! empty($conf->global->ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT : '');
  393. $suggestedaccountingaccountbydefaultfor = 'eec';
  394. } else { // Foreign sale
  395. $objp->code_sell_l = (! empty($conf->global->ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT : '');
  396. $suggestedaccountingaccountbydefaultfor = 'export';
  397. }
  398. }
  399. } elseif ($objp->type_l == 0) {
  400. if ($objp->country_code == $mysoc->country_code || empty($objp->country_code)) { // If buyer in same country than seller (if not defined, we assume it is same country)
  401. $objp->code_sell_l = (! empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : '');
  402. $suggestedaccountingaccountbydefaultfor = '';
  403. } else {
  404. if ($isSellerInEEC && $isBuyerInEEC) { // European intravat sale
  405. $objp->code_sell_l = (! empty($conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT : '');
  406. $suggestedaccountingaccountbydefaultfor = 'eec';
  407. } else {
  408. $objp->code_sell_l = (! empty($conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT : '');
  409. $suggestedaccountingaccountbydefaultfor = 'export';
  410. }
  411. }
  412. }
  413. if ($objp->code_sell_l == -1) $objp->code_sell_l='';
  414. $suggestedaccountingaccountfor = '';
  415. if ($objp->country_code == $mysoc->country_code || empty($objp->country_code)) { // If buyer in same country than seller (if not defined, we assume it is same country)
  416. $objp->code_sell_p = $objp->code_sell;
  417. $objp->aarowid_suggest = $objp->aarowid;
  418. $suggestedaccountingaccountfor = '';
  419. } else {
  420. if ($isSellerInEEC && $isBuyerInEEC) { // European intravat sale
  421. $objp->code_sell_p = $objp->code_sell_intra;
  422. $objp->aarowid_suggest = $objp->aarowid_intra;
  423. $suggestedaccountingaccountfor = 'eec';
  424. } else { // Foreign sale
  425. $objp->code_sell_p = $objp->code_sell_export;
  426. $objp->aarowid_suggest = $objp->aarowid_export;
  427. $suggestedaccountingaccountfor = 'export';
  428. }
  429. }
  430. if (! empty($objp->code_sell)) {
  431. //$objp->code_sell_p = $objp->code_sell; // Code on product
  432. } else {
  433. $code_sell_p_notset = 'color:orange';
  434. }
  435. if (empty($objp->code_sell_l) && empty($objp->code_sell_p)) $code_sell_p_notset = 'color:red';
  436. // $objp->code_sell_l is now default code of product/service
  437. // $objp->code_sell_p is now code of product/service
  438. print '<tr class="oddeven">';
  439. // Line id
  440. print '<td>' . $objp->rowid . '</td>';
  441. // Ref Invoice
  442. print '<td class="nowraponall">' . $facture_static->getNomUrl(1) . '</td>';
  443. print '<td class="center">' . dol_print_date($db->jdate($objp->datef), 'day') . '</td>';
  444. // Ref Product
  445. print '<td>';
  446. if ($product_static->id > 0)
  447. print $product_static->getNomUrl(1);
  448. if ($objp->product_label) print '<br>'.$objp->product_label;
  449. print '</td>';
  450. print '<td class="tdoverflowonsmartphone">';
  451. $text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->description));
  452. $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
  453. print $form->textwithtooltip(dol_trunc($text, $trunclength), $objp->description);
  454. print '</td>';
  455. print '<td class="nowrap right">';
  456. print price($objp->total_ht);
  457. print '</td>';
  458. // Vat rate
  459. if ($objp->vat_tx_l != $objp->vat_tx_p)
  460. $code_vat_differ = 'font-weight:bold; text-decoration:blink; color:red';
  461. print '<td style="' . $code_vat_differ . '" class="right">';
  462. print vatrate($objp->tva_tx_line.($objp->vat_src_code?' ('.$objp->vat_src_code.')':''));
  463. print '</td>';
  464. print '<td>';
  465. $labelcountry=($objp->country_code && ($langs->trans("Country".$objp->country_code)!="Country".$objp->country_code))?$langs->trans("Country".$objp->country_code):$objp->country_label;
  466. print $labelcountry;
  467. print '</td>';
  468. print '<td>' . $objp->tva_intra . '</td>';
  469. // Current account
  470. print '<td class="center" style="' . $code_sell_p_notset . '">';
  471. $s = (($objp->type_l == 1)?$langs->trans("DefaultForService"):$langs->trans("DefaultForProduct")).': ';
  472. $shelp = '';
  473. if ($suggestedaccountingaccountbydefaultfor == 'eec') $shelp.= $langs->trans("SaleEEC");
  474. elseif ($suggestedaccountingaccountbydefaultfor == 'export') $shelp.= $langs->trans("SaleExport");
  475. $s.= ($objp->code_sell_l > 0 ? length_accountg($objp->code_sell_l) : $langs->trans("NotDefined"));
  476. print $form->textwithpicto($s, $shelp, 1, 'help', '', 0, 2, '', 1);
  477. if ($objp->product_id > 0)
  478. {
  479. print '<br>';
  480. $s = (($objp->type_l == 1)?$langs->trans("ThisService"):$langs->trans("ThisProduct")).': ';
  481. $shelp = '';
  482. if ($suggestedaccountingaccountfor == 'eec') $shelp = $langs->trans("SaleEEC");
  483. elseif ($suggestedaccountingaccountfor == 'export') $shelp = $langs->trans("SaleExport");
  484. $s.= (empty($objp->code_sell_p) ? $langs->trans("NotDefined") : length_accountg($objp->code_sell_p));
  485. print $form->textwithpicto($s, $shelp, 1, 'help', '', 0, 2, '', 1);
  486. }
  487. print '</td>';
  488. // Suggested accounting account
  489. print '<td>';
  490. print $formaccounting->select_account($objp->aarowid_suggest, 'codeventil'.$objp->rowid, 1, array(), 0, 0, 'codeventil maxwidth200 maxwidthonsmartphone', 'cachewithshowemptyone');
  491. print '</td>';
  492. // Column with checkbox
  493. print '<td class="center">';
  494. print '<input type="checkbox" class="flat checkforselect checkforselect'.$objp->rowid.'" name="toselect[]" value="' . $objp->rowid . "_" . $i . '"' . ($objp->aarowid ? "checked" : "") . '/>';
  495. print '</td>';
  496. print '</tr>';
  497. $i ++;
  498. }
  499. print '</table>';
  500. print "</div>";
  501. print '</form>';
  502. } else {
  503. print $db->error();
  504. }
  505. // Add code to auto check the box when we select an account
  506. print '<script type="text/javascript" language="javascript">
  507. jQuery(document).ready(function() {
  508. jQuery(".codeventil").change(function() {
  509. var s=$(this).attr("id").replace("codeventil", "")
  510. console.log(s+" "+$(this).val());
  511. if ($(this).val() == -1) jQuery(".checkforselect"+s).prop("checked", false);
  512. else jQuery(".checkforselect"+s).prop("checked", true);
  513. });
  514. });
  515. </script>';
  516. // End of page
  517. llxFooter();
  518. $db->close();