diff --git a/src/Command/SetWarrantyBranchCodeCommand.php b/src/Command/SetWarrantyBranchCodeCommand.php new file mode 100644 index 00000000..51c76ced --- /dev/null +++ b/src/Command/SetWarrantyBranchCodeCommand.php @@ -0,0 +1,68 @@ +em = $em; + + parent::__construct(); + } + + protected function configure() + { + $this->setName('warranty:setbranchcode') + ->setDescription('Set branch code for warranty, if any.') + ->setHelp('Set branch code for warranty, if any.'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $em = $this->em; + + // get all warranties with dealer_name + $query = $em->createQuery('select w from App\Entity\Warranty w where w.dealer_name is not null and w.dealer_name != \'\''); + + $result = $query->iterate(); + + foreach ($result as $row) + { + $warranty = $row[0]; + + // get dealer name, uppercase it since dealer name is saved in uppercase in db + $dealer_name = strtoupper($warranty->getDealerName()); + // error_log('warranty dealer name ' . $dealer_name); + + // find dealer using name with findOneBy + $dealer = $em->getRepository(Dealer::class)->findOneBy(['name' => $dealer_name]); + if ($dealer != null) + { + error_log('Setting branch code for warranty with dealer name ' . $dealer->getName()); + // get branch code + $branch_code = $dealer->getBranchCode(); + + // set warranty branch code + $warranty->setDealerBranchCode($branch_code); + } + } + + $em->flush(); + + return 0; + } +} diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 0568aeb0..31b720a6 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -3164,6 +3164,7 @@ class APIController extends Controller implements LoggedController 'warr_card' => $warr_card_url, 'dealer_name' => $warr->getDealerName() ?? '', 'dealer_address' => $warr->getDealerAddress() ?? '', + 'branch_code' => $warr->getDealerBranchCode() ?? '', ]; } else @@ -3185,6 +3186,7 @@ class APIController extends Controller implements LoggedController 'warr_card' => '', 'dealer_name' => '', 'dealer_address' => '', + 'branch_code' => '', ]; } } @@ -3207,6 +3209,7 @@ class APIController extends Controller implements LoggedController 'warr_card' => '', 'dealer_name' => '', 'dealer_address' => '', + 'branch_code' => '', ]; } @@ -3253,6 +3256,7 @@ class APIController extends Controller implements LoggedController 'date_purchase' => $other_data['date_purchase'], 'dealer_name' => $other_data['dealer_name'], 'dealer_address' => $other_data['dealer_address'], + 'branch_code' => $other_data['branch_code'], 'message' => [ 'register_error' => 'Warranty serial code has already been registered.', 'edit_error' => 'Sorry, warranty is registered under another vehicle not in your list of vehicles.', @@ -3464,6 +3468,7 @@ class APIController extends Controller implements LoggedController ->setCustomerAddress($req->request->get('cust_address')) ->setDealerName($req->request->get('dealer_name')) ->setDealerAddress($req->request->get('dealer_address')) + ->setDealerBranchCode($req->request->get('branch_code')) ->setValidated(false); // TODO: check for date purchase and date expire diff --git a/src/Controller/CAPI/CustomerWarrantyController.php b/src/Controller/CAPI/CustomerWarrantyController.php index 0c1c869e..edf00e2e 100644 --- a/src/Controller/CAPI/CustomerWarrantyController.php +++ b/src/Controller/CAPI/CustomerWarrantyController.php @@ -211,6 +211,7 @@ class CustomerWarrantyController extends APIController 'vmodel' => $warr->getVehicleModelYear(), 'dealer_name' => $warr->getDealerName(), 'dealer_address' => $warr->getDealerAddress(), + 'branch_code' => $warr->getDealerBranchCode(), 'province_id' => $warr->getProvinceID(), 'municipality_id' => $warr->getMunicipalityID(), ]; @@ -238,6 +239,7 @@ class CustomerWarrantyController extends APIController 'vmodel' => '', 'dealer_name' => '', 'dealer_address' => '', + 'branch_code' => '', 'province_id' => '', 'municipality_id' => '', ]; @@ -289,6 +291,7 @@ class CustomerWarrantyController extends APIController 'vmodel' => $other_data['vmodel'], 'dealer_name' => $other_data['dealer_name'], 'dealer_address' => $other_data['dealer_address'], + 'branch_code' => $other_data['branch_code'], 'province_id' => $other_data['province_id'], 'municipality_id' => $other_data['municipality_id'], ]; @@ -537,12 +540,11 @@ class CustomerWarrantyController extends APIController ->setDatePurchaseCustomer($date_pur_cust) ->setContactNumber($req->request->get('contact_num')) ->setCustomerAddress($req->request->get('cust_address')) - ->setDealerName($req->request->get('dealer_name')) - ->setDealerAddress($req->request->get('dealer_address')) ->setVehicle($vehicle) ->setVehicleModelYear($req->request->get('vmodel')) ->setDealerName($req->request->get('dealer_name')) ->setDealerAddress($req->request->get('dealer_address')) + ->setDealerBranchCode($req->request->get('branch_code')) ->setCustomer($cust) ->setValidated(false) diff --git a/src/Controller/ReportController.php b/src/Controller/ReportController.php index 464259df..cc22866b 100644 --- a/src/Controller/ReportController.php +++ b/src/Controller/ReportController.php @@ -749,6 +749,7 @@ class ReportController extends Controller 'Warranty File Card', 'Warranty Vehicle Model Year', 'Warranty Odometer', + 'Warranty Dealer Branch Code', 'Warranty Dealer Name', 'Warranty Dealer Address', 'Warranty Contact Number', @@ -1553,7 +1554,7 @@ class ReportController extends Controller w.warranty_privacy_policy, w.bty_model_id, w.bty_size_id, w.email as w_email, w.vehicle_id, w.customer_id, w.file_invoice, w.file_warr_card, w.v_model_year, w.odometer, w.dealer_name, - w.dealer_address, w.contact_num, w.cust_address, + w.dealer_address, w.dealer_branch_code, w.contact_num, w.cust_address, w.date_purchase_cust, w.flag_validated, w.province_id, w.municipality_id, w.create_source AS w_create_source, c.id AS c_id, c.first_name AS c_fname, c.last_name AS c_lname, c.flag_confirmed, @@ -1651,6 +1652,7 @@ class ReportController extends Controller 'warr_file_warr_card' => $row['file_warr_card'], 'warr_v_model_year' => $row['v_model_year'], 'warr_odometer' => $row['odometer'], + 'warr_dealer_branch_code' => $row['dealer_branch_code'], 'warr_dealer_name' => $row['dealer_name'], 'warr_dealer_address' => $row['dealer_address'], 'warr_contact_number' => $row['contact_num'], diff --git a/src/Entity/Warranty.php b/src/Entity/Warranty.php index 5d45e806..06c18590 100644 --- a/src/Entity/Warranty.php +++ b/src/Entity/Warranty.php @@ -237,6 +237,11 @@ class Warranty */ protected $create_source; + /** + * @ORM\Column(type="string", length=80, nullable=true) + */ + protected $dealer_branch_code; + public function __construct() { $this->date_create = new DateTime(); @@ -676,4 +681,14 @@ class Warranty return $this->create_source; } + public function setDealerBranchCode($dealer_branch_code) + { + $this->dealer_branch_code = $dealer_branch_code; + return $this; + } + + public function getDealerBranchCode() + { + return $this->dealer_branch_code; + } }