From e301012a8d96a5830d437980b8679b07363ac19b Mon Sep 17 00:00:00 2001 From: paulcortez Date: Thu, 5 Dec 2024 15:41:20 +0800 Subject: [PATCH] added API for itemcode added API for itemcode --- application/config/routes.php | 1 + .../api/StoreFrontAPIController.php | 62 ++++++++++++++++++- application/models/Items.php | 6 ++ 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/application/config/routes.php b/application/config/routes.php index eb14bce..f7eb04f 100644 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -54,6 +54,7 @@ $route['exec/(:any)'] = 'executive_view/$1'; $route['api/sf'] = 'api/StoreFrontAPIController/index'; $route['api/sfmodel/(:any)'] = 'api/StoreFrontAPIController/itemModel/$1'; +$route['api/sficode/(:any)'] = 'api/StoreFrontAPIController/itemCode/$1'; $route['(:any)'] = 'pages/$1'; $route['default_controller'] = 'pages/dashboard'; diff --git a/application/controllers/api/StoreFrontAPIController.php b/application/controllers/api/StoreFrontAPIController.php index 9342f2f..d17e03d 100644 --- a/application/controllers/api/StoreFrontAPIController.php +++ b/application/controllers/api/StoreFrontAPIController.php @@ -25,10 +25,68 @@ class StoreFrontAPIController extends RestController $this->load->model("Items"); $this->load->model("BranchItemLedger"); - $row = $this->Items->getItemByModelNo('DB-422'); + // testing mode + //$row = $this->Items->getItemByModelNo('DB-422'); // disabled during testing - //$result = $this->Items->getItemByModelNo($modelno); + $row = $this->Items->getItemByModelNo($modelno); + + if($row != null) + { + $branches = []; + + $resultBranches = $this->BranchItemLedger->getDataByItemcodeWithBranchExcempt($row->itemcode); + + foreach($resultBranches->result() as $rowBranches ) + { + $branches[] = [ + 'itemcode' => $rowBranches->itemcode, + 'brCode' => $rowBranches->brCode, + 'endingqty' => $rowBranches->endingqty + ]; + } + + $item = [ + 'itemcode' => $row->itemcode, + 'modelno' => $row->modelno, + 'seriescode' => $row->seriescode, + 'item_desc' => $row->item_desc, + 'karat' => $row->karat, + 'size' => $row->size, + 'grams' => $row->grams, + 'cts' => $row->cts, + 'srp' => $row->srp, + //'mrp' => $row->mrp, + 'mrp' => '0', + 'pic' => '', + 'catCode' => $row->catCode, + 'goldID' => $row->goldID, + 'supCode' => $row->supCode, + 'modifieddate' => $row->modifieddate, + 'others' => '', + 'remarks' => '', + 'branches' => $branches + ]; + + $data = ['status' => 'FOUND', + 'data' => $item]; + } + else + $data = ['status' => 'NOTFOUND', + 'data' => null]; + + $this->response($data, 200); + } + + public function itemCode_get($itemcode) { + + $this->load->model("Items"); + $this->load->model("BranchItemLedger"); + + //$row = $this->Items->getItemByItemcode(1093218); + + // disabled during testing + $row = $this->Items->getItemByItemcode($itemcode); if($row != null) { diff --git a/application/models/Items.php b/application/models/Items.php index 950f9d2..a8eb060 100644 --- a/application/models/Items.php +++ b/application/models/Items.php @@ -41,6 +41,12 @@ class Items extends CI_Model return $result->row(); } + public function getItemByItemcode($itemcode) + { + $result = $this->db->get_where("items", array("itemcode"=>$itemcode)); + return $result->row(); + } + public function getItemBySeriesNo($series) { $result = $this->db->get_where("items", array("seriescode"=>$series));