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
|
<?php require_once(__DIR__ . '/../checkuser.php'); function index() { global $dbh; $message = $_GET['message'] ?: null; $search = $_GET['search'] ?: array(); $sql = " SELECT payroll.*, latest_staff.last_name, latest_staff.first_name, staff_position.title AS position_title, ( SELECT SUM(payroll_line.amount) FROM mis_payroll_line payroll_line WHERE payroll_line.payroll_id = payroll.id AND payroll_line.deleted = 0 ) AS total_amount FROM mis_payroll payroll INNER JOIN mis_staff staff ON staff.id = payroll.staff_id INNER JOIN mis_staff latest_staff ON latest_staff.root_id = staff.root_id AND latest_staff.is_latest = 1 LEFT JOIN mis_staff_position staff_position ON staff_position.id = latest_staff.position_id WHERE payroll.deleted = 0 AND CASE WHEN COALESCE(LENGTH(?), 0) = 0 THEN 1 = 1 ELSE payroll.createdate >= ? END AND CASE WHEN COALESCE(LENGTH(?), 0) = 0 THEN 1 = 1 ELSE payroll.createdate <= ? END AND CASE WHEN COALESCE(LENGTH(?), 0) = 0 THEN 1 = 1 ELSE staff.root_id = ? END ORDER BY payroll.code"; $parameters = array( $search['start_date'], $search['start_date'], $search['end_date'], $search['end_date'], $search['staff_root_id'], $search['staff_root_id'], ); $sth = Db\Util::execute($dbh, $sql, $parameters); $payrolls = $sth->fetchAll(); $sql = "SELECT * FROM mis_staff WHERE is_latest = ? AND deleted = ? ORDER BY last_name, first_name"; $parameters = array(1, 0); $sth = Db\Util::execute($dbh, $sql, $parameters); $staffs = $sth->fetchAll();
$sql = " SELECT staff.*, staff_position.title AS position_title FROM mis_staff staff LEFT JOIN mis_staff_position staff_position ON staff_position.id = staff.position_id WHERE staff.is_latest = 1 AND staff.deleted = 0 ORDER BY staff.last_name, staff.first_name, staff.root_id"; $parameters = array(); $sth = Db\Util::execute($dbh, $sql, $parameters); $all_staffs = $sth->fetchAll(); return array( 'message' => $message, 'search' => $search, 'payrolls' => $payrolls, 'staffs' => $staffs, 'all_staffs' => $all_staffs, ); } extract(index()); ?><!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <?php require(__DIR__ . '/../inc/_head_meta.php'); ?> <?php require(__DIR__ . '/../inc/_head_css.php'); ?> <?php require(__DIR__ . '/../inc/_head_script.php'); ?> </head> <body> <?php require( __DIR__ . '/../inc/_navbar.php'); ?> <div class="text-right"> <ul class="breadcrumb"> <li><a href="#">Master</a> <span class="divider">></span></li> <li><a href="#">Staff</a> <span class="divider">></span></li> <li class="active">Payroll</li> </ul> </div> <div class="container-fluid pathways-container"> <?php if (isset($message) && !empty($message)): ?> <div class="alert alert-info"> <button type="button" class="close" data-dismiss="alert">×</button> <h5 class="alert-heading">Note:</h5> <p><?=$message?></p> </div> <?php endif; ?>
<a href="form.php" class="btn pull-right"><i class="icon-plus"></i> Add</a> <h3>Staff Payroll</h3> <div class="pathways-search"> <form id="search_form" class="form-inline" action="" method="get"> <div class="pathways-inline-block"> <?php $attribute = 'start_date'; $label = 'Date'; ?> <label class="" for="<?=$attribute?>"><?=$label?></label> <div class="input-append date-picker"> <input type="text" id="<?=$attribute?>" name="search[<?=$attribute?>]" class="dateISO input-small" style="width:90px" value="<?=h(Util::value_to_date_string($search[$attribute]))?>" data-format="yyyy-MM-dd" placeholder="<?=h($label)?>" maxlength="200" /> <span class="add-on"><i data-time-icon="icon-time" data-date-icon="icon-calendar"></i></span> </div> <?php $attribute = 'end_date'; $label = 'To'; ?> <label class="" for="<?=$attribute?>"><?=$label?></label> <div class="input-append date-picker"> <input type="text" id="<?=$attribute?>" name="search[<?=$attribute?>]" class="dateISO input-small" style="width:90px" value="<?=h(Util::value_to_date_string($search[$attribute]))?>" data-format="yyyy-MM-dd" placeholder="<?=h($label)?>" maxlength="200" /> <span class="add-on"><i data-time-icon="icon-time" data-date-icon="icon-calendar"></i></span> </div> </div> <div class="pathways-inline-block"> <?php $attribute = 'staff_root_id'; $label = 'Name'; ?> <label class="" for="<?=$attribute?>"><?=$label?></label> <!-- <input type="text" id="<?=$attribute?>" name="search[<?=$attribute?>]" class="input-medium" value="<?=h($search[$attribute])?>" placeholder="<?=h($label)?>" maxlength="200" /> --> <select id="<?=$attribute?>" name="search[<?=$attribute?>]" class="select2" placeholder="Select a <?=$label?>"> <option value=""></option> <?php foreach ($all_staffs as $staff): ?> <option value="<?=h($staff['root_id'])?>"<?=$staff['root_id'] == $search[$attribute] ? ' selected="selected"' : ''?>> <?=h($staff['last_name'])?> <?=h($staff['first_name'])?> </option> <?php endforeach; ?> </select> </div> <div class="pathways-inline-block"> <button type="submit" class="btn" style="margin-left:10px">GO</button> </div> </form> </div>
<?php if (empty($payrolls)): ?> <p>There are no records.</p> <?php else: ?> <div class="row-fluid" style="margin-bottom:10px"> <div class="btn-group"> <button id="select_all_btn" class="btn btn-small">Select All</button> <button id="delete_btn" class="btn btn-small">Delete</button> </div> </div> <script type="text/javascript"> $(function() { $('#select_all_btn').click(function() { var $selectAllCheckbox = $('.select-all-checkbox'); $selectAllCheckbox.prop('checked', !$selectAllCheckbox.prop('checked')); }); $('#delete_btn').click(function() { if ($('.select-all-checkbox:checked').length == 0) { bootbox.alert('At least select 1 record.'); } else { bootbox.dialog('Delete selected records?', [ { 'label': 'Delete', 'class': 'btn-danger', 'callback': function() { $('#form').attr('action', 'delete.php').submit(); } }, { 'label': 'Cancel', 'class': 'btn' } ]); } }); }); </script> <form id="form" action="" method="post"> <table class="table table-striped table-bordered table-hover table-condensed"> <thead> <tr> <th style="min-width:20px; width:20px"></th> <th style="min-width:50px; width:50px">Edit</th> <th style="min-width:150px; width:150px">Payroll No.</th> <th style="min-width:250px; width:150px">Name</th> <th style="min-width:150px; width:150px">Creation Date</th> <th>Total Amount</th> </tr> </thead> <tbody> <?php foreach ($payrolls as $payroll): ?> <tr> <td><input type="checkbox" name="payroll[selected][]" class="select-all-checkbox" value="<?=h($payroll['id'])?>" /></td> <td><a href="form.php?id=<?=h($payroll['id'])?>" class="btn"><i class="icon-pencil"></i></a></td> <td><?=h($payroll['code'])?></td> <td> <?=h($payroll['last_name'])?> <?=h($payroll['first_name'])?> <?php if (!empty($payroll['position_title'])): ?> (<?=h($payroll['position_title'])?>) <?php endif; ?> </td> <td><?=h($payroll['createdate'])?></td> <td>$<?=h($payroll['total_amount'] ?: '0.0')?></td> </tr> <?php endforeach; ?> </tbody> </table> </form> <script type="text/javascript"> $(function() { $('#form').validate(); }); </script> <?php endif; ?> <script type="text/javascript"> $(function() { $('.date-picker').datetimepicker({ pickTime: false }); $('.select2').select2(); $('#search_form').validate(); }); </script> <?php require( __DIR__ . '/../inc/_footer.php'); ?>
</div> <!-- /container --> </body> </html>
|