-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomplaint_demo.php
260 lines (244 loc) · 12.5 KB
/
complaint_demo.php
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<?php
include "header.php";
setcookie("editId", "", time() - 3600);
setcookie("viewId", "", time() - 3600);
if (isset($_REQUEST["flg"]) && $_REQUEST["flg"] == "del") {
try {
$stmt_del = $obj->con1->prepare(
"delete from customer_reg where id='" . $_REQUEST["n_complaintid"] . "'"
);
$Resp = $stmt_del->execute();
if (!$Resp) {
if (strtok($obj->con1->error, ":") == "Cannot delete or update a parent row") {
throw new Exception("City is already in use!");
}
}
$stmt_del->close();
} catch (\Exception $e) {
setcookie("sql_error", urlencode($e->getMessage()), time() + 3600, "/");
}
if ($Resp) {
setcookie("msg", "data_del", time() + 3600, "/");
}
header("location:complaint_demo.php");
}
?>
<div class='p-6' x-data='exportTable'>
<div class="panel mt-2">
<div class='flex items-center justify-between mb-3'>
<h1 class='text-primary text-2xl font-semibold'>Complaint / Demo</h1>
<div class="flex gap-5 items-center mt-3">
<div class="">
<label class="flex items-center cursor-pointer">
<input type="checkbox" class="form-checkbox" checked />
<span class>New</span>
</label>
</div>
<div class="">
<label class="flex items-center cursor-pointer">
<input type="checkbox" class="form-checkbox" />
<span class>Pending</span>
</label>
</div>
<div class="">
<label class="flex items-center cursor-pointer">
<input type="checkbox" class="form-checkbox" />
<span class>Allocated</span>
</label>
</div>
<div class="">
<label class="flex items-center cursor-pointer">
<input type="checkbox" class="form-checkbox" />
<span class>Closed</span>
</label>
</div>
<div class="">
<label class="flex items-center cursor-pointer">
<input type="checkbox" class="form-checkbox" />
<span class>Cancelled</span>
</label>
</div>
</div>
<div class="flex flex-wrap items-center">
<button type="button" class="p-2 btn btn-primary btn-sm m-1"
onclick="location.href='add_complaint_demo.php'">
<i class="ri-add-line mr-1"></i> Add Complaint
</button>
<button type="button" class="p-2 btn btn-primary btn-sm m-1" @click="printTable">
<i class="ri-printer-line mr-1"></i> PRINT
</button>
<button type="button" class="p-2 btn btn-primary btn-sm m-1" @click="exportTable('csv')">
<i class="ri-file-line mr-1"></i> CSV
</button>
</div>
</div>
<table id="myTable" class="table-hover whitespace-nowrap"></table>
</div>
</div>
<!-- script -->
<script>
function getActions(id, number) {
return `<ul class="flex items-center justify-center gap-4">
<li>
<a href="javascript:viewRecord(${id}, 'add_complaint_demo.php')" class='text-xl' x-tooltip="View">
<i class="ri-eye-line text-primary"></i>
</a>
</li>
<li>
<a href="javascript:updateRecord(${id}, 'add_complaint_demo.php')" class='text-xl' x-tooltip="Edit">
<i class="ri-pencil-line text text-success"></i>
</a>
</li>
<li>
<a href="javascript:;" class='text-xl' x-tooltip="Delete" @click="showAlert(${id}, '${number}')">
<i class="ri-delete-bin-line text-danger"></i>
</a>
</li>
</ul>`
}
document.addEventListener('alpine:init', () => {
Alpine.data('exportTable', () => ({
datatable: null,
init() {
console.log('Initalizing datatable')
this.datatable = new simpleDatatables.DataTable('#myTable', {
data: {
headings: ['Sr.No.', 'Complaint No.', 'Customer name', 'Contact',
'Pincode',
'Service Type', 'Product Category', 'Date Time',
'Warranty-Status', 'Call Status', 'Source', 'Action'
],
data: [
<?php
if (isset($_SESSION['type_center']) && $_SESSION['type_center']) {
$city_id = $_SESSION['sc_city'];
$stmt = $obj->con1->prepare("SELECT c1.*, ca.status, s1.name AS service_type, p1.name AS product_category, CONCAT(c1.fname, ' ', c1.lname) AS customer_name, CONCAT(c1.date, ' ', c1.time) AS datetime FROM customer_reg c1, service_type s1, product_category p1, call_allocation ca WHERE c1.warranty!=2 AND c1.service_type!=16 AND c1.service_type=s1.id AND c1.complaint_no=ca.complaint_no AND c1.product_category=p1.id AND c1.area=? order by c1.id DESC");
$stmt->bind_param("i", $city_id);
$stmt->execute();
$Resp = $stmt->get_result();
$stmt->close();
$id = 1;
} else {
$stmt = $obj->con1->prepare("SELECT c1.*, ca.status, s1.name AS service_type, p1.name AS product_category, CONCAT(c1.fname, ' ', c1.lname) AS customer_name, CONCAT(c1.date, ' ', c1.time) AS datetime FROM customer_reg c1, service_type s1, product_category p1, call_allocation ca WHERE c1.warranty!=2 AND c1.service_type!=16 AND c1.service_type=s1.id and c1.complaint_no=ca.complaint_no AND c1.product_category=p1.id ORDER BY c1.id DESC");
$stmt->execute();
$Resp = $stmt->get_result();
$id = 1;
}
while ($row = mysqli_fetch_array($Resp)) {
?>[
<?php echo $id ?>,
'<?php echo $row['complaint_no'] ?>',
'<?php echo $row['customer_name'] ?>',
'<?php echo $row['contact'] ?>',
'<?php echo $row['zipcode'] ?>',
'<?php echo $row['service_type'] ?>',
'<?php echo $row['product_category'] ?>',
'<?php
$date = date_create($row['datetime']);
echo date_format($date, "d-m-Y h:i A");
?>',
`<span class="badge badge-outline-<?php echo $row['warranty'] == 1 ? 'success' : ($row['warranty'] == 3 ? 'secondary' : 'danger') ?>">
<?php echo $row['warranty'] == 1 ? 'In-Warranty' : ($row['warranty'] == 3 ? 'N / A' : 'Out-of-Warranty') ?>
</span>`,
`<span class="badge badge-outline-<?php
switch ($row["status"]) {
case 'new':
echo 'secondary';
break;
case 'allocated':
echo 'warning';
break;
case 'closed':
echo 'success';
break;
case 'cancelled':
echo 'danger';
break;
case 'pending':
echo 'dark';
break;
default:
echo 'primary';
break;
}
?>">
<?php echo ucfirst($row['status']) ?>
</span>`,
`<span class="badge badge-outline-<?php echo $row['source'] == 'web' ? 'secondary' : 'danger' ?>">
<?php echo ucfirst($row['source']) ?>
</span>`,
getActions('<?php echo $row['id'] ?>',
'<?php echo $row['complaint_no'] ?>')
],
<?php
$id++;
}
?>
],
},
perPage: 10,
perPageSelect: [10, 20, 30, 50, 100],
columns: [{
select: 0,
sort: 'asc',
}, ],
firstLast: true,
firstText: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" class="w-4.5 h-4.5 rtl:rotate-180"> <path d="M13 19L7 12L13 5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> <path opacity="0.5" d="M16.9998 19L10.9998 12L16.9998 5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> </svg>',
lastText: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" class="w-4.5 h-4.5 rtl:rotate-180"> <path d="M11 19L17 12L11 5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> <path opacity="0.5" d="M6.99976 19L12.9998 12L6.99976 5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> </svg>',
prevText: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" class="w-4.5 h-4.5 rtl:rotate-180"> <path d="M15 5L9 12L15 19" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> </svg>',
nextText: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" class="w-4.5 h-4.5 rtl:rotate-180"> <path d="M9 5L15 12L9 19" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> </svg>',
labels: {
perPage: '{select}',
},
layout: {
top: '{search}',
bottom: '{info}{select}{pager}',
},
});
},
exportTable(eType) {
var data = {
type: eType,
filename: 'complaint_demo',
download: true,
};
if (data.type === 'csv') {
data.lineDelimiter = '\n';
data.columnDelimiter = ';';
}
this.datatable.export(data);
},
printTable() {
this.datatable.print();
},
formatDate(date) {
if (date) {
const dt = new Date(date);
const month = dt.getMonth() + 1 < 10 ? '0' + (dt.getMonth() + 1) : dt.getMonth() +
1;
const day = dt.getDate() < 10 ? '0' + dt.getDate() : dt.getDate();
return day + '/' + month + '/' + dt.getFullYear();
}
return '';
},
}));
})
function showAlert(id, number) {
new window.Swal({
title: 'Are you sure?',
text: `You want to delete Call :- ${number}!`,
showCancelButton: true,
confirmButtonText: 'Delete',
padding: '2em',
}).then((result) => {
console.log(result)
if (result.isConfirmed) {
var loc = "complaint_demo.php?flg=del&n_complaintid=" + id;
window.location = loc;
}
});
}
</script>
<?php
include "footer.php";
?>