@@ -38,7 +38,7 @@ class Shipment extends Page
3838
3939 // Dewar Fields
4040 'CODE ' => '([\w\-])+ ' ,
41- 'FACILITYCODE ' => '([\w\-])+ ' ,
41+ 'FACILITYCODE ' => '([\w\-])* ' ,
4242 'NEWFACILITYCODE ' => '([\w\-])+ ' ,
4343 'TRACKINGNUMBERTOSYNCHROTRON ' => '\w* ' ,
4444 'TRACKINGNUMBERFROMSYNCHROTRON ' => '\w* ' ,
@@ -1734,7 +1734,7 @@ function _get_dewars()
17341734 CONCAT(p.proposalcode, p.proposalnumber, '-', se2.visit_number) as udcfirstexperiment,
17351735 r.labcontactid, se.beamlineoperator as localcontact, se.beamlinename,
17361736 TO_CHAR(se.startdate, 'HH24:MI DD-MM-YYYY') as firstexperimentst, d.firstexperimentid,
1737- s.shippingid, s.shippingname, d. facilitycode, count(c.containerid) as ccount,
1737+ s.shippingid, s.shippingname, IFNULL(r.facilitycode, d.facilitycode) as facilitycode, count(c.containerid) as ccount,
17381738 (case when se.visit_number > 0 then (CONCAT(p.proposalcode, p.proposalnumber, '-', se.visit_number)) else '' end) as exp,
17391739 d.code, d.barcode, d.storagelocation, d.dewarstatus, d.dewarid,
17401740 d.trackingnumbertosynchrotron, d.trackingnumberfromsynchrotron, d.externalShippingIdFromSynchrotron,
@@ -1746,11 +1746,11 @@ function _get_dewars()
17461746 INNER JOIN proposal p ON p.proposalid = s.proposalid
17471747 LEFT OUTER JOIN blsession se ON d.firstexperimentid = se.sessionid
17481748 LEFT OUTER JOIN blsession se2 ON c.sessionid = se2.sessionid
1749- LEFT OUTER JOIN dewarregistry r ON r.facilitycode = d.facilitycode
1749+ LEFT OUTER JOIN dewarregistry r ON r.dewarregistryid = d.dewarregistryid
17501750 LEFT OUTER JOIN labcontact lc ON s.sendinglabcontactid = lc.labcontactid
17511751 LEFT OUTER JOIN person pe ON lc.personid = pe.personid
17521752 WHERE $ where
1753- GROUP BY CONCAT(p.proposalcode, p.proposalnumber, '-', se.visit_number), r.labcontactid, se.beamlineoperator, TO_CHAR(se.startdate, 'HH24:MI DD-MM-YYYY'), (case when se.visit_number > 0 then (CONCAT(p.proposalcode, p.proposalnumber, '-', se.visit_number)) else '' end),s.shippingid, s.shippingname, d.code, d.barcode, d.storagelocation, d.dewarstatus, d.dewarid, d.trackingnumbertosynchrotron, d.trackingnumberfromsynchrotron, d. facilitycode, d.firstexperimentid
1753+ GROUP BY CONCAT(p.proposalcode, p.proposalnumber, '-', se.visit_number), r.labcontactid, se.beamlineoperator, TO_CHAR(se.startdate, 'HH24:MI DD-MM-YYYY'), (case when se.visit_number > 0 then (CONCAT(p.proposalcode, p.proposalnumber, '-', se.visit_number)) else '' end),s.shippingid, s.shippingname, d.code, d.barcode, d.storagelocation, d.dewarstatus, d.dewarid, d.trackingnumbertosynchrotron, d.trackingnumberfromsynchrotron, facilitycode, d.firstexperimentid
17541754 ORDER BY $ order " , $ args );
17551755
17561756 if ($ this ->has_arg ('did ' )) {
@@ -1784,6 +1784,7 @@ function _add_dewar()
17841784 $ to = $ this ->has_arg ('TRACKINGNUMBERTOSYNCHROTRON ' ) ? $ this ->arg ('TRACKINGNUMBERTOSYNCHROTRON ' ) : '' ;
17851785 $ from = $ this ->has_arg ('TRACKINGNUMBERFROMSYNCHROTRON ' ) ? $ this ->arg ('TRACKINGNUMBERFROMSYNCHROTRON ' ) : '' ;
17861786 $ fc = $ this ->has_arg ('FACILITYCODE ' ) ? $ this ->arg ('FACILITYCODE ' ) : '' ;
1787+ $ drid = $ this ->_get_dewarregistryid ($ fc );
17871788 $ wg = $ this ->has_arg ('WEIGHT ' ) ? $ this ->arg ('WEIGHT ' ) : $ dewar_weight ;
17881789 $ exp = null ;
17891790 $ source = $ this ->has_arg ('SOURCE ' ) ? $ this ->arg ('SOURCE ' ) : null ;
@@ -1794,9 +1795,9 @@ function _add_dewar()
17941795 }
17951796
17961797 $ this ->db ->pq (
1797- "INSERT INTO dewar (dewarid,code,trackingnumbertosynchrotron,trackingnumberfromsynchrotron,shippingid,bltimestamp,dewarstatus,firstexperimentid,facilitycode,weight,source)
1798- VALUES (s_dewar.nextval,:1,:2,:3,:4,CURRENT_TIMESTAMP,'opened',:5,:6,:7,IFNULL(:8 ,CURRENT_USER)) RETURNING dewarid INTO :id " ,
1799- array ($ this ->arg ('CODE ' ), $ to , $ from , $ this ->arg ('SHIPPINGID ' ), $ exp , $ fc , $ wg , $ source )
1798+ "INSERT INTO dewar (dewarid,code,trackingnumbertosynchrotron,trackingnumberfromsynchrotron,shippingid,bltimestamp,dewarstatus,firstexperimentid,facilitycode,dewarregistryid, weight,source)
1799+ VALUES (s_dewar.nextval,:1,:2,:3,:4,CURRENT_TIMESTAMP,'opened',:5,:6,:7,:8, IFNULL(:9 ,CURRENT_USER)) RETURNING dewarid INTO :id " ,
1800+ array ($ this ->arg ('CODE ' ), $ to , $ from , $ this ->arg ('SHIPPINGID ' ), $ exp , $ fc , $ drid , $ wg , $ source )
18001801 );
18011802
18021803 $ id = $ this ->db ->id ();
@@ -1942,6 +1943,9 @@ function _update_dewar()
19421943 } else {
19431944 $ this ->_output (1 );
19441945 }
1946+ } else if ($ f === 'FACILITYCODE ' ) {
1947+ $ drid = $ this ->_get_dewarregistryid ($ this ->arg ($ f ));
1948+ $ this ->db ->pq ("UPDATE dewar SET $ f=:1, dewarregistryid=:2 WHERE dewarid=:3 " , array ($ this ->arg ($ f ), $ drid , $ this ->arg ('did ' )));
19451949 } else {
19461950 $ this ->db ->pq ("UPDATE dewar SET $ f=:1 WHERE dewarid=:2 " , array ($ this ->arg ($ f ), $ this ->arg ('did ' )));
19471951 $ this ->_output (array ($ f => $ this ->arg ($ f )));
@@ -3146,11 +3150,12 @@ function _add_shipment()
31463150 for ($ i = 0 ; $ i < $ this ->arg ('DEWARS ' ); $ i ++) {
31473151 $ fc = $ i < sizeof ($ this ->arg ('FCODES ' )) ? $ fcs [$ i ] : '' ;
31483152 $ n = $ fc ? $ fc : ('Dewar ' . ($ i + 1 ));
3153+ $ drid = $ this ->_get_dewarregistryid ($ fc );
31493154
31503155 $ this ->db ->pq (
3151- "INSERT INTO dewar (dewarid,code,shippingid,bltimestamp,dewarstatus,firstexperimentid,facilitycode,weight,source)
3152- VALUES (s_dewar.nextval,:1,:2,CURRENT_TIMESTAMP,'opened',:3,:4,:5,IFNULL(:6 ,CURRENT_USER)) RETURNING dewarid INTO :id " ,
3153- array ($ n , $ sid , $ exp , $ fc , $ dewar_weight , $ source )
3156+ "INSERT INTO dewar (dewarid,code,shippingid,bltimestamp,dewarstatus,firstexperimentid,facilitycode,dewarregistryid, weight,source)
3157+ VALUES (s_dewar.nextval,:1,:2,CURRENT_TIMESTAMP,'opened',:3,:4,:5,:6, IFNULL(:7 ,CURRENT_USER)) RETURNING dewarid INTO :id " ,
3158+ array ($ n , $ sid , $ exp , $ fc , $ drid , $ dewar_weight , $ source )
31543159 );
31553160
31563161 $ id = $ this ->db ->id ();
@@ -3170,6 +3175,17 @@ function _add_shipment()
31703175 $ this ->_output (array ('SHIPPINGID ' => $ sid ));
31713176 }
31723177
3178+ function _get_dewarregistryid ($ fc )
3179+ {
3180+ $ drid = null ;
3181+ if ($ fc ) {
3182+ $ dr = $ this ->db ->pq ("SELECT dewarregistryid FROM dewarregistry where facilitycode=:1 " , array ($ fc ));
3183+ if (sizeof ($ dr ))
3184+ $ drid = $ dr [0 ]['DEWARREGISTRYID ' ];
3185+ }
3186+ return $ drid ;
3187+ }
3188+
31733189 function _get_default_dewar ()
31743190 {
31753191 if ($ this ->has_arg ('visit ' )) {
0 commit comments