275 lines
8.0 KiB
PHP
275 lines
8.0 KiB
PHP
<?php
|
|
|
|
namespace Aiko;
|
|
|
|
/** @property ApprovalRequest $obj */
|
|
trait WithApprovalRequest
|
|
{
|
|
/**
|
|
* approve
|
|
*
|
|
* @param Object $oJson
|
|
*
|
|
* expected data property exist in object
|
|
* $oJson->data payload needed
|
|
* [
|
|
* ['id' => 1]
|
|
* ]
|
|
*
|
|
**/
|
|
private function approve($oJson)
|
|
{
|
|
$requestBy = \Helper::getSessionVar('username');
|
|
$transactionIds = \Helper::getArrayValueByKey($oJson->data);
|
|
if (count($transactionIds) == 0) {
|
|
Http::ErrorQueryResponse([
|
|
'pesan' => 'Data is empty',
|
|
'token' => $_SESSION['token']
|
|
], 'json');
|
|
}
|
|
$result = $this->obj->approve($requestBy, $transactionIds[0]);
|
|
if ($result['isSuccess'] == 0) {
|
|
Http::ErrorQueryResponse([
|
|
'pesan' => 'Failed Approve Request',
|
|
'token' => $_SESSION['token']
|
|
], 'json');
|
|
}
|
|
Http::ResponseJson(array(
|
|
'pesan' => 'Success Approve Request',
|
|
'token' => $_SESSION['token']
|
|
), '1');
|
|
}
|
|
|
|
|
|
/**
|
|
* reject
|
|
*
|
|
* @param Object $oJson
|
|
*
|
|
* expected data property exist in object
|
|
* $oJson->data payload needed
|
|
* [
|
|
* ['id' => 1]
|
|
* ]
|
|
*
|
|
**/
|
|
private function reject($oJson)
|
|
{
|
|
$requestBy = \Helper::getSessionVar('username');
|
|
$transactionIds = \Helper::getArrayValueByKey($oJson->data);
|
|
if (count($transactionIds) == 0) {
|
|
Http::ErrorQueryResponse([
|
|
'pesan' => 'Data is empty',
|
|
'token' => $_SESSION['token']
|
|
], 'json');
|
|
}
|
|
$result = $this->obj->reject($requestBy, $transactionIds[0]);
|
|
if ($result['isSuccess'] == 0) {
|
|
Http::ErrorQueryResponse([
|
|
'pesan' => 'Failed Reject Request',
|
|
'token' => $_SESSION['token']
|
|
], 'json');
|
|
}
|
|
Http::ResponseJson(array(
|
|
'pesan' => 'Success Reject Request',
|
|
'token' => $_SESSION['token']
|
|
), '1');
|
|
}
|
|
|
|
/**
|
|
* unapprove
|
|
*
|
|
* @param Object $oJson
|
|
*
|
|
* expected data property exist in object
|
|
* $oJson->data payload needed
|
|
* [
|
|
* ['id' => 1]
|
|
* ]
|
|
*
|
|
**/
|
|
private function unapprove($oJson)
|
|
{
|
|
$requestBy = \Helper::getSessionVar('username');
|
|
$transactionIds = \Helper::getArrayValueByKey($oJson->data);
|
|
if (count($transactionIds) == 0) {
|
|
Http::ErrorQueryResponse([
|
|
'pesan' => 'Data is empty',
|
|
'token' => $_SESSION['token']
|
|
], 'json');
|
|
}
|
|
$result = $this->obj->unapprove($requestBy, $transactionIds[0]);
|
|
if ($result['isSuccess'] == 0) {
|
|
Http::ErrorQueryResponse([
|
|
'pesan' => 'Failed Un-Approve Request',
|
|
'token' => $_SESSION['token']
|
|
], 'json');
|
|
}
|
|
Http::ResponseJson(array(
|
|
'pesan' => 'Success Un-Approve Request',
|
|
'token' => $_SESSION['token']
|
|
), '1');
|
|
}
|
|
|
|
/**
|
|
* unreject
|
|
*
|
|
* @param Object $oJson
|
|
*
|
|
* expected data property exist in object
|
|
* $oJson->data payload needed
|
|
* [
|
|
* ['id' => 1]
|
|
* ]
|
|
*
|
|
**/
|
|
private function unreject($oJson)
|
|
{
|
|
$requestBy = \Helper::getSessionVar('username');
|
|
$transactionIds = \Helper::getArrayValueByKey($oJson->data);
|
|
if (count($transactionIds) == 0) {
|
|
Http::ErrorQueryResponse([
|
|
'pesan' => 'Data is empty',
|
|
'token' => $_SESSION['token']
|
|
], 'json');
|
|
}
|
|
$result = $this->obj->unreject($requestBy, $transactionIds[0]);
|
|
if ($result['isSuccess'] == 0) {
|
|
Http::ErrorQueryResponse([
|
|
'pesan' => 'Failed Un-Reject Request',
|
|
'token' => $_SESSION['token']
|
|
], 'json');
|
|
}
|
|
Http::ResponseJson(array(
|
|
'pesan' => 'Success Un-Reject Request',
|
|
'token' => $_SESSION['token']
|
|
), '1');
|
|
}
|
|
|
|
/**
|
|
* Batch approve
|
|
*
|
|
* Undocumented function long description
|
|
*
|
|
* @param Object $oJson
|
|
*
|
|
* expected data property exist in object
|
|
* $oJson->data payload needed
|
|
* [
|
|
* ['id' => 1]
|
|
* ]
|
|
*
|
|
**/
|
|
private function batchApprove($oJson)
|
|
{
|
|
$requestBy = \Helper::getSessionVar('username');
|
|
$transactionIds = \Helper::getArrayValueByKey($oJson->data);
|
|
if (count($transactionIds) == 0) {
|
|
Http::ErrorQueryResponse([
|
|
'pesan' => 'Data is empty',
|
|
'token' => $_SESSION['token']
|
|
], 'json');
|
|
}
|
|
$result = $this->obj->batchApprove($requestBy, $transactionIds);
|
|
$response = array(
|
|
'pesan' => 'Approve data completed, Success: ' . count($result['success']) . ', Failed: ' . count($result['failed']),
|
|
'moreInfo' => $result,
|
|
'token' => $_SESSION['token']
|
|
);
|
|
Http::ResponseJson($response);
|
|
}
|
|
|
|
/**
|
|
* Batch unapprove
|
|
*
|
|
* @param Object $oJson
|
|
*
|
|
* expected data property exist in object
|
|
* $oJson->data payload needed
|
|
* [
|
|
* ['id' => 1]
|
|
* ]
|
|
*
|
|
**/
|
|
private function batchUnapprove($oJson)
|
|
{
|
|
$requestBy = \Helper::getSessionVar('username');
|
|
$transactionIds = \Helper::getArrayValueByKey($oJson->data);
|
|
if (count($transactionIds) == 0) {
|
|
Http::ErrorQueryResponse([
|
|
'pesan' => 'Data is empty',
|
|
'token' => $_SESSION['token']
|
|
], 'json');
|
|
}
|
|
$result = $this->obj->batchUnapprove($requestBy, $transactionIds);
|
|
$response = array(
|
|
'pesan' => 'Un-Approve data completed, Success: ' . count($result['success']) . ', Failed: ' . count($result['failed']),
|
|
'moreInfo' => $result,
|
|
'token' => $_SESSION['token']
|
|
);
|
|
Http::ResponseJson($response);
|
|
}
|
|
|
|
/**
|
|
* Batch reject
|
|
*
|
|
* @param Object $oJson
|
|
*
|
|
* expected data property exist in object
|
|
* $oJson->data payload needed
|
|
* [
|
|
* ['id' => 1]
|
|
* ]
|
|
*
|
|
**/
|
|
private function batchReject($oJson)
|
|
{
|
|
$requestBy = \Helper::getSessionVar('username');
|
|
$transactionIds = \Helper::getArrayValueByKey($oJson->data);
|
|
if (count($transactionIds) == 0) {
|
|
Http::ErrorQueryResponse([
|
|
'pesan' => 'Data is empty',
|
|
'token' => $_SESSION['token']
|
|
], 'json');
|
|
}
|
|
$result = $this->obj->batchReject($requestBy, $transactionIds, $oJson->comment);
|
|
$response = array(
|
|
'pesan' => 'Reject data completed, Success: ' . count($result['success']) . ', Failed: ' . count($result['failed']),
|
|
'moreInfo' => $result,
|
|
'token' => $_SESSION['token']
|
|
);
|
|
Http::ResponseJson($response, '1');
|
|
}
|
|
|
|
/**
|
|
* Batch unreject
|
|
*
|
|
* @param Object $oJson
|
|
*
|
|
* expected data property exist in object
|
|
* $oJson->data payload needed
|
|
* [
|
|
* ['id' => 1]
|
|
* ]
|
|
*
|
|
**/
|
|
private function batchUnreject($oJson)
|
|
{
|
|
$requestBy = \Helper::getSessionVar('username');
|
|
$transactionIds = \Helper::getArrayValueByKey($oJson->data);
|
|
if (count($transactionIds) == 0) {
|
|
Http::ErrorQueryResponse([
|
|
'pesan' => 'Data is empty',
|
|
'token' => $_SESSION['token']
|
|
], 'json');
|
|
}
|
|
$result = $this->obj->batchUnapprove($requestBy, $transactionIds);
|
|
$response = array(
|
|
'pesan' => 'Approve data completed, Success: ' . count($result['success']) . ', Failed: ' . count($result['failed']),
|
|
'moreInfo' => $result,
|
|
'token' => $_SESSION['token']
|
|
);
|
|
Http::ResponseJson($response);
|
|
}
|
|
}
|