NEW Proposal - Add filter on proposal get lines
This commit is contained in:
parent
58fcf88e24
commit
31787a99f0
@ -274,14 +274,17 @@ class Proposals extends DolibarrApi
|
|||||||
/**
|
/**
|
||||||
* Get lines of a commercial proposal
|
* 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
|
* @url GET {id}/lines
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getLines($id)
|
public function getLines($id, $sqlfilters = '')
|
||||||
{
|
{
|
||||||
|
$filters = "";
|
||||||
|
|
||||||
if (!DolibarrApiAccess::$user->rights->propal->lire) {
|
if (!DolibarrApiAccess::$user->rights->propal->lire) {
|
||||||
throw new RestException(401);
|
throw new RestException(401);
|
||||||
}
|
}
|
||||||
@ -294,7 +297,16 @@ class Proposals extends DolibarrApi
|
|||||||
if (!DolibarrApi::_checkAccessToResource('propal', $this->propal->id)) {
|
if (!DolibarrApi::_checkAccessToResource('propal', $this->propal->id)) {
|
||||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
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();
|
$result = array();
|
||||||
foreach ($this->propal->lines as $line) {
|
foreach ($this->propal->lines as $line) {
|
||||||
array_push($result, $this->_cleanObjectDatas($line));
|
array_push($result, $this->_cleanObjectDatas($line));
|
||||||
|
|||||||
@ -1,20 +1,22 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
|
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
|
||||||
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
* Copyright (C) 2005 Marc Barilley <marc@ocebo.com>
|
* Copyright (C) 2005 Marc Barilley <marc@ocebo.com>
|
||||||
* Copyright (C) 2005-2013 Regis Houssin <regis.houssin@inodbox.com>
|
* Copyright (C) 2005-2013 Regis Houssin <regis.houssin@inodbox.com>
|
||||||
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
|
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
|
||||||
* Copyright (C) 2008 Raphael Bertrand <raphael.bertrand@resultic.fr>
|
* Copyright (C) 2008 Raphael Bertrand <raphael.bertrand@resultic.fr>
|
||||||
* Copyright (C) 2010-2020 Juanjo Menent <jmenent@2byte.es>
|
* Copyright (C) 2010-2020 Juanjo Menent <jmenent@2byte.es>
|
||||||
* Copyright (C) 2010-2017 Philippe Grand <philippe.grand@atoo-net.com>
|
* Copyright (C) 2010-2017 Philippe Grand <philippe.grand@atoo-net.com>
|
||||||
* Copyright (C) 2012-2014 Christophe Battarel <christophe.battarel@altairis.fr>
|
* Copyright (C) 2012-2014 Christophe Battarel <christophe.battarel@altairis.fr>
|
||||||
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
|
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
|
||||||
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
|
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
|
||||||
* Copyright (C) 2014-2015 Marcos García <marcosgdf@gmail.com>
|
* Copyright (C) 2014-2015 Marcos García <marcosgdf@gmail.com>
|
||||||
* Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.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-2021 Frédéric France <frederic.france@netlogic.fr>
|
||||||
* Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
|
* 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
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -1714,12 +1716,13 @@ class Propal extends CommonObject
|
|||||||
/**
|
/**
|
||||||
* Load array lines
|
* Load array lines
|
||||||
*
|
*
|
||||||
* @param int $only_product Return only physical products
|
* @param int $only_product Return only physical products
|
||||||
* @param int $loadalsotranslation Return translation for 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;
|
global $langs, $conf;
|
||||||
// phpcs:enable
|
// phpcs:enable
|
||||||
@ -1738,6 +1741,9 @@ class Propal extends CommonObject
|
|||||||
if ($only_product) {
|
if ($only_product) {
|
||||||
$sql .= ' AND p.fk_product_type = 0';
|
$sql .= ' AND p.fk_product_type = 0';
|
||||||
}
|
}
|
||||||
|
if ($filters) {
|
||||||
|
$sql .= $filters;
|
||||||
|
}
|
||||||
$sql .= ' ORDER by d.rang';
|
$sql .= ' ORDER by d.rang';
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG);
|
dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG);
|
||||||
@ -3689,12 +3695,13 @@ class Propal extends CommonObject
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve an array of proposal lines
|
* Retrieve an array of proposal lines
|
||||||
|
* @param string $filters Filter on other fields
|
||||||
*
|
*
|
||||||
* @return int >0 if OK, <0 if KO
|
* @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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user