View source
<?php
function commerce_invoice_ui_menu() {
$items = array();
$items['admin/commerce/config/invoice'] = array(
'title' => 'Invoice settings',
'description' => 'Configure general invoice settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'commerce_invoice_settings_form',
),
'access arguments' => array(
'configure invoice settings',
),
'file' => 'includes/commerce_invoice_ui.invoices.inc',
);
$items['admin/commerce/config/invoice/settings'] = array(
'title' => 'Settings',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items['admin/commerce/orders/%commerce_order/invoice'] = array(
'title' => 'Invoice',
'page callback' => 'commerce_invoice_ui_invoice_view_by_order',
'page arguments' => array(
3,
),
'access callback' => 'commerce_invoice_ui_access_by_order',
'access arguments' => array(
'view',
3,
),
'type' => MENU_LOCAL_TASK,
'weight' => -5,
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
);
$items['user/%user/invoices/%commerce_invoice'] = array(
'title callback' => 'commerce_invoice_ui_invoice_title',
'title arguments' => array(
3,
),
'page callback' => 'commerce_invoice_ui_invoice_view',
'page arguments' => array(
3,
'customer',
FALSE,
),
'access callback' => 'commerce_invoice_access',
'access arguments' => array(
'view',
3,
),
);
return $items;
}
function commerce_invoice_ui_views_api() {
return array(
'api' => 3,
'path' => drupal_get_path('module', 'commerce_invoice_ui') . '/includes/views',
);
}
function commerce_invoice_ui_invoice_title($invoice) {
return t('Invoice @number', array(
'@number' => $invoice->invoice_number,
));
}
function commerce_invoice_ui_set_breadcrumb($view_mode = 'administrator') {
$breadcrumb = array();
if ($view_mode == 'administrator') {
$breadcrumb = array(
l(t('Home'), '<front>'),
l(t('Administration'), 'admin'),
l(t('Store'), 'admin/commerce'),
l(t('Orders', array(), array(
'context' => 'a drupal commerce order',
)), 'admin/commerce/orders'),
);
}
drupal_set_breadcrumb($breadcrumb);
}
function commerce_invoice_ui_invoice_view($invoice, $view_mode = 'administrator', $breadcrumb = TRUE) {
if ($breadcrumb) {
commerce_invoice_ui_set_breadcrumb();
}
drupal_add_css(drupal_get_path('module', 'commerce_order') . '/theme/commerce_order.css');
return entity_view('commerce_invoice', array(
$invoice->invoice_id => $invoice,
), $view_mode, NULL, TRUE);
}
function commerce_invoice_ui_invoice_view_by_order($order, $view_mode = 'administrator', $breadcrumb = TRUE) {
$invoice = commerce_invoice_load_by_order_id($order->order_id);
if ($invoice) {
return commerce_invoice_ui_invoice_view($invoice, $view_mode, $breadcrumb);
}
else {
drupal_set_message(t('The invoice for this order has not been generated yet'), 'warning');
return '';
}
}
function commerce_invoice_ui_access_by_order($op, $order = NULL, $account = NULL) {
$invoice = commerce_invoice_load_by_order_id($order->order_id);
if ($invoice) {
return commerce_invoice_access($op, $invoice, $account, 'commerce_invoice');
}
else {
return FALSE;
}
}
function commerce_invoice_ui_entity_info_alter(&$entity_info) {
$entity_info['commerce_invoice']['bundles']['commerce_invoice']['admin'] = array(
'path' => 'admin/commerce/config/invoice',
'real path' => 'admin/commerce/config/invoice',
'access arguments' => array(
'configure invoice settings',
),
);
}