diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php
index eedc3297018..1c4ce0cdecf 100644
--- a/htdocs/compta/facture/list.php
+++ b/htdocs/compta/facture/list.php
@@ -47,6 +47,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
+require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
@@ -135,6 +136,7 @@ $search_datelimit_endyear = GETPOST('search_datelimit_endyear', 'int');
$search_datelimit_start = dol_mktime(0, 0, 0, $search_datelimit_startmonth, $search_datelimit_startday, $search_datelimit_startyear);
$search_datelimit_end = dol_mktime(23, 59, 59, $search_datelimit_endmonth, $search_datelimit_endday, $search_datelimit_endyear);
$search_categ_cus = GETPOST("search_categ_cus", 'int');
+$search_fac_rec_source = GETPOST("search_fac_rec_source", 'int');
$search_btn = GETPOST('button_search', 'alpha');
$search_remove_btn = GETPOST('button_removefilter', 'alpha');
$optioncss = GETPOST('optioncss', 'alpha');
@@ -251,6 +253,7 @@ $arrayfields = array(
'f.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>502),
'f.note_public'=>array('label'=>'NotePublic', 'checked'=>0, 'position'=>510, 'enabled'=>(empty($conf->global->MAIN_LIST_ALLOW_PUBLIC_NOTES))),
'f.note_private'=>array('label'=>'NotePrivate', 'checked'=>0, 'position'=>511, 'enabled'=>(empty($conf->global->MAIN_LIST_ALLOW_PRIVATE_NOTES))),
+ 'f.fk_fac_rec_source'=>array('label'=>'GeneratedFromTemplate', 'checked'=>0, 'position'=>520, 'enabled'=>'1'),
'f.fk_statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000),
);
@@ -360,6 +363,7 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter',
$search_datelimit_endyear = '';
$search_datelimit_start = '';
$search_datelimit_end = '';
+ $search_fac_rec_source = '';
$option = '';
$filter = '';
$toselect = '';
@@ -566,6 +570,7 @@ $sql .= ' s.rowid as socid, s.nom as name, s.name_alias as alias, s.email, s.pho
$sql .= ' typent.code as typent_code,';
$sql .= ' state.code_departement as state_code, state.nom as state_name,';
$sql .= ' country.code as country_code,';
+$sql .= ' f.fk_fac_rec_source,';
$sql .= ' p.rowid as project_id, p.ref as project_ref, p.title as project_label,';
$sql .= ' u.login, u.lastname, u.firstname, u.email as user_email, u.statut as user_statut, u.entity, u.photo, u.office_phone, u.office_fax, u.user_mobile, u.job, u.gender';
// We need dynamount_payed to be able to sort on status (value is surely wrong because we can count several lines several times due to other left join or link with contacts. But what we need is just 0 or > 0).
@@ -801,6 +806,10 @@ if ($search_sale > 0) {
if ($search_user > 0) {
$sql .= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='facture' AND tc.source='internal' AND ec.element_id = f.rowid AND ec.fk_socpeople = ".((int) $search_user);
}
+
+if ($search_fac_rec_source > 0) {
+ $sql .= " AND f.fk_fac_rec_source = ".((int) $search_fac_rec_source);
+}
// Add where from extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
// Add where from hooks
@@ -1079,6 +1088,9 @@ if ($resql) {
if ($search_categ_cus > 0) {
$param .= '&search_categ_cus='.urlencode($search_categ_cus);
}
+ if ($search_fac_rec_source > 0) {
+ $param .= '&search_fac_rec_source='.urlencode($search_fac_rec_source);
+ }
// Add $param from extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
@@ -1500,6 +1512,12 @@ if ($resql) {
print '
';
print ' ';
}
+ if (!empty($arrayfields['f.fk_fac_rec_source']['checked'])) {
+ // Template Invoice
+ print '';
+ $form->selectInvoiceRec($search_fac_rec_source, 'search_fac_rec_source');
+ print ' ';
+ }
// Status
if (!empty($arrayfields['f.fk_statut']['checked'])) {
print '';
@@ -1659,6 +1677,9 @@ if ($resql) {
if (!empty($arrayfields['f.note_private']['checked'])) {
print_liste_field_titre($arrayfields['f.note_private']['label'], $_SERVER["PHP_SELF"], "f.note_private", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
}
+ if (!empty($arrayfields['f.fk_fac_rec_source']['checked'])) {
+ print_liste_field_titre($arrayfields['f.fk_fac_rec_source']['label'], $_SERVER["PHP_SELF"], "f.fk_fac_rec_source", "", $param, '', $sortfield, $sortorder);
+ }
if (!empty($arrayfields['f.fk_statut']['checked'])) {
print_liste_field_titre($arrayfields['f.fk_statut']['label'], $_SERVER["PHP_SELF"], "f.fk_statut,f.paye,f.type", "", $param, 'class="right"', $sortfield, $sortorder);
}
@@ -2335,6 +2356,23 @@ if ($resql) {
$totalarray['nbfield']++;
}
}
+ // Template Invoice
+ if (!empty($arrayfields['f.fk_fac_rec_source']['checked'])) {
+ print ' ';
+ if (!empty($obj->fk_fac_rec_source)) {
+ $facrec = new FactureRec($db);
+ $result = $facrec->fetch($obj->fk_fac_rec_source);
+ if ($result < 0) {
+ setEventMessages($facrec->error, $facrec->errors, 'errors');
+ } else {
+ print $facrec->getNomUrl();
+ }
+ }
+ print ' ';
+ if (!$i) {
+ $totalarray['nbfield']++;
+ }
+ }
// Status
if (!empty($arrayfields['f.fk_statut']['checked'])) {
print '';
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index b9812d8eec3..5b74816dfc3 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -9774,6 +9774,101 @@ class Form
}
}
+ /**
+ * Output a combo list with invoices qualified for a third party
+ *
+ * @param int $selected Id invoice preselected
+ * @param string $htmlname Name of HTML select
+ * @param int $maxlength Maximum length of label
+ * @param int $option_only Return only html options lines without the select tag
+ * @param string $show_empty Add an empty line ('1' or string to show for empty line)
+ * @param int $forcefocus Force focus on field (works with javascript only)
+ * @param int $disabled Disabled
+ * @param string $morecss More css added to the select component
+ * @return int Nbr of project if OK, <0 if KO
+ */
+ public function selectInvoiceRec($selected = '', $htmlname = 'facrecid', $maxlength = 24, $option_only = 0, $show_empty = '1', $forcefocus = 0, $disabled = 0, $morecss = 'maxwidth500')
+ {
+ global $user, $conf, $langs;
+
+ $out = '';
+
+ dol_syslog('FactureRec::fetch', LOG_DEBUG);
+
+ $sql = 'SELECT f.rowid, f.entity, f.titre as title, f.suspended, f.fk_soc';
+ //$sql.= ', el.fk_source';
+ $sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture_rec as f';
+ $sql .= " WHERE f.entity IN (" . getEntity('invoice') . ")";
+ $sql .= " ORDER BY f.titre ASC";
+
+ $resql = $this->db->query($sql);
+ if ($resql) {
+ // Use select2 selector
+ if (!empty($conf->use_javascript_ajax)) {
+ include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
+ $comboenhancement = ajax_combobox($htmlname, '', 0, $forcefocus);
+ $out .= $comboenhancement;
+ $morecss = 'minwidth200imp maxwidth500';
+ }
+
+ if (empty($option_only)) {
+ $out .= '';
+ }
+ if (!empty($show_empty)) {
+ $out .= '';
+ if (!is_numeric($show_empty)) {
+ $out .= $show_empty;
+ } else {
+ $out .= ' ';
+ }
+ $out .= ' ';
+ }
+ $num = $this->db->num_rows($resql);
+ if ($num) {
+ while ($obj = $this->db->fetch_object($resql)) {
+ $labeltoshow = dol_trunc($obj->title, 18); // Invoice ref
+
+ $disabled = 0;
+ if (!empty($obj->suspended)) {
+ $disabled = 1;
+ $labeltoshow .= ' - ' . $langs->trans("Closed");
+ }
+
+
+ if (!empty($selected) && $selected == $obj->rowid) {
+ $out .= '';
+ } else {
+ if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
+ $resultat = '';
+ } else {
+ $resultat = ' db->free($resql);
+ return $num;
+ } else {
+ $this->errors[]=$this->db->lasterror;
+ return -1;
+ }
+ }
+
/**
* Output the component to make advanced search criteries
*