Skip to content

Commit

Permalink
I15_1-1318: Cannot create default shipment for visit 0 (#677)
Browse files Browse the repository at this point in the history
* I15_1-1318: Cannot create default shipment for visit 0

* I15_1-1318: Fix container names

* I15_1-1318: Remove debug statement

---------

Co-authored-by: Mark Williams <[email protected]>
  • Loading branch information
ndg63276 and Mark Williams authored Oct 4, 2023
1 parent bd36cd4 commit 48bed40
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
55 changes: 33 additions & 22 deletions api/src/Page/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2613,46 +2613,57 @@ function _add_shipment()

function _get_default_dewar()
{
if (!$this->has_arg('visit'))
$this->_error('No visit specified');

$sids = $this->db->pq("SELECT s.sessionid FROM blsession s INNER JOIN proposal p ON p.proposalid = s.proposalid WHERE CONCAT(p.proposalcode, p.proposalnumber, '-', s.visit_number) LIKE :1 AND p.proposalid=:2", array($this->arg('visit'), $this->proposalid));

if (!sizeof($sids))
$this->_error('No such visit');
else
$sid = $sids[0]['SESSIONID'];
if ($this->has_arg('visit')) {
$shipmentName = $this->arg('visit') . '_Shipment1';
$dewarName = $this->arg('visit') . '_Dewar1';
$sids = $this->db->pq("SELECT s.sessionid FROM blsession s INNER JOIN proposal p ON p.proposalid = s.proposalid WHERE CONCAT(p.proposalcode, p.proposalnumber, '-', s.visit_number) LIKE :1 AND p.proposalid=:2", array($this->arg('visit'), $this->proposalid));
if (!sizeof($sids))
$this->_error('No such visit');
else
$sid = $sids[0]['SESSIONID'];

} elseif ($this->has_arg('prop')) {
$shipmentName = $this->arg('prop') . '_Shipment1';
$dewarName = $this->arg('prop') . '_Dewar1';
$sid = null;
} else {
$this->_error('No visit or proposal specified');
}

$shids = $this->db->pq("SELECT shippingid FROM shipping WHERE proposalid LIKE :1 AND shippingname LIKE :2", array($this->proposalid, $this->arg('visit') . '_Shipment1'));
$shids = $this->db->pq("SELECT shippingid FROM shipping WHERE proposalid LIKE :1 AND shippingname LIKE :2", array($this->proposalid, $shipmentName));

if (sizeof($shids) > 0) {
$shid = $shids[0]['SHIPPINGID'];
} else {
$this->db->pq("INSERT INTO shipping (shippingid,proposalid,shippingname,bltimestamp,creationdate,shippingstatus) VALUES (s_shipping.nextval,:1,:2,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,'processing') RETURNING shippingid INTO :id", array($this->proposalid, $this->arg('visit') . '_Shipment1'));
$this->db->pq("INSERT INTO shipping (shippingid,proposalid,shippingname,bltimestamp,creationdate,shippingstatus) VALUES (s_shipping.nextval,:1,:2,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,'processing') RETURNING shippingid INTO :id", array($this->proposalid, $shipmentName));

$shid = $this->db->id();

$vals = $this->db->pq("INSERT INTO shippinghassession (shippingid,sessionid) VALUES (:1,:2)", array($shid, $sid));
if ($sid)
$vals = $this->db->pq("INSERT INTO shippinghassession (shippingid,sessionid) VALUES (:1,:2)", array($shid, $sid));
}

$did = -1;
if ($sid) {
$dids = $this->db->pq("SELECT dewarid from dewar WHERE shippingid LIKE :1 AND code LIKE :2", array($shid, $this->arg('visit') . '_Dewar1'));

if (sizeof($dids) > 0) {
$did = $dids[0]['DEWARID'];
} else {
$this->db->pq("INSERT INTO dewar (dewarid,code,shippingid,bltimestamp,dewarstatus,firstexperimentid) VALUES (s_dewar.nextval,:1,:2,CURRENT_TIMESTAMP,'processing',:3) RETURNING dewarid INTO :id", array($this->arg('visit') . '_Dewar1', $shid, $sid));
$dids = $this->db->pq("SELECT dewarid from dewar WHERE shippingid LIKE :1 AND code LIKE :2", array($shid, $dewarName));

if (sizeof($dids) > 0) {
$did = $dids[0]['DEWARID'];
} else {
$this->db->pq("INSERT INTO dewar (dewarid,code,shippingid,bltimestamp,dewarstatus,firstexperimentid) VALUES (s_dewar.nextval,:1,:2,CURRENT_TIMESTAMP,'processing',:3) RETURNING dewarid INTO :id", array($dewarName, $shid, $sid));

$did = $this->db->id();
$did = $this->db->id();

# Need to generate barcode
# Need to generate barcode
if ($this->has_arg('visit')) {
$bl = $this->db->pq("SELECT s.beamlinename as bl FROM blsession s WHERE s.sessionid=:1", array($sid));
$this->db->pq("UPDATE dewar set barcode=:1 WHERE dewarid=:2", array($this->arg('visit') . '-' . $bl[0]['BL'] . '-' . str_pad($did, 7, '0', STR_PAD_LEFT), $did));
$barcode = $this->arg('visit') . '-' . $bl[0]['BL'] . '-' . str_pad($did, 7, '0', STR_PAD_LEFT);
} else {
$barcode = $this->arg('prop') . '-' . str_pad($did, 7, '0', STR_PAD_LEFT);
}
$this->db->pq("UPDATE dewar set barcode=:1 WHERE dewarid=:2", array($barcode, $did));
}


if ($did == -1)
$this->_error('Couldn\'t create default dewar');
$this->_output($did);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,8 @@
methods: {
async setDewarInformation() {
// Try to retrieve the default dewar for this proposal/visit
// Uses the special session-0 because at this point we are not necessarily on a session
this.defaultDewarId = await this.$store.dispatch('fetchDataFromApi', {
url: '/shipment/dewars/default',
data: { visit: `${this.$store.getters['proposal/currentProposal']}-0`},
requestType: 'fetching default dewar for this proposal/visit'
})
},
Expand Down Expand Up @@ -542,7 +540,7 @@
})
let container = new Container({
NAME: app.prop + '-' + app.visit + '_samples',
NAME: app.visit ? app.prop + '-' + app.visit + '_samples' : app.prop + '_samples',
CAPACITY: self.capacity,
CONTAINERTYPE: 'Box',
COMMENTS: item.comments
Expand Down Expand Up @@ -620,7 +618,7 @@
})
let container = new Container({
NAME: app.prop + '-' + app.visit + '_samples',
NAME: app.visit ? app.prop + '-' + app.visit + '_samples' : app.prop + '_samples',
CAPACITY: this.capacity,
CONTAINERTYPE: 'Box',
COMMENTS: this.comments
Expand Down Expand Up @@ -840,4 +838,4 @@
}
}
}
</script>
</script>

0 comments on commit 48bed40

Please sign in to comment.