示例#1
0
 function getByTag($count = 10, $from = "", $to = "", $account = "", $tag = "", $orderby = "", $order = "")
 {
     //Connect
     $sql = new DataBase();
     $sql->connect();
     //Query
     $query = "\r\n\t\t\tSELECT tht.transaction_id, tht.tag_id , transaction.*\r\n\t\t\tFROM transactions_has_tags tht, transactions transaction\r\n\t\t\tWHERE tht.tag_id = '" . $tag . "' AND transaction.id = tht.transaction_id ";
     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 . "' ";
     }
     if ($orderby == 'date') {
         $query .= " ORDER BY transaction.date ";
     }
     if ($order == "ASC") {
         $query .= "ASC ";
     }
     if ($order == "DESC") {
         $query .= "DESC ";
     }
     $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;
 }
示例#2
0
 $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');
     $balance -= $data[0]['amount'];
     $sql->query("UPDATE accounts SET balance='" . $balance . "' WHERE id = '" . $data[0]['account_from'] . "'");
 }
 //Close Connection
 $sql->close();
 RestUtils::sendResponse('200');
 break;
 /*
示例#3
0
         //GET types
         if ($_DATA['id'] == 'types') {
             echo json_encode($accounts->getTypes());
             exit;
             //Get Balance
         } elseif ($_DATA['id'] == 'balance') {
             isset($_DATA['account']) ? $account = $_DATA['account'] : ($account = "");
             isset($_DATA['year']) ? $year = $_DATA['year'] : ($year = "");
             isset($_DATA['month']) ? $month = $_DATA['month'] : ($month = "");
             isset($_DATA['orderBy']) ? $orderBy = $_DATA['orderBy'] : ($orderBy = "year");
             isset($_DATA['order']) ? $order = $_DATA['order'] : ($order = "DESC");
             echo json_encode($accounts->getBalance($account, $month, $year, $orderBy, $order));
             exit;
             //Get info of one account
         } else {
             echo json_encode($accounts->get(1, $_DATA['id']));
             exit;
         }
         //Get ALL
     } else {
         isset($_DATA['count']) ? $count = intval($_DATA['count']) : ($count = 50);
         echo json_encode($accounts->get($count));
         exit;
     }
     break;
     /*
      * ======================================
      * PUT method
      * ======================================
      */
 /*