invoicetemplate_list.php 32 KB

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