You are here

function uc_shipping_order_shipments in Ubercart 6.2

Same name and namespace in other branches
  1. 5 shipping/uc_shipping/uc_shipping.module \uc_shipping_order_shipments()
  2. 7.3 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_shipping_menu().

File

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

Code

function uc_shipping_order_shipments($order) {
  $result = db_query("SELECT * FROM {uc_shipments} WHERE order_id = %d", $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();
  while ($shipment = db_fetch_object($result)) {
    $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, 'custom', variable_get('uc_date_format_default', 'm/d/Y'));
    $row[] = format_date($shipment->expected_delivery, 'custom', variable_get('uc_date_format_default', 'm/d/Y'));
    $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)) {
    drupal_set_message(t('No shipments have been made for this order.'));
    drupal_goto('admin/store/orders/' . $order->order_id . '/shipments/new');
  }
  $output = theme('table', $header, $rows);
  $packages = db_result(db_query("SELECT COUNT(*) FROM {uc_packages} WHERE order_id = %d AND sid IS NULL", $order->order_id));
  if ($packages) {
    $output .= l(t('Make a new shipment'), 'admin/store/orders/' . $order->order_id . '/shipments/new');
  }
  else {
    $result = db_query("SELECT op.order_product_id, CASE WHEN COUNT(pp.qty) = 0 THEN 0 ELSE SUM(op.qty) / COUNT(pp.qty) END AS total, SUM(pp.qty) AS packaged FROM {uc_order_products} AS op LEFT JOIN {uc_packaged_products} AS pp ON op.order_product_id = pp.order_product_id WHERE op.order_id = %d AND op.data LIKE '%%%s%%' GROUP BY op.order_product_id HAVING SUM(pp.qty) IS NULL OR CASE WHEN COUNT(pp.qty) = 0 THEN 0 ELSE SUM(op.qty) / COUNT(pp.qty) END > SUM(pp.qty)", $order->order_id, 's:9:"shippable";s:1:"1";');
    if (db_fetch_object($result)) {
      $output .= l(t('Put products into packages to make shipments.'), 'admin/store/orders/' . $order->order_id . '/packages/new');
    }
  }
  return $output;
}