diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 73d2343c..8c874ea5 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -38,6 +38,7 @@ use App\Entity\RiderRating; use App\Entity\JOEvent; use DateTime; +use Exception; class APIController extends Controller @@ -311,6 +312,8 @@ class APIController extends Controller $data = [ 'first_name' => '', 'last_name' => '', + 'priv_third_party' => (bool) false, + 'priv_promo' => (bool) false, ]; $res->setData($data); @@ -1036,11 +1039,11 @@ class APIController extends Controller // make invoice json data $data = [ - 'total_price' => $invoice->getTotalPrice(), - 'vat_ex_price' => $invoice->getVATExclusivePrice(), - 'vat' => $invoice->getVAT(), - 'discount' => $invoice->getDiscount(), - 'trade_in' => $invoice->getTradeIn(), + 'total_price' => (float) $invoice->getTotalPrice(), + 'vat_ex_price' => (float) $invoice->getVATExclusivePrice(), + 'vat' => (float) $invoice->getVAT(), + 'discount' => (float) $invoice->getDiscount(), + 'trade_in' => (float) $invoice->getTradeIn(), ]; $items = $invoice->getItems(); $items_data = []; @@ -1048,8 +1051,8 @@ class APIController extends Controller { $my_data = [ 'title' => $item->getTitle(), - 'qty' => $item->getQuantity() + 0, - 'price' => $item->getPrice() + 0.0, + 'qty' => (int) $item->getQuantity() + 0, + 'price' => (float) $item->getPrice() + 0.0, ]; $item_batt = $item->getBattery(); @@ -1101,14 +1104,25 @@ class APIController extends Controller // return $res->getReturnResponse(); if (count($ongoing_jos) <= 0) { - // check if the latest fulfilled jo they have needs rider rating - $query = $em->createQuery('select jo from App\Entity\JobOrder jo where jo.customer = :cust and jo.status = :status order by jo.date_fulfill desc'); - $fulfill_jo = $query->setParameters([ - 'cust' => $cust, - 'status' => JOStatus::FULFILLED, - ]) - ->setMaxResults(1) - ->getSingleResult(); + try + { + // check if the latest fulfilled jo they have needs rider rating + $query = $em->createQuery('select jo from App\Entity\JobOrder jo where jo.customer = :cust and jo.status = :status order by jo.date_fulfill desc'); + $fulfill_jo = $query->setParameters([ + 'cust' => $cust, + 'status' => JOStatus::FULFILLED, + ]) + ->setMaxResults(1) + ->getSingleResult(); + } + catch (Exception $e) + { + // no pending + $res->setData([ + 'status' => APIRiderStatus::NO_PENDING_JO + ]); + return $res->getReturnResponse(); + } // we got a recently fulfilled job order if ($fulfill_jo) @@ -1399,11 +1413,11 @@ class APIController extends Controller // make invoice json data $data = [ - 'total_price' => $invoice->getTotalPrice(), - 'vat_ex_price' => $invoice->getVATExclusivePrice(), - 'vat' => $invoice->getVAT(), - 'discount' => $invoice->getDiscount(), - 'trade_in' => $invoice->getTradeIn(), + 'total_price' => (float) $invoice->getTotalPrice(), + 'vat_ex_price' => (float) $invoice->getVATExclusivePrice(), + 'vat' => (float) $invoice->getVAT(), + 'discount' => (float) $invoice->getDiscount(), + 'trade_in' => (float) $invoice->getTradeIn(), ]; $items = $invoice->getItems(); $items_data = []; @@ -1411,8 +1425,8 @@ class APIController extends Controller { $my_data = [ 'title' => $item->getTitle(), - 'qty' => $item->getQuantity() + 0, - 'price' => $item->getPrice() + 0.0, + 'qty' => (int) $item->getQuantity() + 0, + 'price' => (float) $item->getPrice() + 0.0, ]; $item_batt = $item->getBattery(); diff --git a/utils/mqtt_sender/mqtt_sender.py b/utils/mqtt_sender/mqtt_sender.py index 07e81174..d2c3368e 100644 --- a/utils/mqtt_sender/mqtt_sender.py +++ b/utils/mqtt_sender/mqtt_sender.py @@ -7,17 +7,18 @@ import time import signal import sys import os +import logging def sigint_handler(signal, frame): - print 'Interrupted' + logging.warning('Interrupted') sys.exit(0) os._exit(0) def on_connect(client, userdata, flags, rc): - print("Connected with result code "+str(rc)) + logging.info("Connected with result code "+str(rc)) client.subscribe("$SYS/#") @@ -34,13 +35,13 @@ def getRedis(i, client): data = r.brpop("events", 10) if data: info = data[1].split('|') - print "Channel: " + info[0] + " message: " + info[1] + logging.info("Channel: " + info[0] + " message: " + info[1]) client.publish(info[0], info[1]) def sigint_handler(signal, frame): - print 'Interrupted' + logging.warning('Interrupted') sys.exit(0) @@ -49,8 +50,6 @@ def main(): client.on_connect = on_connect client.on_publish = on_publish - - client.tls_set( "/etc/letsencrypt/live/resqaws.jankstudio.com/fullchain.pem", cert_reqs=ssl.CERT_NONE, tls_version=ssl.PROTOCOL_TLSv1) @@ -64,8 +63,9 @@ def main(): client.loop_forever() - -#pid = "/tmp/mqtt_sender.pid" -#daemon = Daemonize(app="mqtt_sender", pid=pid, action=main) -#daemon.start() -main() +logging.basicConfig(filename='/tmp/mqtt_sender.log', level=logging.INFO) +logging.info('Started mqtt_sender') +pid = "/tmp/mqtt_sender.pid" +daemon = Daemonize(app="mqtt_sender", pid=pid, action=main) +daemon.start() +#main()