// GLOBAL VARIABLES
var edit_id = 0;
var birthday = "";
$(function(){
initTableBankInformation();
refreshTableBankInformation();
// reloadTopDetails();
// INITIALIZATION
$('#edit-info-bank').select2({
placeholder: "Select bank",
allowClear: false
});
$('#edit-info-area').select2({
placeholder: "Select area",
allowClear: false
});
$('#filter-date').datetimepicker({
format: 'L'
});
$('[data-mask]').inputmask();
})
function initTableBankInformation() { // refreshTableBankInformation
var $table = $('#bank-information-table');
$table.bootstrapTable('destroy').bootstrapTable({
onLoadSuccess: function(data){
edit_id = data.rows[0].record_id;
var bank_info_record_total = data.total;
$('#bank-info-address').val(data.address);
$('#bank-info-bank').val(data.rows[0].bank);
$('#bank-info-branch-name').val(data.rows[0].branch_name);
$('#bank-info-area').val(data.rows[0].area);
if(bank_info_record_total > 1){
setSpanRed();
$('#span-date-uploaded').text("No row selected");
$('#span-uploaded-by').text("No row selected");
$('#span-last-modified-by').text("No row selected");
}
else {
setSpanBlack();
$('#span-date-uploaded').text(data.rows[0].date_added);
$('#span-uploaded-by').text(data.rows[0].uploaded_by);
// $('#span-last-modified-by').text(data.rows[0].last_modified_by + " (" + data.rows[0].date_modified + ")");
if(data.rows[0].last_modified_by == "Unknown"){ $('#span-last-modified-by').text("-") } else { $('#span-last-modified-by').text(data.rows[0].last_modified_by + " (" + data.rows[0].date_modified + ")"); }
}
}
})
}
function refreshTableBankInformation() { // 3 bank list
var $table = $('#bank-information-table')
$(function() {
$table.bootstrapTable('refresh', {
url: 'app/table/bank_table.php'
});
})
}
function queryParamsBankInformationTable(params) {
return {
search: params.search,
offset: params.offset,
limit: params.limit,
type: 3, // bank/branch head information table
bank_id: bank_id,
branch_name: branch_name
};
}
function editBHInfo(value, row, index){
if(bank_edit_record == 0){
return '
';
}
else {
return '
';
}
}
function back(){
window.history.back();
}
function setSpanRed(){
$('#span-date-uploaded').css('color', 'red');
$('#span-uploaded-by').css('color', 'red');
$('#span-last-modified-by').css('color', 'red');
}
function setSpanBlack(){
$('#span-date-uploaded').css('color', 'black');
$('#span-uploaded-by').css('color', 'black');
$('#span-last-modified-by').css('color', 'black');
}
// READ EDIT
function editInformation(row_id){
if(bank_edit_record == 0){
toastr.remove();
toastr.error("Sorry, you have no access in updating record", "No access");
return;
}
else {
edit_id = row_id;
$.ajax({
url: "app/bank/crud_bank_details.php",
method: "POST",
dataType: 'json',
data: {
edit_id: edit_id,
type: 1 // read details
},
beforeSend: function(){
},
success: function(result) {
var bh_contact = result.bh_contact.substring(3, 13);
$('#edit-info-bank').val(result.bank_id).trigger('change');
$('#edit-info-branch-name').val(result.branch_name);
$('#edit-info-area').val(result.area_id).trigger('change');
$('#edit-info-address').val(result.branch_address);
$('#edit-info-branch-contact').val(result.branch_contact_number);
$('#edit-info-branch-head').val(result.branch_head);
$('#edit-info-bh-contact').val(bh_contact);
$('#edit-info-bh-email').val(result.bh_email);
$('#filter-date').val(result.bh_birthday);
$('#edit-info-bh-position').val(result.bh_position);
}
});
}
}
function loadAuditTrail(record_id){
var record_id = record_id;
$.ajax({
url: "app/bank/crud_bank_details.php",
method: "POST",
dataType: 'json',
data: {
record_id: record_id,
type: 3 // reload top details
},
beforeSend: function(){
},
success: function(result) {
setSpanBlack();
$('#span-date-uploaded').text(result.date_added);
$('#span-uploaded-by').text(result.added_by);
$('#span-last-modified-by').text(result.last_modified_by);
}
});
}
function checkMobile(data){
var number = data;
var substr_number = number.substring(0, 4);
if(number.length == 3){
return 10; // no input, yet valid
}
else if(number.length != 13){
return 0; // not valid
}
else if(substr_number != "+639"){
return 0; // not valid
}
else {
return 1; // valid
}
}
// function reloadTopDetails(){
// $.ajax({
// url: "app/bank/update_bank_details.php",
// method: "POST",
// dataType: 'json',
// data: {
// bank_id: bank_id,
// branch_name: branch_name,
// type: 30 // reload top details
// },
// beforeSend: function(){
// },
// success: function(result) {
// $('#bank-info-bank').val(result.bank);
// $('#bank-info-branch-name').val(result.branch_name);
// $('#bank-info-area').val(result.area);
// $('#bank-info-address').val(result.address);
// }
// });
// }
// SAVE EDIT
$('#button-edit-bank-details').on('click', function(){
var update_bank = $('#edit-info-bank').val();
var update_branch_name = $('#edit-info-branch-name').val();
var update_area = $('#edit-info-area').val();
var update_address = $('#edit-info-address').val();
var update_branch_contact = $('#edit-info-branch-contact').val();
var update_branch_head = $('#edit-info-branch-head').val();
var update_bh_contact = "+63" + $('#edit-info-bh-contact').val();
var update_bh_email = $('#edit-info-bh-email').val();
var update_bh_birthday = $('#filter-date').val();
var update_bh_position = $('#edit-info-bh-position').val();
// DATA VALIDATIONS
if(update_bank == ""){
toastr.remove();
toastr.error("Please specify bank");
return;
}
if(update_branch_name == ""){
toastr.remove();
toastr.error("Please specify branch name");
return;
}
if(update_area == ""){
toastr.remove();
toastr.error("Please specify branch area");
return;
}
var is_bh_contact_valid = checkMobile(update_bh_contact);
if(is_bh_contact_valid == 0){ // not valid
toastr.remove();
toastr.error("It seems that BH contact number isn't valid");
return;
}
else if(is_bh_contact_valid == 10){ // empty
update_bh_contact = "";
}
$.ajax({
url: "app/bank/crud_bank_details.php",
method: "POST",
dataType: 'json',
data: {
edit_id: edit_id,
bank_id: bank_id, // needed for branch addess update
branch_name: branch_name, // needed for branch name update
type: 2, // update details
updated_bank: update_bank,
updated_branch_name: update_branch_name,
updated_area: update_area,
updated_address: update_address,
updated_branch_contact: update_branch_contact,
updated_branch_head: update_branch_head,
updated_bh_contact: update_bh_contact,
updated_bh_email: update_bh_email,
updated_bh_birthday: update_bh_birthday,
updated_bh_position: update_bh_position
},
beforeSend: function(){
$('#loading-view').attr('hidden', false);
},
success: function(result) {
if(result.status == 0){ // failed update
toastr.remove();
toastr.error("Something went wrong. Try again.");
$('#loading-view').attr('hidden', true);
}
else { // success update
$('#loading-view').attr('hidden', true);
$('#modal-bankbanks-info-bank').modal('hide');
toastr.remove();
toastr.success("Updated successfully");
bank_id = update_bank;
branch_name = update_branch_name;
// reloadTopDetails();
refreshTableBankInformation();
}
}
})
})
$('#filter-date').on('change.datetimepicker', function(e){
birthday = $('#filter-date').val();
birthday = moment(e.date).format('yyyy-MM-DD');
})
$('#bank-information-table').on('click-cell.bs.table', function(field, value, row, $el) {
var record_id = $el.record_id;
loadAuditTrail(record_id);
})