Merge branch '597-add-dealer-branch_code-to-warranty-details-report' into 'master-fix'

Resolve "Add dealer branch_code to Warranty Details Report"

See merge request jankstudio/resq!717
This commit is contained in:
Kendrick Chan 2021-07-23 04:17:36 +00:00
commit 8fbfc1ebe7
5 changed files with 95 additions and 3 deletions

View file

@ -0,0 +1,68 @@
<?php
namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Warranty;
use App\Entity\Dealer;
class SetWarrantyBranchCodeCommand extends Command
{
protected $em;
public function __construct(EntityManagerInterface $em)
{
$this->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;
}
}

View file

@ -3164,6 +3164,7 @@ class APIController extends Controller implements LoggedController
'warr_card' => $warr_card_url, 'warr_card' => $warr_card_url,
'dealer_name' => $warr->getDealerName() ?? '', 'dealer_name' => $warr->getDealerName() ?? '',
'dealer_address' => $warr->getDealerAddress() ?? '', 'dealer_address' => $warr->getDealerAddress() ?? '',
'branch_code' => $warr->getDealerBranchCode() ?? '',
]; ];
} }
else else
@ -3185,6 +3186,7 @@ class APIController extends Controller implements LoggedController
'warr_card' => '', 'warr_card' => '',
'dealer_name' => '', 'dealer_name' => '',
'dealer_address' => '', 'dealer_address' => '',
'branch_code' => '',
]; ];
} }
} }
@ -3207,6 +3209,7 @@ class APIController extends Controller implements LoggedController
'warr_card' => '', 'warr_card' => '',
'dealer_name' => '', 'dealer_name' => '',
'dealer_address' => '', 'dealer_address' => '',
'branch_code' => '',
]; ];
} }
@ -3253,6 +3256,7 @@ class APIController extends Controller implements LoggedController
'date_purchase' => $other_data['date_purchase'], 'date_purchase' => $other_data['date_purchase'],
'dealer_name' => $other_data['dealer_name'], 'dealer_name' => $other_data['dealer_name'],
'dealer_address' => $other_data['dealer_address'], 'dealer_address' => $other_data['dealer_address'],
'branch_code' => $other_data['branch_code'],
'message' => [ 'message' => [
'register_error' => 'Warranty serial code has already been registered.', 'register_error' => 'Warranty serial code has already been registered.',
'edit_error' => 'Sorry, warranty is registered under another vehicle not in your list of vehicles.', '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')) ->setCustomerAddress($req->request->get('cust_address'))
->setDealerName($req->request->get('dealer_name')) ->setDealerName($req->request->get('dealer_name'))
->setDealerAddress($req->request->get('dealer_address')) ->setDealerAddress($req->request->get('dealer_address'))
->setDealerBranchCode($req->request->get('branch_code'))
->setValidated(false); ->setValidated(false);
// TODO: check for date purchase and date expire // TODO: check for date purchase and date expire

View file

@ -211,6 +211,7 @@ class CustomerWarrantyController extends APIController
'vmodel' => $warr->getVehicleModelYear(), 'vmodel' => $warr->getVehicleModelYear(),
'dealer_name' => $warr->getDealerName(), 'dealer_name' => $warr->getDealerName(),
'dealer_address' => $warr->getDealerAddress(), 'dealer_address' => $warr->getDealerAddress(),
'branch_code' => $warr->getDealerBranchCode(),
'province_id' => $warr->getProvinceID(), 'province_id' => $warr->getProvinceID(),
'municipality_id' => $warr->getMunicipalityID(), 'municipality_id' => $warr->getMunicipalityID(),
]; ];
@ -238,6 +239,7 @@ class CustomerWarrantyController extends APIController
'vmodel' => '', 'vmodel' => '',
'dealer_name' => '', 'dealer_name' => '',
'dealer_address' => '', 'dealer_address' => '',
'branch_code' => '',
'province_id' => '', 'province_id' => '',
'municipality_id' => '', 'municipality_id' => '',
]; ];
@ -289,6 +291,7 @@ class CustomerWarrantyController extends APIController
'vmodel' => $other_data['vmodel'], 'vmodel' => $other_data['vmodel'],
'dealer_name' => $other_data['dealer_name'], 'dealer_name' => $other_data['dealer_name'],
'dealer_address' => $other_data['dealer_address'], 'dealer_address' => $other_data['dealer_address'],
'branch_code' => $other_data['branch_code'],
'province_id' => $other_data['province_id'], 'province_id' => $other_data['province_id'],
'municipality_id' => $other_data['municipality_id'], 'municipality_id' => $other_data['municipality_id'],
]; ];
@ -537,12 +540,11 @@ class CustomerWarrantyController extends APIController
->setDatePurchaseCustomer($date_pur_cust) ->setDatePurchaseCustomer($date_pur_cust)
->setContactNumber($req->request->get('contact_num')) ->setContactNumber($req->request->get('contact_num'))
->setCustomerAddress($req->request->get('cust_address')) ->setCustomerAddress($req->request->get('cust_address'))
->setDealerName($req->request->get('dealer_name'))
->setDealerAddress($req->request->get('dealer_address'))
->setVehicle($vehicle) ->setVehicle($vehicle)
->setVehicleModelYear($req->request->get('vmodel')) ->setVehicleModelYear($req->request->get('vmodel'))
->setDealerName($req->request->get('dealer_name')) ->setDealerName($req->request->get('dealer_name'))
->setDealerAddress($req->request->get('dealer_address')) ->setDealerAddress($req->request->get('dealer_address'))
->setDealerBranchCode($req->request->get('branch_code'))
->setCustomer($cust) ->setCustomer($cust)
->setValidated(false) ->setValidated(false)

View file

@ -749,6 +749,7 @@ class ReportController extends Controller
'Warranty File Card', 'Warranty File Card',
'Warranty Vehicle Model Year', 'Warranty Vehicle Model Year',
'Warranty Odometer', 'Warranty Odometer',
'Warranty Dealer Branch Code',
'Warranty Dealer Name', 'Warranty Dealer Name',
'Warranty Dealer Address', 'Warranty Dealer Address',
'Warranty Contact Number', 'Warranty Contact Number',
@ -1553,7 +1554,7 @@ class ReportController extends Controller
w.warranty_privacy_policy, w.bty_model_id, w.bty_size_id, 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.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.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.date_purchase_cust, w.flag_validated, w.province_id,
w.municipality_id, w.create_source AS w_create_source, c.id AS c_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, 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_file_warr_card' => $row['file_warr_card'],
'warr_v_model_year' => $row['v_model_year'], 'warr_v_model_year' => $row['v_model_year'],
'warr_odometer' => $row['odometer'], 'warr_odometer' => $row['odometer'],
'warr_dealer_branch_code' => $row['dealer_branch_code'],
'warr_dealer_name' => $row['dealer_name'], 'warr_dealer_name' => $row['dealer_name'],
'warr_dealer_address' => $row['dealer_address'], 'warr_dealer_address' => $row['dealer_address'],
'warr_contact_number' => $row['contact_num'], 'warr_contact_number' => $row['contact_num'],

View file

@ -237,6 +237,11 @@ class Warranty
*/ */
protected $create_source; protected $create_source;
/**
* @ORM\Column(type="string", length=80, nullable=true)
*/
protected $dealer_branch_code;
public function __construct() public function __construct()
{ {
$this->date_create = new DateTime(); $this->date_create = new DateTime();
@ -676,4 +681,14 @@ class Warranty
return $this->create_source; 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;
}
} }