list-rec.php 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100
  1. <?php
  2. /* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  6. * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  8. * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
  9. * Copyright (C) 2015-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
  10. * Copyright (C) 2016 Meziane Sof <virtualsof@yahoo.fr>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  24. */
  25. /**
  26. * \file htdocs/fourn/facture/list-rec.php
  27. * \ingroup facture
  28. * \brief Page to show list of template/recurring invoices
  29. */
  30. // Load Dolibarr environment
  31. require '../../main.inc.php';
  32. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture-rec.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  41. // Load translation files required by the page
  42. $langs->loadLangs(array('bills', 'compta', 'admin', 'other', 'suppliers'));
  43. $action = GETPOST('action', 'alpha');
  44. $massaction = GETPOST('massaction', 'alpha');
  45. $show_files = GETPOST('show_files', 'int');
  46. $confirm = GETPOST('confirm', 'alpha');
  47. $cancel = GETPOST('cancel', 'alpha');
  48. $toselect = GETPOST('toselect', 'array');
  49. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'supplierinvoicestemplatelist'; // To manage different context of search
  50. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  51. $mode = GETPOST('mode', 'aZ'); // The output mode ('list', 'kanban', 'hierarchy', 'calendar', ...)
  52. $socid = GETPOST('socid', 'int');
  53. $id = (GETPOST('facid', 'int') ? GETPOST('facid', 'int') : GETPOST('id', 'int'));
  54. $lineid = GETPOST('lineid', 'int');
  55. $ref = GETPOST('ref', 'alpha');
  56. if ($user->socid) {
  57. $socid = $user->socid;
  58. }
  59. $objecttype = 'facture_fourn_rec';
  60. if ($action == "create" || $action == "add") {
  61. $objecttype = '';
  62. }
  63. $search_ref = GETPOST('search_ref');
  64. $search_societe = GETPOST('search_societe');
  65. $search_montant_ht = GETPOST('search_montant_ht');
  66. $search_montant_vat = GETPOST('search_montant_vat');
  67. $search_montant_ttc = GETPOST('search_montant_ttc');
  68. $search_payment_mode = GETPOST('search_payment_mode');
  69. $search_payment_term = GETPOST('search_payment_term');
  70. $search_date_startday = GETPOST('search_date_startday', 'int');
  71. $search_date_startmonth = GETPOST('search_date_startmonth', 'int');
  72. $search_date_startyear = GETPOST('search_date_startyear', 'int');
  73. $search_date_endday = GETPOST('search_date_endday', 'int');
  74. $search_date_endmonth = GETPOST('search_date_endmonth', 'int');
  75. $search_date_endyear = GETPOST('search_date_endyear', 'int');
  76. $search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver
  77. $search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
  78. $search_date_when_startday = GETPOST('search_date_when_startday', 'int');
  79. $search_date_when_startmonth = GETPOST('search_date_when_startmonth', 'int');
  80. $search_date_when_startyear = GETPOST('search_date_when_startyear', 'int');
  81. $search_date_when_endday = GETPOST('search_date_when_endday', 'int');
  82. $search_date_when_endmonth = GETPOST('search_date_when_endmonth', 'int');
  83. $search_date_when_endyear = GETPOST('search_date_when_endyear', 'int');
  84. $search_date_when_start = dol_mktime(0, 0, 0, $search_date_when_startmonth, $search_date_when_startday, $search_date_when_startyear); // Use tzserver
  85. $search_date_when_end = dol_mktime(23, 59, 59, $search_date_when_endmonth, $search_date_when_endday, $search_date_when_endyear);
  86. $search_recurring = GETPOST('search_recurring', 'int');
  87. $search_frequency = GETPOST('search_frequency', 'alpha');
  88. $search_unit_frequency = GETPOST('search_unit_frequency', 'alpha');
  89. $search_nb_gen_done = GETPOST('search_nb_gen_done', 'alpha');
  90. $search_status = GETPOST('search_status', 'int');
  91. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  92. $sortfield = GETPOST('sortfield', 'aZ09comma');
  93. $sortorder = GETPOST('sortorder', 'aZ09comma');
  94. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  95. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  96. // If $page is not defined, or '' or -1 or if we click on clear filters
  97. $page = 0;
  98. }
  99. $offset = $limit * $page;
  100. $pageprev = $page - 1;
  101. $pagenext = $page + 1;
  102. // Initialize technical objects
  103. $object = new FactureFournisseurRec($db);
  104. $extrafields = new ExtraFields($db);
  105. if (($id > 0 || $ref) && $action != 'create' && $action != 'add') {
  106. $ret = $object->fetch($id, $ref);
  107. if (!$ret) {
  108. setEventMessages($langs->trans("ErrorRecordNotFound"), null, 'errors');
  109. }
  110. }
  111. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  112. $hookmanager->initHooks(array('supplierinvoicereclist'));
  113. // Fetch optionals attributes and labels
  114. $extrafields->fetch_name_optionals_label($object->table_element);
  115. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  116. // Default sort order (if not yet defined by previous GETPOST)
  117. if (!$sortorder) {
  118. $sortorder = 'DESC';
  119. }
  120. if (!$sortfield) {
  121. $sortfield = 'f.titre';
  122. }
  123. $arrayfields = array(
  124. 'f.titre'=>array('label'=>'Ref', 'checked'=>1),
  125. 's.nom'=>array('label'=>'ThirdParty', 'checked'=>1),
  126. 'f.total_ht'=>array('label'=>'AmountHT', 'checked'=>1),
  127. 'f.total_tva'=>array('label'=>'AmountVAT', 'checked'=>1),
  128. 'f.total_ttc'=>array('label'=>'AmountTTC', 'checked'=>1),
  129. 'f.fk_mode_reglement'=>array('label'=>'PaymentMode', 'checked'=>0),
  130. 'f.fk_cond_reglement'=>array('label'=>'PaymentTerm', 'checked'=>0),
  131. 'recurring'=>array('label'=>'RecurringInvoice', 'checked'=>1),
  132. 'f.frequency'=>array('label'=>'Frequency', 'checked'=>1),
  133. 'f.unit_frequency'=>array('label'=>'FrequencyUnit', 'checked'=>1),
  134. 'f.nb_gen_done'=>array('label'=>'NbOfGenerationDoneShort', 'checked'=>1),
  135. 'f.date_last_gen'=>array('label'=>'DateLastGenerationShort', 'checked'=>1),
  136. 'f.date_when'=>array('label'=>'NextDateToExecutionShort', 'checked'=>1),
  137. 'f.fk_user_author'=>array('label'=>'UserCreation', 'checked'=>0, 'position'=>500),
  138. 'f.fk_user_modif'=>array('label'=>'UserModification', 'checked'=>0, 'position'=>505),
  139. 'f.datec'=>array('label'=>'DateCreation', 'checked'=>0, 'position'=>520),
  140. 'f.tms'=>array('label'=>'DateModificationShort', 'checked'=>0, 'position'=>525),
  141. 'status'=>array('label'=>'Status', 'checked'=>1, 'position'=>1000),
  142. );
  143. // Extra fields
  144. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  145. $object->fields = dol_sort_array($object->fields, 'position');
  146. $arrayfields = dol_sort_array($arrayfields, 'position');
  147. if ($socid > 0) {
  148. $tmpthirdparty = new Societe($db);
  149. $res = $tmpthirdparty->fetch($socid);
  150. if ($res > 0) {
  151. $search_societe = $tmpthirdparty->name;
  152. }
  153. }
  154. $objecttype = 'facture_fourn_rec';
  155. $permissionnote = $user->hasRight('facture', 'creer'); // Used by the include of actions_setnotes.inc.php
  156. $permissiondellink = $user->hasRight('facture', 'creer'); // Used by the include of actions_dellink.inc.php
  157. $permissiontoedit = $user->hasRight('facture', 'creer'); // Used by the include of actions_lineupdonw.inc.php
  158. $result = restrictedArea($user, 'supplier_invoicerec', $object->id, $objecttype);
  159. /*
  160. * Actions
  161. */
  162. if (GETPOST('cancel', 'alpha')) {
  163. $action = 'list';
  164. $massaction = '';
  165. }
  166. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  167. $massaction = '';
  168. }
  169. $parameters = array('socid' => $socid);
  170. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  171. if ($reshook < 0) {
  172. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  173. }
  174. if (empty($reshook)) {
  175. /*if (GETPOST('cancel', 'alpha')) {
  176. $action = '';
  177. }*/
  178. // Selection of new fields
  179. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  180. // Purge search criteria
  181. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
  182. $search_ref = '';
  183. $search_societe = '';
  184. $search_montant_ht = '';
  185. $search_montant_vat = '';
  186. $search_montant_ttc = '';
  187. $search_payment_mode = '';
  188. $search_payment_term = '';
  189. $search_date_startday = '';
  190. $search_date_startmonth = '';
  191. $search_date_startyear = '';
  192. $search_date_endday = '';
  193. $search_date_endmonth = '';
  194. $search_date_endyear = '';
  195. $search_date_start = '';
  196. $search_date_end = '';
  197. $search_date_when_startday = '';
  198. $search_date_when_startmonth = '';
  199. $search_date_when_startyear = '';
  200. $search_date_when_endday = '';
  201. $search_date_when_endmonth = '';
  202. $search_date_when_endyear = '';
  203. $search_date_when_start = '';
  204. $search_date_when_end = '';
  205. $search_recurring = '';
  206. $search_frequency = '';
  207. $search_unit_frequency = '';
  208. $search_nb_gen_done = '';
  209. $search_status = '';
  210. $toselect = array();
  211. $search_array_options = array();
  212. }
  213. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  214. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  215. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  216. }
  217. // Mass actions
  218. /*$objectclass='MyObject';
  219. $objectlabel='MyObject';
  220. $permissiontoread = $user->hasRight("mymodule", "read");
  221. $permissiontodelete = $user->hasRight("mymodule", "delete");
  222. $uploaddir = $conf->mymodule->dir_output;
  223. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';*/
  224. }
  225. /*
  226. * View
  227. */
  228. $form = new Form($db);
  229. $formother = new FormOther($db);
  230. if (isModEnabled('project')) {
  231. $formproject = new FormProjets($db);
  232. }
  233. $companystatic = new Societe($db);
  234. $supplierinvoicerectmp = new FactureFournisseurRec($db);
  235. $tmpuser = new User($db);
  236. $now = dol_now();
  237. $help_url = '';
  238. $title = $langs->trans("RepeatableSupplierInvoices");
  239. $morejs = array();
  240. $morecss = array();
  241. $tmparray = dol_getdate($now);
  242. $today = dol_mktime(23, 59, 59, $tmparray['mon'], $tmparray['mday'], $tmparray['year']); // Today is last second of current day
  243. // Build and execute select
  244. // --------------------------------------------------------------------
  245. $sql = "SELECT s.nom as name, s.rowid as socid, f.rowid as facid, f.titre as title, f.total_ht, f.total_tva, f.total_ttc, f.frequency, f.unit_frequency,";
  246. $sql .= " f.nb_gen_done, f.nb_gen_max, f.date_last_gen, f.date_when, f.suspended,";
  247. $sql .= " f.datec, f.fk_user_author, f.tms, f.fk_user_modif,";
  248. $sql .= " f.fk_cond_reglement, f.fk_mode_reglement";
  249. // Add fields from extrafields
  250. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  251. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  252. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  253. }
  254. }
  255. // Add fields from hooks
  256. $parameters = array();
  257. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  258. $sql .= $hookmanager->resPrint;
  259. $sql = preg_replace('/,\s*$/', '', $sql);
  260. $sqlfields = $sql; // $sql fields to remove for count total
  261. $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'facture_fourn_rec as f';
  262. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_rec_extrafields as ef ON ef.fk_object = f.rowid';
  263. if (!$user->hasRight("societe", "client", "voir") && !$socid) {
  264. $sql .= ', '.MAIN_DB_PREFIX.'societe_commerciaux as sc';
  265. }
  266. // Add table from hooks
  267. $parameters = array();
  268. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  269. $sql .= $hookmanager->resPrint;
  270. $sql .= " WHERE f.fk_soc = s.rowid";
  271. $sql .= ' AND f.entity IN ('.getEntity('invoice').')';
  272. if (!$user->hasRight("societe", "client", "voir") && !$socid) {
  273. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  274. }
  275. if ($search_ref) {
  276. $sql .= natural_search('f.titre', $search_ref);
  277. }
  278. if ($socid) {
  279. $sql .= ' AND s.rowid = '.(int) $socid;
  280. }
  281. if ($search_societe) {
  282. $sql .= natural_search('s.nom', $search_societe);
  283. }
  284. if ($search_montant_ht != '') {
  285. $sql .= natural_search('f.total_ht', $search_montant_ht, 1);
  286. }
  287. if ($search_montant_vat != '') {
  288. $sql .= natural_search('f.total_tva', $search_montant_vat, 1);
  289. }
  290. if ($search_montant_ttc != '') {
  291. $sql .= natural_search('f.total_ttc', $search_montant_ttc, 1);
  292. }
  293. if (!empty($search_payment_mode) && $search_payment_mode != '-1') {
  294. $sql .= natural_search('f.fk_mode_reglement', $search_payment_mode, 1);
  295. }
  296. if (!empty($search_payment_term) && $search_payment_term != '-1') {
  297. $sql .= natural_search('f.fk_cond_reglement', $search_payment_term, 1);
  298. }
  299. if ($search_recurring == '1') {
  300. $sql .= ' AND f.frequency > 0';
  301. }
  302. if ($search_recurring == '0') {
  303. $sql .= ' AND (f.frequency IS NULL or f.frequency = 0)';
  304. }
  305. if ($search_frequency != '') {
  306. $sql .= natural_search('f.frequency', $search_frequency, 1);
  307. }
  308. if ($search_unit_frequency != '') {
  309. $sql .= ' AND f.frequency > 0';
  310. $sql .= natural_search('f.unit_frequency', $search_unit_frequency);
  311. }
  312. if ($search_nb_gen_done != '') {
  313. $sql .= natural_search("f.nb_gen_done", $search_nb_gen_done, 1);
  314. }
  315. if ($search_status != '' && $search_status >= -1) {
  316. if ($search_status == 0) {
  317. $sql .= ' AND frequency = 0 AND suspended = 0';
  318. }
  319. if ($search_status == 1) {
  320. $sql .= ' AND frequency != 0 AND suspended = 0';
  321. }
  322. if ($search_status == -1) {
  323. $sql .= ' AND suspended = 1';
  324. }
  325. }
  326. if ($search_date_start) {
  327. $sql .= " AND f.date_last_gen >= '".$db->idate($search_date_start)."'";
  328. }
  329. if ($search_date_end) {
  330. $sql .= " AND f.date_last_gen <= '".$db->idate($search_date_end)."'";
  331. }
  332. if ($search_date_when_start) {
  333. $sql .= " AND f.date_when >= '".$db->idate($search_date_when_start)."'";
  334. }
  335. if ($search_date_when_end) {
  336. $sql .= " AND f.date_when <= '".$db->idate($search_date_when_end)."'";
  337. }
  338. // Count total nb of records
  339. $nbtotalofrecords = '';
  340. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  341. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  342. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  343. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  344. $resql = $db->query($sqlforcount);
  345. if ($resql) {
  346. $objforcount = $db->fetch_object($resql);
  347. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  348. } else {
  349. dol_print_error($db);
  350. }
  351. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  352. $page = 0;
  353. $offset = 0;
  354. }
  355. $db->free($resql);
  356. }
  357. $tmpsortfield = $sortfield;
  358. if ($tmpsortfield == 'recurring') {
  359. $tmpsortfield = 'f.frequency';
  360. }
  361. // Complete request and execute it with limit
  362. $sql .= $db->order($tmpsortfield, $sortorder);
  363. if ($limit) {
  364. $sql .= $db->plimit($limit + 1, $offset);
  365. }
  366. $resql = $db->query($sql);
  367. if (!$resql) {
  368. dol_print_error($db);
  369. exit;
  370. }
  371. $num = $db->num_rows($resql);
  372. // Output page
  373. // --------------------------------------------------------------------
  374. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist');
  375. $arrayofselected = is_array($toselect) ? $toselect : array();
  376. $param = '';
  377. if (!empty($mode)) {
  378. $param .= '&mode='.urlencode($mode);
  379. }
  380. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  381. $param .= '&contextpage='.urlencode($contextpage);
  382. }
  383. if ($limit > 0 && $limit != $conf->liste_limit) {
  384. $param .= '&limit='.((int) $limit);
  385. }
  386. if ($socid > 0) {
  387. $param .= '&socid='.urlencode($socid);
  388. }
  389. if ($search_date_startday) {
  390. $param .= '&search_date_startday='.urlencode($search_date_startday);
  391. }
  392. if ($search_date_startmonth) {
  393. $param .= '&search_date_startmonth='.urlencode($search_date_startmonth);
  394. }
  395. if ($search_date_startyear) {
  396. $param .= '&search_date_startyear='.urlencode($search_date_startyear);
  397. }
  398. if ($search_date_endday) {
  399. $param .= '&search_date_endday='.urlencode($search_date_endday);
  400. }
  401. if ($search_date_endmonth) {
  402. $param .= '&search_date_endmonth='.urlencode($search_date_endmonth);
  403. }
  404. if ($search_date_endyear) {
  405. $param .= '&search_date_endyear='.urlencode($search_date_endyear);
  406. }
  407. if ($search_date_when_startday) {
  408. $param .= '&search_date_when_startday='.urlencode($search_date_when_startday);
  409. }
  410. if ($search_date_when_startmonth) {
  411. $param .= '&search_date_when_startmonth='.urlencode($search_date_when_startmonth);
  412. }
  413. if ($search_date_when_startyear) {
  414. $param .= '&search_date_when_startyear='.urlencode($search_date_when_startyear);
  415. }
  416. if ($search_date_when_endday) {
  417. $param .= '&search_date_when_endday='.urlencode($search_date_when_endday);
  418. }
  419. if ($search_date_when_endmonth) {
  420. $param .= '&search_date_when_endmonth='.urlencode($search_date_when_endmonth);
  421. }
  422. if ($search_date_when_endyear) {
  423. $param .= '&search_date_when_endyear='.urlencode($search_date_when_endyear);
  424. }
  425. if ($search_ref) {
  426. $param .= '&search_ref='.urlencode($search_ref);
  427. }
  428. if ($search_societe) {
  429. $param .= '&search_societe='.urlencode($search_societe);
  430. }
  431. if ($search_montant_ht != '') {
  432. $param .= '&search_montant_ht='.urlencode($search_montant_ht);
  433. }
  434. if ($search_montant_vat != '') {
  435. $param .= '&search_montant_vat='.urlencode($search_montant_vat);
  436. }
  437. if ($search_montant_ttc != '') {
  438. $param .= '&search_montant_ttc='.urlencode($search_montant_ttc);
  439. }
  440. if ($search_payment_mode != '') {
  441. $param .= '&search_payment_mode='.urlencode($search_payment_mode);
  442. }
  443. if ($search_payment_term != '') {
  444. $param .= '&search_payment_term='.urlencode($search_payment_term);
  445. }
  446. if ($search_recurring != '' && $search_recurring != '-1') {
  447. $param .= '&search_recurring='.urlencode($search_recurring);
  448. }
  449. if ($search_frequency > 0) {
  450. $param .= '&search_frequency='.urlencode($search_frequency);
  451. }
  452. if ($search_unit_frequency != '') {
  453. $param .= '&search_unit_frequency='.urlencode($search_unit_frequency);
  454. }
  455. if ($search_nb_gen_done != '') {
  456. $param .= '&search_nb_gen_done='.urlencode($search_nb_gen_done);
  457. }
  458. if ($search_status != '') {
  459. $param .= '&search_status='.urlencode($search_status);
  460. }
  461. if ($optioncss != '') {
  462. $param .= '&optioncss='.urlencode($optioncss);
  463. }
  464. // Add $param from extra fields
  465. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  466. // Add $param from hooks
  467. $parameters = array();
  468. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  469. $param .= $hookmanager->resPrint;
  470. // List of mass actions available
  471. $arrayofmassactions = array(
  472. //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
  473. //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  474. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  475. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  476. );
  477. $massactionbutton = $form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge")));
  478. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  479. $selectedfields = ($mode != 'kanban' ? $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')) : ''); // This also change content of $arrayfields
  480. //$selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
  481. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  482. if ($optioncss != '') {
  483. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  484. }
  485. print '<input type="hidden" name="token" value="'.newToken().'">';
  486. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  487. print '<input type="hidden" name="action" value="list">';
  488. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  489. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  490. print '<input type="hidden" name="page" value="'.$page.'">';
  491. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  492. print '<input type="hidden" name="search_status" value="'.$search_status.'">';
  493. print '<input type="hidden" name="page_y" value="">';
  494. print '<input type="hidden" name="mode" value="'.$mode.'">';
  495. print_barre_liste($title, $page, $_SERVER['PHP_SELF'], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'bill', 0, '', '', $limit, 0, 0, 1);
  496. print '<span class="opacitymedium">'.$langs->trans("ToCreateAPredefinedSupplierInvoice", $langs->transnoentitiesnoconv("ChangeIntoRepeatableInvoice")).'</span><br><br>';
  497. $i = 0;
  498. $moreforfilter = '';
  499. $parameters = array();
  500. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  501. if (empty($reshook)) {
  502. $moreforfilter .= $hookmanager->resPrint;
  503. } else {
  504. $moreforfilter = $hookmanager->resPrint;
  505. }
  506. if (!empty($moreforfilter)) {
  507. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  508. print $moreforfilter;
  509. print '</div>';
  510. }
  511. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  512. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
  513. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  514. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  515. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  516. // Fields title search
  517. // --------------------------------------------------------------------
  518. print '<tr class="liste_titre_filter">';
  519. // Action column
  520. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  521. print '<td class="liste_titre maxwidthsearch center">';
  522. $searchpicto = $form->showFilterButtons('left');
  523. print $searchpicto;
  524. print '</td>';
  525. }
  526. // Ref
  527. if (!empty($arrayfields['f.titre']['checked'])) {
  528. print '<td class="liste_titre left">';
  529. print '<input class="flat maxwidth100" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
  530. print '</td>';
  531. }
  532. // Thirdparty
  533. if (!empty($arrayfields['s.nom']['checked'])) {
  534. print '<td class="liste_titre left"><input class="flat" type="text" size="8" name="search_societe" value="'.dol_escape_htmltag($search_societe).'"></td>';
  535. }
  536. if (!empty($arrayfields['f.total_ht']['checked'])) {
  537. // Amount net
  538. print '<td class="liste_titre right">';
  539. print '<input class="flat" type="text" size="5" name="search_montant_ht" value="'.dol_escape_htmltag($search_montant_ht).'">';
  540. print '</td>';
  541. }
  542. if (!empty($arrayfields['f.total_tva']['checked'])) {
  543. // Amount Vat
  544. print '<td class="liste_titre right">';
  545. print '<input class="flat" type="text" size="5" name="search_montant_vat" value="'.dol_escape_htmltag($search_montant_vat).'">';
  546. print '</td>';
  547. }
  548. if (!empty($arrayfields['f.total_ttc']['checked'])) {
  549. // Amount
  550. print '<td class="liste_titre right">';
  551. print '<input class="flat" type="text" size="5" name="search_montant_ttc" value="'.dol_escape_htmltag($search_montant_ttc).'">';
  552. print '</td>';
  553. }
  554. if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
  555. // Payment term
  556. print '<td class="liste_titre">';
  557. print $form->getSelectConditionsPaiements($search_payment_term, 'search_payment_term', -1, 1, 1, 'maxwidth100');
  558. print "</td>";
  559. }
  560. if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
  561. // Payment mode
  562. print '<td class="liste_titre">';
  563. print $form->select_types_paiements($search_payment_mode, 'search_payment_mode', '', 0, 1, 1, 0, 1, 'maxwidth100', 1);
  564. print '</td>';
  565. }
  566. if (!empty($arrayfields['recurring']['checked'])) {
  567. // Recurring or not
  568. print '<td class="liste_titre center">';
  569. print $form->selectyesno('search_recurring', $search_recurring, 1, false, 1);
  570. print '</td>';
  571. }
  572. if (!empty($arrayfields['f.frequency']['checked'])) {
  573. // Recurring or not
  574. print '<td class="liste_titre center">';
  575. print '<input class="flat" type="text" size="1" name="search_frequency" value="'.dol_escape_htmltag($search_frequency).'">';
  576. print '</td>';
  577. }
  578. if (!empty($arrayfields['f.unit_frequency']['checked'])) {
  579. // Frequency unit
  580. print '<td class="liste_titre center">';
  581. print '<input class="flat" type="text" size="1" name="search_unit_frequency" value="'.dol_escape_htmltag($search_unit_frequency).'">';
  582. print '</td>';
  583. }
  584. if (!empty($arrayfields['f.nb_gen_done']['checked'])) {
  585. // Nb generation
  586. print '<td class="liste_titre" align="center">';
  587. print '<input class="flat" type="text" size="1" name="search_nb_gen_done" value="'.dol_escape_htmltag($search_nb_gen_done).'">';
  588. print '</td>';
  589. }
  590. // Date invoice
  591. if (!empty($arrayfields['f.date_last_gen']['checked'])) {
  592. print '<td class="liste_titre center">';
  593. print '<div class="nowrapfordate">';
  594. print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  595. print '</div>';
  596. print '<div class="nowrapfordate">';
  597. print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  598. print '</div>';
  599. print '</td>';
  600. }
  601. // Date next generation
  602. if (!empty($arrayfields['f.date_when']['checked'])) {
  603. print '<td class="liste_titre center">';
  604. print '<div class="nowrapfordate">';
  605. print $form->selectDate($search_date_when_start ? $search_date_when_start : -1, 'search_date_when_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  606. print '</div>';
  607. print '<div class="nowrapfordate">';
  608. print $form->selectDate($search_date_when_end ? $search_date_when_end : -1, 'search_date_when_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  609. print '</div>';
  610. print '</td>';
  611. }
  612. // Extra fields
  613. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  614. // Fields from hook
  615. $parameters = array('arrayfields'=>$arrayfields);
  616. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  617. print $hookmanager->resPrint;
  618. // User creation
  619. if (!empty($arrayfields['f.fk_user_author']['checked'])) {
  620. print '<td class="liste_titre">';
  621. print '</td>';
  622. }
  623. // User modification
  624. if (!empty($arrayfields['f.fk_user_modif']['checked'])) {
  625. print '<td class="liste_titre">';
  626. print '</td>';
  627. }
  628. // Date creation
  629. if (!empty($arrayfields['f.datec']['checked'])) {
  630. print '<td class="liste_titre">';
  631. print '</td>';
  632. }
  633. // Date modification
  634. if (!empty($arrayfields['f.tms']['checked'])) {
  635. print '<td class="liste_titre">';
  636. print '</td>';
  637. }
  638. // Status
  639. if (!empty($arrayfields['status']['checked'])) {
  640. print '<td class="liste_titre center minwidth75imp parentonrightofpage">';
  641. $liststatus = array(
  642. 0=>$langs->trans("Draft"),
  643. 1=>$langs->trans("Active"),
  644. -1=>$langs->trans("Disabled"),
  645. );
  646. print $form->selectarray('search_status', $liststatus, $search_status, -2, 0, 0, '', 0, 0, 0, '', 'width100 onrightofpage');
  647. print '</td>';
  648. }
  649. // Action column
  650. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  651. print '<td class="liste_titre maxwidthsearch center">';
  652. $searchpicto = $form->showFilterButtons();
  653. print $searchpicto;
  654. print '</td>';
  655. }
  656. print '</tr>'."\n";
  657. $totalarray = array();
  658. $totalarray['nbfield'] = 0;
  659. // Fields title label
  660. // --------------------------------------------------------------------
  661. print '<tr class="liste_titre">';
  662. // Action column
  663. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  664. print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  665. $totalarray['nbfield']++;
  666. }
  667. if (!empty($arrayfields['f.titre']['checked'])) {
  668. print_liste_field_titre($arrayfields['f.titre']['label'], $_SERVER['PHP_SELF'], "f.titre", "", $param, "", $sortfield, $sortorder);
  669. $totalarray['nbfield']++;
  670. }
  671. if (!empty($arrayfields['s.nom']['checked'])) {
  672. print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER['PHP_SELF'], "s.nom", "", $param, "", $sortfield, $sortorder);
  673. $totalarray['nbfield']++;
  674. }
  675. if (!empty($arrayfields['f.total_ht']['checked'])) {
  676. print_liste_field_titre($arrayfields['f.total_ht']['label'], $_SERVER['PHP_SELF'], "f.total_ht", "", $param, '', $sortfield, $sortorder, 'right ');
  677. $totalarray['nbfield']++;
  678. }
  679. if (!empty($arrayfields['f.total_tva']['checked'])) {
  680. print_liste_field_titre($arrayfields['f.total_tva']['label'], $_SERVER['PHP_SELF'], "f.total_tva", "", $param, '', $sortfield, $sortorder, 'right ');
  681. $totalarray['nbfield']++;
  682. }
  683. if (!empty($arrayfields['f.total_ttc']['checked'])) {
  684. print_liste_field_titre($arrayfields['f.total_ttc']['label'], $_SERVER['PHP_SELF'], "f.total_ttc", "", $param, '', $sortfield, $sortorder, 'right ');
  685. $totalarray['nbfield']++;
  686. }
  687. if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
  688. print_liste_field_titre($arrayfields['f.fk_cond_reglement']['label'], $_SERVER['PHP_SELF'], "f.fk_cond_reglement", "", $param, '', $sortfield, $sortorder);
  689. $totalarray['nbfield']++;
  690. }
  691. if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
  692. print_liste_field_titre($arrayfields['f.fk_mode_reglement']['label'], $_SERVER['PHP_SELF'], "f.fk_mode_reglement", "", $param, '', $sortfield, $sortorder);
  693. $totalarray['nbfield']++;
  694. }
  695. if (!empty($arrayfields['recurring']['checked'])) {
  696. print_liste_field_titre($arrayfields['recurring']['label'], $_SERVER['PHP_SELF'], "recurring", "", $param, '', $sortfield, $sortorder, 'center ');
  697. $totalarray['nbfield']++;
  698. }
  699. if (!empty($arrayfields['f.frequency']['checked'])) {
  700. print_liste_field_titre($arrayfields['f.frequency']['label'], $_SERVER['PHP_SELF'], "f.frequency", "", $param, '', $sortfield, $sortorder, 'center ');
  701. $totalarray['nbfield']++;
  702. }
  703. if (!empty($arrayfields['f.unit_frequency']['checked'])) {
  704. print_liste_field_titre($arrayfields['f.unit_frequency']['label'], $_SERVER['PHP_SELF'], "f.unit_frequency", "", $param, '', $sortfield, $sortorder, 'center ');
  705. $totalarray['nbfield']++;
  706. }
  707. if (!empty($arrayfields['f.nb_gen_done']['checked'])) {
  708. print_liste_field_titre($arrayfields['f.nb_gen_done']['label'], $_SERVER['PHP_SELF'], "f.nb_gen_done", "", $param, '', $sortfield, $sortorder, 'center ');
  709. $totalarray['nbfield']++;
  710. }
  711. if (!empty($arrayfields['f.date_last_gen']['checked'])) {
  712. print_liste_field_titre($arrayfields['f.date_last_gen']['label'], $_SERVER['PHP_SELF'], "f.date_last_gen", "", $param, '', $sortfield, $sortorder, 'center ');
  713. $totalarray['nbfield']++;
  714. }
  715. if (!empty($arrayfields['f.date_when']['checked'])) {
  716. print_liste_field_titre($arrayfields['f.date_when']['label'], $_SERVER['PHP_SELF'], "f.date_when", "", $param, '', $sortfield, $sortorder, 'center ');
  717. $totalarray['nbfield']++;
  718. }
  719. if (!empty($arrayfields['f.fk_user_author']['checked'])) {
  720. print_liste_field_titre($arrayfields['f.fk_user_author']['label'], $_SERVER['PHP_SELF'], "f.fk_user_author", "", $param, '', $sortfield, $sortorder, 'center ');
  721. $totalarray['nbfield']++;
  722. }
  723. if (!empty($arrayfields['f.fk_user_modif']['checked'])) {
  724. print_liste_field_titre($arrayfields['f.fk_user_modif']['label'], $_SERVER['PHP_SELF'], "f.fk_user_modif", "", $param, '', $sortfield, $sortorder, 'center ');
  725. $totalarray['nbfield']++;
  726. }
  727. if (!empty($arrayfields['f.datec']['checked'])) {
  728. print_liste_field_titre($arrayfields['f.datec']['label'], $_SERVER['PHP_SELF'], "f.datec", "", $param, '', $sortfield, $sortorder, 'center ');
  729. $totalarray['nbfield']++;
  730. }
  731. if (!empty($arrayfields['f.tms']['checked'])) {
  732. print_liste_field_titre($arrayfields['f.tms']['label'], $_SERVER['PHP_SELF'], "f.tms", "", $param, '', $sortfield, $sortorder, 'center ');
  733. $totalarray['nbfield']++;
  734. }
  735. // Extra fields
  736. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  737. if (!empty($arrayfields['status']['checked'])) {
  738. print_liste_field_titre($arrayfields['status']['label'], $_SERVER['PHP_SELF'], "f.suspended,f.frequency", "", $param, '', $sortfield, $sortorder, 'center ');
  739. $totalarray['nbfield']++;
  740. }
  741. // Action column
  742. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  743. print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  744. $totalarray['nbfield']++;
  745. }
  746. print '</tr>'."\n";
  747. $i = 0;
  748. $savnbfield = $totalarray['nbfield'];
  749. $totalarray = array();
  750. $totalarray['nbfield'] = 0;
  751. $totalarray['val']['f.total_ht'] = 0;
  752. $totalarray['val']['f.total_tva'] = 0;
  753. $totalarray['val']['f.total_ttc'] = 0;
  754. $imaxinloop = ($limit ? min($num, $limit) : $num);
  755. while ($i < $imaxinloop) {
  756. $objp = $db->fetch_object($resql);
  757. if (empty($objp)) {
  758. break;
  759. }
  760. $companystatic->id = $objp->socid;
  761. $companystatic->name = $objp->name;
  762. $supplierinvoicerectmp->id = !empty($objp->id) ? $objp->id : $objp->facid;
  763. $supplierinvoicerectmp->frequency = $objp->frequency;
  764. $supplierinvoicerectmp->suspended = $objp->suspended;
  765. $supplierinvoicerectmp->unit_frequency = $objp->unit_frequency;
  766. $supplierinvoicerectmp->nb_gen_max = $objp->nb_gen_max;
  767. $supplierinvoicerectmp->nb_gen_done = $objp->nb_gen_done;
  768. $supplierinvoicerectmp->ref = $objp->title;
  769. $supplierinvoicerectmp->total_ht = $objp->total_ht;
  770. $supplierinvoicerectmp->total_tva = $objp->total_tva;
  771. $supplierinvoicerectmp->total_ttc = $objp->total_ttc;
  772. // Show here line of result
  773. $j = 0;
  774. print '<tr data-rowid="'.$object->id.'" class="oddeven">';
  775. // Action column
  776. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  777. print '<td class="center tdoverflowmax125">';
  778. if ($user->hasRight('facture', 'creer') && empty($supplierinvoicerectmp->suspended)) {
  779. if ($supplierinvoicerectmp->isMaxNbGenReached()) {
  780. print $langs->trans("MaxNumberOfGenerationReached");
  781. } elseif (empty($objp->frequency) || $db->jdate($objp->date_when) <= $today) {
  782. print '<a href="'.DOL_URL_ROOT.'/fourn/facture/card.php?action=create&amp;socid='.$objp->socid.'&amp;fac_rec='.$objp->facid.'">';
  783. print img_picto($langs->trans("CreateBill"), 'add', 'class="paddingrightonly"');
  784. print $langs->trans("CreateBill").'</a>';
  785. } else {
  786. print $form->textwithpicto('', $langs->trans("DateIsNotEnough"));
  787. }
  788. }
  789. print "</td>";
  790. if (!$i) {
  791. $totalarray['nbfield']++;
  792. }
  793. }
  794. if (!empty($arrayfields['f.titre']['checked'])) {
  795. print '<td class="nowrap tdoverflowmax200">';
  796. print $supplierinvoicerectmp->getNomUrl(1);
  797. print "</td>\n";
  798. if (!$i) {
  799. $totalarray['nbfield']++;
  800. }
  801. }
  802. if (!empty($arrayfields['s.nom']['checked'])) {
  803. print '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'supplier').'</td>';
  804. if (!$i) {
  805. $totalarray['nbfield']++;
  806. }
  807. }
  808. if (!empty($arrayfields['f.total_ht']['checked'])) {
  809. print '<td class="nowrap right amount">'.price($objp->total_ht).'</td>'."\n";
  810. if (!$i) {
  811. $totalarray['nbfield']++;
  812. }
  813. if (!$i) {
  814. $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ht';
  815. }
  816. $totalarray['val']['f.total_ht'] += $objp->total_ht;
  817. }
  818. if (!empty($arrayfields['f.total_tva']['checked'])) {
  819. print '<td class="nowrap right amount">'.price($objp->total_tva).'</td>'."\n";
  820. if (!$i) {
  821. $totalarray['nbfield']++;
  822. }
  823. if (!$i) {
  824. $totalarray['pos'][$totalarray['nbfield']] = 'f.total_tva';
  825. }
  826. $totalarray['val']['f.total_tva'] += $objp->total_tva;
  827. }
  828. if (!empty($arrayfields['f.total_ttc']['checked'])) {
  829. print '<td class="nowrap right amount">'.price($objp->total_ttc).'</td>'."\n";
  830. if (!$i) {
  831. $totalarray['nbfield']++;
  832. }
  833. if (!$i) {
  834. $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ttc';
  835. }
  836. $totalarray['val']['f.total_ttc'] += $objp->total_ttc;
  837. }
  838. // Payment term
  839. if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
  840. print '<td class="tdoverflowmax150">';
  841. $form->form_conditions_reglement('', $objp->fk_cond_reglement, 'none');
  842. print '</td>'."\n";
  843. if (!$i) {
  844. $totalarray['nbfield']++;
  845. }
  846. }
  847. // Payment mode
  848. if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
  849. print '<td class="tdoverflowmax150">';
  850. $form->form_modes_reglement('', $objp->fk_mode_reglement, 'none');
  851. print '</td>'."\n";
  852. if (!$i) {
  853. $totalarray['nbfield']++;
  854. }
  855. }
  856. // Is it a recurring invoice
  857. if (!empty($arrayfields['recurring']['checked'])) {
  858. print '<td class="center">'.($objp->frequency ? img_picto($langs->trans("Frequency").': '.$objp->frequency.' '.$objp->unit_frequency, 'recurring', 'class="opacitymedium"').' ' : '').yn($objp->frequency ? 1 : 0).'</td>';
  859. if (!$i) {
  860. $totalarray['nbfield']++;
  861. }
  862. }
  863. if (!empty($arrayfields['f.frequency']['checked'])) {
  864. print '<td class="center">';
  865. print($objp->frequency > 0 ? $objp->frequency : '');
  866. print '</td>';
  867. if (!$i) {
  868. $totalarray['nbfield']++;
  869. }
  870. }
  871. if (!empty($arrayfields['f.unit_frequency']['checked'])) {
  872. print '<td class="center">';
  873. if ($objp->frequency > 1) {
  874. $dur = array("i"=>$langs->trans("Minutes"), "h"=>$langs->trans("Hours"), "d"=>$langs->trans("Days"), "w"=>$langs->trans("Weeks"), "m"=>$langs->trans("Months"), "y"=>$langs->trans("Years"));
  875. } else {
  876. $dur = array("i"=>$langs->trans("Minute"), "h"=>$langs->trans("Hour"), "d"=>$langs->trans("Day"), "w"=>$langs->trans("Week"), "m"=>$langs->trans("Month"), "y"=>$langs->trans("Year"));
  877. }
  878. print($objp->frequency > 0 ? $dur[$objp->unit_frequency] : '');
  879. print '</td>';
  880. if (!$i) {
  881. $totalarray['nbfield']++;
  882. }
  883. }
  884. if (!empty($arrayfields['f.nb_gen_done']['checked'])) {
  885. print '<td class="center">';
  886. print($objp->frequency > 0 ? $objp->nb_gen_done.($objp->nb_gen_max > 0 ? ' / '.$objp->nb_gen_max : '') : '<span class="opacitymedium">'.$langs->trans('NA').'</span>');
  887. print '</td>';
  888. if (!$i) {
  889. $totalarray['nbfield']++;
  890. }
  891. }
  892. // Date last generation
  893. if (!empty($arrayfields['f.date_last_gen']['checked'])) {
  894. print '<td class="center">';
  895. print($objp->frequency > 0 ? dol_print_date($db->jdate($objp->date_last_gen), 'day') : '<span class="opacitymedium">'.$langs->trans('NA').'</span>');
  896. print '</td>';
  897. if (!$i) {
  898. $totalarray['nbfield']++;
  899. }
  900. }
  901. // Date next generation
  902. if (!empty($arrayfields['f.date_when']['checked'])) {
  903. print '<td class="center">';
  904. print '<div class="nowraponall">';
  905. print($objp->frequency ? ($supplierinvoicerectmp->isMaxNbGenReached() ? '<strike>' : '').dol_print_date($db->jdate($objp->date_when), 'day').($supplierinvoicerectmp->isMaxNbGenReached() ? '</strike>' : '') : '<span class="opacitymedium">'.$langs->trans('NA').'</span>');
  906. if (!$supplierinvoicerectmp->isMaxNbGenReached()) {
  907. if (!$objp->suspended && $objp->frequency > 0 && $db->jdate($objp->date_when) && $db->jdate($objp->date_when) < $now) {
  908. print img_warning($langs->trans("Late"));
  909. }
  910. } else {
  911. print img_info($langs->trans("MaxNumberOfGenerationReached"));
  912. }
  913. print '</div>';
  914. print '</td>';
  915. if (!$i) {
  916. $totalarray['nbfield']++;
  917. }
  918. }
  919. if (!empty($arrayfields['f.fk_user_author']['checked'])) {
  920. print '<td class="center tdoverflowmax150">';
  921. if ($objp->fk_user_author > 0) {
  922. $tmpuser->fetch($objp->fk_user_author);
  923. print $tmpuser->getNomUrl(1);
  924. }
  925. print '</td>';
  926. if (!$i) {
  927. $totalarray['nbfield']++;
  928. }
  929. }
  930. if (!empty($arrayfields['f.fk_user_modif']['checked'])) {
  931. print '<td class="center tdoverflowmax150">';
  932. if ($objp->fk_user_author > 0) {
  933. $tmpuser->fetch($objp->fk_user_author);
  934. print $tmpuser->getNomUrl(1);
  935. }
  936. print '</td>';
  937. if (!$i) {
  938. $totalarray['nbfield']++;
  939. }
  940. }
  941. if (!empty($arrayfields['f.datec']['checked'])) {
  942. print '<td class="center nowraponall">';
  943. print dol_print_date($db->jdate($objp->datec), 'dayhour');
  944. print '</td>';
  945. if (!$i) {
  946. $totalarray['nbfield']++;
  947. }
  948. }
  949. if (!empty($arrayfields['f.tms']['checked'])) {
  950. print '<td class="center nowraponall">';
  951. print dol_print_date($db->jdate($objp->tms), 'dayhour');
  952. print '</td>';
  953. if (!$i) {
  954. $totalarray['nbfield']++;
  955. }
  956. }
  957. $obj = $objp;
  958. // Extra fields
  959. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  960. // Fields from hook
  961. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  962. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  963. print $hookmanager->resPrint;
  964. // Status
  965. if (!empty($arrayfields['status']['checked'])) {
  966. print '<td class="center">';
  967. print $supplierinvoicerectmp->getLibStatut(5, 0);
  968. print '</td>';
  969. if (!$i) {
  970. $totalarray['nbfield']++;
  971. }
  972. }
  973. // Action column
  974. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  975. print '<td class="nowrap center tdoverflowmax125">';
  976. if ($user->hasRight('facture', 'creer') && empty($supplierinvoicerectmp->suspended)) {
  977. if ($supplierinvoicerectmp->isMaxNbGenReached()) {
  978. print $langs->trans("MaxNumberOfGenerationReached");
  979. } elseif (empty($objp->frequency) || $db->jdate($objp->date_when) <= $today) {
  980. print '<a href="'.DOL_URL_ROOT.'/fourn/facture/card.php?action=create&amp;socid='.$objp->socid.'&amp;fac_rec='.$objp->facid.'">';
  981. print img_picto($langs->trans("CreateBill"), 'add', 'class="paddingrightonly"');
  982. print $langs->trans("CreateBill").'</a>';
  983. } else {
  984. print $form->textwithpicto('', $langs->trans("DateIsNotEnough"));
  985. }
  986. }
  987. print '</td>';
  988. if (!$i) {
  989. $totalarray['nbfield']++;
  990. }
  991. }
  992. print '</tr>'."\n";
  993. $i++;
  994. }
  995. // Show total line
  996. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  997. // If no record found
  998. if ($num == 0) {
  999. $colspan = 1;
  1000. foreach ($arrayfields as $key => $val) {
  1001. if (!empty($val['checked'])) {
  1002. $colspan++;
  1003. }
  1004. }
  1005. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  1006. }
  1007. $db->free($resql);
  1008. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  1009. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1010. print $hookmanager->resPrint;
  1011. print '</table>'."\n";
  1012. print '</div>'."\n";
  1013. print '</form>'."\n";
  1014. // End of page
  1015. llxFooter();
  1016. $db->close();