public function testCreate()
 {
     $db = DB::get();
     $srv = new CashMovementsService();
     $mvt = new CashMovement($this->cashId, $db->readDate("2014-01-03 00:00:00"), CashMovement::TYPE_CASHIN, 10.0, $this->currencyId, 12, "note");
     $id = $srv->create($mvt);
     $this->assertNotEquals(false, $id, "Creation failed");
     $pdo = PDOBuilder::getPDO();
     $stmt = $pdo->prepare("SELECT * FROM RECEIPTS WHERE ID = :id");
     $stmt->bindParam(":id", $id);
     $stmt->execute();
     $row = $stmt->fetch();
     $this->assertNotEquals(false, $row, "No receipt found");
     $this->assertEquals($mvt->date, $db->readDate($row['DATENEW']), "Date mismatch");
     $this->assertEquals($mvt->cashId, $row['MONEY'], "Cash session id mismatch");
     $stmtP = $pdo->prepare("SELECT * FROM PAYMENTS WHERE ID = :id");
     $stmtP->bindParam(":id", $id);
     $stmtP->execute();
     $row = $stmtP->fetch();
     $this->assertNotEquals(false, $row, "No payment found");
     $this->assertEquals($id, $row['RECEIPT'], "Receipt id mismatch");
     $this->assertEquals($mvt->type, $row['PAYMENT'], "Payment type mismatch");
     $this->assertEquals($mvt->amount, $row['TOTAL'], "Amount mismatch");
     $this->assertEquals($mvt->currencyId, $row['CURRENCY'], "Currency id mismatch");
     $this->assertEquals($mvt->currencyAmount, $row['TOTALCURRENCY'], "Currency amount mismatch");
     $this->assertEquals($mvt->note, $row['NOTE'], "Note mismatch");
 }
Example #2
0
 protected function proceed()
 {
     switch ($this->action) {
         case 'move':
             $cashId = $this->getParam("cashId");
             $date = $this->getParam("date");
             $note = $this->getParam("note");
             $json = json_decode($this->getParam("payment"));
             $move = new CashMovement($cashId, $date, $json->type, $json->amount, $json->currencyId, $json->currencyAmount, $note);
             $srv = new CashMovementsService();
             $id = $srv->create($move);
             if ($id !== false) {
                 $this->succeed($id);
             } else {
                 $this->fail(APIError::$ERR_GENERIC);
             }
             break;
     }
 }