Clean code

This commit is contained in:
Laurent Destailleur 2023-01-04 11:36:46 +01:00
parent 4ea81b4a96
commit 43a0ccce2b
20 changed files with 302 additions and 335 deletions

View File

@ -319,8 +319,8 @@ class Setup extends DolibarrApi
/**
* Get state by ID.
*
* @param int $id ID of state
* @return array Array of cleaned object properties
* @param int $id ID of state
* @return Object Object with cleaned properties
*
* @url GET dictionary/states/{id}
*
@ -334,8 +334,8 @@ class Setup extends DolibarrApi
/**
* Get state by Code.
*
* @param string $code Code of state
* @return array Array of cleaned object properties
* @param string $code Code of state
* @return Object Object with cleaned properties
*
* @url GET dictionary/states/byCode/{code}
*
@ -424,10 +424,9 @@ class Setup extends DolibarrApi
/**
* Get country by ID.
*
* @param int $id ID of country
* @param string $lang Code of the language the name of the
* country must be translated to
* @return array Array of cleaned object properties
* @param int $id ID of country
* @param string $lang Code of the language the name of the country must be translated to
* @return Object Object with cleaned properties
*
* @url GET dictionary/countries/{id}
*
@ -441,10 +440,9 @@ class Setup extends DolibarrApi
/**
* Get country by Code.
*
* @param string $code Code of country (2 characters)
* @param string $lang Code of the language the name of the
* country must be translated to
* @return array Array of cleaned object properties
* @param string $code Code of country (2 characters)
* @param string $lang Code of the language the name of the country must be translated to
* @return Object Object with cleaned properties
*
* @url GET dictionary/countries/byCode/{code}
*
@ -458,10 +456,9 @@ class Setup extends DolibarrApi
/**
* Get country by Iso.
*
* @param string $iso ISO of country (3 characters)
* @param string $lang Code of the language the name of the
* country must be translated to
* @return array Array of cleaned object properties
* @param string $iso ISO of country (3 characters)
* @param string $lang Code of the language the name of the country must be translated to
* @return Object Object with cleaned properties
*
* @url GET dictionary/countries/byISO/{iso}
*
@ -475,9 +472,9 @@ class Setup extends DolibarrApi
/**
* Get state.
*
* @param int $id ID of state
* @param string $code Code of state
* @return array Array of cleaned object properties
* @param int $id ID of state
* @param string $code Code of state
* @return Object Object with cleaned properties
*
* @throws RestException
*/
@ -498,12 +495,11 @@ class Setup extends DolibarrApi
/**
* Get country.
*
* @param int $id ID of country
* @param string $code Code of country (2 characters)
* @param string $iso ISO of country (3 characters)
* @param string $lang Code of the language the name of the
* country must be translated to
* @return array Array of cleaned object properties
* @param int $id ID of country
* @param string $code Code of country (2 characters)
* @param string $iso ISO of country (3 characters)
* @param string $lang Code of the language the name of the country must be translated to
* @return Object Object with cleaned properties
*
* @throws RestException
*/
@ -527,12 +523,12 @@ class Setup extends DolibarrApi
/**
* Get the list of delivery times.
*
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Number of items per page
* @param int $page Page number {@min 0}
* @param int $active Delivery times is active or not {@min 0} {@max 1}
* @param string $sqlfilters SQL criteria to filter with.
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Number of items per page
* @param int $page Page number {@min 0}
* @param int $active Delivery times is active or not {@min 0} {@max 1}
* @param string $sqlfilters SQL criteria to filter with.
*
* @url GET dictionary/availability
*
@ -592,8 +588,8 @@ class Setup extends DolibarrApi
/**
* Clean sensible object datas
*
* @param Object $object Object to clean
* @return Object Object with cleaned properties
* @param Object $object Object to clean
* @return Object Object with cleaned properties
*/
protected function _cleanObjectDatas($object)
{
@ -1786,8 +1782,8 @@ class Setup extends DolibarrApi
/**
* Get establishment by ID.
*
* @param int $id ID of establishment
* @return array Array of cleaned object properties
* @param int $id ID of establishment
* @return Object Object with cleaned properties
*
* @url GET establishments/{id}
*
@ -1813,7 +1809,7 @@ class Setup extends DolibarrApi
* Note that conf variables that stores security key or password hashes can't be loaded with API.
*
* @param string $constantname Name of conf variable to get
* @return array|mixed Data without useless information
* @return string Data without useless information
*
* @url GET conf/{constantname}
*
@ -1825,7 +1821,7 @@ class Setup extends DolibarrApi
global $conf;
if (!DolibarrApiAccess::$user->admin
&& (empty($conf->global->API_LOGINS_ALLOWED_FOR_CONST_READ) || DolibarrApiAccess::$user->login != $conf->global->API_LOGINS_ALLOWED_FOR_CONST_READ)) {
&& (!getDolGlobalString('API_LOGINS_ALLOWED_FOR_CONST_READ') || DolibarrApiAccess::$user->login != getDolGlobalString('API_LOGINS_ALLOWED_FOR_CONST_READ'))) {
throw new RestException(403, 'Error API open to admin users only or to the users with logins defined into constant API_LOGINS_ALLOWED_FOR_CONST_READ');
}
@ -1836,7 +1832,7 @@ class Setup extends DolibarrApi
throw new RestException(403, 'Forbidden. This parameter cant be read with APIs');
}
return $conf->global->$constantname;
return getDolGlobalString($constantname);
}
/**

View File

@ -1329,7 +1329,7 @@ class BOM extends CommonObject
* BOM costs calculation based on cost_price or pmp of each BOM line.
* Set the property ->total_cost and ->unit_cost of BOM.
*
* @return void
* @return int <0 if KO, >0 if OK
*/
public function calculateCosts()
{
@ -1414,6 +1414,8 @@ class BOM extends CommonObject
$this->unit_cost = price2num($this->total_cost * $this->qty, 'MU');
}
}
return 1;
}
/**

View File

@ -402,7 +402,7 @@ class ICal
public function get_event_list()
{
// phpcs:enable
return (empty($this->cal['VEVENT']) ? '' : $this->cal['VEVENT']);
return (empty($this->cal['VEVENT']) ? array() : $this->cal['VEVENT']);
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
@ -414,7 +414,7 @@ class ICal
public function get_freebusy_list()
{
// phpcs:enable
return (empty($this->cal['VFREEBUSY']) ? '' : $this->cal['VFREEBUSY']);
return (empty($this->cal['VFREEBUSY']) ? array() : $this->cal['VFREEBUSY']);
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps

View File

@ -49,7 +49,7 @@ class Proposals extends DolibarrApi
*/
public function __construct()
{
global $db, $conf;
global $db;
$this->db = $db;
$this->propal = new Propal($this->db);
}
@ -59,9 +59,9 @@ class Proposals extends DolibarrApi
*
* Return an array with commercial proposal informations
*
* @param int $id ID of commercial proposal
* @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id
* @return array|mixed data without useless information
* @param int $id ID of commercial proposal
* @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id
* @return Object Object with cleaned properties
*
* @throws RestException
*/
@ -76,8 +76,8 @@ class Proposals extends DolibarrApi
* Return an array with proposal informations
*
* @param string $ref Ref of object
* @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id
* @return array|mixed data without useless information
* @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id
* @return Object Object with cleaned properties
*
* @url GET ref/{ref}
*
@ -93,9 +93,9 @@ class Proposals extends DolibarrApi
*
* Return an array with proposal informations
*
* @param string $ref_ext External reference of object
* @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id
* @return array|mixed data without useless information
* @param string $ref_ext External reference of object
* @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id
* @return Object Object with cleaned properties
*
* @url GET ref_ext/{ref_ext}
*
@ -111,11 +111,11 @@ class Proposals extends DolibarrApi
*
* Return an array with proposal informations
*
* @param int $id ID of order
* @param string $ref Ref of object
* @param string $ref_ext External reference of object
* @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id
* @return array|mixed data without useless information
* @param int $id ID of order
* @param string $ref Ref of object
* @param string $ref_ext External reference of object
* @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id
* @return Object Object with cleaned properties
*
* @throws RestException
*/
@ -289,7 +289,7 @@ class Proposals extends DolibarrApi
*
* @url GET {id}/lines
*
* @return int
* @return array
*/
public function getLines($id, $sqlfilters = '')
{
@ -461,7 +461,7 @@ class Proposals extends DolibarrApi
}
if (empty($errors)) {
$this->db->commit();
return count($request_data);
return $updateRes;
} else {
$this->db->rollback();
throw new RestException(400, implode(", ", $errors));
@ -471,13 +471,12 @@ class Proposals extends DolibarrApi
/**
* Update a line of given commercial proposal
*
* @param int $id Id of commercial proposal to update
* @param int $lineid Id of line to update
* @param array $request_data Commercial proposal line data
* @param int $id Id of commercial proposal to update
* @param int $lineid Id of line to update
* @param array $request_data Commercial proposal line data
* @return Object|false Object with cleaned properties
*
* @url PUT {id}/lines/{lineid}
*
* @return object
*/
public function putLine($id, $lineid, $request_data = null)
{
@ -548,13 +547,12 @@ class Proposals extends DolibarrApi
* Delete a line of given commercial proposal
*
*
* @param int $id Id of commercial proposal to update
* @param int $lineid Id of line to delete
* @param int $id Id of commercial proposal to update
* @param int $lineid Id of line to delete
* @return Object|false Object with cleaned properties
*
* @url DELETE {id}/lines/{lineid}
*
* @return int
*
* @throws RestException 401
* @throws RestException 404
*/
@ -573,9 +571,7 @@ class Proposals extends DolibarrApi
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
// TODO Check the lineid $lineid is a line of ojbect
$updateRes = $this->propal->deleteline($lineid);
$updateRes = $this->propal->deleteline($lineid, $id);
if ($updateRes > 0) {
return $this->get($id);
} else {
@ -589,11 +585,10 @@ class Proposals extends DolibarrApi
* @param int $id Id of commercial proposal to update
* @param int $contactid Id of contact to add
* @param string $type Type of the contact (BILLING, SHIPPING, CUSTOMER)
* @return array
*
* @url POST {id}/contact/{contactid}/{type}
*
* @return int
*
* @throws RestException 401
* @throws RestException 404
*/
@ -623,20 +618,24 @@ class Proposals extends DolibarrApi
throw new RestException(500, 'Error when added the contact');
}
return $this->propal;
return array(
'success' => array(
'code' => 200,
'message' => 'Contact linked to the proposal'
)
);
}
/**
* Delete a contact type of given commercial proposal
*
* @param int $id Id of commercial proposal to update
* @param int $contactid Row key of the contact in the array contact_ids.
* @param string $type Type of the contact (BILLING, SHIPPING, CUSTOMER).
* @param int $id Id of commercial proposal to update
* @param int $contactid Row key of the contact in the array contact_ids.
* @param string $type Type of the contact (BILLING, SHIPPING, CUSTOMER).
* @return Object Object with cleaned properties
*
* @url DELETE {id}/contact/{contactid}/{type}
*
* @return int
*
* @throws RestException 401
* @throws RestException 404
* @throws RestException 500 System error
@ -675,10 +674,9 @@ class Proposals extends DolibarrApi
/**
* Update commercial proposal general fields (won't touch lines of commercial proposal)
*
* @param int $id Id of commercial proposal to update
* @param array $request_data Datas
*
* @return int
* @param int $id Id of commercial proposal to update
* @param array $request_data Datas
* @return Object Object with cleaned properties
*/
public function put($id, $request_data = null)
{
@ -722,7 +720,6 @@ class Proposals extends DolibarrApi
* Delete commercial proposal
*
* @param int $id Commercial proposal ID
*
* @return array
*/
public function delete($id)
@ -755,10 +752,9 @@ class Proposals extends DolibarrApi
* Set a proposal to draft
*
* @param int $id Order ID
* @return Object Object with cleaned properties
*
* @url POST {id}/settodraft
*
* @return array
*/
public function settodraft($id)
{
@ -807,6 +803,7 @@ class Proposals extends DolibarrApi
*
* @param int $id Commercial proposal ID
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
* @return Object Object with cleaned properties
*
* @url POST {id}/validate
*
@ -814,8 +811,6 @@ class Proposals extends DolibarrApi
* @throws RestException 401
* @throws RestException 404
* @throws RestException 500 System error
*
* @return array
*/
public function validate($id, $notrigger = 0)
{
@ -860,10 +855,9 @@ class Proposals extends DolibarrApi
* @param int $status Must be 2 (accepted) or 3 (refused) {@min 2}{@max 3}
* @param string $note_private Add this mention at end of private note
* @param int $notrigger Disabled triggers
* @return Object Object with cleaned properties
*
* @url POST {id}/close
*
* @return array
*/
public function close($id, $status, $note_private = '', $notrigger = 0)
{
@ -905,10 +899,9 @@ class Proposals extends DolibarrApi
* Set a commercial proposal billed. Could be also called setbilled
*
* @param int $id Commercial proposal ID
* @return Object Object with cleaned properties
*
* @url POST {id}/setinvoiced
*
* @return array
*/
public function setinvoiced($id)
{
@ -949,6 +942,7 @@ class Proposals extends DolibarrApi
*
* @param array $data Array with data to verify
* @return array
*
* @throws RestException
*/
private function _validate($data)

View File

@ -983,9 +983,10 @@ class Propal extends CommonObject
* Delete detail line
*
* @param int $lineid Id of line to delete
* @param int $id Id of object (for a check)
* @return int >0 if OK, <0 if KO
*/
public function deleteline($lineid)
public function deleteline($lineid, $id = 0)
{
global $user;
@ -994,9 +995,20 @@ class Propal extends CommonObject
$line = new PropaleLigne($this->db);
// For triggers
$line->context = $this->context;
// Load data
$line->fetch($lineid);
if ($id > 0 && $line->fk_propal != $id) {
$this->error = 'ErrorLineIDDoesNotMatchWithObjectID';
return -1;
}
// Memorize previous line for triggers
$staticline = clone $line;
$line->oldline = $staticline;
if ($line->delete($user) > 0) {
$this->update_price(1);

View File

@ -28,7 +28,6 @@ require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
*/
class Orders extends DolibarrApi
{
/**
* @var array $FIELDS Mandatory fields, checked when create and update object
*/
@ -299,7 +298,7 @@ class Orders extends DolibarrApi
*
* @url GET {id}/lines
*
* @return int
* @return array
*/
public function getLines($id)
{
@ -393,13 +392,12 @@ class Orders extends DolibarrApi
/**
* Update a line to given order
*
* @param int $id Id of order to update
* @param int $lineid Id of line to update
* @param array $request_data OrderLine data
* @param int $id Id of order to update
* @param int $lineid Id of line to update
* @param array $request_data OrderLine data
* @return Object|false Object with cleaned properties
*
* @url PUT {id}/lines/{lineid}
*
* @return array|bool
*/
public function putLine($id, $lineid, $request_data = null)
{
@ -458,16 +456,14 @@ class Orders extends DolibarrApi
}
/**
* Delete a line to given order
* Delete a line of a given order
*
*
* @param int $id Id of order to update
* @param int $lineid Id of line to delete
* @param int $id Id of order to update
* @param int $lineid Id of line to delete
* @return Object Object with cleaned properties
*
* @url DELETE {id}/lines/{lineid}
*
* @return int
*
* @throws RestException 401
* @throws RestException 404
*/
@ -486,9 +482,7 @@ class Orders extends DolibarrApi
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
// TODO Check the lineid $lineid is a line of ojbect
$updateRes = $this->commande->deleteline(DolibarrApiAccess::$user, $lineid);
$updateRes = $this->commande->deleteline(DolibarrApiAccess::$user, $lineid, $id);
if ($updateRes > 0) {
return $this->get($id);
} else {
@ -501,13 +495,12 @@ class Orders extends DolibarrApi
*
* Return an array with contact informations
*
* @param int $id ID of order
* @param string $type Type of the contact (BILLING, SHIPPING, CUSTOMER)
* @param int $id ID of order
* @param string $type Type of the contact (BILLING, SHIPPING, CUSTOMER)
* @return Object Object with cleaned properties
*
* @url GET {id}/contacts
*
* @return array data without useless information
*
* @throws RestException
*/
public function getContacts($id, $type = '')
@ -536,11 +529,10 @@ class Orders extends DolibarrApi
* @param int $id Id of order to update
* @param int $contactid Id of contact to add
* @param string $type Type of the contact (BILLING, SHIPPING, CUSTOMER)
* @return array
*
* @url POST {id}/contact/{contactid}/{type}
*
* @return int
*
* @throws RestException 401
* @throws RestException 404
*/
@ -586,7 +578,7 @@ class Orders extends DolibarrApi
*
* @url DELETE {id}/contact/{contactid}/{type}
*
* @return int
* @return array
*
* @throws RestException 401
* @throws RestException 404
@ -630,10 +622,9 @@ class Orders extends DolibarrApi
/**
* Update order general fields (won't touch lines of order)
*
* @param int $id Id of order to update
* @param array $request_data Datas
*
* @return int
* @param int $id Id of order to update
* @param array $request_data Datas
* @return Object Object with cleaned properties
*/
public function put($id, $request_data = null)
{
@ -777,7 +768,6 @@ class Orders extends DolibarrApi
*/
public function reopen($id)
{
if (!DolibarrApiAccess::$user->rights->commande->creer) {
throw new RestException(401);
}
@ -802,12 +792,11 @@ class Orders extends DolibarrApi
/**
* Classify the order as invoiced. Could be also called setbilled
*
* @param int $id Id of the order
* @param int $id Id of the order
* @return Object Object with cleaned properties
*
* @url POST {id}/setinvoiced
*
* @return int
*
* @throws RestException 400
* @throws RestException 401
* @throws RestException 404
@ -851,10 +840,9 @@ class Orders extends DolibarrApi
*
* @param int $id Order ID
* @param int $notrigger Disabled triggers
* @return Object Object with cleaned properties
*
* @url POST {id}/close
*
* @return int
*/
public function close($id, $notrigger = 0)
{
@ -897,10 +885,9 @@ class Orders extends DolibarrApi
*
* @param int $id Order ID
* @param int $idwarehouse Warehouse ID to use for stock change (Used only if option STOCK_CALCULATE_ON_VALIDATE_ORDER is on)
* @return Object Object with cleaned properties
*
* @url POST {id}/settodraft
*
* @return array
*/
public function settodraft($id, $idwarehouse = -1)
{
@ -942,12 +929,11 @@ class Orders extends DolibarrApi
/**
* Create an order using an existing proposal.
*
*
* @param int $proposalid Id of the proposal
* @return Object Object with cleaned properties
*
* @url POST /createfromproposal/{proposalid}
*
* @return int
* @throws RestException 400
* @throws RestException 401
* @throws RestException 404

View File

@ -2379,58 +2379,45 @@ class Commande extends CommonOrder
*
* @param User $user User object
* @param int $lineid Id of line to delete
* @param int $id Id of object (for a check)
* @return int >0 if OK, 0 if nothing to do, <0 if KO
*/
public function deleteline($user = null, $lineid = 0)
public function deleteline($user = null, $lineid = 0, $id = 0)
{
if ($this->statut == self::STATUS_DRAFT) {
$this->db->begin();
$sql = "SELECT fk_product, qty";
$sql .= " FROM ".MAIN_DB_PREFIX."commandedet";
$sql .= " WHERE rowid = ".((int) $lineid);
// Delete line
$line = new OrderLine($this->db);
$result = $this->db->query($sql);
if ($result) {
$obj = $this->db->fetch_object($result);
$line->context = $this->context;
if ($obj) {
$product = new Product($this->db);
$product->id = $obj->fk_product;
// Load data
$line->fetch($lineid);
// Delete line
$line = new OrderLine($this->db);
if ($id > 0 && $line->fk_commande != $id) {
$this->error = 'ErrorLineIDDoesNotMatchWithObjectID';
return -1;
}
// For triggers
$line->fetch($lineid);
// Memorize previous line for triggers
$staticline = clone $line;
$line->oldline = $staticline;
// Memorize previous line for triggers
$staticline = clone $line;
$line->oldline = $staticline;
if ($line->delete($user) > 0) {
$result = $this->update_price(1);
if ($line->delete($user) > 0) {
$result = $this->update_price(1);
if ($result > 0) {
$this->db->commit();
return 1;
} else {
$this->db->rollback();
$this->error = $this->db->lasterror();
return -1;
}
} else {
$this->db->rollback();
$this->error = $line->error;
return -1;
}
if ($result > 0) {
$this->db->commit();
return 1;
} else {
$this->db->rollback();
return 0;
$this->error = $this->db->lasterror();
return -1;
}
} else {
$this->db->rollback();
$this->error = $this->db->lasterror();
$this->error = $line->error;
return -1;
}
} else {

View File

@ -65,9 +65,9 @@ class Invoices extends DolibarrApi
*
* Return an array with invoice informations
*
* @param int $id ID of invoice
* @param int $contact_list 0:Return array contains all properties, 1:Return array contains just id, -1: Do not return contacts/adddesses
* @return array|mixed data without useless information
* @param int $id ID of invoice
* @param int $contact_list 0:Return array contains all properties, 1:Return array contains just id, -1: Do not return contacts/adddesses
* @return Object Object with cleaned properties
*
* @throws RestException
*/
@ -81,9 +81,9 @@ class Invoices extends DolibarrApi
*
* Return an array with invoice informations
*
* @param string $ref Ref of object
* @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id, -1: Do not return contacts/adddesses
* @return array|mixed data without useless information
* @param string $ref Ref of object
* @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id, -1: Do not return contacts/adddesses
* @return Object Object with cleaned properties
*
* @url GET ref/{ref}
*
@ -99,9 +99,9 @@ class Invoices extends DolibarrApi
*
* Return an array with invoice informations
*
* @param string $ref_ext External reference of object
* @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id, -1: Do not return contacts/adddesses
* @return array|mixed data without useless information
* @param string $ref_ext External reference of object
* @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id, -1: Do not return contacts/adddesses
* @return Object Object with cleaned properties
*
* @url GET ref_ext/{ref_ext}
*
@ -117,11 +117,11 @@ class Invoices extends DolibarrApi
*
* Return an array with invoice informations
*
* @param int $id ID of order
* @param string $ref Ref of object
* @param string $ref_ext External reference of object
* @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id, -1: Do not return contacts/adddesses
* @return array|mixed data without useless information
* @param int $id ID of order
* @param string $ref Ref of object
* @param string $ref_ext External reference of object
* @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id, -1: Do not return contacts/adddesses
* @return Object Object with cleaned properties
*
* @throws RestException
*/
@ -325,12 +325,11 @@ class Invoices extends DolibarrApi
/**
* Create an invoice using an existing order.
*
*
* @param int $orderid Id of the order
* @return Object Object with cleaned properties
*
* @url POST /createfromorder/{orderid}
*
* @return int
* @throws RestException 400
* @throws RestException 401
* @throws RestException 404
@ -338,7 +337,6 @@ class Invoices extends DolibarrApi
*/
public function createInvoiceFromOrder($orderid)
{
require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
if (!DolibarrApiAccess::$user->rights->commande->lire) {
@ -368,11 +366,10 @@ class Invoices extends DolibarrApi
/**
* Get lines of an invoice
*
* @param int $id Id of invoice
* @param int $id Id of invoice
* @return array Array of lines
*
* @url GET {id}/lines
*
* @return int
*/
public function getLines($id)
{
@ -399,14 +396,13 @@ class Invoices extends DolibarrApi
/**
* Update a line to a given invoice
*
* @param int $id Id of invoice to update
* @param int $lineid Id of line to update
* @param array $request_data InvoiceLine data
* @param int $id Id of invoice to update
* @param int $lineid Id of line to update
* @param array $request_data InvoiceLine data
* @return Object Object with cleaned properties
*
* @url PUT {id}/lines/{lineid}
*
* @return array
*
* @throws RestException 304
* @throws RestException 401
* @throws RestException 404 Invoice not found
@ -472,14 +468,13 @@ class Invoices extends DolibarrApi
/**
* Add a contact type of given invoice
*
* @param int $id Id of invoice to update
* @param int $contactid Id of contact to add
* @param string $type Type of the contact (BILLING, SHIPPING, CUSTOMER)
* @param int $id Id of invoice to update
* @param int $contactid Id of contact to add
* @param string $type Type of the contact (BILLING, SHIPPING, CUSTOMER)
* @return array
*
* @url POST {id}/contact/{contactid}/{type}
*
* @return int
*
* @throws RestException 401
* @throws RestException 404
*/
@ -509,20 +504,24 @@ class Invoices extends DolibarrApi
throw new RestException(500, 'Error when added the contact');
}
return $this->_cleanObjectDatas($this->invoice);
return array(
'success' => array(
'code' => 200,
'message' => 'Contact linked to the invoice'
)
);
}
/**
* Delete a contact type of given invoice
*
* @param int $id Id of invoice to update
* @param int $contactid Row key of the contact in the array contact_ids.
* @param string $type Type of the contact (BILLING, SHIPPING, CUSTOMER).
* @param int $id Id of invoice to update
* @param int $contactid Row key of the contact in the array contact_ids.
* @param string $type Type of the contact (BILLING, SHIPPING, CUSTOMER).
* @return Object Object with cleaned properties
*
* @url DELETE {id}/contact/{contactid}/{type}
*
* @return array
*
* @throws RestException 401
* @throws RestException 404
* @throws RestException 500 System error
@ -561,13 +560,12 @@ class Invoices extends DolibarrApi
/**
* Deletes a line of a given invoice
*
* @param int $id Id of invoice
* @param int $lineid Id of the line to delete
* @param int $id Id of invoice
* @param int $lineid Id of the line to delete
* @return Object Object with cleaned properties
*
* @url DELETE {id}/lines/{lineid}
*
* @return array
*
* @throws RestException 400
* @throws RestException 401
* @throws RestException 404
@ -575,7 +573,6 @@ class Invoices extends DolibarrApi
*/
public function deleteLine($id, $lineid)
{
if (!DolibarrApiAccess::$user->rights->facture->creer) {
throw new RestException(401);
}
@ -592,9 +589,7 @@ class Invoices extends DolibarrApi
throw new RestException(404, 'Invoice not found');
}
// TODO Check the lineid $lineid is a line of ojbect
$updateRes = $this->invoice->deleteline($lineid);
$updateRes = $this->invoice->deleteline($lineid, $id);
if ($updateRes > 0) {
return $this->get($id);
} else {
@ -605,9 +600,9 @@ class Invoices extends DolibarrApi
/**
* Update invoice
*
* @param int $id Id of invoice to update
* @param array $request_data Datas
* @return int
* @param int $id Id of invoice to update
* @param array $request_data Datas
* @return Object|false Object with cleaned properties
*/
public function put($id, $request_data = null)
{
@ -648,8 +643,8 @@ class Invoices extends DolibarrApi
/**
* Delete invoice
*
* @param int $id Invoice ID
* @return array
* @param int $id Invoice ID
* @return array
*/
public function delete($id)
{
@ -829,11 +824,10 @@ class Invoices extends DolibarrApi
*
* @param int $id Order ID
* @param int $idwarehouse Warehouse ID
* @return Object Object with cleaned properties
*
* @url POST {id}/settodraft
*
* @return array
*
* @throws RestException 304
* @throws RestException 401
* @throws RestException 404
@ -887,10 +881,9 @@ class Invoices extends DolibarrApi
* @param int $id Invoice ID
* @param int $idwarehouse Warehouse ID
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
* @return Object|false Object with cleaned properties
*
* @url POST {id}/validate
*
* @return array
*/
public function validate($id, $idwarehouse = 0, $notrigger = 0)
{
@ -932,11 +925,10 @@ class Invoices extends DolibarrApi
* @param int $id Order ID
* @param string $close_code Code filled if we classify to 'Paid completely' when payment is not complete (for escompte for example)
* @param string $close_note Comment defined if we classify to 'Paid' when payment is not complete (for escompte for example)
* @return Object Object with cleaned properties
*
* @url POST {id}/settopaid
*
* @return array An invoice object
*
* @throws RestException 304
* @throws RestException 401
* @throws RestException 404
@ -981,12 +973,11 @@ class Invoices extends DolibarrApi
/**
* Sets an invoice as unpaid
*
* @param int $id Order ID
* @param int $id Order ID
* @return Object Object with cleaned properties
*
* @url POST {id}/settounpaid
*
* @return array An invoice object
*
* @throws RestException 304
* @throws RestException 401
* @throws RestException 404
@ -1031,10 +1022,9 @@ class Invoices extends DolibarrApi
* Get discount from invoice
*
* @param int $id Id of invoice
* @return Object Object with cleaned properties
*
* @url GET {id}/discount
*
* @return mixed
*/
public function getDiscount($id)
{
@ -1069,10 +1059,10 @@ class Invoices extends DolibarrApi
/**
* Create a discount (credit available) for a credit note or a deposit.
*
* @param int $id Invoice ID
* @url POST {id}/markAsCreditAvailable
* @param int $id Invoice ID
* @return Object Object with cleaned properties
*
* @return array An invoice object
* @url POST {id}/markAsCreditAvailable
*
* @throws RestException 304
* @throws RestException 401
@ -1241,11 +1231,10 @@ class Invoices extends DolibarrApi
*
* @param int $id Id of invoice
* @param int $discountid Id of discount
* @return int
*
* @url POST {id}/usediscount/{discountid}
*
* @return int
*
* @throws RestException 400
* @throws RestException 401
* @throws RestException 404
@ -1253,7 +1242,6 @@ class Invoices extends DolibarrApi
*/
public function useDiscount($id, $discountid)
{
if (!DolibarrApiAccess::$user->rights->facture->creer) {
throw new RestException(401);
}
@ -1288,11 +1276,10 @@ class Invoices extends DolibarrApi
*
* @param int $id Id of invoice
* @param int $discountid Id of a discount coming from a credit note
* @return int
*
* @url POST {id}/usecreditnote/{discountid}
*
* @return int
*
* @throws RestException 400
* @throws RestException 401
* @throws RestException 404
@ -1300,7 +1287,6 @@ class Invoices extends DolibarrApi
*/
public function useCreditNote($id, $discountid)
{
require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
if (!DolibarrApiAccess::$user->rights->facture->creer) {
@ -1333,12 +1319,11 @@ class Invoices extends DolibarrApi
/**
* Get list of payments of a given invoice
*
* @param int $id Id of invoice
* @param int $id Id of invoice
* @return array
*
* @url GET {id}/payments
*
* @return array
*
* @throws RestException 400
* @throws RestException 401
* @throws RestException 404
@ -1395,8 +1380,6 @@ class Invoices extends DolibarrApi
*/
public function addPayment($id, $datepaye, $paymentid, $closepaidinvoices, $accountid, $num_payment = '', $comment = '', $chqemetteur = '', $chqbank = '')
{
global $conf;
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
if (!DolibarrApiAccess::$user->rights->facture->creer) {
@ -1509,6 +1492,7 @@ class Invoices extends DolibarrApi
* @url POST /paymentsdistributed
*
* @return int Payment ID
*
* @throws RestException 400
* @throws RestException 401
* @throws RestException 403
@ -1516,8 +1500,6 @@ class Invoices extends DolibarrApi
*/
public function addPaymentDistributed($arrayofamounts, $datepaye, $paymentid, $closepaidinvoices, $accountid, $num_payment = '', $comment = '', $chqemetteur = '', $chqbank = '', $ref_ext = '', $accepthigherpayment = false)
{
global $conf;
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
if (!DolibarrApiAccess::$user->rights->facture->creer) {
@ -1645,6 +1627,7 @@ class Invoices extends DolibarrApi
* @url PUT payments/{id}
*
* @return array
*
* @throws RestException 400 Bad parameters
* @throws RestException 401 Not allowed
* @throws RestException 404 Not found
@ -1708,8 +1691,8 @@ class Invoices extends DolibarrApi
/**
* Validate fields before create or update object
*
* @param array|null $data Datas to validate
* @return array
* @param array|null $data Datas to validate
* @return array
*
* @throws RestException
*/
@ -1733,7 +1716,7 @@ class Invoices extends DolibarrApi
*
* @param int $id ID of template invoice
* @param int $contact_list 0:Return array contains all properties, 1:Return array contains just id, -1: Do not return contacts/adddesses
* @return array|mixed data without useless information
* @return Object Object with cleaned properties
*
* @url GET templates/{id}
*
@ -1749,11 +1732,11 @@ class Invoices extends DolibarrApi
*
* Return an array with invoice informations
*
* @param int $id ID of order
* @param string $ref Ref of object
* @param string $ref_ext External reference of object
* @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id, -1: Do not return contacts/adddesses
* @return array|mixed data without useless information
* @param int $id ID of order
* @param string $ref Ref of object
* @param string $ref_ext External reference of object
* @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id, -1: Do not return contacts/adddesses
* @return Object Object with cleaned properties
*
* @throws RestException
*/

View File

@ -4148,9 +4148,10 @@ class Facture extends CommonInvoice
* Delete line in database
*
* @param int $rowid Id of line to delete
* @param int $id Id of object (for a check)
* @return int <0 if KO, >0 if OK
*/
public function deleteline($rowid)
public function deleteline($rowid, $id = 0)
{
global $user;
@ -4161,6 +4162,22 @@ class Facture extends CommonInvoice
return -1;
}
$line = new FactureLigne($this->db);
$line->context = $this->context;
// Load line
$result = $line->fetch($rowid);
if (!($result > 0)) {
dol_print_error($this->db, $line->error, $line->errors);
return -1;
}
if ($id > 0 && $line->fk_facture != $id) {
$this->error = 'ErrorLineIDDoesNotMatchWithObjectID';
return -1;
}
$this->db->begin();
// Free discount linked to invoice line
@ -4176,15 +4193,9 @@ class Facture extends CommonInvoice
return -1;
}
$line = new FactureLigne($this->db);
$line->context = $this->context;
// For triggers
$result = $line->fetch($rowid);
if (!($result > 0)) {
dol_print_error($this->db, $line->error, $line->errors);
}
// Memorize previous line for triggers
$staticline = clone $line;
$line->oldline = $staticline;
if ($line->delete($user) > 0) {
$result = $this->update_price(1);

View File

@ -1347,7 +1347,7 @@ class Form
* @param bool $multiple add [] in the name of element and add 'multiple' attribut
* @param array $excludeids Exclude IDs from the select combo
* @param int $showcode Show code in list
* @return string HTML string with
* @return array|string HTML string with
*/
public function select_thirdparty_list($selected = '', $htmlname = 'socid', $filter = '', $showempty = '', $showtype = 0, $forcecombo = 0, $events = array(), $filterkey = '', $outputmode = 0, $limit = 0, $morecss = 'minwidth100', $moreparam = '', $multiple = false, $excludeids = array(), $showcode = 0)
{
@ -1936,7 +1936,7 @@ class Form
* @param int $outputmode 0=HTML select string, 1=Array
* @param bool $multiple add [] in the name of element and add 'multiple' attribut
* @param int $forcecombo Force the component to be a simple combo box without ajax
* @return string HTML select string
* @return array|string HTML select string
* @see select_dolgroups()
*/
public function select_dolusers($selected = '', $htmlname = 'userid', $show_empty = 0, $exclude = null, $disabled = 0, $include = '', $enableonly = '', $force_entity = '0', $maxlength = 0, $showstatus = 0, $morefilter = '', $show_every = 0, $enableonlytext = '', $morecss = '', $notdisabled = 0, $outputmode = 0, $multiple = false, $forcecombo = 0)
@ -3791,7 +3791,7 @@ class Form
* @param int $socid Id of company
* @param string $htmlname Name of HTML field
* @param int $showempty Add an empty field
* @return integer|null
* @return integer
*/
public function select_address($selected, $socid, $htmlname = 'address_id', $showempty = 0)
{
@ -3827,7 +3827,7 @@ class Form
return $num;
} else {
dol_print_error($this->db);
return;
return -1;
}
}
@ -7139,7 +7139,7 @@ class Form
* @param string $showempty '' to not show empty line. Translation key to show an empty line. '1' show empty line with no text.
* @param int $forcecombo Force to use combo box
* @param string $morecss Add more css on select
* @return array Array of keys for json
* @return array|string Array of keys for json or HTML component
*/
public function selectTicketsList($selected = '', $htmlname = 'ticketid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
{
@ -7345,7 +7345,7 @@ class Form
* @param string $showempty '' to not show empty line. Translation key to show an empty line. '1' show empty line with no text.
* @param int $forcecombo Force to use combo box
* @param string $morecss Add more css on select
* @return array Array of keys for json
* @return array|string Array of keys for json or HTML component
*/
public function selectProjectsList($selected = '', $htmlname = 'projectid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
{
@ -7560,7 +7560,7 @@ class Form
* @param string $showempty '' to not show empty line. Translation key to show an empty line. '1' show empty line with no text.
* @param int $forcecombo Force to use combo box
* @param string $morecss Add more css on select
* @return array Array of keys for json
* @return array|string Array of keys for json or HTML string component
*/
public function selectMembersList($selected = '', $htmlname = 'adherentid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
{

View File

@ -982,7 +982,7 @@ class Ldap
*
* @param string $filterrecord Record
* @param string $attribute Attributes
* @return void
* @return array|boolean
*/
public function getAttributeValues($filterrecord, $attribute)
{
@ -1025,7 +1025,7 @@ class Ldap
* @param array $attributeArray Array of fields required. Note this array must also contains field $useridentifier (Ex: sn,userPassword)
* @param int $activefilter '1' or 'user'=use field this->filter as filter instead of parameter $search, 'group'=use field this->filtergroup as filter, 'member'=use field this->filtermember as filter
* @param array $attributeAsArray Array of fields wanted as an array not a string
* @return array Array of [id_record][ldap_field]=value
* @return array|int Array of [id_record][ldap_field]=value
*/
public function getRecords($search, $userDn, $useridentifier, $attributeArray, $activefilter = 0, $attributeAsArray = array())
{
@ -1342,7 +1342,7 @@ class Ldap
* UserAccountControl Flgs to more human understandable form...
*
* @param string $uacf UACF
* @return void
* @return array
*/
public function parseUACF($uacf)
{
@ -1382,7 +1382,7 @@ class Ldap
}
//Return human friendly flags
return($retval);
return $retval;
}
/**
@ -1414,7 +1414,7 @@ class Ldap
$retval = "UNKNOWN_TYPE_".$samtype;
}
return($retval);
return $retval;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps

View File

@ -175,7 +175,7 @@ class RssParser
/**
* getItems
*
* @return string
* @return array
*/
public function getItems()
{
@ -801,8 +801,8 @@ class RssParser
/**
* Function to convert an XML object into an array
*
* @param SimpleXMLElement $xml Xml
* @return void
* @param SimpleXMLElement $xml Xml
* @return array|string
*/
function xml2php($xml)
{

View File

@ -35,11 +35,10 @@
* @param string $ftp_password FTP password
* @param string $section Directory
* @param integer $ftp_passive Use a passive mode
* @return int <0 if OK, >0 if KO
* @return array Result of connect
*/
function dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive = 0)
{
global $langs, $conf;
$ok = 1;
@ -127,7 +126,6 @@ function dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $sect
*/
function ftp_isdir($connect_id, $dir)
{
if (@ftp_chdir($connect_id, $dir)) {
ftp_cdup($connect_id);
return 1;
@ -140,11 +138,10 @@ function ftp_isdir($connect_id, $dir)
* Tell if an entry is a FTP directory
*
* @param resource $connect_id Connection handler
* @return result
* @return boolean Result of closing
*/
function dol_ftp_close($connect_id)
{
global $conf;
// Close FTP connection
@ -196,7 +193,7 @@ function dol_ftp_delete($connect_id, $file, $newsection)
* @param string $localfile The local file path
* @param string $file The remote file path
* @param string $newsection $newsection
* @return result
* @return bool|resource
*/
function dol_ftp_get($connect_id, $localfile, $file, $newsection)
{
@ -226,11 +223,10 @@ function dol_ftp_get($connect_id, $localfile, $file, $newsection)
* @param string $file File name
* @param string $localfile The path to the local file
* @param string $newsection $newsection
* @return result
* @return boolean
*/
function dol_ftp_put($connect_id, $file, $localfile, $newsection)
{
global $conf;
if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
@ -255,11 +251,10 @@ function dol_ftp_put($connect_id, $file, $localfile, $newsection)
* @param resource $connect_id Connection handler
* @param string $file File
* @param string $newsection $newsection
* @return result
* @return boolean
*/
function dol_ftp_rmdir($connect_id, $file, $newsection)
{
global $conf;
if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {
@ -285,11 +280,10 @@ function dol_ftp_rmdir($connect_id, $file, $newsection)
* @param resource $connect_id Connection handler
* @param string $newdir Dir create
* @param string $newsection $newsection
* @return result
* @return boolean|string
*/
function dol_ftp_mkdir($connect_id, $newdir, $newsection)
{
global $conf;
if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) {

View File

@ -1734,9 +1734,9 @@ class ExpenseReport extends CommonObject
/**
* Update total of an expense report when you add a line.
*
* @param string $ligne_total_ht Amount without taxes
* @param string $ligne_total_ht Amount without taxes
* @param string $ligne_total_tva Amount of all taxes
* @return void
* @return int
*/
public function update_totaux_add($ligne_total_ht, $ligne_total_tva)
{
@ -1885,7 +1885,7 @@ class ExpenseReport extends CommonObject
*
* @param int $type Type of line
* @param string $seller Seller, but actually he is unknown
* @return true or false
* @return boolean true or false
*/
public function checkRules($type = 0, $seller = '')
{

View File

@ -4086,11 +4086,11 @@ function migrate_rename_directories($db, $langs, $conf, $oldname, $newname)
* @param DoliDB $db Database handler
* @param Translate $langs Object langs
* @param Conf $conf Object conf
* @return void
* @return boolean
*/
function migrate_delete_old_files($db, $langs, $conf)
{
$result = true;
$ret = true;
dolibarr_install_syslog("upgrade2::migrate_delete_old_files");
@ -4155,7 +4155,6 @@ function migrate_delete_old_files($db, $langs, $conf)
foreach ($filetodeletearray as $filetodelete) {
//print '<b>'DOL_DOCUMENT_ROOT.$filetodelete."</b><br>\n";
$result = 1;
if (file_exists(DOL_DOCUMENT_ROOT.$filetodelete)) {
$result = dol_delete_file(DOL_DOCUMENT_ROOT.$filetodelete, 0, 0, 0, null, true, false);
if (!$result) {
@ -4167,7 +4166,8 @@ function migrate_delete_old_files($db, $langs, $conf)
}
}
}
return $result;
return $ret;
}
/**
@ -4176,11 +4176,11 @@ function migrate_delete_old_files($db, $langs, $conf)
* @param DoliDB $db Database handler
* @param Translate $langs Object langs
* @param Conf $conf Object conf
* @return void
* @return boolean
*/
function migrate_delete_old_dir($db, $langs, $conf)
{
$result = true;
$ret = true;
dolibarr_install_syslog("upgrade2::migrate_delete_old_dir");
@ -4206,7 +4206,8 @@ function migrate_delete_old_dir($db, $langs, $conf)
print ' '.$langs->trans("RemoveItManuallyAndPressF5ToContinue").'</div>';
}
}
return $result;
return $ret;
}

View File

@ -1487,7 +1487,7 @@ class Mo extends CommonObject
/**
* Function used to return childs of Mo
*
* @return array if OK, -1 if KO
* @return array|int array if OK, -1 if KO
*/
public function getMoChilds()
{
@ -1525,11 +1525,10 @@ class Mo extends CommonObject
/**
* Function used to return childs of Mo
*
* @return object Mo if OK, -1 if KO, 0 if not exist
* @return Object|int MO object if OK, -1 if KO, 0 if not exist
*/
public function getMoParent()
{
$MoParent = new Mo($this->db);
$error = 0;

View File

@ -1079,8 +1079,8 @@ class Products extends DolibarrApi
/**
* Get attribute by ID.
*
* @param int $id ID of Attribute
* @return array
* @param int $id ID of Attribute
* @return Object Object with cleaned properties
*
* @throws RestException 401
* @throws RestException 404
@ -1116,7 +1116,7 @@ class Products extends DolibarrApi
$obj = $this->db->fetch_object($resql);
$prodattr->is_used_by_products = (int) $obj->nb;
return $prodattr;
return $this->_cleanObjectDatas($prodattr);
}
/**
@ -1213,6 +1213,7 @@ class Products extends DolibarrApi
$resql = $this->db->query($sql);
$obj = $this->db->fetch_object($resql);
$attr["is_used_by_products"] = (int) $obj->nb;
return $attr;
@ -1246,15 +1247,16 @@ class Products extends DolibarrApi
if ($resid <= 0) {
throw new RestException(500, "Error creating new attribute");
}
return $resid;
}
/**
* Update attributes by id.
*
* @param int $id ID of Attribute
* @param array $request_data Datas
* @return array
* @param int $id ID of Attribute
* @param array $request_data Datas
* @return Object Object with cleaned properties
*
* @throws RestException
* @throws RestException 401
@ -1291,7 +1293,7 @@ class Products extends DolibarrApi
} elseif ($result < 0) {
throw new RestException(500, "Error fetching attribute");
} else {
return $prodattr;
return $this->_cleanObjectDatas($prodattr);
}
}
throw new RestException(500, "Error updating attribute");
@ -1560,9 +1562,9 @@ class Products extends DolibarrApi
/**
* Update attribute value.
*
* @param int $id ID of Attribute
* @param array $request_data Datas
* @return array
* @param int $id ID of Attribute
* @param array $request_data Datas
* @return Object Object with cleaned properties
*
* @throws RestException 401
* @throws RestException 500 System error
@ -1598,7 +1600,7 @@ class Products extends DolibarrApi
} elseif ($result < 0) {
throw new RestException(500, "Error fetching attribute");
} else {
return $objectval;
return $this->_cleanObjectDatas($objectval);
}
}
throw new RestException(500, "Error updating attribute");
@ -1887,7 +1889,7 @@ class Products extends DolibarrApi
*
* @param int $id ID of Product
* @param int $selected_warehouse_id ID of warehouse
* @return int
* @return array
*
* @throws RestException 500 System error
* @throws RestException 401
@ -1897,7 +1899,6 @@ class Products extends DolibarrApi
*/
public function getStock($id, $selected_warehouse_id = null)
{
if (!DolibarrApiAccess::$user->rights->produit->lire || !DolibarrApiAccess::$user->rights->stock->lire) {
throw new RestException(401);
}
@ -1923,7 +1924,7 @@ class Products extends DolibarrApi
throw new RestException(404, 'No stock found');
}
return ['stock_warehouses'=>$stockData];
return array('stock_warehouses'=>$stockData);
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore

View File

@ -812,7 +812,7 @@ class Task extends CommonObjectLine
* @param array $search_array_options Array of search
* @param int $loadextras Fetch all Extrafields on each task
* @param int $loadRoleMode 1= will test Roles on task; 0 used in delete project action
* @return array Array of tasks
* @return array|string Array of tasks
*/
public function getTasksArray($usert = null, $userp = null, $projectid = 0, $socid = 0, $mode = 0, $filteronproj = '', $filteronprojstatus = '-1', $morewherefilter = '', $filteronprojuser = 0, $filterontaskuser = 0, $extrafields = array(), $includebilltime = 0, $search_array_options = array(), $loadextras = 0, $loadRoleMode = 1)
{
@ -1063,7 +1063,7 @@ class Task extends CommonObjectLine
* @param int $projectid Project id list separated with , to filter on project
* @param int $taskid Task id to filter on a task
* @param integer $filteronprojstatus Filter on project status if userp is set. Not used if userp not defined.
* @return array Array (projectid => 'list of roles for project' or taskid => 'list of roles for task')
* @return array|int Array (projectid => 'list of roles for project' or taskid => 'list of roles for task')
*/
public function getUserRolesForProjectsOrTasks($userp, $usert, $projectid = '', $taskid = 0, $filteronprojstatus = -1)
{
@ -1398,12 +1398,10 @@ class Task extends CommonObjectLine
*
* @param User|int $userobj Filter on user. null or 0=No filter
* @param string $morewherefilter Add more filter into where SQL request (must start with ' AND ...')
* @return array Array of info for task array('min_date', 'max_date', 'total_duration', 'total_amount', 'nblines', 'nblinesnull')
* @return array|int Array of info for task array('min_date', 'max_date', 'total_duration', 'total_amount', 'nblines', 'nblinesnull')
*/
public function getSummaryOfTimeSpent($userobj = null, $morewherefilter = '')
{
global $langs;
if (is_object($userobj)) {
$userid = $userobj->id;
} else {
@ -1567,14 +1565,12 @@ class Task extends CommonObjectLine
/**
* Load all records of time spent
*
* @param User $userobj User object
* @param string $morewherefilter Add more filter into where SQL request (must start with ' AND ...')
* @return int <0 if KO, array of time spent if OK
* @param User $userobj User object
* @param string $morewherefilter Add more filter into where SQL request (must start with ' AND ...')
* @return array|int <0 if KO, array of time spent if OK
*/
public function fetchAllTimeSpent(User $userobj, $morewherefilter = '')
{
global $langs;
$arrayres = array();
$sql = "SELECT";

View File

@ -1789,11 +1789,11 @@ class Ticket extends CommonObject
/**
* Search and fetch thirparties by email
*
* @param string $email Email
* @param int $type Type of thirdparties (0=any, 1=customer, 2=prospect, 3=supplier)
* @param array $filters Array of couple field name/value to filter the companies with the same name
* @param string $clause Clause for filters
* @return array Array of thirdparties object
* @param string $email Email
* @param int $type Type of thirdparties (0=any, 1=customer, 2=prospect, 3=supplier)
* @param array $filters Array of couple field name/value to filter the companies with the same name
* @param string $clause Clause for filters
* @return array|int Array of thirdparties object
*/
public function searchSocidByEmail($email, $type = '0', $filters = array(), $clause = 'AND')
{
@ -1854,10 +1854,10 @@ class Ticket extends CommonObject
/**
* Search and fetch contacts by email
*
* @param string $email Email
* @param array $socid Limit to a thirdparty
* @param string $case Respect case
* @return array Array of contacts object
* @param string $email Email
* @param array $socid Limit to a thirdparty
* @param string $case Respect case
* @return array|int Array of contacts object
*/
public function searchContactByEmail($email, $socid = '', $case = '')
{
@ -1900,8 +1900,8 @@ class Ticket extends CommonObject
/**
* Define parent commany of current ticket
*
* @param int $id Id of thirdparty to set or '' to remove
* @return int <0 if KO, >0 if OK
* @param int $id Id of thirdparty to set or '' to remove
* @return int <0 if KO, >0 if OK
*/
public function setCustomer($id)
{
@ -2075,7 +2075,7 @@ class Ticket extends CommonObject
* @param string $source Source of contact: external or thirdparty (llx_socpeople) or internal (llx_user)
* @param int $list 0:Return array contains all properties, 1:Return array contains just id
* @param string $code Filter on this code of contact type ('SHIPPING', 'BILLING', ...)
* @return array Array of contacts
* @return array|int Array of contacts
*/
public function listeContact($status = -1, $source = 'external', $list = 0, $code = '')
{
@ -2364,7 +2364,7 @@ class Ticket extends CommonObject
}
}
return;
return 1;
}
/**

View File

@ -119,6 +119,11 @@ class ProductAttribute extends CommonObject
*/
public $line;
/**
* @var int Number of product that use this attribute
*/
public $is_used_by_products;
/**
* Constructor