示例#1
0
 protected function setUp()
 {
     // Attribute set
     $set = new AttributeSet("set");
     $attr = new Attribute("attr", 1);
     $val = new AttributeValue("value");
     $attr->id = AttributesService::createAttribute($attr);
     $val->id = AttributesService::createValue($val, $attr->id);
     $attr->addValue($val);
     $set->addAttribute($attr);
     $set->id = AttributesService::createSet($set);
     // Product, tax and category
     $taxCat = new TaxCat("Tax");
     $tax = new Tax(null, "Tax", stdtimefstr("2001-01-01 00:00:00"), 0.1);
     $taxCat->addTax($tax);
     $taxCat->id = TaxesService::createCat($taxCat);
     $taxCat2 = new TaxCat("Tax2");
     $tax2 = new Tax(null, "Tax2", stdtimefstr("2001-01-01 00:00:00"), 0.2);
     $taxCat2->addTax($tax2);
     $taxCat2->id = TaxesService::createCat($taxCat2);
     $pdo = PDOBuilder::getPDO();
     $stmt = $pdo->prepare("INSERT INTO CATEGORIES (ID, NAME) " . "VALUES (:id, :name)");
     $stmt->execute(array(":id" => "-1", ":name" => "Refill"));
     $cat = new Category(null, "Category", false, 1);
     $cat->id = CategoriesService::createCat($cat);
     $prd = new Product("REF", "product", 1.0, $cat->id, null, 1, $taxCat->id, true, false, 0.5, $set->id);
     $prd->id = ProductsService::create($prd);
     $prd2 = new Product("REF2", "product2", 2.0, $cat->id, null, 1, $taxCat2->id, true, false, 0.5, null);
     $prd2->id = ProductsService::create($prd2);
     $prdRefill = new Product("REFILL", "Refill", 1.0, "-1", null, 1, $taxCat->id, true, false);
     $prdRefill->id = ProductsService::create($prdRefill);
     // Tariff area
     $srvArea = new TariffAreasService();
     $area = new TariffArea("area", 1);
     $area->addPrice($prd->id, 0.8);
     $area->id = $srvArea->create($area);
     $this->areaId = $area->id;
     // Customer
     $srvCust = new CustomersService();
     $cust = new Customer(1, "Cust", "It's me", "card", null, null, 50.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);
     $cust->id = $srvCust->create($cust);
     $this->custId = $cust->id;
     // Location
     $locSrv = new LocationsService();
     $loc = new Location("Location");
     $loc->id = $locSrv->create($loc);
     $this->locationId = $loc->id;
     // Cash register
     $srvCashReg = new CashRegistersService();
     $cashReg = new CashRegister("Cash", $loc->id, 1);
     $cashReg->id = $srvCashReg->create($cashReg);
     // Cash
     $srvCash = new CashesService();
     $cash = $srvCash->add($cashReg->id);
     $cash->openDate = stdtimefstr("2000-02-02 02:02:02");
     $srvCash->update($cash);
     $this->cashId = $cash->id;
     // User
     $srvUsers = new UsersService();
     $user = new User("User", null, null, "0", true, false);
     $user->id = $srvUsers->create($user);
     // Currency
     $curr = new Currency("Eur", "€", ",", ".", "#,##0.00\$", 1, true, false);
     $srvCurr = new CurrenciesService();
     $curr->id = $srvCurr->create($curr);
     // Discount profile
     $profSrv = new DiscountProfilesService();
     $prof = new DiscountProfile("Profile", 0.1);
     $prof->id = $profSrv->create($prof);
     $this->discountProfilId = $prof->id;
     // Ticket
     $tkt1 = array("date" => stdtimefstr("2012-01-01 00:00:00"), "userId" => $user->id, "customerId" => null, "type" => Ticket::TYPE_SELL, "custCount" => 3, "tariffAreaId" => null, "discountRate" => 0.0, "discountProfileId" => null, "payments" => array(array("type" => "cash", "amount" => 10, "currencyId" => $curr->id, "currencyAmount" => 12)), "lines" => array(array("dispOrder" => 1, "productId" => $prd->id, "taxId" => $tax->id, "attributes" => null, "quantity" => 1.0, "price" => 10.0, "discountRate" => 0.0)));
     $jsAttr = array("attributeSetId" => $set->id, "values" => array(array("id" => $attr->id, "value" => "value")));
     $tkt2 = array("date" => stdtimefstr("2012-01-01 00:00:00"), "userId" => $user->id, "customerId" => null, "type" => Ticket::TYPE_SELL, "custCount" => 3, "tariffAreaId" => null, "discountRate" => 0.25, "discountProfileId" => $prof->id, "payments" => array(array("type" => "cash", "amount" => 10, "currencyId" => $curr->id, "currencyAmount" => 12)), "lines" => array(array("dispOrder" => 1, "productId" => $prd->id, "taxId" => $tax->id, "attributes" => $jsAttr, "quantity" => 1.0, "price" => 10.0, "discountRate" => 0.25)));
     $this->jsTicket1 = json_encode($tkt1);
     $this->jsTicket2 = json_encode($tkt2);
 }
