Add jo history api call and fix estimate and request jo to use new criteria system #104
This commit is contained in:
parent
4ca630659b
commit
bb3ac8ecd4
2 changed files with 110 additions and 2 deletions
|
|
@ -94,3 +94,8 @@ api_jo_cancel:
|
|||
path: /api/job_order/cancel
|
||||
controller: App\Controller\APIController:cancelJobOrder
|
||||
methods: [POST]
|
||||
|
||||
api_jo_history:
|
||||
path: /api/job_order/history
|
||||
controller: App\Controller\APIController:getJOHistory
|
||||
methods: [GET]
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ use App\Ramcar\ServiceType;
|
|||
use App\Ramcar\WarrantyClass;
|
||||
use App\Ramcar\APIRiderStatus;
|
||||
use App\Ramcar\TransactionOrigin;
|
||||
use App\Ramcar\TradeInType;
|
||||
|
||||
use App\Service\InvoiceCreator;
|
||||
|
||||
|
|
@ -781,10 +782,26 @@ class APIController extends Controller
|
|||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
/*
|
||||
// put battery in criteria
|
||||
$icrit->addBattery($batt);
|
||||
*/
|
||||
|
||||
// TODO: check trade-in
|
||||
// check trade-in
|
||||
// only allow motolite, other, none
|
||||
$trade_in = $req->request->get('trade_in');
|
||||
switch ($trade_in)
|
||||
{
|
||||
case TradeInType::MOTOLITE:
|
||||
case TradeInType::OTHER:
|
||||
break;
|
||||
|
||||
default:
|
||||
$trade_in = '';
|
||||
break;
|
||||
}
|
||||
|
||||
$icrit->addEntry($batt, $trade_in, 1);
|
||||
|
||||
// send to invoice generator
|
||||
$invoice = $ic->processCriteria($icrit);
|
||||
|
|
@ -831,6 +848,7 @@ class APIController extends Controller
|
|||
{
|
||||
// check required parameters and api key
|
||||
$required_params = [
|
||||
'stype_id',
|
||||
'cv_id',
|
||||
'batt_id',
|
||||
'trade_in',
|
||||
|
|
@ -851,6 +869,7 @@ class APIController extends Controller
|
|||
|
||||
// make invoice criteria
|
||||
$icrit = new InvoiceCriteria();
|
||||
$icrit->setServiceType($req->request->get('stype_id'));
|
||||
|
||||
// check promo
|
||||
$promo_id = $req->request->get('promo_id');
|
||||
|
|
@ -894,10 +913,26 @@ class APIController extends Controller
|
|||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
/*
|
||||
// put battery in criteria
|
||||
$icrit->addBattery($batt);
|
||||
*/
|
||||
|
||||
// TODO: check trade-in
|
||||
// check trade-in
|
||||
// only allow motolite, other, none
|
||||
$trade_in = $req->request->get('trade_in');
|
||||
switch ($trade_in)
|
||||
{
|
||||
case TradeInType::MOTOLITE:
|
||||
case TradeInType::OTHER:
|
||||
break;
|
||||
|
||||
default:
|
||||
$trade_in = '';
|
||||
break;
|
||||
}
|
||||
|
||||
$icrit->addEntry($batt, $trade_in, 1);
|
||||
|
||||
// send to invoice generator
|
||||
$invoice = $ic->processCriteria($icrit);
|
||||
|
|
@ -1187,4 +1222,72 @@ class APIController extends Controller
|
|||
|
||||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
public function getJOHistory(Request $req)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$res = $this->checkParamsAndKey($req, $em, []);
|
||||
if ($res->isError())
|
||||
return $res->getReturnResponse();
|
||||
|
||||
// get customer
|
||||
$cust = $this->session->getCustomer();
|
||||
if ($cust == null)
|
||||
{
|
||||
$res->setError(true)
|
||||
->setErrorMessage('No customer information found');
|
||||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
// get job orders
|
||||
$all_jo_data = [];
|
||||
$jos = $cust->getJobOrders();
|
||||
foreach ($jos as $jo)
|
||||
{
|
||||
$status = $jo->getStatus();
|
||||
|
||||
$jo_data = [
|
||||
'id' => $jo->getID(),
|
||||
'date_create' => $jo->getDateCreate()->format('M d, Y'),
|
||||
'service_type' => $jo->getServiceType(),
|
||||
'status' => $status,
|
||||
];
|
||||
|
||||
// invoice items
|
||||
$items = [];
|
||||
$jo_items = $jo->getInvoice()->getItems();
|
||||
foreach ($jo_items as $item)
|
||||
{
|
||||
$items[] = [
|
||||
'id' => $item->getID(),
|
||||
'title' => $item->getTitle(),
|
||||
'qty' => $item->getQuantity(),
|
||||
'price' => $item->getPrice(),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
// dates depending on status
|
||||
switch ($status)
|
||||
{
|
||||
case JOStatus::FULFILLED:
|
||||
$jo_data['date_fulfilled'] = $jo->getDateFulfilled()->format('M d, Y');
|
||||
break;
|
||||
case JOStatus::CANCELLED:
|
||||
$jo_data['date_cancelled'] = $jo->getDateCancelled()->format('M d, Y');
|
||||
break;
|
||||
}
|
||||
|
||||
$all_jo_data[] = $jo_data;
|
||||
}
|
||||
|
||||
// return data
|
||||
$data = [
|
||||
'job_orders' => $all_jo_data
|
||||
];
|
||||
$res->setData($data);
|
||||
|
||||
// response
|
||||
return $res->getReturnResponse();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue