Batch 6b: application controllers mockup base
This commit is contained in:
242
application/controllers/mockup/sampling/sampling/Sampling.php
Executable file
242
application/controllers/mockup/sampling/sampling/Sampling.php
Executable file
@@ -0,0 +1,242 @@
|
||||
<?php
|
||||
|
||||
class Sampling extends MY_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_smartone = $this->load->database("onedev", true);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "Sampling API";
|
||||
}
|
||||
|
||||
public function get_samples()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$order_id = $prm['orderid'];
|
||||
$station_id = $prm['stationid'];
|
||||
|
||||
if ($order_id == null)
|
||||
$order_id = 0;
|
||||
|
||||
if ($station_id == null)
|
||||
$station_id = 0;
|
||||
|
||||
$sql = "CALL sp_sampling_get_samples('{$order_id}', '$station_id')";
|
||||
$query = $this->db_smartone->query($sql);
|
||||
|
||||
if ($query)
|
||||
{
|
||||
$rows = $query->result_array();
|
||||
foreach($rows as $k => $v)
|
||||
$rows[$k]['reqs'] = json_decode($v['reqs']);
|
||||
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("Get Samples rows", $this->db_smartone);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_sample()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$order_id = $prm['orderid'];
|
||||
$sample_id = $prm['sampleid'];
|
||||
$barcode = $prm['barcode'];
|
||||
|
||||
if ($order_id == null)
|
||||
$order_id = 0;
|
||||
|
||||
if ($sample_id == null)
|
||||
$sample_id = 0;
|
||||
|
||||
$sql = "CALL sp_sampling_get_sample('{$order_id}', '{$sample_id}', '{$barcode}')";
|
||||
$query = $this->db_smartone->query($sql);
|
||||
|
||||
if ($query)
|
||||
{
|
||||
$rows = $query->row();
|
||||
$rows->reqs = json_decode($rows->reqs);
|
||||
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("Get Samples row", $this->db_smartone);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$order_id = $prm['orderid'];
|
||||
$sample_id = $prm['sampleid'];
|
||||
$barcode = $prm['barcode'];
|
||||
$json = $prm['json_data'];
|
||||
|
||||
$json = json_encode($json);
|
||||
$sql = "CALL sp_sampling_save('{$order_id}', '{$sample_id}', '{$barcode}', '{$json}', '{$this->sys_user['M_UserID']}')";
|
||||
$query = $this->db_smartone->query($sql);
|
||||
|
||||
if ($query)
|
||||
{
|
||||
$rows = $query->row();
|
||||
$rows->data = json_decode($rows->data);
|
||||
$this->sys_ok($rows);
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("Get Samples rows", $this->db_smartone);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
public function save_2()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$order_id = $prm['orderid'];
|
||||
$sample_id = $prm['sampleid'];
|
||||
$barcode = $prm['barcode'];
|
||||
$json = $prm['json_data'];
|
||||
|
||||
$json = json_encode($json);
|
||||
$sql = "CALL sp_sampling_save_2('{$order_id}', '{$sample_id}', '{$barcode}', '{$json}', '{$this->sys_user['M_UserID']}')";
|
||||
$query = $this->db_smartone->query($sql);
|
||||
|
||||
if ($query)
|
||||
{
|
||||
$rows = $query->row();
|
||||
$rows->data = json_decode($rows->data);
|
||||
$this->sys_ok($rows);
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("Get Samples rows", $this->db_smartone);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
public function save_note_supervisor()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$order_id = $prm['orderid'];
|
||||
$message = $prm['message'];
|
||||
|
||||
$json = json_encode($json);
|
||||
$sql = "CALL sp_sampling_save_note_supervisor('{$order_id}', '{$message}', '{$this->sys_user['M_UserID']}')";
|
||||
$query = $this->db_smartone->query($sql);
|
||||
|
||||
if ($query)
|
||||
{
|
||||
$rows = $query->result_array();
|
||||
$this->sys_ok($rows);
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("Note Supervisor rows", $this->db_smartone);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
public function barcode_add()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$order_id = $prm['order_id'];
|
||||
$sample_id = $prm['sample_id'];
|
||||
|
||||
$sql = "CALL sp_sampling_barcode_add('{$order_id}', '{$sample_id}')";
|
||||
$query = $this->db_smartone->query($sql);
|
||||
$this->clean_mysqli_connection($this->db_smartone->conn_id);
|
||||
if ($query)
|
||||
{
|
||||
$row = $query->row();
|
||||
if ($row->status == "OK")
|
||||
{
|
||||
$row->data = json_decode($row->data);
|
||||
$this->sys_ok($row->data);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$this->sys_error_db("Barcode ADD", $this->db_smartone);
|
||||
}
|
||||
|
||||
public function get_requirement()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$sql = "SELECT Nat_RequirementID, Nat_RequirementName FROM nat_requirement
|
||||
JOIN nat_requirementposition ON Nat_RequirementPositionNat_RequirementID = Nat_RequirementID
|
||||
AND Nat_RequirementPositionIsActive = 'Y'
|
||||
JOIN nat_position ON Nat_RequirementPositionNat_PositionID = Nat_PositionID
|
||||
AND Nat_PositionCode = 'SPEC.COL'";
|
||||
$query = $this->db_smartone->query($sql);
|
||||
|
||||
if ($query)
|
||||
{
|
||||
$rows = $query->result_array();
|
||||
$this->sys_ok($rows);
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("Get Requirement row", $this->db_smartone);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
public function save_requirement()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
$order_id = $prm['order_id'];
|
||||
$station_id = $prm['station_id'];
|
||||
$reqs = $prm['reqs'];
|
||||
$status = $prm['status'];
|
||||
|
||||
$pos_code = 'SPEC.COL';
|
||||
|
||||
// GET POSITION
|
||||
$p = $this->db_smartone->query("SELECT Nat_PositionID id FROM nat_position WHERE Nat_PositionCode = ?", [$pos_code])
|
||||
->row();
|
||||
|
||||
$sql = "SELECT T_OrderSampleReqID id FROM t_ordersamplereq
|
||||
JOIN nat_position on T_OrderSampleReqNat_PositionID = Nat_PositionID
|
||||
AND Nat_PositionCode = ?
|
||||
WHERE T_OrderSampleReqT_OrderHeaderID = ?
|
||||
AND T_OrderSampleReqT_SampleStationID = ?
|
||||
AND T_OrderSampleReqIsActive = 'Y'";
|
||||
$query = $this->db_smartone->query($sql, [$pos_code, $order_id, $station_id]);
|
||||
$r = $query->row();
|
||||
|
||||
if ($r)
|
||||
{
|
||||
$sql = "UPDATE t_ordersamplereq
|
||||
SET T_OrderSampleReqStatus = ?, T_OrderSampleReqs = ?
|
||||
WHERE T_OrderSampleReqID = ?";
|
||||
$query = $this->db_smartone->query($sql, [$status, $reqs, $r->id]);
|
||||
|
||||
$this->sys_ok($r->id);
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = "INSERT INTO t_ordersamplereq(T_OrderSampleReqT_OrderHeaderID, T_OrderSampleReqT_SampleStationID, T_OrderSampleReqStatus, T_OrderSampleReqs, T_OrderSampleReqNat_PositionID)
|
||||
VALUES(?, ?, ?, ?, ?)";
|
||||
$query = $this->db_smartone->query($sql, [$order_id, $station_id, $status, $reqs, $p->id]);
|
||||
if ($query)
|
||||
{
|
||||
$this->sys_ok($this->db_smartone->insert_id());
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$this->sys_error_db("Sample Req", $this->db_smartone);
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user