SHARE
TWEET

Untitled

a guest Jun 18th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class ItemModel extends CI_Model {
  2.  
  3.     public function itemList () {
  4.  
  5.     return $this->db->select("items.*, supplier.name as supplier_name")
  6.                     ->from("items")
  7.                     ->join("supplier", "supplier.id = items.supplier_id", "both")
  8.                     ->get()
  9.                     ->result();
  10.  
  11.     }
  12.  
  13.  
  14.     public function deleteItem($id) {
  15.         $id = $this->security->xss_clean($id);
  16.         $this->db->trans_start();
  17.         $this->db->where('item_id', $id)->delete('ordering_level');
  18.         $this->db->where('item_id', $id)->delete('prices');
  19.         $this->db->where('id', $id)->delete('items');
  20.  
  21.         if ($this->db->trans_status() === FALSE) {
  22.             $this->db->trans_rollback();
  23.             return false;
  24.         }
  25.  
  26.         return $this->db->trans_commit();
  27.  
  28.     }
  29.  
  30.     public function getDetails($id) {
  31.         $id = $this->security->xss_clean($id);
  32.         return $this->db->where('id', $id)->get('items')->row();
  33.     }
  34.  
  35.     public function item_info($id) {
  36.         $id = $this->security->xss_clean($id);
  37.         $sql = $this->db->where('id', $id)->get('items');
  38.         return $sql->row();
  39.  
  40.     }
  41.  
  42.     public function update_item($id,$name,$category,$description,$price_id, $image, $supplier_id) {
  43.  
  44.        $item = $this->db->where('id',$id)->get('items')->row();
  45.  
  46.        $data = array(
  47.             'name' => $name,
  48.             'category_id' => $category,
  49.             'description' => $description,
  50.             'supplier_id' => $supplier_id
  51.             );
  52.         $data = $this->security->xss_clean($data);
  53.             if ($image != '')
  54.             $data['image'] = $image;
  55.  
  56.         return $this->db->where('id',$id)->update('items',$data);
  57.     }
  58.  
  59.     public function get_all_item() {
  60.         $items = $this->db->select('name')->get('items');
  61.         return $items->result_array();
  62.     }
  63.  
  64.     public function total() {
  65.         return $this->db->select("SUM(prices.price * ordering_level.quantity) as total")
  66.                     ->from("items")
  67.                     ->join("prices", "prices.item_id = items.id", "both")
  68.                     ->join("ordering_level", "ordering_level.item_id = items.id", "both")
  69.                     ->get()
  70.                     ->row();
  71.     }
  72.  
  73. }
  74.      
  75. class ItemController extends CI_Controller {
  76.  
  77.  
  78.  
  79.         $datasets = array_map(function($item) {
  80.         $itemPrice = $this->PriceModel->getPrice($item->id);
  81.         $itemCapital = $this->PriceModel->getCapital($item->id);
  82.         $stocksRemaining = $this->OrderingLevelModel->getQuantity($item->id)->quantity ?? 0;
  83.         $itemSupplier = $this->db->where('id', $item->supplier_id)->get('supplier')->row()->name ?? '';
  84.  
  85.     return [
  86.         $this->disPlayItemImage($item->image), //line 137
  87.                 $item->name,
  88.         $this->categories_model->getName($item >category_id),
  89.                 '₱' . number_format($itemCapital),
  90.                 '₱' . number_format($itemPrice),
  91.                 $stocksRemaining . ' pcs',
  92.                 $item->name,
  93.                 $itemSupplier,
  94.                ];
  95.  
  96.         }, $items);
  97.  
  98.         echo json_encode([
  99.             'draw' => $this->input->post('draw'),
  100.             'recordsTotal' => count($datasets),
  101.             'recordsFiltered' => count($datasets),
  102.             'data' => $datasets
  103.         ]);
  104.     }
  105.      
  106. <div class="panel-heading">
  107.          Items List
  108.  
  109.      </div>
  110.  
  111.      <!-- /.panel-heading -->
  112.      <div class="panel-body">
  113.          <table class="table table-responsive table-hover table-bordered" id="item_tbl">
  114.            <thead>
  115.             <tr>
  116.                 <th width="8%">&nbsp;</th>
  117.                 <th width="20%">Item Name</th>
  118.                 <th width="10%">Category</th>
  119.                 <th width="11%">Capital Per/Item</th>
  120.                 <th width="11%">Retail Price</th>
  121.                 <th width="10%">Stocks</th>
  122.                 <th width="10%">Total</th>
  123.                 <th width="10%">Supplier</th>
  124.                 <th width="10%">Action</th>
  125.             </tr>
  126.         </thead>
  127.         <tbody>
  128.  
  129.  
  130.         </tbody>
  131.     </table>
  132. </div>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top