Skip to content

Commit

Permalink
Forgot to commit the shipment change
Browse files Browse the repository at this point in the history
  • Loading branch information
John Holt authored and John Holt committed Aug 18, 2023
1 parent e81367e commit 61f78a3
Showing 1 changed file with 23 additions and 31 deletions.
54 changes: 23 additions & 31 deletions api/src/Page/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SynchWeb\Page;

use Exception;
use SynchWeb\Database\DatabaseQueryBuilder;
use SynchWeb\Page;
use SynchWeb\Shipment\Courier\DHL;
use SynchWeb\Shipment\ShippingService;
Expand Down Expand Up @@ -1641,13 +1642,6 @@ function _check_container()
$this->_output($cont[0]);
}

function _add_to_array($array, $value)
{
if (!in_array($value, $array))
array_push($array, $value);
return $array;
}

function _get_all_containers()
{
//$this->db->set_debug(True);
Expand All @@ -1656,16 +1650,16 @@ function _get_all_containers()

$having = '';
$subsamplesInTotal = "";
$join_arr = array();
$totalQuery = new DatabaseQueryBuilder($this->db);

if ($this->has_arg('visit')) {
$join = " INNER JOIN blsession ses2 ON ses2.proposalid = p.proposalid";
$args = array($this->arg('visit'));
$where = "CONCAT(p.proposalcode, p.proposalnumber, '-', ses2.visit_number) LIKE :1";
$join_arr = $this->_add_to_array($join_arr, "INNER JOIN blsession ses2 ON ses2.proposalid = p.proposalid");
$join_arr = $this->_add_to_array($join_arr, "INNER JOIN dewar d ON d.dewarid = c.dewarid");
$join_arr = $this->_add_to_array($join_arr, "INNER JOIN shipping sh ON sh.shippingid = d.shippingid");
$join_arr = $this->_add_to_array($join_arr, "INNER JOIN proposal p ON p.proposalid = sh.proposalid");
$totalQuery->joinClause("INNER JOIN blsession ses2 ON ses2.proposalid = p.proposalid");
$totalQuery->joinClause("INNER JOIN dewar d ON d.dewarid = c.dewarid");
$totalQuery->joinClause("INNER JOIN shipping sh ON sh.shippingid = d.shippingid");
$totalQuery->joinClause("INNER JOIN proposal p ON p.proposalid = sh.proposalid");
} else if ($this->has_arg('all') && $this->staff) {
$join = '';
$args = array();
Expand All @@ -1674,8 +1668,8 @@ function _get_all_containers()
$join = '';
$args = array($this->proposalid);
$where = 'sh.proposalid=:1';
$join_arr = $this->_add_to_array($join_arr, "INNER JOIN dewar d ON d.dewarid = c.dewarid");
$join_arr = $this->_add_to_array($join_arr, "INNER JOIN shipping sh ON sh.shippingid = d.shippingid");
$totalQuery->joinClause("INNER JOIN dewar d ON d.dewarid = c.dewarid");
$totalQuery->joinClause("INNER JOIN shipping sh ON sh.shippingid = d.shippingid");
}


Expand All @@ -1689,22 +1683,22 @@ function _get_all_containers()
} else if ($this->arg('ty') == 'todispose') {
$where .= " AND c.imagerid IS NOT NULL";
$having .= " HAVING (TIMESTAMPDIFF('HOUR', min(ci.bltimestamp), CURRENT_TIMESTAMP)/24) > 42";
$join_arr = $this->_add_to_array($join_arr, "LEFT OUTER JOIN containerinspection ci ON ci.containerid = c.containerid AND ci.state = 'Completed'");
$totalQuery->joinClause("LEFT OUTER JOIN containerinspection ci ON ci.containerid = c.containerid AND ci.state = 'Completed'");
} else if ($this->arg('ty') == 'queued') {
$where .= " AND cq.containerqueueid IS NOT NULL";
$join_arr = $this->_add_to_array($join_arr, "LEFT OUTER JOIN containerqueue cq ON cq.containerid = c.containerid AND cq.completedtimestamp IS NULL");
$totalQuery->joinClause("LEFT OUTER JOIN containerqueue cq ON cq.containerid = c.containerid AND cq.completedtimestamp IS NULL");
} else if ($this->arg('ty') == 'completed') {
$where .= " AND cq2.completedtimestamp IS NOT NULL";
$join_arr = $this->_add_to_array($join_arr, "LEFT OUTER JOIN containerqueue cq2 ON cq2.containerid = c.containerid AND cq2.completedtimestamp IS NOT NULL");
$totalQuery->joinClause("LEFT OUTER JOIN containerqueue cq2 ON cq2.containerid = c.containerid AND cq2.completedtimestamp IS NOT NULL");
$this->args['sort_by'] = 'COMPLETEDTIMESTAMP';
$this->args['order'] = 'desc';
} else if ($this->arg('ty') == 'processing') {
$where .= " AND c.containerstatus = 'processing'";
} else if ($this->arg('ty') == 'subsamples') {
$having .= " HAVING subsamples > 0";
$subsamplesInTotal = ", count(distinct ss.blsubsampleid) as subsamples";
$join_arr = $this->_add_to_array($join_arr, "LEFT OUTER JOIN blsample s ON s.containerid = c.containerid");
$join_arr = $this->_add_to_array($join_arr, "LEFT OUTER JOIN blsubsample ss ON s.blsampleid = ss.blsampleid AND ss.source='manual'");
$totalQuery->joinClause("LEFT OUTER JOIN blsample s ON s.containerid = c.containerid");
$totalQuery->joinClause("LEFT OUTER JOIN blsubsample ss ON s.blsampleid = ss.blsampleid AND ss.source='manual'");
}
}