示例#2
0
 /** Run the service and set result. */
 protected function proceed()
 {
     $srv = new CashesService();
     $db = DB::get();
     switch ($this->action) {
         case 'get':
             if (isset($this->params['id'])) {
                 $ret = $srv->get($this->params['id']);
             } else {
                 $ret = $srv->getCashRegister($this->params['cashRegisterId']);
                 if ($ret === null || $ret->isClosed()) {
                     $ret = null;
                 }
             }
             $this->succeed($ret);
             break;
         case 'zticket':
             $ret = $srv->getZTicket($this->params['id']);
             $this->succeed($ret);
             break;
         case 'search':
             $cashRegisterId = $this->getParam("cashRegisterId");
             $dateStart = $this->getParam("dateStart");
             $dateStop = $this->getParam("dateStop");
             $conditions = array();
             if ($cashRegisterId !== null) {
                 $conditions[] = array("cashRegisterId", "=", $cashRegisterId);
             }
             if ($dateStart !== null) {
                 $conditions[] = array("openDate", ">=", $db->dateVal($dateStart));
             }
             if ($dateStop !== null) {
                 $conditions[] = array("closeDate", "<=", $db->dateVal($dateStop));
             }
             $this->succeed($srv->search($conditions));
             break;
         case 'update':
             $json = json_decode($this->params['cash']);
             $open = null;
             $id = null;
             if (property_exists($json, 'id')) {
                 $id = $json->id;
             }
             if (property_exists($json, 'openDate')) {
                 $open = $json->openDate;
             }
             $close = null;
             if (property_exists($json, 'closeDate')) {
                 $close = $json->closeDate;
             }
             $openCash = null;
             if (property_exists($json, 'openCash')) {
                 $openCash = $json->openCash;
             }
             $closeCash = null;
             if (property_exists($json, 'closeCash')) {
                 $closeCash = $json->closeCash;
             }
             $expectedCash = null;
             if (property_exists($json, 'expectedCash')) {
                 $expectedCash = $json->expectedCash;
             }
             $cashRegisterId = $json->cashRegisterId;
             $sequence = null;
             if (property_exists($json, 'sequence')) {
                 $sequence = $json->sequence;
             }
             if ($id !== null) {
                 // Update an existing cash
                 $cash = Cash::__build($id, $cashRegisterId, $sequence, $open, $close, $openCash, $closeCash, $expectedCash);
                 if ($srv->update($cash)) {
                     $this->succeed($cash);
                 } else {
                     $this->fail(APIError::$ERR_GENERIC);
                 }
             } else {
                 // Create a cash and update with given data
                 if ($srv->add($cashRegisterId)) {
                     $cash = $srv->getCashRegister($cashRegisterId);
                     $cash->openDate = $open;
                     $cash->closeDate = $close;
                     $cash->openCash = $openCash;
                     $cash->closeCash = $closeCash;
                     $cash->expectedCash = $expectedCash;
                     if ($srv->update($cash)) {
                         $this->succeed($cash);
                     } else {
                         $this->fail(APIError::$ERR_GENERIC);
                     }
                 } else {
                     $this->fail(APIError::$ERR_GENERIC);
                 }
             }
             break;
     }
 }
