<?php
$this->load->view ( $left );
$this->load->view ( $header );
?>
<style type="text/css">
    .ibox-content {
        border-style : none;
    }

    .hr-line-dashed {
        margin: 5px 0;
    }
</style>

<h2> Previous Payments -</h2>
<?php 
//print_r($payment_list);
foreach($payment_list as $payment){
echo date("d/m/Y",strtotime($payment->date_added)).' = '.$payment->amount. "<br>";
}
?>
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-sm-4">
        <h2>Add paid amount</h2>
    </div>
</div>
<div class="wrapper wrapper-content">
    <div class="row text-center animated fadeInRightBig">
        <div class="col-lg-12">
            <form method="post" class="form-horizontal" id="invoice_data">
                <input type="hidden" name="worker_id" id="worker_id" value="<?php echo $user_id ?>" >
                <input type="hidden" name="date" id="date" value="<?php echo date("Y-m-d"); ?>" >
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Add Amount</label>
                            <div class="col-sm-10">
                                 <input type="text" name="amount_paid" id="amount_paid" class="form-control" placeholder="amount" value="">
                            </div>
                        </div>                        
                    </div>
                </div>
                
                <div class="ibox">
                    <div class="ibox-content">
                        <div class="row">
                            <div class="col-lg-6 pull-right">
                                <div class="form-group">
                                    <div class="col-sm-12 col-sm-offset-2">
                                        <button class="btn btn-info save_item" type="button" data-status="0"><i class="fa fa-dropbox"></i><span class="m-l-xs">Save</span></button>
                                        <button class="btn btn-danger back_listing" type="button">Cancel</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script src="http://sastadokan.in/assets/js/bootstrap3-typeahead.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
                
        $('.save_item').on('click',function(){
            if ($('#amount_paid').val() == '') {
                $('#amount_paid').parent().parent().addClass('has-error');
                return false;
            } else {
                $('#amount_paid').parent().parent().removeClass('has-error');
            }            

            var amount_paid = $('#amount_paid').val();
            var worker_id = $('#worker_id').val();
            var date = $('#date').val();

            var formData = new FormData();
            formData.append('amount_paid', amount_paid);
            formData.append('worker_id', worker_id);
            formData.append('date', date);

            $.ajax({
                url: '<?php echo site_url('user/addamount');?>',
                type: "POST",
                data:formData,
                processData: false,
                contentType: false,
                success: function(data){ 
                  window.location.href = '<?php echo site_url("user/workerlist");?>';
                }
            });
        });
    });
</script>
<?php $this->load->view($footer); ?>
