You are here

function payment_line_items in Payment 7

Return a render array containing a Payment's line items.

Parameters

Payment $payment:

Return value

array

2 calls to payment_line_items()
PaymentEntityController::view in ./payment.classes.inc
Implements EntityAPIControllerInterface.
payment_form_embedded in ./payment.ui.inc
Builds common elements for a payment add/edit form.

File

./payment.ui.inc, line 542
The Payment user interface.

Code

function payment_line_items(Payment $payment) {
  $rows = array();
  foreach ($payment->line_items as $name => $line_item) {
    $rows[] = array(
      'data' => array(
        t($line_item->description, $line_item->description_arguments),
        $line_item->quantity,
        payment_amount_human_readable($line_item
          ->unitAmount(TRUE), $payment->currency_code),
        payment_amount_human_readable($line_item
          ->totalAmount(TRUE), $payment->currency_code),
        t('!amount (!percentage%)', array(
          '!amount' => payment_amount_human_readable($line_item->amount * $line_item->tax_rate, $payment->currency_code),
          '!percentage' => $line_item->tax_rate * 100,
        )),
      ),
      'class' => array(
        'payment-line_item-' . $name,
      ),
    );
  }
  $rows[] = array(
    'data' => array(
      array(
        'data' => t('Total amount'),
        'colspan' => 3,
      ),
      payment_amount_human_readable($payment
        ->totalAmount(TRUE), $payment->currency_code),
      '',
    ),
    'class' => array(
      'payment-line_item-total',
    ),
  );
  $build = array(
    '#type' => 'markup',
    '#markup' => theme('table', array(
      'header' => array(
        t('Description'),
        t('Quantity'),
        t('Amount'),
        t('Total'),
        t('Tax'),
      ),
      'rows' => $rows,
    )),
  );
  return $build;
}