protected function setUp()
 {
     // Products
     $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);
     $cat = new Category(null, "Category", false, 1);
     $cat->id = CategoriesService::createCat($cat);
     $prd1 = new Product("REF", "product", 1.0, $cat->id, null, 1, $taxCat->id, true, true, 0.3, null, "12345", false, true, 0.2);
     $prd1->id = ProductsService::create($prd1);
     $prd2 = new Product("REF2", "product2", 2.0, $cat->id, null, 3, $taxCat->id, true, false);
     $prd2->id = ProductsService::create($prd2);
     $this->products = array($prd1, $prd2);
     // Locations
     $locSrv = new LocationsService();
     $loc1 = new Location("Location1");
     $loc1->id = $locSrv->create($loc1);
     $loc2 = new Location("Location2");
     $loc2->id = $locSrv->create($loc2);
     $this->locations = array($loc1, $loc2);
     // Stocks
     $lvl11 = new StockLevel($prd1->id, $loc1->id, null, null, 10);
     $lvl11->id = StocksService::createLevel($lvl11);
     $lvl12 = new StockLevel($prd1->id, $loc2->id, null, 5.2, null);
     $lvl12->id = StocksService::createLevel($lvl12);
     $lvl21 = new StockLevel($prd2->id, $loc1->id, null, 7, 20);
     $lvl21->id = StocksService::createLevel($lvl21);
     $move = new StockMove(stdtimefstr("2014-01-01 00:00:00"), StockMove::REASON_IN_BUY, $loc1->id, $prd1->id, null, 3.5, 2.1);
     StocksService::addMove($move);
     $this->levels = array($lvl11, $lvl12, $lvl21);
 }
Exemple #2
0
function init_catalog_old($jsName, $containerId, $selectCallback, $categories, $products)
{
    echo '<script type="text/javascript" src="inc/catalog-old.js"></script>';
    echo '<script type="text/javascript">';
    echo "var {$jsName} = new Catalog(\"{$containerId}\", \"{$selectCallback}\");\n";
    echo "jQuery(document).ready(function() {\n";
    echo "var html = \"<div class=\\\"catalog-categories-container\\\"></div>\";\n";
    echo "html += \"<div class=\\\"catalog-products-container\\\"></div>\";\n";
    echo "jQuery(\"#{$containerId}\").html(html);\n";
    foreach ($categories as $cat) {
        echo $jsName . ".createCategory(\"" . $jsName . "\", \"" . $cat->id . "\"" . ", \"" . $cat->label . "\", " . ($cat->hasImage ? "true" : "false") . ");\n";
    }
    foreach ($products as $product) {
        $taxCat = TaxesService::get($product->taxCatId);
        $tax = $taxCat->getCurrentTax();
        $vatPrice = $product->priceSell * (1 + $tax->rate);
        $prd = '{' . jsonify("id", $product->id) . ', ' . jsonify("label", $product->label) . ', ' . jsonify("reference", $product->reference) . ', ' . jsonify("hasImage", $product->hasImage) . ', ' . jsonify("buy", $product->priceBuy) . ', ' . jsonify("sell", $product->priceSell) . ', ' . jsonify("vatSell", $vatPrice) . '}';
        echo $jsName . ".addProductToCat(\"" . $product->id . "\", \"" . $product->categoryId . "\");\n";
        echo $jsName . ".addProduct(" . $prd . ");\n";
    }
    if (count($categories) > 0) {
        echo $jsName . ".changeCategory(\"" . $categories[0]->id . "\");\n";
    }
    echo "});\n</script>";
}
 private static function buildTicket($row, $pdo)
 {
     $db = DB::get();
     $id = $row['ID'];
     // Get lines
     $lines = array();
     $lineSql = "SELECT * FROM TICKETLINES WHERE TICKET = :id " . "ORDER BY LINE";
     $lineStmt = $pdo->prepare($lineSql);
     $lineStmt->bindParam(":id", $id);
     $lineStmt->execute();
     while ($rowLine = $lineStmt->fetch()) {
         $product = ProductsService::get($rowLine['PRODUCT']);
         $tax = TaxesService::getTax($rowLine['TAXID']);
         $line = new TicketLine($rowLine['LINE'], $product, $rowLine['ATTRIBUTESETINSTANCE_ID'], $rowLine['UNITS'], $rowLine['PRICE'], $tax, $rowLine['DISCOUNTRATE']);
         $lines[] = $line;
     }
     // Get payments
     $payments = array();
     $paySql = "SELECT * FROM PAYMENTS WHERE RECEIPT = :id";
     $payStmt = $pdo->prepare($paySql);
     $payStmt->bindParam(":id", $id);
     $payStmt->execute();
     while ($rowPay = $payStmt->fetch()) {
         $pay = Payment::__build($rowPay['ID'], $rowPay['PAYMENT'], $rowPay['TOTAL'], $rowPay['CURRENCY'], $rowPay['TOTALCURRENCY']);
         $payments[] = $pay;
     }
     // Build ticket
     $tkt = Ticket::__build($row['ID'], $row['TICKETID'], $row['TICKETTYPE'], $row['PERSON'], $db->readDate($row['DATENEW']), $lines, $payments, $row['MONEY'], $row['CUSTOMER'], $row['CUSTCOUNT'], $row['TARIFFAREA'], $row['DISCOUNTRATE'], $row['DISCOUNTPROFILE_ID']);
     return $tkt;
 }
