roller_handling.class.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?php
  2. require_once DOL_DOCUMENT_ROOT . '/custom/rollerstorage/class/rollerrenthistory.class.php';
  3. require_once DOL_DOCUMENT_ROOT . '/custom/bbus/class/roller_handling_helper.class.php';
  4. use Luracast\Restler\RestException;
  5. trait RollerHandling
  6. {
  7. use RollerHandligHelper;
  8. /**
  9. * Get status of a roller by barcode
  10. *
  11. * Return an array with product information.
  12. *
  13. * @param string $code Roller QR code
  14. *
  15. * @return array|mixed Data without useless information
  16. *
  17. * @url POST RENT_checkScooterStatus
  18. */
  19. // Kellenek még a foglalási adatok ha vanank egy tömbben. HA nincs ,akkor üres tömb.
  20. public function RENT_checkScooterStatus(string $code)
  21. {
  22. ApiBbusLog::ScooterRentLog("RENT_checkScooterStatus: ___START___");
  23. $scooterData = $this->getAllScooterDataByCode($code);
  24. ApiBbusLog::ScooterRentLog("RENT_checkScooterStatus: ___END___");
  25. return $scooterData;
  26. }
  27. /**
  28. * Get status of a roller by barcode and Invoice number
  29. *
  30. * Return an array with product information.
  31. *
  32. * @param string $code Roller QR code
  33. * @param string $invoice_number Invoice number
  34. *
  35. * @return array|mixed Data without useless information
  36. *
  37. * @url POST RENT_checkScooterStatusAfterTicketValidation
  38. */
  39. // Kellenek még a foglalási adatok ha vanank egy tömbben. HA nincs ,akkor üres tömb.
  40. public function RENT_checkScooterStatusAfterTicketValidation(string $code, $invoice_number)
  41. {
  42. ApiBbusLog::ScooterRentLog("RENT_checkScooterStatusAfterTicketValidation: ___START___");
  43. $scooterDataArray = [];
  44. $scooterData = $this->getAllScooterDataByCode($code);
  45. $scooterDataArray['scooter'] = $scooterData;
  46. $scooterDataArray['isRented'] = $this->db->num_rows($this->checkRentHistory($scooterData->rowid, $invoice_number)) > 0;
  47. ApiBbusLog::ScooterRentLog("RENT_checkScooterStatusAfterTicketValidation: ___END___");
  48. return $scooterDataArray;
  49. }
  50. /**
  51. * Get available statuses of a roller
  52. *
  53. * Return an array with product information.
  54. *
  55. * @return array|mixed Data without useless information
  56. *
  57. * @url GET RENT_GetAvailableStatuses
  58. */
  59. public function RENT_GetAvailableStatuses()
  60. {
  61. ApiBbusLog::ScooterRentLog("RENT_GetAvailableStatuses: ___START___");
  62. $statuses = [];
  63. $sql = "SELECT status_id FROM llx_rollerstorage_statuses WHERE status_id != 112";
  64. $result = $this->db->query($sql);
  65. if ($this->db->num_rows($result) > 0) {
  66. while ($row = $this->db->fetch_object($result)) {
  67. $statuses[] = $row->status_id;
  68. }
  69. ApiBbusLog::ScooterRentLog("RENT_GetAvailableStatuses: ___END___");
  70. return $statuses;
  71. }
  72. ApiBbusLog::ScooterRentLog("RENT_GetAvailableStatuses: ___END___");
  73. return $statuses;
  74. }
  75. /**
  76. * Set status of a scooter
  77. *
  78. * @param string $statuscode
  79. * @param string $rowid
  80. *
  81. * @return array|mixed Data without useless information
  82. *
  83. * @url POST RENT_setScooterStatus
  84. */
  85. public function RENT_setScooterStatus($statuscode, $rowid)
  86. {
  87. ApiBbusLog::ScooterRentLog("RENT_setScooterStatus: ___START___");
  88. $sql = "UPDATE llx_inventory SET status = {$statuscode} WHERE rowid = {$rowid}";
  89. $result = $this->db->query($sql);
  90. $inventoryObj = new Inventory($this->db);
  91. $resultupdated = $inventoryObj->fetch($rowid);
  92. ApiBbusLog::ScooterRentLog("Scooter status changed to {$inventoryObj->status}!");
  93. ApiBbusLog::ScooterRentLog("RENT_setScooterStatus: ___END___");
  94. return $inventoryObj->status;
  95. }
  96. /**
  97. * Connect scooter and event
  98. *
  99. * @param string $inventory_id
  100. * @param string $invoice_number
  101. * @param int $ticket_id
  102. *
  103. * @return array|mixed Data without useless information
  104. *
  105. * @url POST RENT_ConnectFactureAndScooter
  106. */
  107. public function RENT_ConnectFactureAndScooter($inventory_id, $invoice_number, $ticket_id, $isReplaced = false)
  108. {
  109. ApiBbusLog::ScooterRentLog("RENT_ConnectFactureAndScooter: ___START___");
  110. $error = 0;
  111. $this->db->begin();
  112. $ScooterRentHistoryId = $this->CreateScooterRentHistoryRecord($inventory_id, $invoice_number);
  113. (int)$ScooterRentHistoryId > 0 ?: $error++;
  114. ApiBbusLog::ScooterRentLog("RentHistoryRecord: {$ScooterRentHistoryId}");
  115. $this->RENT_setScooterStatus("112", $inventory_id) == '112' ?: $error++;
  116. if(!$isReplaced){
  117. $sql = "SELECT * FROM llx_bbus_bbticket WHERE rowid = {$ticket_id}";
  118. $result = $this->db->query($sql);
  119. while ($row = $this->db->fetch_object($result)) {
  120. $this->updateScooterBbticket($row) > 0 ?: $error++;
  121. }
  122. }
  123. $this->checkError($error);
  124. $this->db->commit();
  125. ApiBbusLog::ScooterRentLog("RENT_ConnectFactureAndScooter: ___END___");
  126. return "OK";
  127. }
  128. /**
  129. * Scooter Take back
  130. *
  131. * @param string $code Scooter title code
  132. *
  133. * @return array|mixed Data without useless information
  134. *
  135. * @url POST RENT_isExpired
  136. */
  137. public function RENT_isExpired($code)
  138. {
  139. ApiBbusLog::ScooterRentLog("RENT_isExpired: ___START___");
  140. $scooterData = $this->getScooterRowidByCode($code);
  141. $invoice_number = $this->getInvoiceNumberByInvetoryId($scooterData);
  142. return $this->checkExpireDate($invoice_number);
  143. }
  144. /**
  145. * Scooter Take back
  146. *
  147. * @param string $code
  148. * @param int $roller_status
  149. *
  150. * @return array|mixed Data without useless information
  151. *
  152. * @url POST RENT_scooterTakeBack
  153. */
  154. public function RENT_scooterTakeBack($code, $roller_status)
  155. {
  156. ApiBbusLog::ScooterRentLog("RENT_scooterReplacement: ___START___");
  157. # 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.
  158. $error = 0;
  159. $scooterData = $this->getScooterRowidByCode($code);
  160. $invoice_number = $this->getInvoiceNumberByInvetoryId($scooterData);
  161. $this->db->begin();
  162. # Create RollerRentHistory Record
  163. $ScooterRentHistoryId = $this->CreateScooterRentHistoryRecord($scooterData, $invoice_number, 0);
  164. (int)$ScooterRentHistoryId > 0 ?: $error++;
  165. # Update Rollerstatus in llx_inventory
  166. $this->RENT_setScooterStatus($roller_status, $scooterData) == $roller_status ?: $error++;
  167. $this->checkError($error);
  168. $this->db->commit();
  169. ApiBbusLog::ScooterRentLog("RENT_scooterReplacement: ___END___");
  170. return 'OK';
  171. }
  172. /**
  173. * Scooter Take back
  174. *
  175. * @param string $code_1
  176. * @param string $scooter_1_status
  177. * @param string $code_2
  178. *
  179. * @return array|mixed Data without useless information
  180. *
  181. * @url POST RENT_scooterReplacement
  182. */
  183. public function RENT_scooterReplacement($code_1, $scooter_1_status, $code_2)
  184. {
  185. ApiBbusLog::ScooterRentLog("RENT_scooterReplacement: ___START___");
  186. $this->RENT_scooterTakeBack($code_1, $scooter_1_status);
  187. $scooter_2_data = $this->RENT_checkScooterStatus($code_2);
  188. if($scooter_2_data->status == '110'){
  189. $scooter_1_data = $this->RENT_checkScooterStatus($code_1);
  190. $invoice_number = $this->getInvoiceNumberByInvetoryId($scooter_1_data->rowid);
  191. $ticket_id = $this->getTicketIdByInvoiceNumber($invoice_number);
  192. $this->RENT_ConnectFactureAndScooter($scooter_2_data->rowid, $invoice_number, $ticket_id, true);
  193. }else{
  194. return $scooter_2_data->status;
  195. }
  196. ApiBbusLog::ScooterRentLog("RENT_scooterReplacement: ___END___");
  197. return 'OK';
  198. }
  199. }