@@ -153,6 +153,7 @@ class Shipment extends Page
153153 'AWBURL ' => '[\w\:\/\.\-]+ ' ,
154154 'PROPOSALTYPE ' => '\w+ ' ,
155155 'pickup_confirmation_code ' => '\w+ ' ,
156+ 'status ' => '\w+ ' ,
156157
157158 'manifest ' => '\d ' ,
158159 'currentuser ' => '\d ' ,
@@ -209,7 +210,7 @@ class Shipment extends Page
209210 array ('/dewars/transfer ' , 'post ' , '_transfer_dewar ' ),
210211 array ('/dewars/dispatch ' , 'post ' , '_dispatch_dewar ' ),
211212 array ('/dewars/confirmdispatch/did/:did/token/:TOKEN ' , 'post ' , '_dispatch_dewar_confirmation ' ),
212- array ('/dewars/confirmpickup/sid/:sid/token/:TOKEN ' , 'post ' , '_pickup_dewar_confirmation ' ),
213+ array ('/dewars/confirmpickup/sid/:sid/token/:TOKEN ' , 'post ' , '_incoming_shipment_confirmation ' ),
213214
214215 array ('/dewars/tracking(/:DEWARID) ' , 'get ' , '_get_dewar_tracking ' ),
215216
@@ -1486,15 +1487,26 @@ function _dispatch_dewar_confirmation()
14861487 $ this ->_output (1 );
14871488 }
14881489
1489- function _pickup_dewar_confirmation ()
1490+ function _incoming_shipment_confirmation ()
14901491 {
14911492 if (!$ this ->has_arg ('sid ' ))
14921493 $ this ->_error ('No shipment specified ' );
14931494 if (!$ this ->has_arg ('TOKEN ' ))
14941495 $ this ->_error ('No token specified ' );
1495- if (!$ this ->has_arg ('tracking_number ' ))
1496- $ this ->_error ('No tracking number specified ' );
1496+ if (!$ this ->has_arg ('status ' ))
1497+ $ this ->_error ('No status specified ' );
1498+
1499+ if ($ this ->arg ('status ' ) === 'CREATED ' ) {
1500+ $ this ->_cancel_pickup_dewar_confirmation ();
1501+ } else if ($ this ->arg ('status ' ) === 'BOOKED ' || $ this ->arg ('status ' ) === 'PENDING ' ) {
1502+ $ this ->_pickup_dewar_confirmation ();
1503+ } else {
1504+ $ this ->_error ('Invalid status ' );
1505+ }
1506+ }
14971507
1508+ function _pickup_dewar_confirmation ()
1509+ {
14981510 // Check token against each dewar
14991511 $ dewars = $ this ->db ->pq (
15001512 "SELECT d.dewarid,
@@ -1504,29 +1516,42 @@ function _pickup_dewar_confirmation()
15041516 array ($ this ->arg ('sid ' ))
15051517 );
15061518
1519+ if ($ this ->arg ('status ' ) === 'BOOKED ' ) {
1520+ if (!$ this ->has_arg ('tracking_number ' ))
1521+ $ this ->_error ('No tracking number specified ' );
1522+ $ tracking = $ this ->arg ('tracking_number ' );
1523+ $ status = 'awb created ' ;
1524+ } else if ($ this ->arg ('status ' ) === 'PENDING ' ) {
1525+ $ tracking = '' ;
1526+ $ status = 'awb requested ' ;
1527+ } else {
1528+ $ this ->_error ('Invalid status ' );
1529+ }
1530+
1531+
15071532 foreach ($ dewars as $ dew ) {
15081533 if ($ this ->arg ('TOKEN ' ) !== $ dew ['TOKEN ' ]) {
15091534 $ this ->_error ('Incorrect token ' );
15101535 }
15111536 }
15121537
1513- $ this ->db ->pq ("UPDATE shipping set shippingstatus='awb created' WHERE shippingid=:1 " , array ($ this ->arg ('sid ' )));
1538+ $ this ->db ->pq ("UPDATE shipping set shippingstatus=:1 WHERE shippingid=:2 " , array ($ status , $ this ->arg ('sid ' )));
15141539
15151540 foreach ($ dewars as $ dew ) {
15161541 // Update the dewar status and storage location
15171542 $ this ->db ->pq (
15181543 "UPDATE dewar
1519- set dewarstatus='awb created' , storagelocation='off-site', trackingnumbertosynchrotron=:2
1544+ set dewarstatus=:2 , storagelocation='off-site', trackingnumbertosynchrotron=:3
15201545 WHERE dewarid=:1 " ,
1521- array ($ dew ['DEWARID ' ], $ this -> arg ( ' tracking_number ' ) )
1546+ array ($ dew ['DEWARID ' ], $ status , $ tracking )
15221547 );
15231548
15241549 // Update dewar transport history
15251550 $ this ->db ->pq (
15261551 "INSERT INTO dewartransporthistory (dewartransporthistoryid,dewarid,dewarstatus,storagelocation,arrivaldate)
1527- VALUES (s_dewartransporthistory.nextval,:1,'awb created' ,'off-site',CURRENT_TIMESTAMP)
1552+ VALUES (s_dewartransporthistory.nextval,:1,:2 ,'off-site',CURRENT_TIMESTAMP)
15281553 RETURNING dewartransporthistoryid INTO :id " ,
1529- array ($ dew ['DEWARID ' ])
1554+ array ($ dew ['DEWARID ' ], $ status )
15301555 );
15311556 }
15321557
@@ -1551,6 +1576,41 @@ function _pickup_dewar_confirmation()
15511576 $ this ->_output (1 );
15521577 }
15531578
1579+ function _cancel_pickup_dewar_confirmation ()
1580+ {
1581+ // Check token against each dewar
1582+ $ dewars = $ this ->db ->pq (
1583+ "SELECT d.dewarid, json_unquote(json_extract(d.extra, '$.token')) as token, storagelocation
1584+ FROM dewar d
1585+ WHERE d.shippingid=:1 " ,
1586+ array ($ this ->arg ('sid ' ))
1587+ );
1588+
1589+ foreach ($ dewars as $ dew ) {
1590+ if ($ this ->arg ('TOKEN ' ) !== $ dew ['TOKEN ' ]) {
1591+ $ this ->_error ('Incorrect token ' );
1592+ }
1593+ }
1594+
1595+ $ this ->db ->pq ("UPDATE shipping set shippingstatus='pickup cancelled' WHERE shippingid=:1 " , array ($ this ->arg ('sid ' )));
1596+
1597+ foreach ($ dewars as $ dew ) {
1598+ // Update the dewar status
1599+ $ this ->db ->pq ("UPDATE dewar set dewarstatus='pickup cancelled' WHERE dewarid=:1 " , array ($ dew ['DEWARID ' ]));
1600+
1601+ // Update dewar transport history
1602+ $ loc = Utils::getValueOrDefault ($ dew ['STORAGELOCATION ' ], '' );
1603+ $ this ->db ->pq (
1604+ "INSERT INTO dewartransporthistory (dewartransporthistoryid,dewarid,dewarstatus,storagelocation,arrivaldate)
1605+ VALUES (s_dewartransporthistory.nextval,:1,'pickup cancelled',:2,CURRENT_TIMESTAMP)
1606+ RETURNING dewartransporthistoryid INTO :id " ,
1607+ array ($ dew ['DEWARID ' ], $ loc )
1608+ );
1609+ }
1610+
1611+ $ this ->_output (1 );
1612+ }
1613+
15541614 function _get_dewar_tracking ()
15551615 {
15561616 if (!$ this ->has_arg ('prop ' )) {
0 commit comments