Merge pull request #19927 from aspangaro/16a10

NEW Proposal - Add filter on proposal get lines
This commit is contained in:
Laurent Destailleur 2022-01-26 11:38:25 +01:00 committed by GitHub
commit ebdea44de9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 25 deletions

View File

@ -274,14 +274,17 @@ class Proposals extends DolibarrApi
/**
* Get lines of a commercial proposal
*
* @param int $id Id of commercial proposal
* @param int $id Id of commercial proposal
* @param string $sqlfilters Other criteria to filter answers separated by a comma. d is the alias for proposal lines table, p is the alias for product table. "Syntax example "(p.ref:like:'SO-%') and (d.date_start:<:'20220101')"
*
* @url GET {id}/lines
*
* @return int
*/
public function getLines($id)
public function getLines($id, $sqlfilters = '')
{
$filters = "";
if (!DolibarrApiAccess::$user->rights->propal->lire) {
throw new RestException(401);
}
@ -294,7 +297,16 @@ class Proposals extends DolibarrApi
if (!DolibarrApi::_checkAccessToResource('propal', $this->propal->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$this->propal->getLinesArray();
if (!empty($sqlfilters)) {
if (!DolibarrApi::_checkFilters($sqlfilters)) {
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
}
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
$filters = " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
}
$this->propal->getLinesArray($filters);
$result = array();
foreach ($this->propal->lines as $line) {
array_push($result, $this->_cleanObjectDatas($line));

View File

@ -1,20 +1,22 @@
<?php
/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Marc Barilley <marc@ocebo.com>
* Copyright (C) 2005-2013 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2008 Raphael Bertrand <raphael.bertrand@resultic.fr>
* Copyright (C) 2010-2020 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2010-2017 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2012-2014 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2014-2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
* Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Marc Barilley <marc@ocebo.com>
* Copyright (C) 2005-2013 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2008 Raphael Bertrand <raphael.bertrand@resultic.fr>
* Copyright (C) 2010-2020 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2010-2017 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2012-2014 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2014-2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
* Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2022 ATM Consulting <contact@atm-consulting.fr>
* Copyright (C) 2022 OpenDSI <support@open-dsi.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
@ -1714,12 +1716,13 @@ class Propal extends CommonObject
/**
* Load array lines
*
* @param int $only_product Return only physical products
* @param int $loadalsotranslation Return translation for products
* @param int $only_product Return only physical products
* @param int $loadalsotranslation Return translation for products
* @param string $filters Filter on other fields
*
* @return int <0 if KO, >0 if OK
* @return int <0 if KO, >0 if OK
*/
public function fetch_lines($only_product = 0, $loadalsotranslation = 0)
public function fetch_lines($only_product = 0, $loadalsotranslation = 0, $filters = '')
{
global $langs, $conf;
// phpcs:enable
@ -1738,6 +1741,9 @@ class Propal extends CommonObject
if ($only_product) {
$sql .= ' AND p.fk_product_type = 0';
}
if ($filters) {
$sql .= $filters;
}
$sql .= ' ORDER by d.rang';
dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG);
@ -3689,12 +3695,13 @@ class Propal extends CommonObject
/**
* Retrieve an array of proposal lines
* @param string $filters Filter on other fields
*
* @return int >0 if OK, <0 if KO
*/
public function getLinesArray()
public function getLinesArray($filters = '')
{
return $this->fetch_lines();
return $this->fetch_lines(0, 0, $filters);
}
/**