diff --git a/api/config_sample.php b/api/config_sample.php index e89e01bec..4d20ddd58 100644 --- a/api/config_sample.php +++ b/api/config_sample.php @@ -266,8 +266,6 @@ $use_shipping_service = null; $use_shipping_service_nde = False; $use_shipping_service_incoming_shipments = null; - $use_shipping_service_redirect = null; - $use_shipping_service_redirect_incoming_shipments = null; $shipping_service_api_user = null; $shipping_service_api_password = null; $shipping_service_app_url = null; diff --git a/api/index.php b/api/index.php index f4116e816..62259f375 100644 --- a/api/index.php +++ b/api/index.php @@ -71,7 +71,7 @@ function setupApplication($mode): Slim $facility_courier_countries, $facility_courier_countries_nde, $facility_courier_countries_link, $icat_base_url, $visit_persist_storage_dir_segment, $dhl_enable, $scale_grid, $scale_grid_end_date, $preset_proposal, $timezone, $valid_components, $enabled_container_types, $synchweb_version, $redirects, - $shipping_service_app_url, $use_shipping_service_redirect, $use_shipping_service_redirect_incoming_shipments, + $shipping_service_app_url, $use_shipping_service, $use_shipping_service_incoming_shipments, $use_shipping_service_nde, $dials_rest_url_rings, $closed_proposal_link, $ccp4_cloud_upload_url, $only_staff_can_assign, $industrial_prop_codes, $upstream_reprocessing_pipelines, $downstream_reprocessing_pipelines, @@ -100,8 +100,8 @@ function setupApplication($mode): Slim 'enabled_container_types' => $enabled_container_types, 'synchweb_version' => $synchweb_version, 'redirects' => $redirects, - 'shipping_service_app_url' => $use_shipping_service_redirect ? $shipping_service_app_url : null, - 'shipping_service_app_url_incoming' => $use_shipping_service_redirect_incoming_shipments ? $shipping_service_app_url : null, + 'shipping_service_app_url' => $use_shipping_service ? $shipping_service_app_url : null, + 'shipping_service_app_url_incoming' => $use_shipping_service_incoming_shipments ? $shipping_service_app_url : null, 'use_shipping_service_nde' => $use_shipping_service_nde, 'dials_rest_url_rings' => $dials_rest_url_rings, 'closed_proposal_link' => $closed_proposal_link, diff --git a/api/src/Page/Shipment.php b/api/src/Page/Shipment.php index f4b897ad4..f508bd9d5 100644 --- a/api/src/Page/Shipment.php +++ b/api/src/Page/Shipment.php @@ -1030,7 +1030,6 @@ function _create_dewars_shipment_request( array $dewars, string $proposal, int $session_number, - int $external_id, int $shipping_id, string $callback_url="" ): int { @@ -1038,7 +1037,7 @@ function _create_dewars_shipment_request( foreach (array_values($dewars) as $dew) { $package = [ - "external_id" => (int) $dew['DEWARID'], + "external_id" => null, "container_name" => $dew['NAME'], "serial_number" => $dew['MANUFACTURERSERIALNUMBER'], "shippable_item_type" => "CRYOGENIC_DRY_SHIPPER_CASE", @@ -1080,7 +1079,7 @@ function _create_dewars_shipment_request( $shipment_request_info = array( "proposal" => $proposal, "session_number" => $session_number, - "external_id" => $external_id, + "external_id" => null, "origin_url" => "{$protocol}://{$_SERVER['SERVER_NAME']}{$server_port}/shipments/sid/{$shipping_id}", "packages" => $packages ); @@ -1101,93 +1100,24 @@ function _dispatch_dewar_shipment_request($dewar) $dewars = [$dewar]; $proposal = $dewar['PROPOSAL']; $session_number = $dewar['VIS']; - $external_id = (int) $dewar['DEWARID']; + $dewar_id = (int) $dewar['DEWARID']; $shipping_id = (int) $dewar['SHIPPINGID']; $token = Utils::generateRandomMd5(); $this->db->pq( "UPDATE dewar SET extra = JSON_SET(IFNULL(extra, '{}'), '$.token', :1 ) WHERE dewarid=:2", - array($token, $external_id) + array($token, $dewar_id) ); - $callback_url = "/api/shipment/dewars/confirmdispatch/did/{$external_id}/token/{$token}"; - $external_shipping_id = $this->_create_dewars_shipment_request($dewars, $proposal, $session_number, $external_id, $shipping_id, $callback_url); + $callback_url = "/api/shipment/dewars/confirmdispatch/did/{$dewar_id}/token/{$token}"; + $external_shipping_id = $this->_create_dewars_shipment_request($dewars, $proposal, $session_number, $shipping_id, $callback_url); $this->db->pq( "UPDATE dewar SET externalShippingIdFromSynchrotron=:1 WHERE dewarid=:2", - array($external_shipping_id, $dewar['DEWARID']) + array($external_shipping_id, $dewar_id) ); return $external_shipping_id; } - function _dispatch_dewar_in_shipping_service($dispatch_info, $dewar) - { - global $facility_company; - global $facility_address; - global $facility_city; - global $facility_postcode; - global $facility_country; - global $facility_phone; - global $facility_contact; - global $facility_email; - - # Create shipment - $shipment_data = array( - "consignee_company_name" => $dispatch_info['LABNAME'], - "consignee_country" => $dispatch_info['COUNTRY'], - "consignee_city" => $dispatch_info['CITY'], - "consignee_post_code" => Utils::getValueOrDefault($dispatch_info['POSTCODE'], null), - "consignee_contact_name" => $dispatch_info['GIVENNAME'] . " " . $dispatch_info['FAMILYNAME'], - "consignee_contact_phone_number" => $dispatch_info['PHONENUMBER'], - "consignee_contact_email" => $dispatch_info['EMAILADDRESS'], - "shipper_company_name" => $facility_company, - "shipper_address_line1" => $facility_address, - "shipper_city" => $facility_city, - "shipper_country" => $facility_country, - "shipper_post_code" => $facility_postcode, - "shipper_contact_name" => $facility_contact, - "shipper_contact_phone_number" => $facility_phone, - "shipper_contact_email" => $facility_email, - "internal_contact_name" => $this->has_arg('LOCALCONTACT') ? $this->args['LOCALCONTACT'] : null, - "shipment_reference" => $dispatch_info['VISIT'], - "external_id" => (int) $dispatch_info['DEWARID'], - "journey_type" => ShippingService::JOURNEY_FROM_FACILITY, - "packages" => array( - array( - "external_id" => (int) $dispatch_info['DEWARID'], - "container_name" => $dewar['NAME'], - ) - ) - ); - - # Split up address. Necessary as address is a single field in ispyb - $address_lines = explode(PHP_EOL, rtrim($dispatch_info['ADDRESS'])); - $num_lines = count($address_lines); - if ($num_lines > 3) { - throw new Exception("Could not build request for shipping service: address input contains more than 3 lines (exc. city and post code)"); - } - if (isset($address_lines[0])) $shipment_data['consignee_address_line1'] = $address_lines[0]; - if (isset($address_lines[1])) $shipment_data['consignee_address_line2'] = $address_lines[1]; - if (isset($address_lines[2])) $shipment_data['consignee_address_line3'] = $address_lines[2]; - - $create = ($dewar['DEWARSTATUS'] != 'dispatch-requested'); - - try { - if ($create === true) { - $shipment_data["proposal"] = $dewar["PROPOSAL"]; - $response = $this->shipping_service->create_shipment($shipment_data); - } else { - $this->shipping_service->update_shipment($dispatch_info['DEWARID'], $shipment_data, ShippingService::JOURNEY_FROM_FACILITY); - $response = $this->shipping_service->get_shipment($dispatch_info['DEWARID'], ShippingService::JOURNEY_FROM_FACILITY); - } - $shipment_id = $response['shipmentId']; - $this->shipping_service->dispatch_shipment($shipment_id, false); - } catch (Exception $e) { - throw new Exception($e->getMessage()); - } - - return $shipment_id; - } - function _dispatch_dewar() { global $facility_country; @@ -1197,7 +1127,6 @@ function _dispatch_dewar() global $dispatch_email_intl; global $use_shipping_service, $use_shipping_service_nde; global $shipping_service_links_in_emails; - global $use_shipping_service_redirect; global $shipping_service_app_url; // Variable to store where the dewar is (Synchrotron or eBIC building) // Could map this to dewar storage locations in ISPyB to make more generic...? @@ -1282,31 +1211,16 @@ function _dispatch_dewar() if (Utils::getValueOrDefault($use_shipping_service) && ($domestic || $nde)) { if ($terms_accepted) { - if (Utils::getValueOrDefault($use_shipping_service_redirect)) { - try { - $shipment_id = $this->_dispatch_dewar_shipment_request($dew); - } catch (Exception $e) { - $error_json = json_decode($e->getMessage()); - $error_response = $error_json->content->detail ?? $e->getMessage(); - $error_status = $error_json->status ? $error_json->status : 400; // Status can be 0 - $this->_error("Shipping service error: " . json_encode($error_response), $error_status); - } - if (Utils::getValueOrDefault($shipping_service_links_in_emails)) { - $data['AWBURL'] = "{$shipping_service_app_url}/shipment-requests/{$shipment_id}/outgoing"; - } - } else { - try { - $shipment_id = $this->_dispatch_dewar_in_shipping_service($data, $dew); - if (Utils::getValueOrDefault($shipping_service_links_in_emails)) { - $data['AWBURL'] = $this->shipping_service->get_awb_pdf_url($shipment_id); - } - } catch (Exception $e) { - error_log($e); - $error_json = json_decode($e->getMessage()); - $error_response = $error_json->content->detail ?? $e->getMessage(); - $error_status = $error_json->status ? $error_json->status : 400; - $this->_error($error_response, $error_status); - } + try { + $shipment_id = $this->_dispatch_dewar_shipment_request($dew); + } catch (Exception $e) { + $error_json = json_decode($e->getMessage()); + $error_response = $error_json->content->detail ?? $e->getMessage(); + $error_status = $error_json->status ? $error_json->status : 400; // Status can be 0 + $this->_error("Shipping service error: " . json_encode($error_response), $error_status); + } + if (Utils::getValueOrDefault($shipping_service_links_in_emails)) { + $data['AWBURL'] = "{$shipping_service_app_url}/shipment-requests/{$shipment_id}/outgoing"; } } } @@ -1316,7 +1230,6 @@ function _dispatch_dewar() Utils::getValueOrDefault($use_shipping_service) && ($domestic || $nde) && $terms_accepted - && Utils::getValueOrDefault($use_shipping_service_redirect) ); if ($use_dispatch_lite_template) { @@ -3449,67 +3362,6 @@ function _get_default_dewar() } - function _book_shipment_in_shipping_service($user, $shipment, $dewars, $journey_type) { - $address_lines = explode(PHP_EOL, rtrim($user["address"])); - $contact = array( - "company_name" => $user["company"], - "address_line1" => isset($address_lines[0]) ? $address_lines[0] : null, - "address_line2" => isset($address_lines[1]) ? $address_lines[1] : null, - "address_line3" => isset($address_lines[2]) ? $address_lines[2] : null, - "city" => $user["city"], - "country" => $user["country"], - "post_code" => trim($user["postcode"]), - "contact_name" => $user["name"], - "contact_phone_number" => $user["phone"], - "contact_email" => trim($user["email"]) - ); - $shipment_data = array( - "shipment_reference" => $shipment["PROP"] . '-' . ($shipment["session_number"] ?? 0), - "external_id" => $shipment['SHIPPINGID'], - "packages" => array_map( - function($dewar) { - return array( - "external_id" => $dewar["DEWARID"], - "container_name" => $dewar["NAME"], - ); - }, - $dewars - ) - ); - - // Create or update shipment in shipping service - try { - $response = $this->shipping_service->get_shipment($shipment['SHIPPINGID'], $journey_type); - $user_shipment_role = $this->has_arg('RETURN') ? "consignee" : "shipper"; - $relabelled_contact = array_combine( - array_map(function($key) use ($user_shipment_role) {return $user_shipment_role."_".$key;}, - array_keys($contact)), - $contact); - $shipment_update_data = array_merge($response, $shipment_data, $relabelled_contact); - $this->shipping_service->update_shipment($shipment["SHIPPINGID"], $shipment_update_data, ShippingService::JOURNEY_TO_FACILITY); - } catch (\Exception $e) { - $shipment_data["proposal"] = $shipment["PROP"]; - $shipment_data["contact"] = $contact; - $response = $this->shipping_service->create_shipment_by_journey_type($shipment_data, $journey_type); - } - - // Dispatch shipment in shipping service - $shipmentId = $response["shipmentId"]; - $dispatch_details = $this->shipping_service->dispatch_shipment($shipmentId, false); - - $awb_pieces = array_map( - function($package, $index) {return array("piecenumber" => $index+1, "licenseplate" => $package["tracking_number"]);}, - $dispatch_details["packages"], - array_keys($dispatch_details["packages"]) - ); - - return array( - "awb" => $dispatch_details["tracking_number"], - "label" => $dispatch_details["air_waybill"], - "pieces" => $awb_pieces - ); - } - function _create_shipment_shipment_request($shipment, array $dewars): int { @@ -3528,7 +3380,6 @@ function _create_shipment_shipment_request($shipment, array $dewars): int $shipment['PROP'], isset($shipment['session_number']) ? $shipment['session_number'] : 0, $shipping_id, - $shipping_id, $callback_url ); @@ -3543,8 +3394,7 @@ function _create_shipment_shipment_request($shipment, array $dewars): int function _create_awb() { global $dhl_service, $dhl_service_eu, $dhl_acc, $dhl_acc_import, $facility_courier_countries, - $facility_courier_countries_nde, $use_shipping_service_incoming_shipments, - $use_shipping_service_redirect_incoming_shipments; + $facility_courier_countries_nde, $use_shipping_service_incoming_shipments; if (!$this->has_arg('prop')) $this->_error('No proposal specified'); if (!$this->has_arg('sid')) @@ -3593,7 +3443,6 @@ function _create_awb() if ( Utils::getValueOrDefault($use_shipping_service_incoming_shipments) && in_array($this->arg('COUNTRY'), $facility_courier_countries) - && Utils::getValueOrDefault($use_shipping_service_redirect_incoming_shipments) ) { if ($ship['EXTERNALSHIPPINGIDTOSYNCHROTRON']) { $this->_error("Shipping service error: Booking already exists"); @@ -3698,28 +3547,23 @@ function _create_awb() $awb = null; if (!$ship['DELIVERYAGENT_FLIGHTCODE']) { try { - if (Utils::getValueOrDefault($use_shipping_service_incoming_shipments) && $accno === $dhl_acc) { - $journey_type = $this->has_arg('RETURN') ? ShippingService::JOURNEY_FROM_FACILITY : ShippingService::JOURNEY_TO_FACILITY; - $awb = $this->_book_shipment_in_shipping_service($user, $ship, $dewars, $journey_type); - } else { - error_log("Not using shipping service for: {$ship['SHIPPINGID']}"); - $awb = $this->dhl->create_awb(array( - 'payee' => $payee, - 'accountnumber' => $accno, - 'shipperid' => $ship['PROP'], - 'service' => $product, - 'date' => $ship['DELIVERYAGENT_SHIPPINGDATE'], - 'declaredvalue' => $this->arg('DECLAREDVALUE'), - 'description' => $this->arg('DESCRIPTION'), - - 'sender' => $this->has_arg('RETURN') ? $facility : $user, - 'receiver' => $this->has_arg('RETURN') ? $user : $facility, - - 'pieces' => $pieces, - 'notification' => implode(';', $emails), - 'message' => $facility_company . ': Shipment booked from ISPyB for ' . $ship['PROP'] . ' ' . $ship['SHIPPINGNAME'] . ' containing ' . implode(',', $names) - )); - } + error_log("Not using shipping service for: {$ship['SHIPPINGID']}"); + $awb = $this->dhl->create_awb(array( + 'payee' => $payee, + 'accountnumber' => $accno, + 'shipperid' => $ship['PROP'], + 'service' => $product, + 'date' => $ship['DELIVERYAGENT_SHIPPINGDATE'], + 'declaredvalue' => $this->arg('DECLAREDVALUE'), + 'description' => $this->arg('DESCRIPTION'), + + 'sender' => $this->has_arg('RETURN') ? $facility : $user, + 'receiver' => $this->has_arg('RETURN') ? $user : $facility, + + 'pieces' => $pieces, + 'notification' => implode(';', $emails), + 'message' => $facility_company . ': Shipment booked from ISPyB for ' . $ship['PROP'] . ' ' . $ship['SHIPPINGNAME'] . ' containing ' . implode(',', $names) + )); $this->db->pq("UPDATE shipping SET deliveryagent_flightcode=:1, deliveryagent_flightcodetimestamp=CURRENT_TIMESTAMP, deliveryagent_label=:2, deliveryagent_productcode=:3, deliveryagent_flightcodepersonid=:4, shippingstatus='awb created', deliveryagent_agentname='DHL' diff --git a/api/src/Shipment/ShippingService.php b/api/src/Shipment/ShippingService.php index eb5974bb7..b9a6b82a3 100644 --- a/api/src/Shipment/ShippingService.php +++ b/api/src/Shipment/ShippingService.php @@ -9,7 +9,6 @@ class ShippingService { private $shipping_api_url; - private $shipping_app_url; public const JOURNEY_TO_FACILITY = "TO_FACILITY"; public const JOURNEY_FROM_FACILITY = "FROM_FACILITY"; @@ -41,7 +40,6 @@ function _build_headers() function __construct() { global $shipping_service_app_url; - $this->shipping_app_url = $shipping_service_app_url; $this->shipping_api_url = $shipping_service_app_url . "/api"; } @@ -98,66 +96,6 @@ function _send_request($url, $type, $data, $expected_status_code) } - function create_shipment($shipment_data) - { - return $this->_send_request( - $this->shipping_api_url . '/shipments/', - "POST", - $shipment_data, - 201 - ); - } - - - function create_shipment_by_journey_type($shipment_data, $journey_type) - { - return $this->_send_request( - $this->shipping_api_url . '/shipments/' . $journey_type, - "POST", - $shipment_data, - 201 - ); - } - - - function get_shipment($external_id, $journey_type) - { - return $this->_send_request( - $this->shipping_api_url . '/shipments/external_id/' . $external_id . '?journey_type=' . $journey_type, - "GET", - null, - 200 - ); - } - - - function update_shipment($external_id, $shipment_data, $journey_type) - { - return $this->_send_request( - $this->shipping_api_url . '/shipments/external_id/' . $external_id . '?journey_type=' . $journey_type, - "PUT", - $shipment_data, - 204 - ); - } - - - function dispatch_shipment($shipment_id, $pickup_requested) - { - $pickup_requested_str = ($pickup_requested) ? "true" : "false"; - return $this->_send_request( - $this->shipping_api_url . '/shipments/' . $shipment_id . '/dispatch?pickup_requested=' . $pickup_requested_str, - "POST", - null, - 201 - ); - } - - function get_awb_pdf_url($shipment_id) - { - return $this->shipping_app_url . '/shipments/' . $shipment_id . '/awb'; - } - function create_shipment_request($shipment_request_data) { return $this->_send_request( diff --git a/client/src/js/modules/shipment/views/dispatch.js b/client/src/js/modules/shipment/views/dispatch.js index 2918c5462..5909b1d33 100644 --- a/client/src/js/modules/shipment/views/dispatch.js +++ b/client/src/js/modules/shipment/views/dispatch.js @@ -204,12 +204,12 @@ define(['marionette', 'views/form', if (location) { self.ui.loc.val(location) if (restrictedLocations.includes(location.toLowerCase())) { - self.ui.dispatchState.text("Warning: This dewar is still on the beamline. We recommend waiting until the dewar returns to storage before requesting it's return. Dewars are not topped up with LN2 after a return is requested.") + self.ui.dispatchState.text("Warning: This dewar is still on the beamline. We recommend waiting until the dewar returns to storage before requesting its return. Dewars are not topped up with LN2 after a return is requested.") } else if ( location.startsWith('tray-') && (!historyComment || (typeof historyComment === 'object' && !historyComment.checked)) ) { - self.ui.dispatchState.text("Warning: This dewar has not had it's contents checked. We recommend asking your local contact to check the dewar's contents before requesting it's return. Dewars are not topped up with LN2 after a return is requested.") + self.ui.dispatchState.text("Warning: This dewar has not had its contents checked. We recommend asking your local contact to check the dewar's contents before requesting its return. Dewars are not topped up with LN2 after a return is requested.") } } })