Skip to content

Commit

Permalink
Merge pull request #11132 from ptibogxiv/patch-174
Browse files Browse the repository at this point in the history
NEW add API shipment mode dictionnary
  • Loading branch information
eldy committed Jun 20, 2019
2 parents 77a45b8 + 40023c8 commit 06e5fbd
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
63 changes: 62 additions & 1 deletion htdocs/api/class/api_setup.class.php
Expand Up @@ -4,7 +4,7 @@
* Copyright (C) 2017 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2017 Neil Orley <neil.orley@oeris.fr>
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2019 Thibault FOUCART <support@ptibogxiv.net>
* Copyright (C) 2018-2019 Thibault FOUCART <support@ptibogxiv.net>
*
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -707,6 +707,67 @@ public function getPaymentTerms($sortfield = "sortorder", $sortorder = 'ASC', $l

return $list;
}

/**
* Get the list of shipping methods.
*
* @param int $limit Number of items per page
* @param int $page Page number {@min 0}
* @param int $active Shipping methodsm is active or not {@min 0} {@max 1}
* @param string $sqlfilters SQL criteria to filter. Syntax example "(t.code:=:'CHQ')"
*
* @url GET dictionary/shipping_methods
*
* @return array List of shipping methods
*
* @throws 400 RestException
* @throws 200 OK
*/
public function getShippingModes($limit = 100, $page = 0, $active = 1, $sqlfilters = '')
{
$list = array();

$sql = "SELECT rowid as id, code, libelle as label, description, tracking, module";
$sql.= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as t";
$sql.= " WHERE t.entity IN (".getEntity('c_shipment_mode').")";
$sql.= " AND t.active = ".$active;
// Add sql filters
if ($sqlfilters)
{
if (! DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(400, 'Error when validating parameter sqlfilters '.$sqlfilters);
}
$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
}


//$sql.= $this->db->order($sortfield, $sortorder);

if ($limit) {
if ($page < 0) {
$page = 0;
}
$offset = $limit * $page;

$sql .= $this->db->plimit($limit, $offset);
}

$result = $this->db->query($sql);

if ($result) {
$num = $this->db->num_rows($result);
$min = min($num, ($limit <= 0 ? $num : $limit));
for ($i = 0; $i < $min; $i++) {
$list[] = $this->db->fetch_object($result);
}
} else {
throw new RestException(400, $this->db->lasterror());
}

return $list;
}

/**
* Get the list of measuring units.
Expand Down
2 changes: 1 addition & 1 deletion htdocs/install/mysql/tables/llx_c_shipment_mode.key.sql
Expand Up @@ -16,5 +16,5 @@
--
-- ===================================================================

ALTER TABLE llx_c_shipment_mode ADD UNIQUE INDEX uk_c_shipment_mode (code);
ALTER TABLE llx_c_shipment_mode ADD UNIQUE INDEX uk_c_shipment_mode (code, entity);

1 change: 1 addition & 0 deletions htdocs/install/mysql/tables/llx_c_shipment_mode.sql
Expand Up @@ -19,6 +19,7 @@
create table llx_c_shipment_mode
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
entity integer DEFAULT 1 NOT NULL, -- multi company id
tms timestamp,
code varchar(30) NOT NULL,
libelle varchar(50) NOT NULL,
Expand Down

0 comments on commit 06e5fbd

Please sign in to comment.