|
|
@@ -83,6 +83,31 @@ trait RollerHandling
|
|
|
return $statuses;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Get all statuses of a rollers
|
|
|
+ *
|
|
|
+ * Return an array with product information.
|
|
|
+ *
|
|
|
+ * @return array|mixed Data without useless information
|
|
|
+ *
|
|
|
+ * @url GET RENT_GetAllStatuses
|
|
|
+ */
|
|
|
+ public function RENT_GetAllStatuses()
|
|
|
+ {
|
|
|
+ ApiBbusLog::ScooterRentLog("RENT_GetAllStatuses: ___START___");
|
|
|
+ $statuses = [];
|
|
|
+ $sql = "SELECT status_id FROM llx_rollerstorage_statuses";
|
|
|
+ $result = $this->db->query($sql);
|
|
|
+ if ($this->db->num_rows($result) > 0) {
|
|
|
+ while ($row = $this->db->fetch_object($result)) {
|
|
|
+ $statuses[] = $row->status_id;
|
|
|
+ }
|
|
|
+ ApiBbusLog::ScooterRentLog("RENT_GetAllStatuses: ___END___");
|
|
|
+ return $statuses;
|
|
|
+ }
|
|
|
+ ApiBbusLog::ScooterRentLog("RENT_GetAllStatuses: ___END___");
|
|
|
+ return $statuses;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* Set status of a scooter
|
|
|
@@ -96,6 +121,10 @@ trait RollerHandling
|
|
|
*/
|
|
|
public function RENT_setScooterStatus($statuscode, $rowid)
|
|
|
{
|
|
|
+ $statuses = $this->RENT_GetAllStatuses();
|
|
|
+ if (!in_array($statuscode, $statuses)) {
|
|
|
+ throw new RestException(404, 'Status Not found.');
|
|
|
+ }
|
|
|
ApiBbusLog::ScooterRentLog("RENT_setScooterStatus: ___START___");
|
|
|
$sql = "UPDATE llx_inventory SET status = {$statuscode} WHERE rowid = {$rowid}";
|
|
|
$result = $this->db->query($sql);
|
|
|
@@ -107,26 +136,31 @@ trait RollerHandling
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Connect scooter and event
|
|
|
+ * Connect scooter and facture
|
|
|
*
|
|
|
* @param string $inventory_id
|
|
|
- * @param string $invoice_number
|
|
|
- * @param int $ticket_id
|
|
|
+ * @param string $ticketQRCode
|
|
|
*
|
|
|
* @return array|mixed Data without useless information
|
|
|
*
|
|
|
* @url POST RENT_ConnectFactureAndScooter
|
|
|
*/
|
|
|
- public function RENT_ConnectFactureAndScooter($inventory_id, $invoice_number, $ticket_id, $isReplaced = false)
|
|
|
+ public function RENT_ConnectFactureAndScooter($inventory_id, $ticketQRCode, $isReplaced = false)
|
|
|
{
|
|
|
ApiBbusLog::ScooterRentLog("RENT_ConnectFactureAndScooter: ___START___");
|
|
|
+ $QRCodeData = explode('_', $ticketQRCode);
|
|
|
+ if ($this->isRented($QRCodeData, $inventory_id)) {
|
|
|
+ ApiBbusLog::ScooterRentLog("RENT_ConnectFactureAndScooter: Already rented -> return: FALSE");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
$error = 0;
|
|
|
$this->db->begin();
|
|
|
- $ScooterRentHistoryId = $this->CreateScooterRentHistoryRecord($inventory_id, $invoice_number);
|
|
|
+ $ScooterRentHistoryId = $this->CreateScooterRentHistoryRecord($inventory_id, $QRCodeData[0], $QRCodeData[1], null);
|
|
|
(int)$ScooterRentHistoryId > 0 ?: $error++;
|
|
|
ApiBbusLog::ScooterRentLog("RentHistoryRecord: {$ScooterRentHistoryId}");
|
|
|
$this->RENT_setScooterStatus("112", $inventory_id) == '112' ?: $error++;
|
|
|
- if(!$isReplaced){
|
|
|
+ $ticket_id = $this->getTicketId($QRCodeData[0], $QRCodeData[1]);
|
|
|
+ if (!$isReplaced) {
|
|
|
$sql = "SELECT * FROM llx_bbus_bbticket WHERE rowid = {$ticket_id}";
|
|
|
$result = $this->db->query($sql);
|
|
|
while ($row = $this->db->fetch_object($result)) {
|
|
|
@@ -140,7 +174,7 @@ trait RollerHandling
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Scooter Take back
|
|
|
+ * Scooter isExpired check
|
|
|
*
|
|
|
* @param string $code Scooter title code
|
|
|
*
|
|
|
@@ -152,8 +186,8 @@ trait RollerHandling
|
|
|
{
|
|
|
ApiBbusLog::ScooterRentLog("RENT_isExpired: ___START___");
|
|
|
$scooterData = $this->getScooterRowidByCode($code);
|
|
|
- $invoice_number = $this->getInvoiceNumberByInvetoryId($scooterData);
|
|
|
- return $this->checkExpireDate($invoice_number);
|
|
|
+ $rollerrenthistoryData = $this->getRollerrenthistoryDataByInvetoryId($scooterData);
|
|
|
+ return $this->checkExpireDate($rollerrenthistoryData->ticket_id);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -168,30 +202,30 @@ trait RollerHandling
|
|
|
*/
|
|
|
public function RENT_scooterTakeBack($code, $roller_status)
|
|
|
{
|
|
|
- ApiBbusLog::ScooterRentLog("RENT_scooterReplacement: ___START___");
|
|
|
-
|
|
|
+ ApiBbusLog::ScooterRentLog("RENT_scooterTakeBack: ___START___");
|
|
|
# Ezt hívjuk meg akkor is, ha csere van (státusz: 110 (In stock) / 114 (Faulty)) és akkor is ha rendes visszavételezés történik, de ebben az esetben 111-es státusszal.
|
|
|
$error = 0;
|
|
|
$scooterData = $this->getScooterRowidByCode($code);
|
|
|
- $invoice_number = $this->getInvoiceNumberByInvetoryId($scooterData);
|
|
|
+ $rollerrenthistoryData = $this->getRollerrenthistoryDataByInvetoryId($scooterData);
|
|
|
$this->db->begin();
|
|
|
# Create RollerRentHistory Record
|
|
|
- $ScooterRentHistoryId = $this->CreateScooterRentHistoryRecord($scooterData, $invoice_number, 0);
|
|
|
+ $ScooterRentHistoryId = $this->CreateScooterRentHistoryRecord($scooterData, $rollerrenthistoryData->invoice_number, null, $rollerrenthistoryData->ticket_id, 0);
|
|
|
(int)$ScooterRentHistoryId > 0 ?: $error++;
|
|
|
# Update Rollerstatus in llx_inventory
|
|
|
$this->RENT_setScooterStatus($roller_status, $scooterData) == $roller_status ?: $error++;
|
|
|
$this->checkError($error);
|
|
|
$this->db->commit();
|
|
|
- ApiBbusLog::ScooterRentLog("RENT_scooterReplacement: ___END___");
|
|
|
+ ApiBbusLog::ScooterRentLog("RENT_scooterTakeBack: {$code} -> Rent record created: {$ScooterRentHistoryId}");
|
|
|
+ ApiBbusLog::ScooterRentLog("RENT_scooterTakeBack: ___END___");
|
|
|
return 'OK';
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Scooter Take back
|
|
|
+ * Scooter replacement
|
|
|
*
|
|
|
- * @param string $code_1
|
|
|
- * @param string $scooter_1_status
|
|
|
- * @param string $code_2
|
|
|
+ * @param string $code_1 //Scooter QRcode
|
|
|
+ * @param string $scooter_1_status //1st Scooter status
|
|
|
+ * @param string $code_2 //Scooter QRcode
|
|
|
*
|
|
|
* @return array|mixed Data without useless information
|
|
|
*
|
|
|
@@ -199,15 +233,35 @@ trait RollerHandling
|
|
|
*/
|
|
|
public function RENT_scooterReplacement($code_1, $scooter_1_status, $code_2)
|
|
|
{
|
|
|
+ $error = 0;
|
|
|
ApiBbusLog::ScooterRentLog("RENT_scooterReplacement: ___START___");
|
|
|
+ # Take the scooter back
|
|
|
$this->RENT_scooterTakeBack($code_1, $scooter_1_status);
|
|
|
$scooter_2_data = $this->RENT_checkScooterStatus($code_2);
|
|
|
- if($scooter_2_data->status == '110'){
|
|
|
+ if ($scooter_2_data->status == '110') {
|
|
|
+ $isReplaced = true;
|
|
|
$scooter_1_data = $this->RENT_checkScooterStatus($code_1);
|
|
|
$invoice_number = $this->getInvoiceNumberByInvetoryId($scooter_1_data->rowid);
|
|
|
- $ticket_id = $this->getTicketIdByInvoiceNumber($invoice_number);
|
|
|
- $this->RENT_ConnectFactureAndScooter($scooter_2_data->rowid, $invoice_number, $ticket_id, true);
|
|
|
- }else{
|
|
|
+ $ticket_id = $this->getTicketIdByInvoiceNumberFromRollerRentHistory($invoice_number, $code_1);
|
|
|
+ $this->db->begin();
|
|
|
+ $ScooterRentHistoryId = $this->CreateScooterRentHistoryRecord($scooter_2_data->rowid, $invoice_number, null, $ticket_id, 1);
|
|
|
+ (int)$ScooterRentHistoryId > 0 ?: $error++;
|
|
|
+ ApiBbusLog::ScooterRentLog("RENT_scooterReplacement: {$code_2} -> Rent record created: {$ScooterRentHistoryId}");
|
|
|
+ $this->RENT_setScooterStatus("112", $scooter_2_data->rowid) == '112' ?: $error++;
|
|
|
+ if (!$isReplaced) {
|
|
|
+ $sql = "SELECT * FROM llx_bbus_bbticket WHERE rowid = {$ticket_id}";
|
|
|
+ $result = $this->db->query($sql);
|
|
|
+ while ($row = $this->db->fetch_object($result)) {
|
|
|
+ $this->updateScooterBbticket($row) > 0 ?: $error++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->checkError($error);
|
|
|
+ $this->db->commit();
|
|
|
+ ApiBbusLog::ScooterRentLog("RENT_scooterReplacement: ___END___");
|
|
|
+ return "OK";
|
|
|
+ //$this->RENT_ConnectFactureAndScooter($scooter_2_data->rowid, $invoice_number, $ticket_id, true);
|
|
|
+
|
|
|
+ } else {
|
|
|
return $scooter_2_data->status;
|
|
|
}
|
|
|
ApiBbusLog::ScooterRentLog("RENT_scooterReplacement: ___END___");
|