-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtility_model.php
More file actions
171 lines (151 loc) · 4.59 KB
/
Utility_model.php
File metadata and controls
171 lines (151 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Utility_model extends CI_Model {
//update
public function update_ci($table,$dataToUpdate,$whereClause){
$this->db->where($whereClause);
return $this->db->update($table, $dataToUpdate);
}
// insert
public function insert_ci($table, $data){
$this->db->insert($table, $data);
return $insert_id = $this->db->insert_id();
}
//Delete
public function delete_ci($table,$whereClause){
return $this->db->delete($table,$whereClause);
}
// Fetching Process
public function getRows($table,$conditions = array()){
if(array_key_exists("col",$conditions)){
$this->db->select($conditions['col']);
}
if(array_key_exists("group_by",$conditions)){
$this->db->group_by($conditions['group_by']);
}
if(array_key_exists("where",$conditions)){
$this->db->where($conditions['where']);
}
if(array_key_exists("order_by",$conditions)){
$this->db->order_by($conditions['order_by']);
}
if(array_key_exists("start",$conditions) && array_key_exists("limit",$conditions)){
$this->db->limit($conditions['limit'], $conditions['start']);
}elseif(!array_key_exists("start",$conditions) && array_key_exists("limit",$conditions)){
$this->db->limit($conditions['limit']);
}
if(array_key_exists("return_type",$conditions) && $conditions['return_type'] != 'all'){
switch($conditions['return_type']){
case 'count':
return $this->db->count_all_results($table);
break;
case 'single':
$query = $this->db->get($table);
return $query->row_array();
break;
default:
$data = '';
}
}else{
$query = $this->db->get($table);
if ($query->num_rows() > 0){
return $query->result_array();
}else{
return false;
}
}
}
// Custom Query
public function custom_query($query){
$query_res = $this->db->query($query);
if ($query_res->num_rows() > 0){
return $query_res->result_array();
}
else{
return false;
}
}
public function users()
{
$this->db->select('a.id, a.email, gs.name');
$this->db->from('users a');
$this->db->join('users_groups g', 'g.user_id = a.id', 'left');
$this->db->join('groups gs', 'gs.id = g.group_id', 'left');
$this->db->where('a.comp_id', $this->session->userdata('comp_id') );
$query = $this->db->get();
if($query->num_rows() != 0)
{
return $query->result_array();
}
else
{
return false;
}
}
// fetch item
// fetch item
public function order($id ,$conditions = array())
{
$this->db->select('a.id, a.user_id , a.origin, a.destination, a.consinNo, a.consigName, a.consigAdd, a.consigCont, a.consigEmail, a.piece, a.weight, a.costumer_ref, a.cash_collection, a.cash_status, a.product_detail,a.type,a.isfragile,a.remarks,a.status,a.date,
p.id as paymentid,
p.amount as paymentamount,
p.charges as paymentcharges,
p.date as paymentdate,
p.status as paymentstatus,
u.bus_name as UserbusName,
u.phone as Userphone,
u.email as Useremail,
');
$this->db->from('orders a');
$this->db->join('order_payment p', 'p.order_id = a.id', 'left');
$this->db->join('users u', 'u.id = a.user_id', 'left');
// $this->db->join('units u', 'u.id = a.Unit', 'left');
$this->db->where('a.id', $id );
if(array_key_exists("where",$conditions)){
$this->db->where($conditions['where']);
}
if(array_key_exists("order_by",$conditions)){
$this->db->order_by($conditions['order_by']);
}
if(array_key_exists("start",$conditions) && array_key_exists("limit",$conditions)){
$this->db->limit($conditions['limit'], $conditions['start']);
}elseif(!array_key_exists("start",$conditions) && array_key_exists("limit",$conditions)){
$this->db->limit($conditions['limit']);
}
if(array_key_exists("return_type",$conditions) && $conditions['return_type'] != 'all'){
switch($conditions['return_type']){
case 'count':
return $this->db->count_all_results($table);
break;
case 'single':
$query = $this->db->get();
return $query->row_array();
break;
default:
$data = '';
}
}else{
$query = $this->db->get();
if ($query->num_rows() > 0){
return $query->result_array();
}else{
return false;
}
}
}
public function getstatus($value='')
{
$this->db->select('s.status , s.date , s.type');
$this->db->from('orders a');
$this->db->join('order_status s', 's.order_id = a.id', 'right');
$this->db->where('a.consinNo', $value);
$query = $this->db->get();
if($query->num_rows() != 0){
return $query->result_array();
}else{
return false;
}
}
}
/* End of file Utility_model.php */
/* Location: ./application/models/Utility_model.php */