Exemple #4
0
 function getTotalPrice()
 {
     $taxCat = TaxesService::get($this->taxCatId);
     $currentTax = $this->taxCat->getCurrentTax();
     if ($currentTax != null) {
         return $this->priceSell * (1 + $currentTax->rate);
     } else {
         return $this->priceSell;
     }
 }
Exemple #5
0
 protected function proceed()
 {
     switch ($this->action) {
         case 'get':
             $this->succeed(TaxesService::get($this->params['id']));
             break;
         case 'getAll':
             $this->succeed(TaxesService::getAll());
             break;
     }
 }
 protected function setUp()
 {
     $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);
     $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);
     $this->prdId = ProductsService::create($prd);
 }
 protected function setUp()
 {
     $this->products = array();
     $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);
     $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, true, 0.3, null, "12345", false, true, 0.2);
     $prd->id = ProductsService::create($prd);
     $this->products[] = $prd;
     $prd2 = new Product("REF2", "product2", 2.0, $cat->id, null, 3, $taxCat->id, true, false);
     $prd2->id = ProductsService::create($prd2);
     $this->products[] = $prd2;
 }
 protected function setUp()
 {
     $this->taxes = array();
     $taxCat1 = new TaxCat("Standard");
     $tax1 = new Tax(null, "20%", stdtimefstr("2014-01-01 00:00:00"), 0.2);
     $taxCat1->addTax($tax1);
     $tax3 = new Tax(null, "Old", stdtimefstr("2000-01-01 00:00:00"), 0.22);
     $taxCat1->addTax($tax3);
     $taxCat1->id = TaxesService::createCat($taxCat1);
     $taxCat2 = new TaxCat("Reduced");
     $tax2 = new Tax(null, "10%", stdtimefstr("2014-01-01 00:00:00"), 0.1);
     $taxCat2->addTax($tax2);
     $taxCat2->id = TaxesService::createCat($taxCat2);
     $this->taxes[] = $taxCat1;
     $this->taxes[] = $taxCat2;
 }
 protected function setUp()
 {
     $this->areas = array();
     $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);
     $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);
     $prd->id = ProductsService::create($prd);
     $area = new TariffArea("Area", 1);
     $area->addPrice($prd->id, 0.8);
     $srv = new TariffAreasService();
     $area->id = $srv->create($area);
     $area2 = new TariffArea("Area51", 51);
     $area2->id = $srv->create($area2);
     $this->areas[] = $area;
     $this->areas[] = $area2;
 }
 protected function setUp()
 {
     // Products
     $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);
     $cat = new Category(null, "Category", false, 1);
     $cat->id = CategoriesService::createCat($cat);
     $prd1 = new Product("REF", "product", 1.0, $cat->id, null, 1, $taxCat->id, true, true, 0.3, null, "12345", false, true, 0.2);
     $prd1->id = ProductsService::create($prd1);
     $prd2 = new Product("REF2", "product2", 2.0, $cat->id, null, 3, $taxCat->id, true, false);
     $prd2->id = ProductsService::create($prd2);
     $this->products = array($prd1, $prd2);
     // Locations
     $locSrv = new LocationsService();
     $loc1 = new Location("Location1");
     $loc1->id = $locSrv->create($loc1);
     $loc2 = new Location("Location2");
     $loc2->id = $locSrv->create($loc2);
     $this->locations = array($loc1, $loc2);
 }
 protected function setUp()
 {
     $this->products = array();
     $this->compositions = array();
     // Setup tax and categories
     $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);
     $pdo = PDOBuilder::getPDO();
     $id = CompositionsService::CAT_ID;
     $catCmp = new Category(null, "Compositions", false, 1);
     $sql = "INSERT INTO CATEGORIES (ID, NAME, PARENTID, DISPORDER, IMAGE) " . "VALUES (:id, :name, :pid, :order, null)";
     $stmt = $pdo->prepare($sql);
     $stmt->bindParam(":name", $catCmp->label, \PDO::PARAM_STR);
     $stmt->bindParam(":pid", $catCmp->parentId, \PDO::PARAM_INT);
     $stmt->bindParam(":id", $id, \PDO::PARAM_INT);
     $stmt->bindParam(":order", $catCmp->dispOrder, \PDO::PARAM_INT);
     $stmt->execute();
     $cat = new Category(null, "Category", false, 2);
     $cat->id = CategoriesService::createCat($cat);
     // Set up products
     $prd = new Product("REF", "product", 1.0, $cat->id, null, 1, $taxCat->id, true, true, 0.3, null, "12345", false, true, 0.2);
     $prd->id = ProductsService::create($prd, null);
     $this->products[] = $prd;
     $prd2 = new Product("REF2", "product2", 2.0, $cat->id, null, 3, $taxCat->id, true, false);
     $prd2->id = ProductsService::create($prd2, null);
     $this->products[] = $prd2;
     $cmp = new Composition("CMP", "composition", 1.0, $id, 1, $taxCat->id, true, true, 0.3, null, "12345", false, true, 0.2);
     $subgrp = new Subgroup(null, "Subgroup", 1, false);
     $subgrp->addProduct(new SubgroupProduct($prd->id, null, 1));
     $subgrp->addProduct(new SubgroupProduct($prd2->id, null, 2));
     $cmp->addGroup($subgrp);
     $cmp->id = CompositionsService::create($cmp, null, null);
     $this->compositions[] = $cmp;
 }
 static function getTax($id)
 {
     $pdo = PDOBuilder::getPDO();
     $stmt = $pdo->prepare("SELECT * FROM TAXES WHERE ID = :id");
     if ($stmt->execute(array(':id' => $id))) {
         if ($row = $stmt->fetch()) {
             return TaxesService::buildDBTax($row, $pdo);
         }
     }
     return null;
 }
 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);
 }
