From 01a4ab6e93e56694c99711955efaf796e241c370 Mon Sep 17 00:00:00 2001 From: paulcortez Date: Sat, 24 Aug 2024 15:19:52 +0800 Subject: [PATCH] search by series and desc Added search by series and description to dashboard --- application/controllers/Pages.php | 95 ++++++++++++++++---- application/models/ItemLedger.php | 35 ++++++++ application/models/Items.php | 6 ++ application/views/pages/dashboard.php | 122 ++++++++++++++++++++++++-- application/views/pages/leftnav.php | 2 +- 5 files changed, 231 insertions(+), 29 deletions(-) diff --git a/application/controllers/Pages.php b/application/controllers/Pages.php index 656f9e7..c05845f 100644 --- a/application/controllers/Pages.php +++ b/application/controllers/Pages.php @@ -1319,7 +1319,7 @@ class Pages extends CI_controller * Store Item Inquiry Methods */ - public function getItemInfo() + public function getItemInfoByModelNo() { if(!$this->isLogged()) redirect('login', 'refresh'); @@ -1331,35 +1331,92 @@ class Pages extends CI_controller $this->load->model("StockReceivingView"); $result = $this->Items->getItemInfoByModelNo($this->input->post("modelno")); - $row = $result->row(); + + if($result->num_rows() > 0) + { + $row = $result->row(); + + $resultBranches = $this->BranchItemLedger->getDataByItemcodeWithBranchExcempt($row->itemcode); + + $kwhRow = $this->ItemLedger->getItemLedgerOfKWHByItemcode($row->itemcode); + //$kwhRow = $resultKWH->row(); + + $resultKWHStockReceived = $this->StockReceivingView->getDtlDataByItemcode($row->itemcode); + $kwhStockReceivedRow = $resultKWHStockReceived->row(); + + // Log searched item + $this->ItemInquiryLog->itemcode = $row->itemcode; + $this->ItemInquiryLog->modelno = $row->modelno; + $this->ItemInquiryLog->catCode = $row->catCode; + $this->ItemInquiryLog->brCode = $this->session->user["branch"]; + $this->ItemInquiryLog->searchedBy = $this->session->user["username"]; + $this->ItemInquiryLog->dateSearched = date('m/d/Y'); + $this->ItemInquiryLog->addNewData(); + // --- END --- Log searched item + + $htmlTable = ""; + + foreach($resultBranches->result() as $rowBranches ) + { + $htmlTable .= "" . $rowBranches->itemcode . "" . $rowBranches->brCode . "" . $rowBranches->endingqty . ""; + } + + echo json_encode(array("success"=>true, "data" => $row, "htmlTable" => $htmlTable, "KWHData" => $kwhRow, "KWHStockReceived" => $kwhStockReceivedRow)); + } + else + echo json_encode(array("success"=>false, "data" => "No Record")); + } + + public function getItemInfoBySeries() + { + if(!$this->isLogged()) + redirect('login', 'refresh'); + + $this->load->model("ItemLedger"); - $resultBranches = $this->BranchItemLedger->getDataByItemcodeWithBranchExcempt($row->itemcode); + $result = $this->ItemLedger->getBranchesBySeriesCodeWithBranchExcempt($this->input->post("series"), false); + + $htmlTable = ""; - $kwhRow = $this->ItemLedger->getItemLedgerOfKWHByItemcode($row->itemcode); - //$kwhRow = $resultKWH->row(); + foreach($result->result() as $rowItems ) + { + $htmlTable .= "" . $rowItems->itemcode . + "" . $rowItems->modelno . + "" . $rowItems->seriescode . + "" . $rowItems->item_desc . + "" . $rowItems->brCode . + "" . $rowItems->endingqty . ""; + } - $resultKWHStockReceived = $this->StockReceivingView->getDtlDataByItemcode($row->itemcode); - $kwhStockReceivedRow = $resultKWHStockReceived->row(); + if($result->num_rows() > 0) + echo json_encode(array("success"=>true, "htmlTable" => $htmlTable)); + else + echo json_encode(array("success"=>false, "data" => "No Record")); + } - // Log searched item - $this->ItemInquiryLog->itemcode = $row->itemcode; - $this->ItemInquiryLog->modelno = $row->modelno; - $this->ItemInquiryLog->catCode = $row->catCode; - $this->ItemInquiryLog->brCode = $this->session->user["branch"]; - $this->ItemInquiryLog->searchedBy = $this->session->user["username"]; - $this->ItemInquiryLog->dateSearched = date('m/d/Y'); - $this->ItemInquiryLog->addNewData(); - // --- END --- Log searched item + public function getItemInfoByDescription() + { + if(!$this->isLogged()) + redirect('login', 'refresh'); + + $this->load->model("ItemLedger"); + $result = $this->ItemLedger->getBranchesByDescWithBranchExcempt($this->input->post("series"), false); + $htmlTable = ""; - foreach($resultBranches->result() as $rowBranches ) + foreach($result->result() as $rowItems ) { - $htmlTable .= "" . $rowBranches->itemcode . "" . $rowBranches->brCode . "" . $rowBranches->endingqty . ""; + $htmlTable .= "" . $rowItems->itemcode . + '' . $rowItems->modelno . + "" . $rowItems->seriescode . + "" . $rowItems->item_desc . + "" . $rowItems->brCode . + "" . $rowItems->endingqty . ""; } if($result->num_rows() > 0) - echo json_encode(array("success"=>true, "data" => $row, "htmlTable" => $htmlTable, "KWHData" => $kwhRow, "KWHStockReceived" => $kwhStockReceivedRow)); + echo json_encode(array("success"=>true, "htmlTable" => $htmlTable)); else echo json_encode(array("success"=>false, "data" => "No Record")); } diff --git a/application/models/ItemLedger.php b/application/models/ItemLedger.php index 3cc4bb3..3f7865b 100644 --- a/application/models/ItemLedger.php +++ b/application/models/ItemLedger.php @@ -26,6 +26,41 @@ class ItemLedger extends CI_Model return $this->db->get_where("itemledger", array("itemcode"=>$itemcode)); } + public function getBranchesBySeriesCode($seriescode, $includeKWH) + { + $this->db->select("itemledger.*, items.*"); + $this->db->from("itemledger"); + $this->db->join("items", "itemledger.itemcode = items.itemcode", "left"); + $this->db->where("items.seriescode", $seriescode); + if(!$includeKWH) $this->db->where("itemledger.brCode != 'KWH'"); // exclude KWH + $this->db->where("itemledger.endingqty > 0"); + return $this->db->get(); + } + + public function getBranchesBySeriesCodeWithBranchExcempt($seriescode, $includeKWH) + { + $this->db->select("itemledger.*, items.*"); + $this->db->from("itemledger"); + $this->db->join("items", "itemledger.itemcode = items.itemcode", "left"); + $this->db->where("items.seriescode", $seriescode); + $this->db->where("itemledger.endingqty > 0"); + if(!$includeKWH) $this->db->where("itemledger.brCode != 'KWH'"); // exclude KWH + $this->db->where("itemledger.brCode NOT IN (SELECT brCode FROM branchexemption)"); + return $this->db->get(); + } + + public function getBranchesByDescWithBranchExcempt($itemdesc, $includeKWH) + { + $this->db->select("itemledger.*, items.*"); + $this->db->from("itemledger"); + $this->db->join("items", "itemledger.itemcode = items.itemcode", "left"); + $this->db->like("items.item_desc", $itemdesc); + $this->db->where("itemledger.endingqty > 0"); + if(!$includeKWH) $this->db->where("itemledger.brCode != 'KWH'"); // exclude KWH + $this->db->where("itemledger.brCode NOT IN (SELECT brCode FROM branchexemption)"); + return $this->db->get(); + } + public function getItemLedgerOfKWHByItemcode($itemcode) { $result = $this->db->get_where("itemledger", array("itemcode"=>$itemcode, "brCode"=>"KWH")); diff --git a/application/models/Items.php b/application/models/Items.php index 218981d..950f9d2 100644 --- a/application/models/Items.php +++ b/application/models/Items.php @@ -40,4 +40,10 @@ class Items extends CI_Model $result = $this->db->get_where("items", array("modelno"=>$modelno)); return $result->row(); } + + public function getItemBySeriesNo($series) + { + $result = $this->db->get_where("items", array("seriescode"=>$series)); + return $result->row(); + } } \ No newline at end of file diff --git a/application/views/pages/dashboard.php b/application/views/pages/dashboard.php index 07bf545..f483458 100644 --- a/application/views/pages/dashboard.php +++ b/application/views/pages/dashboard.php @@ -157,17 +157,67 @@
-
-
- -
- + + '; } + + function showItemListFromInquiry(htmlTable) + { + return '
' + + '
' + + '

Item Information

' + + '
' + + ' ' + + '
' + + '
' + + '
' + + '

List of items that matches with the series code in the inquiry

' + + '
' + + '
' + + ' ' + + ' ' + + ' ' + htmlTable + '' + + '
ItemcodeModelSeriesDescriptionBranchQty
' + + '
' + + '
' + + '
' + + '
'; + } + function showIteminquiredInformation(data, htmlTable, KWHData, KWHStockReceived) { return '
' + @@ -393,10 +467,11 @@ }, "json"); }); + // ------- Item Search Area ------- $("#frmModelNoInquiry").on("submit", function(e) { e.preventDefault(); - $.post("getItemInfo", { + $.post("getItemInfoByModelNo", { modelno: $("#txtModelNoInquiry").val() }, function(data) { if (data["success"] == true) { @@ -407,6 +482,35 @@ }, "json"); }); + $("#frmSeriesNoInquiry").on("submit", function(e) { + e.preventDefault(); + + $.post("getItemInfoBySeries", { + series: $("#txtSeriesNoInquiry").val() + }, function(data) { + if (data["success"] == true) { + $("#resultContainerStoreInquiry").prepend(showItemListFromInquiry(data["htmlTable"])); + } else { + $("#resultContainerStoreInquiry").prepend(errorMessage(data["data"])); + } + }, "json"); + }); + + $("#frmDescriptionInquiry").on("submit", function(e) { + e.preventDefault(); + + $.post("getItemInfoByDescription", { + series: $("#txtDescriptionInquiry").val() + }, function(data) { + if (data["success"] == true) { + $("#resultContainerStoreInquiry").prepend(showItemListFromInquiry(data["htmlTable"])); + } else { + $("#resultContainerStoreInquiry").prepend(errorMessage(data["data"])); + } + }, "json"); + }); + // ------- /.Item Search Area ------- + $(document).on("click", "#btnRenewCard", function() { $("#mdlRenewCustomerCard").modal("show"); diff --git a/application/views/pages/leftnav.php b/application/views/pages/leftnav.php index 964708c..de42312 100644 --- a/application/views/pages/leftnav.php +++ b/application/views/pages/leftnav.php @@ -30,7 +30,7 @@
  • - Dashboard + Product Inquiry