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');
86 throw new RestException(403,
'Access to this payment not allowed for this user');
112 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'')
115 $tmpobject =
new Paiement($this->db);
117 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
118 throw new RestException(403);
121 $sql =
"SELECT t.rowid";
122 $sql .=
" FROM ".$this->db->prefix().$tmpobject->table_element.
" AS t";
123 $sql .=
" WHERE 1 = 1";
124 if ($tmpobject->ismultientitymanaged) {
125 $sql .=
' AND t.entity IN ('.getEntity($tmpobject->element).
')';
128 $socid = (int) DolibarrApiAccess::$user->socid;
130 $sql .=
" AND EXISTS (SELECT pf.rowid FROM ".$this->db->prefix().
"paiement_facture as pf, ".$this->db->prefix().
"facture as f";
131 $sql .=
" WHERE pf.fk_paiement = t.rowid AND pf.fk_facture = f.rowid AND f.fk_soc = ".((int) $socid).
")";
132 $sql .=
" AND NOT EXISTS (SELECT pf2.rowid FROM ".$this->db->prefix().
"paiement_facture as pf2, ".$this->db->prefix().
"facture as f2";
133 $sql .=
" WHERE pf2.fk_paiement = t.rowid AND pf2.fk_facture = f2.rowid AND f2.fk_soc <> ".((int) $socid).
")";
139 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
143 $sql .= $this->db->order($sortfield, $sortorder);
148 $offset = $limit * $page;
150 $sql .= $this->db->plimit($limit + 1, $offset);
153 $result = $this->db->query($sql);
156 $num = $this->db->num_rows($result);
157 $min = min($num, ($limit <= 0 ? $num : $limit));
159 $obj = $this->db->fetch_object($result);
160 $tmp_object =
new Paiement($this->db);
161 if ($tmp_object->fetch($obj->rowid)) {
167 throw new RestException(503,
'Error when retrieving Paiement list: '.$this->db->lasterror());
190 public function put(
$id, $request_data =
null)
192 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'creer')) {
193 throw new RestException(403);
196 $result = $this->paiement->fetch(
$id);
198 throw new RestException(404,
'paiement not found');
201 throw new RestException(403,
'Access to this payment not allowed for this user');
204 foreach ($request_data as $field => $value) {
205 if ($field ==
'id') {
208 if ($field ===
'caller') {
210 $this->paiement->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
214 $this->paiement->$field = $this->
_checkValForAPI($field, $value, $this->paiement);
220 if ($this->paiement->update(DolibarrApiAccess::$user, 0) > 0) {
221 return $this->
get(
$id);
223 throw new RestException(500, $this->paiement->errorsToString());
241 public function delete(
$id)
243 if (!DolibarrApiAccess::$user->hasRight(
'facture',
'paiement')) {
244 throw new RestException(403);
247 $result = $this->paiement->fetch(
$id);
249 throw new RestException(404,
'Paiement not found');
252 throw new RestException(403,
'Access to this payment not allowed for this user');
255 if ($this->paiement->delete(DolibarrApiAccess::$user) == 0) {
256 throw new RestException(409,
'Error when deleting Paiement : '.$this->paiement->errorsToString());
257 } elseif ($this->paiement->delete(DolibarrApiAccess::$user) < 0) {
258 throw new RestException(500,
'Error when deleting Paiement : '.$this->paiement->errorsToString());
264 'message' =>
'Paiement deleted'
283 $socid = (int) DolibarrApiAccess::$user->socid;
288 $sql =
"SELECT SUM(CASE WHEN f.fk_soc = ".((int) $socid).
" THEN 1 ELSE 0 END) as nbok, SUM(CASE WHEN f.fk_soc = ".((int) $socid).
" THEN 0 ELSE 1 END) as nbko";
289 $sql .=
" FROM ".$this->db->prefix().
"paiement_facture as pf, ".$this->db->prefix().
"facture as f";
290 $sql .=
" WHERE pf.fk_facture = f.rowid AND pf.fk_paiement = ".((int) $paymentid);
292 $resql = $this->db->query($sql);
294 throw new RestException(503,
'Error when checking access to payment: '.$this->db->lasterror());
296 $obj = $this->db->fetch_object($resql);
297 $this->db->free($resql);
299 return ($obj && (
int) $obj->nbok > 0 && (
int) $obj->nbko == 0);
$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.
_checkAccessToPaymentForExternalUser($paymentid)
Check that an external user can access a payment: all invoices of the payment must belong to the user...
_cleanObjectDatas($object)
Clean sensitive object data fields @phpstan-template T.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.