<script type="text/javascript">
    $(document).ready(function () {
        $('.datatables').DataTable();
        $.calculator.setDefaults({showOn: 'both', buttonImageOnly: true, buttonImage: 'img/calculator.png'});
        $('.amount').calculator();
        $('.datetimepicker').datetimepicker({
            viewMode: 'months',
            format: 'DD-MM-YYYY'
        });

    });

     function saveEditTransfer(){
         if ($("#edittransferForm").validationEngine('validate')) {
        $('#editTransferModal').modal('hide');
        setTimeout(function(){
             confirmBox('conf_saveEditTransfer()', '<?php echo $this->lang->line('msgconfirm'); ?>');
        },500);
        }
    }

    function conf_saveEditTransfer(){


            var transID = $('#edittransID').val();
            var transDate = $('#edittransDate').val();
            var transFrom = $('#edittransFrom').val();
            var transTo = $('#edittransTo').val();
            var transAmount = $('#edittransAmount').val();
            var transDesc = $('#edittransDesc').val();
            var link_acct_id =  $('#edittransTo option:selected').attr("data-acctID");
             var edittransID = $("#edittransID").attr("data-detail");
             var journalNo = $("#edittransID").attr("data-journalID");
            var postData = {
                //'formNo' : formNo,
                'ID' : transID,
                'paymentDate' : transDate,
                'bankID' : transFrom,
                'payTo' : transTo,
                'amountPaid' : transAmount,
                'memo' : transDesc,
                'link_acct_id' : link_acct_id,
                'detailid' : edittransID,
                'journalNo' : journalNo
            };

            $.ajax({
                type: "POST",
                dataType: "json",
                url: "<?php echo base_url()?>transfer/saveTransfer",
                data: postData ,
                success: function(content){
                    if(content.status == "success") {
                        notify('Data successfully saved',false, 'success');
                        $("#refresh_submit").submit();
                        location.reload();
                        // window.location.href = "<?php echo base_url()?>transfer";
                    }
                }
            });
    }
</script>

<div id="editTransferModal" class="modal fade in">
    <div class="modal-dialog">
            <input type="hidden" name="ID" id="ID" value="<?php echo (isset($ID))?$ID:'0';?>">
            <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"><?php echo $this->lang->line('editTransfer'); ?></h4>
                </div>
                <form role="form" id="edittransferForm" action="#" method="post">
                <div class="modal-body">
                <!-- Main content -->
                    <section class="content">
                        <div class="row">
                            <div class="col-md-12">
                               <!-- Horizontal Form -->
                                <div class="box box-primary">
                                    <div class="box-body">

                                        <div style="margin-top:10px;" class="row form-horizontal">
                                            <div class="col-md-12 col-xs-12 col-sm-12" style="display:none">
                                                <div class="form-group">
                                                    <div class="col-sm-6">
                                                        <input type="text" class="form-control col-sm-6" id="edittransID" placeholder="">
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-md-12 col-xs-12 col-sm-12">
                                                <div class="form-group">
                                                    <label for="date" class="col-sm-4 control-label"><?php echo $this->lang->line('date'); ?>: </label>
                                                    <div class="col-sm-6">
                                                        <input type="text" class="form-control col-sm-6 datetimepicker validate[required]" id="edittransDate" placeholder="<?php echo $this->lang->line('date'); ?>">
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-md-12 col-xs-12 col-sm-12">
                                                <div class="form-group">
                                                    <label for="formNo" class="col-sm-4 control-label"><?php echo $this->lang->line('formno'); ?>: </label>
                                                    <div class="col-sm-6">
                                                        <input type="text" disabled class="form-control col-sm-6 datetimepicker validate[required]" id="edittransformNo" placeholder="<?php echo $this->lang->line('autogen'); ?>">
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div><!-- /.box-body -->
                                </div><!-- /.box -->
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-md-12">
                                    <!-- Horizontal Form -->

                                    <!-- general form elements disabled -->
                                <div class="box box-primary">

                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="box-body">
                                <div style="margin-top:10px;" class="row form-horizontal">
                                    <div class="col-md-12 col-xs-12 col-sm-12">
                                        <div class="form-group">
                                            <label for="transFrom" class="col-sm-4 control-label"><?php echo $this->lang->line('transFrom'); ?>: </label>
                                            <div class="col-sm-6">
                                                <select id="edittransFrom" class="form-control col-sm-6 validate[required]" placeholder="Select Bank">
                                                    <option><?php echo $this->lang->line('selectBank'); ?></option>
                                                    <?php foreach($bankaccount as $row): ?>
                                                        <option value="<?php echo $row->ID; ?>"><?php echo $row->bankName; ?></option>
                                                    <?php endforeach; ?>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="transTo" class="col-sm-4 control-label"><?php echo $this->lang->line('transTo'); ?>: </label>
                                            <div class="col-sm-6">
                                                <select id="edittransTo" class="form-control col-sm-6 validate[required]" placeholder="Select Bank">
                                                    <option><?php echo $this->lang->line('selectBank'); ?></option>
                                                    <?php foreach($bankaccount as $row): ?>
                                                        <option data-acctID="<?php echo $row->linkAccountID; ?>" value="<?php echo $row->ID; ?>"><?php echo $row->bankName; ?></option>
                                                    <?php endforeach; ?>
                                                </select>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-md-12 col-xs-12 col-sm-12">

                                        <div class="form-group">
                                            <label for="transfAmount" class="col-sm-4 control-label"><?php echo $this->lang->line('amount'); ?>: </label>
                                            <div class="col-sm-6">
                                                <input  type="number" pattern="[0-9]*" inputmode="numeric" class="form-control validate[required]" placeholder="<?php echo $this->lang->line('amount'); ?>">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="transferDesc" class="col-sm-4 control-label"><?php echo $this->lang->line('description'); ?>: </label>
                                            <div class="col-sm-6">
                                                <input type="text" class="form-control" id="edittransDesc" placeholder="<?php echo $this->lang->line('transferDetail'); ?>">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </section><!-- /.content -->
                </div>
                <div class="modal-footer">
                    <a class="btn btn-primary btn-sm pull-left" id="href_printdetails" href=""><i class="fa fa-print"></i></a>
                    <button class="btn btn-default" data-dismiss="modal" aria-hidden="true"><?php echo $this->lang->line('close') ?></button>
                    <a href="" id="href_journalentry" class="btn btn-primary"><?php echo $this->lang->line('journalentry'); ?></a>
                    <button type="button" onclick="saveEditTransfer()" class="btn btn-primary"><?php echo $this->lang->line('update'); ?></button>
                </div>
            </div>

        </form>
    </div><!-- /.modal-dialog -->
</div>