Expand All @@ -1716,13 +1710,13 @@ function _get_all_containers()

if ($this->has_arg('did')) {
$where .= ' AND d.dewarid=:' . (sizeof($args) + 1);
$join_arr = $this->_add_to_array($join_arr, "INNER JOIN dewar d ON d.dewarid = c.dewarid");
$totalQuery->joinClause("INNER JOIN dewar d ON d.dewarid = c.dewarid");
array_push($args, $this->arg('did'));
}
if ($this->has_arg('sid')) {
$where .= ' AND sh.shippingid=:' . (sizeof($args) + 1);
$join_arr = $this->_add_to_array($join_arr, "INNER JOIN dewar d ON d.dewarid = c.dewarid");
$join_arr = $this->_add_to_array($join_arr, "INNER JOIN shipping sh ON sh.shippingid = d.shippingid");
$totalQuery->joinClause("INNER JOIN dewar d ON d.dewarid = c.dewarid");
$totalQuery->joinClause("INNER JOIN shipping sh ON sh.shippingid = d.shippingid");
array_push($args, $this->arg('sid'));
}
if ($this->has_arg('cid')) {
Expand All @@ -1734,15 +1728,15 @@ function _get_all_containers()
// $this->db->set_debug(True);
$join .= ' LEFT OUTER JOIN crystal cr ON cr.crystalid = s.crystalid LEFT OUTER JOIN protein pr ON pr.proteinid = cr.proteinid';
$where .= ' AND pr.proteinid=:' . (sizeof($args) + 1);
$join_arr = $this->_add_to_array($join_arr, "LEFT OUTER JOIN blsample s ON s.containerid = c.containerid");
$join_arr = $this->_add_to_array($join_arr, "LEFT OUTER JOIN crystal cr ON cr.crystalid = s.crystalid");
$join_arr = $this->_add_to_array($join_arr, "LEFT OUTER JOIN protein pr ON pr.proteinid = cr.proteinid");
$totalQuery->joinClause("LEFT OUTER JOIN blsample s ON s.containerid = c.containerid");
$totalQuery->joinClause("LEFT OUTER JOIN crystal cr ON cr.crystalid = s.crystalid");
$totalQuery->joinClause("LEFT OUTER JOIN protein pr ON pr.proteinid = cr.proteinid");
array_push($args, $this->arg('pid'));
}

if ($this->has_arg('assigned')) {
$where .= " AND d.dewarstatus LIKE 'processing' AND c.samplechangerlocation > 0";
$join_arr = $this->_add_to_array($join_arr, "INNER JOIN dewar d ON d.dewarid = c.dewarid");
$totalQuery->joinClause("INNER JOIN dewar d ON d.dewarid = c.dewarid");
}

if ($this->has_arg('bl')) {
Expand All @@ -1754,8 +1748,8 @@ function _get_all_containers()
$where .= " AND c.containerid NOT IN (SELECT c.containerid FROM container c INNER JOIN dewar d ON d.dewarid = c.dewarid WHERE d.dewarstatus LIKE 'processing' AND c.samplechangerlocation > 0 AND c.beamlinelocation=:" . (sizeof($args) + 1) . ")";

array_push($args, $this->arg('unassigned'));
$join_arr = $this->_add_to_array($join_arr, "INNER JOIN dewar d ON d.dewarid = c.dewarid");
$join_arr = $this->_add_to_array($join_arr, "INNER JOIN shipping sh ON sh.shippingid = d.shippingid");
$totalQuery->joinClause("INNER JOIN dewar d ON d.dewarid = c.dewarid");
$totalQuery->joinClause("INNER JOIN shipping sh ON sh.shippingid = d.shippingid");
$this->args['sort_by'] = 'SHIPPINGID';
$this->args['order'] = 'desc';
}
Expand Down Expand Up @@ -1783,12 +1777,10 @@ function _get_all_containers()
array_push($args, $this->user->personId);
}

$join_str = implode(" ", $join_arr);

$tot = $this->db->pq("SELECT count(distinct c.containerid) as tot
$subsamplesInTotal
FROM container c
$join_str
{$totalQuery->getJoins()}
WHERE $where
$having", $args);
$tot = sizeof($tot) ? intval($tot[0]['TOT']) : 0;
Expand Down

0 comments on commit 61f78a3

Please sign in to comment.