/** @depends testGet
  * @depends testSaveDebt
  */
 public function testDeleteDebt()
 {
     $currDebt = $this->customer->currDebt;
     $date = stdtimefstr("2013-01-01 00:00:00");
     $line = new TicketLine(1, $this->prd, null, 1, 10, $this->tax);
     $payment = new Payment("debt", 3, $this->currency->id, 3);
     $ticket = new Ticket(Ticket::TYPE_SELL, $this->user->id, $date, array($line), array($payment), $this->cash->id, $this->customer->id);
     $id = TicketsService::save($ticket, $this->location->id);
     $this->assertTrue(TicketsService::delete($id), "Delete failed");
     $custSrv = new CustomersService();
     $cust = $custSrv->get($this->customer->id);
     $this->assertEquals($currDebt, $cust->currDebt, "Debt not cleared after ticket is deleted");
 }
Beispiel #2
0
 protected function proceed()
 {
     $srv = new CustomersService();
     switch ($this->action) {
         case 'get':
             $this->succeed($srv->get($this->params['id']));
             break;
         case 'getAll':
             $this->succeed($srv->getAll());
             break;
         case 'addPrepaid':
             $this->succeed($srv->addPrepaid($this->params['id'], $this->params['amount']));
             break;
         case 'getTop':
             $this->succeed($srv->getTop($this->getParam("limit")));
             break;
         case 'save':
             // Convert single customer to array for consistency
             if ($this->isParamSet('customers')) {
                 $json = json_decode($this->params['customers']);
             } else {
                 $json = array(json_decode($this->params['customer']));
             }
             $srv = new CustomersService();
             $result = array();
             // Begin transaction
             $pdo = PDOBuilder::getPDO();
             if (!$pdo->beginTransaction()) {
                 $this->fail(APIError::$ERR_GENERIC);
                 break;
             }
             foreach ($json as $customer) {
                 if (isset($customer->id) && $customer->id !== null) {
                     // Edit
                     if (!$srv->update($customer)) {
                         // Error, rollback
                         $pdo->rollback();
                         $this->fail(APIError::$ERR_GENERIC);
                         return;
                     } else {
                         $result[] = $customer->id;
                     }
                 } else {
                     // Create
                     $id = $srv->create($customer);
                     if ($id !== false) {
                         $result[] = $id;
                     } else {
                         // Error, rollback
                         $pdo->rollback();
                         $this->fail(APIError::$ERR_GENERIC);
                         return;
                     }
                 }
             }
             // Success, commit
             if ($pdo->commit()) {
                 $this->succeed(array("saved" => $result));
             } else {
                 $this->fail(APIError::$ERR_GENERIC);
             }
             break;
     }
 }
 public function testCreate()
 {
     $broker = new APIBroker(CustomersAPITest::API);
     $srv = new CustomersService();
     $cust = new Customer(null, "Cust", "It's me", "card", null, null, 12.0, 10.0, 5.0, stdtimefstr("2012-01-01 00:00:00"), "It's", "me", "*****@*****.**", "012345", "23456", "11111", "Address1", "Address2", "59000", "City", "Region", "France", "Note", true);
     unset($cust->id);
     $result = $broker->run("save", array("customer" => json_encode($cust)));
     $this->assertEquals(APIResult::STATUS_CALL_OK, $result->status, "Result status check failed");
     $content = $result->content;
     $id = $content['saved'][0];
     $cust->id = $id;
     $this->assertNotNull($content, "Result not found");
     $read = $srv->get($id);
     $this->checkCustEquality($cust, $read);
 }
 /** @depends testCreate
  * @depends testReadInexistent
  */
 public function testDelete()
 {
     $srv = new CustomersService();
     $cust = new Customer(1, "Cust", "It's me", "card", null, null, 12.0, 10.0, 5.0, stdtimefstr("2012-01-01 00:00:00"), "It's", "me", "*****@*****.**", "012345", "23456", "11111", "Address1", "Address2", "59000", "City", "Region", "France", "Note", true);
     $id = $srv->create($cust);
     $this->assertTrue($srv->delete($id));
     $read = $srv->get($id);
     $this->assertNull($srv->get($id));
 }