Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/src/Controllers/AuthenticationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private function checkAuthRequiredForSpecificSituations($parts): bool
($parts[0] == 'shipment' && $parts[1] == 'containers' && $parts[2] == 'history' && in_array($_SERVER["REMOTE_ADDR"], $bcr)) ||

# Allow shipping service to update dewar status
($parts[0] == 'shipment' && $parts[1] == 'dewars' && $parts[2] == 'confirmdispatch')
($parts[0] == 'shipment' && $parts[1] == 'dewars' && ($parts[2] == 'confirmdispatch' || $parts[2] == 'confirmpickup'))
)
{
$need_auth = false;
Expand Down
1 change: 0 additions & 1 deletion api/src/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ function auth($require_staff)
if ($require_staff)
{
$auth = $this->staff;

}
// Barcode Scanners
else if ($this->bcr() && !$this->user->loginId)
Expand Down
27 changes: 13 additions & 14 deletions api/src/Page/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ class Contact extends Page
# Get List of Lab Contacts
function _get_contacts() {
if (!$this->has_arg('prop')) $this->_error('No proposal specified');

$args = array($this->proposalid);
$where = 'WHERE c.proposalid = :1';

if ($this->has_arg('cid')) {
$where .= ' AND c.labcontactid=:'.(sizeof($args)+1);
array_push($args, $this->arg('cid'));
Expand All @@ -63,37 +63,36 @@ function _get_contacts() {
$pp = $this->has_arg('per_page') ? $this->arg('per_page') : 15;
$start = 0;
$end = $pp;

if ($this->has_arg('page')) {
$pg = $this->arg('page') - 1;
$start = $pg*$pp;
$end = $pg*$pp+$pp;
}

$st = sizeof($args)+1;
$en = $st + 1;
array_push($args, $start);
array_push($args, $end);

$order = 'c.labcontactid DESC';
$rows = $this->db->paginate("SELECT c.labcontactid, c.cardname, pe.givenname, pe.familyname, pe.phonenumber, l.name as labname, l.address, l.city, l.country, c.courieraccount, c.billingreference, c.defaultcourriercompany, c.dewaravgcustomsvalue, c.dewaravgtransportvalue, pe.emailaddress, l.postcode, l.country

$rows = $this->db->paginate("SELECT c.labcontactid, c.cardname, pe.givenname, pe.familyname, pe.phonenumber, IF(pe.login IS NOT NULL, pe.login, IF(pe.externalid IS NOT NULL, 'External', NULL)) AS login, l.name as labname, l.address, l.city, l.country, c.courieraccount, c.billingreference, c.defaultcourriercompany, c.dewaravgcustomsvalue, c.dewaravgtransportvalue, pe.emailaddress, l.postcode, l.country
FROM labcontact c
INNER JOIN person pe ON c.personid = pe.personid
INNER JOIN laboratory l ON l.laboratoryid = pe.laboratoryid
INNER JOIN proposal p ON p.proposalid = c.proposalid
$where ORDER BY $order", $args);

if ($this->has_arg('cid')) {
if (sizeof($rows))$this->_output($rows[0]);
else $this->_error('No such contact');

} else $this->_output(array('total' => $tot,
'data' => $rows,
));
} else {
$this->_output(array('total' => $tot, 'data' => $rows));
}
}


# ------------------------------------------------------------------------
# Update field for lab contact
function _update_contact() {
Expand Down
84 changes: 78 additions & 6 deletions api/src/Page/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class Shipment extends Page
'TOKEN' => '\w+',
'tracking_number' => '\w+',
'AWBURL' => '[\w\:\/\.\-]+',
'pickup_confirmation_code' => '\w+',

'manifest' => '\d',
'currentuser' => '\d',
Expand Down Expand Up @@ -200,6 +201,7 @@ class Shipment extends Page
array('/dewars/transfer', 'post', '_transfer_dewar'),
array('/dewars/dispatch', 'post', '_dispatch_dewar'),
array('/dewars/confirmdispatch/did/:did/token/:TOKEN', 'post', '_dispatch_dewar_confirmation'),
array('/dewars/confirmpickup/sid/:sid/token/:TOKEN', 'post', '_pickup_dewar_confirmation'),

array('/dewars/tracking(/:DEWARID)', 'get', '_get_dewar_tracking'),

Expand Down Expand Up @@ -1444,7 +1446,70 @@ function _dispatch_dewar_confirmation()
$this->_output(1);
}

function _pickup_dewar_confirmation()
{
if (!$this->has_arg('sid'))
$this->_error('No shipment specified');
if (!$this->has_arg('TOKEN'))
$this->_error('No token specified');
if (!$this->has_arg('tracking_number'))
$this->_error('No tracking number specified');

// Check token against each dewar
$dewars = $this->db->pq(
"SELECT d.dewarid,
json_unquote(json_extract(d.extra, '$.token')) as token
FROM dewar d
WHERE d.shippingid=:1",
array($this->arg('sid'))
);

foreach ($dewars as $dew) {
if ($this->arg('TOKEN') !== $dew['TOKEN']) {
$this->_error('Incorrect token');
}
}

$this->db->pq("UPDATE shipping set shippingstatus='awb created' WHERE shippingid=:1", array($this->arg('sid')));

foreach ($dewars as $dew) {
// Update the dewar status and storage location
$this->db->pq(
"UPDATE dewar
set dewarstatus='awb created', storagelocation='off-site', trackingnumbertosynchrotron=:2
WHERE dewarid=:1",
array($dew['DEWARID'], $this->arg('tracking_number'))
);

// Update dewar transport history
$this->db->pq(
"INSERT INTO dewartransporthistory (dewartransporthistoryid,dewarid,dewarstatus,storagelocation,arrivaldate)
VALUES (s_dewartransporthistory.nextval,:1,'awb created','off-site',CURRENT_TIMESTAMP)
RETURNING dewartransporthistoryid INTO :id",
array($dew['DEWARID'])
);
}

if ($this->has_arg('pickup_confirmation_code')) {

$this->db->pq("UPDATE shipping set shippingstatus='pickup booked' WHERE shippingid=:1", array($this->arg('sid')));

foreach ($dewars as $dew) {
// Update the dewar status
$this->db->pq("UPDATE dewar set dewarstatus='pickup booked' WHERE dewarid=:1", array($dew['DEWARID']));

// Update dewar transport history (plus 1s so history appears in order)
$this->db->pq(
"INSERT INTO dewartransporthistory (dewartransporthistoryid,dewarid,dewarstatus,storagelocation,arrivaldate)
VALUES (s_dewartransporthistory.nextval,:1,'pickup booked','off-site',CURRENT_TIMESTAMP+1)
RETURNING dewartransporthistoryid INTO :id",
array($dew['DEWARID'])
);
}
}

$this->_output(1);
}

function _get_dewar_tracking()
{
Expand Down Expand Up @@ -3086,20 +3151,27 @@ function($package, $index) {return array("piecenumber" => $index+1, "licenseplat
function _create_shipment_shipment_request($shipment, array $dewars): int
{

// if (!is_null($shipment['EXTERNALSHIPPINGIDTOSYNCHROTRON'])) {
// return $shipment['EXTERNALSHIPPINGIDTOSYNCHROTRON'];
// }
$shipping_id = (int) $shipment['SHIPPINGID'];

$token = md5(openssl_random_pseudo_bytes(7));
$this->db->pq(
"UPDATE dewar SET extra = JSON_SET(IFNULL(extra, '{}'), '$.token', :1 ) WHERE shippingid=:2",
array($token, $shipping_id)
);

$callback_url = "/api/shipment/dewars/confirmpickup/sid/{$shipping_id}/token/{$token}";

$external_shipping_id = $this->_create_dewars_shipment_request(
$dewars,
$shipment['PROP'],
(int) $shipment['SHIPPINGID'],
(int) $shipment['SHIPPINGID']
$shipping_id,
$shipping_id,
$callback_url
);

$this->db->pq(
"UPDATE shipping SET externalShippingIdToSynchrotron=:1 WHERE shippingId=:2",
array($external_shipping_id, $shipment['SHIPPINGID'])
array($external_shipping_id, $shipping_id)
);
return $external_shipping_id;
}
Expand Down
Loading
Loading