Merge branch 'master' of gitlab.com:jankstudio/resq into 543-autoassign-revisions

This commit is contained in:
Korina Cordero 2021-04-21 03:25:55 +00:00
commit 17f800196d
7 changed files with 244 additions and 1 deletions

View file

@ -57,3 +57,8 @@ access_keys:
acls:
- id: customer.register
label: Register Customer
- id: municipality
label: Municipality
acls:
- id: municipality.list
label: List

View file

@ -166,3 +166,9 @@ capi_cwarr_register:
controller: App\Controller\CAPI\CustomerWarrantyController::register
methods: [POST]
# municipality
capi_municipality_list:
path: /capi/municipality
controller: App\Controller\CAPI\MunicipalityController::getAll
methods: [GET]

View file

@ -199,6 +199,8 @@ class CustomerWarrantyController extends APIController
'vmodel' => $warr->getVehicleModelYear(),
'dealer_name' => $warr->getDealerName(),
'dealer_address' => $warr->getDealerAddress(),
'province_id' => $warr->getProvinceID(),
'municipality_id' => $warr->getMunicipalityID(),
];
}
else
@ -224,6 +226,8 @@ class CustomerWarrantyController extends APIController
'vmodel' => '',
'dealer_name' => '',
'dealer_address' => '',
'province_id' => '',
'municipality_id' => '',
];
}
@ -263,6 +267,8 @@ class CustomerWarrantyController extends APIController
'vmodel' => $other_data['vmodel'],
'dealer_name' => $other_data['dealer_name'],
'dealer_address' => $other_data['dealer_address'],
'province_id' => $other_data['province_id'],
'municipality_id' => $other_data['municipality_id'],
];
return new APIResponse(true, 'Warranty found.', $data);
@ -422,6 +428,12 @@ class CustomerWarrantyController extends APIController
}
else
{
// NOTE: behaviour has been changed. we now save customer details too
$cust->setFirstName($req->request->get('first_name'))
->setLastName($req->request->get('last_name'))
->setEmail($req->request->get('email'))
->setPrivacyPromo($priv_promo)
->setPhoneMobile($req->request->get('contact_num'));
// only update privacy promo
$cust->setPrivacyPromo($priv_promo);
}
@ -461,7 +473,11 @@ class CustomerWarrantyController extends APIController
->setDealerName($req->request->get('dealer_name'))
->setDealerAddress($req->request->get('dealer_address'))
->setCustomer($cust)
->setValidated(false);
->setValidated(false)
// and more new fields
->setProvinceID($req->request->get('province_id'))
->setMunicipalityID($req->request->get('municipality_id'));
// TODO: check for date purchase and date expire

View file

@ -0,0 +1,63 @@
<?php
namespace App\Controller\CAPI;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\ORM\Query;
use Doctrine\ORM\EntityManagerInterface;
use Catalyst\APIBundle\Controller\APIController;
use Catalyst\APIBundle\Response\APIResponse;
use App\Entity\Municipality;
use Catalyst\APIBundle\Access\Generator as ACLGenerator;
class MunicipalityController extends APIController
{
protected $acl_gen;
public function __construct(ACLGenerator $acl_gen)
{
$this->acl_gen = $acl_gen;
}
public function getAll(EntityManagerInterface $em)
{
$this->denyAccessUnlessGranted('municipality.list', null, 'No access.');
$muns = $em->getRepository(Municipality::class)->findBy([], ['province_name' => 'ASC', 'name' => 'ASC']);
$result = [];
$provinces = [];
foreach ($muns as $m)
{
$pid = $m->getProvinceID();
$pname = $m->getProvinceName();
$mid = $m->getID();
$mname = $m->getName();
if (!isset($provinces[$pid]))
{
$provinces[$pid] = [
'id' => $pid,
'name' => $pname,
'municipalities' => [],
];
}
// error_log("$pid - $pname - $mid - $mname");
$provinces[$pid]['municipalities'][$mid] = [
'id' => $mid,
'name' => $mname,
];
}
$data = [
'provinces' => $provinces,
];
return new APIResponse(true, 'Municipalities loaded.', $data);
}
}

View file

@ -0,0 +1,69 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity
* @ORM\Table(name="municipality")
*/
class Municipality
{
// unique id
/**
* @ORM\Id
* @ORM\Column(type="string", length=11)
*/
protected $code;
// name
/**
* @ORM\Column(type="string", length=100)
*/
protected $name;
// province id
/**
* @ORM\Column(type="string", length=11)
*/
protected $province_id;
// province name
/**
* @ORM\Column(type="string", length=100)
*/
protected $province_name;
public function __construct()
{
}
public function getID()
{
return $this->code;
}
public function setName($name)
{
$this->name = $name;
return $this;
}
public function getName()
{
return $this->name;
}
public function getProvinceID()
{
return $this->province_id;
}
public function getProvinceName()
{
return $this->province_name;
}
}

View file

@ -222,6 +222,16 @@ class Warranty
*/
protected $customer;
/**
* @ORM\Column(type="string", length=11, nullable=true)
*/
protected $province_id;
/**
* @ORM\Column(type="string", length=11, nullable=true)
*/
protected $municipality_id;
public function __construct()
{
$this->date_create = new DateTime();
@ -626,4 +636,26 @@ class Warranty
{
return $this->customer;
}
public function setProvinceID($province_id)
{
$this->province_id = $province_id;
return $this;
}
public function getProvinceID()
{
return $this->province_id;
}
public function setMunicipalityID($municipality_id)
{
$this->municipality_id = $municipality_id;
return $this;
}
public function getMunicipalityID()
{
return $this->municipality_id;
}
}

52
utils/municipalities.sql Normal file

File diff suppressed because one or more lines are too long