예제 #1
0
 $transactionTagsCompare = array();
 foreach ($transactionTags as $tag) {
     $tag = prepareToCompare($tag);
     array_push($transactionTagsCompare, $tag);
 }
 //Insert transaction
 $sql->query("\n\t\t\tINSERT INTO transactions(id,description,amount,date,account_to_id,account_from_id,transaction_type_id,profile_id)\n\t\t\tVALUES('" . $transactionId . "','" . $data['description'] . "','" . $data['amount'] . "','" . $data['date'] . "','" . $data['accountTo'] . "','" . $data['accountFrom'] . "','" . $data['transType'] . "','" . CurrentUser::getId() . "')\n\t\t");
 //Insert tags
 foreach ($tags->get() as $tag) {
     if (in_array(prepareToCompare($tag['name']), $transactionTagsCompare)) {
         //IF have in BD
         $sql->query("\n\t\t\t\t\tINSERT INTO transactions_has_tags(transaction_id,tag_id)\n\t\t\t\t\tVALUES('" . $transactionId . "','" . $tag['id'] . "')\n\t\t\t\t");
     }
 }
 foreach ($transactionTags as $tag) {
     if (!in_array(prepareToCompare($tag), $allTagsCompare)) {
         //IF DONT have in BD
         $sql->query("\n\t\t\t\t\tINSERT INTO tags(name, profile_id)\n\t\t\t\t\tVALUES ('" . ucfirst(trim(convertToUnicode($tag))) . "','" . CurrentUser::getId() . "')\n\t\t\t\t");
         $tagId = $sql->insertId;
         $sql->query("\n\t\t\t\t\tINSERT INTO transactions_has_tags(transaction_id,tag_id)\n\t\t\t\t\tVALUES('" . $transactionId . "','" . $tagId . "')\n\t\t\t\t");
     }
 }
 //Add in Ammount
 $balance = $accounts->get(1, $data['accountFrom'], 'balance');
 $balance += $data['amount'];
 $sql->query("UPDATE accounts SET balance='" . $balance . "' WHERE id = '" . $data['accountFrom'] . "'");
 if ($data['accountTo'] != '') {
     $balance = $accounts->get(1, $data['accountTo'], 'balance');
     $balance -= $data['amount'];
     $sql->query("UPDATE accounts SET balance='" . $balance . "' WHERE id = '" . $data['accountTo'] . "'");
 }
예제 #2
0
 //Informações cadastradas
 $data = array('tagName' => trim($_DATA['tagName']));
 //Instâncias
 $tags = new Tags();
 //Verificar inputs básicos
 if ($data['tagName'] == '' || count($data['tagName']) > 28) {
     //Nome da tag
     RestUtils::sendResponse('406', array('data' => 'tagName', 'message' => 'Por favor, verifique o nome da tag.'));
 }
 //Verifica se a tag já não existe
 $allTagsCompare = array();
 foreach ($tags->get(500) as $tag) {
     $tag = strtolower(clearUTF($tag['name']));
     array_push($allTagsCompare, $tag);
 }
 if (in_array(prepareToCompare($data['tagName']), $allTagsCompare)) {
     //Se a tag já existe
     RestUtils::sendResponse('406', array('data' => 'tagName', 'message' => 'A tag a ser cadastrada já existe.'));
 }
 //Conexão
 $sql = new DataBase();
 $sql->connect();
 //Adiciona a tag no banco
 $sql->query("INSERT INTO tags(name, profile_id) VALUES ('" . ucfirst(trim(convertToUnicode($data['tagName']))) . "','" . CurrentUser::getId() . "')");
 //Termina execução com sucesso
 $sql->close();
 RestUtils::sendResponse('201');
 break;
 /*
  * ======================================
  * POST method