From bc8d01dc6ad6383f5e08e32450e05fc3d0a98098 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Thu, 21 Feb 2019 14:40:17 +0800 Subject: [PATCH 01/45] Add coord_long and coord_lat fields to JobOrder entity #186 --- src/Entity/JobOrder.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Entity/JobOrder.php b/src/Entity/JobOrder.php index 346319dd..36834cc1 100644 --- a/src/Entity/JobOrder.php +++ b/src/Entity/JobOrder.php @@ -64,6 +64,18 @@ class JobOrder */ protected $coordinates; + // we split up coordinates into long / lat for reports purposes + /** + * @ORM\Column(type="decimal", precision=11, scale=8) + */ + protected $coord_long; + + // we split up coordinates into long / lat for reports purposes + /** + * @ORM\Column(type="decimal", precision=11, scale=8) + */ + protected $coord_lat; + // is it an advanced order (future date) /** * @ORM\Column(type="boolean") @@ -350,6 +362,9 @@ class JobOrder public function setCoordinates(Point $point) { $this->coordinates = $point; + + $this->coord_lat = $point->getLatitude(); + $this->coord_long = $point->getLongitude(); return $this; } From 3d3f386fa308e05c9acecde8281eba1c62f3dcf6 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Thu, 21 Feb 2019 15:39:24 +0800 Subject: [PATCH 02/45] Add command for populating long / lat fields in job order #186 --- src/Command/AdjustLongLatCommand.php | 50 ++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/Command/AdjustLongLatCommand.php diff --git a/src/Command/AdjustLongLatCommand.php b/src/Command/AdjustLongLatCommand.php new file mode 100644 index 00000000..b7e26ad1 --- /dev/null +++ b/src/Command/AdjustLongLatCommand.php @@ -0,0 +1,50 @@ +em = $om; + + parent::__construct(); + } + + protected function configure() + { + $this->setName('joborder:adjust_longlat') + ->setDescription('Separate longitude and latitude from coordinate point.') + ->setHelp('Get longitude and latitude from existing point type coordinate. Separate into individual fields for reports purposes.'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + // get entity manager + $em = $this->em; + + $job_orders = $em->getRepository(JobOrder::class)->findAll(); + + // fulfill each + foreach ($job_orders as $jo) + { + $point = $jo->getCoordinates(); + $jo->setCoordinates($point); + } + + $em->flush(); + } +} From f59476c2d3af10bf3b5392ec1df8cd2c3847dc8a Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Sat, 23 Feb 2019 23:31:46 +0800 Subject: [PATCH 03/45] Add routes, acl and template changes for rejection report #184 --- config/acl.yaml | 8 + config/routes/report.yaml | 9 + src/Controller/ReportController.php | 350 ++++++++++++++++++++++++++++ templates/base.html.twig | 44 +--- 4 files changed, 375 insertions(+), 36 deletions(-) create mode 100644 config/routes/report.yaml create mode 100644 src/Controller/ReportController.php diff --git a/config/acl.yaml b/config/acl.yaml index f8a5febc..f50b9d33 100644 --- a/config/acl.yaml +++ b/config/acl.yaml @@ -238,3 +238,11 @@ access_keys: label: Update - id: promo.delete label: Delete + + - id: report + label: Reports + acls: + - id: report.menu + label: Menu + - id: report.reject + label: Rejection Report diff --git a/config/routes/report.yaml b/config/routes/report.yaml new file mode 100644 index 00000000..c933d680 --- /dev/null +++ b/config/routes/report.yaml @@ -0,0 +1,9 @@ +rep_reject_form: + path: /report/rejection + controller: App\Controller\ReportController::rejectForm + methods: [GET] + +rep_reject_submit: + path: /report/rejection + controller: App\Controller\ReportController::rejectSubmit + methods: [POST] diff --git a/src/Controller/ReportController.php b/src/Controller/ReportController.php new file mode 100644 index 00000000..4b5333d4 --- /dev/null +++ b/src/Controller/ReportController.php @@ -0,0 +1,350 @@ +denyAccessUnlessGranted('report.reject', null, 'No access.'); + + $params = $this->initParameters('outlet_list'); + + return $this->render('outlet/list.html.twig', $params); + } + + public function rejectSubmit(Request $req) + { + $this->denyAccessUnlessGranted('report.reject', null, 'No access.'); + + // get query builder + $qb = $this->getDoctrine() + ->getRepository(Outlet::class) + ->createQueryBuilder('q'); + + // get datatable params + $datatable = $req->request->get('datatable'); + + // count total records + $tquery = $qb->select('COUNT(q)') + ->leftJoin('q.hub', 'hub'); + + // add filters to count query + $this->setQueryFilters($datatable, $tquery); + + $total = $tquery->getQuery() + ->getSingleScalarResult(); + + // get current page number + $page = $datatable['pagination']['page'] ?? 1; + + $perpage = $datatable['pagination']['perpage']; + $offset = ($page - 1) * $perpage; + + // add metadata + $meta = [ + 'page' => $page, + 'perpage' => $perpage, + 'pages' => ceil($total / $perpage), + 'total' => $total, + 'sort' => 'asc', + 'field' => 'id' + ]; + + // build query + $query = $qb->select('q') + ->addSelect('hub.name as hub_name') + ->addSelect('hub.branch as hub_branch'); + + $this->setQueryFilters($datatable, $query); + + // check if sorting is present, otherwise use default + if (isset($datatable['sort']['field']) && !empty($datatable['sort']['field'])) { + $prefix = ''; + + if (!in_array($datatable['sort']['field'], ['hub_name'])) + $prefix = 'q.'; + + $order = $datatable['sort']['sort'] ?? 'asc'; + $query->orderBy($prefix . $datatable['sort']['field'], $order); + } else { + $query->orderBy('q.id', 'asc'); + } + + // get rows for this page + $obj_rows = $query->setFirstResult($offset) + ->setMaxResults($perpage) + ->getQuery() + ->getResult(); + + // process rows + $rows = []; + foreach ($obj_rows as $orow) { + // add row data + $row['id'] = $orow[0]->getID(); + $row['name'] = $orow[0]->getName(); + $row['branch'] = $orow[0]->getBranch(); + $row['address'] = $orow[0]->getAddress(); + $row['contact_nums'] = $orow[0]->getContactNumbers(); + $row['time_open'] = $orow[0]->getTimeOpen()->format('g:i A'); + $row['time_close'] = $orow[0]->getTimeClose()->format('g:i A'); + $row['hub_name'] = $orow['hub_name'] . ' ' . $orow['hub_branch']; + + // add row metadata + $row['meta'] = [ + 'update_url' => '', + 'delete_url' => '' + ]; + + // add crud urls + if ($this->isGranted('outlet.update')) + $row['meta']['update_url'] = $this->generateUrl('outlet_update', ['id' => $row['id']]); + if ($this->isGranted('outlet.delete')) + $row['meta']['delete_url'] = $this->generateUrl('outlet_delete', ['id' => $row['id']]); + + $rows[] = $row; + } + + // response + return $this->json([ + 'meta' => $meta, + 'data' => $rows + ]); + } + + public function addForm() + { + $this->denyAccessUnlessGranted('outlet.add', null, 'No access.'); + + $params = $this->initParameters('outlet_list'); + $params['obj'] = new Outlet(); + $params['mode'] = 'create'; + + $em = $this->getDoctrine()->getManager(); + + // get parent associations + $params['hubs'] = $em->getRepository(Hub::class)->findAll(); + + // response + return $this->render('outlet/form.html.twig', $params); + } + + protected function setObject(Outlet $obj, Request $req) + { + // coordinates + $point = new Point($req->request->get('coord_lng'), $req->request->get('coord_lat')); + + // times + $format = 'g:i A'; + $time_open = DateTime::createFromFormat($format, $req->request->get('time_open')); + $time_close = DateTime::createFromFormat($format, $req->request->get('time_close')); + + // set and save values + $obj->setName($req->request->get('name')) + ->setBranch($req->request->get('branch')) + ->setAddress($req->request->get('address')) + ->setContactNumbers($req->request->get('contact_nums')) + ->setTimeOpen($time_open) + ->setTimeClose($time_close) + ->setCoordinates($point); + } + + protected function setQueryFilters($datatable, QueryBuilder $query) + { + if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) { + $query->where('hub.name LIKE :filter') + ->orWhere('q.name LIKE :filter') + ->orWhere('q.branch LIKE :filter') + ->orWhere('q.address LIKE :filter') + ->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%'); + } + } + + public function addSubmit(Request $req, EncoderFactoryInterface $ef, ValidatorInterface $validator) + { + $this->denyAccessUnlessGranted('outlet.add', null, 'No access.'); + + // create new object + $em = $this->getDoctrine()->getManager(); + $obj = new Outlet(); + + // initialize error list + $error_array = []; + + // custom validation for associations + $hub_id = $req->request->get('hub'); + + if ($hub_id) { + $hub = $em->getRepository(Hub::class) + ->find($hub_id); + + if (empty($hub)) + $error_array['hub'] = 'Invalid hub selected.'; + else + $obj->setHub($hub); + } else { + $error_array['hub'] = 'This value should not be blank.'; + } + + // check if lat and lng are provided + if (empty($req->request->get('coord_lng')) || empty($req->request->get('coord_lat'))) + { + $error_array['coordinates'] = 'No map coordinates provided. Please click on a location on the map.'; + } + + if (empty($error_array)) + { + // set object + $this->setObject($obj, $req); + + // validate + $errors = $validator->validate($obj); + + // add errors to list + foreach ($errors as $error) + { + $error_array[$error->getPropertyPath()] = $error->getMessage(); + } + } + + // check if any errors were found + if (!empty($error_array)) + { + // return validation failure response + return $this->json([ + 'success' => false, + 'errors' => $error_array + ], 422); + } + + // validated! save the entity + $em->persist($obj); + $em->flush(); + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + } + + public function updateForm($id) + { + $this->denyAccessUnlessGranted('outlet.update', null, 'No access.'); + + $params = $this->initParameters('outlet_list'); + + // get row data + $em = $this->getDoctrine()->getManager(); + $obj = $em->getRepository(Outlet::class)->find($id); + + // make sure this row exists + if (empty($obj)) + throw $this->createNotFoundException('The item does not exist'); + + $em = $this->getDoctrine()->getManager(); + + // get parent associations + $params['hubs'] = $em->getRepository(Hub::class)->findAll(); + + $params['obj'] = $obj; + $params['mode'] = 'update'; + + // response + return $this->render('outlet/form.html.twig', $params); + } + + public function updateSubmit(Request $req, EncoderFactoryInterface $ef, ValidatorInterface $validator, $id) + { + $this->denyAccessUnlessGranted('outlet.update', null, 'No access.'); + + // get object data + $em = $this->getDoctrine()->getManager(); + $obj = $em->getRepository(Outlet::class)->find($id); + + // make sure this object exists + if (empty($obj)) + throw $this->createNotFoundException('The item does not exist'); + + $this->setObject($obj, $req); + + // validate + $errors = $validator->validate($obj); + + // initialize error list + $error_array = []; + + // custom validation for associations + $hub_id = $req->request->get('hub'); + + if ($hub_id) { + $hub = $em->getRepository(Hub::class) + ->find($hub_id); + + if (empty($hub)) + $error_array['hub'] = 'Invalid hub selected.'; + else + $obj->setHub($hub); + } else { + $error_array['hub'] = 'This value should not be blank.'; + } + + // add errors to list + foreach ($errors as $error) { + $error_array[$error->getPropertyPath()] = $error->getMessage(); + } + + // check if any errors were found + if (!empty($error_array)) { + // return validation failure response + return $this->json([ + 'success' => false, + 'errors' => $error_array + ], 422); + } + + // validated! save the entity + $em->flush(); + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + } + + public function destroy($id) + { + $this->denyAccessUnlessGranted('outlet.delete', null, 'No access.'); + + $params = $this->initParameters('outlet_list'); + + // get objext data + $em = $this->getDoctrine()->getManager(); + $obj = $em->getRepository(Outlet::class)->find($id); + + if (empty($obj)) + throw $this->createNotFoundException('The item does not exist'); + + // delete this object + $em->remove($obj); + $em->flush(); + + // response + $response = new Response(); + $response->setStatusCode(Response::HTTP_OK); + $response->send(); + } +} diff --git a/templates/base.html.twig b/templates/base.html.twig index 84dbcbb4..f0aad73f 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -103,53 +103,24 @@ + From 167452caad6556beaba1225425e069e43835f39e Mon Sep 17 00:00:00 2001 From: Ramon Gutierrez Date: Sun, 24 Feb 2019 00:49:18 +0800 Subject: [PATCH 04/45] Add template for rejection report form #184 --- public/assets/css/style.css | 75 +++++++++++++++++++++ templates/report/rejection/form.html.twig | 82 +++++++++++++++++++++++ 2 files changed, 157 insertions(+) create mode 100644 templates/report/rejection/form.html.twig diff --git a/public/assets/css/style.css b/public/assets/css/style.css index ef00d1b7..96f1f655 100644 --- a/public/assets/css/style.css +++ b/public/assets/css/style.css @@ -196,6 +196,81 @@ span.has-danger, top: -0.45rem; } +.input-group .form-control:first-child:not(:last-child):not(:focus):not(.focus) { + border-right: 0; +} + +.input-group .input-group-append + .form-control:not(:focus):not(.focus) { + border-left: 0; +} + +.input-group > .form-control:not(:first-child) { + border-top-left-radius: 0; + border-bottom-left-radius: 0; +} + +.input-group > .form-control:not(:last-child) { + border-top-right-radius: 0; + border-bottom-right-radius: 0; +} + +.input-group .input-group-append > .input-group-text { + border-color: #ebedf2; + background-color: #f4f5f8; + color: #575962; +} + +.input-group > .input-group-append > .input-group-text { + border-top-left-radius: 0; + border-bottom-left-radius: 0; +} + +.input-group > .input-group-append:not(:last-child) > .input-group-text { + border-top-right-radius: 0; + border-bottom-right-radius: 0; +} + +.input-group-text { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + padding: .85rem 1.15rem; + margin-bottom: 0; + font-size: 1rem; + font-weight: 400; + line-height: 1.25; + color: #495057; + text-align: center; + white-space: nowrap; + background-color: #e9ecef; + border: 1px solid #ced4da; + border-radius: .25rem; +} + +.input-daterange input:last-child { + border-radius: 0 3px 3px 0; +} + +.input-group { + position: relative; + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -ms-flex-wrap: wrap; + flex-wrap: wrap; + -webkit-box-align: stretch; + -ms-flex-align: stretch; + align-items: stretch; + width: 100%; +} + +.input-daterange { + width: 100%; +} + @media (min-width: 995px) { .modal-lg { max-width: 1024px; diff --git a/templates/report/rejection/form.html.twig b/templates/report/rejection/form.html.twig new file mode 100644 index 00000000..a6ffb3ef --- /dev/null +++ b/templates/report/rejection/form.html.twig @@ -0,0 +1,82 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

