-
Notifications
You must be signed in to change notification settings - Fork 0
/
companyexpense.php
584 lines (469 loc) · 20 KB
/
companyexpense.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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
<?php
$permission = "VIEW";
require_once('head.php');
require_once('bodystart.php');
?>
<script type="text/javascript">
var table;
var status;
var ExpenseType;
var region;
var startDT;
var endDT;
$(document).ready(function() {
//refreshTable();
fillDropDown("api/getGLLookups.php?type=EXP", "#expenseType", true);
fillDropDown("api/getGLLookups.php?type=RGNGRP", "#region", true);
fillDropDown("api/getGLLookups.php?type=RGN", "#region-cr", true);
fillDropDown("api/getGLLookups.php?type=EXP", "#expense-type-cr", true);
fillDropDown("api/getGLLookups.php?type=PNL", "#pnl-line-cr", true);
fillDropDown("api/getGLLookups.php?type=PC", "#profit-centre-cr", true);
$(function () {
$('[data-toggle="tooltip"]').tooltip({
trigger : 'hover'
});
});
//Datepicker code
$(function() {
var start = moment().startOf('year').add(3,'month');
var end = moment().endOf('year').add(3,'month');
function cb(start, end) {
$('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
startDT = start.format('YYYY-MM-DD');
endDT = end.format('YYYY-MM-DD');
}
$('#reportrange').daterangepicker({
startDate: start,
endDate: end,
ranges: {
'Today': [moment(), moment()],
'This Financial Year': [moment().startOf('year').add(3,'month'), moment().endOf('year').add(3,'month')],
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
'Last 30 Days': [moment().subtract(29, 'days'), moment()],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
}
}, cb);
cb(start, end);
});
//Export Excel
var tableToExcel = (function() {
var uri = 'data:application/vnd.ms-excel;base64,',
template =
'<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>',
base64 = function(s) {
return window.btoa(unescape(encodeURIComponent(s)))
},
format = function(s, c) {
return s.replace(/{(\w+)}/g, function(m, p) {
return c[p];
})
}
return function(table, name, filename) {
if (!table.nodeType) table = document.getElementById(table)
var ctx = {
worksheet: name || 'Worksheet',
table: table.innerHTML
}
document.getElementById("dlink").href = uri + base64(format(template, ctx));
document.getElementById("dlink").download = filename;
document.getElementById("dlink").click();
}
})()
$('#det').click(function() {
refreshTable();
});
createOrShowTable();
$('#transcreatedlg').on('show.bs.modal', function(event) {
var button = $(event.relatedTarget); // Button that triggered the modal
var expid = button.data('dtexpid');
var dttype = button.data('dttype');
$.getJSON("api/getTransaction.php?expid=" + expid, function(data) {
$(".modal-body #expense-type-cr").val(data[0]['expense_type_id']);
$(".modal-body #pnl-line-cr").val(data[0]['pnl_line_id']);
$(".modal-body #profit-centre-cr").val(data[0]['pc_id']);
$(".modal-body #direct-expense-cr").prop("checked",data[0]['direct_expense']==="1");
$(".modal-body #capex-cr").prop("checked",data[0]['capex']==="1");
$(".modal-body #region-cr").val(data[0]['opp_region_id']);
$(".modal-body #expense-date-cr").val(data[0]['gen_date']);
$(".modal-body #expense-detail-cr").val(data[0]['expense_det']);
$(".modal-body #remarks-cr").val(data[0]['remarks']);
$(".modal-body #expense-ccy-cr").val(data[0]['expense_ccy']);
$(".modal-body #expense-amount-cr").val(data[0]['expense_amt_ccy']);
$(".modal-body #expense-amount-lcy-cr").val(data[0]['expense_amt_lcy']);
$(".modal-body #transtatus-cr").val(data[0]['tran_status']);
$(".modal-body #operation").val(dttype);
$(".modal-body #expense-id-cr").val(expid);
});
var modal = $(this);
if(dttype == "EditStatus"){
disbableForm(true);
$(".modal-body #transtatus-cr").removeAttr("disabled");
modal.find('.modal-title').text('Edit Transaction Status');
setTimeout(function (){
$(".modal-body #transtatus-cr").focus();
}, 1000);
}
if(dttype == "EditTran"){
disbableForm(false);
modal.find('.modal-title').text('Edit Transaction Details');
setTimeout(function (){
$('#region-cr').focus();
}, 500);
}
if(dttype == "CreateTran"){
disbableForm(false);
modal.find('.modal-title').text('Create New Transaction Details');
setTimeout(function (){
$('#region-cr').focus();
}, 500);
}
});
function disbableForm(disable){
if(disable===true){
$("#expense-type-cr").attr("disabled", "disabled");
$("#pnl-line-cr").attr("disabled", "disabled");
$("#profit-centre-cr").attr("disabled", "disabled");
$("#direct-expense-cr").attr("disabled", "disabled");
$("#capex-cr").attr("disabled", "disabled");
$("#region-cr").attr("disabled", "disabled");
$("#expense-date-cr").attr("disabled", "disabled");
$("#expense-detail-cr").attr("disabled", "disabled");
$("#remarks-cr").attr("disabled", "disabled");
$("#expense-ccy-cr").attr("disabled", "disabled");
$("#expense-amount-cr").attr("disabled", "disabled");
$("#expense-amount-lcy-cr").attr("disabled", "disabled");
$("#transtatus-cr").attr("disabled", "disabled");
}
else{
$("#expense-type-cr").removeAttr("disabled");
$("#pnl-line-cr").removeAttr("disabled");
$("#profit-centre-cr").removeAttr("disabled");
$("#direct-expense-cr").removeAttr("disabled");
$("#capex-cr").removeAttr("disabled");
$("#region-cr").removeAttr("disabled");
$("#expense-date-cr").removeAttr("disabled");
$("#expense-detail-cr").removeAttr("disabled");
$("#remarks-cr").removeAttr("disabled");
$("#expense-ccy-cr").removeAttr("disabled");
$("#expense-amount-cr").removeAttr("disabled");
$("#expense-amount-lcy-cr").removeAttr("disabled");
$("#transtatus-cr").removeAttr("disabled");
}
}
//Create Transaction details dialog on submit
$('#transcreatedlg').on('submit', '#transcrfrm', function(e) {
/* Get input values from form */
disbableForm(false);
values = jQuery("#transcrfrm").serializeArray();
console.log("values "+values);
/* Because serializeArray() ignores unset checkboxes and radio buttons: */
values = values.concat(
jQuery('#transcrfrm input[type=checkbox]:not(:checked)').map(
function() {
return {"name": this.name, "value": "off"}
}).get()
);
if (!e.isDefaultPrevented()) {
var url = "api/editExp.php";
$.ajax({
type: "POST",
url: url,
data: values,
success: function(data) {
console.log(data);
if(data.trim() === "SUCCESS"){
ic = 'success';
txt = 'Transaction Details Updated Successfully';
}
else {
ic = 'error';
txt = 'Transaction Details Update Failed';
}
Swal.fire({
// position: 'top-end',
icon: ic,
title: txt,
showConfirmButton: false,
timer: 2000
});
}
});
$('#transcreatedlg').modal("hide");
$('#transcrfrm')[0].reset();
refreshTable();
return false;
}
});
});
function createOrShowTable() {
table = $('#transaction').DataTable({
"pagingType": "full_numbers",
"lengthMenu": [
[10, 25, 50, 100, -1],
[10, 25, 50, 100, "All"]
],
"pageLength": 50,
"autoWidth": true,
"order": [],
"orderMulti": true,
"ajax": {
url: "api/getTransactionList.php",
"dataSrc": "",
data: function(d) {
d.status = status;
d.expensetype = ExpenseType;
d.start = startDT;
d.end = endDT;
d.region = region;
}
},
"columns": [{
"data": "region_grp"
},
{
"data": "expense_type"
},
{
"data": "gen_date"
},
{
"data": "expense_det"
},
{
"data": "expense_ccy"
},
{
"className": "text-right",
"data": "expense_amt_ccy",
"render": function(data, type, row, meta) {
return amtFormat(data);
}
},
// {
// "className": "text-right",
// "data": "expense_amt_lcy",
// "render": function(data, type, row, meta) {
// return amtFormat(data);
// }
// },
{
"data": "tran_status"
},
{
"className": "side-by-side",
"data": "id",
"render": function(data, type, row, meta) {
if (type === 'display') {
data =
'<span data-toggle="tooltip" data-placement="left" title="Edit Transaction Status">'+
'<button type="button" class="btn btn-default" data-dttype="EditStatus" '+
' data-dtexpid="' + data +
'" data-toggle="modal" data-target="#transcreatedlg" aria-label="Left Align">' +
'<span class="glyphicon glyphicon-check" aria-hidden="true">' +
'</span>'+
'</button> </span>'+
'<span data-toggle="tooltip" data-placement="left" title="Edit Transaction Details">'+
'<button type="button" data-placement="top" class="btn btn-default" data-dttype="EditTran" '+
'data-dtexpid="' + data +
'" data-toggle="modal" data-target="#transcreatedlg" aria-label="Left Align">' +
'<span class="glyphicon glyphicon-edit" aria-hidden="true"></span>'+
'</button> </span>'+
'<span data-toggle="tooltip" data-placement="right" title="Copy Transaction Details">'+
'<button type="button" data-placement="top" class="btn btn-default" data-dttype="CreateTran" '+
'data-dtexpid="' + data +
'" data-toggle="modal" data-target="#transcreatedlg" aria-label="Left Align">' +
'<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>'+
'</button> </span>';
}
return data;
}
}
]
});
}
function refreshTable() {
var stat = "";
$('#expenseType :selected').each(function(i, sel) {
stat = "" + $(sel).val() + " " + stat;
});
ExpenseType = stat.search("999") != -1 ? "" : stat.trim().replace(/ /g, ',');
stat = "";
$('#region :selected').each(function(i, sel) {
stat = "" + $(sel).val() + " " + stat;
});
region = stat.search("999") != -1 ? "" : stat.trim().replace(/ /g, ',');
stat = "";
$('#status :selected').each(function(i, sel) {
stat = "'" + $(sel).val() + "' " + stat;
});
status = stat.search("999") != -1 ? "" : stat.trim().replace(/ /g, ',');
table.ajax.reload();
}
</script>
<legend>Company Expense Information</legend>
<div class="row">
<form id="opportunity-search">
<div class="form-group col-xs-10 col-sm-4 col-md-8 col-lg-4">
<label class="control-label" for="status">Expense Type</label>
<select id="expenseType" name="expenseType" class="form-control" multiple="multiple">
<option value="999">ALL</option>
</select>
</div>
<div class="form-group col-xs-10 col-sm-4 col-md-8 col-lg-4">
<label class="control-label" for="status">Status</label>
<select id="status" name="status" class="form-control" multiple="multiple">
<option value="999">ALL</option>
<option value="ENTERED">ENTERED</option>
<option value="POSTED">POSTED</option>
<option value="PAID">PAID</option>
<option value="DELETED">DELETED</option>
</select>
</label>
</div>
<div class="clearfix"></div>
<div class="form-group col-xs-10 col-sm-4 col-md-8 col-lg-4">
<label class="control-label" for="status">Region</label>
<select id="region" name="region" class="form-control" multiple="multiple">
<option value="999">ALL</option>
</select>
</div>
<div class="form-group col-xs-10 col-sm-4 col-md-8 col-lg-4">
<label class="control-label" for="reportrange">Value Date Range</label>
<div id="reportrange" style="background: #fff; cursor: pointer; padding: 5px 10px; border: 1px solid #ccc; width: 100%">
<i class="fa fa-calendar glyphicon glyphicon-calendar"></i>
<span></span> <i class="fa fa-caret-down"></i>
</div>
</div>
<div class="clearfix"></div>
<div class="col-xs-10 col-sm-4 col-md-8 col-lg-4">
<button id="det" name="det" type="button" class="btn btn-primary btn-sm">
<span class="glyphicon glyphicon-search"></span>
Search
</button>
</div>
</form>
</div>
<br>
<form>
<div id="tableholder">
<input type="button" class="btn btn-default" onclick="tableToExcel('opportunity', 'Crux Report', 'cruxReport.xls')" value="Export to MS Excel">
<a id="dlink" style="display:none;"></a>
<div class="clearfix"></div><br>
<table id="transaction" class="table table-striped" width="100%">
<thead>
<tr>
<th>Region</th>
<th>Expense Type</th>
<th>Value Date</th>
<th>Expense Details</th>
<th>Expense Currency</th>
<th>Expense Amount</th>
<!-- <th>Expense Amount in LCY</th> -->
<th>Transaction Status</th>
<th>Operations</th>
</tr>
</thead>
</table>
</div>
</div>
</form>
<div class="modal fade" id="transcreatedlg" tabindex="-1" role="dialog" aria-labelledby="transcreatedlgLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="transcreatedlgLabel">Create Transaction</h4>
</div>
<div class="modal-body">
<div class="row">
<form id="transcrfrm" method="post" action="api/editExp.php" role="form">
<div class="table-responsive col-md-4 form-group">
<label for="region-cr" class="control-label">Region</label>
<select class="form-control" id="region-cr" name="region-cr"></select>
</div>
<div class="table-responsive col-md-4 form-group">
<label for="expense-type-cr" class="control-label">Expense Type</label>
<select class="form-control" id="expense-type-cr" name="expense-type-cr" ></select>
</div>
<div class="table-responsive col-md-4 form-group">
<label for="profit-centre-cr" class="control-label">Profit Centre</label>
<select class="form-control" id="profit-centre-cr" name="profit-centre-cr"></select>
</div>
<div class="clearfix"></div>
<div class="table-responsive col-md-6 form-group">
<label for="pnl-line-cr" class="control-label">PNL Line</label>
<select class="form-control" id="pnl-line-cr" name="pnl-line-cr"></select>
</div>
<div class="container">
<div class="row">
<div class="table-responsive col-md-2 form-group">
<input type="checkbox" class="form-check-input" id="direct-expense-cr" name="direct-expense-cr" >
<label for="direct-expense-cr" class="control-label">Direct Expense</label>
</div>
<div class="table-responsive col-md-2 form-group">
<input type="checkbox" class="form-check-input" id="capex-cr" name="capex-cr" >
<label for="capex-cr" class="control-label">CAPEX</label>
</div>
</div>
</div>
<div class="clearfix"></div>
<div class="table-responsive col-md-4 form-group">
<label for="expense-date-cr" class="control-label">Expense Date</label>
<input type="date" class="form-control" id="expense-date-cr" name="expense-date-cr" required>
</div>
<div class="table-responsive col-md-4 form-group">
<label for="expense-detail-cr" class="control-label">Expense details</label>
<textarea class="form-control" id="expense-detail-cr" name="expense-detail-cr" required></textarea>
</div>
<div class="table-responsive col-md-4 form-group">
<label for="remarks-cr" class="control-label">Remarks</label>
<textarea class="form-control" id="remarks-cr" name="remarks-cr" required></textarea>
</div>
<div class="table-responsive col-md-4 form-group">
<label for="expense-ccy-cr" class="control-label">Expense Currency</label>
<select class="form-control" id="expense-ccy-cr" name="expense-ccy-cr" >
<option value="INR">Indian Rupees</option>
<option value="AED">United Arab Dhirams</option>
<option value="USD">US Dollars</option>
</select>
</div>
<div class="table-responsive col-md-4 form-group">
<label for="expense-amount-cr" class="control-label">Expense Amount</label>
<input type="number" step=".01" class="form-control text-right" id="expense-amount-cr" name="expense-amount-cr" required>
</div>
<div class="table-responsive col-md-4 form-group">
<label for="expense-lcy-amount-cr" class="control-label">Expense Amount in LCY</label>
<input type="number" step=".01" class="form-control text-right" id="expense-amount-lcy-cr" name="expense-amount-lcy-cr" required>
</div>
<div class="clearfix"></div>
<div class="table-responsive col-md-4 form-group">
<label for="transtatus-cr" class="control-label">Transaction Status</label>
<select id="transtatus-cr" name="transtatus-cr" class="form-control" required>
<option value="ENTERED">ENTERED</option>
<option value="POSTED">POSTED</option>
<option value="PAID">PAID</option>
<option value="DELETED">DELETED</option>
</select>
</div>
<div class="clearfix"></div>
<div class="form-group">
<input type="hidden" class="form-control" id="expense-id-cr" name="expense-id-cr">
</div>
<div class="form-group">
<input type="hidden" class="form-control" id="operation" name="operation">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" form="transcrfrm">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<?php
require_once('bodyend.php');
?>