Modify claim warranty api call #171
This commit is contained in:
parent
e4cedd9e4d
commit
bc9cf2a74f
4 changed files with 62 additions and 7 deletions
|
|
@ -63,9 +63,17 @@ class TestCommand extends Command
|
||||||
|
|
||||||
// warranty find
|
// warranty find
|
||||||
$api->get('/capi/warranties/' . $serial);
|
$api->get('/capi/warranties/' . $serial);
|
||||||
|
*/
|
||||||
|
|
||||||
// warranty claim
|
// warranty claim
|
||||||
$api->post('/capi/warranties/' . $serial . '/claim');
|
$id = 86811;
|
||||||
|
$serial = 'TEST001';
|
||||||
|
$params = [
|
||||||
|
'serial' => $serial,
|
||||||
|
];
|
||||||
|
$api->post('/capi/warranties/' . $id . '/claim', $params);
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
// plate warranty
|
// plate warranty
|
||||||
$api->get('/capi/plates/' . $plate_num . '/warranties');
|
$api->get('/capi/plates/' . $plate_num . '/warranties');
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ capi_warranty_register:
|
||||||
|
|
||||||
# claim warranty
|
# claim warranty
|
||||||
capi_warranty_claim:
|
capi_warranty_claim:
|
||||||
path: /capi/warranties/{serial}/claim
|
path: /capi/warranties/{id}/claim
|
||||||
controller: App\Controller\CAPI\WarrantyController::claim
|
controller: App\Controller\CAPI\WarrantyController::claim
|
||||||
methods: [POST]
|
methods: [POST]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -194,23 +194,52 @@ class WarrantyController extends APIController
|
||||||
return new APIResponse(true, 'Warranty registered.', $data);
|
return new APIResponse(true, 'Warranty registered.', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function claim(Request $req, EntityManagerInterface $em, $serial)
|
public function claim(Request $req, EntityManagerInterface $em, $id)
|
||||||
{
|
{
|
||||||
$clean_serial = $this->cleanSerial($serial);
|
// required parameters
|
||||||
$warr = $em->getRepository(Warranty::class)->findOneBy(['serial' => $clean_serial]);
|
$params = [
|
||||||
|
'serial',
|
||||||
|
];
|
||||||
|
$msg = $this->checkRequiredParameters($req, $params);
|
||||||
|
if ($msg)
|
||||||
|
return new APIResponse(false, $msg);
|
||||||
|
|
||||||
// no warranty
|
// no warranty
|
||||||
|
$warr = $em->getRepository(Warranty::class)->find($id);
|
||||||
if ($warr == null)
|
if ($warr == null)
|
||||||
return new APIResponse(false, 'No warranty found with that serial number.', null, 404);
|
return new APIResponse(false, 'No warranty found with that id.', null, 404);
|
||||||
|
|
||||||
// warranty is not active
|
// warranty is not active
|
||||||
if (!$warr->canClaim())
|
if (!$warr->canClaim())
|
||||||
return new APIResponse(false, 'Warranty is not active.');
|
return new APIResponse(false, 'Warranty is not active.');
|
||||||
|
|
||||||
|
|
||||||
|
// check if new serial has been used
|
||||||
|
$serial = $req->request->get('serial');
|
||||||
|
$clean_serial = $this->cleanSerial($serial);
|
||||||
|
$check_warr = $em->getRepository(Warranty::class)->findOneBy(['serial' => $clean_serial]);
|
||||||
|
if ($check_warr != null)
|
||||||
|
return new APIResponse(false, 'Serial for replacement has already been used.');
|
||||||
|
|
||||||
// set status to claim
|
// set status to claim
|
||||||
$warr->setStatus(WarrantyStatus::CLAIMED)
|
$warr->setStatus(WarrantyStatus::CLAIMED)
|
||||||
->setDateClaim(new DateTime());
|
->setDateClaim(new DateTime());
|
||||||
|
|
||||||
|
// make replacement warranty
|
||||||
|
$new_warr = new Warranty();
|
||||||
|
$new_warr->setSerial($clean_serial)
|
||||||
|
->setWarrantyClass($warr->getWarrantyClass())
|
||||||
|
->setPlateNumber($warr->getPlateNumber())
|
||||||
|
->setBatteryModel($warr->getBatteryModel())
|
||||||
|
->setBatterySize($warr->getBatterySize())
|
||||||
|
->setDatePurchase($warr->getDatePurchase())
|
||||||
|
->setDateClaim(null)
|
||||||
|
->setDateExpire($warr->getDateExpire())
|
||||||
|
->setClaimedFrom($warr);
|
||||||
|
|
||||||
|
$em->persist($new_warr);
|
||||||
|
|
||||||
|
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
// TODO: claim log
|
// TODO: claim log
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,13 @@ class Warranty
|
||||||
*/
|
*/
|
||||||
protected $date_claim;
|
protected $date_claim;
|
||||||
|
|
||||||
|
// claimed from
|
||||||
|
/**
|
||||||
|
* @ORM\OneToOne(targetEntity="Warranty")
|
||||||
|
* @ORM\JoinColumn(name="claim_id", referencedColumnName="id", nullable=true)
|
||||||
|
*/
|
||||||
|
protected $claim_from;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->date_create = new DateTime();
|
$this->date_create = new DateTime();
|
||||||
|
|
@ -250,8 +257,19 @@ class Warranty
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if ($this->status == WarrantyStatus::CLAIMED)
|
if ($this->status == WarrantyStatus::CLAIMED)
|
||||||
return true;
|
return false;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setClaimedFrom($claim_from)
|
||||||
|
{
|
||||||
|
$this->claim_form = $claim_from;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getClaimedFrom()
|
||||||
|
{
|
||||||
|
return $this->claim_from;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue