Sindbad~EG File Manager

Current Path : /proc/self/cwd/application/models/
Upload File :
Current File : //proc/self/cwd/application/models/Promo.php

<?php
 
class Promo extends CI_Model {
    private $table = 'promo';

    public function getPromo($item_id) {
        // print($item_id);
        $current_date = date('Y-m-d H:i:s');
        $res = $this->db
            ->where(
                "condition_product_id = $item_id AND promo_start_date <= '$current_date' AND
                  promo_expire_date >= '$current_date' ")
            ->get($this->table);
            // print_r($res->result());
        $this->exists = 0;
        if ($res->num_rows()) {
            $this->exists = 1;
        }

        return $res->result();

    }

    public function exists($person_id)
    {
        $this->db->from($this->table);
        $this->db->where('promo.id', $promo_id);
 
        return ($this->db->get()->num_rows() == 1);
    }
    
    public function funtionName()
    {
 
    }
 
        /*
    Deletes one promos
    */
    public function delete($promo_id)
    {
        $this->db->where('promo_id', $promo_id);
 
        return $this->db->update($this->table, array('deleted' => 1));
    }
 
    /*
    Deletes a list of promos
    */
    public function delete_list($promo_ids)
    {
        $this->db->where_in('promo_id', $promo_ids);
 
        return $this->db->update($this->table, array('deleted' => 1));
    }

    public function checkTebusMurah(){
        $this->db
            ->where('promo_type', 'Purchase With Purchase')
            ->where('promo_tebus_murah_price !=', '')
            ->or_where('promo_tebus_murah_price !=', 0);
        return $this->db->get($this->table)->result();
    }

    public function addPromo($data) {
        $this->db->insert($this->table, $data);
        // print_r($this->db->last_query());
    }

    public function checkMemberDiscount($customer_id)
    {
        $current_date = date('Y-m-d H:i:s');
        $promo = $this->db->where('member_id', $customer_id)
            ->where("promo_start_date <=", $current_date)
            ->where('promo_expire_date >=', $current_date)
            ->where('promo_type', 'Member')
            ->where('is_active', 1)
            ->get($this->table);

        // print($this->db->last_query());

        // print($promo->num_rows());

        $this->num_rows = $promo->num_rows();

        return $promo->row();

    }

    public function get_data_promo()
    {
        $query = 
        "SELECT
        op.id,
        op.condition_product_id,
        op.promo_type,
        op.condition_min_purchase,
        op.promo_get_price_discount,
        op.promo_get_persentase_discount,
        op.promo_product_get_discount,
        op.promo_get_gift_product_id,
        op.promo_day,
        op.promo_time,
        op.promo_start_date,
        op.promo_expire_date,
        op.member_id,
        ot.item_id,
        op.is_active,
        op.tipe_diskon,
        ot.name AS produk_dibeli,
        (SELECT ot.name FROM ospos_items ot WHERE ot.item_id = op.promo_product_get_discount) AS barang_didapat,
        (SELECT ot.name FROM ospos_items ot WHERE ot.item_id = op.promo_get_gift_product_id) AS barang_hadiah
        FROM
        ospos_promo op, ospos_items ot
        WHERE
        op.is_deleted = 1 AND
        op.condition_product_id = ot.item_id ";  //u menampilkan promo
        return $this->db->query($query)->result(); //memanggil db result memnggil isi db dari tabel tsb
    }

    public function get_search_suggestions($search, $filters = array('is_deleted' => FALSE, 'search_custom' => FALSE), $unique = FALSE, $limit = 25)
    {
        $suggestions = array();
        $non_kit = array(ITEM, ITEM_AMOUNT_ENTRY);

        $this->db->select($this->get_search_suggestion_format('item_id, name, pack_name'));
        $this->db->from('items');
        $this->db->where('deleted', $filters['is_deleted']);
        $this->db->where_in('item_type', $non_kit); // standard, exclude kit items since kits will be picked up later
        $this->db->like('name', $search);
        $this->db->order_by('name', 'asc');
        foreach($this->db->get()->result() as $row)
        {
            $suggestions[] = array('value' => $row->item_id, 'label' => $this->get_search_suggestion_label($row));
        }

        $this->db->select($this->get_search_suggestion_format('item_id, item_number, pack_name'));
        $this->db->from('items');
        $this->db->where('deleted', $filters['is_deleted']);
        $this->db->where_in('item_type', $non_kit); // standard, exclude kit items since kits will be picked up later
        $this->db->like('item_number', $search);
        $this->db->order_by('item_number', 'asc');
        foreach($this->db->get()->result() as $row)
        {
            $suggestions[] = array('value' => $row->item_id, 'label' => $this->get_search_suggestion_label($row));
        }

        if(!$unique)
        {
            //Search by category
            $this->db->select('category');
            $this->db->from('items');
            $this->db->where('deleted', $filters['is_deleted']);
            $this->db->where_in('item_type', $non_kit); // standard, exclude kit items since kits will be picked up later
            $this->db->distinct();
            $this->db->like('category', $search);
            $this->db->order_by('category', 'asc');
            foreach($this->db->get()->result() as $row)
            {
                $suggestions[] = array('label' => $row->category);
            }

            //Search by supplier
            $this->db->select('company_name');
            $this->db->from('suppliers');
            $this->db->like('company_name', $search);
            // restrict to non deleted companies only if is_deleted is FALSE
            $this->db->where('deleted', $filters['is_deleted']);
            $this->db->where_in('item_type', $non_kit); // standard, exclude kit items since kits will be picked up later
            $this->db->distinct();
            $this->db->order_by('company_name', 'asc');
            foreach($this->db->get()->result() as $row)
            {
                $suggestions[] = array('label' => $row->company_name);
            }

            //Search by description
            $this->db->select($this->get_search_suggestion_format('item_id, name, pack_name, description'));
            $this->db->from('items');
            $this->db->where('deleted', $filters['is_deleted']);
            $this->db->where_in('item_type', $non_kit); // standard, exclude kit items since kits will be picked up later
            $this->db->like('description', $search);
            $this->db->order_by('description', 'asc');
            foreach($this->db->get()->result() as $row)
            {
                $entry = array('value' => $row->item_id, 'label' => $this->get_search_suggestion_label($row));
                if(!array_walk($suggestions, function($value, $label) use ($entry) { return $entry['label'] != $label; } ))
                {
                    $suggestions[] = $entry;
                }
            }

            //Search by custom fields
            if($filters['search_custom'] != FALSE)
            {
                $this->db->from('attribute_links');
                $this->db->join('attribute_links.attribute_id = attribute_values.attribute_id');
                $this->db->join('attribute_definitions', 'attribute_definitions.definition_id = attribute_links.definition_id');
                $this->db->like('attribute_value', $search);
                $this->db->where('definition_type', TEXT);
                $this->db->where('deleted', $filters['is_deleted']);
                $this->db->where_in('item_type', $non_kit); // standard, exclude kit items since kits will be picked up later
                foreach($this->db->get()->result() as $row)
                {
                    $suggestions[] = array('value' => $row->item_id, 'label' => get_search_suggestion_label($row));
                }
            }
        }

        //only return $limit suggestions
        if(count($suggestions) > $limit)
        {
            $suggestions = array_slice($suggestions, 0, $limit);
        }

        return array_unique($suggestions, SORT_REGULAR);
    }

    public function get_data_item()
    {
        $query = "SELECT * FROM ospos_items WHERE is_active = 1";
        return $this->db->query($query)->result();
    }

    public function hapus($id)
    {
        $data = array(
                'updated_at' => date('Y-m-d H:i:s'),
                'is_deleted' => 0
        );

        // echo "<pre>"; print_r($data); echo "</pre>";
        $this->db->where('id', $id);
        $this->db->update('ospos_promo', $data);
    }

    public function enable($id)
    {
        $data = array(
                'id' => $id,
                'updated_at' => date('Y-m-d H:i:s'),
                'is_active' => 1
        );

        // echo "<pre>"; print_r($data); echo "</pre>";
        $this->db->where('id', $id);
        $this->db->update('ospos_promo', $data);
    }

    public function disable($id)
    {
        $data = array(
                'id' => $id,
                'updated_at' => date('Y-m-d H:i:s'),
                'is_active' => 0
        );

        // echo "<pre>"; print_r($data); echo "</pre>";
        $this->db->where('id', $id);
        $this->db->update('ospos_promo', $data);
    }
}

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists