 <?php $__env->startSection('content'); ?>
    <?php echo $__env->make('administrator.construction.purchase.payment.form-pay', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
	<style>
		#from-account,#to-account,#cheque-no{
			width: 190px !important;
		}
		#select2-bank-to-id-container,#select2-bank-from-id-container,#select2-bank-of-cheque-container{
			width: 165px !important;
		}
	</style>
    <?php Fun::lang()?>
    <div class="title-page">
        <div class="page-bar">
            <ul class="page-breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> Dashboard</a></li>
                <li><a href="#">Report</a></li>
                <li><a href="#">Report Construction</a></li>
                <li><a href="#">Report Payment History</a></li>
            </ul>
        </div>
    </div>
    <div class="page">
        <div class="top-content">
            <div class="row">
                <div class="col-sm-12 col-xs-12">
                    <div class="title-page">
                        <div class="pull-left">
                            <h3>Report Payment History</h3>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="box-body table-responsive">
			<form action="<?php echo e(route('report.report_purchase_payment')); ?>" method="post">
				<?php echo csrf_field(); ?>
				<div class="row">
					<div class="col-md-6">
						<div class="form-group">
							<strong >Request by :</strong>
							<?php echo Form::text('prepare_by',null, array('class' => 'form-control')); ?>

						</div>
					</div>
					<div class="col-md-6">
						<div class="form-group">
							<strong >Supplier Name :</strong>
							<?php echo Form::select('supplier_id',$supplers,null, array('class' => 'form-control select2')); ?>

						</div>
					</div>
					<div class="col-md-6">
						<div class="form-group">
							<strong >Project :</strong>
							<?php echo Form::select('project',$projects,null, array('class' => 'form-control select2')); ?>

						</div>
					</div>
					<div class="col-md-6">
						<div class="form-group">
							<strong >Stock Position :</strong>
							<?php echo Form::text('stock_position',null, array('class' => 'form-control')); ?>

						</div>
					</div>
					<div class="col-md-12" style="text-align:right;margin-bottom:40px !important;">
						<button class="button_xs button_success" href="javascript:void(0)" id="search-submit" onclick="searching()"><span class="fa fa-search"></span> Search</button>
						<button class="button_xs button_primary" type="submit"><span class="fa fa-print"></span> Print</button>
					</div>
				</div>  
			</form>
            <table id="datatable_purchase_order" class="table table-striped table-bordered table-hover nowrap" widtd="100%">
                <thead>
                <tr>
                    <th>NO</th>
                    <th>Payment Date</th>
                    <th>Request By</th>
                    <th>Project</th>
                    <th>Supplier</th>
                    <th>Phone</th>
                    <th>Stock Position</th>
                    <th>Total Amount</th>
					<th>Paid Amount</th>
					<th>Method</th>
                </tr>
                </thead>
                <tbody>

                </tbody>
				<tfoot>
					<tr>
						<td colspan="7" class="text-right">Total</td>
						<td></td>
						<td></td>
						<td></td>
					</tr>
				</tfoot>
            </table>

        </div>
    </div>

<?php $__env->stopSection(); ?>
<?php $__env->startSection('js'); ?>
    <script type="text/javascript">
			function make_payment(obj){
				$("#main-spinner").show();
				let href = $(obj).data('href');
				$.ajax({
					type: "GET",
					url: href,
					data: "data",
					dataType: "JSON",
					success: function (data) {
						$("#form-pay").modal("show");
						$("input[name=purchase_id]").val(data.purchase.id);
						$("#supplier").val(data.purchase_info.name);
						$("#total_amount").val(data.purchase.total_amount);
						$("#payment").val(data.purchase.total_amount);
						$("#phone").val(data.purchase_info.phone);
					},
					complete:function(data){
						$("#main-spinner").hide();
					}
				});

			}
            function searching(){
                $("#datatable_purchase_order").DataTable().draw(true);
            }
            let table = $('#datatable_purchase_order').DataTable({
                ordering: false,
                "serverSide": true,
                "scrollY":"600px",
                "scrollCollapse": true,
                "scrollX": true,
                "lengthMenu": [
                    [20, 25, 50, 100, 500],
                    [20, 25, 50, 100, 500]
                ],
                ajax: {
                    url:"<?php echo e(route('report.report_purchase_payment')); ?>",
                    type:"GET",
                    data:function(d){
                        d.request_name = $("input[name=prepare_by]").val();
                        d.supplier_id = $("select[name=supplier_id]").val();
                        d.stock_position = $("input[name=stock_position]").val();
                        d.project_id = $("select[name=project]").val();
                    }
                },
                columns: [
                    {data: 'DT_RowIndex'},
                    {data: 'date'},
                    {data: 'request_by'},
                    {data: 'project_name'},
                    {data: 'supplier_id'},
                    {data: 'phone_number'},
                    {data: 'stock_position'},
                    {data: 'amount'},
					{data: 'total_paid'},
					{data: 'method'},
                ],
                "initComplete": function(settings, json) {
					$('#main-spinner').hide();
				},
				"footerCallback": function(row, data, start, end, display) {
					var api = this.api(),
					data;
					var intVal = function(i) {
					return typeof i === 'string' ?
						i.replace(/[\$,]/g, '') * 1 :
						typeof i === 'number' ?
						i : 0;
					};

					var total_sale = api
					.column(7)
					.data()
					.reduce(function(a, b) {
						return intVal(a) + intVal(b);
					}, 0);

					var total_paid = api
					.column(8)
					.data()
					.reduce(function(a, b) {
						return intVal(a) + intVal(b);
					}, 0);

					var numFormat = $.fn.dataTable.render.number('\,', '.', 2, '$ ').display;
					$(api.column(7).footer()).html(numFormat(total_sale));
					$(api.column(8).footer()).html(numFormat(total_paid));
				},
            });
            $.fn.dataTable.ext.errMode = 'throw';
    </script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('adminlte::page', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>