Exemple #14
0
 protected function proceed()
 {
     switch ($this->action) {
         case 'getShared':
             $tkt = TicketsService::getSharedTicket($this->params['id']);
             $this->succeed($tkt);
             break;
         case 'getAllShared':
             $tkts = TicketsService::getAllSharedTickets();
             $this->succeed($tkts);
             break;
         case 'delShared':
             $this->succeed(TicketsService::deleteSharedTicket($this->params['id']));
             break;
         case 'share':
             $json = json_decode($this->params['ticket']);
             $ticket = SharedTicket::__build($json->id, $json->label, $json->customerId, $json->custCount, $json->tariffAreaId, $json->discountProfileId, $json->discountRate);
             $lines = array();
             foreach ($json->lines as $jsLine) {
                 // Get line info
                 $tktLine = new SharedTicketLines($ticket->id, $jsLine->dispOrder, $jsLine->productId, $jsLine->taxId, $jsLine->quantity, $jsLine->discountRate, $jsLine->price, $jsLine->attributes);
                 $lines[] = $tktLine;
             }
             if (TicketsService::createSharedTicket($ticket, $lines) === false) {
                 $this->succeed(TicketsService::updateSharedTicket($ticket, $lines));
             } else {
                 $this->succeed(true);
             }
             break;
         case 'getOpen':
             $this->succeed(TicketsService::getOpen());
             break;
         case 'search':
             $this->succeed(TicketsService::search($this->getParam("ticketId"), $this->getParam("ticketType"), $this->getParam("cashId"), $this->getParam("dateStart"), $this->getParam("dateStop"), $this->getParam("customerId"), $this->getParam("userId"), $this->getParam("limit")));
             break;
         case 'delete':
             if (!TicketsService::delete($this->getParam("id"))) {
                 $this->fail(APIError::$ERR_GENERIC);
             } else {
                 $this->succeed(true);
             }
             break;
         case 'save':
             // Receive ticket data as json
             // Convert single ticket to array for consistency
             if (isset($this->params['tickets'])) {
                 $json = json_decode($this->params['tickets']);
             } else {
                 $json = array(json_decode($this->params['ticket']));
             }
             // Get location from cash register
             $cashId = $this->params['cashId'];
             $cashSrv = new CashesService();
             $cash = $cashSrv->get($cashId);
             if ($cash === null) {
                 $this->fail(new APIError("Unknown cash session"));
                 break;
             }
             $cashRegSrv = new CashRegistersService();
             $cashReg = $cashRegSrv->get($cash->cashRegisterId);
             if ($cashReg === null) {
                 $this->fail(new APIError("Cash register not found"));
                 break;
             }
             $locationId = $cashReg->locationId;
             if ($locationId === null) {
                 $this->fail(new APIError("Location not set"));
                 break;
             }
             // Register tickets
             $ticketsCount = count($json);
             $successes = 0;
             $pdo = PDOBuilder::getPDO();
             if (!$pdo->beginTransaction()) {
                 $this->fail(APIError::$ERR_GENERIC);
                 break;
             }
             foreach ($json as $jsonTkt) {
                 if ($jsonTkt === null) {
                     $this->fail(new APIError("Unable to decode ticket"));
                     break;
                 }
                 $ticketId = $jsonTkt->ticketId;
                 $userId = $jsonTkt->userId;
                 $customerId = $jsonTkt->customerId;
                 $date = $jsonTkt->date;
                 $tktType = $jsonTkt->type;
                 $custCount = $jsonTkt->custCount;
                 $tariffAreaId = $jsonTkt->tariffAreaId;
                 $discountRate = $jsonTkt->discountRate;
                 $discountProfileId = $jsonTkt->discountProfileId;
                 // Get lines
                 $lines = array();
                 foreach ($jsonTkt->lines as $jsLine) {
                     // Get line info
                     $number = $jsLine->dispOrder;
                     if (property_exists($jsLine, "productId")) {
                         $productId = $jsLine->productId;
                     } else {
                         $productId = null;
                     }
                     $productLabel = $jsLine->productLabel;
                     $quantity = $jsLine->quantity;
                     $price = $jsLine->price;
                     $taxId = $jsLine->taxId;
                     $lineDiscountRate = $jsLine->discountRate;
                     if ($jsLine->attributes !== null) {
                         $jsAttr = $jsLine->attributes;
                         $attrSetId = $jsAttr->attributeSetId;
                         $values = $jsAttr->values;
                         $desc = "";
                         foreach ($values as $val) {
                             $desc .= $val->value . ", ";
                         }
                         $desc = substr($desc, 0, -2);
                         $attrs = new AttributeSetInstance($attrSetId, $desc);
                         foreach ($values as $val) {
                             $attrVal = new AttributeInstance(null, $val->id, $val->value);
                             $attrs->addAttrInst($attrVal);
                         }
                         $attrsId = TicketsService::createAttrSetInst($attrs);
                         if ($attrsId === false) {
                             $this->fail(new APIError("Unknown attributes"));
                             break;
                         }
                     } else {
                         $attrsId = null;
                     }
                     $product = ProductsService::get($productId);
                     if ($product === null) {
                         $product = new Product($productId, $productId, $productId, null, null, null, $taxId, true, false);
                     }
                     $tax = TaxesService::getTax($taxId);
                     if ($tax == null) {
                         $this->fail(new APIError("Unknown tax"));
                         break;
                     }
                     $newLine = new TicketLine($number, $product, $attrsId, $quantity, $price, $tax, $lineDiscountRate, $productLabel);
                     $lines[] = $newLine;
                 }
                 if (count($lines) != count($jsonTkt->lines)) {
                     break;
                 }
                 // Get payments
                 $payments = array();
                 foreach ($jsonTkt->payments as $jspay) {
                     $type = $jspay->type;
                     $amount = $jspay->amount;
                     if (!property_exists($jspay, "currencyId") || $jspay->currencyId === null) {
                         $currSrv = new CurrenciesService();
                         $currencyId = $currSrv->getDefault()->id;
                         $currencyAmount = $amount;
                     } else {
                         $currencyId = $jspay->currencyId;
                         $currencyAmount = $jspay->currencyAmount;
                     }
                     $backType = null;
                     $backAmount = null;
                     if (property_exists($jspay, "back") && $jspay->back !== null) {
                         $backType = $jspay->back->type;
                         $backAmount = $jspay->back->amount;
                     }
                     $payment = new Payment($type, $amount, $currencyId, $currencyAmount, $backType, $backAmount);
                     $payments[] = $payment;
                 }
                 $ticket = new Ticket($tktType, $userId, $date, $lines, $payments, $cashId, $customerId, $custCount, $tariffAreaId, $discountRate, $discountProfileId);
                 $ticket->ticketId = $ticketId;
                 if (isset($jsonTkt->id)) {
                     // Ticket edit
                     $ticket->id = $jsonTkt->id;
                     //Check if cash is still opened
                     $oldTicket = TicketsService::get($id);
                     if ($oldTicket != null) {
                         $cashSrv = new CashesService();
                         $cash = $cashSrv->get($oldTicket->cashId);
                         if ($cash->isClosed()) {
                             $this->fail(new APIError("Cannot edit a ticket from " . "a closed cash"));
                             break;
                         }
                         // Delete the old ticket and recreate
                         if (TicketsService::delete($oldTicket->id) && TicketsService::save($ticket, $locationId)) {
                             $successes++;
                         } else {
                             $this->fail(new APIError("Unable to edit ticket"));
                             break;
                         }
                     }
                 } else {
                     // New ticket
                     if (TicketsService::save($ticket)) {
                         $successes++;
                     } else {
                         $this->fail(new APIError("Unable to save ticket"));
                         break;
                     }
                 }
             }
             // Check if all tickets were saved, if not rollback and error
             $ret = $successes == $ticketsCount;
             if ($ret === true) {
                 if ($pdo->commit()) {
                     $ticketId++;
                     $cashRegSrv->setNextTicketId($ticketId, $cash->cashRegisterId);
                     $this->succeed(array("saved" => $ticketsCount));
                 } else {
                     $this->fail(APIError::$ERR_GENERIC);
                 }
             } else {
                 $pdo->rollback();
                 if ($this->result === null) {
                     $this->fail(APIError::$ERR_GENERIC);
                 }
             }
             break;
     }
 }
