protected function setUp() { $locSrv = new LocationsService(); $location = new Location("Location"); $location->id = $locSrv->create($location); $cashRegSrv = new CashRegistersService(); $cashReg = new CashRegister("CashReg", $location->id, 1); $cashRegId = $cashRegSrv->create($cashReg); // Create a cash session $srv = new CashesService(); $cash = $srv->add($cashRegId); $this->cashId = $cash->id; $srv = new CurrenciesService(); $eur = new Currency("Eur", "€", ",", ".", "#,##0.00\$", 1, true, false); $this->currencyId = $srv->create($eur); }
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); }
/** 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; } }
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); $this->attr = $attr; $set->addAttribute($attr); $set->id = AttributesService::createSet($set); $this->attrSet = $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); $this->tax = $taxCat->taxes[0]; $this->tax2 = $taxCat2->taxes[0]; $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); $this->prd = $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); $this->prd = $prd; $this->prd2 = $prd2; $this->prdRefill = $prdRefill; // Tariff area $srvArea = new TariffAreasService(); $area = new TariffArea("area", 1); $area->addPrice($this->prd->id, 0.8); $area->id = $srvArea->create($area); $this->area = $area; // Discount profile $srvProfile = new DiscountProfilesService(); $profile = new DiscountProfile("Discount profile", 1.0); $profile->id = $srvProfile->create($profile); $this->discountProfile = $profile; // 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->customer = $cust; // Location $locSrv = new LocationsService(); $loc = new Location("Location"); $loc->id = $locSrv->create($loc); $this->location = $loc; // Cash $srvCashReg = new CashRegistersService(); $cashReg = new CashRegister("CashReg", $loc->id, 1); $cashReg->id = $srvCashReg->create($cashReg); $srvCash = new CashesService(); $cash = $srvCash->add($cashReg->id); $cash->openDate = stdtimefstr("2000-02-02 02:02:02"); $srvCash->update($cash); $this->cash = $cash; // User $srvUsers = new UsersService(); $user = new User("User", null, null, "0", true, false); $user->id = $srvUsers->create($user); $this->user = $user; // Currency $curr = new Currency("Eur", "€", ",", ".", "#,##0.00\$", 1, true, false); $srvCurr = new CurrenciesService(); $curr->id = $srvCurr->create($curr); $this->currency = $curr; }
public function testUpdate() { $broker = new APIBroker("CashesAPI"); $srv = new CashesService(); $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 = 1.0; $cash->closeCash = 13.0; $cash->expectedCash = 15.0; $result = $broker->run("update", array("cash" => json_encode($cash))); $this->assertEquals(APIResult::STATUS_CALL_OK, $result->status, "Result status check failed"); $content = $result->content; $this->assertNotNull($content, "Content is null"); $this->assertEquals($cash->id, $content->id, "Id mismatch"); $this->assertEquals($cash->cashRegisterId, $content->cashRegisterId, "Cash register id mismatch"); $this->assertEquals($cash->sequence, $content->sequence, "Sequence mismatch"); $this->assertEquals($cash->openDate, $content->openDate, "Open date mismatch"); $this->assertEquals($cash->closeDate, $content->closeDate, "Close date mismatch"); $this->assertEquals($cash->openCash, $content->openCash, "Open cash mismatch"); $this->assertEquals($cash->closeCash, $content->closeCash, "Close cash mismatch"); $this->assertEquals($cash->expectedCash, $content->expectedCash, "Expected cash mismatch"); }
/** @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"); }