Fix issue on batch updates and inserts. #654

This commit is contained in:
Korina Cordero 2022-05-18 05:53:38 +00:00
parent a7d1bb6a90
commit 1778af3f9f

View file

@ -92,6 +92,7 @@ class FulfillOpenJobOrderCommand extends Command
$total_jos = count($jo_results);
$jo_ctr = 0;
$running_jo_total = 0;
$running_jo_event_total = 0;
$update_jo_ctr = 0;
@ -110,11 +111,13 @@ class FulfillOpenJobOrderCommand extends Command
$rider_id = $jo_row['rider_id'];
$str_date_schedule = $jo_row['date_schedule'];
$jo_ctr++;
// fulfill JO
$this->fulfillJO($conn, $jo_id, $update_jo_ctr, $update_wheres, $running_jo_total, $total_jos);
$this->fulfillJO($conn, $jo_id, $update_jo_ctr, $update_wheres, $jo_ctr, $total_jos);
// create JO event
$this->createJOEvent($conn, $jo_id, $str_current_date, $rider_id, $create_jo_event_ctr, $jo_event_values, $jo_event_total, $total_jos);
$this->createJOEvent($conn, $jo_id, $str_current_date, $rider_id, $create_jo_event_ctr, $jo_event_values, $jo_ctr, $total_jos);
// error_log($jo_ctr . ' Processing JO ' . $jo_id);
@ -133,19 +136,13 @@ class FulfillOpenJobOrderCommand extends Command
}
protected function fulfillJO($conn, $jo_id, &$update_jo_ctr, &$update_wheres, &$running_jo_total, $total_jos)
protected function fulfillJO($conn, $jo_id, &$update_jo_ctr, &$update_wheres, $jo_ctr, $total_jos)
{
$update_wheres[] = 'id = ' . $jo_id;
$unprocessed_jos = $total_jos - $running_jo_total;
error_log('Unprocessed JOs ' . $unprocessed_jos);
error_log('Update JO counter ' . $update_jo_ctr);
// TODO: check why this is not working for unprocessed jos. this is for the case when we have the remainder.
// solution to this will also need to be applied to jo event creation
// update db when we reach max # of JOs or when remaining JOs are less than max #
// update db when we reach max # of JOs or when we reach total number of jos
if (($update_jo_ctr == self::JO_BATCH_CTR) ||
($update_jo_ctr == $unprocessed_jos))
($jo_ctr == $total_jos))
{
$update_where_string = implode(' OR ' , $update_wheres);
@ -160,11 +157,6 @@ class FulfillOpenJobOrderCommand extends Command
'del_fulfilled' => DeliveryStatus::FULFILLED,
]);
error_log('Processed ' . $update_jo_ctr . ' job orders. ');
// update the running total
$running_jo_total = $running_jo_total + $update_jo_ctr;
// reset the wheres string
$update_wheres = [];
@ -176,10 +168,8 @@ class FulfillOpenJobOrderCommand extends Command
}
protected function createJOEvent($conn, $jo_id, $str_current_date, $rider_id, &$create_jo_event_ctr, &$jo_event_value_string,
&$running_jo_event_total, $total_jos)
$jo_ctr, $total_jos)
{
$unprocessed_events = $total_jos - $running_jo_event_total;
// create jo event
// set user to admin that has id of 1
$user_id = 1;
@ -204,9 +194,9 @@ class FulfillOpenJobOrderCommand extends Command
$jo_event_value_string = $jo_event_value_string . ',' . $jo_event_values;
}
// insert to db when we reach max # of JOs or when remaining JOs are less than max #
// insert to db when we reach max # of JOs or when we reach total number of jos
if (($create_jo_event_ctr == self::JO_EVENT_BATCH_CTR) ||
($create_jo_event_ctr == $unprocessed_events))
($jo_ctr == $total_jos))
{
$create_jo_event_sql = 'INSERT into `jo_event` (create_user_id, job_order_id, date_create, date_happen, type_id, rider_id) VALUES ' . $jo_event_value_string . ';' . "\n";
@ -215,9 +205,6 @@ class FulfillOpenJobOrderCommand extends Command
$create_jo_event_stmt = $conn->prepare($create_jo_event_sql);
$create_jo_event_stmt->execute();
// update the running jo event total
$running_jo_event_total = $running_jo_event_total + $create_jo_event_ctr;
// reset the counter and value string
$jo_event_value_string = '';
$create_jo_event_ctr = 0;
@ -311,6 +298,27 @@ class FulfillOpenJobOrderCommand extends Command
else
$sap_code = 'NULL';
/*
// create array for the infile
$warranty_data = [
$model_id,
$size_id,
$sap_code,
$warranty_class,
$plate_number,
$warranty_status,
$str_current_date,
$str_date_schedule,
$str_date_expire,
$first_name,
$last_name,
$mobile,
$vehicle_id,
$cust_id,
$WarrantySource::ADMIN_PANEL,
];
*/
// populate the values string for the values to be inserted into warranty
// check for sap_code. Not all batteries have sap_code
if ($sap_code == 'NULL')
@ -332,6 +340,8 @@ class FulfillOpenJobOrderCommand extends Command
$stmt = $conn->prepare($sql_statement);
$stmt->execute();
// $this->createLoadDataFileForWarranty($warranty_data);
}
protected function getCustomerInfo($conn, $id)