| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- <?php
- /* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
- * Copyright (C) 2024 László Szollősi
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
- use Luracast\Restler\RestException;
- dol_include_once('/rollerstorage/class/rollerhistory.class.php');
- require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/groupusers.class.php';
- require_once DOL_DOCUMENT_ROOT . '/custom/rollerstorage/class/rollerhistory.class.php';
- require_once DOL_DOCUMENT_ROOT . '/custom/rollerstorage/class/lunatours.class.php';
- require_once DOL_DOCUMENT_ROOT . '/custom/bbus/class/api_bbus_log.class.php';
- require_once DOL_DOCUMENT_ROOT . '/custom/bbus/class/api_bbus.class.php';
- require_once DOL_DOCUMENT_ROOT . '/api/class/api_access.class.php';
- /**
- * \file rollerstorage/class/api_rollerstorage.class.php
- * \ingroup rollerstorage
- * \brief File for API management of rollerhistory.
- */
- /**
- * API class for rollerstorage rollerhistory
- *
- * @access protected
- * @class DolibarrApiAccess {@requires user,external}
- */
- class RollerstorageApi extends DolibarrApi
- {
- /**
- * @var RollerHistory $rollerhistory {@type RollerHistory}
- */
- public $rollerhistory;
- public $lunatours;
- /**
- * Constructor
- *
- * @url GET /
- *
- */
- public function __construct()
- {
- global $db;
- $this->db = $db;
- $this->rollerhistory = new RollerHistory($this->db);
- $this->lunatours = new Lunatours($db);
- }
- private function runQuery($sql)
- {
- $array = [];
- $result = $this->db->query($sql);
- if ($this->db->num_rows($result) > 0) {
- while ($row = $this->db->fetch_object($result)) {
- $array[] = $row;
- }
- }
- return $array;
- }
- /**
- * Get app config
- *
- * Return an array with config params.
- *
- * @return array|mixed Data without useless information
- *
- * @url GET config
- *
- * @throws RestException 401
- * @throws RestException 403
- * @throws RestException 404
- */
- public function config(): array
- {
- $ApiBbus = new BBus();
- return $ApiBbus->config();
- }
- /**
- * checkPermissionLT
- *
- * Return a result.
- *
- * @return array|mixed Data without useless information
- *
- * @url POST checkPermissionLT
- */
- public function checkPermissionLT()
- {
- global $conf, $user;
- //ApiBbusLog::LunaToursLog("checkPermissionLT_START");
- $memcached = new Memcached();
- $memcached->addServer("szollosil-excelia-urbanms-memcached", 11211);
- $key = '"' . $user->api_key . '"';
- $cacheValue = $memcached->get($key);
- if ($cacheValue === false) {
- $permissionArray = [];
- $sqlProductsBasicService = "SELECt p.rowid, p.label, p.description, p.price_ttc, p.price, p.tva_tx FROM llx_product as p
- INNER JOIN llx_product_extrafields as pe ON pe.fk_object = p.rowid
- INNER JOIN llx_bbus_basicservices as bs ON bs.basic_service_id = pe.basic_service::integer
- WHERE bs.server_host = '{$conf->global->LOCAL_SERVER_HOST}'";
- $productsBasicServices = $this->runQuery($sqlProductsBasicService);
- $permissionArray = $this->lunatours->createPermissionArray($productsBasicServices);
- $cacheValue = json_encode($permissionArray);
- $memcached->set($key, $cacheValue, 600); // 5 percig tároljuk
- //ApiBbusLog::LunaToursLog("Adat betöltve az adatbázisból: " . $cacheValue);
- } else {
- //ApiBbusLog::LunaToursLog("Adat betöltve a cache-ből: " . $cacheValue);
- }
- return json_decode($cacheValue, true);
- }
- /**
- * getAllAvailablePlaces
- *
- * Return a result.
- *
- * @return array|mixed Data without useless information
- *
- * @param string date_from
- * @param string date_to
- * @param int product_id
- *
- * @url POST getAllAvailablePlaces
- */
- public function getAllAvailablePlaces($date_from, $date_to, $product_id)
- {
- ApiBbusLog::LunaToursLog("getAllAvailablePlaces");
- return $this->lunatours->localAvailablePlaces($date_from, $date_to, $product_id);
- }
- /**
- * FirstStepPreOrder
- *
- * Return a result.
- *
- * @return array|mixed Data without useless information
- *
- * @param int $fk_event //selected evet from llx_event
- * @param int $reservations //numbers of reservations
- * @param int $product_id //Product
- *
- * @url POST FirstStepPreOrder
- */
- public function FirstStepPreOrder(int $fk_event, int $reservations, int $product_id)
- {
- global $conf;
- ApiBbusLog::LunaToursLog("FirstStepPreOrder");
- if (!DolibarrApiAccess::$user->rights->facture->creer) {
- ApiBbusLog::LunaToursLog("{$sendId} Insufficient rights");
- throw new RestException(401, 'Insufficient rights');
- }
- $this->lunatours->createLog($fk_event, $reservations, $product_id);
- $createdPreOrderOBJ = $this->lunatours->localcreatedpreorderobj($fk_event, $reservations, $product_id);
- ApiBbusLog::LunaToursLog(json_encode($createdPreOrderOBJ));
- return $createdPreOrderOBJ;
- }
- /**
- * Validate and save invoice
- *
- * Return an array with details
- *
- * @return array|mixed data without useless information
- *
- * @param array $payment Invoice payment
- * @param array $preorder preorder
- * @param array $invoice Invoice
- * @param string $cardPaymentLog Card payment log data
- * @param string $note Name, phone, email
- * @param array $company_invoice Invoice data
- *
- * @url POST validateandsaveinvoice
- * @access protected
- * @throws RestException 401 Not allowed
- * @throws RestException 404 Not found
- * @throws RestException 506 No available spaces
- *
- */
- public function validateandsaveinvoice(array $payment, array $preorder, array $invoice, string $cardPaymentLog = '', $note = '', $company_invoice = [])
- {
- ApiBbusLog::LunaToursLog("validateandsaveinvoice: START");
- $createdInvoiceArray = $this->lunatours->localValidateAndSaveInvoice($invoice, $preorder, $payment, $cardPaymentLog, $company_invoice);
- ApiBbusLog::LunaToursLog(json_encode($preorder));
- foreach ($preorder as $order) {
- $sql = "SELECT fk_product, fk_event FROM llx_booking_preorder WHERE rowid = {$order}";
- $data = $this->db->query($sql);
- if ($this->db->num_rows($data) > 0) {
- while ($row = $this->db->fetch_object($data)) {
- $bookingHistory = $this->lunatours->saveEventData((int)$row->fk_event, $createdInvoiceArray[0]['invoice']['id'], null, $createdInvoiceArray[0]['invoice']['ref'], $note);
- ApiBbusLog::LunaToursLog("______________________________________________________________________________");
- $this->lunatours->updateBbticket($createdInvoiceArray[0]['invoice'], $bookingHistory);
- $this->lunatours->deletePreorder($preorder);
- }
- }
- }
- ApiBbusLog::LunaToursLog("validateandsaveinvoice: END");
- $this->lunatours->emailSender($note, $createdInvoiceArray);
- return $createdInvoiceArray;
- }
- /**
- * Check user and eventdetail type permissions
- *
- * Return a result.
- *
- * @return array|mixed Data without useless information
- *
- * @url POST checkPermission
- */
- public function checkPermission()
- {
- global $user, $db;
- $permissionArray = [];
- dol_include_once('/eventwizard/class/eventdetails.class.php');
- $sqlBasicService = "SELECT pe.basic_service FROM llx_product as p
- INNER JOIN llx_product_extrafields as pe ON pe.fk_object = p.rowid
- GROUP BY pe.basic_service";
- $resultBasicServices = $db->query($sqlBasicService);
- if ($db->num_rows($resultBasicServices) > 0) {
- while ($row = $db->fetch_object($resultBasicServices)) {
- $basicServices[] = $row->basic_service;
- }
- }
- $sqlBasicServicesTable = "SELECT basic_service_id, ref FROM llx_bbus_basicServices WHERE server_host = 'excelia' ORDER BY basic_service_id ASC";
- $resultBasicServicesObj = $db->query($sqlBasicServicesTable);
- if ($db->num_rows($resultBasicServicesObj) > 0) {
- while ($bsrow = $db->fetch_object($resultBasicServicesObj)) {
- foreach ($basicServices as $item) {
- if ($bsrow->basic_service_id == $item) {
- $permissionArray[$item] = $bsrow->ref;
- }
- }
- }
- }
- return $permissionArray;
- }
- }
|