Ejemplo n.º 1
0
 function get($count = 50, $id = "", $info = "all")
 {
     //Connect
     $sql = new DataBase();
     $sql->connect();
     $query = "\r\n\t\tSELECT DISTINCT acc.*\r\n\t\tFROM accounts acc\r\n\t\tWHERE acc.profile_id = '" . CurrentUser::getId() . "'";
     if (!empty($id)) {
         $query .= " AND acc.id = '" . $id . "'";
     }
     $query .= " ORDER BY acc.account_type_id, acc.name LIMIT " . $count;
     //Execute
     $sql->query($query);
     //Objects
     $json = array();
     //Data
     while ($data = mysql_fetch_array($sql->result)) {
         if ($info == "all") {
             $array = array("id" => $data["id"], "name" => $data["name"], "profile_id" => $data["profile_id"], "initial_balance" => $data["initial_balance"], "account_type_id" => $data["account_type_id"], "balance" => $data["balance"], "status" => $data["status"]);
             array_push($json, $array);
         } else {
             $json = $data[$info];
         }
     }
     //Return
     return $json;
     $sql->close();
 }
Ejemplo n.º 2
0
 function get($count = 10, $from = "", $to = "", $account = "", $id = "")
 {
     //Connect
     $sql = new DataBase();
     $sql->connect();
     //Query
     $query = "\r\n\t\t\tSELECT DISTINCT transaction.*\r\n\t\t\tFROM transactions transaction\r\n\t\t\tWHERE transaction.profile_id = " . CurrentUser::getId() . " ";
     if (!empty($from)) {
         $query .= "AND transaction.date >= '" . $from . "' ";
     }
     if (!empty($to)) {
         $query .= "AND transaction.date <= '" . $to . "' ";
     }
     if (!empty($account)) {
         $query .= "AND (transaction.account_from_id = '" . $account . "' || transaction.account_to_id = '" . $account . "') ";
     }
     if (!empty($id)) {
         $query .= "AND transaction.id = '" . $id . "' ";
     }
     $query .= "ORDER BY transaction.date DESC ";
     if ($count != "all") {
         $query .= "LIMIT " . $count;
     }
     $sql->query($query);
     //Objects
     $json = array();
     //Instances
     $tags = new Tags();
     $accounts = new Accounts();
     //Data
     while ($data = mysql_fetch_array($sql->result)) {
         $array = array("id" => $data["id"], "description" => $data["description"], "amount" => $data['transaction_type_id'] == 3 && $data["account_from_id"] != $account ? $data["amount"] * -1 : $data["amount"], "type" => $data["transaction_type_id"], "date" => $data["date"], "account_from" => $data["account_from_id"], "account_to" => $data["account_to_id"], "account_type" => $accounts->get(1, $data["account_from_id"], "account_type_id"), "profile_id" => $data["profile_id"], 'tags' => $tags->getTransactionTags(1000, $data["id"]));
         array_push($json, $array);
     }
     //Close connection
     //$sql->close();
     //Return
     return $json;
 }
Ejemplo n.º 3
0
 /////////////////////////////////////DELETE
 case 'delete':
     //Instances and Variables
     $ID = $_GET['id'];
     //$transactions = new Transactions;
     $accounts = new Accounts();
     //Connect
     $sql = new DataBase();
     $sql->connect();
     //Verify if exists
     $tr = $transactions->get('all', '', '', '', $ID);
     $data = $tr;
     if (count($tr) == 0) {
         RestUtils::sendResponse('406', array('data' => 'transactionId', 'message' => 'Essa transa&ccedil;&atilde;o n&atilde;o existe.'));
     }
     if ($tr[0]['profile_id'] != CurrentUser::getId()) {
         RestUtils::sendResponse('406', array('data' => 'transactionId', 'message' => 'Essa transa&ccedil;&atilde;o n&atilde;o pertence ao perfil.'));
     }
     //Remove
     $sql->query("DELETE FROM transactions_has_tags WHERE transaction_id = '" . $ID . "'");
     $sql->query("DELETE FROM transactions WHERE id = '" . $ID . "'");
     //Remove in Ammount
     if ($data[0]['account_to'] != '') {
         $balance = $accounts->get(1, $data[0]['account_from'], 'balance');
         $balance += $data[0]['amount'];
         $sql->query("UPDATE accounts SET balance='" . $balance . "' WHERE id = '" . $data[0]['account_from'] . "'");
         $balance = $accounts->get(1, $data[0]['account_to'], 'balance');
         $balance -= $data[0]['amount'];
         $sql->query("UPDATE accounts SET balance='" . $balance . "' WHERE id = '" . $data[0]['account_to'] . "'");
     } else {
         $balance = $accounts->get(1, $data[0]['account_from'], 'balance');
Ejemplo n.º 4
0
     $sql = new DataBase();
     $sql->connect();
     //Verify if account exists
     $haserror = true;
     foreach ($accounts->get() as $acc) {
         if ($_DATA['id'] == $acc['id']) {
             $haserror = false;
             $forProfileId = $acc['profile_id'];
             break;
         }
     }
     if ($haserror) {
         RestUtils::sendResponse('406', array('data' => 'accountId', 'message' => 'A conta escolhida n&atilde;o existe.'));
         exit;
     }
     if ($forProfileId != CurrentUser::getId()) {
         RestUtils::sendResponse('406', array('data' => 'accountId', 'message' => 'A conta escolhida n&atilde;o pertence ao usu&aacute;rio.'));
         exit;
     }
     //Disable STATUS
     $sql->query("UPDATE accounts SET status = 0 WHERE id = '" . $_DATA['id'] . "'");
     //Close Connection
     $sql->close();
     RestUtils::sendResponse('200');
     exit;
     break;
     /////////////////////////////////////DEFAULT
 /////////////////////////////////////DEFAULT
 default:
     RestUtils::sendResponse('405', array('message' => 'O m&eacute;todo escolhido n&atilde;o &eacute; suportado.'));
     exit;
Ejemplo n.º 5
0
 function getTransactionTags($count, $id)
 {
     $sql = new DataBase();
     $sql->connect();
     $sql->query("\r\n\t\tSELECT tag.*\r\n\t\tFROM tags tag, transactions_has_tags tht\r\n\t\tWHERE tht.transaction_id = '" . $id . "' AND tag.profile_id = " . CurrentUser::getId() . "\r\n\t\tAND tag.id = tht.tag_id\r\n\t\tLIMIT " . $count . "\r\n\t\t");
     //Objects
     $json = array();
     //Data
     while ($data = mysql_fetch_array($sql->result)) {
         $array = array("id" => $data["id"], "name" => $data["name"]);
         array_push($json, $array);
     }
     //Close connection
     $sql->close();
     //Return
     return $json;
 }