You are here

function uc_shipping_order_shipments in Ubercart 7.3

Same name and namespace in other branches
  1. 5 shipping/uc_shipping/uc_shipping.module \uc_shipping_order_shipments()
  2. 6.2 shipping/uc_shipping/uc_shipping.admin.inc \uc_shipping_order_shipments()

Displays a list of shipments for an order.

Parameters

$order: The order object.

1 string reference to 'uc_shipping_order_shipments'
uc_shipping_menu in shipping/uc_shipping/uc_shipping.module
Implements hook_menu().

File

shipping/uc_shipping/uc_shipping.admin.inc, line 501
Shipping administration menu items.

Code

function uc_shipping_order_shipments($order) {
  $result = db_query("SELECT * FROM {uc_shipments} WHERE order_id = :id", array(
    ':id' => $order->order_id,
  ));
  $header = array(
    t('Shipment ID'),
    t('Name'),
    t('Company'),
    t('Destination'),
    t('Ship date'),
    t('Estimated delivery'),
    t('Tracking number'),
    array(
      'data' => t('Actions'),
      'colspan' => 5,
    ),
  );
  $rows = array();
  foreach ($result as $shipment) {
    $row = array();
    $row[] = $shipment->sid;
    $row[] = check_plain($shipment->d_first_name) . ' ' . check_plain($shipment->d_last_name);
    $row[] = check_plain($shipment->d_company);
    $row[] = check_plain($shipment->d_city) . ', ' . uc_get_zone_code($shipment->d_zone) . ' ' . check_plain($shipment->d_postal_code);
    $row[] = format_date($shipment->ship_date, 'uc_store');
    $row[] = format_date($shipment->expected_delivery, 'uc_store');
    $row[] = is_null($shipment->tracking_number) ? t('n/a') : check_plain($shipment->tracking_number);
    $row[] = l(t('view'), 'admin/store/orders/' . $order->order_id . '/shipments/' . $shipment->sid . '/view');
    $row[] = l(t('edit'), 'admin/store/orders/' . $order->order_id . '/shipments/' . $shipment->sid . '/edit');
    $row[] = l(t('print'), 'admin/store/orders/' . $order->order_id . '/shipments/' . $shipment->sid . '/print');
    $row[] = l(t('packing slip'), 'admin/store/orders/' . $order->order_id . '/shipments/' . $shipment->sid . '/packing_slip');
    $row[] = l(t('delete'), 'admin/store/orders/' . $order->order_id . '/shipments/' . $shipment->sid . '/delete');
    $rows[] = $row;
  }
  if (empty($rows)) {
    if (!db_query("SELECT COUNT(*) FROM {uc_packages} WHERE order_id = :id", array(
      ':id' => $order->order_id,
    ))
      ->fetchField()) {
      drupal_set_message(t("This order's products have not been organized into packages."));
      drupal_goto('admin/store/orders/' . $order->order_id . '/packages/new');
    }
    else {
      drupal_set_message(t('No shipments have been made for this order.'));
      drupal_goto('admin/store/orders/' . $order->order_id . '/shipments/new');
    }
  }
  $build['shipments'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
  );
  return $build;
}