19use Luracast\Restler\RestException;
21require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/paymentvarious.class.php';
35 public static $FIELDS = array(
61 public function get(
$id)
63 if (!DolibarrApiAccess::$user->hasRight(
'banque',
'lire')) {
64 throw new RestException(403);
68 $result = $payment->fetch(
$id);
71 if ($result <= 0 || empty($payment->id)) {
72 throw new RestException(404,
'Various payment not found');
98 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'', $pagination_data =
false)
100 if (!DolibarrApiAccess::$user->hasRight(
'banque',
'lire')) {
101 throw new RestException(403);
106 $sql =
"SELECT t.rowid";
107 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_various AS t";
108 $sql .=
" WHERE t.entity IN (".getEntity(
'payment_various').
")";
115 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
120 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
122 $sql .= $this->db->order($sortfield, $sortorder);
127 $offset = $limit * $page;
129 $sql .= $this->db->plimit($limit + 1, $offset);
133 $result = $this->db->query($sql);
136 throw new RestException(503,
'Error when retrieving list of various payments: '.$this->db->lasterror());
139 $num = $this->db->num_rows($result);
140 $min = min($num, ($limit <= 0 ? $num : $limit));
141 for ($i = 0; $i < $min; $i++) {
142 $obj = $this->db->fetch_object($result);
144 if ($payment->fetch($obj->rowid) > 0) {
151 if ($pagination_data) {
152 $totalsResult = $this->db->query($sqlTotals);
153 $total = $this->db->fetch_object($totalsResult)->total;
158 $obj_ret[
'data'] = $tmp;
159 $obj_ret[
'pagination'] = array(
160 'total' => (
int) $total,
162 'page_count' => ($limit > 0 ? (
int) ceil((
int) $total / $limit) : 1),
182 public function post($request_data =
null)
184 if (!DolibarrApiAccess::$user->hasRight(
'banque',
'modifier')) {
185 throw new RestException(403);
192 foreach ($request_data as $field => $value) {
193 if ($field ===
'caller') {
195 $payment->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
202 if ($payment->create(DolibarrApiAccess::$user) < 0) {
203 throw new RestException(500,
'Error when creating various payment: '.$payment->errorsToString());
222 public function put(
$id, $request_data =
null)
224 if (!DolibarrApiAccess::$user->hasRight(
'banque',
'modifier')) {
225 throw new RestException(403);
229 $result = $payment->fetch(
$id);
232 if ($result <= 0 || empty($payment->id)) {
233 throw new RestException(404,
'Various payment not found');
236 foreach ($request_data as $field => $value) {
237 if ($field ==
'id') {
240 if ($field ===
'caller') {
242 $payment->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
245 if ($field ==
'array_options' && is_array($value)) {
246 foreach ($value as $index => $val) {
255 if ($payment->update(DolibarrApiAccess::$user) > 0) {
256 return $this->
get(
$id);
258 throw new RestException(500,
'Error when updating various payment: '.$payment->errorsToString());
274 public function delete(
$id)
276 if (!DolibarrApiAccess::$user->hasRight(
'banque',
'modifier')) {
277 throw new RestException(403);
281 $result = $payment->fetch(
$id);
284 if ($result <= 0 || empty($payment->id)) {
285 throw new RestException(404,
'Various payment not found');
288 if ($payment->delete(DolibarrApiAccess::$user) < 0) {
289 throw new RestException(500,
'Error when deleting various payment: '.$payment->errorsToString());
295 'message' =>
'Various payment deleted'
310 if ($data ===
null) {
314 foreach (VariousPayments::$FIELDS as $field) {
315 if (!isset($data[$field])) {
316 throw new RestException(400,
"$field field missing");
318 $payment[$field] = $data[$field];
337 unset(
$object->labelStatusShort);
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
_checkValExtrafieldsForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
_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 various payments.
_validate($data)
Validate fields before creating an object.
post($request_data=null)
Create a various payment (manual journal entry).
_cleanObjectDatas($object)
Clean sensitive object data.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $sqlfilters='', $properties='', $pagination_data=false)
List various payments (manual journal entries).
__construct()
Constructor.
put($id, $request_data=null)
Update a various payment (manual journal entry).
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.