From 714aa5636dc0b5bfb7984d256d79b26f2db0cb89 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 21 May 2020 10:48:58 +0000 Subject: [PATCH] Add checking for warranties with date schedule as the start date of expiry date computation. #407 --- src/Command/GetFlawedWarrantiesCommand.php | 124 ++++++++++++++------- 1 file changed, 86 insertions(+), 38 deletions(-) diff --git a/src/Command/GetFlawedWarrantiesCommand.php b/src/Command/GetFlawedWarrantiesCommand.php index 2b93938b..73d87966 100644 --- a/src/Command/GetFlawedWarrantiesCommand.php +++ b/src/Command/GetFlawedWarrantiesCommand.php @@ -169,61 +169,109 @@ class GetFlawedWarrantiesCommand extends Command if (empty($results_date_create)) { - // TODO: find warranties that used date_schedule for date_purchase + // find warranties that used date_schedule for date_purchase $missing_flag = true; $jo_warranty_class = $jo->getWarrantyClass(); $warr_period = $this->getWarrantyPeriod($jo_warranty_class, $invoice_item); - // get date fulfill - $datetime_fulfilled = $jo->getDateFulfill(); - if ($datetime_fulfilled != null) + // get date schedule + $datetime_schedule = $jo->getDateSchedule(); + $datetime_schedule_str = $datetime_schedule->format('Y-m-d'); + $date_scheduled = DateTime::createFromFormat('Y-m-d', $datetime_schedule_str); + + $expiry_date_date_scheduled = $this->wh->computeDateExpire($date_scheduled, $warr_period); + + // find warranties with date_schedule as the date_purchase + $warranties_date_scheduled = $em->getRepository(Warranty::class)->findBy(['plate_number' => $cleaned_plate_number, + 'date_purchase' => $date_scheduled]); + + if (!(empty($warranties_date_scheduled))) { - $datetime_fulfilled_str = $datetime_fulfilled->format('Y-m-d'); - $date_fulfilled = DateTime::createFromFormat('Y-m-d', $datetime_fulfilled_str); + $missing_flag = false; - $expiry_date_date_create = $this->wh->computeDateExpire($date_fulfilled, $warr_period); - - // find warranties with date fulfilled as the date_purchase - $warranties_date_fulfilled = $em->getRepository(Warranty::class)->findBy(['plate_number' => $cleaned_plate_number, - 'date_purchase' => $date_fulfilled]); - - if (!(empty($warranties_date_fulfilled))) + foreach ($warranties_date_scheduled as $warranty_date_scheduled) { - $missing_flag = false; - - foreach ($warranties_date_fulfilled as $warranty_date_fulfilled) + // check if sap_code exists in battery + $warr_sap_battery = $warranty_date_scheduled->getSAPBattery(); + if ($warr_sap_battery != null) { - // check if sap_code exists in battery - $warr_sap_battery = $warranty_date_fulfilled->getSAPBattery(); - if ($warr_sap_battery != null) - { - $warr_sap_code = $warr_sap_battery->getID(); + $warr_sap_code = $warr_sap_battery->getID(); - if ($warr_sap_code != null) + if ($warr_sap_code != null) + { + $batteries = $em->getRepository(Battery::class)->findBy(['sap_code' => $warr_sap_code]); + if ($batteries == null) { - $batteries = $em->getRepository(Battery::class)->findBy(['sap_code' => $warr_sap_code]); - if ($batteries == null) - { - $no_saps[] = [ - 'warranty_id' => $warranty_date_fulfilled->getID(), - 'plate_number' => $cleaned_plate_number, - 'sap_code' => $warr_sap_code, - ]; - } + $no_saps[] = [ + 'warranty_id' => $warranty_date_scheduled->getID(), + 'plate_number' => $cleaned_plate_number, + 'sap_code' => $warr_sap_code, + ]; } } - - // wrong expiration date - $date_expiry_wrongs[] = [ - 'warranty_id' => $warranty_date_fulfilled->getID(), - 'plate_number' => $cleaned_plate_number, - 'expiry_date' => $expiry_date_date_create->format('Y-m-d'), - ]; } + + // wrong expiration date + $date_expiry_wrongs[] = [ + 'warranty_id' => $warranty_date_scheduled->getID(), + 'plate_number' => $cleaned_plate_number, + 'expiry_date' => $expiry_date_date_create->format('Y-m-d'), + ]; } } + else + { + // get date fulfill + $datetime_fulfilled = $jo->getDateFulfill(); + if ($datetime_fulfilled != null) + { + $datetime_fulfilled_str = $datetime_fulfilled->format('Y-m-d'); + $date_fulfilled = DateTime::createFromFormat('Y-m-d', $datetime_fulfilled_str); + + $expiry_date_date_create = $this->wh->computeDateExpire($date_fulfilled, $warr_period); + + // find warranties with date fulfilled as the date_purchase + $warranties_date_fulfilled = $em->getRepository(Warranty::class)->findBy(['plate_number' => $cleaned_plate_number, + 'date_purchase' => $date_fulfilled]); + + if (!(empty($warranties_date_fulfilled))) + { + $missing_flag = false; + + foreach ($warranties_date_fulfilled as $warranty_date_fulfilled) + { + // check if sap_code exists in battery + $warr_sap_battery = $warranty_date_fulfilled->getSAPBattery(); + if ($warr_sap_battery != null) + { + $warr_sap_code = $warr_sap_battery->getID(); + + if ($warr_sap_code != null) + { + $batteries = $em->getRepository(Battery::class)->findBy(['sap_code' => $warr_sap_code]); + if ($batteries == null) + { + $no_saps[] = [ + 'warranty_id' => $warranty_date_fulfilled->getID(), + 'plate_number' => $cleaned_plate_number, + 'sap_code' => $warr_sap_code, + ]; + } + } + } + + // wrong expiration date + $date_expiry_wrongs[] = [ + 'warranty_id' => $warranty_date_fulfilled->getID(), + 'plate_number' => $cleaned_plate_number, + 'expiry_date' => $expiry_date_date_create->format('Y-m-d'), + ]; + } + } + } + } if ($missing_flag) {