You are here

function uc_shipping_order_shipments in Ubercart 5

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

Display a list of shipments for an order.

Parameters

$order_id: The order's id.

1 string reference to 'uc_shipping_order_shipments'
uc_shipping_menu in shipping/uc_shipping/uc_shipping.module
Implementation of hook_shipping_menu().

File

shipping/uc_shipping/uc_shipping.module, line 582
Organizes ordered products into packages and sets them up for shipment. Shipping method modules may add functionality to generate shipping labels and tracking numbers.

Code

function uc_shipping_order_shipments($order_id) {
  $result = db_query("SELECT * FROM {uc_shipments} WHERE order_id = %d", $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' => 3,
    ),
  );
  $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_id . '/shipments/' . $shipment->sid . '/view');
    $row[] = l(t('edit'), 'admin/store/orders/' . $order_id . '/shipments/' . $shipment->sid . '/edit');
    $row[] = l(t('delete'), 'admin/store/orders/' . $order_id . '/shipments/' . $shipment->sid . '/delete');
    $rows[] = $row;
  }
  if (empty($rows)) {
    $rows[] = array(
      array(
        'data' => t('No shipments have been made for this order.'),
        'colspan' => 10,
      ),
    );
  }
  $output = theme('table', $header, $rows);
  $packages = db_num_rows(db_query("SELECT * FROM {uc_packages} WHERE order_id = %d AND sid IS NULL", $order_id));
  if ($packages) {
    $output .= l(t('Make a new shipment'), 'admin/store/orders/' . $order_id . '/shipments/new');
  }
  else {
    $result = db_query("SELECT op.order_product_id, CAST(SUM(op.qty) / COUNT(pp.qty) AS UNSIGNED) 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 CAST(SUM(op.qty) / COUNT(pp.qty) AS UNSIGNED) > SUM(pp.qty)", $order_id, 's:9:"shippable";s:1:"1";');
    if (db_num_rows($result)) {
      $output .= l(t('Put products into packages to make shipments.'), 'admin/store/orders/' . $order_id . '/packages/new');
    }
  }
  return $output;
}