WIP
This commit is contained in:
parent
9328fb4f6c
commit
a2a4078b04
69
htdocs/core/ajax/ajaxinvoiceline.php
Normal file
69
htdocs/core/ajax/ajaxinvoiceline.php
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
/* Copyright (C) 2022 Florian HENRY <florian.henry@scopen.fr>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file htdocs/core/ajax/ajaxinvoiceline.php
|
||||||
|
* \brief File to load contacts combobox
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!defined('NOTOKENRENEWAL')) {
|
||||||
|
define('NOTOKENRENEWAL', '1'); // Disables token renewal
|
||||||
|
}
|
||||||
|
if (!defined('NOREQUIREMENU')) {
|
||||||
|
define('NOREQUIREMENU', '1');
|
||||||
|
}
|
||||||
|
if (!defined('NOREQUIREAJAX')) {
|
||||||
|
define('NOREQUIREAJAX', '1');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load Dolibarr environment
|
||||||
|
require '../../main.inc.php';
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
|
||||||
|
|
||||||
|
$invoice_id = GETPOST('id', 'int'); // id of thirdparty
|
||||||
|
$action = GETPOST('action', 'aZ09');
|
||||||
|
$htmlname = GETPOST('htmlname', 'alpha');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Security check
|
||||||
|
restrictedArea($user, 'facture', $invoice_id, '', '', 'fk_soc', 'rowid');
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* View
|
||||||
|
*/
|
||||||
|
|
||||||
|
top_httphead();
|
||||||
|
|
||||||
|
//print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
|
||||||
|
|
||||||
|
// Load original field value
|
||||||
|
if (!empty($invoice_id) && !empty($action) && !empty($htmlname)) {
|
||||||
|
$formProject = new FormProjets($db);
|
||||||
|
|
||||||
|
$return = array();
|
||||||
|
if (empty($showempty)) {
|
||||||
|
$showempty = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$return['value'] = $formProject->selectInvoiceAndLine($invoice_id, 0, 'invoiceid', 'invoicelineid', 'maxwidth500', array(), 1);
|
||||||
|
//$return['num'] = $form->num;
|
||||||
|
//$return['error'] = $form->error;
|
||||||
|
|
||||||
|
echo json_encode($return);
|
||||||
|
}
|
||||||
@ -757,20 +757,21 @@ class FormProjets
|
|||||||
*
|
*
|
||||||
* @param int $selectedInvoiceId Id invoice preselected
|
* @param int $selectedInvoiceId Id invoice preselected
|
||||||
* @param int $selectedLineId Id invoice line preselected
|
* @param int $selectedLineId Id invoice line preselected
|
||||||
* @param string $htmlNameInvoiceId Name of HTML select for Invoice
|
* @param string $htmlNameInvoice Name of HTML select for Invoice
|
||||||
* @param int $htmlNameInvoiceLineId Name of HTML select for Invoice Line
|
* @param int $htmlNameInvoiceLine Name of HTML select for Invoice Line
|
||||||
* @param string $morecss More css added to the select component
|
* @param string $morecss More css added to the select component
|
||||||
* @param array $filters Array of filters
|
* @param array $filters Array of filters
|
||||||
|
* @param int $lineOnly return only option for line
|
||||||
* @return int Nbr of project if OK, <0 if KO
|
* @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())
|
public function selectInvoiceAndLine($selectedInvoiceId = 0, $selectedLineId = 0, $htmlNameInvoice = 'invoiceid', $htmlNameInvoiceLine = 'invoicelineid', $morecss = 'maxwidth500', $filters = array(), $lineOnly = 0)
|
||||||
{
|
{
|
||||||
global $user, $conf, $langs;
|
global $user, $conf, $langs;
|
||||||
|
|
||||||
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
|
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
|
||||||
|
|
||||||
$out = '';
|
$out = '';
|
||||||
|
if (empty($lineOnly)) {
|
||||||
// Search Invoice
|
// Search Invoice
|
||||||
$sql = "SELECT f.rowid, f.ref as fref,";
|
$sql = "SELECT f.rowid, f.ref as fref,";
|
||||||
$sql .= ' s.nom as name';
|
$sql .= ' s.nom as name';
|
||||||
@ -795,12 +796,12 @@ class FormProjets
|
|||||||
// Use select2 selector
|
// Use select2 selector
|
||||||
if (!empty($conf->use_javascript_ajax)) {
|
if (!empty($conf->use_javascript_ajax)) {
|
||||||
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
|
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
|
||||||
$comboenhancement = ajax_combobox($htmlNameInvoiceId, '', 0, 0);
|
$comboenhancement = ajax_combobox($htmlNameInvoice, array(array('method'=>'getLines', 'url'=>dol_buildpath('/core/ajax/ajaxinvoiceline.php', 1), 'htmlname'=>$htmlNameInvoiceLine)), 0, 0);
|
||||||
$out .= $comboenhancement;
|
$out .= $comboenhancement;
|
||||||
$morecss = 'minwidth200imp maxwidth500';
|
$morecss = 'minwidth200imp maxwidth500';
|
||||||
}
|
}
|
||||||
|
|
||||||
$out .= '<select class="valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '" id="' . $htmlNameInvoiceId . '" name="' . $htmlNameInvoiceId . '">';
|
$out .= '<select class="valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '" id="' . $htmlNameInvoice . '" name="' . $htmlNameInvoice . '">';
|
||||||
$num = $this->db->num_rows($resql);
|
$num = $this->db->num_rows($resql);
|
||||||
if ($num) {
|
if ($num) {
|
||||||
while ($obj = $this->db->fetch_object($resql)) {
|
while ($obj = $this->db->fetch_object($resql)) {
|
||||||
@ -816,9 +817,11 @@ class FormProjets
|
|||||||
$out .= '>' . $labeltoshow . '</option>';
|
$out .= '>' . $labeltoshow . '</option>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$out .= '</select>';
|
||||||
} else {
|
} else {
|
||||||
dol_print_error($this->db->lasterror);
|
dol_print_error($this->db->lasterror);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Search Invoice Line
|
// Search Invoice Line
|
||||||
$sql = "SELECT fd.rowid, fd.label, fd.description";
|
$sql = "SELECT fd.rowid, fd.label, fd.description";
|
||||||
@ -838,29 +841,34 @@ class FormProjets
|
|||||||
$sql .= " AND f.rowid=" . (int) $selectedInvoiceId;
|
$sql .= " AND f.rowid=" . (int) $selectedInvoiceId;
|
||||||
}
|
}
|
||||||
$sql .= " ORDER BY p.ref, f.ref ASC";
|
$sql .= " ORDER BY p.ref, f.ref ASC";
|
||||||
|
$resql = $this->db->query($sql);
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
// Use select2 selector
|
// Use select2 selector
|
||||||
|
if (empty($lineOnly)) {
|
||||||
if (!empty($conf->use_javascript_ajax)) {
|
if (!empty($conf->use_javascript_ajax)) {
|
||||||
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
|
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
|
||||||
$comboenhancement = ajax_combobox($htmlNameInvoiceLineId, '', 0, 0);
|
$comboenhancement = ajax_combobox($htmlNameInvoiceLine, '', 0, 0);
|
||||||
$out .= $comboenhancement;
|
$out .= $comboenhancement;
|
||||||
$morecss = 'minwidth200imp maxwidth500';
|
$morecss = 'minwidth200imp maxwidth500';
|
||||||
}
|
}
|
||||||
|
|
||||||
$out .= '<select class="valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '" id="' . $htmlNameInvoiceLineId . '" name="' . $htmlNameInvoiceLineId . '">';
|
$out .= '<select class="valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '" id="' . $htmlNameInvoiceLine . '" name="' . $htmlNameInvoiceLine . '">';
|
||||||
|
}
|
||||||
$num = $this->db->num_rows($resql);
|
$num = $this->db->num_rows($resql);
|
||||||
if ($num) {
|
if ($num) {
|
||||||
while ($obj = $this->db->fetch_object($resql)) {
|
while ($obj = $this->db->fetch_object($resql)) {
|
||||||
$labeltoshow .= $obj->label; // Invoice ref
|
$labeltoshow .= $obj->description; // Invoice ref
|
||||||
$labeltoshow .= dol_trunc($obj->description, 25); // Invoice ref
|
|
||||||
|
|
||||||
$out .= '<option value="' . $obj->rowid . '" ';
|
$out .= '<option value="' . $obj->rowid . '" ';
|
||||||
if (!empty($selectedInvoiceId) && $selectedLineId == $obj->rowid) {
|
if (!empty($selectedLineId) && $selectedLineId == $obj->rowid) {
|
||||||
$out .= ' selected ';
|
$out .= ' selected ';
|
||||||
}
|
}
|
||||||
$out .= '>' . $labeltoshow . '</option>';
|
$out .= '>' . $labeltoshow . '</option>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (empty($lineOnly)) {
|
||||||
|
$out .= '</select>';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
dol_print_error($this->db->lasterror);
|
dol_print_error($this->db->lasterror);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user