Add index for serial. Add additional checks for serial in warranty. #660

This commit is contained in:
Korina Cordero 2022-05-06 10:17:27 +00:00
parent 86ef1ec646
commit e8670e4b60
2 changed files with 28 additions and 8 deletions

View file

@ -157,8 +157,8 @@ class TestWarrantyUploadCommand extends Command
$cv_results = $stmt->fetch(); $cv_results = $stmt->fetch();
$cust_id = null; $cust_id = 'NULL';
$vehicle_id = null; $vehicle_id = 'NULL';
if (!empty($cv_results)) if (!empty($cv_results))
{ {
$cust_id = $cv_results['c_id']; $cust_id = $cv_results['c_id'];
@ -238,7 +238,7 @@ class TestWarrantyUploadCommand extends Command
} }
// validate date purchase // validate date purchase
// (1) date purchase should not be empty // (1) date purchase should not be empty
// (2) date purchase should be of format: m/d/y // (2) date purchase should be of format: d-M-y
if (empty($date_purchase)) if (empty($date_purchase))
{ {
$message = 'No date purchase.'; $message = 'No date purchase.';
@ -246,10 +246,10 @@ class TestWarrantyUploadCommand extends Command
return $errors; return $errors;
} }
$purchase_date = DateTime::createFromFormat('d-M-y', $date_purchase); $purchase_date = DateTime::createFromFormat('m/d/y', $date_purchase);
if ($purchase_date === false) if ($purchase_date === false)
{ {
$message = 'Invalid date format. Date format should be: dd-mon-yy (example: 27-Nov-21)'; $message = 'Invalid date format. Date format should be: m/d/y (example: 06/13/16)';
$errors = $this->setOutputInfo($fields, 'NOT ADDED', $message); $errors = $this->setOutputInfo($fields, 'NOT ADDED', $message);
return $errors; return $errors;
} }
@ -288,10 +288,11 @@ class TestWarrantyUploadCommand extends Command
return $errors; return $errors;
} }
// check if warranty exists using serial + plate number // (1) check if warranty exists using serial + plate number
// (2) check if serial already exists even if for another plate number
$conn = $this->em->getConnection(); $conn = $this->em->getConnection();
// find warranties // find warranties using serial + plate number
$sql = 'SELECT w.id FROM warranty w WHERE w.serial = :serial AND w.plate_number = :plate_number'; $sql = 'SELECT w.id FROM warranty w WHERE w.serial = :serial AND w.plate_number = :plate_number';
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute([ $stmt->execute([
@ -308,6 +309,22 @@ class TestWarrantyUploadCommand extends Command
return $errors; return $errors;
} }
// find warranties using serial number alone
$w_sql = 'SELECT w.id FROM warranty w WHERE w.serial = :serial';
$w_stmt = $conn->prepare($w_sql);
$w_stmt->execute([
'serial' => $serial,
]);
$w_results = $w_stmt->fetchAll();
if (!empty($w_results))
{
$message = 'Warranty already exists for serial.';
$errors = $this->setOutputInfo($fields, 'NOT ADDED', $message);
return $errors;
}
return $errors; return $errors;
} }

View file

@ -15,7 +15,10 @@ use Exception;
* uniqueConstraints={ * uniqueConstraints={
* @ORM\UniqueConstraint(columns={"serial"}) * @ORM\UniqueConstraint(columns={"serial"})
* }, * },
* indexes={@ORM\Index(name="plate_number_idx", columns={"plate_number"})}) * indexes={
* @ORM\Index(name="plate_number_idx", columns={"plate_number"}),
@ORM\Index(name="serial_idx", columns={"serial"})
* })
* ) * )
*/ */
class Warranty class Warranty