<?php require('../connection.php');
$stmt = $GLOBALS['con']->prepare("SELECT * FROM `dd_payee` WHERE `id`='".$_REQUEST['id']."'")or die(mysqli_error("getItems: ".$GLOBALS['con']));
$stmt->execute();$rslt=$stmt->get_result();
$d=mysqli_fetch_array($rslt);

?>
<form id="editForm">
    <div class="row">
        <div class="col-12 col-md-6 mb-2">
        <span>Name</span>
        <input type="text" class="form-control form-control-sm" aria-label="code" name="name" value="<?php echo $d['name']?>" />
        </div>
        <div class="col-12 col-md-6 mb-2">
        <span>Description</span>
        <select id="type" type="text" class="form-control form-control-sm" name="type">
        <option value="in" <?php if($d['type']=="in"){?>SELECTED <?php }?>>Receipts</option>
        <option value="out" <?php if($d['type']=="out"){?>SELECTED <?php }?>>Outgoings</option>
        </select>
        </div>
        <input type="hidden" name="id" value="<?php echo $d['id']?>">
        <input type="hidden" name="mode" value="payee">
        <input type="hidden" name="FUNCTION" value="update">
    </div>
</form>
<script>
    $('#popupBox .modal-header').html('<a href="javascript:void(0)" class="sa">Edit Payee Entry</a>');
    $('#popupBox .modal-footer').html('<div class="col-12 text-center"><a href="javascript:void(0)" class="btn btn-info" onClick="updateEntry()"><i class="fad fa-save" aria-hidden="true"></i> Save Changes</a></div>');


    function updateEntry(){
confirmBox('Update Entry','Sure you wish to update this entry?','updateItemData()')

}

function updateItemData(){
event.preventDefault();
$.ajax({
url:'includes/finance/jump_functions.php',
type:'POST',
data:$('#editForm').serialize(),
success:function(result){
    var m=$('#type option:selected').text().toLowerCase();
if($.trim(result)=="s"){response('success','Your entry has been updated successfully');
loadItems('payee','list','pl',m)
$('#confirmBox').modal('hide')
closePop()

}
else{response('danger','There was a problem, please check your details and try again')}
}
});
}

</script>