Rejection Report

+
+
+
+ +
+ +
+
+
+
+
+
+ + + +

+ Select a date range +

+
+
+
+
+
+
+
+ +
+ +
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} From 8b6066bb3894fe976fb64d6a96b8619958618ec2 Mon Sep 17 00:00:00 2001 From: Ramon Gutierrez Date: Sun, 24 Feb 2019 00:49:48 +0800 Subject: [PATCH 05/45] Update template path for rejection report form #184 --- src/Controller/ReportController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/ReportController.php b/src/Controller/ReportController.php index 4b5333d4..5ce7d0ee 100644 --- a/src/Controller/ReportController.php +++ b/src/Controller/ReportController.php @@ -24,7 +24,7 @@ class ReportController extends BaseController $params = $this->initParameters('outlet_list'); - return $this->render('outlet/list.html.twig', $params); + return $this->render('report/rejection/form.html.twig', $params); } public function rejectSubmit(Request $req) From c0500180a0b6fb7814262940f49b0b97984ff2f2 Mon Sep 17 00:00:00 2001 From: Ramon Gutierrez Date: Sun, 24 Feb 2019 00:50:06 +0800 Subject: [PATCH 06/45] Fix link to rejection report on header #184 --- templates/base.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/base.html.twig b/templates/base.html.twig index f0aad73f..656d5418 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -109,7 +109,7 @@ +
+
+
+

