'Seev Citycoco', '6' => 'WIZTEM']; $sql = "SELECT i.rowid, i.entity, i.ref, i.fk_warehouse, i.status, i.title , ent.ref, ent.lieu , ie.device_type FROM llx_inventory as i INNER JOIN llx_entrepot AS ent ON ent.rowid = i.fk_warehouse INNER JOIN llx_inventory_extrafields as ie ON ie.fk_object = i.rowid WHERE i.title ILIKE '%{$code}%'"; $result = $this->db->query($sql); if ($this->db->num_rows($result) > 0) { while ($row = $this->db->fetch_object($result)) { $row->device_type = $deviceTypes[$row->device_type]; return $row; } } return []; } public function getScooterRowidByCode($code) { $sql = "SELECT * FROM llx_inventory as i WHERE i.title ILIKE '%{$code}%'"; $result = $this->db->query($sql); if ($this->db->num_rows($result) > 0) { while ($row = $this->db->fetch_object($result)) { return $row->rowid; } } return []; } private function CreateScooterRentHistoryRecord($inventory_id, $invoice_number, $status = 1) { ApiBbusLog::ScooterRentLog('RentHistoryRecord: ___START___'); global $user; $rollerRentHistoryObj = new RollerRentHistory($this->db); $rollerRentHistoryObj->inventory_id = $inventory_id; $rollerRentHistoryObj->invoice_number = $invoice_number; $rollerRentHistoryObj->status = $status; return $rollerRentHistoryObj->create($user); } private function checkError($error) { if ($error > 0) { $this->db->rollback(); ApiBbusLog::ScooterRentLog('ConnectFactureAndScooter Rollback...'); throw new RestException(509); } } private function updateScooterBbticket($selectedTicket) { $ticketChecker = new TicketChecker(); $validated_at = date('Y-m-d H:i:s'); $duration = $this->getDurationByProductId($selectedTicket->ticket_id); $expire_at = $this->getExpireAt($selectedTicket, $duration, $validated_at); $usage = $this->setUsage($selectedTicket); $sql = "UPDATE " . $this->db->prefix() . "bbus_bbticket SET validated_at = '" . $validated_at . "', expire_at = '" . $expire_at . "'"; $sql .= ", usage = '" . $usage . "'"; $sql .= " WHERE rowid = " . $selectedTicket->rowid; return $this->db->query($sql); } private function getDurationByProductId($ticket_id) { $sql = "SELECT p.duration as duration FROM " . $this->db->prefix() . "product AS p WHERE rowid = " . $ticket_id; $result = $this->db->query($sql); while ($row = $this->db->fetch_object($result)) { return $row->duration; } } private function getExpireAt($obj, $duration, $validated_at) { return date('Y-m-d H:i:s', strtotime($validated_at . ' +' . substr($duration, 0, -1) . ' ' . $this->getIntervalTimeByDuration())); } private function setUsage($selectedTicket) { $usage = (int)$selectedTicket->usage + 1; return $usage; } private function getIntervalTimeByDuration() { $duration = $this->duration[-1]; switch ($duration) { case 'h': return 'hours'; case 'd': return 'days'; case 'w': return 'weeks'; case 'm': return 'months'; case 'y': return 'years'; default: return 'hours'; } } public function checkRentHistory($rowid, $invoice_number) { $sql = "SELECT * FROM llx_rollerstorage_rollerrenthistory WHERE inventory_id = {$rowid} AND invoice_number = '{$invoice_number}' AND status = 1"; return $this->db->query($sql); } public function getInvoiceNumberByInvetoryId($inventory_id) { $invoice_number = ''; $sql = "SELECT * FROM llx_rollerstorage_rollerrenthistory WHERE inventory_id = {$inventory_id} AND status = 1 ORDER BY date_creation DESC LIMIT 1"; $result = $this->db->query($sql); if ($this->db->num_rows($result) > 0) { while ($row = $this->db->fetch_object($result)) { $invoice_number = $row->invoice_number; } } return $invoice_number; } public function getBbticketDataByInvoiceNumber($invoice_number) { $bbTicketData = []; $sql = "SELECT * FROM llx_bbus_bbticket WHERE invoice_number = '{$invoice_number}'"; $result = $this->db->query($sql); if ($this->db->num_rows($result) > 0) { while ($row = $this->db->fetch_object($result)) { $bbTicketData = $row; } } return $bbTicketData; } public function checkExpireDate($invoice_number) { $now = date("Y-m-d H:i:s", dol_now()); if ($invoice_number !== '') { $ticketData = $this->getBbticketDataByInvoiceNumber($invoice_number); if (strtotime($ticketData->expire_at) < strtotime($now)) { return true; } } else { throw new RestException(508); } return false; } public function getTicketIdByInvoiceNumber($invoice_number) { $bbticketObj = $this->getBbticketDataByInvoiceNumber($invoice_number); return $bbticketObj->ticket_id; } }