Exemple #15
0
function form_input($form_id, $class, $object, $field, $type, $args = array())
{
    if (!isset($args['nolabel']) || $args['nolabel'] === false) {
        echo "<div class=\"row\">\n";
    }
    if (isset($args['nameid']) && $args['nameid'] == true) {
        $name = $field . "-" . $form_id;
    } else {
        $name = $field;
    }
    if (isset($args['array']) && $args['array'] == true) {
        $name = $name . "[]";
    }
    if ($type != "pick_multiple") {
        if (!isset($args['nolabel']) || $args['nolabel'] === false) {
            echo '<label for="' . esc_attr($form_id . '-' . $field) . '">';
            $fieldLabel = $field;
            if (substr($field, -2) == "Id") {
                $fieldLabel = substr($field, 0, -2);
            }
            echo esc_html(\i18n($class . "." . $fieldLabel));
            echo "</label>\n";
        }
    }
    $required = "";
    if (isset($args['required']) && $args['required']) {
        $required = ' required="true"';
    }
    switch ($type) {
        case 'string':
            echo '<input id="' . esc_attr($form_id . '-' . $field) . '" type="text" name="' . esc_attr($name) . '"';
            if ($object != NULL) {
                echo ' value="' . esc_attr($object->{$field}) . '"';
            }
            echo "{$required} />\n";
            break;
        case 'text':
            echo '<textarea id="' . esc_attr($form_id . '-' . $field) . '" name="' . esc_attr($name) . '">';
            if ($object != NULL) {
                echo esc_html($object->{$field});
            }
            echo '</textarea>';
            break;
        case 'numeric':
            echo '<input id="' . esc_attr($form_id . '-' . $field) . '" type="numeric" name="' . esc_attr($name) . '"';
            if ($object != NULL) {
                echo ' value="' . esc_attr($object->{$field}) . '"';
            }
            echo "{$required} />\n";
            break;
        case 'boolean':
            echo '<input id="' . esc_attr($form_id . '-' . $field) . '" type="checkbox" name="' . esc_attr($name) . '"';
            if ($object != NULL) {
                if ($object->{$field}) {
                    echo ' checked="checked"';
                }
            } else {
                if (!isset($args['default']) || $args['default'] == TRUE) {
                    echo ' checked="checked"';
                }
            }
            echo " />\n";
            break;
        case 'float':
            if (!isset($args['step'])) {
                $step = 0.01;
            } else {
                $step = $args['step'];
            }
            echo '<input id="' . esc_attr($form_id . '-' . $field) . '" type="number" step="' . esc_attr($step) . '" min="0.00" name="' . esc_attr($name) . '"';
            if ($object != NULL) {
                echo ' value="' . esc_attr($object->{$field}) . '"';
            }
            echo "{$required} />\n";
            break;
        case 'date':
            // Class dateinput will be catched to show js date picker
            echo '<input id="' . esc_attr($form_id . '-' . $field) . '" type="text" class="dateinput" name="' . esc_attr($name) . '"';
            if ($object !== null) {
                if (isset($args['dataformat'])) {
                    if ($args['dataformat'] == 'standard') {
                        $timestamp = stdtimefstr($object->{$field});
                    } else {
                        $timestamp = timefstr($args['dataformat'], $object->{$field});
                    }
                } else {
                    $timestamp = $object->{$field};
                }
                echo ' value="' . esc_attr(\i18nDate($timestamp)) . '"';
            }
            echo "{$required} />\n";
            break;
        case 'pick':
            $model = $args['model'];
            $data = $args['data'];
            if ($model !== null) {
                switch ($model) {
                    case 'Category':
                        $data = CategoriesService::getAll(false);
                        break;
                    case 'Provider':
                        $data = ProvidersService::getAll();
                        break;
                    case 'TaxCategory':
                        $data = TaxesService::getAll();
                        break;
                    case 'Tax':
                        $cats = TaxesService::getAll();
                        $data = array();
                        foreach ($cats as $cat) {
                            $data[] = $cat->getCurrentTax();
                        }
                        break;
                    case 'CustTaxCat':
                        $data = CustTaxCatsService::getAll();
                        break;
                    case 'Role':
                        $data = RolesService::getAll();
                        break;
                    case 'Attribute':
                        $data = AttributesService::getAllAttrs();
                        break;
                    case 'AttributeSet':
                        $data = AttributesService::getAll();
                        break;
                    case 'Location':
                        $locSrv = new LocationsService();
                        $data = $locSrv->getAll();
                        break;
                    case 'DiscountProfile':
                        $profSrv = new DiscountProfilesService();
                        $data = $profSrv->getAll();
                        break;
                    case 'TariffArea':
                        $areaSrv = new TariffAreasService();
                        $data = $areaSrv->getAll();
                        break;
                }
            }
            echo '<select id="' . esc_attr($form_id . '-' . $field) . '" name="' . esc_attr($name) . '">';
            if (isset($args['nullable']) && $args['nullable']) {
                echo '<option value=""></option>';
            }
            foreach ($data as $r) {
                $selected = "";
                $r_id = $r->id;
                $r_label = $r->label;
                if ($model == null) {
                    $r_id = $r['id'];
                    $r_label = $r['label'];
                }
                if ($object != NULL && ($object->{$field} == $r_id || is_object($object->{$field}) && $object->{$field}->id == $r_id)) {
                    $selected = ' selected="true"';
                }
                echo '<option value="' . esc_attr($r_id) . '"' . $selected . '>' . esc_html($r_label) . '</option>';
            }
            echo "</select>\n";
            break;
        case 'pick_multiple':
            $model = $args['model'];
            switch ($model) {
                case 'Category':
                    $data = CategoriesService::getAll();
                    break;
            }
            foreach ($data as $r) {
                $selected = "";
                if ($object != NULL && array_search($r->id, $object->{$field}) !== FALSE) {
                    $selected = ' checked="true"';
                }
                $id = $form_id . "-" . $field . "-" . $r->id;
                echo '<label for="' . esc_attr($id) . '">' . esc_html($r->label) . '</label>';
                echo '<input id="' . esc_attr($id) . '" type="checkbox" name="' . esc_attr($name) . '[]" value="' . esc_attr($r->id) . '"' . $selected . "/>\n";
            }
            break;
    }
    if (!isset($args['nolabel']) || $args['nolabel'] === false) {
        echo "</div>";
    }
}
Exemple #16
0
 function getAmount()
 {
     $tax = TaxesService::getTax($this->taxId);
     return $this->base * $tax->rate;
 }
 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;
 }