ok
Direktori : /home2/selectio/public_html/mm-tailor-billing/app/models/ |
Current File : /home2/selectio/public_html/mm-tailor-billing/app/models/Site.php |
<?php defined('BASEPATH') or exit('No direct script access allowed'); class Site extends CI_Model { public function __construct() { parent::__construct(); } public function getAllCategories() { $this->db->order_by('code'); $q = $this->db->get('categories'); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } public function getAllProductCategory() { $q = $this->db->get('categories'); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } // Extra Option Function Starts Here public function getAllExtraOption() { $q = $this->db->get('extra_option'); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return FALSE; } public function getExtraoptionCategory($category) { $q = $this->db->get_where('extra_option', ['category' => $category]); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } // Category Starts Here public function getAllMmCategory($category) { $q = $this->db->get_where('mm_categories', ['category' => $category]); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } // Category Ends Here public function getUnitsByIDD($id) { $q = $this->db->get_where('units', ['id' => $id]); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } // MM Category - Sub Category Starts Here public function getAllMmSubCategory($category) { $q = $this->db->get_where('mm_sub_categories', ['category_id' => $category]); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } public function getAllMmSubCategoryByID($id) { $q = $this->db->get_where('mm_sub_categories', ['id' => $id], 1); if ($q->num_rows() > 0) { return $q->row(); } return false; } // MM Category - Sub Category Ends Here public function getAllExtraoptioncategory($category) { $q = $this->db->get_where('extra_option', ['id' => $category], 1); if ($q->num_rows() > 0) { return $q->row(); } return false; } // Extra Option Function Ends Here // All Product Material Starts Here public function getAllServiceProducts() { $q = $this->db->get_where('products', ['type' => 'standard']); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } public function getAllProducts() { $q = $this->db->get_where('products'); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } // All Product Material Ends Here //Units Here public function getAllUnits() { $q = $this->db->get_where('units'); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } // MM Categories Starts Here public function getAllMMCategories() { $this->db->order_by('name'); $q = $this->db->get('mm_categories'); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } public function getMMCategoryByID($id) { $q = $this->db->get_where('mm_categories', ['id' => $id], 1); if ($q->num_rows() > 0) { return $q->row(); } return false; } public function getMMSubCategoryByID($id) { $q = $this->db->get_where('mm_sub_categories', ['id' => $id], 1); if ($q->num_rows() > 0) { return $q->row(); } return false; } // MM Categories Ends Here public function getAllCustomers() { $q = $this->db->get('customers'); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } public function getAllPrinters() { $this->db->order_by('title'); $q = $this->db->get('printers'); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } public function getAllStores() { $q = $this->db->get('stores'); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } public function getAllSuppliers() { $q = $this->db->get('suppliers'); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } public function getAllUsers() { $this->db->select("{$this->db->dbprefix('users')}.id as id, first_name, last_name, {$this->db->dbprefix('users')}.email, company, {$this->db->dbprefix('groups')}.name as group, active, {$this->db->dbprefix('stores')}.name as store, {$this->db->dbprefix('users')}.emp_role,{$this->db->dbprefix('users')}.categories, {$this->db->dbprefix('users')}.phone") ->join('groups', 'users.group_id=groups.id', 'left') ->join('stores', 'users.store_id=stores.id', 'left') ->group_by('users.id'); $q = $this->db->get('users'); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } public function getCategoryByCode($code) { $q = $this->db->get_where('categories', ['code' => $code], 1); if ($q->num_rows() > 0) { return $q->row(); } return false; } public function getCategoryByID($id) { $q = $this->db->get_where('categories', ['id' => $id], 1); if ($q->num_rows() > 0) { return $q->row(); } return false; } public function getUnitsByID($id) { $q = $this->db->get_where('units', ['id' => $id], 1); if ($q->num_rows() > 0) { return $q->row(); } return false; } public function getMaterialUsgaeByID($id) { $q = $this->db->get_where('material_usage', ['id' => $id], 1); if ($q->num_rows() > 0) { return $q->row(); } return false; } public function getCustomerByID($id) { $q = $this->db->get_where('customers', ['id' => $id], 1); if ($q->num_rows() > 0) { return $q->row(); } return false; } public function getGiftCard($no) { $q = $this->db->get_where('gift_cards', ['card_no' => $no], 1); if ($q->num_rows() > 0) { return $q->row(); } return false; } public function getGiftCardByID($id) { $q = $this->db->get_where('gift_cards', ['id' => $id], 1); if ($q->num_rows() > 0) { return $q->row(); } return false; } public function getPrinterByID($id) { $q = $this->db->get_where('printers', ['id' => $id], 1); if ($q->num_rows() > 0) { return $q->row(); } return false; } public function getProductByID($id, $store_id = null) { if (!$store_id) { $store_id = $this->session->userdata('store_id'); } $jpsq = "( SELECT product_id, quantity, price from {$this->db->dbprefix('product_store_qty')} WHERE store_id = " . ($store_id ? $store_id : "''") . ' ) AS PSQ'; $this->db->select("{$this->db->dbprefix('products')}.*, COALESCE(PSQ.quantity, 0) as quantity, COALESCE(PSQ.price, {$this->db->dbprefix('products')}.price) as store_price", false) ->join($jpsq, 'PSQ.product_id=products.id', 'left'); $q = $this->db->get_where('products', ['products.id' => $id], 1); if ($q->num_rows() > 0) { return $q->row(); } return false; } public function getQtyAlerts() { if (!$this->session->userdata('store_id')) { return 0; } $this->db->join("( SELECT (CASE WHEN quantity IS NULL THEN 0 ELSE quantity END) as quantity, product_id from {$this->db->dbprefix('product_store_qty')} WHERE store_id = {$this->session->userdata('store_id')} ) psq", 'products.id=psq.product_id', 'left') ->where("psq.quantity < {$this->db->dbprefix('products')}.alert_quantity", null, false) ->where('products.alert_quantity >', 0); return $this->db->count_all_results('products'); } public function getSettings() { $q = $this->db->get('settings'); if ($q->num_rows() > 0) { return $q->row(); } return false; } public function getStoreByID($id = null) { if (!$id) { return false; } $q = $this->db->get_where('stores', ['id' => $id], 1); if ($q->num_rows() > 0) { return $q->row(); } return false; } public function getUpcomingEvents() { $dt = date('Y-m-d'); $this->db->where('date >=', $dt)->order_by('date')->limit(5); if ($this->Settings->restrict_calendar) { $q = $this->db->get_where('calendar', ['user_id' => $this->session->userdata('iser_id')]); } else { $q = $this->db->get('calendar'); } if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } public function getUser($id = null) { if (!$id) { $id = $this->session->userdata('user_id'); } $q = $this->db->get_where('users', ['id' => $id], 1); if ($q->num_rows() > 0) { return $q->row(); } return false; } public function getUserGroup($user_id = null) { if ($group_id = $this->getUserGroupID($user_id)) { $q = $this->db->get_where('groups', ['id' => $group_id], 1); if ($q->num_rows() > 0) { return $q->row(); } } return false; } public function getUserGroupID($user_id = null) { if ($user = $this->getUser($user_id)) { return $user->group_id; } return false; } public function getUsers() { $q = $this->db->get('users'); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } public function getUserSuspenedSales() { $user_id = $this->session->userdata('user_id'); $this->db->select('id, date, customer_name, hold_ref') ->order_by('id desc'); //->limit(10); $this->db->where('store_id', $this->session->userdata('store_id')); $q = $this->db->get_where('suspended_sales', ['created_by' => $user_id]); if ($q->num_rows() > 0) { foreach (($q->result()) as $row) { $data[] = $row; } return $data; } return false; } public function registerData($user_id) { if (!$user_id) { $user_id = $this->session->userdata('user_id'); } $q = $this->db->get_where('registers', ['user_id' => $user_id, 'status' => 'open'], 1); if ($q->num_rows() > 0) { return $q->row(); } return false; } }