示例#3
0
 public function testGetClosedByCashRegister()
 {
     $broker = new APIBroker("CashesAPI");
     $srv = new CashesService();
     // Init cash
     $cash = $srv->add($this->cashRegisterId);
     $cash->openDate = stdtimefstr("2002-02-02 02:02:02");
     $cash->closeDate = stdtimefstr("2002-02-03 03:03:03");
     $cash->openCash = 8.0;
     $cash->closeCash = 8.199999999999999;
     $srv->update($cash);
     // Get it through API
     $result = $broker->run("get", array("cashRegisterId" => $cash->cashRegisterId));
     $this->assertEquals(APIResult::STATUS_CALL_OK, $result->status, "Result status check failed");
     $content = $result->content;
     $this->assertNull($content, "Content is not null");
 }
 /** @depends testGet */
 public function testDeleteClosed()
 {
     $date = stdtimefstr("2013-01-01 00:00:00");
     $ticket = new Ticket(Ticket::TYPE_SELL, $this->user->id, $date, array(), array(), $this->cash->id);
     $id = TicketsService::save($ticket, $this->location->id);
     $this->cash->closeDate = stdtimefstr("2013-01-01 12:00:00");
     $cashSrv = new CashesService();
     $cashSrv->update($this->cash);
     $this->assertFalse(TicketsService::delete($id), "Closed ticket should not be deleted");
     $this->assertNotNull(TicketsService::get($id), "Ticket is not there anymore");
 }
 /** @depends testAdd
  * @depends testGet
  */
 public function testUpdate()
 {
     $srv = new CashesService();
     $cash = $srv->add($this->cashRegisterId);
     // Edit open date
     $cash->openDate = stdtimefstr("2000-02-02 02:02:02");
     $cash->openCash = 10.0;
     $srv->update($cash);
     $read = $srv->get($cash->id);
     $this->assertNotNull($read, "Created cash not found");
     $this->assertEquals($cash->id, $read->id, "Id was modified");
     $this->assertEquals($cash->cashRegisterId, $read->cashRegisterId, "Cash register id was modified");
     $this->assertEquals($cash->sequence, $read->sequence, "Sequence was modified");
     $this->assertEquals($cash->openDate, $read->openDate, "Open date Mismatch");
     $this->assertEquals($cash->closeDate, $read->closeDate, "Close date was modified");
     $this->assertEquals($cash->openCash, $read->openCash, "Open cash mismatch");
     $this->assertEquals($cash->closeCash, $read->closeCash, "Close cash was modified");
     $this->assertEquals($cash->expectedCash, $read->expectedCash, "Expected cash was modified");
     // Edit close date
     $cash->closeDate = stdtimefstr("2000-02-03 02:02:02");
     $cash->closeCash = 12.0;
     $cash->expectedCash = 25.0;
     $srv->update($cash);
     $read = $srv->get($cash->id);
     $this->assertNotNull($read, "Created cash not found");
     $this->assertEquals($cash->id, $read->id, "Id was modified");
     $this->assertEquals($cash->cashRegisterId, $read->cashRegisterId, "Cash register id was modified");
     $this->assertEquals($cash->sequence, $read->sequence, "Sequence was modified");
     $this->assertEquals($cash->openDate, $read->openDate, "Open date was modified");
     $this->assertEquals($cash->closeDate, $read->closeDate, "Close date was modified");
     $this->assertEquals($cash->openCash, $read->openCash, "Open cash was modified");
     $this->assertEquals($cash->closeCash, $read->closeCash, "Close cash mismatch");
     $this->assertEquals($cash->expectedCash, $read->expectedCash, "Expected cash was modified");
     // Edit open and close date
     $cash->openDate = stdtimefstr("2001-02-02 03:03:03");
     $cash->closeDate = stdtimefstr("2001-02-03 03:03:03");
     $cash->openCash = 9.0;
     $cash->closeCash = 9.1;
     $cash->expectedCash = 9.199999999999999;
     $srv->update($cash);
     $read = $srv->get($cash->id);
     $this->assertNotNull($read, "Created cash not found");
     $this->assertEquals($cash->id, $read->id, "Id was modified");
     $this->assertEquals($cash->cashRegisterId, $read->cashRegisterId, "Cash register id was modified");
     $this->assertEquals($cash->sequence, $read->sequence, "Sequence was modified");
     $this->assertEquals($cash->openDate, $read->openDate, "Open date mismatch");
     $this->assertEquals($cash->closeDate, $read->closeDate, "Close date mismatch");
     $this->assertEquals($cash->openCash, $read->openCash, "Open cash mismatch");
     $this->assertEquals($cash->closeCash, $read->closeCash, "Close cash mismatch");
     $this->assertEquals($cash->expectedCash, $read->expectedCash, "Expected cash was modified");
 }