invoicetemplate_list.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  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@capnetworks.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 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
  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 <http://www.gnu.org/licenses/>.
  24. */
  25. /**
  26. * \file htdocs/compta/facture/invoicetemplate_list.php
  27. * \ingroup facture
  28. * \brief Page to show list of template/recurring invoices
  29. */
  30. require '../../main.inc.php';
  31. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  34. if (! empty($conf->projet->enabled)) {
  35. require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
  36. //require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
  37. }
  38. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
  39. require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
  40. require_once DOL_DOCUMENT_ROOT . '/core/lib/invoice.lib.php';
  41. require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
  42. $langs->load('bills');
  43. $langs->load('compta');
  44. $langs->load('admin');
  45. $langs->load('other');
  46. $action = GETPOST('action','alpha');
  47. $massaction = GETPOST('massaction','alpha');
  48. $show_files = GETPOST('show_files','int');
  49. $confirm = GETPOST('confirm','alpha');
  50. $cancel = GETPOST('cancel', 'alpha');
  51. $toselect = GETPOST('toselect', 'array');
  52. $contextpage= GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'invoicetemplatelist'; // To manage different context of search
  53. // Security check
  54. $id=(GETPOST('facid','int')?GETPOST('facid','int'):GETPOST('id','int'));
  55. $lineid=GETPOST('lineid','int');
  56. $ref=GETPOST('ref','alpha');
  57. if ($user->societe_id) $socid=$user->societe_id;
  58. $objecttype = 'facture_rec';
  59. if ($action == "create" || $action == "add") $objecttype = '';
  60. $result = restrictedArea($user, 'facture', $id, $objecttype);
  61. $projectid = GETPOST('projectid','int');
  62. $search_ref=GETPOST('search_ref');
  63. $search_societe=GETPOST('search_societe');
  64. $search_montant_ht=GETPOST('search_montant_ht');
  65. $search_montant_vat=GETPOST('search_montant_vat');
  66. $search_montant_ttc=GETPOST('search_montant_ttc');
  67. $search_payment_mode=GETPOST('search_payment_mode');
  68. $search_payment_term=GETPOST('search_payment_term');
  69. $search_day=GETPOST('search_day','int');
  70. $search_year=GETPOST('search_year','int');
  71. $search_month=GETPOST('search_month','int');
  72. $search_day_date_when=GETPOST('search_day_date_when','int');
  73. $search_year_date_when=GETPOST('search_year_date_when','int');
  74. $search_month_date_when=GETPOST('search_month_date_when','int');
  75. $search_recurring=GETPOST('search_recurring','int');
  76. $search_frequency=GETPOST('search_frequency','alpha');
  77. $search_unit_frequency=GETPOST('search_unit_frequency','alpha');
  78. $search_status=GETPOST('search_status','int');
  79. $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
  80. $sortfield = GETPOST("sortfield",'alpha');
  81. $sortorder = GETPOST("sortorder",'alpha');
  82. $page = GETPOST("page",'int');
  83. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  84. $offset = $limit * $page;
  85. if (! $sortorder) $sortorder='DESC';
  86. if (! $sortfield) $sortfield='f.titre';
  87. $pageprev = $page - 1;
  88. $pagenext = $page + 1;
  89. $object = new FactureRec($db);
  90. if (($id > 0 || $ref) && $action != 'create' && $action != 'add')
  91. {
  92. $ret = $object->fetch($id, $ref);
  93. if (!$ret)
  94. {
  95. setEventMessages($langs->trans("ErrorRecordNotFound"), null, 'errors');
  96. }
  97. }
  98. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  99. $hookmanager->initHooks(array('invoicereccard','globalcard'));
  100. $extrafields = new ExtraFields($db);
  101. // fetch optionals attributes and labels
  102. $extralabels = $extrafields->fetch_name_optionals_label('facture_rec');
  103. $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
  104. $permissionnote = $user->rights->facture->creer; // Used by the include of actions_setnotes.inc.php
  105. $permissiondellink=$user->rights->facture->creer; // Used by the include of actions_dellink.inc.php
  106. $permissiontoedit = $user->rights->facture->creer; // Used by the include of actions_lineupdonw.inc.php
  107. $arrayfields=array(
  108. 'f.titre'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
  109. 's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
  110. 'f.total'=>array('label'=>$langs->trans("AmountHT"), 'checked'=>1),
  111. 'f.tva'=>array('label'=>$langs->trans("AmountVAT"), 'checked'=>1),
  112. 'f.total_ttc'=>array('label'=>$langs->trans("AmountTTC"), 'checked'=>1),
  113. 'f.fk_mode_reglement'=>array('label'=>$langs->trans("PaymentMode"), 'checked'=>0),
  114. 'f.fk_cond_reglement'=>array('label'=>$langs->trans("PaymentTerm"), 'checked'=>0),
  115. 'recurring'=>array('label'=>$langs->trans("RecurringInvoiceTemplate"), 'checked'=>1),
  116. 'f.frequency'=>array('label'=>$langs->trans("Frequency"), 'checked'=>1),
  117. 'f.unit_frequency'=>array('label'=>$langs->trans("FrequencyUnit"), 'checked'=>1),
  118. 'f.nb_gen_done'=>array('label'=>$langs->trans("NbOfGenerationDoneShort"), 'checked'=>1),
  119. 'f.date_last_gen'=>array('label'=>$langs->trans("DateLastGenerationShort"), 'checked'=>1),
  120. 'f.date_when'=>array('label'=>$langs->trans("NextDateToExecutionShort"), 'checked'=>1),
  121. 'status'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>100),
  122. 'f.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
  123. 'f.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
  124. );
  125. // Extra fields
  126. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  127. {
  128. foreach($extrafields->attribute_label as $key => $val)
  129. {
  130. if (! empty($extrafields->attribute_list[$key])) $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>(($extrafields->attribute_list[$key]<0)?0:1), 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>(abs($extrafields->attribute_list[$key])!=3 && $extrafields->attribute_perms[$key]));
  131. }
  132. }
  133. /*
  134. * Actions
  135. */
  136. if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
  137. if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
  138. $parameters = array('socid' => $socid);
  139. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  140. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  141. if (empty($reshook))
  142. {
  143. if (GETPOST('cancel','alpha')) $action='';
  144. // Selection of new fields
  145. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  146. // Do we click on purge search criteria ?
  147. 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
  148. {
  149. $search_ref='';
  150. $search_societe='';
  151. $search_montant_ht='';
  152. $search_montant_vat='';
  153. $search_montant_ttc='';
  154. $search_payment_mode='';
  155. $search_payment_term='';
  156. $search_day='';
  157. $search_year='';
  158. $search_month='';
  159. $search_day_date_when='';
  160. $search_year_date_when='';
  161. $search_month_date_when='';
  162. $search_recurring='';
  163. $search_frequency='';
  164. $search_unit_frequency='';
  165. $search_status='';
  166. $search_array_options=array();
  167. }
  168. // Mass actions
  169. /*$objectclass='MyObject';
  170. $objectlabel='MyObject';
  171. $permtoread = $user->rights->mymodule->read;
  172. $permtodelete = $user->rights->mymodule->delete;
  173. $uploaddir = $conf->mymodule->dir_output;
  174. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';*/
  175. }
  176. /*
  177. * View
  178. */
  179. llxHeader('',$langs->trans("RepeatableInvoices"),'ch-facture.html#s-fac-facture-rec');
  180. $form = new Form($db);
  181. $formother = new FormOther($db);
  182. if (! empty($conf->projet->enabled)) { $formproject = new FormProjets($db); }
  183. $companystatic = new Societe($db);
  184. $invoicerectmp = new FactureRec($db);
  185. $now = dol_now();
  186. $tmparray=dol_getdate($now);
  187. $today = dol_mktime(23,59,59,$tmparray['mon'],$tmparray['mday'],$tmparray['year']); // Today is last second of current day
  188. /*
  189. * List mode
  190. */
  191. $sql = "SELECT s.nom as name, s.rowid as socid, f.rowid as facid, f.titre, f.total, f.tva as total_vat, f.total_ttc, f.frequency, f.unit_frequency,";
  192. $sql.= " f.nb_gen_done, f.nb_gen_max, f.date_last_gen, f.date_when, f.suspended,";
  193. $sql.= " f.datec, f.tms,";
  194. $sql.= " f.fk_cond_reglement, f.fk_mode_reglement";
  195. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_rec as f";
  196. if (! $user->rights->societe->client->voir && ! $socid) {
  197. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  198. }
  199. $sql.= " WHERE f.fk_soc = s.rowid";
  200. $sql.= ' AND f.entity IN ('.getEntity('facture').')';
  201. if (! $user->rights->societe->client->voir && ! $socid) {
  202. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
  203. }
  204. if ($search_ref) $sql .= natural_search('f.titre', $search_ref);
  205. if ($search_societe) $sql .= natural_search('s.nom', $search_societe);
  206. if ($search_montant_ht != '') $sql .= natural_search('f.total', $search_montant_ht, 1);
  207. if ($search_montant_vat != '') $sql .= natural_search('f.tva', $search_montant_vat, 1);
  208. if ($search_montant_ttc != '') $sql .= natural_search('f.total_ttc', $search_montant_ttc, 1);
  209. if (! empty($search_payment_mode) && $search_payment_mode != '-1') $sql .= natural_search('f.fk_mode_reglement', $search_payment_mode, 1);
  210. if (! empty($search_payment_term) && $search_payment_term != '-1') $sql .= natural_search('f.fk_cond_reglement', $search_payment_term, 1);
  211. if ($search_recurring == '1') $sql .= ' AND f.frequency > 0';
  212. if ($search_recurring == '0') $sql .= ' AND (f.frequency IS NULL or f.frequency = 0)';
  213. if ($search_frequency != '') $sql .= natural_search('f.frequency', $search_frequency, 1);
  214. if ($search_unit_frequency != '') $sql .= ' AND f.frequency > 0'.natural_search('f.unit_frequency', $search_unit_frequency);
  215. if ($search_status != '' && $search_status >= -1)
  216. {
  217. if ($search_status == 0) $sql.= ' AND frequency = 0 AND suspended = 0';
  218. if ($search_status == 1) $sql.= ' AND frequency != 0 AND suspended = 0';
  219. if ($search_status == -1) $sql.= ' AND suspended = 1';
  220. }
  221. if ($search_month > 0)
  222. {
  223. if ($search_year > 0 && empty($search_day))
  224. $sql.= " AND f.date_last_gen BETWEEN '".$db->idate(dol_get_first_day($search_year,$search_month,false))."' AND '".$db->idate(dol_get_last_day($search_year,$search_month,false))."'";
  225. else if ($search_year > 0 && ! empty($search_day))
  226. $sql.= " AND f.date_last_gen 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.date_last_gen, '%m') = '".$db->escape($search_month)."'";
  229. }
  230. else if ($search_year > 0)
  231. {
  232. $sql.= " AND f.date_last_gen 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 ($search_month_date_when > 0)
  235. {
  236. if ($search_year_date_when > 0 && empty($search_day_date_when))
  237. $sql.= " AND f.date_when BETWEEN '".$db->idate(dol_get_first_day($search_year_date_when,$search_month_date_when,false))."' AND '".$db->idate(dol_get_last_day($search_year_date_when,$search_month_date_when,false))."'";
  238. else if ($search_year_date_when > 0 && ! empty($search_day_date_when))
  239. $sql.= " AND f.date_date_when_reglement BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $search_month_date_when, $search_day_date_when, $search_year_date_when))."' AND '".$db->idate(dol_mktime(23, 59, 59, $search_month_date_when, $search_day_date_when, $search_year_date_when))."'";
  240. else
  241. $sql.= " AND date_format(f.date_when, '%m') = '".$db->escape($search_month_date_when)."'";
  242. }
  243. else if ($search_year_date_when > 0)
  244. {
  245. $sql.= " AND f.date_when BETWEEN '".$db->idate(dol_get_first_day($search_year_date_when,1,false))."' AND '".$db->idate(dol_get_last_day($search_year_date_when,12,false))."'";
  246. }
  247. $nbtotalofrecords = '';
  248. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  249. {
  250. $result = $db->query($sql);
  251. $nbtotalofrecords = $db->num_rows($result);
  252. }
  253. $sql.= $db->order($sortfield, $sortorder);
  254. $sql.= $db->plimit($limit+1,$offset);
  255. $resql = $db->query($sql);
  256. if ($resql)
  257. {
  258. $num = $db->num_rows($resql);
  259. $param='';
  260. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
  261. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit);
  262. if ($socid) $param.='&socid='.urlencode($socid);
  263. if ($search_day) $param.='&search_day='.urlencode($search_day);
  264. if ($search_month) $param.='&search_month='.urlencode($search_month);
  265. if ($search_year) $param.='&search_year=' .urlencode($search_year);
  266. if ($search_day_date_when) $param.='&search_day_date_when='.urlencode($search_day_date_when);
  267. if ($search_month_date_when) $param.='&search_month_date_when='.urlencode($search_month_date_when);
  268. if ($search_year_date_when) $param.='&search_year_date_when=' .urlencode($search_year_date_when);
  269. if ($search_ref) $param.='&search_ref=' .urlencode($search_ref);
  270. if ($search_societe) $param.='&search_societe=' .urlencode($search_societe);
  271. if ($search_montant_ht != '') $param.='&search_montant_ht=' .urlencode($search_montant_ht);
  272. if ($search_montant_vat != '') $param.='&search_montant_vat='.urlencode($search_montant_vat);
  273. if ($search_montant_ttc != '') $param.='&search_montant_ttc='.urlencode($search_montant_ttc);
  274. if ($search_payment_mode != '') $param.='&search_payment_mode='.urlencode($search_payment_mode);
  275. if ($search_payment_type != '') $param.='&search_payment_type='.urlencode($search_payment_type);
  276. if ($search_recurring != '' && $search_recurrning != '-1') $param.='&search_recurring=' .urlencode($search_recurring);
  277. if ($search_frequency > 0) $param.='&search_frequency=' .urlencode($search_frequency);
  278. if ($search_unit_frequency != '') $param.='&search_unit_frequency='.urlencode($search_unit_frequency);
  279. if ($search_status != '') $param.='&search_status='.urlencode($search_status);
  280. if ($option) $param.="&option=".urlencode($option);
  281. if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss);
  282. // Add $param from extra fields
  283. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  284. $massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge")));
  285. $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
  286. $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  287. //$selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
  288. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  289. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  290. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  291. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  292. print '<input type="hidden" name="action" value="list">';
  293. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  294. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  295. print '<input type="hidden" name="page" value="'.$page.'">';
  296. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  297. print '<input type="hidden" name="viewstatut" value="'.$viewstatut.'">';
  298. print_barre_liste($langs->trans("RepeatableInvoices"),$page,$_SERVER['PHP_SELF'],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecords,'title_accountancy.png',0,'','', $limit);
  299. print $langs->trans("ToCreateAPredefinedInvoice", $langs->transnoentitiesnoconv("ChangeIntoRepeatableInvoice")).'<br><br>';
  300. $i = 0;
  301. print '<div class="div-table-responsive">';
  302. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  303. // Filters lines
  304. print '<tr class="liste_titre_filter">';
  305. // Ref
  306. if (! empty($arrayfields['f.titre']['checked']))
  307. {
  308. print '<td class="liste_titre" align="left">';
  309. print '<input class="flat" size="6" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
  310. print '</td>';
  311. }
  312. // Thirpdarty
  313. if (! empty($arrayfields['s.nom']['checked']))
  314. {
  315. print '<td class="liste_titre" align="left"><input class="flat" type="text" size="8" name="search_societe" value="'.dol_escape_htmltag($search_societe).'"></td>';
  316. }
  317. if (! empty($arrayfields['f.total']['checked']))
  318. {
  319. // Amount net
  320. print '<td class="liste_titre" align="right">';
  321. print '<input class="flat" type="text" size="5" name="search_montant_ht" value="'.dol_escape_htmltag($search_montant_ht).'">';
  322. print '</td>';
  323. }
  324. if (! empty($arrayfields['f.tva']['checked']))
  325. {
  326. // Amount Vat
  327. print '<td class="liste_titre" align="right">';
  328. print '<input class="flat" type="text" size="5" name="search_montant_vat" value="'.dol_escape_htmltag($search_montant_vat).'">';
  329. print '</td>';
  330. }
  331. if (! empty($arrayfields['f.total_ttc']['checked']))
  332. {
  333. // Amount
  334. print '<td class="liste_titre" align="right">';
  335. print '<input class="flat" type="text" size="5" name="search_montant_ttc" value="'.dol_escape_htmltag($search_montant_ttc).'">';
  336. print '</td>';
  337. }
  338. if (! empty($arrayfields['f.fk_cond_reglement']['checked']))
  339. {
  340. // Payment term
  341. print '<td class="liste_titre" align="right">';
  342. print $form->select_conditions_paiements($search_payment_term, 'search_payment_term', -1, 1, 1, 'maxwidth100');
  343. print "</td>";
  344. }
  345. if (! empty($arrayfields['f.fk_mode_reglement']['checked']))
  346. {
  347. // Payment mode
  348. print '<td class="liste_titre" align="right">';
  349. print $form->select_types_paiements($search_payment_mode, 'search_payment_mode', '', 0, 1, 1, 0, 1, 'maxwidth100');
  350. print '</td>';
  351. }
  352. if (! empty($arrayfields['recurring']['checked']))
  353. {
  354. // Recurring or not
  355. print '<td class="liste_titre" align="center">';
  356. print $form->selectyesno('search_recurring', $search_recurring, 1, false, 1);
  357. print '</td>';
  358. }
  359. if (! empty($arrayfields['f.frequency']['checked']))
  360. {
  361. // Recurring or not
  362. print '<td class="liste_titre" align="center">';
  363. print '<input class="flat" type="text" size="1" name="search_frequency" value="'.dol_escape_htmltag($search_frequency).'">';
  364. print '</td>';
  365. }
  366. if (! empty($arrayfields['f.unit_frequency']['checked']))
  367. {
  368. // Frequency unit
  369. print '<td class="liste_titre" align="center">';
  370. print '<input class="flat" type="text" size="1" name="search_unit_frequency" value="'.dol_escape_htmltag($search_unit_frequency).'">';
  371. print '</td>';
  372. }
  373. if (! empty($arrayfields['f.nb_gen_done']['checked']))
  374. {
  375. // Nb generation
  376. print '<td class="liste_titre" align="center">';
  377. print '</td>';
  378. }
  379. // Date invoice
  380. if (! empty($arrayfields['f.date_last_gen']['checked']))
  381. {
  382. print '<td class="liste_titre" align="center">';
  383. if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="search_day" value="'.$search_day.'">';
  384. print '<input class="flat" type="text" size="1" maxlength="2" name="search_month" value="'.$search_month.'">';
  385. $formother->select_year($search_year?$search_year:-1,'search_year',1, 20, 5);
  386. print '</td>';
  387. }
  388. // Date next generation
  389. if (! empty($arrayfields['f.date_when']['checked']))
  390. {
  391. print '<td class="liste_titre" align="center">';
  392. if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="search_day_date_when" value="'.$search_day_date_when.'">';
  393. print '<input class="flat" type="text" size="1" maxlength="2" name="search_month_date_when" value="'.$search_month_date_when.'">';
  394. $formother->select_year($search_year_date_when?$search_year_date_when:-1,'search_year_date_when',1, 20, 5);
  395. print '</td>';
  396. }
  397. // Extra fields
  398. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  399. // Fields from hook
  400. $parameters=array('arrayfields'=>$arrayfields);
  401. $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
  402. print $hookmanager->resPrint;
  403. // Date creation
  404. if (! empty($arrayfields['f.datec']['checked']))
  405. {
  406. print '<td class="liste_titre">';
  407. print '</td>';
  408. }
  409. // Date modification
  410. if (! empty($arrayfields['f.tms']['checked']))
  411. {
  412. print '<td class="liste_titre">';
  413. print '</td>';
  414. }
  415. // Status
  416. if (! empty($arrayfields['status']['checked']))
  417. {
  418. print '<td class="liste_titre" align="center">';
  419. $liststatus=array(
  420. 0=>$langs->trans("Draft"),
  421. 1=>$langs->trans("Active"),
  422. -1=>$langs->trans("Disabled"),
  423. );
  424. print $form->selectarray('search_status', $liststatus, $search_status, -2);
  425. print '</td>';
  426. }
  427. // Action column
  428. print '<td class="liste_titre" align="middle">';
  429. $searchpicto=$form->showFilterAndCheckAddButtons(0, 'checkforselect', 1);
  430. print $searchpicto;
  431. print '</td>';
  432. print "</tr>\n";
  433. print '<tr class="liste_titre">';
  434. if (! empty($arrayfields['f.titre']['checked'])) print_liste_field_titre($arrayfields['f.titre']['label'],$_SERVER['PHP_SELF'],"f.titre","",$param,"",$sortfield,$sortorder);
  435. if (! empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'],$_SERVER['PHP_SELF'],"s.nom","",$param,"",$sortfield,$sortorder);
  436. if (! empty($arrayfields['f.total']['checked'])) print_liste_field_titre($arrayfields['f.total']['label'],$_SERVER['PHP_SELF'],"f.total","",$param,'align="right"',$sortfield,$sortorder);
  437. if (! empty($arrayfields['f.tva']['checked'])) print_liste_field_titre($arrayfields['f.tva']['label'],$_SERVER['PHP_SELF'],"f.tva","",$param,'align="right"',$sortfield,$sortorder);
  438. if (! empty($arrayfields['f.total_ttc']['checked'])) print_liste_field_titre($arrayfields['f.total_ttc']['label'],$_SERVER['PHP_SELF'],"f.total_ttc","",$param,'align="right"',$sortfield,$sortorder);
  439. if (! empty($arrayfields['f.fk_cond_reglement']['checked'])) print_liste_field_titre($arrayfields['f.fk_cond_reglement']['label'],$_SERVER['PHP_SELF'],"f.fk_cond_reglement","",$param,'',$sortfield,$sortorder);
  440. if (! empty($arrayfields['f.fk_mode_reglement']['checked'])) print_liste_field_titre($arrayfields['f.fk_mode_reglement']['label'],$_SERVER['PHP_SELF'],"f.fk_mode_reglement","",$param,'',$sortfield,$sortorder);
  441. if (! empty($arrayfields['recurring']['checked'])) print_liste_field_titre($arrayfields['recurring']['label'],$_SERVER['PHP_SELF'],"recurring","",$param,'align="center"',$sortfield,$sortorder);
  442. if (! empty($arrayfields['f.frequency']['checked'])) print_liste_field_titre($arrayfields['f.frequency']['label'],$_SERVER['PHP_SELF'],"f.frequency","",$param,'align="center"',$sortfield,$sortorder);
  443. if (! empty($arrayfields['f.unit_frequency']['checked'])) print_liste_field_titre($arrayfields['f.unit_frequency']['label'],$_SERVER['PHP_SELF'],"f.unit_frequency","",$param,'align="center"',$sortfield,$sortorder);
  444. if (! empty($arrayfields['f.nb_gen_done']['checked'])) print_liste_field_titre($arrayfields['f.nb_gen_done']['label'],$_SERVER['PHP_SELF'],"f.nb_gen_done","",$param,'align="center"',$sortfield,$sortorder);
  445. if (! empty($arrayfields['f.date_last_gen']['checked'])) print_liste_field_titre($arrayfields['f.date_last_gen']['label'],$_SERVER['PHP_SELF'],"f.date_last_gen","",$param,'align="center"',$sortfield,$sortorder);
  446. if (! empty($arrayfields['f.date_when']['checked'])) print_liste_field_titre($arrayfields['f.date_when']['label'],$_SERVER['PHP_SELF'],"f.date_when","",$param,'align="center"',$sortfield,$sortorder);
  447. if (! empty($arrayfields['f.datec']['checked'])) print_liste_field_titre($arrayfields['f.datec']['label'],$_SERVER['PHP_SELF'],"f.datec","",$param,'align="center"',$sortfield,$sortorder);
  448. if (! empty($arrayfields['f.tms']['checked'])) print_liste_field_titre($arrayfields['f.tms']['label'],$_SERVER['PHP_SELF'],"f.tms","",$param,'align="center"',$sortfield,$sortorder);
  449. if (! empty($arrayfields['status']['checked'])) print_liste_field_titre($arrayfields['status']['label'],$_SERVER['PHP_SELF'],"f.suspended,f.frequency","",$param,'align="center"',$sortfield,$sortorder);
  450. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'nomaxwidthsearch ')."\n";
  451. print "</tr>\n";
  452. if ($num > 0)
  453. {
  454. $i=0;
  455. $totalarray=array();
  456. while ($i < min($num,$limit))
  457. {
  458. $objp = $db->fetch_object($resql);
  459. if (empty($objp)) break;
  460. $companystatic->id=$objp->socid;
  461. $companystatic->name=$objp->name;
  462. $invoicerectmp->id=$objp->id?$objp->id:$objp->facid;
  463. $invoicerectmp->frequency=$objp->frequency;
  464. $invoicerectmp->suspended=$objp->suspended;
  465. $invoicerectmp->unit_frequency=$objp->unit_frequency;
  466. $invoicerectmp->nb_gen_max=$objp->nb_gen_max;
  467. $invoicerectmp->nb_gen_done=$objp->nb_gen_done;
  468. $invoicerectmp->ref=$objp->titre;
  469. print '<tr class="oddeven">';
  470. if (! empty($arrayfields['f.titre']['checked']))
  471. {
  472. print '<td>';
  473. print $invoicerectmp->getNomUrl(1);
  474. print "</a>";
  475. print "</td>\n";
  476. if (! $i) $totalarray['nbfield']++;
  477. }
  478. if (! empty($arrayfields['s.nom']['checked']))
  479. {
  480. print '<td class="tdoverflowmax200">'.$companystatic->getNomUrl(1,'customer').'</td>';
  481. if (! $i) $totalarray['nbfield']++;
  482. }
  483. if (! empty($arrayfields['f.total']['checked']))
  484. {
  485. print '<td align="right">'.price($objp->total).'</td>'."\n";
  486. if (! $i) $totalarray['nbfield']++;
  487. if (! $i) $totalarray['pos'][$totalarray['nbfield']]='f.total';
  488. $totalarray['val']['f.total'] += $objp->total;
  489. }
  490. if (! empty($arrayfields['f.tva']['checked']))
  491. {
  492. print '<td align="right">'.price($objp->total_vat).'</td>'."\n";
  493. if (! $i) $totalarray['nbfield']++;
  494. if (! $i) $totalarray['pos'][$totalarray['nbfield']]='f.tva';
  495. $totalarray['val']['f.tva'] += $objp->total_vat;
  496. }
  497. if (! empty($arrayfields['f.total_ttc']['checked']))
  498. {
  499. print '<td align="right">'.price($objp->total_ttc).'</td>'."\n";
  500. if (! $i) $totalarray['nbfield']++;
  501. if (! $i) $totalarray['pos'][$totalarray['nbfield']]='f.total_ttc';
  502. $totalarray['val']['f.total_ttc'] += $objp->total_ttc;
  503. }
  504. // Payment term
  505. if (! empty($arrayfields['f.fk_cond_reglement']['checked']))
  506. {
  507. print '<td align="right">';
  508. print $form->form_conditions_reglement('', $objp->fk_cond_reglement, 'none');
  509. print '</td>'."\n";
  510. if (! $i) $totalarray['nbfield']++;
  511. }
  512. // Payment mode
  513. if (! empty($arrayfields['f.fk_mode_reglement']['checked']))
  514. {
  515. print '<td align="right">';
  516. print $form->form_modes_reglement('', $objp->fk_mode_reglement, 'none');
  517. print '</td>'."\n";
  518. if (! $i) $totalarray['nbfield']++;
  519. }
  520. if (! empty($arrayfields['recurring']['checked']))
  521. {
  522. print '<td align="center">'.yn($objp->frequency?1:0).'</td>';
  523. if (! $i) $totalarray['nbfield']++;
  524. }
  525. if (! empty($arrayfields['f.frequency']['checked']))
  526. {
  527. print '<td align="center">'.($objp->frequency > 0 ? $objp->frequency : '').'</td>';
  528. if (! $i) $totalarray['nbfield']++;
  529. }
  530. if (! empty($arrayfields['f.unit_frequency']['checked']))
  531. {
  532. print '<td align="center">'.($objp->frequency > 0 ? $objp->unit_frequency : '').'</td>';
  533. if (! $i) $totalarray['nbfield']++;
  534. }
  535. if (! empty($arrayfields['f.nb_gen_done']['checked']))
  536. {
  537. print '<td align="center">';
  538. print ($objp->frequency > 0 ? $objp->nb_gen_done.($objp->nb_gen_max>0?' / '. $objp->nb_gen_max:'') : '<span class="opacitymedium">'.$langs->trans('NA').'</span>');
  539. print '</td>';
  540. if (! $i) $totalarray['nbfield']++;
  541. }
  542. // Date last generation
  543. if (! empty($arrayfields['f.date_last_gen']['checked']))
  544. {
  545. print '<td align="center">';
  546. print ($objp->frequency > 0 ? dol_print_date($db->jdate($objp->date_last_gen),'day') : '<span class="opacitymedium">'.$langs->trans('NA').'</span>');
  547. print '</td>';
  548. if (! $i) $totalarray['nbfield']++;
  549. }
  550. // Date next generation
  551. if (! empty($arrayfields['f.date_when']['checked']))
  552. {
  553. print '<td align="center">';
  554. print '<div class="nowraponall">';
  555. print ($objp->frequency ? ($invoicerectmp->isMaxNbGenReached()?'<strike>':'').dol_print_date($db->jdate($objp->date_when),'day').($invoicerectmp->isMaxNbGenReached()?'</strike>':'') : '<span class="opacitymedium">'.$langs->trans('NA').'</span>');
  556. if ($objp->frequency > 0 && $db->jdate($objp->date_when) && $db->jdate($objp->date_when) < $now) print img_warning($langs->trans("Late"));
  557. print '</div>';
  558. print '</td>';
  559. if (! $i) $totalarray['nbfield']++;
  560. }
  561. if (! empty($arrayfields['f.datec']['checked']))
  562. {
  563. print '<td align="center">';
  564. print dol_print_date($db->jdate($objp->datec),'dayhour');
  565. print '</td>';
  566. if (! $i) $totalarray['nbfield']++;
  567. }
  568. if (! empty($arrayfields['f.tms']['checked']))
  569. {
  570. print '<td align="center">';
  571. print dol_print_date($db->jdate($objp->tms),'dayhour');
  572. print '</td>';
  573. if (! $i) $totalarray['nbfield']++;
  574. }
  575. if (! empty($arrayfields['status']['checked']))
  576. {
  577. print '<td align="center">';
  578. print $invoicerectmp->getLibStatut(3,0);
  579. print '</td>';
  580. if (! $i) $totalarray['nbfield']++;
  581. }
  582. // Action column
  583. print '<td align="center">';
  584. if ($user->rights->facture->creer && empty($invoicerectmp->suspended))
  585. {
  586. if (empty($objp->frequency) || $db->jdate($objp->date_when) <= $today)
  587. {
  588. print '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?action=create&amp;socid='.$objp->socid.'&amp;fac_rec='.$objp->facid.'">';
  589. print $langs->trans("CreateBill").'</a>';
  590. }
  591. else
  592. {
  593. print $form->textwithpicto('', $langs->trans("DateIsNotEnough"));
  594. }
  595. }
  596. else
  597. {
  598. print "&nbsp;";
  599. }
  600. if (! $i) $totalarray['nbfield']++;
  601. print "</td>";
  602. print "</tr>\n";
  603. $i++;
  604. }
  605. }
  606. else
  607. {
  608. $colspan=1;
  609. foreach($arrayfields as $key => $val) { if (! empty($val['checked'])) $colspan++; }
  610. print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  611. }
  612. //var_dump($totalarray);
  613. // Show total line
  614. if (isset($totalarray['pos']))
  615. {
  616. print '<tr class="liste_total">';
  617. $i=0;
  618. while ($i < $totalarray['nbfield'])
  619. {
  620. $i++;
  621. if (! empty($totalarray['pos'][$i])) print '<td align="right">'.price($totalarray['val'][$totalarray['pos'][$i]]).'</td>';
  622. else
  623. {
  624. if ($i == 1)
  625. {
  626. if ($num < $limit) print '<td align="left">'.$langs->trans("Total").'</td>';
  627. else print '<td align="left">'.$langs->trans("Totalforthispage").'</td>';
  628. }
  629. else print '<td></td>';
  630. }
  631. }
  632. print '</tr>';
  633. }
  634. print "</table>";
  635. print "</div>";
  636. print "</form>";
  637. $db->free($resql);
  638. }
  639. else
  640. {
  641. dol_print_error($db);
  642. }
  643. llxFooter();
  644. $db->close();