WIP
This commit is contained in:
parent
be877ffb4b
commit
b658b9b1d3
File diff suppressed because it is too large
Load Diff
@ -748,4 +748,122 @@ class FormProjets
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Output a combo list with invoices and lines qualified for a project
|
||||
*
|
||||
* @param int $selectedInvoiceId Id invoice preselected
|
||||
* @param int $selectedLineId Id invoice line preselected
|
||||
* @param string $htmlNameInvoiceId Name of HTML select for Invoice
|
||||
* @param int $htmlNameInvoiceLineId Name of HTML select for Invoice Line
|
||||
* @param int $option_only Return only html options lines without the select tag
|
||||
* @param string $morecss More css added to the select component
|
||||
* @param array $filters Array of filters
|
||||
* @return int Nbr of project if OK, <0 if KO
|
||||
*/
|
||||
public function selectInvoiceAndLine($selectedInvoiceId = 0, $selectedLineId = 0, $htmlNameInvoiceId = 'invoiceid', $htmlNameInvoiceLineId = 'invoicelineid', $morecss = 'maxwidth500', $filters = array())
|
||||
{
|
||||
global $user, $conf, $langs;
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
|
||||
|
||||
$out = '';
|
||||
|
||||
// Search Invoice
|
||||
$sql = "SELECT f.rowid, f.ref as fref,";
|
||||
$sql .= ' s.nom as name';
|
||||
$sql .= ' FROM ' . $this->db->prefix() . 'projet as p';
|
||||
$sql .= ' INNER JOIN ' . $this->db->prefix() . 'societe as s ON s.rowid = p.fk_soc';
|
||||
$sql .= ' INNER JOIN ' . $this->db->prefix() . 'facture as f ON f.fk_projet = p.rowid';
|
||||
$sql .= " WHERE p.entity IN (" . getEntity('project') . ")";
|
||||
if (!empty($filters)) {
|
||||
foreach ($filters as $key => $value) {
|
||||
if ($key == 'p.rowid') {
|
||||
$sql .= " AND p.rowid=" . (int)$value;
|
||||
}
|
||||
if ($key == 'f.rowid') {
|
||||
$sql .= " AND f.rowid=" . (int)$value;
|
||||
}
|
||||
}
|
||||
}
|
||||
$sql .= " ORDER BY p.ref, f.ref 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($htmlNameInvoiceId, '', 0, 0);
|
||||
$out .= $comboenhancement;
|
||||
$morecss = 'minwidth200imp maxwidth500';
|
||||
}
|
||||
|
||||
$out .= '<select class="valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '" id="' . $htmlNameInvoiceId . '" name="' . $htmlNameInvoiceId . '">';
|
||||
$num = $this->db->num_rows($resql);
|
||||
if ($num) {
|
||||
while ($obj = $this->db->fetch_object($resql)) {
|
||||
$labeltoshow = $obj->fref; // Invoice ref
|
||||
if ($obj->name) {
|
||||
$labeltoshow .= ' - ' . $obj->name;
|
||||
}
|
||||
|
||||
$out .= '<option value="' . $obj->rowid . '" ';
|
||||
if (!empty($selectedInvoiceId) && $selectedInvoiceId == $obj->rowid) {
|
||||
$out .= ' selected ';
|
||||
}
|
||||
$out .= '>' . $labeltoshow . '</option>';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dol_print_error($this->db->lasterror);
|
||||
}
|
||||
|
||||
// Search Invoice Line
|
||||
$sql = "SELECT fd.rowid, fd.label, fd.description";
|
||||
$sql .= ' FROM ' . $this->db->prefix() . 'projet as p';
|
||||
$sql .= ' INNER JOIN ' . $this->db->prefix() . 'societe as s ON s.rowid = p.fk_soc';
|
||||
$sql .= ' INNER JOIN ' . $this->db->prefix() . 'facture as f ON f.fk_projet = p.rowid';
|
||||
$sql .= ' INNER JOIN ' . $this->db->prefix() . 'facturedet as fd ON fd.fk_facture = f.rowid';
|
||||
$sql .= " WHERE p.entity IN (" . getEntity('project') . ")";
|
||||
if (!empty($filters)) {
|
||||
foreach ($filters as $key => $value) {
|
||||
if ($key == 'p.rowid') {
|
||||
$sql .= " AND p.rowid=" . (int) $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($selectedInvoiceId)) {
|
||||
$sql .= " AND f.rowid=" . (int) $selectedInvoiceId;
|
||||
}
|
||||
$sql .= " ORDER BY p.ref, f.ref ASC";
|
||||
if ($resql) {
|
||||
// Use select2 selector
|
||||
if (!empty($conf->use_javascript_ajax)) {
|
||||
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
|
||||
$comboenhancement = ajax_combobox($htmlNameInvoiceLineId, '', 0, 0);
|
||||
$out .= $comboenhancement;
|
||||
$morecss = 'minwidth200imp maxwidth500';
|
||||
}
|
||||
|
||||
$out .= '<select class="valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '" id="' . $htmlNameInvoiceLineId . '" name="' . $htmlNameInvoiceLineId . '">';
|
||||
$num = $this->db->num_rows($resql);
|
||||
if ($num) {
|
||||
while ($obj = $this->db->fetch_object($resql)) {
|
||||
$labeltoshow .= $obj->label; // Invoice ref
|
||||
$labeltoshow .= dol_trunc($obj->description, 25); // Invoice ref
|
||||
|
||||
|
||||
$out .= '<option value="' . $obj->rowid . '" ';
|
||||
if (!empty($selectedInvoiceId) && $selectedLineId == $obj->rowid) {
|
||||
$out .= ' selected ';
|
||||
}
|
||||
$out .= '>' . $labeltoshow . '</option>';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dol_print_error($this->db->lasterror);
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2345,9 +2345,11 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0 || $allprojectforuser
|
||||
if ($task_time->invoice_id) {
|
||||
$result = $tmpinvoice->fetch($task_time->invoice_id);
|
||||
if ($result > 0) {
|
||||
var_dump($task_time->invoice_line_id);
|
||||
//print $tmpinvoice->getNomUrl(1);
|
||||
//print $form->selectInvoiceAndLines($projectstatic->thirdparty->id, $tmpinvoice->id, 'invoiceid', 'invoicelineid', 24, 0, $langs->trans('NewInvoice'), 1, 0, 0, 'maxwidth500', '', 'all',null,-1);
|
||||
if ($action=='editline' && $_GET['lineid'] == $task_time->rowid) {
|
||||
print $formproject->selectInvoiceAndLine($task_time->invoice_id, $task_time->invoice_line_id, 'invoiceid', 'invoicelineid', 'maxwidth500', array('p.rowid'=>$projectstatic->id));
|
||||
} else {
|
||||
print $tmpinvoice->getNomUrl(1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
print $langs->trans("No");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user