-
Notifications
You must be signed in to change notification settings - Fork 0
/
product_service.php
180 lines (170 loc) · 7.56 KB
/
product_service.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
<?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 product_service where srno='" .
$_REQUEST["n_pserviceid"] .
"'"
);
$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:product_service.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'>Product-Service</h1>
<div class="flex flex-wrap items-center">
<button type="button" class="p-2 btn btn-primary btn-sm m-1"
onclick="location.href='add_product_service.php'">
<i class="ri-add-line mr-1"></i> Add Product-Service
</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,product,service) {
return `<ul class="flex items-center gap-4">
<li>
<a href="javascript:viewRecord(${id}, 'add_product_service.php')" class='text-xl' x-tooltip="View">
<i class="ri-eye-line text-primary"></i>
</a>
</li>
<li>
<a href="javascript:updateRecord(${id}, 'add_product_service.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},'${product}','${service}')">
<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.', 'Product', 'Service', 'Status', 'Action'],
data: [
<?php
$stmt = $obj->con1->prepare(
"SELECT ps1.*,p1.name as product,s1.name as service FROM `product_service` ps1, `product_category` p1,`service_type` s1 WHERE ps1.pid=p1.id AND ps1.sid=s1.id;"
);
$stmt->execute();
$Resp = $stmt->get_result();
$i = 1;
while ($row = mysqli_fetch_array($Resp)) {
?>
[
<?php echo $i; ?>,
'<?php echo $row["product"]; ?>',
'<?php echo $row["service"]; ?>',
`<span class="badge badge-outline-<?php echo $row["status"] == "enable" ? 'success' : 'danger'?>">
<?php echo ucfirst($row["status"]); ?>
</span>`,
getActions(<?php echo $row["srno"]; ?> ,'<?php echo $row["product"];?>','<?php echo $row["service"];?>')
],
<?php
$i++;}
$stmt->close();
?>
],
},
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: 'product_service',
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 '';
},
}));
})
async function showAlert(id,product,service) {
new window.Swal({
title: 'Are you sure?',
text: `You want to delete Product service :- ${product}, ${service}!`,
showCancelButton: true,
confirmButtonText: 'Delete',
padding: '2em',
}).then((result) => {
console.log(result)
if (result.isConfirmed) {
var loc = "product_service.php?flg=del&n_pserviceid=" + id;
window.location = loc;
}
});
}
</script>
<?php
include "footer.php";
?>