<div class="panel widget-comments">
    <div class="panel-body">
        <?php foreach($purchases as $purchase): ?>
            <div class="comment">

                <div class="comment-body no-margin">
                    <div class="comment-by">
                        <a onclick="javascript:generateJobPurchaseDetail('<?php echo e(URL::action("JobController@generateJobPurchaseDetail")); ?>', '<?php echo e($purchase["id"]); ?>', '<?php echo e(csrf_token()); ?>')"><?php echo e($purchase['orderRef']); ?></a>
                    </div>
                    <div class="comment-text">
                        Total net: &pound; <?php echo e($purchase['totalNet']); ?> <br/>
                        Status: <?php echo e($purchase['invoiceStatus']); ?>

                    </div>
                    <div class="comment-actions">
                        <a id="deleteJobHistoryButton<?php echo e($purchase['id']); ?>"
                           onclick="javascript:showConfirmRemove(<?php echo e($purchase['id']); ?>)"><i class="fa fa-times"></i>Remove</a>
                        <a id="confirmRemove<?php echo e($purchase['id']); ?>"
                           onclick="javascript:deletePurchase('<?php echo e(URL::action("PurchaseController@uiDelete")); ?>', '<?php echo e($purchase["id"]); ?>', '<?php echo e(csrf_token()); ?>')"><i
                                    class="fa fa-trash-o"></i>Confirm to delete?</a>
                        <span class="pull-right"><?php echo e($purchase['orderDate']); ?></span>
                    </div>
                </div>
            </div>
        <?php endforeach; ?>
    </div>
</div>

<script type="text/javascript">
    function showConfirmRemove(id) {
        $('#confirmRemove' + id).show();
    }

    function deletePurchase(url, purchaseId, csrToken) {
        $.post(url, {
            id: purchaseId,
            _token: csrToken
        }).done(function (data) {
            generateJobPurchases('<?php echo e(URL::action("JobController@generateJobPurchases")); ?>', '<?php echo e($job['id']); ?>', '<?php echo e(csrf_token()); ?>');
        });
    }

    $('a[id^="confirmRemove"]').hide();
</script>