Battery Conflict Report

+
+
+
+ +
+ +
+
+
+
+
+
+ + + +

+ Select a date range +

+
+
+
+
+
+
+
+ +
+ +
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} From b988abd8520f88429a289613dd0848086be43618 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Tue, 2 Apr 2019 12:06:55 +0800 Subject: [PATCH 35/45] Change error message for geofence error in mobile app #199 --- src/Controller/APIController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index a9a23caf..4925cf9b 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -802,8 +802,9 @@ class APIController extends Controller $is_covered = $geo->isCovered($long, $lat); if (!$is_covered) { + // TODO: put geofence error message in config file somewhere $res->setError(true) - ->setErrorMessage('Location is not covered by our service.'); + ->setErrorMessage('Oops! Our service is limited to Metro Manila only. We will update you as soon as we are able to cover your area'); return $res->getReturnResponse(); } From c971499109ef574bd327d015e616d0c130b3f3d2 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Tue, 2 Apr 2019 14:14:48 +0800 Subject: [PATCH 36/45] Add kml file for supported areas #200 --- kml/supported_areas.kml | 73 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 kml/supported_areas.kml diff --git a/kml/supported_areas.kml b/kml/supported_areas.kml new file mode 100644 index 00000000..aa643fb4 --- /dev/null +++ b/kml/supported_areas.kml @@ -0,0 +1,73 @@ + + + + ResQ Supported Area + + + + + + normal + #poly-000000-1200-77-nodesc-normal + + + highlight + #poly-000000-1200-77-nodesc-highlight + + + + ResQ Supported Area + + Supported Area + #poly-000000-1200-77-nodesc + + + + 1 + + 121.0717128,14.7868868,0 + 121.0222743,14.7895424,0 + 120.9302638,14.6793076,0 + 120.9494899,14.4427135,0 + 121.0250209,14.3735484,0 + 121.0744593,14.5171749,0 + 121.1513636,14.5357864,0 + 121.1884425,14.5809791,0 + 121.2021754,14.6248337,0 + 121.1321376,14.6540653,0 + 121.129391,14.7616569,0 + 121.0717128,14.7868868,0 + + + + + + + + From b0386c47580d946038d25d0a0a675b5707da7765 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 2 Apr 2019 10:22:17 +0000 Subject: [PATCH 37/45] Add checking for battery conflicts in existing job orders. #197 --- src/Controller/ReportController.php | 101 ++++++++++++++++++++-------- 1 file changed, 72 insertions(+), 29 deletions(-) diff --git a/src/Controller/ReportController.php b/src/Controller/ReportController.php index 352dadf0..545bdae6 100644 --- a/src/Controller/ReportController.php +++ b/src/Controller/ReportController.php @@ -277,16 +277,13 @@ class ReportController extends BaseController { $this->denyAccessUnlessGranted('report.battery.conflict', null, 'No access.'); - // get battery query builder - $batt_qb = $this->getDoctrine() - ->getRepository(Battery::class) - ->createQueryBuilder('batt'); - // get job order query builder $job_qb = $this->getDoctrine() ->getRepository(JobOrder::class) ->createQueryBuilder('jo'); + $em = $this->getDoctrine()->getManager(); + // get dates $raw_date_start = $req->request->get('date_start'); $raw_date_end = $req->request->get('date_end'); @@ -294,10 +291,7 @@ class ReportController extends BaseController $date_start = DateTime::createFromFormat('m/d/Y', $raw_date_start); $date_end = DateTime::createFromFormat('m/d/Y', $raw_date_end); - // build query for battery - $batt_query = $batt_qb->getQuery(); - - // build query for job order + // build query for job order $jo_query = $job_qb->where('jo.date_create >= :start') ->andWhere('jo.date_create <= :end') ->andWhere('jo.status != :status') @@ -305,38 +299,87 @@ class ReportController extends BaseController ->setParameter('end', $date_end->format('Y-m-d') . ' 23:59:59') ->setParameter('status', JOStatus::CANCELLED) ->getQuery(); + // run queries - $batts = $batt_query->getResult(); $jos = $jo_query->getResult(); - $battcomp = []; - // get battery results and store in array - foreach ($batts as $batt) - { - $batt_id = $batt->getID(); + $batteries = $em->getRepository(Battery::class)->findAll(); - $comp_vehicles = $batt->getVehicles(); - // go through compatible vehicle list and add to array - foreach ($comp_vehicles as $vehicle) + // create compatibility matrix for battery and vehicle + $comp_matrix = []; + foreach ($batteries as $batt) + { + $vehicles = $batt->getVehicles(); + foreach ($vehicles as $vehicle) { - $battcomp[$batt_id] = [ - 'manufacturer' => $vehicle->getManufacturer(), - 'make' => $vehicle->getMake(), - ]; + $comp_matrix[$batt->getID()][$vehicle->getID()] = true; } } - // get results + // go through the job orders to find the conflicts + $results = []; foreach ($jos as $jo) { - $vehicle = $jo->getCustomerVehicle()->getVehicle(); - $vmanufacturer = $vehicle->getManufacturer(); - $vmake = $vehicle->getMake(); - - $invoice_items = $jo->getInvoice()->getItems(); - + $invoice_items = $jo->getInvoice()->getItems(); + foreach ($invoice_items as $item) + { + if ($item->getBattery() != null) + { + $batt_id = $item->getBattery()->getID(); + $vehicle_id = $jo->getCustomerVehicle()->getVehicle()->getID(); + if (isset($comp_matrix[$batt_id][$vehicle_id])) + // if (!isset($comp_matrix[$batt_id][$vehicle_id]) && !$comp_matrix[$batt_id][$vehicle_id]) + { + $results[] = [ + 'jo_id' => $jo->getID(), + 'jo_date_create' => $jo->getDateCreate(), + 'cus_vehicle_manufacturer' => $jo->getCustomerVehicle()->getVehicle()->getManufacturer()->getName(), + 'cus_vehicle_make' => $jo->getCustomerVehicle()->getVehicle()->getMake(), + 'cus_vehicle_model' => $jo->getCustomerVehicle()->getModelYear(), + 'battery_model_ordered' => $item->getBattery()->getModel()->getName(), + 'battery_size_ordered' => $item->getBattery()->getSize()->getName(), + 'compatible_batt' => $jo->getCustomerVehicle()->getVehicle()->getBatteries(), + ]; + } + } + } } + /* + $resp = new StreamedResponse(); + $resp->setCallback(function() use ($results) { + // csv output + $csv_handle = fopen('php://output', 'w+'); + fputcsv($csv_handle, [ + 'Order #', + 'Order Date and Time' + //'Manufacturer', + //'Make', + //'Year', + //'Battery Model', + //'Battery Size', + //'Compatible Batteries' + ]); + foreach ($results as $row) + { + fputcsv($csv_handle, $row); + } + + fclose($csv_handle); + }); + + $filename = 'battery_conflict_' . $date_start->format('Ymd') . '_' . $date_end->format('Ymd') . '.csv'; + + $resp->setStatusCode(200); + $resp->headers->set('Content-Type', 'text/csv; charset=utf-8'); + $resp->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"'); + + return $resp; + */ + + return $this->json([ + 'result' => $results, + ]); } } From 3af6d6b7e8f13ccd39bd83d27229daa13ff37e37 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 3 Apr 2019 02:14:26 +0000 Subject: [PATCH 38/45] Fix checking for battery conflicts. Add list of compatible batteries for vehicle. #197 --- src/Controller/ReportController.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Controller/ReportController.php b/src/Controller/ReportController.php index 545bdae6..13d63613 100644 --- a/src/Controller/ReportController.php +++ b/src/Controller/ReportController.php @@ -328,18 +328,32 @@ class ReportController extends BaseController { $batt_id = $item->getBattery()->getID(); $vehicle_id = $jo->getCustomerVehicle()->getVehicle()->getID(); - if (isset($comp_matrix[$batt_id][$vehicle_id])) - // if (!isset($comp_matrix[$batt_id][$vehicle_id]) && !$comp_matrix[$batt_id][$vehicle_id]) + if (isset($comp_matrix[$batt_id][$vehicle_id]) && $comp_matrix[$batt_id][$vehicle_id]) { + continue; + } + else + { + // get the compatible batteries for the customer vehicle + $batteries = []; + foreach($jo->getCustomerVehicle()->getVehicle()->getBatteries() as $comp_batt) + { + $batteries[] = [ + 'id' => $comp_batt->getID(), + 'mfg_name' => $comp_batt->getManufacturer()->getName(), + 'model_name' => $comp_batt->getModel()->getName(), + 'size_name' => $comp_batt->getSize()->getName(), + ]; + } $results[] = [ 'jo_id' => $jo->getID(), 'jo_date_create' => $jo->getDateCreate(), 'cus_vehicle_manufacturer' => $jo->getCustomerVehicle()->getVehicle()->getManufacturer()->getName(), 'cus_vehicle_make' => $jo->getCustomerVehicle()->getVehicle()->getMake(), 'cus_vehicle_model' => $jo->getCustomerVehicle()->getModelYear(), - 'battery_model_ordered' => $item->getBattery()->getModel()->getName(), + 'battery_model_ordered' => $item->getBattery()->getModel()->getName(), 'battery_size_ordered' => $item->getBattery()->getSize()->getName(), - 'compatible_batt' => $jo->getCustomerVehicle()->getVehicle()->getBatteries(), + 'compatible_batt' => $batteries, ]; } } From c80013bc023a6a16ebd73c649186b273e4294b61 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 3 Apr 2019 07:29:14 +0000 Subject: [PATCH 39/45] Fix formatting issue for csv output. #197 --- src/Controller/ReportController.php | 46 +++++++++++++++-------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/Controller/ReportController.php b/src/Controller/ReportController.php index 13d63613..800474d7 100644 --- a/src/Controller/ReportController.php +++ b/src/Controller/ReportController.php @@ -324,6 +324,7 @@ class ReportController extends BaseController $invoice_items = $jo->getInvoice()->getItems(); foreach ($invoice_items as $item) { + // check if the item is a battery if ($item->getBattery() != null) { $batt_id = $item->getBattery()->getID(); @@ -338,42 +339,44 @@ class ReportController extends BaseController $batteries = []; foreach($jo->getCustomerVehicle()->getVehicle()->getBatteries() as $comp_batt) { - $batteries[] = [ - 'id' => $comp_batt->getID(), - 'mfg_name' => $comp_batt->getManufacturer()->getName(), - 'model_name' => $comp_batt->getModel()->getName(), - 'size_name' => $comp_batt->getSize()->getName(), - ]; + //$batteries[] = [ + // 'mfg_name' => $comp_batt->getManufacturer()->getName(), + // 'model_name' => $comp_batt->getModel()->getName(), + // 'size_name' => $comp_batt->getSize()->getName(), + //]; + $batteries[] = $comp_batt->getManufacturer()->getName() . ' ' . + $comp_batt->getModel()->getName() . ' ' . + $comp_batt->getSize()->getName(); } + $results[] = [ 'jo_id' => $jo->getID(), - 'jo_date_create' => $jo->getDateCreate(), + 'jo_date_create' => $jo->getDateCreate()->format('m/d/Y H:i'), 'cus_vehicle_manufacturer' => $jo->getCustomerVehicle()->getVehicle()->getManufacturer()->getName(), 'cus_vehicle_make' => $jo->getCustomerVehicle()->getVehicle()->getMake(), 'cus_vehicle_model' => $jo->getCustomerVehicle()->getModelYear(), 'battery_model_ordered' => $item->getBattery()->getModel()->getName(), 'battery_size_ordered' => $item->getBattery()->getSize()->getName(), - 'compatible_batt' => $batteries, + 'compatible_batt' => implode(', ', $batteries), ]; } } } } - - /* + $resp = new StreamedResponse(); $resp->setCallback(function() use ($results) { // csv output $csv_handle = fopen('php://output', 'w+'); fputcsv($csv_handle, [ 'Order #', - 'Order Date and Time' - //'Manufacturer', - //'Make', - //'Year', - //'Battery Model', - //'Battery Size', - //'Compatible Batteries' + 'Order Date and Time', + 'Manufacturer', + 'Make', + 'Year', + 'Battery Model', + 'Battery Size', + 'Compatible Batteries' ]); foreach ($results as $row) { @@ -390,10 +393,9 @@ class ReportController extends BaseController $resp->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"'); return $resp; - */ - - return $this->json([ - 'result' => $results, - ]); + + //return $this->json([ + // 'result' => $results, + //]); } } From 620a750465dcc0c655f9d02fe36814a4582d5cc6 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 4 Apr 2019 09:07:41 +0000 Subject: [PATCH 40/45] Add CAPI call to add a new battery. #201 --- catalyst/api-bundle/Command/TestCommand.php | 11 +++ .../routes/{warranty_api.yaml => capi.yaml} | 6 ++ src/Controller/CAPI/BatteryController.php | 68 +++++++++++++++++++ 3 files changed, 85 insertions(+) rename config/routes/{warranty_api.yaml => capi.yaml} (94%) diff --git a/catalyst/api-bundle/Command/TestCommand.php b/catalyst/api-bundle/Command/TestCommand.php index 03d1fe85..66ec639d 100644 --- a/catalyst/api-bundle/Command/TestCommand.php +++ b/catalyst/api-bundle/Command/TestCommand.php @@ -75,6 +75,17 @@ class TestCommand extends Command ]; $api->post('/capi/warranties/' . $id . '/claim', $params); + // add battery + $sku = 'WZMB31QT-CPP00-S'; + $brand = '4'; + $size = '1'; + $params = [ + 'sku' => $sku, + 'brand' => $brand, + 'size' => $size, + ]; + $api->post('/capi/batteries', $params); + /* // plate warranty diff --git a/config/routes/warranty_api.yaml b/config/routes/capi.yaml similarity index 94% rename from config/routes/warranty_api.yaml rename to config/routes/capi.yaml index 85075440..a340041c 100644 --- a/config/routes/warranty_api.yaml +++ b/config/routes/capi.yaml @@ -30,6 +30,12 @@ capi_battery_sizes: controller: App\Controller\CAPI\BatteryController::getSizes methods: [GET] +# add battery +capi_battery_add: + path: /capi/batteries + controller: App\Controller\CAPI\BatteryController::addBattery + methods: [POST] + # vehicle api diff --git a/src/Controller/CAPI/BatteryController.php b/src/Controller/CAPI/BatteryController.php index a8197bab..dc035c58 100644 --- a/src/Controller/CAPI/BatteryController.php +++ b/src/Controller/CAPI/BatteryController.php @@ -75,4 +75,72 @@ class BatteryController extends APIController return new APIResponse(true, 'Battery sizes loaded.', $data); } + + public function addBattery(Request $req, EntityManagerInterface $em) + { + // required parameters + $params = [ + 'sku', + 'brand', + 'size', + ]; + + $msg = $this->checkRequiredParameters($req, $params); + error_log('msg - ' . $msg); + if ($msg) + return new APIResponse(false, $msg); + + $sku = $req->request->get('sku'); + $brand = $req->request->get('brand'); + $size = $req->request->get('size'); + + // check if sku already exists + $batt = $em->getRepository(SAPBattery::class)->find($sku); + if ($batt != null) + return new APIResponse(false, 'Battery SKU already exists.'); + + // check if brand exists + $batt_brand = $em->getRepository(SAPBatteryBrand::class)->find($brand); + if ($batt_brand == null) + return new APIResponse(false, 'Invalid brand.'); + + // check if size exists + $batt_size = $em->getRepository(SAPBatterySize::class)->find($size); + if ($batt_size == null) + return new APIResponse(false, 'Invalid size.'); + + + $new_batt = new SAPBattery(); + $new_batt->setID($sku) + ->setBrand($batt_brand) + ->setSize($batt_size); + + try + { + $em->persist($new_batt); + $em->flush(); + } + catch (UniqueConstraintViolationException $e) + { + return new APIResponse(false, 'Battery SKU already exists.'); + } + + // return the new battery data + $data = [ + 'battery' => $this->generateBatteryData($new_batt), + ]; + + return new APIResponse(true, 'Battery added.', $data); + } + + protected function generateBatteryData(SAPBattery $batt) + { + $data = [ + 'sku' => $batt->getID(), + 'brand' => $batt->getBrand()->getID(), + 'size' => $batt->getSize()->getID(), + ]; + + return $data; + } } From 24a0e5a2d13ceea9dff29f2d615276144f5d7ff2 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 4 Apr 2019 09:22:31 +0000 Subject: [PATCH 41/45] Change brand and size parameters to brand_id and size_id. #201 --- catalyst/api-bundle/Command/TestCommand.php | 8 ++++---- src/Controller/CAPI/BatteryController.php | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/catalyst/api-bundle/Command/TestCommand.php b/catalyst/api-bundle/Command/TestCommand.php index 66ec639d..3d03ae0d 100644 --- a/catalyst/api-bundle/Command/TestCommand.php +++ b/catalyst/api-bundle/Command/TestCommand.php @@ -77,12 +77,12 @@ class TestCommand extends Command // add battery $sku = 'WZMB31QT-CPP00-S'; - $brand = '4'; - $size = '1'; + $brand_id = '4'; + $size_id = '1'; $params = [ 'sku' => $sku, - 'brand' => $brand, - 'size' => $size, + 'brand_id' => $brand_id, + 'size_id' => $size_id, ]; $api->post('/capi/batteries', $params); diff --git a/src/Controller/CAPI/BatteryController.php b/src/Controller/CAPI/BatteryController.php index dc035c58..ec0d65d9 100644 --- a/src/Controller/CAPI/BatteryController.php +++ b/src/Controller/CAPI/BatteryController.php @@ -81,8 +81,8 @@ class BatteryController extends APIController // required parameters $params = [ 'sku', - 'brand', - 'size', + 'brand_id', + 'size_id', ]; $msg = $this->checkRequiredParameters($req, $params); @@ -91,8 +91,8 @@ class BatteryController extends APIController return new APIResponse(false, $msg); $sku = $req->request->get('sku'); - $brand = $req->request->get('brand'); - $size = $req->request->get('size'); + $brand_id = $req->request->get('brand_id'); + $size_id = $req->request->get('size_id'); // check if sku already exists $batt = $em->getRepository(SAPBattery::class)->find($sku); @@ -100,12 +100,12 @@ class BatteryController extends APIController return new APIResponse(false, 'Battery SKU already exists.'); // check if brand exists - $batt_brand = $em->getRepository(SAPBatteryBrand::class)->find($brand); + $batt_brand = $em->getRepository(SAPBatteryBrand::class)->find($brand_id); if ($batt_brand == null) return new APIResponse(false, 'Invalid brand.'); // check if size exists - $batt_size = $em->getRepository(SAPBatterySize::class)->find($size); + $batt_size = $em->getRepository(SAPBatterySize::class)->find($size_id); if ($batt_size == null) return new APIResponse(false, 'Invalid size.'); From e39289bb544412a99bfb2639d24386281d3d3ce6 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 9 Apr 2019 09:23:38 +0000 Subject: [PATCH 42/45] Add the customer name, mobile, and sap battery fields to the warranty csv file. #202 --- src/Command/ImportLegacyJobOrderCommand.php | 112 +++++++++++++++----- 1 file changed, 83 insertions(+), 29 deletions(-) diff --git a/src/Command/ImportLegacyJobOrderCommand.php b/src/Command/ImportLegacyJobOrderCommand.php index 8161fbae..7546880b 100644 --- a/src/Command/ImportLegacyJobOrderCommand.php +++ b/src/Command/ImportLegacyJobOrderCommand.php @@ -10,6 +10,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Doctrine\Common\Persistence\ObjectManager; use App\Entity\Warranty; +use App\Entity\Battery; use App\Entity\BatterySize; use App\Entity\BatteryModel; use App\Entity\VehicleManufacturer; @@ -31,6 +32,7 @@ use DateTime; class ImportLegacyJobOrderCommand extends Command { protected $em; + protected $batt_hash; protected $bmodel_hash; protected $bsize_hash; protected $vmfg_hash; @@ -50,6 +52,7 @@ class ImportLegacyJobOrderCommand extends Command $this->loadBatterySizes(); $this->loadVehicleManufacturers(); $this->loadVehicles(); + $this->loadBatteries(); $this->jo_hash = []; @@ -312,7 +315,7 @@ class ImportLegacyJobOrderCommand extends Command continue; // check if battery is found - $found_battery = $this->findBattery($fields[92], $batt_model, $batt_size); + $found_battery = $this->findBattery($fields[92], $batt_model, $batt_size, $sap_code); if (!$found_battery) { // $output->writeln('battery not found - ' . $fields[92]); @@ -399,7 +402,33 @@ class ImportLegacyJobOrderCommand extends Command $line .= '\N,'; // date claim - $line .= '\N'; + $line .= '\N,'; + + // claim id + $line .= '\N,'; + + // sap battery id + if (isset($sap_code)) + $line .= $sap_code . ','; + else + $line .= '\N,'; + // first name + if (isset($fields[20]) && strlen(trim($fields[20])) > 0) + $line .= $fields[20] . ','; + else + $line .= '\N,'; + + // last name + if (isset($fields[22]) && strlen(trim($fields[22])) > 0) + $line .= $fields[22] . ','; + else + $line .= '\N,'; + + // mobile number + if (isset($fields[24]) && strlen(trim($fields[24])) > 0) + $line .= $fields[24] . ','; + else + $line .= '\N'; fwrite($warr_outfile, $line . "\n"); } @@ -769,6 +798,25 @@ class ImportLegacyJobOrderCommand extends Command } } + protected function loadBatteries() + { + $this->batt_hash = []; + + $batts = $this->em->getRepository(Battery::class)->findAll(); + foreach ($batts as $batt) + { + if (($batt->getModel() == null) or ($batt->getSize() == null) or ($batt->getSAPCode() == null)) + { + continue; + } + + $model_id = $batt->getModel()->getID(); + $size_id = $batt->getSize()->getID(); + + $this->batt_hash[$model_id][$size_id] = $batt->getSAPCode(); + } + } + protected function loadVehicleManufacturers() { $this->vmfg_hash = []; @@ -817,16 +865,16 @@ class ImportLegacyJobOrderCommand extends Command return $clean_text; } - protected function findBattery($batt_field, &$batt_model, &$batt_size) - { - // split battery into model and size - // echo "trying match - " . $fields[92] . "\n"; - $res = preg_match("/^(.+)(GOLD|EXCEL|ENDURO|\(Trade-In\))/", $batt_field, $matches); - if (!$res) - { - // echo "no match - " . $fields[92] . "\n"; + protected function findBattery($batt_field, &$batt_model, &$batt_size, &$sap_code) + { + // split battery into model and size + // echo "trying match - " . $batt_field . "\n"; + $res = preg_match("/^(.+)(GOLD|EXCEL|ENDURO|\(Trade-In\))/", $batt_field, $matches); + if (!$res) + { + //echo "no match - " . $fields[92] . "\n"; return false; - } + } if ($matches[2] == '(Trade-In)') return false; @@ -836,29 +884,35 @@ class ImportLegacyJobOrderCommand extends Command // TODO: what to do about (Trade-In) - // check if we have the size - $found_size = $this->simplifyName($matches[1]); - if (!isset($this->bsize_hash[$found_size])) - { - // try legacy battery lookup - $legacy_size = LegacyBattery::translate($found_size); - if ($legacy_size == null) - { - // echo "no size - $found_size\n"; - if (isset($no_sizes[$found_size])) - $no_sizes[$found_size]++; - else - $no_sizes[$found_size] = 1; - return false; - } + // check if we have the size + $found_size = $this->simplifyName($matches[1]); + if (!isset($this->bsize_hash[$found_size])) + { + // try legacy battery lookup + $legacy_size = LegacyBattery::translate($found_size); + if ($legacy_size == null) + { + // echo "no size - $found_size\n"; + if (isset($no_sizes[$found_size])) + $no_sizes[$found_size]++; + else + $no_sizes[$found_size] = 1; + return false; + } - $found_size = $legacy_size; - } + $found_size = $legacy_size; + } $batt_size = $this->bsize_hash[$found_size]; // $batt_size = $found_size; + //get battery using ids of batt_model and batt_size + if (!isset($this->batt_hash[$batt_model][$batt_size])) + return false; + + $sap_code = $this->batt_hash[$batt_model][$batt_size]; + return true; - } + } protected function findVehicle($vmfg_field, $vmake_field, $vmodel_field, &$vehicle) { From a08e7b39eb2934a443eec0803ba8f1ecd028a92f Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 9 Apr 2019 09:41:37 +0000 Subject: [PATCH 43/45] Create a file with sql commands to load the legacy data from csv to the database. #202 --- utils/legacy_load/import_legacy_data.sql | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 utils/legacy_load/import_legacy_data.sql diff --git a/utils/legacy_load/import_legacy_data.sql b/utils/legacy_load/import_legacy_data.sql new file mode 100644 index 00000000..0f12390e --- /dev/null +++ b/utils/legacy_load/import_legacy_data.sql @@ -0,0 +1,4 @@ +load data local infile '/tmp/plate_numbers.csv' into table plate_number fields terminated by ','; +load data infile '/tmp/legacy_jo_row.csv' into table legacy_job_order_row fields terminated by ',' enclosed by '"' lines terminated by '\n' (job_order_id, item, qty, price, price_level, status, account, enrollee) set id = null; +load data local infile '/tmp/warranty.csv' into table warranty fields terminated by ',' (bty_model_id, bty_size_id, serial, warranty_class, plate_number, status, date_create, date_purchase, date_expire, date_claim, claim_id, sap_bty_id, first_name, last_name, mobile_number) set id = null; +load data infile '/tmp/legacy_jo.csv' into table legacy_job_order fields terminated by '|' (id, trans_date, trans_type, origin, car_brand, car_make, car_model, car_color, cust_name, cust_first_name, cust_middle_name, cust_last_name, cust_contact, cust_mobile, cust_landline, delivery_instructions, agent_notes_1, delivery_date, delivery_time, advance_order, stage, cancel_reason, cancel_reason_specify, payment_method, prepared_by, dispatch_time, dispatch_date, dispatched_by, address, landmark, date_purchase, plate_number); From be8ceb7e2931dd1f841227c2996a7c85e2c19f9a Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 11 Apr 2019 07:33:25 +0000 Subject: [PATCH 44/45] Add warr_tnv to the Battery entity. Add the tnv warranty to the add/edit forms. Add means to save/display the tnv warranty data in the forms. #203 --- src/Controller/BatteryController.php | 3 +++ src/Entity/Battery.php | 18 ++++++++++++++++++ templates/battery/form.html.twig | 8 ++++++++ 3 files changed, 29 insertions(+) diff --git a/src/Controller/BatteryController.php b/src/Controller/BatteryController.php index 317f0f43..48e1dde4 100644 --- a/src/Controller/BatteryController.php +++ b/src/Controller/BatteryController.php @@ -119,6 +119,7 @@ class BatteryController extends BaseController $row['sell_price'] = $orow[0]->getSellingPrice(); $row['warr_private'] = $orow[0]->getWarrantyPrivate(); $row['warr_commercial'] = $orow[0]->getWarrantyCommercial(); + $row['warr_tnv'] = $orow[0]->getWarrantyTnv(); $row['res_capacity'] = $orow[0]->getReserveCapacity(); $row['length'] = $orow[0]->getLength(); $row['width'] = $orow[0]->getWidth(); @@ -181,6 +182,7 @@ class BatteryController extends BaseController ->setSAPCode($req->request->get('sap_code')) ->setWarrantyPrivate($req->request->get('warr_private')) ->setWarrantyCommercial($req->request->get('warr_commercial')) + ->setWarrantyTnv($req->request->get('warr_tnv')) ->setReserveCapacity($req->request->get('res_capacity')) ->setLength($req->request->get('length')) ->setWidth($req->request->get('width')) @@ -303,6 +305,7 @@ class BatteryController extends BaseController ->setSAPCode($req->request->get('sap_code')) ->setWarrantyPrivate($req->request->get('warr_private')) ->setWarrantyCommercial($req->request->get('warr_commercial')) + ->setWarrantyTnv($req->request->get('warr_tnv')) ->setReserveCapacity($req->request->get('res_capacity')) ->setLength($req->request->get('length')) ->setWidth($req->request->get('width')) diff --git a/src/Entity/Battery.php b/src/Entity/Battery.php index ed0c99ec..e05bff81 100644 --- a/src/Entity/Battery.php +++ b/src/Entity/Battery.php @@ -85,6 +85,13 @@ class Battery */ protected $warr_commercial; + // warranty tnv + /** + * @ORM\Column(type="smallint") + * @Assert\NotBlank() + */ + protected $warr_tnv; + // reserve capacity /** * @ORM\Column(type="smallint") @@ -248,6 +255,17 @@ class Battery return $this->warr_commercial; } + public function setWarrantyTnv($warr_tnv) + { + $this->warr_tnv = $warr_tnv; + return $this; + } + + public function getWarrantyTnv() + { + return $this->warr_tnv; + } + public function setReserveCapacity($res_capacity) { $this->res_capacity = $res_capacity; diff --git a/templates/battery/form.html.twig b/templates/battery/form.html.twig index b0e46cbb..53adb693 100644 --- a/templates/battery/form.html.twig +++ b/templates/battery/form.html.twig @@ -157,6 +157,14 @@ In months +
+ + + + In months +
From e4e52768f3d3e0d5023e3c7b6f7da59bbe06b3b9 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 11 Apr 2019 09:00:31 +0000 Subject: [PATCH 45/45] Create sql script to set the tnv warranty for all GOLD model batteries. #203 --- utils/battery_warranty/set_tnv_warranty.sql | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 utils/battery_warranty/set_tnv_warranty.sql diff --git a/utils/battery_warranty/set_tnv_warranty.sql b/utils/battery_warranty/set_tnv_warranty.sql new file mode 100644 index 00000000..28f67d82 --- /dev/null +++ b/utils/battery_warranty/set_tnv_warranty.sql @@ -0,0 +1,2 @@ +update battery as batt inner join battery_model as bmodel on batt.model_id = bmodel.id set batt.warr_tnv=12 where bmodel.name='GOLD'; +