Merge branch 'master' of gitlab.com:jankstudio/resq into 162-phase-2-changes

This commit is contained in:
Kendrick Chan 2018-08-14 23:58:41 +08:00
commit dbe152598f
3 changed files with 63 additions and 32 deletions

View file

@ -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)
@ -1412,11 +1426,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 = [];
@ -1424,8 +1438,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();

View file

@ -771,7 +771,7 @@ class RAPIController extends Controller
$jo->setORNum($or_num);
// check battery id
$batt_id = $req->request->get('batt_id');
$batt_id = $req->request->get('batt_id', null);
// no battery
if ($batt_id == 0 || $batt_id == null)
$battery = null;

View file

@ -12,13 +12,13 @@ import logging
def sigint_handler(signal, frame):
logging.warning('Interrupted')
#logging.warning('Interrupted')
sys.exit(0)
os._exit(0)
def on_connect(client, userdata, flags, rc):
logging.info("Connected with result code "+str(rc))
#logging.info("Connected with result code "+str(rc))
client.subscribe("$SYS/#")
@ -27,25 +27,39 @@ def on_publish(client, userdata, mid):
pass
def getRedis(i):
def getRedis(i, client, logger):
logger.info("Listening in redis events")
r = redis.StrictRedis(host='localhost', port=6379, db=0)
while 1:
time.sleep(0)
data = r.brpop("events", 10)
if data:
info = data[1].split('|')
logging.info("Channel: " + info[0] + " message: " + info[1])
logger.info("Channel: " + info[0] + " message: " + info[1])
client.publish(info[0], info[1])
def sigint_handler(signal, frame):
logging.warning('Interrupted')
sys.exit(0)
def get_logger():
logger = logging.getLogger("mqtt_logger")
logger.setLevel(logging.INFO)
fh = logging.FileHandler("/tmp/mqtt_sender.log")
fmt = '%(asctime)s - %(threadName)s - %(levelname)s - %(message)s'
formatter = logging.Formatter(fmt)
fh.setFormatter(formatter)
logger.addHandler(fh)
return logger
def main():
logger = get_logger()
logger.info("Starting mqtt_sender")
logger.info("Connecting to MQTT server")
client = mqtt.Client()
client.on_connect = on_connect
client.on_publish = on_publish
@ -55,7 +69,9 @@ def main():
tls_version=ssl.PROTOCOL_TLSv1)
client.connect("resqaws.jankstudio.com", 8883, 60)
t = Thread(target=getRedis, args=(1,))
logger.info("Starting redis thread")
t = Thread(target=getRedis, args=(1, client, logger))
t.start()
@ -63,8 +79,9 @@ def main():
client.loop_forever()
logging.basicConfig(filename='/tmp/mqtt_sender.log', level=logging.INFO)
logging.info('Started mqtt_sender')
#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()