step 1 : download one api pettycash
This commit is contained in:
239
pettycash/Transaction.php
Normal file
239
pettycash/Transaction.php
Normal file
@@ -0,0 +1,239 @@
|
||||
<?php
|
||||
|
||||
class Transaction extends MY_Controller
|
||||
{
|
||||
var $db_onedev;
|
||||
public function index()
|
||||
{
|
||||
echo "BRANCH API";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
}
|
||||
|
||||
function list_type()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
/* if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
*/
|
||||
$prm = $this->sys_input;
|
||||
$sql = "SELECT 'DEBIT' as typeid,
|
||||
'DEBIT' as typename
|
||||
UNION SELECT 'KREDIT' as typeid,
|
||||
'KREDIT' as typename";
|
||||
$query = $this->db_onedev->query($sql);
|
||||
//echo $this->db_onedev->last_query();
|
||||
if ($query) {
|
||||
$rows = $query->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("Total select");
|
||||
exit;
|
||||
}
|
||||
$this->sys_ok($rows);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function list_category()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
/* if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
*/
|
||||
$prm = $this->sys_input;
|
||||
$sql = "SELECT M_CategoryID as categoryid,
|
||||
M_CategoryName as categoryname
|
||||
FROM m_category
|
||||
WHERE
|
||||
M_CategoryIsActive = 'Y'";
|
||||
$query = $this->db_onedev->query($sql);
|
||||
//echo $this->db_onedev->last_query();
|
||||
if ($query) {
|
||||
$rows = $query->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("Category select");
|
||||
exit;
|
||||
}
|
||||
$this->sys_ok($rows);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
public function addtransaction()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
/* if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
*/
|
||||
$this->db_onedev->trans_begin();
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$tanggal = $prm['tanggal'];
|
||||
$tipe = $prm['tipe'];
|
||||
$kategori = $prm['kategoriid'];
|
||||
$jumlah = $prm['jumlah'];
|
||||
$catatan = $prm['catatan'];
|
||||
$sender = $prm['sender'];
|
||||
$companyid = $prm['companyid'];
|
||||
$userid = $prm['userid'];
|
||||
$fileDataBase64 = $prm['base64File'];
|
||||
$fileName = $prm['fileName'];
|
||||
$file = base64_decode($fileDataBase64);
|
||||
// print_r(strlen($fileDataBase64));
|
||||
// print_r(strlen($file));
|
||||
// print_r($prm);
|
||||
// exit;
|
||||
|
||||
$url = '';
|
||||
$sql = "insert into t_transaction(
|
||||
T_TransactionDate,
|
||||
T_TransactionType,
|
||||
T_TransactionM_CategoryID,
|
||||
T_TransactionAmount,
|
||||
T_TransactionNote,
|
||||
T_TransactionImg,
|
||||
T_TransactionSender,
|
||||
T_TransactionM_CompanyID,
|
||||
T_TransactionUserID,
|
||||
T_TransactionCreated,
|
||||
T_TransactionLastUpdated)
|
||||
values( ?, ?, ? , ?, ?, ? , ? , ?, ?, now(), now())";
|
||||
$query = $this->db_onedev->query(
|
||||
$sql,
|
||||
array(
|
||||
$tanggal,
|
||||
$tipe,
|
||||
$kategori,
|
||||
$jumlah,
|
||||
$catatan,
|
||||
$url,
|
||||
$sender,
|
||||
$companyid,
|
||||
$userid
|
||||
)
|
||||
);
|
||||
//echo $query;
|
||||
if (!$query) {
|
||||
// $error = array(
|
||||
// "message" => $this->db_onedev->error(),
|
||||
// );
|
||||
// $this->sys_error($error);
|
||||
$this->sys_error_db("Error Insert transaksi");
|
||||
$this->db_onedev->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$last_id = $this->db_onedev->insert_id();
|
||||
$newFilename = $companyid . "-" . strval($last_id) . "-" . $fileName;
|
||||
if ($fileDataBase64 != "") {
|
||||
# code...
|
||||
try {
|
||||
file_put_contents("/home/one/project/one/pettycash-media/attachment/" . $newFilename, $file);
|
||||
} catch (Exception $e) {
|
||||
$this->sys_error_db("Error Upload file");
|
||||
$this->db_onedev->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$sql_update = "UPDATE t_transaction
|
||||
SET T_TransactionImg = ?
|
||||
WHERE T_TransactionID = ?";
|
||||
$query_update = $this->db_onedev->query(
|
||||
$sql_update,
|
||||
[$newFilename, $last_id]
|
||||
);
|
||||
//echo $query;
|
||||
if (!$query_update) {
|
||||
// $error = array(
|
||||
// "message" => $this->db_onedev->error(),
|
||||
// );
|
||||
// $this->sys_error($error);
|
||||
$this->sys_error_db("Error update transaksi");
|
||||
$this->db_onedev->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$result = array("total" => 1, "records" => array("xid" => 0, "file" => $fileDataBase64, "filename" => $fileName, 'path' => "/home/one/project/one/pettycash-media/attachment/" . strval($last_id) . " - " . $fileName));
|
||||
|
||||
$this->db_onedev->trans_commit();
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
public function deletetransaction()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
/* if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
*/
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$id = $prm['id'];
|
||||
$userid = $prm['userid'];
|
||||
$sql = "UPDATE t_transaction SET T_TransactionIsActive = 'N',
|
||||
T_TransactionUserID = $userid
|
||||
WHERE T_TransactionID = $id";
|
||||
$query = $this->db_onedev->query($sql);
|
||||
//echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("t_transaction delete");
|
||||
exit;
|
||||
}
|
||||
$result = array("total" => 1, "records" => array("xid" => $id));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
public function confirmtransaction()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
/* if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
*/
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$id = $prm['id'];
|
||||
$userid = $prm['userid'];
|
||||
$sql = "UPDATE t_transaction SET T_TransactionIsConfirm = 'Y',
|
||||
T_TransactionConfirmDate = now(),
|
||||
T_TransactionConfirmUserID = $userid
|
||||
WHERE T_TransactionID = $id";
|
||||
$query = $this->db_onedev->query($sql);
|
||||
//echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("t_transaction confirmed");
|
||||
exit;
|
||||
}
|
||||
$result = array("total" => 1, "records" => array("xid" => $id));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user