20use Luracast\Restler\RestException;
54 $this->paiement =
new Paiement($this->db);
75 public function get(
$id)
77 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
78 throw new RestException(403);
81 $result = $this->paiement->fetch(
$id);
83 throw new RestException(404,
'Paiement not found');
109 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'')
112 $tmpobject =
new Paiement($this->db);
114 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
115 throw new RestException(403);
118 $sql =
"SELECT t.rowid";
119 $sql .=
" FROM ".$this->db->prefix().$tmpobject->table_element.
" AS t";
120 $sql .=
" WHERE 1 = 1";
121 if ($tmpobject->ismultientitymanaged) {
122 $sql .=
' AND t.entity IN ('.getEntity($tmpobject->element).
')';
128 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
132 $sql .= $this->db->order($sortfield, $sortorder);
137 $offset = $limit * $page;
139 $sql .= $this->db->plimit($limit + 1, $offset);
142 $result = $this->db->query($sql);
145 $num = $this->db->num_rows($result);
146 $min = min($num, ($limit <= 0 ? $num : $limit));
148 $obj = $this->db->fetch_object($result);
149 $tmp_object =
new Paiement($this->db);
150 if ($tmp_object->fetch($obj->rowid)) {
156 throw new RestException(503,
'Error when retrieving Paiement list: '.$this->db->lasterror());
179 public function put(
$id, $request_data =
null)
181 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
182 throw new RestException(403);
185 $result = $this->paiement->fetch(
$id);
187 throw new RestException(404,
'paiement not found');
190 foreach ($request_data as $field => $value) {
191 if ($field ==
'id') {
194 if ($field ===
'caller') {
196 $this->paiement->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
200 $this->paiement->$field = $this->
_checkValForAPI($field, $value, $this->paiement);
206 if ($this->paiement->update(DolibarrApiAccess::$user, 0) > 0) {
207 return $this->
get(
$id);
209 throw new RestException(500, $this->paiement->error);
227 public function delete(
$id)
229 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'supprimer')) {
230 throw new RestException(403);
233 $result = $this->paiement->fetch(
$id);
235 throw new RestException(404,
'Paiement not found');
238 if ($this->paiement->delete(DolibarrApiAccess::$user) == 0) {
239 throw new RestException(409,
'Error when deleting Paiement : '.$this->paiement->error);
240 } elseif ($this->paiement->delete(DolibarrApiAccess::$user) < 0) {
241 throw new RestException(500,
'Error when deleting Paiement : '.$this->paiement->error);
247 'message' =>
'Paiement deleted'
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
_filterObjectProperties($object, $properties)
Filter properties that will be returned on object.
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
Class to manage payments of customer invoices.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $sqlfilters='', $properties='')
List paiements.
put($id, $request_data=null)
Update paiement.
__construct()
Constructor.
_cleanObjectDatas($object)
Clean sensitive object data fields @phpstan-template T.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.