Fix file logging format for hub filtering #800
This commit is contained in:
parent
a335f84a13
commit
9b63139957
3 changed files with 26 additions and 23 deletions
|
|
@ -63,11 +63,26 @@ class BaseHubFilter
|
||||||
public function log(Hub $hub): void
|
public function log(Hub $hub): void
|
||||||
{
|
{
|
||||||
$this->hub_filter_logger->logFilteredHub($hub, $this->getID(), $this->getJOID(), $this->getCustomerID());
|
$this->hub_filter_logger->logFilteredHub($hub, $this->getID(), $this->getJOID(), $this->getCustomerID());
|
||||||
|
|
||||||
|
// log to file
|
||||||
|
$filename = '/../../../var/log/hub_rejection.log';
|
||||||
|
$date = date("Y-m-d H:i:s");
|
||||||
|
|
||||||
|
// build log entry
|
||||||
|
$entry = implode("", [
|
||||||
|
"[JO: " . $this->getJOID() . "]",
|
||||||
|
"[" . $date . "]",
|
||||||
|
"[" . $this->getID() . "]",
|
||||||
|
" " . $hub->getName() . " (ID: " . $hub->getID() . ")",
|
||||||
|
"\r\n",
|
||||||
|
]);
|
||||||
|
|
||||||
|
@file_put_contents(__DIR__ . $filename, $entry, FILE_APPEND);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createRejectionEntry($jo_id, $hub, $reason, $remarks = ""): JORejection
|
protected function createRejectionEntry($hub, $reason, $remarks = ""): JORejection
|
||||||
{
|
{
|
||||||
$jo = $this->em->getRepository(JobOrder::class)->find($jo_id);
|
$jo = $this->em->getRepository(JobOrder::class)->find($this->getJOID());
|
||||||
|
|
||||||
$robj = new JORejection();
|
$robj = new JORejection();
|
||||||
$robj->setDateCreate(new DateTime())
|
$robj->setDateCreate(new DateTime())
|
||||||
|
|
@ -79,26 +94,13 @@ class BaseHubFilter
|
||||||
$this->em->persist($robj);
|
$this->em->persist($robj);
|
||||||
$this->em->flush();
|
$this->em->flush();
|
||||||
|
|
||||||
// log to file
|
|
||||||
$filename = '/../../../var/log/hub_rejection.log';
|
|
||||||
$date = date("Y-m-d H:i:s");
|
|
||||||
|
|
||||||
// build log entry
|
|
||||||
$entry = implode("", [
|
|
||||||
"[JO: " . $jo_id . "]",
|
|
||||||
"[HUB:" . $hub->getID() . "]",
|
|
||||||
"[" . $date . "]",
|
|
||||||
$reason,
|
|
||||||
$remarks ? " - " . $remarks : "",
|
|
||||||
]);
|
|
||||||
|
|
||||||
@file_put_contents(__DIR__ . $filename, $entry, FILE_APPEND);
|
|
||||||
|
|
||||||
return $robj;
|
return $robj;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function sendSMSMessage($hub, $jo_id, $order_date, $service_type, $rejection, $reason = "", $remarks = ""): void
|
protected function sendSMSMessage($hub, $order_date, $service_type, $rejection, $reason = "", $remarks = ""): void
|
||||||
{
|
{
|
||||||
|
$jo_id = $this->getJOID();
|
||||||
|
|
||||||
// check if we already have a rejection record for this hub and JO. this also means an SMS was already sent
|
// check if we already have a rejection record for this hub and JO. this also means an SMS was already sent
|
||||||
$rejection_count = $this->em->createQueryBuilder()
|
$rejection_count = $this->em->createQueryBuilder()
|
||||||
->select('count(r)')
|
->select('count(r)')
|
||||||
|
|
@ -126,7 +128,7 @@ class BaseHubFilter
|
||||||
'Remarks: ' . $remarks . "\n" .
|
'Remarks: ' . $remarks . "\n" .
|
||||||
'Type of Service: ' . ServiceType::getName($service_type);
|
'Type of Service: ' . ServiceType::getName($service_type);
|
||||||
|
|
||||||
error_log("SENDING SMS MESsAGE:\r\n" . $message);
|
error_log("SENDING SMS MESSAGE:\r\n" . $message);
|
||||||
|
|
||||||
// send SMS message to hub
|
// send SMS message to hub
|
||||||
$this->rt->sendSMS(
|
$this->rt->sendSMS(
|
||||||
|
|
|
||||||
|
|
@ -121,10 +121,11 @@ class InventoryHubFilter extends BaseHubFilter implements HubFilterInterface
|
||||||
// check if we are filtering this hub
|
// check if we are filtering this hub
|
||||||
if (isset($hubs_to_filter[$branch_code]) || empty($branch_code) || !isset($qtys[$branch_code])) {
|
if (isset($hubs_to_filter[$branch_code]) || empty($branch_code) || !isset($qtys[$branch_code])) {
|
||||||
// if we have a JO, create rejection record and notify
|
// if we have a JO, create rejection record and notify
|
||||||
|
$jo_id = $this->getJOID();
|
||||||
|
|
||||||
if (!empty($jo_id)) {
|
if (!empty($jo_id)) {
|
||||||
// create rejection report entry
|
// create rejection report entry
|
||||||
$robj = $this->createRejectionEntry(
|
$robj = $this->createRejectionEntry(
|
||||||
$jo_id,
|
|
||||||
$hub,
|
$hub,
|
||||||
JORejectionReason::NO_STOCK_SALES,
|
JORejectionReason::NO_STOCK_SALES,
|
||||||
"SKU(s): " . $battery_string,
|
"SKU(s): " . $battery_string,
|
||||||
|
|
@ -133,7 +134,6 @@ class InventoryHubFilter extends BaseHubFilter implements HubFilterInterface
|
||||||
// build SMS message
|
// build SMS message
|
||||||
$this->sendSMSMessage(
|
$this->sendSMSMessage(
|
||||||
$hub,
|
$hub,
|
||||||
$jo_id,
|
|
||||||
$params['order_date'],
|
$params['order_date'],
|
||||||
$params['service_type'],
|
$params['service_type'],
|
||||||
$robj,
|
$robj,
|
||||||
|
|
|
||||||
|
|
@ -45,14 +45,15 @@ class RiderAvailabilityHubFilter extends BaseHubFilter implements HubFilterInter
|
||||||
error_log("TOTAL RIDERS: " . $available_riders);
|
error_log("TOTAL RIDERS: " . $available_riders);
|
||||||
if ($available_riders === 0) {
|
if ($available_riders === 0) {
|
||||||
// if we have a JO, create rejection record and notify
|
// if we have a JO, create rejection record and notify
|
||||||
|
$jo_id = $this->getJOID();
|
||||||
|
|
||||||
if (!empty($jo_id)) {
|
if (!empty($jo_id)) {
|
||||||
// create rejection report entry
|
// create rejection report entry
|
||||||
$robj = $this->createRejectionEntry($jo_id, $hub, JORejectionReason::NO_RIDER_AVAILABLE);
|
$robj = $this->createRejectionEntry($hub, JORejectionReason::NO_RIDER_AVAILABLE);
|
||||||
|
|
||||||
// build SMS message
|
// build SMS message
|
||||||
$this->sendSMSMessage(
|
$this->sendSMSMessage(
|
||||||
$hub,
|
$hub,
|
||||||
$jo_id,
|
|
||||||
$params['order_date'],
|
$params['order_date'],
|
||||||
$params['service_type'],
|
$params['service_type'],
|
||||||
$robj,
|
$robj,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue