Skip to content

Commit c614c57

Browse files
Version 1.8 Customer Management Added
1 parent 5e5463f commit c614c57

File tree

7 files changed

+211
-123
lines changed

7 files changed

+211
-123
lines changed

README.MD

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,25 @@ Here you can change the `xampp/htdocs/index.php` to redirect to the `CUSTMBRS` f
3737

3838
## LICENSE
3939
```
40-
MIT License
41-
42-
Copyright (c) 2023 Joshua Ambalong
43-
44-
Permission is hereby granted, free of charge, to any person obtaining a copy
45-
of this software and associated documentation files (the "Software"), to deal
46-
in the Software without restriction, including without limitation the rights
47-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
48-
copies of the Software, and to permit persons to whom the Software is
49-
furnished to do so, subject to the following conditions:
50-
51-
The above copyright notice and this permission notice shall be included in all
52-
copies or substantial portions of the Software.
53-
54-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
55-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
56-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
57-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
58-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
59-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
60-
SOFTWARE.
40+
MIT License
41+
42+
Copyright (c) 2023 Joshua Ambalong
43+
44+
Permission is hereby granted, free of charge, to any person obtaining a copy
45+
of this software and associated documentation files (the "Software"), to deal
46+
in the Software without restriction, including without limitation the rights
47+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
48+
copies of the Software, and to permit persons to whom the Software is
49+
furnished to do so, subject to the following conditions:
50+
51+
The above copyright notice and this permission notice shall be included in all
52+
copies or substantial portions of the Software.
53+
54+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
55+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
56+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
57+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
58+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
59+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
60+
SOFTWARE.
6161
```

assets/js/main.js

Lines changed: 65 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -74,85 +74,81 @@ new DataTable('table.table-display',{
7474
)
7575
}
7676

77-
// if (currentPath.includes("/RMMFB/customers.php")) {
78-
// $('a[data-bs-target="#update"]').on('click', function() {
79-
// var id = $(this).data('id');
80-
// var fullname = $(this).data('fullname');
81-
// var address = $(this).data('address');
82-
// var phone = $(this).data('phone');
83-
// var email = $(this).data('email');
84-
// var date = $(this).data('birthdate');
77+
if (currentPath.includes("/CUSTMBRS/customer.php")) {
78+
$('a[data-bs-target="#update"]').on('click', function() {
79+
var id = $(this).data('id');
80+
var fullname = $(this).data('fullname');
81+
var address = $(this).data('address');
82+
var phone = $(this).data('phone');
8583

86-
// // console.log(id, fullname, address, phone, email, date);
87-
// $('input[name="data_id"]').val(id);
88-
// $('input[name="name"]').val(fullname);
89-
// $('input[name="address"]').val(address);
90-
// $('input[name="phone"]').val(phone);
91-
// $('input[name="email"]').val(email);
92-
// $('input[name="date"]').val(date);
93-
// });
84+
// console.log(id, fullname, address, phone, email, date);
85+
$('input[name="id"]').val(id);
86+
$('input[name="fullname"]').val(fullname);
87+
$('input[name="address"]').val(address);
88+
$('input[name="phone"]').val(phone);
89+
});
9490

95-
// } else if (currentPath.includes("/RMMFB/staff.php")) {
96-
// $('a[data-bs-target="#update"]').on('click', function() {
97-
// var id = $(this).data('id');
98-
// var username = $(this).data('username');
99-
// console.log(id, username);
91+
} else if (currentPath.includes("/RMMFB/staff.php")) {
92+
$('a[data-bs-target="#update"]').on('click', function() {
93+
var id = $(this).data('id');
94+
var username = $(this).data('username');
95+
console.log(id, username);
10096

101-
// $('input[name="data_id"]').val(id);
102-
// $('input[name="username"]').val(username);
97+
$('input[name="data_id"]').val(id);
98+
$('input[name="username"]').val(username);
10399

104-
// });
105-
// } else if (currentPath.includes("/RMMFB/inventory.php")) {
106-
// $('a[data-bs-target="#update"]').on('click', function() {
107-
// var id = $(this).data('id');
108-
// var name = $(this).data('name');
109-
// var description = $(this).data('description');
110-
// $('input[name="data_id"]').val(id);
111-
// $('input[name="name"]').val(name);
112-
// $('input[name="description"]').val(description);
113-
// console.log(id);
114-
// $('input[name="data_id"]').val(id);
115-
// });
100+
});
101+
} else if (currentPath.includes("/RMMFB/inventory.php")) {
102+
$('a[data-bs-target="#update"]').on('click', function() {
103+
var id = $(this).data('id');
104+
var name = $(this).data('name');
105+
var description = $(this).data('description');
106+
$('input[name="data_id"]').val(id);
107+
$('input[name="name"]').val(name);
108+
$('input[name="description"]').val(description);
109+
console.log(id);
110+
$('input[name="data_id"]').val(id);
111+
});
116112

117-
// $('a[data-bs-target="#stock-in"]').on('click', function() {
118-
// var id = $(this).data('id');
119-
// console.log(id);
120-
// $('input[name="data_id"]').val(id);
121-
// });
113+
$('a[data-bs-target="#stock-in"]').on('click', function() {
114+
var id = $(this).data('id');
115+
console.log(id);
116+
$('input[name="data_id"]').val(id);
117+
});
122118

123-
// $('a[data-bs-target="#stock-out"]').on('click', function() {
124-
// var id = $(this).data('id');
125-
// console.log(id);
126-
// $('input[name="data_id"]').val(id);
127-
// });
128-
// }else if (currentPath.includes("/RMMFB/rents.php")) {
129-
// $('a[data-bs-target="#return"]').on('click', function() {
130-
// var id = $(this).data('id');
131-
// $('input[name="data_id"]').val(id);
132-
// console.log(id);
133-
// });
119+
$('a[data-bs-target="#stock-out"]').on('click', function() {
120+
var id = $(this).data('id');
121+
console.log(id);
122+
$('input[name="data_id"]').val(id);
123+
});
124+
}else if (currentPath.includes("/RMMFB/rents.php")) {
125+
$('a[data-bs-target="#return"]').on('click', function() {
126+
var id = $(this).data('id');
127+
$('input[name="data_id"]').val(id);
128+
console.log(id);
129+
});
134130

135-
// $('a[data-bs-target="#stock-in"]').on('click', function() {
136-
// var id = $(this).data('id');
137-
// console.log(id);
138-
// $('input[name="data_id"]').val(id);
139-
// });
131+
$('a[data-bs-target="#stock-in"]').on('click', function() {
132+
var id = $(this).data('id');
133+
console.log(id);
134+
$('input[name="data_id"]').val(id);
135+
});
140136

141-
// $('a[data-bs-target="#stock-out"]').on('click', function() {
142-
// var id = $(this).data('id');
143-
// console.log(id);
144-
// $('input[name="data_id"]').val(id);
145-
// });
146-
// } else{
147-
// console.log("The URL is neither /customer nor /list");
148-
// }
137+
$('a[data-bs-target="#stock-out"]').on('click', function() {
138+
var id = $(this).data('id');
139+
console.log(id);
140+
$('input[name="data_id"]').val(id);
141+
});
142+
} else{
143+
console.log("The URL is neither /customer nor /list");
144+
}
149145

150146

151147

152-
// $('a[data-bs-target="#remove"]').on('click', function() {
153-
// var id = $(this).data('id');
154-
// console.log(id);
155-
// $('input[name="data_id"]').val(id);
156-
// });
148+
$('a[data-bs-target="#remove"]').on('click', function() {
149+
var id = $(this).data('id');
150+
console.log(id);
151+
$('input[name="id"]').val(id);
152+
});
157153

158154
} );

customer.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
include_once 'functions/menu/offcanva-menu.php';
33
include_once 'functions/authentication.php';
4+
include_once 'functions/tables/datatables.php';
45
?>
56
<!DOCTYPE html>
67
<html data-bs-theme="light" lang="en">
@@ -93,19 +94,11 @@
9394
<th>Address</th>
9495
<th>Phone</th>
9596
<th>Created At</th>
96-
<th>Total Sales</th>
9797
<th class="text-center">Option</th>
9898
</tr>
9999
</thead>
100100
<tbody>
101-
<tr>
102-
<td><img class="rounded-circle me-2" width="30" height="30" src="assets/img/icon.png">Airi Satou</td>
103-
<td>&lt;address&gt;</td>
104-
<td>&lt;phone&gt;</td>
105-
<td>&lt;created_at&gt;</td>
106-
<td>&lt;sales&gt;</td>
107-
<td class="text-center"><a class="mx-1" href="#"><i class="fas fa-eye fs-4"></i></a><a class="mx-1" href="#" data-bs-target="#update" data-bs-toggle="modal"><i class="fas fa-user-edit fs-4 text-warning"></i></a><a class="mx-1" href="#" data-bs-target="#remove" data-bs-toggle="modal"><i class="fas fa-trash-alt fs-4 text-danger"></i></a></td>
108-
</tr>
101+
<?php customer_list(); ?>
109102
</tbody>
110103
<tfoot>
111104
<tr></tr>
@@ -131,7 +124,7 @@
131124
<h4 class="modal-title">Add Customer</h4><button class="btn-close" type="button" aria-label="Close" data-bs-dismiss="modal"></button>
132125
</div>
133126
<div class="modal-body">
134-
<form class="needs-validation" method="post" novalidate>
127+
<form class="needs-validation" action="functions/customer-create.php" method="post" novalidate>
135128
<div class="mb-1"><label class="form-label">Fullname</label><input class="form-control" type="text" name="fullname" required="">
136129
<div class="invalid-feedback">
137130
Please enter your fullname.
@@ -160,7 +153,8 @@
160153
<h4 class="modal-title">Update Customer</h4><button class="btn-close" type="button" aria-label="Close" data-bs-dismiss="modal"></button>
161154
</div>
162155
<div class="modal-body">
163-
<form class="needs-validation" method="post" novalidate>
156+
<form class="needs-validation" action="functions/customer-update.php" method="post" novalidate>
157+
<input type="hidden" name="id" id="id">
164158
<div class="mb-1"><label class="form-label">Fullname</label><input class="form-control" type="text" name="fullname" required="">
165159
<div class="invalid-feedback">
166160
Please enter your fullname.
@@ -191,7 +185,10 @@
191185
<div class="modal-body">
192186
<p>Are you sure you want to remove this customer?</p>
193187
</div>
194-
<div class="modal-footer"><button class="btn btn-light" type="button" data-bs-dismiss="modal">Close</button><button class="btn btn-danger" type="button">Remove</button></div>
188+
<form action="functions/customer-remove.php" method="post">
189+
<input type="hidden" name="id" id="id">
190+
<div class="modal-footer"><button class="btn btn-light" type="button" data-bs-dismiss="modal">Close</button><button class="btn btn-danger" type="submit">Remove</button></div>
191+
</form>
195192
</div>
196193
</div>
197194
</div>
@@ -208,7 +205,6 @@
208205
<script src="assets/js/buttons.html5.min.js"></script>
209206
<script src="assets/js/sweetalert2.all.min.js"></script>
210207
<script src="assets/js/main.js"></script>
211-
<script src="assets/js/fullcalendar.js"></script>
212208
<script src="assets/js/index.global.min.js"></script>
213209
<script src="assets/js/tinymce.min.js"></script>
214210
</body>

functions/customer-create.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,27 @@
11
<?php
22
include_once 'connection.php';
33

4-
$fullname = $_POST['name'];
4+
$fullname = $_POST['fullname'];
55
$address = $_POST['address'];
66
$phone = $_POST['phone'];
7-
$email = $_POST['email'];
8-
$birthdate = $_POST['date'];
9-
107
$sql = "SELECT * FROM customers WHERE fullname = :fullname OR phone = :phone";
118
$stmt = $db->prepare($sql);
129
$stmt->bindParam(':fullname', $fullname);
1310
$stmt->bindParam(':phone', $phone);
1411
$stmt->execute();
1512

1613
if ($stmt->rowCount() > 0) {
17-
header('Location: ../customers.php?type=error&message='.$fullname.' is already exist or phone number is already exist');
14+
header('Location: ../customer.php?type=error&message='.$fullname.' is already exist');
1815
exit;
1916
}
2017

21-
$sql = "INSERT INTO customers (fullname, address, phone, email, birthdate) VALUES (:fullname, :address, :phone, :email, :birthdate)";
18+
$sql = "INSERT INTO customers (fullname, address, phone) VALUES (:fullname, :address, :phone)";
2219
$stmt = $db->prepare($sql);
2320
$stmt->bindParam(':fullname', $fullname);
2421
$stmt->bindParam(':address', $address);
2522
$stmt->bindParam(':phone', $phone);
26-
$stmt->bindParam(':email', $email);
27-
$stmt->bindParam(':birthdate', $birthdate);
2823
$stmt->execute();
2924

3025
generate_logs('Adding Customer', $fullname.'| New Customer was added');
31-
header('Location: ../customers.php?type=success&message=New customer was added successfully');
26+
header('Location: ../customer.php?type=success&message=New customer was added successfully');
3227
?>

functions/customer-remove.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
include_once 'connection.php';
33

44
try {
5-
$id = $_POST['data_id'];
5+
$id = $_POST['id'];
66
$sql = "SELECT * FROM customers WHERE id = :id";
77
$statement = $db->prepare($sql);
88
$statement->bindParam(':id', $id);
@@ -14,8 +14,8 @@
1414
$statement->bindParam(':id', $id);
1515
$statement->execute();
1616
generate_logs('Removing Customer', $result['fullname'].' was removed');
17-
header('Location: ../customers.php?type=success&message='.$result['fullname'].' was removed successfully!');
17+
header('Location: ../customer.php?type=success&message='.$result['fullname'].' was removed successfully!');
1818
} catch (\Throwable $th) {
1919
generate_logs('Removing Staff', $th);
20-
header('Location: ../customers.php?type=error&message=Something went wrong, please try again');
20+
header('Location: ../customer.php?type=error&message=Something went wrong, please try again');
2121
}

functions/customer-update.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,21 @@
22
include_once 'connection.php';
33

44
try {
5-
$id = $_POST['data_id'];
6-
$fullname = $_POST['name'];
5+
$id = $_POST['id'];
6+
$fullname = $_POST['fullname'];
77
$address = $_POST['address'];
88
$phone = $_POST['phone'];
9-
$email = $_POST['email'];
10-
$birthdate = $_POST['date'];
119

12-
$sql = "UPDATE customers SET fullname = :fullname, address = :address, phone = :phone, email = :email, birthdate = :birthdate WHERE id = :id";
10+
$sql = "UPDATE customers SET fullname = :fullname, address = :address, phone = :phone WHERE id = :id";
1311
$statement = $db->prepare($sql);
1412
$statement->bindParam(':id', $id);
1513
$statement->bindParam(':fullname', $fullname);
1614
$statement->bindParam(':address', $address);
1715
$statement->bindParam(':phone', $phone);
18-
$statement->bindParam(':email', $email);
19-
$statement->bindParam(':birthdate', $birthdate);
2016
$statement->execute();
2117

2218
generate_logs('Customer Update', $fullname.'| Info was updated');
23-
header('Location: ../customers.php?type=success&message=Customer Info was updated successfully!');
19+
header('Location: ../customer.php?type=success&message=Customer Info was updated successfully!');
2420
exit();
2521

2622
} catch (\Throwable $th) {

0 commit comments

Comments
 (0)