Skip to content

Commit

Permalink
added bulk operations
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Dec 6, 2017
1 parent dfcd919 commit 38e9809
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 36 deletions.
23 changes: 23 additions & 0 deletions Controller/PaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,29 @@ public function newAction(string $terminal, Request $request)
return $this->redirect($response->getUrl());
}

/**
* @Method("POST")
* @Route("/bulk", name="loevgaard_dandomain_altapay_payment_bulk")
*
* @param Request $request
*
* @return RedirectResponse
*/
public function bulkPaymentAction(Request $request)
{
$op = $request->request->getAlpha('bulkOperation');
$paymentRepository = $this->container->get('loevgaard_dandomain_altapay.payment_repository');
$payments = $paymentRepository->findByIds($request->request->get('payments', []));

if($op === 'capture') {
foreach ($payments as $payment) {
// @todo capture $payment
}
}

return $this->redirectToRoute('loevgaard_dandomain_altapay_payment_index');
}

/**
* @Method("GET")
* @Route("/{paymentId}/capture", name="loevgaard_dandomain_altapay_payment_capture")
Expand Down
13 changes: 13 additions & 0 deletions Entity/PaymentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,17 @@ public function findByOrderIdOrAltapayId($id): ?Payment

return $payment;
}

/**
* @param array $ids
* @return array|Payment[]
*/
public function findByIds(array $ids) : array
{
$qb = $this->getQueryBuilder('p');
$qb->where($qb->expr()->in('p.id', ':ids'));
$qb->setParameter('ids', $ids);

return $qb->getQuery()->getResult();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,5 @@ layout:
cancel: Cancel
edit: Edit
save: Save
create: Create
create: Create
submit: Submit
103 changes: 68 additions & 35 deletions Resources/views/payment/index_content.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,77 @@
<h1>{{ 'payment.index.heading'|trans }}</h1>

{% if payments|length %}
<table class="table table-hover table-striped">
<thead>
<tr>
<th>{{ 'payment.label.order_id'|trans }}</th>
<th>{{ 'payment.label.payment_method'|trans }}</th>
<th>{{ 'payment.label.customer_name'|trans }}</th>
<th>{{ 'payment.label.total'|trans }}</th>
<th>{{ 'payment.label.refunded_amount'|trans }}</th>
<th>{{ 'layout.actions'|trans }}</th>
</tr>
</thead>
<tbody>
{% for payment in payments %}
<tr>
<td>{{ payment.orderId }}</td>
<td>{{ payment.paymentMethod }}</td>
<td>{{ payment.customerName }}</td>
<td>{{ payment.totalAmount|money_localized_format }}</td>
<td>{{ payment.refundedAmount|money_localized_format }}</td>
<td nowrap>
<a class="btn btn-sm btn-default" href="{{ path('loevgaard_dandomain_altapay_payment_show', {paymentId: payment.id}) }}"><span class="glyphicon glyphicon-eye-open"></span> {{ 'layout.show'|trans }}</a>
{% if payment.captureable %}
<a class="btn btn-sm btn-success" href="{{ path('loevgaard_dandomain_altapay_payment_capture', {paymentId: payment.id}) }}"><span class="glyphicon glyphicon-download"></span> {{ 'payment.label.capture'|trans }}</a>
{% endif %}
{% if payment.refundable %}
<button class="btn btn-sm btn-warning btn-refund" data-refundable-amount="{{ payment.refundableAmount.amount }}" data-form-action="{{ path('loevgaard_dandomain_altapay_payment_refund', {paymentId: payment.id}) }}"><span class="glyphicon glyphicon-upload"></span> {{ 'payment.label.refund'|trans }}</button>
{% endif %}
{% if payment.altapayId %}
<a class="btn btn-sm btn-default" href="{{ path('loevgaard_dandomain_altapay_redirect_to_altapay_payment', {paymentId: payment.id}) }}" target="_blank"><span class="glyphicon glyphicon-new-window"></span> {{ 'payment.label.open_in_altapay'|trans }}</a>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
<form action="" method="post">
<table class="table table-hover table-striped">
<thead>
<tr>
<th><input type="checkbox" class="input-select-all" title=""></th>
<th>{{ 'payment.label.order_id'|trans }}</th>
<th>{{ 'payment.label.payment_method'|trans }}</th>
<th>{{ 'payment.label.customer_name'|trans }}</th>
<th>{{ 'payment.label.total'|trans }}</th>
<th>{{ 'payment.label.refunded_amount'|trans }}</th>
<th>{{ 'layout.actions'|trans }}</th>
</tr>
</thead>
<tbody>
{% for payment in payments %}
<tr>
<td><input type="checkbox" name="payments[]" value="{{ payment.id }}" title=""></td>
<td>{{ payment.orderId }}</td>
<td>{{ payment.paymentMethod }}</td>
<td>{{ payment.customerName }}</td>
<td>{{ payment.totalAmount|money_localized_format }}</td>
<td>{{ payment.refundedAmount|money_localized_format }}</td>
<td nowrap>
<a class="btn btn-sm btn-default" href="{{ path('loevgaard_dandomain_altapay_payment_show', {paymentId: payment.id}) }}"><span class="glyphicon glyphicon-eye-open"></span> {{ 'layout.show'|trans }}</a>
{% if payment.captureable %}
<a class="btn btn-sm btn-success" href="{{ path('loevgaard_dandomain_altapay_payment_capture', {paymentId: payment.id}) }}"><span class="glyphicon glyphicon-download"></span> {{ 'payment.label.capture'|trans }}</a>
{% endif %}
{% if payment.refundable %}
<button class="btn btn-sm btn-warning btn-refund" data-refundable-amount="{{ payment.refundableAmount.amount }}" data-form-action="{{ path('loevgaard_dandomain_altapay_payment_refund', {paymentId: payment.id}) }}"><span class="glyphicon glyphicon-upload"></span> {{ 'payment.label.refund'|trans }}</button>
{% endif %}
{% if payment.altapayId %}
<a class="btn btn-sm btn-default" href="{{ path('loevgaard_dandomain_altapay_redirect_to_altapay_payment', {paymentId: payment.id}) }}" target="_blank"><span class="glyphicon glyphicon-new-window"></span> {{ 'payment.label.open_in_altapay'|trans }}</a>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr>
<td colspan="7">
<select class="form-control" name="bulkOperation" title="">
<option value=""></option>
<option value="capture">Capture</option>
</select>
<button type="submit">{{ 'layout.submit'|trans }}</button>
</td>
</tr>
</tfoot>
</table>
</form>
{{ knp_pagination_render(payments) }}
{% else %}
<div class="alert alert-info">{{ 'payment.index.empty_collection'|trans }}</div>
{% endif %}

<script>
$(function () {
$('.input-select-all').on('change', function () {
$('input[type="checkbox"]').prop('checked', $(this).prop('checked'));
});
$('input[type="checkbox"]').on('change', function () {
if($(this).prop('checked')) {
if ($('input[type="checkbox"]:checked').length === $('input[type="checkbox"]').length) {
$(".input-select-all").prop('checked', true);
}
} else {
$('.input-select-all').prop('checked', false);
}
});
});
</script>

{% include "@LoevgaardDandomainAltapay/payment/partial/modal_refund.html.twig" %}

0 comments on commit 38e9809

Please sign in to comment.