From 22c1fab15ca28aaa5e56ea4985d5aa8d08a7129d Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 2 Jun 2020 07:41:47 +0000 Subject: [PATCH] Add generateInvoice API call. #421 --- .../RiderAPIHandler/CMBRiderAPIHandler.php | 87 +++++++++++-------- 1 file changed, 50 insertions(+), 37 deletions(-) diff --git a/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php b/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php index 2e3bc064..39314fd9 100644 --- a/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php +++ b/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php @@ -1180,54 +1180,66 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface public function generateInvoice(Request $req) { $required_params = ['jo_id']; - $data = $this->checkJO($req, $required_params, $jo); + $data = $this->checkParamsAndKey($req, $required_params); if (isset($data['error'])) return $data; - $inv = $jo->getInvoice(); - $promo = $inv->getPromo(); + // get jo + $jo_id = $req->query->get('jo_id'); - // invoice items - $inv_items = []; - foreach ($inv->getItems() as $item) + $jo = $this->em->getRepository(JobOrder::class)->find($jo_id); + if ($jo == null) { - $item_batt = $item->getBattery(); - if ($item_batt == null) - $batt_id = null; - else - $batt_id = $item_batt->getID(); - - $inv_items[] = [ - 'id' => $item->getID(), - 'title' => $item->getTitle(), - 'qty' => $item->getQuantity(), - 'price' => $item->getPrice(), - 'batt_id' => $batt_id, - ]; - } - - // promo - if ($promo != null) - { - $promo_data = [ - 'id' => $promo->getID(), - 'name' => $promo->getName(), - 'code' => $promo->getCode(), - 'discount_rate' => $promo->getDiscountRate(), - 'discount_apply' => $promo->getDiscountApply(), + $data = [ + 'invoice' => null ]; } else { - $promo_data = null; - } + $inv = $jo->getInvoice(); + $promo = $inv->getPromo(); - $trade_in_type = $jo->getTradeInType(); - if (empty($trade_in_type)) - $trade_in_type = 'none'; + // invoice items + $inv_items = []; + foreach ($inv->getItems() as $item) + { + $item_batt = $item->getBattery(); + if ($item_batt == null) + $batt_id = null; + else + $batt_id = $item_batt->getID(); - $data = [ - 'invoice' => [ + $inv_items[] = [ + 'id' => $item->getID(), + 'title' => $item->getTitle(), + 'qty' => $item->getQuantity(), + 'price' => $item->getPrice(), + 'batt_id' => $batt_id, + ]; + } + + // promo + if ($promo != null) + { + $promo_data = [ + 'id' => $promo->getID(), + 'name' => $promo->getName(), + 'code' => $promo->getCode(), + 'discount_rate' => $promo->getDiscountRate(), + 'discount_apply' => $promo->getDiscountApply(), + ]; + } + else + { + $promo_data = null; + } + + $trade_in_type = $jo->getTradeInType(); + if (empty($trade_in_type)) + $trade_in_type = 'none'; + + $data = [ + 'invoice' => [ 'id' => $inv->getID(), 'discount' => $inv->getDiscount(), 'trade_in' => $inv->getTradeIn(), @@ -1238,6 +1250,7 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface 'promo' => $promo_data, ] ]; + } return $data; }