0byt3m1n1
Path:
C:
/
wamp64
/
www
/
cpms_new
/
ACCOUNTS
/
[
Home
]
File: ac_pending_vouchers_acc.php
<?php $MAIN_HEADING="Pending Vouchers" ; $SUB_HEADING="" ; include( "../lib/config.php"); require_once BASE_DIR. "/lib/db/connection.php"; require_once "../model/uploader_mdl.php"; require_once "../model/defaultValues_mdl.php"; require_once "ac_models.php"; include( "include/accountsheader.php"); include("../ADMIN/models.php"); $servername = "localhost"; $username = "root"; $password = ""; $dbname = "cpms"; // Create a database connection $dbConnection = new mysqli($servername, $username, $password, $dbname); // Create an instance of the Models class and pass the database connection $acModelsInstance = new Ac_Models($dbConnection); $pendingVouchers = $acModelsInstance->getPendingVouchers(); ?> <?php $json=json_encode($pendingVouchers) ;?> <script> var array_code = '<?php echo $json; ?>'; var pendingVoucherJson = JSON.parse(array_code); </script> <?php include( "include/alert_message.php"); ?> <ul class="nav navbar-right panel_toolbox"> <button class="btn btn-success" onclick="acceptPendingVouchers()"> <i class="fa fa-check-circle"></i> Accept</button> <button class="btn btn-danger hide" onclick="showRemarkModal()"> <i class="fa fa-trash"></i> Decline</button> <i class="fa fa-spin fa-refresh" style="display:none" id="accept-spin"></i> </ul> <div class="clearfix"></div> <span id="accept-error" style="color:red;margin-top:10px;display:none" class="pull-right ">Please select the checkbox to take an action</span> <br/> <div id="accept-msg" class="row" style="color:green;display:none; " > <i class="fa fa-check-circle-o"> </i> Success</div> <table class="table table-striped table-bordered jambo_table bulk_action " id="table"> <thead> <tr> <th> <input type="checkbox" id="check-all" class="flat"> </th> <th>Supplier Name</th> <th>Invoice No</th> <th>Invoice Date</th> <th>Amount</th> <th>Project Code</th> <th>Debit Head</th> <th>Date</th> <th>Remarks</th> <th>Status</th> <th>Created By</th> <th>Action</th> </tr> </thead> <tbody> <?php $i=0; if(!empty($pendingVouchers)){ foreach ($pendingVouchers as $kk=> $value) { ?> <tr id="<?php echo $value["id"] ?>"> <td class="a-center "> <input type="checkbox" class="flat" name="table_records" value="<?php echo $value["id"] ?>"> </td> <td> <?php echo $value[ "sup_name"] ?> </td> <td> <?php echo $value[ "invoice_number"] ?> </td> <td> <?php echo $value[ "invoice_date"] ?> </td> <td> <?php echo $value[ "amount"] ?> </td> <td> <?php echo $value[ "project_code"] ?> </td> <td> <?php echo $value[ "debit_head"] ?> </td> <td> <?php echo $value[ "created_on"] ?> </td> <td> <?php echo $value["remarks"] ?> </td> <td> <label class="label label-info"> <?php echo $value[ "status"] ?> <lable> </td> <td> <?php echo $value[ "user_name"] ?> </td> <td> <a type="button" href="ac_edit_voucher.php?id=<?php echo $value["id"] ?>" class="btn btn btn-xs btn-success">Edit</a> <a onclick="return confirm('Delete this voucher?')" href="ac_delete_voucher.php?id=<?php echo $value['id']?>" class="btn btn-xs btn-danger" >Delete</a> </td> </td> </tr> <?php } }else{ echo '<tr class="odd"><td valign="top" colspan="12" class="dataTables_empty">No matching records found</td></tr>'; } ?> </tbody> <tbody> </tbody> </table> </div> </div> </div> <div class="modal fade" id="modal-edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <form method="post" class="form-horizontal form-label-left" name="form1" id="form1" data-parsley-validate=""> <div class="modal-content"> <div class="modal-header"> <h4 class="modal-title" id="myModalLabel">Edit Voucher</h4> </div> <div class="modal-body" id="edit-content"> </div> <div class="modal-footer"> <i class="fa fa-refresh fa-spin fa-2x" id="spin" style="display:none"></i> <button type="button" class="btn btn-sm btn-primary" data-dismiss="modal">Cancel</button> <button id="add-install-btn" type="submit" class="btn btn-sm btn-success" >Update</button> </div> </div> </form> </div> </div> <div class="modal fade" id="modal-decline" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <form method="post" class="form-horizontal form-label-left" name="form1" id="decline" data-parsley-validate=""> <div class="modal-content"> <div class="modal-header"> <h4 class="modal-title" id="myModalLabel">Remarks</h4> </div> <div class="modal-body"> <div class="form-group invoice"> <label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">Remarks </label> <div class="col-md-6 col-sm-6 col-xs-12"> <textarea type="text" class="form-control col-md-7 col-xs-12" required="" name="remarks" id="remarks" ></textarea> </div> </div> </div> <div class="modal-footer"> <i class="fa fa-refresh fa-spin fa-2x" id="spin2" style="display:none"></i> <button id="decline" type="submit" onclick="declinePendingVouchers()" class="btn btn-sm btn-success" >Update</button> </div> </div> </form> </div> </div> <?php include "include/footer.php"; ?> <script> $(function() { $('#form1').parsley({ excluded: "input[type=button], input[type=submit], input[type=reset], input[type=hidden], [disabled], :hidden" }).on('field:validated', function(fieldInstance) { if (!fieldInstance.$element.is(":visible")) { fieldInstance._ui.$errorsWrapper.css('display', 'none'); fieldInstance.validationResult = true; return true; } }) .on('form:submit', function() { updateVoucherDetails( $('#form1').attr("voucher_id")); return false; }); $('#decline').parsley({ excluded: "input[type=button], input[type=submit], input[type=reset], input[type=hidden], [disabled], :hidden" }).on('field:validated', function(fieldInstance) { if (!fieldInstance.$element.is(":visible")) { fieldInstance._ui.$errorsWrapper.css('display', 'none'); fieldInstance.validationResult = true; return true; } }) .on('form:submit', function() { return false; }); }); function showRemarkModal() { if (!isAnyItemChecked()) { return; } var checked = $.map($('table#table tbody input.flat:checked'), function(n, i) { return n.value; }).join(','); $("#modal-decline").modal("toggle"); } function editVoucher(index) { var obj = pendingVoucherJson[index]; console.log(obj) getVoucherDetails(obj.id); } function getVoucherDetails(id) { $("#modal-edit #edit-content").html(""); $.ajax({ type: 'POST', url: BASE_URL + "ac_ajax.php", data: { voucher_id: id, f: "get_voucher_details" }, dataType: 'json', error: function() { alert("something went wrong, Try again"); }, success: function(data) { if (data.status !== undefined && data.status && data.data !== undefined) { $("#modal-edit").modal('show'); $("#modal-edit form").attr("voucher_id", id); $("#modal-edit #edit-content").html(data.data); } else { alert("something went wrong, Try again"); } }, }); } function updateVoucherDetails(id){ var name = $.trim($('#form1 input[name="name"]').val()); var invoice_date = $.trim($('#form1 input[name="invoice_date"]').val()); var invoice_number = $.trim($('#form1 input[name="invoice_number"]').val()); var amount = $.trim($('#form1 input[name="amount"]').val()); var data = {name:name,invoice_date:invoice_date,invoice_number:invoice_number,amount:amount}; $("#spin").show(); $("#modal-edit .modal-body #msg").remove(); $.ajax({ type: 'POST', url: BASE_URL + "ac_ajax.php", data: { voucher_id: id, data:data, f: "update_voucher_details" }, dataType: 'json', error: function() { $("#modal-edit .modal-body").append("<span id='msg' class='row center ' style='color:green'>Somthing went wrong, Try again</span>"); $("#spin").hide(); }, success: function(data) { $("#spin").hide(); if (data.status !== undefined && data.status) { $("#modal-edit .modal-body").append("<span id='msg' class='row center ' style='color:green'>Successfully updated</span>"); setTimeout(function(){ location.href = "ac_pending_vouchers_acc.php?message=Updated%20Successfully" },1000); } else { $("#modal-edit .modal-body").append("<span id='msg' class='row center ' style='color:green'>Somthing went wrong, Try again</span>"); } }, }); } function isAnyItemChecked() { var length = $("table#table tbody input.flat:checked").length; var flag = true; if (length == 0) { $("#accept-error").show(); flag = false } else { $("#accept-error").hide() } return flag; } function acceptPendingVouchers() { if (!isAnyItemChecked()) { return; } var checked = $.map($('table#table tbody input.flat:checked'), function(n, i) { return n.value; }).join(','); pendingVouchers(checked,'accept') } function declinePendingVouchers() { if (!isAnyItemChecked()) { $("#modal-decline").modal("toggle"); return; } var checked = $.map($('table#table tbody input.flat:checked'), function(n, i) { return n.value; }).join(','); pendingVouchers(checked,'self_declined', $.trim($("textarea#remarks").val())); } function pendingVouchers(checked,type,remarks) { var checkedArray = checked.split(","); $("#accept-spin").show(); $("#spin2").show(); remarks = (remarks!==undefined) ? remarks : ""; $.ajax({ type: 'POST', url: BASE_URL + "ac_ajax.php", data: { f: "update_voucher_status", type: type, budget_id: checked, remarks : remarks }, dataType: 'json', error: function() { $("#accept-spin").hide(); $("#spin2").hide(); $("#modal-decline").modal("hide"); alert("Something went wrong"); }, success: function(data) { $("#accept-spin").hide(); $("#spin2").hide(); $("#modal-decline").modal("hide"); if (data.status !== undefined && data.status) { // $("#accept-msg").show(); // setTimeout(function() { // $("#accept-msg").hide('blind', {}, 500) // }, 5000); $.each(checkedArray, function(a, b) { $("table#table tbody tr#" + b).remove(); }) } else { alert("Something went wrong"); } }, }); } function capitalize(string) { return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase(); } </script>