Initial import
This commit is contained in:
279
one-api/application/libraries/ImageManipulator.php
Normal file
279
one-api/application/libraries/ImageManipulator.php
Normal file
@@ -0,0 +1,279 @@
|
||||
<?php
|
||||
class ImageManipulator
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* @var resource
|
||||
*/
|
||||
protected $image;
|
||||
|
||||
/**
|
||||
* Image manipulator constructor
|
||||
*
|
||||
* @param string $file OPTIONAL Path to image file or image data as string
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($file = null)
|
||||
{
|
||||
if (null !== $file) {
|
||||
if (is_file($file)) {
|
||||
$this->setImageFile($file);
|
||||
} else {
|
||||
$this->setImageString($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set image resource from file
|
||||
*
|
||||
* @param string $file Path to image file
|
||||
* @return ImageManipulator for a fluent interface
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function setImageFile($file)
|
||||
{
|
||||
if (!(is_readable($file) && is_file($file))) {
|
||||
throw new InvalidArgumentException("Image file $file is not readable");
|
||||
}
|
||||
|
||||
if (is_resource($this->image)) {
|
||||
imagedestroy($this->image);
|
||||
}
|
||||
|
||||
list ($this->width, $this->height, $type) = getimagesize($file);
|
||||
|
||||
switch ($type) {
|
||||
case IMAGETYPE_GIF :
|
||||
$this->image = imagecreatefromgif($file);
|
||||
break;
|
||||
case IMAGETYPE_JPEG :
|
||||
$this->image = imagecreatefromjpeg($file);
|
||||
break;
|
||||
case IMAGETYPE_PNG :
|
||||
$this->image = imagecreatefrompng($file);
|
||||
break;
|
||||
default :
|
||||
throw new InvalidArgumentException("Image type $type not supported");
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set image resource from string data
|
||||
*
|
||||
* @param string $data
|
||||
* @return ImageManipulator for a fluent interface
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function setImageString($data)
|
||||
{
|
||||
if (is_resource($this->image)) {
|
||||
imagedestroy($this->image);
|
||||
}
|
||||
|
||||
if (!$this->image = imagecreatefromstring($data)) {
|
||||
throw new RuntimeException('Cannot create image from data string');
|
||||
}
|
||||
$this->width = imagesx($this->image);
|
||||
$this->height = imagesy($this->image);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resamples the current image
|
||||
*
|
||||
* @param int $width New width
|
||||
* @param int $height New height
|
||||
* @param bool $constrainProportions Constrain current image proportions when resizing
|
||||
* @return ImageManipulator for a fluent interface
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function resample($width, $height, $constrainProportions = true)
|
||||
{
|
||||
if (!is_resource($this->image)) {
|
||||
throw new RuntimeException('No image set');
|
||||
}
|
||||
if ($constrainProportions) {
|
||||
if ($this->height >= $this->width) {
|
||||
$width = round($height / $this->height * $this->width);
|
||||
} else {
|
||||
$height = round($width / $this->width * $this->height);
|
||||
}
|
||||
}
|
||||
$temp = imagecreatetruecolor($width, $height);
|
||||
imagecopyresampled($temp, $this->image, 0, 0, 0, 0, $width, $height, $this->width, $this->height);
|
||||
return $this->_replace($temp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enlarge canvas
|
||||
*
|
||||
* @param int $width Canvas width
|
||||
* @param int $height Canvas height
|
||||
* @param array $rgb RGB colour values
|
||||
* @param int $xpos X-Position of image in new canvas, null for centre
|
||||
* @param int $ypos Y-Position of image in new canvas, null for centre
|
||||
* @return ImageManipulator for a fluent interface
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function enlargeCanvas($width, $height, array $rgb = array(), $xpos = null, $ypos = null)
|
||||
{
|
||||
if (!is_resource($this->image)) {
|
||||
throw new RuntimeException('No image set');
|
||||
}
|
||||
|
||||
$width = max($width, $this->width);
|
||||
$height = max($height, $this->height);
|
||||
|
||||
$temp = imagecreatetruecolor($width, $height);
|
||||
if (count($rgb) == 3) {
|
||||
$bg = imagecolorallocate($temp, $rgb[0], $rgb[1], $rgb[2]);
|
||||
imagefill($temp, 0, 0, $bg);
|
||||
}
|
||||
|
||||
if (null === $xpos) {
|
||||
$xpos = round(($width - $this->width) / 2);
|
||||
}
|
||||
if (null === $ypos) {
|
||||
$ypos = round(($height - $this->height) / 2);
|
||||
}
|
||||
|
||||
imagecopy($temp, $this->image, (int) $xpos, (int) $ypos, 0, 0, $this->width, $this->height);
|
||||
return $this->_replace($temp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Crop image
|
||||
*
|
||||
* @param int|array $x1 Top left x-coordinate of crop box or array of coordinates
|
||||
* @param int $y1 Top left y-coordinate of crop box
|
||||
* @param int $x2 Bottom right x-coordinate of crop box
|
||||
* @param int $y2 Bottom right y-coordinate of crop box
|
||||
* @return ImageManipulator for a fluent interface
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function crop($x1, $y1 = 0, $x2 = 0, $y2 = 0)
|
||||
{
|
||||
if (!is_resource($this->image)) {
|
||||
throw new RuntimeException('No image set');
|
||||
}
|
||||
if (is_array($x1) && 4 == count($x1)) {
|
||||
list($x1, $y1, $x2, $y2) = $x1;
|
||||
}
|
||||
|
||||
$x1 = max($x1, 0);
|
||||
$y1 = max($y1, 0);
|
||||
|
||||
$x2 = min($x2, $this->width);
|
||||
$y2 = min($y2, $this->height);
|
||||
|
||||
$width = $x2 - $x1;
|
||||
$height = $y2 - $y1;
|
||||
|
||||
$temp = imagecreatetruecolor($width, $height);
|
||||
imagecopy($temp, $this->image, 0, 0, $x1, $y1, $width, $height);
|
||||
|
||||
return $this->_replace($temp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace current image resource with a new one
|
||||
*
|
||||
* @param resource $res New image resource
|
||||
* @return ImageManipulator for a fluent interface
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
protected function _replace($res)
|
||||
{
|
||||
if (!is_resource($res)) {
|
||||
throw new UnexpectedValueException('Invalid resource');
|
||||
}
|
||||
if (is_resource($this->image)) {
|
||||
imagedestroy($this->image);
|
||||
}
|
||||
$this->image = $res;
|
||||
$this->width = imagesx($res);
|
||||
$this->height = imagesy($res);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save current image to file
|
||||
*
|
||||
* @param string $fileName
|
||||
* @return void
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function save($fileName, $type = IMAGETYPE_JPEG)
|
||||
{
|
||||
$dir = dirname($fileName);
|
||||
if (!is_dir($dir)) {
|
||||
if (!mkdir($dir, 0755, true)) {
|
||||
throw new RuntimeException('Error creating directory ' . $dir);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
switch ($type) {
|
||||
case IMAGETYPE_GIF :
|
||||
if (!imagegif($this->image, $fileName)) {
|
||||
throw new RuntimeException;
|
||||
}
|
||||
break;
|
||||
case IMAGETYPE_PNG :
|
||||
if (!imagepng($this->image, $fileName)) {
|
||||
throw new RuntimeException;
|
||||
}
|
||||
break;
|
||||
case IMAGETYPE_JPEG :
|
||||
default :
|
||||
if (!imagejpeg($this->image, $fileName, 95)) {
|
||||
throw new RuntimeException;
|
||||
}
|
||||
}
|
||||
} catch (Exception $ex) {
|
||||
throw new RuntimeException('Error saving image file to ' . $fileName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the GD image resource
|
||||
*
|
||||
* @return resource
|
||||
*/
|
||||
public function getResource()
|
||||
{
|
||||
return $this->image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current image resource width
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getWidth()
|
||||
{
|
||||
return $this->width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current image height
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getHeight()
|
||||
{
|
||||
return $this->height;
|
||||
}
|
||||
}
|
||||
196
one-api/application/libraries/Jwt.php
Normal file
196
one-api/application/libraries/Jwt.php
Normal file
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* JSON Web Token implementation, based on this spec:
|
||||
* http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-06
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Authentication
|
||||
* @package Authentication_JWT
|
||||
* @author Neuman Vong <neuman@twilio.com>
|
||||
* @author Anant Narayanan <anant@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause 3-clause BSD
|
||||
* @link https://github.com/firebase/php-jwt
|
||||
*/
|
||||
class JWT
|
||||
{
|
||||
/**
|
||||
* Decodes a JWT string into a PHP object.
|
||||
*
|
||||
* @param string $jwt The JWT
|
||||
* @param string|null $key The secret key
|
||||
* @param bool $verify Don't skip verification process
|
||||
*
|
||||
* @return object The JWT's payload as a PHP object
|
||||
* @throws UnexpectedValueException Provided JWT was invalid
|
||||
* @throws DomainException Algorithm was not provided
|
||||
*
|
||||
* @uses jsonDecode
|
||||
* @uses urlsafeB64Decode
|
||||
*/
|
||||
public static function decode($jwt, $key = null, $verify = true)
|
||||
{
|
||||
$tks = explode('.', $jwt);
|
||||
if (count($tks) != 3) {
|
||||
throw new UnexpectedValueException('Wrong number of segments');
|
||||
}
|
||||
list($headb64, $bodyb64, $cryptob64) = $tks;
|
||||
if (null === ($header = JWT::jsonDecode(JWT::urlsafeB64Decode($headb64)))) {
|
||||
throw new UnexpectedValueException('Invalid segment encoding');
|
||||
}
|
||||
if (null === $payload = JWT::jsonDecode(JWT::urlsafeB64Decode($bodyb64))) {
|
||||
throw new UnexpectedValueException('Invalid segment encoding');
|
||||
}
|
||||
$sig = JWT::urlsafeB64Decode($cryptob64);
|
||||
if ($verify) {
|
||||
if (empty($header->alg)) {
|
||||
throw new DomainException('Empty algorithm');
|
||||
}
|
||||
if ($sig != JWT::sign("$headb64.$bodyb64", $key, $header->alg)) {
|
||||
throw new UnexpectedValueException('Signature verification failed');
|
||||
}
|
||||
}
|
||||
return $payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts and signs a PHP object or array into a JWT string.
|
||||
*
|
||||
* @param object|array $payload PHP object or array
|
||||
* @param string $key The secret key
|
||||
* @param string $algo The signing algorithm. Supported
|
||||
* algorithms are 'HS256', 'HS384' and 'HS512'
|
||||
*
|
||||
* @return string A signed JWT
|
||||
* @uses jsonEncode
|
||||
* @uses urlsafeB64Encode
|
||||
*/
|
||||
public static function encode($payload, $key, $algo = 'HS256')
|
||||
{
|
||||
$header = array('typ' => 'JWT', 'alg' => $algo);
|
||||
|
||||
$segments = array();
|
||||
$segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($header));
|
||||
$segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($payload));
|
||||
$signing_input = implode('.', $segments);
|
||||
|
||||
$signature = JWT::sign($signing_input, $key, $algo);
|
||||
$segments[] = JWT::urlsafeB64Encode($signature);
|
||||
|
||||
return implode('.', $segments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign a string with a given key and algorithm.
|
||||
*
|
||||
* @param string $msg The message to sign
|
||||
* @param string $key The secret key
|
||||
* @param string $method The signing algorithm. Supported
|
||||
* algorithms are 'HS256', 'HS384' and 'HS512'
|
||||
*
|
||||
* @return string An encrypted message
|
||||
* @throws DomainException Unsupported algorithm was specified
|
||||
*/
|
||||
public static function sign($msg, $key, $method = 'HS256')
|
||||
{
|
||||
$methods = array(
|
||||
'HS256' => 'sha256',
|
||||
'HS384' => 'sha384',
|
||||
'HS512' => 'sha512',
|
||||
);
|
||||
if (empty($methods[$method])) {
|
||||
throw new DomainException('Algorithm not supported');
|
||||
}
|
||||
return hash_hmac($methods[$method], $msg, $key, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode a JSON string into a PHP object.
|
||||
*
|
||||
* @param string $input JSON string
|
||||
*
|
||||
* @return object Object representation of JSON string
|
||||
* @throws DomainException Provided string was invalid JSON
|
||||
*/
|
||||
public static function jsonDecode($input)
|
||||
{
|
||||
$obj = json_decode($input);
|
||||
if (function_exists('json_last_error') && $errno = json_last_error()) {
|
||||
JWT::_handleJsonError($errno);
|
||||
} else if ($obj === null && $input !== 'null') {
|
||||
throw new DomainException('Null result with non-null input');
|
||||
}
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode a PHP object into a JSON string.
|
||||
*
|
||||
* @param object|array $input A PHP object or array
|
||||
*
|
||||
* @return string JSON representation of the PHP object or array
|
||||
* @throws DomainException Provided object could not be encoded to valid JSON
|
||||
*/
|
||||
public static function jsonEncode($input)
|
||||
{
|
||||
$json = json_encode($input);
|
||||
if (function_exists('json_last_error') && $errno = json_last_error()) {
|
||||
JWT::_handleJsonError($errno);
|
||||
} else if ($json === 'null' && $input !== null) {
|
||||
throw new DomainException('Null result with non-null input');
|
||||
}
|
||||
return $json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode a string with URL-safe Base64.
|
||||
*
|
||||
* @param string $input A Base64 encoded string
|
||||
*
|
||||
* @return string A decoded string
|
||||
*/
|
||||
public static function urlsafeB64Decode($input)
|
||||
{
|
||||
$remainder = strlen($input) % 4;
|
||||
if ($remainder) {
|
||||
$padlen = 4 - $remainder;
|
||||
$input .= str_repeat('=', $padlen);
|
||||
}
|
||||
return base64_decode(strtr($input, '-_', '+/'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode a string with URL-safe Base64.
|
||||
*
|
||||
* @param string $input The string you want encoded
|
||||
*
|
||||
* @return string The base64 encode of what you passed in
|
||||
*/
|
||||
public static function urlsafeB64Encode($input)
|
||||
{
|
||||
return str_replace('=', '', strtr(base64_encode($input), '+/', '-_'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to create a JSON error.
|
||||
*
|
||||
* @param int $errno An error number from json_last_error()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function _handleJsonError($errno)
|
||||
{
|
||||
$messages = array(
|
||||
JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
|
||||
JSON_ERROR_CTRL_CHAR => 'Unexpected control character found',
|
||||
JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON'
|
||||
);
|
||||
throw new DomainException(
|
||||
isset($messages[$errno])
|
||||
? $messages[$errno]
|
||||
: 'Unknown JSON error: ' . $errno
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
547
one-api/application/libraries/SsPriceMou-bkp.php
Normal file
547
one-api/application/libraries/SsPriceMou-bkp.php
Normal file
@@ -0,0 +1,547 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
class SsPriceMou{
|
||||
|
||||
// retrun array status, message
|
||||
public function create($mouID) {
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("regional",true);
|
||||
|
||||
$sql = "select * from m_mou where M_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "MOU ID : $mouID not found");
|
||||
}
|
||||
$companyID = $rows[0]["M_MouM_CompanyID"];
|
||||
|
||||
$sql = "select distinct T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y'
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID <> 5
|
||||
where T_PriceM_MouID = ?
|
||||
and length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional select t_price " . print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$flag_error = false;
|
||||
foreach($rows as $idx => $r) {
|
||||
$nat_testType = $r["Nat_TestNat_TestTypeID"];
|
||||
switch($nat_testType) {
|
||||
case 1: //Single
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
case 3: //Multi
|
||||
case 4: //Panel
|
||||
$sasCode = $r["T_TestSasCode"] . '%';
|
||||
$sql = "select T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestIsResult = 'Y'
|
||||
and T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array($r["Nat_TestID"]);
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = $nr["T_TestNat_TestID"];
|
||||
}
|
||||
$rows[$idx]['nat_test'] = "[" . join(",",$t_rows) . "]";
|
||||
break;
|
||||
default :
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
}
|
||||
unset($rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
//Test Profile
|
||||
// wip profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, 0 T_PriceAmount, 0 T_PriceDisc, 0 T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, 0 T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PXR' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_test
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID = 5
|
||||
where length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$p_rows = $qry->result_array();
|
||||
|
||||
$sql = "select distinct substr(T_TestSasCode,1,8) parentCode, T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode,T_TestIsResult, T_TestCode
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y'
|
||||
and T_PriceIsCito = 'N'
|
||||
and length(T_TestSasCode) = 10
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
where T_PriceM_MouID = ? ";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional child test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_child = array();
|
||||
$p_codes = "'0'";
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
if ( ! isset($arr_child[$pCode])) {
|
||||
$arr_child[$pCode] = array();
|
||||
}
|
||||
$cCode = $r["T_TestSasCode"];
|
||||
$p_codes .= ", '$cCode'";
|
||||
unset($r["parentCode"]);
|
||||
$arr_child[$pCode][] = $r;
|
||||
}
|
||||
$sql = "select substr(T_TestSasCode,1,8) parentCode,
|
||||
group_concat(distinct T_TestNat_TestID) nat
|
||||
from t_test
|
||||
where ( T_TestIsResult = 'Y' or T_TestIsPrice = 'Y' )
|
||||
and T_TestSasCode in ( $p_codes )
|
||||
and T_TestIsActive = 'Y'
|
||||
group by parentCode";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_nat = array();
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
//if ( ! isset($arr_nat[$pCode])) {
|
||||
// $arr_nat[$pCode] = array();
|
||||
//}
|
||||
$arr_nat[$pCode] = $r["nat"];
|
||||
}
|
||||
$flag_error = false;
|
||||
foreach($p_rows as $idx => $r) {
|
||||
$T_TestName= $r["T_TestName"] ;
|
||||
$sasCode = $r["T_TestSasCode"];
|
||||
if ( isset($arr_child[$sasCode]) ) {
|
||||
$the_childs = $arr_child[$sasCode];
|
||||
$p_rows[$idx]['child_test'] = json_encode($the_childs,true);
|
||||
if ( isset($arr_nat[$sasCode] )) {
|
||||
$p_rows[$idx]['nat_test'] = "[" . $arr_nat[$sasCode] . "]";
|
||||
}
|
||||
unset($p_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($p_rows[$idx]["T_TestSasCode"]);
|
||||
} else {
|
||||
unset($p_rows[$idx]);
|
||||
}
|
||||
}
|
||||
//Paket Panel / Profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_PacketID T_TestID, T_PacketName T_TestName, 'N' IsFromPanel, 0 Nat_TestID,
|
||||
T_PacketID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, T_PacketOriginalBruto T_PriceAmount, 0 T_PriceDisc,
|
||||
(T_PacketOriginalBruto - T_PacketPrice) T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketPrice T_PriceTotal, 'Y' T_TestForceSell, 'Y' is_packet, T_PacketID packet_id,
|
||||
T_PacketType px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
$mouID Ss_PriceMouM_MouID
|
||||
from
|
||||
t_packet
|
||||
where
|
||||
T_PacketIsActive = 'Y'
|
||||
and T_PacketM_MouID = ?";
|
||||
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$pn_rows = $qry->result_array();
|
||||
foreach($pn_rows as $idx => $pnr) {
|
||||
$packetID = $pnr["packet_id"];
|
||||
//child test
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID,
|
||||
$mouID T_PriceM_MouID, 0 T_PricePriority, T_PacketDetailPriceAmount T_PriceAmount,
|
||||
T_PacketDetailPriceDisc T_PriceDisc, T_PacketDetailPriceDiscRp T_PriceDiscRp, T_PacketDetailPriceSubTotal T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketDetailPrice T_PriceTotal,
|
||||
'Y' T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite, T_TestSasCode
|
||||
from t_packetdetail
|
||||
join t_test on T_PacketDetailT_TestID = T_TestID
|
||||
and T_PacketDetailIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_PacketDetailT_PacketID = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($packetID));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$ct_rows = $qry->result_array();
|
||||
$p_nat_test = array();
|
||||
foreach($ct_rows as $ct_idx => $cr) {
|
||||
$sasCode = $cr["T_TestSasCode"] . '%';
|
||||
$sql = "select distinct T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array();
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = intval( $nr["T_TestNat_TestID"]);
|
||||
$p_nat_test[]= intval( $nr["T_TestNat_TestID"]);
|
||||
}
|
||||
$ct_rows[$ct_idx]['nat_test'] = json_encode($t_rows,JSON_NUMERIC_CHECK);
|
||||
}
|
||||
if (count($ct_rows) > 0 ) {
|
||||
$x_arr = array();
|
||||
foreach($ct_rows as $x_cr) {
|
||||
$x_arr[] = $x_cr;
|
||||
}
|
||||
$pn_rows[$idx]['child_test'] = json_encode($x_arr,true);
|
||||
$pn_rows[$idx]['nat_test'] = json_encode($p_nat_test,true);
|
||||
}
|
||||
unset($pn_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($pn_rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
|
||||
$rows = array_merge($rows,$p_rows, $pn_rows);
|
||||
$qry = $this->db->query("delete from ss_price_mou where Ss_PriceMouM_MouID=?", array($mouID));
|
||||
if ( ! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$qry = $this->db->insert_batch("ss_price_mou", $rows);
|
||||
if ( ! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
return array(true, "OK");
|
||||
}
|
||||
public function edit($mouID,$testID,$cito) {
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("regional",true);
|
||||
|
||||
$sql = "select * from t_test where T_TestID = ? ";
|
||||
$qry = $this->db->query($sql, array($testID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "No Test $testID found");
|
||||
}
|
||||
$sasCode = $rows[0]["T_TestSasCode"];
|
||||
if ( strlen($sasCode) == 8 ) {
|
||||
$flagProfile = false;
|
||||
} else {
|
||||
$flagProfile = true;
|
||||
}
|
||||
|
||||
$sql = "select * from m_mou where M_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "No MOU $mouID found");
|
||||
}
|
||||
$mouName = $rows[0]["M_MouName"];
|
||||
$companyID = $rows[0]["M_MouM_CompanyID"];
|
||||
|
||||
$sql = "select distinct T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID and T_TestID = ?
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y' and T_PriceIsCito = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID <> 5
|
||||
where T_PriceM_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($testID, $cito, $mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
|
||||
foreach($rows as $idx => $r) {
|
||||
$nat_testType = $r["Nat_TestNat_TestTypeID"];
|
||||
switch($nat_testType) {
|
||||
case 1: //Single
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
case 3: //Multi
|
||||
case 4: //Panel
|
||||
$sasCode = $r["T_TestSasCode"] . '%';
|
||||
$sql = "select T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestIsResult = 'Y'
|
||||
and T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array($r["Nat_TestID"]);
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = $nr["T_TestNat_TestID"];
|
||||
}
|
||||
$rows[$idx]['nat_test'] = "[" . join(",",$t_rows) . "]";
|
||||
break;
|
||||
default :
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
}
|
||||
unset($rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
}
|
||||
if ( count($rows) > 0 ) {
|
||||
$r = $rows[0];
|
||||
unset($r["T_TestSasCode"]);
|
||||
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
||||
$this->db->where("T_TestID", $r["T_TestID"]);
|
||||
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
||||
$qry = $this->db->update("ss_price_mou",$r);
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
}
|
||||
$sasCode = substr($sasCode,0,8);
|
||||
foreach($rows as $idx => $r ) {
|
||||
if ( strlen($r["T_TestSasCode"]) > 8 ) {
|
||||
unset($rows[$idx]);
|
||||
} else {
|
||||
unset($rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
}
|
||||
if ($cito == 'Y' ) {
|
||||
return array(true,"OK",$rows);
|
||||
}
|
||||
// for non cito
|
||||
if($flagProfile ) {
|
||||
//wip profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, 0 T_PriceAmount, 0 T_PriceDisc, 0 T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, 0 T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PXR' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_test
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID and T_TestSasCode = ?
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID = 5
|
||||
where length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($sasCode));
|
||||
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$p_rows = $qry->result_array();
|
||||
|
||||
$sasCodeLike = $sasCode . "%";
|
||||
$sql = "select distinct substr(T_TestSasCode,1,8) parentCode, T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode,T_TestIsResult, T_TestCode
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y' and T_PriceIsCito = 'N'
|
||||
and T_TestSasCode like ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
where T_PriceM_MouID = ? ";
|
||||
$qry = $this->db->query($sql,array($sasCodeLike,$mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional child_test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_child = array();
|
||||
$p_codes = "'0'";
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
if ( ! isset($arr_child[$pCode])) {
|
||||
$arr_child[$pCode] = array();
|
||||
}
|
||||
$cCode = $r["T_TestSasCode"];
|
||||
$p_codes .= ", '$cCode'";
|
||||
unset($r["parentCode"]);
|
||||
$arr_child[$pCode][] = $r;
|
||||
}
|
||||
|
||||
$sql = "select substr(T_TestSasCode,1,8) parentCode,
|
||||
group_concat(distinct T_TestNat_TestID) nat
|
||||
from t_test
|
||||
where ( T_TestIsResult = 'Y' or T_TestIsPrice = 'Y' )
|
||||
and T_TestSasCode in ( $p_codes )
|
||||
and T_TestIsActive = 'Y'
|
||||
group by parentCode";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional nat_test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_nat = array();
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
//if ( ! isset($arr_nat[$pCode])) {
|
||||
// $arr_nat[$pCode] = array();
|
||||
//}
|
||||
$arr_nat[$pCode] = $r["nat"];
|
||||
}
|
||||
|
||||
$flag_error = false;
|
||||
foreach($p_rows as $idx => $r) {
|
||||
$T_TestName= $r["T_TestName"] ;
|
||||
$sasCode = $r["T_TestSasCode"];
|
||||
if ( isset($arr_child[$sasCode]) ) {
|
||||
$the_childs = $arr_child[$sasCode];
|
||||
$p_rows[$idx]['child_test'] = json_encode($the_childs,true);
|
||||
if ( isset($arr_nat[$sasCode] )) {
|
||||
$p_rows[$idx]['nat_test'] = "[" . $arr_nat[$sasCode] . "]";
|
||||
}
|
||||
unset($p_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($p_rows[$idx]["T_TestSasCode"]);
|
||||
} else {
|
||||
unset($p_rows[$idx]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach($p_rows as $r) {
|
||||
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
||||
$this->db->where("T_TestID", $r["T_TestID"]);
|
||||
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
||||
$qry = $this->db->update("ss_price_mou",$r);
|
||||
if (! $qry ) {
|
||||
return array(false, "Err Update Ss_priceMou " . print_r($this->db->error(),true));
|
||||
}
|
||||
}
|
||||
$rows = array_merge($rows,$p_rows);
|
||||
}
|
||||
//Update Panel yang mengandung Test
|
||||
$sql = "select
|
||||
distinct T_PacketDetailT_PacketID
|
||||
from
|
||||
t_packetdetail
|
||||
where T_PacketDetailIsActive = 'Y'
|
||||
and T_PacketDetailT_TestID = ?";
|
||||
$qry = $this->db->query($sql, array($testID));
|
||||
if (!$qry) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$packet_ids = "0";
|
||||
foreach($xrows as $r ) {
|
||||
$packet_ids .= "," . $r["T_PacketDetailT_PacketID"];
|
||||
}
|
||||
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_PacketID T_TestID, T_PacketName T_TestName, 'N' IsFromPanel, 0 Nat_TestID,
|
||||
T_PacketID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, T_PacketOriginalBruto T_PriceAmount, 0 T_PriceDisc,
|
||||
(T_PacketOriginalBruto - T_PacketPrice) T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketPrice T_PriceTotal, 'Y' T_TestForceSell, 'Y' is_packet, T_PacketID packet_id,
|
||||
T_PacketType px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
$mouID Ss_PriceMouM_MouID
|
||||
from
|
||||
t_packet
|
||||
where
|
||||
T_PacketIsActive = 'Y' and T_PacketID in ( $packet_ids )
|
||||
and T_PacketM_MouID = ?";
|
||||
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$pn_rows = $qry->result_array();
|
||||
foreach($pn_rows as $idx => $pnr) {
|
||||
$packetID = $pnr["packet_id"];
|
||||
//child test
|
||||
$sql = "select $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID,
|
||||
$mouID T_PriceM_MouID, 0 T_PricePriority, T_PacketDetailPriceAmount T_PriceAmount,
|
||||
T_PacketDetailPriceDisc T_PriceDisc, T_PacketDetailPriceDiscRp T_PriceDiscRp, T_PacketDetailPriceSubTotal T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketDetailPrice T_PriceTotal,
|
||||
'Y' T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite, T_TestSasCode
|
||||
from t_packetdetail
|
||||
join t_test on T_PacketDetailT_TestID = T_TestID
|
||||
and T_PacketDetailIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_PacketDetailT_PacketID = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
";
|
||||
$qry = $this->db->query($sql,array($packetID));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$ct_rows = $qry->result_array();
|
||||
$p_nat_test = array();
|
||||
foreach($ct_rows as $ct_idx => $cr) {
|
||||
$sasCode = $cr["T_TestSasCode"] . '%';
|
||||
$sql = "select distinct T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array();
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = intval( $nr["T_TestNat_TestID"]);
|
||||
$p_nat_test[]= intval( $nr["T_TestNat_TestID"]);
|
||||
}
|
||||
$ct_rows[$ct_idx]['nat_test'] = json_encode($t_rows,JSON_NUMERIC_CHECK);
|
||||
}
|
||||
if (count($ct_rows) > 0 ) {
|
||||
$x_arr = array();
|
||||
foreach($ct_rows as $x_cr) {
|
||||
$x_arr[] = $x_cr;
|
||||
}
|
||||
$pn_rows[$idx]['child_test'] = json_encode($x_arr,true);
|
||||
$pn_rows[$idx]['nat_test'] = json_encode($p_nat_test,true);
|
||||
}
|
||||
unset($pn_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($pn_rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
foreach($pn_rows as $r ) {
|
||||
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
||||
$this->db->where("T_TestID", $r["T_TestID"]);
|
||||
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
||||
$qry = $this->db->update("ss_price_mou",$r);
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
}
|
||||
$rows = array_merge($rows,$pn_rows);
|
||||
return array(true,"OK",$rows);
|
||||
}
|
||||
}
|
||||
556
one-api/application/libraries/SsPriceMou-dev.php
Normal file
556
one-api/application/libraries/SsPriceMou-dev.php
Normal file
@@ -0,0 +1,556 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
class SsPriceMou{
|
||||
|
||||
// retrun array status, message
|
||||
public function create($mouID) {
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("regional",true);
|
||||
|
||||
$sql = "select * from m_mou where M_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "MOU ID : $mouID not found");
|
||||
}
|
||||
$companyID = $rows[0]["M_MouM_CompanyID"];
|
||||
|
||||
$sql = "select distinct T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y'
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID <> 5
|
||||
where T_PriceM_MouID = ?
|
||||
and length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional select t_price " . print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$flag_error = false;
|
||||
foreach($rows as $idx => $r) {
|
||||
$nat_testType = $r["Nat_TestNat_TestTypeID"];
|
||||
switch($nat_testType) {
|
||||
case 1: //Single
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
case 3: //Multi
|
||||
case 4: //Panel
|
||||
$sasCode = $r["T_TestSasCode"] . '%';
|
||||
$sql = "select T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestIsResult = 'Y'
|
||||
and T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array($r["Nat_TestID"]);
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = $nr["T_TestNat_TestID"];
|
||||
}
|
||||
$rows[$idx]['nat_test'] = "[" . join(",",$t_rows) . "]";
|
||||
break;
|
||||
default :
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
}
|
||||
unset($rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
//Test Profile
|
||||
// wip profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, 0 T_PriceAmount, 0 T_PriceDisc, 0 T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, 0 T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PXR' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_test
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID = 5
|
||||
where length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$p_rows = $qry->result_array();
|
||||
|
||||
$sql = "select distinct substr(T_TestSasCode,1,8) parentCode, T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode,T_TestIsResult, T_TestCode
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y'
|
||||
and T_PriceIsCito = 'N'
|
||||
and length(T_TestSasCode) = 10
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
where T_PriceM_MouID = ? ";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional child test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_child = array();
|
||||
$p_codes = "'0'";
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
if ( ! isset($arr_child[$pCode])) {
|
||||
$arr_child[$pCode] = array();
|
||||
}
|
||||
$cCode = $r["T_TestSasCode"];
|
||||
$p_codes .= ", '$cCode'";
|
||||
unset($r["parentCode"]);
|
||||
$arr_child[$pCode][] = $r;
|
||||
}
|
||||
$sql = "select substr(T_TestSasCode,1,8) parentCode,
|
||||
group_concat(distinct T_TestNat_TestID) nat
|
||||
from t_test
|
||||
where ( T_TestIsResult = 'Y' or T_TestIsPrice = 'Y' )
|
||||
and T_TestSasCode in ( $p_codes )
|
||||
and T_TestIsActive = 'Y'
|
||||
group by parentCode";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_nat = array();
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
//if ( ! isset($arr_nat[$pCode])) {
|
||||
// $arr_nat[$pCode] = array();
|
||||
//}
|
||||
$arr_nat[$pCode] = $r["nat"];
|
||||
}
|
||||
$flag_error = false;
|
||||
foreach($p_rows as $idx => $r) {
|
||||
$T_TestName= $r["T_TestName"] ;
|
||||
$sasCode = $r["T_TestSasCode"];
|
||||
if ( isset($arr_child[$sasCode]) ) {
|
||||
$the_childs = $arr_child[$sasCode];
|
||||
$p_rows[$idx]['child_test'] = json_encode($the_childs,true);
|
||||
if ( isset($arr_nat[$sasCode] )) {
|
||||
$p_rows[$idx]['nat_test'] = "[" . $arr_nat[$sasCode] . "]";
|
||||
}
|
||||
unset($p_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($p_rows[$idx]["T_TestSasCode"]);
|
||||
} else {
|
||||
unset($p_rows[$idx]);
|
||||
}
|
||||
}
|
||||
//Paket Panel / Profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_PacketID T_TestID, T_PacketName T_TestName, 'N' IsFromPanel, 0 Nat_TestID,
|
||||
T_PacketID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, T_PacketOriginalBruto T_PriceAmount, 0 T_PriceDisc,
|
||||
(T_PacketOriginalBruto - T_PacketPrice) T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketPrice T_PriceTotal, 'Y' T_TestForceSell, 'Y' is_packet, T_PacketID packet_id,
|
||||
T_PacketType px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
$mouID Ss_PriceMouM_MouID
|
||||
from
|
||||
t_packet
|
||||
where
|
||||
T_PacketIsActive = 'Y'
|
||||
and T_PacketM_MouID = ?";
|
||||
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$pn_rows = $qry->result_array();
|
||||
foreach($pn_rows as $idx => $pnr) {
|
||||
$packetID = $pnr["packet_id"];
|
||||
//child test
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID,
|
||||
$mouID T_PriceM_MouID, 0 T_PricePriority, T_PacketDetailPriceAmount T_PriceAmount,
|
||||
T_PacketDetailPriceDisc T_PriceDisc, T_PacketDetailPriceDiscRp T_PriceDiscRp, T_PacketDetailPriceSubTotal T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketDetailPrice T_PriceTotal,
|
||||
'Y' T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite, T_TestSasCode
|
||||
from t_packetdetail
|
||||
join t_test on T_PacketDetailT_TestID = T_TestID
|
||||
and T_PacketDetailIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_PacketDetailT_PacketID = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($packetID));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$ct_rows = $qry->result_array();
|
||||
$p_nat_test = array();
|
||||
foreach($ct_rows as $ct_idx => $cr) {
|
||||
$sasCode = $cr["T_TestSasCode"] . '%';
|
||||
$sql = "select distinct T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array();
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = intval( $nr["T_TestNat_TestID"]);
|
||||
$p_nat_test[]= intval( $nr["T_TestNat_TestID"]);
|
||||
}
|
||||
$ct_rows[$ct_idx]['nat_test'] = json_encode($t_rows,JSON_NUMERIC_CHECK);
|
||||
}
|
||||
if (count($ct_rows) > 0 ) {
|
||||
$x_arr = array();
|
||||
foreach($ct_rows as $x_cr) {
|
||||
$x_arr[] = $x_cr;
|
||||
}
|
||||
$pn_rows[$idx]['child_test'] = json_encode($x_arr,true);
|
||||
$pn_rows[$idx]['nat_test'] = json_encode($p_nat_test,true);
|
||||
}
|
||||
unset($pn_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($pn_rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
|
||||
$rows = array_merge($rows,$p_rows, $pn_rows);
|
||||
$qry = $this->db->query("delete from ss_price_mou where Ss_PriceMouM_MouID=?", array($mouID));
|
||||
if ( ! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$qry = $this->db->insert_batch("ss_price_mou", $rows);
|
||||
if ( ! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
return array(true, "OK");
|
||||
}
|
||||
public function edit($mouID,$testID,$cito) {
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("regional",true);
|
||||
|
||||
$sql = "select * from t_test where T_TestID = ? ";
|
||||
$qry = $this->db->query($sql, array($testID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "No Test $testID found");
|
||||
}
|
||||
$sasCode = $rows[0]["T_TestSasCode"];
|
||||
if ( strlen($sasCode) == 8 ) {
|
||||
$flagProfile = false;
|
||||
} else {
|
||||
$flagProfile = true;
|
||||
}
|
||||
|
||||
$sql = "select * from m_mou where M_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "No MOU $mouID found");
|
||||
}
|
||||
$mouName = $rows[0]["M_MouName"];
|
||||
$companyID = $rows[0]["M_MouM_CompanyID"];
|
||||
|
||||
$sql = "select distinct T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID and T_TestID = ?
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y' and T_PriceIsCito = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID <> 5
|
||||
where T_PriceM_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($testID, $cito, $mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
|
||||
foreach($rows as $idx => $r) {
|
||||
$nat_testType = $r["Nat_TestNat_TestTypeID"];
|
||||
switch($nat_testType) {
|
||||
case 1: //Single
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
case 3: //Multi
|
||||
case 4: //Panel
|
||||
$sasCode = $r["T_TestSasCode"] . '%';
|
||||
$sql = "select T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestIsResult = 'Y'
|
||||
and T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array($r["Nat_TestID"]);
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = $nr["T_TestNat_TestID"];
|
||||
}
|
||||
$rows[$idx]['nat_test'] = "[" . join(",",$t_rows) . "]";
|
||||
break;
|
||||
default :
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
}
|
||||
unset($rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
}
|
||||
if ( count($rows) > 0 ) {
|
||||
$r = $rows[0];
|
||||
unset($r["T_TestSasCode"]);
|
||||
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
||||
$this->db->where("T_TestID", $r["T_TestID"]);
|
||||
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
||||
$qry = $this->db->update("ss_price_mou",$r);
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
if ($this->db->affected_rows() == 0 ) {
|
||||
$this->db->insert("ss_price_mou", $r);
|
||||
}
|
||||
}
|
||||
$sasCode = substr($sasCode,0,8);
|
||||
foreach($rows as $idx => $r ) {
|
||||
if ( strlen($r["T_TestSasCode"]) > 8 ) {
|
||||
unset($rows[$idx]);
|
||||
} else {
|
||||
unset($rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
}
|
||||
if ($cito == 'Y' ) {
|
||||
return array(true,"OK",$rows);
|
||||
}
|
||||
// for non cito
|
||||
if($flagProfile ) {
|
||||
//wip profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, 0 T_PriceAmount, 0 T_PriceDisc, 0 T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, 0 T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PXR' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_test
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID and T_TestSasCode = ?
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID = 5
|
||||
where length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($sasCode));
|
||||
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$p_rows = $qry->result_array();
|
||||
|
||||
$sasCodeLike = $sasCode . "%";
|
||||
$sql = "select distinct substr(T_TestSasCode,1,8) parentCode, T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode,T_TestIsResult, T_TestCode
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y' and T_PriceIsCito = 'N'
|
||||
and T_TestSasCode like ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
where T_PriceM_MouID = ? ";
|
||||
$qry = $this->db->query($sql,array($sasCodeLike,$mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional child_test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_child = array();
|
||||
$p_codes = "'0'";
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
if ( ! isset($arr_child[$pCode])) {
|
||||
$arr_child[$pCode] = array();
|
||||
}
|
||||
$cCode = $r["T_TestSasCode"];
|
||||
$p_codes .= ", '$cCode'";
|
||||
unset($r["parentCode"]);
|
||||
$arr_child[$pCode][] = $r;
|
||||
}
|
||||
|
||||
$sql = "select substr(T_TestSasCode,1,8) parentCode,
|
||||
group_concat(distinct T_TestNat_TestID) nat
|
||||
from t_test
|
||||
where ( T_TestIsResult = 'Y' or T_TestIsPrice = 'Y' )
|
||||
and T_TestSasCode in ( $p_codes )
|
||||
and T_TestIsActive = 'Y'
|
||||
group by parentCode";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional nat_test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_nat = array();
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
//if ( ! isset($arr_nat[$pCode])) {
|
||||
// $arr_nat[$pCode] = array();
|
||||
//}
|
||||
$arr_nat[$pCode] = $r["nat"];
|
||||
}
|
||||
|
||||
$flag_error = false;
|
||||
foreach($p_rows as $idx => $r) {
|
||||
$T_TestName= $r["T_TestName"] ;
|
||||
$sasCode = $r["T_TestSasCode"];
|
||||
if ( isset($arr_child[$sasCode]) ) {
|
||||
$the_childs = $arr_child[$sasCode];
|
||||
$p_rows[$idx]['child_test'] = json_encode($the_childs,true);
|
||||
if ( isset($arr_nat[$sasCode] )) {
|
||||
$p_rows[$idx]['nat_test'] = "[" . $arr_nat[$sasCode] . "]";
|
||||
}
|
||||
unset($p_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($p_rows[$idx]["T_TestSasCode"]);
|
||||
} else {
|
||||
unset($p_rows[$idx]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach($p_rows as $r) {
|
||||
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
||||
$this->db->where("T_TestID", $r["T_TestID"]);
|
||||
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
||||
$qry = $this->db->update("ss_price_mou",$r);
|
||||
if (! $qry ) {
|
||||
return array(false, "Err Update Ss_priceMou " . print_r($this->db->error(),true));
|
||||
}
|
||||
if ($this->db->affected_rows() == 0 ) {
|
||||
$this->db->insert("ss_price_mou", $r);
|
||||
}
|
||||
}
|
||||
$rows = array_merge($rows,$p_rows);
|
||||
}
|
||||
//Update Panel yang mengandung Test
|
||||
$sql = "select
|
||||
distinct T_PacketDetailT_PacketID
|
||||
from
|
||||
t_packetdetail
|
||||
where T_PacketDetailIsActive = 'Y'
|
||||
and T_PacketDetailT_TestID = ?";
|
||||
$qry = $this->db->query($sql, array($testID));
|
||||
if (!$qry) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$packet_ids = "0";
|
||||
foreach($xrows as $r ) {
|
||||
$packet_ids .= "," . $r["T_PacketDetailT_PacketID"];
|
||||
}
|
||||
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_PacketID T_TestID, T_PacketName T_TestName, 'N' IsFromPanel, 0 Nat_TestID,
|
||||
T_PacketID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, T_PacketOriginalBruto T_PriceAmount, 0 T_PriceDisc,
|
||||
(T_PacketOriginalBruto - T_PacketPrice) T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketPrice T_PriceTotal, 'Y' T_TestForceSell, 'Y' is_packet, T_PacketID packet_id,
|
||||
T_PacketType px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
$mouID Ss_PriceMouM_MouID
|
||||
from
|
||||
t_packet
|
||||
where
|
||||
T_PacketIsActive = 'Y' and T_PacketID in ( $packet_ids )
|
||||
and T_PacketM_MouID = ?";
|
||||
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$pn_rows = $qry->result_array();
|
||||
foreach($pn_rows as $idx => $pnr) {
|
||||
$packetID = $pnr["packet_id"];
|
||||
//child test
|
||||
$sql = "select $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID,
|
||||
$mouID T_PriceM_MouID, 0 T_PricePriority, T_PacketDetailPriceAmount T_PriceAmount,
|
||||
T_PacketDetailPriceDisc T_PriceDisc, T_PacketDetailPriceDiscRp T_PriceDiscRp, T_PacketDetailPriceSubTotal T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketDetailPrice T_PriceTotal,
|
||||
'Y' T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite, T_TestSasCode
|
||||
from t_packetdetail
|
||||
join t_test on T_PacketDetailT_TestID = T_TestID
|
||||
and T_PacketDetailIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_PacketDetailT_PacketID = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
";
|
||||
$qry = $this->db->query($sql,array($packetID));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$ct_rows = $qry->result_array();
|
||||
$p_nat_test = array();
|
||||
foreach($ct_rows as $ct_idx => $cr) {
|
||||
$sasCode = $cr["T_TestSasCode"] . '%';
|
||||
$sql = "select distinct T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array();
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = intval( $nr["T_TestNat_TestID"]);
|
||||
$p_nat_test[]= intval( $nr["T_TestNat_TestID"]);
|
||||
}
|
||||
$ct_rows[$ct_idx]['nat_test'] = json_encode($t_rows,JSON_NUMERIC_CHECK);
|
||||
}
|
||||
if (count($ct_rows) > 0 ) {
|
||||
$x_arr = array();
|
||||
foreach($ct_rows as $x_cr) {
|
||||
$x_arr[] = $x_cr;
|
||||
}
|
||||
$pn_rows[$idx]['child_test'] = json_encode($x_arr,true);
|
||||
$pn_rows[$idx]['nat_test'] = json_encode($p_nat_test,true);
|
||||
}
|
||||
unset($pn_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($pn_rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
foreach($pn_rows as $r ) {
|
||||
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
||||
$this->db->where("T_TestID", $r["T_TestID"]);
|
||||
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
||||
$qry = $this->db->update("ss_price_mou",$r);
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
if ($this->db->affected_rows() == 0 ) {
|
||||
$this->db->insert("ss_price_mou", $r);
|
||||
}
|
||||
}
|
||||
$rows = array_merge($rows,$pn_rows);
|
||||
return array(true,"OK",$rows);
|
||||
}
|
||||
}
|
||||
547
one-api/application/libraries/SsPriceMou-devone.php
Normal file
547
one-api/application/libraries/SsPriceMou-devone.php
Normal file
@@ -0,0 +1,547 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
class SsPriceMou{
|
||||
|
||||
// retrun array status, message
|
||||
public function create($mouID) {
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("onedev",true);
|
||||
|
||||
$sql = "select * from m_mou where M_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "MOU ID : $mouID not found");
|
||||
}
|
||||
$companyID = $rows[0]["M_MouM_CompanyID"];
|
||||
|
||||
$sql = "select distinct T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y'
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID <> 5
|
||||
where T_PriceM_MouID = ?
|
||||
and length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional select t_price " . print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$flag_error = false;
|
||||
foreach($rows as $idx => $r) {
|
||||
$nat_testType = $r["Nat_TestNat_TestTypeID"];
|
||||
switch($nat_testType) {
|
||||
case 1: //Single
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
case 3: //Multi
|
||||
case 4: //Panel
|
||||
$sasCode = $r["T_TestSasCode"] . '%';
|
||||
$sql = "select T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestIsResult = 'Y'
|
||||
and T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array($r["Nat_TestID"]);
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = $nr["T_TestNat_TestID"];
|
||||
}
|
||||
$rows[$idx]['nat_test'] = "[" . join(",",$t_rows) . "]";
|
||||
break;
|
||||
default :
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
}
|
||||
unset($rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
//Test Profile
|
||||
// wip profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, 0 T_PriceAmount, 0 T_PriceDisc, 0 T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, 0 T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PXR' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_test
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID = 5
|
||||
where length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$p_rows = $qry->result_array();
|
||||
|
||||
$sql = "select distinct substr(T_TestSasCode,1,8) parentCode, T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode,T_TestIsResult, T_TestCode
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y'
|
||||
and T_PriceIsCito = 'N'
|
||||
and length(T_TestSasCode) = 10
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
where T_PriceM_MouID = ? ";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional child test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_child = array();
|
||||
$p_codes = "'0'";
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
if ( ! isset($arr_child[$pCode])) {
|
||||
$arr_child[$pCode] = array();
|
||||
}
|
||||
$cCode = $r["T_TestSasCode"];
|
||||
$p_codes .= ", '$cCode'";
|
||||
unset($r["parentCode"]);
|
||||
$arr_child[$pCode][] = $r;
|
||||
}
|
||||
$sql = "select substr(T_TestSasCode,1,8) parentCode,
|
||||
group_concat(distinct T_TestNat_TestID) nat
|
||||
from t_test
|
||||
where ( T_TestIsResult = 'Y' or T_TestIsPrice = 'Y' )
|
||||
and T_TestSasCode in ( $p_codes )
|
||||
and T_TestIsActive = 'Y'
|
||||
group by parentCode";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_nat = array();
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
//if ( ! isset($arr_nat[$pCode])) {
|
||||
// $arr_nat[$pCode] = array();
|
||||
//}
|
||||
$arr_nat[$pCode] = $r["nat"];
|
||||
}
|
||||
$flag_error = false;
|
||||
foreach($p_rows as $idx => $r) {
|
||||
$T_TestName= $r["T_TestName"] ;
|
||||
$sasCode = $r["T_TestSasCode"];
|
||||
if ( isset($arr_child[$sasCode]) ) {
|
||||
$the_childs = $arr_child[$sasCode];
|
||||
$p_rows[$idx]['child_test'] = json_encode($the_childs,true);
|
||||
if ( isset($arr_nat[$sasCode] )) {
|
||||
$p_rows[$idx]['nat_test'] = "[" . $arr_nat[$sasCode] . "]";
|
||||
}
|
||||
unset($p_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($p_rows[$idx]["T_TestSasCode"]);
|
||||
} else {
|
||||
unset($p_rows[$idx]);
|
||||
}
|
||||
}
|
||||
//Paket Panel / Profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_PacketID T_TestID, T_PacketName T_TestName, 'N' IsFromPanel, 0 Nat_TestID,
|
||||
T_PacketID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, T_PacketOriginalBruto T_PriceAmount, 0 T_PriceDisc,
|
||||
(T_PacketOriginalBruto - T_PacketPrice) T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketPrice T_PriceTotal, 'Y' T_TestForceSell, 'Y' is_packet, T_PacketID packet_id,
|
||||
T_PacketType px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
$mouID Ss_PriceMouM_MouID
|
||||
from
|
||||
t_packet
|
||||
where
|
||||
T_PacketIsActive = 'Y'
|
||||
and T_PacketM_MouID = ?";
|
||||
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$pn_rows = $qry->result_array();
|
||||
foreach($pn_rows as $idx => $pnr) {
|
||||
$packetID = $pnr["packet_id"];
|
||||
//child test
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID,
|
||||
$mouID T_PriceM_MouID, 0 T_PricePriority, T_PacketDetailPriceAmount T_PriceAmount,
|
||||
T_PacketDetailPriceDisc T_PriceDisc, T_PacketDetailPriceDiscRp T_PriceDiscRp, T_PacketDetailPriceSubTotal T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketDetailPrice T_PriceTotal,
|
||||
'Y' T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite, T_TestSasCode
|
||||
from t_packetdetail
|
||||
join t_test on T_PacketDetailT_TestID = T_TestID
|
||||
and T_PacketDetailIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_PacketDetailT_PacketID = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($packetID));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$ct_rows = $qry->result_array();
|
||||
$p_nat_test = array();
|
||||
foreach($ct_rows as $ct_idx => $cr) {
|
||||
$sasCode = $cr["T_TestSasCode"] . '%';
|
||||
$sql = "select distinct T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array();
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = intval( $nr["T_TestNat_TestID"]);
|
||||
$p_nat_test[]= intval( $nr["T_TestNat_TestID"]);
|
||||
}
|
||||
$ct_rows[$ct_idx]['nat_test'] = json_encode($t_rows,JSON_NUMERIC_CHECK);
|
||||
}
|
||||
if (count($ct_rows) > 0 ) {
|
||||
$x_arr = array();
|
||||
foreach($ct_rows as $x_cr) {
|
||||
$x_arr[] = $x_cr;
|
||||
}
|
||||
$pn_rows[$idx]['child_test'] = json_encode($x_arr,true);
|
||||
$pn_rows[$idx]['nat_test'] = json_encode($p_nat_test,true);
|
||||
}
|
||||
unset($pn_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($pn_rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
|
||||
$rows = array_merge($rows,$p_rows, $pn_rows);
|
||||
$qry = $this->db->query("delete from ss_price_mou where Ss_PriceMouM_MouID=?", array($mouID));
|
||||
if ( ! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$qry = $this->db->insert_batch("ss_price_mou", $rows);
|
||||
if ( ! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
return array(true, "OK");
|
||||
}
|
||||
public function edit($mouID,$testID,$cito) {
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("onedev",true);
|
||||
|
||||
$sql = "select * from t_test where T_TestID = ? ";
|
||||
$qry = $this->db->query($sql, array($testID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "No Test $testID found");
|
||||
}
|
||||
$sasCode = $rows[0]["T_TestSasCode"];
|
||||
if ( strlen($sasCode) == 8 ) {
|
||||
$flagProfile = false;
|
||||
} else {
|
||||
$flagProfile = true;
|
||||
}
|
||||
|
||||
$sql = "select * from m_mou where M_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "No MOU $mouID found");
|
||||
}
|
||||
$mouName = $rows[0]["M_MouName"];
|
||||
$companyID = $rows[0]["M_MouM_CompanyID"];
|
||||
|
||||
$sql = "select distinct T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID and T_TestID = ?
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y' and T_PriceIsCito = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID <> 5
|
||||
where T_PriceM_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($testID, $cito, $mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
|
||||
foreach($rows as $idx => $r) {
|
||||
$nat_testType = $r["Nat_TestNat_TestTypeID"];
|
||||
switch($nat_testType) {
|
||||
case 1: //Single
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
case 3: //Multi
|
||||
case 4: //Panel
|
||||
$sasCode = $r["T_TestSasCode"] . '%';
|
||||
$sql = "select T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestIsResult = 'Y'
|
||||
and T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array($r["Nat_TestID"]);
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = $nr["T_TestNat_TestID"];
|
||||
}
|
||||
$rows[$idx]['nat_test'] = "[" . join(",",$t_rows) . "]";
|
||||
break;
|
||||
default :
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
}
|
||||
unset($rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
}
|
||||
if ( count($rows) > 0 ) {
|
||||
$r = $rows[0];
|
||||
unset($r["T_TestSasCode"]);
|
||||
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
||||
$this->db->where("T_TestID", $r["T_TestID"]);
|
||||
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
||||
$qry = $this->db->update("ss_price_mou",$r);
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
}
|
||||
$sasCode = substr($sasCode,0,8);
|
||||
foreach($rows as $idx => $r ) {
|
||||
if ( strlen($r["T_TestSasCode"]) > 8 ) {
|
||||
unset($rows[$idx]);
|
||||
} else {
|
||||
unset($rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
}
|
||||
if ($cito == 'Y' ) {
|
||||
return array(true,"OK",$rows);
|
||||
}
|
||||
// for non cito
|
||||
if($flagProfile ) {
|
||||
//wip profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, 0 T_PriceAmount, 0 T_PriceDisc, 0 T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, 0 T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PXR' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_test
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID and T_TestSasCode = ?
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID = 5
|
||||
where length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($sasCode));
|
||||
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$p_rows = $qry->result_array();
|
||||
|
||||
$sasCodeLike = $sasCode . "%";
|
||||
$sql = "select distinct substr(T_TestSasCode,1,8) parentCode, T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode,T_TestIsResult, T_TestCode
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y' and T_PriceIsCito = 'N'
|
||||
and T_TestSasCode like ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
where T_PriceM_MouID = ? ";
|
||||
$qry = $this->db->query($sql,array($sasCodeLike,$mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional child_test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_child = array();
|
||||
$p_codes = "'0'";
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
if ( ! isset($arr_child[$pCode])) {
|
||||
$arr_child[$pCode] = array();
|
||||
}
|
||||
$cCode = $r["T_TestSasCode"];
|
||||
$p_codes .= ", '$cCode'";
|
||||
unset($r["parentCode"]);
|
||||
$arr_child[$pCode][] = $r;
|
||||
}
|
||||
|
||||
$sql = "select substr(T_TestSasCode,1,8) parentCode,
|
||||
group_concat(distinct T_TestNat_TestID) nat
|
||||
from t_test
|
||||
where ( T_TestIsResult = 'Y' or T_TestIsPrice = 'Y' )
|
||||
and T_TestSasCode in ( $p_codes )
|
||||
and T_TestIsActive = 'Y'
|
||||
group by parentCode";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional nat_test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_nat = array();
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
//if ( ! isset($arr_nat[$pCode])) {
|
||||
// $arr_nat[$pCode] = array();
|
||||
//}
|
||||
$arr_nat[$pCode] = $r["nat"];
|
||||
}
|
||||
|
||||
$flag_error = false;
|
||||
foreach($p_rows as $idx => $r) {
|
||||
$T_TestName= $r["T_TestName"] ;
|
||||
$sasCode = $r["T_TestSasCode"];
|
||||
if ( isset($arr_child[$sasCode]) ) {
|
||||
$the_childs = $arr_child[$sasCode];
|
||||
$p_rows[$idx]['child_test'] = json_encode($the_childs,true);
|
||||
if ( isset($arr_nat[$sasCode] )) {
|
||||
$p_rows[$idx]['nat_test'] = "[" . $arr_nat[$sasCode] . "]";
|
||||
}
|
||||
unset($p_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($p_rows[$idx]["T_TestSasCode"]);
|
||||
} else {
|
||||
unset($p_rows[$idx]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach($p_rows as $r) {
|
||||
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
||||
$this->db->where("T_TestID", $r["T_TestID"]);
|
||||
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
||||
$qry = $this->db->update("ss_price_mou",$r);
|
||||
if (! $qry ) {
|
||||
return array(false, "Err Update Ss_priceMou " . print_r($this->db->error(),true));
|
||||
}
|
||||
}
|
||||
$rows = array_merge($rows,$p_rows);
|
||||
}
|
||||
//Update Panel yang mengandung Test
|
||||
$sql = "select
|
||||
distinct T_PacketDetailT_PacketID
|
||||
from
|
||||
t_packetdetail
|
||||
where T_PacketDetailIsActive = 'Y'
|
||||
and T_PacketDetailT_TestID = ?";
|
||||
$qry = $this->db->query($sql, array($testID));
|
||||
if (!$qry) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$packet_ids = "0";
|
||||
foreach($xrows as $r ) {
|
||||
$packet_ids .= "," . $r["T_PacketDetailT_PacketID"];
|
||||
}
|
||||
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_PacketID T_TestID, T_PacketName T_TestName, 'N' IsFromPanel, 0 Nat_TestID,
|
||||
T_PacketID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, T_PacketOriginalBruto T_PriceAmount, 0 T_PriceDisc,
|
||||
(T_PacketOriginalBruto - T_PacketPrice) T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketPrice T_PriceTotal, 'Y' T_TestForceSell, 'Y' is_packet, T_PacketID packet_id,
|
||||
T_PacketType px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
$mouID Ss_PriceMouM_MouID
|
||||
from
|
||||
t_packet
|
||||
where
|
||||
T_PacketIsActive = 'Y' and T_PacketID in ( $packet_ids )
|
||||
and T_PacketM_MouID = ?";
|
||||
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$pn_rows = $qry->result_array();
|
||||
foreach($pn_rows as $idx => $pnr) {
|
||||
$packetID = $pnr["packet_id"];
|
||||
//child test
|
||||
$sql = "select $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID,
|
||||
$mouID T_PriceM_MouID, 0 T_PricePriority, T_PacketDetailPriceAmount T_PriceAmount,
|
||||
T_PacketDetailPriceDisc T_PriceDisc, T_PacketDetailPriceDiscRp T_PriceDiscRp, T_PacketDetailPriceSubTotal T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketDetailPrice T_PriceTotal,
|
||||
'Y' T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite, T_TestSasCode
|
||||
from t_packetdetail
|
||||
join t_test on T_PacketDetailT_TestID = T_TestID
|
||||
and T_PacketDetailIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_PacketDetailT_PacketID = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
";
|
||||
$qry = $this->db->query($sql,array($packetID));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$ct_rows = $qry->result_array();
|
||||
$p_nat_test = array();
|
||||
foreach($ct_rows as $ct_idx => $cr) {
|
||||
$sasCode = $cr["T_TestSasCode"] . '%';
|
||||
$sql = "select distinct T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array();
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = intval( $nr["T_TestNat_TestID"]);
|
||||
$p_nat_test[]= intval( $nr["T_TestNat_TestID"]);
|
||||
}
|
||||
$ct_rows[$ct_idx]['nat_test'] = json_encode($t_rows,JSON_NUMERIC_CHECK);
|
||||
}
|
||||
if (count($ct_rows) > 0 ) {
|
||||
$x_arr = array();
|
||||
foreach($ct_rows as $x_cr) {
|
||||
$x_arr[] = $x_cr;
|
||||
}
|
||||
$pn_rows[$idx]['child_test'] = json_encode($x_arr,true);
|
||||
$pn_rows[$idx]['nat_test'] = json_encode($p_nat_test,true);
|
||||
}
|
||||
unset($pn_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($pn_rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
foreach($pn_rows as $r ) {
|
||||
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
||||
$this->db->where("T_TestID", $r["T_TestID"]);
|
||||
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
||||
$qry = $this->db->update("ss_price_mou",$r);
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
}
|
||||
$rows = array_merge($rows,$pn_rows);
|
||||
return array(true,"OK",$rows);
|
||||
}
|
||||
}
|
||||
547
one-api/application/libraries/SsPriceMou-prod-04-12.php
Normal file
547
one-api/application/libraries/SsPriceMou-prod-04-12.php
Normal file
@@ -0,0 +1,547 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
class SsPriceMou{
|
||||
|
||||
// retrun array status, message
|
||||
public function create($mouID) {
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("regional",true);
|
||||
|
||||
$sql = "select * from m_mou where M_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "MOU ID : $mouID not found");
|
||||
}
|
||||
$companyID = $rows[0]["M_MouM_CompanyID"];
|
||||
|
||||
$sql = "select distinct T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y'
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID <> 5
|
||||
where T_PriceM_MouID = ?
|
||||
and length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional select t_price " . print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$flag_error = false;
|
||||
foreach($rows as $idx => $r) {
|
||||
$nat_testType = $r["Nat_TestNat_TestTypeID"];
|
||||
switch($nat_testType) {
|
||||
case 1: //Single
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
case 3: //Multi
|
||||
case 4: //Panel
|
||||
$sasCode = $r["T_TestSasCode"] . '%';
|
||||
$sql = "select T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestIsResult = 'Y'
|
||||
and T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array($r["Nat_TestID"]);
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = $nr["T_TestNat_TestID"];
|
||||
}
|
||||
$rows[$idx]['nat_test'] = "[" . join(",",$t_rows) . "]";
|
||||
break;
|
||||
default :
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
}
|
||||
unset($rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
//Test Profile
|
||||
// wip profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, 0 T_PriceAmount, 0 T_PriceDisc, 0 T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, 0 T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PXR' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_test
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID = 5
|
||||
where length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$p_rows = $qry->result_array();
|
||||
|
||||
$sql = "select distinct substr(T_TestSasCode,1,8) parentCode, T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode,T_TestIsResult, T_TestCode
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y'
|
||||
and T_PriceIsCito = 'N'
|
||||
and length(T_TestSasCode) = 10
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
where T_PriceM_MouID = ? ";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional child test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_child = array();
|
||||
$p_codes = "'0'";
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
if ( ! isset($arr_child[$pCode])) {
|
||||
$arr_child[$pCode] = array();
|
||||
}
|
||||
$cCode = $r["T_TestSasCode"];
|
||||
$p_codes .= ", '$cCode'";
|
||||
unset($r["parentCode"]);
|
||||
$arr_child[$pCode][] = $r;
|
||||
}
|
||||
$sql = "select substr(T_TestSasCode,1,8) parentCode,
|
||||
group_concat(distinct T_TestNat_TestID) nat
|
||||
from t_test
|
||||
where ( T_TestIsResult = 'Y' or T_TestIsPrice = 'Y' )
|
||||
and T_TestSasCode in ( $p_codes )
|
||||
and T_TestIsActive = 'Y'
|
||||
group by parentCode";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_nat = array();
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
//if ( ! isset($arr_nat[$pCode])) {
|
||||
// $arr_nat[$pCode] = array();
|
||||
//}
|
||||
$arr_nat[$pCode] = $r["nat"];
|
||||
}
|
||||
$flag_error = false;
|
||||
foreach($p_rows as $idx => $r) {
|
||||
$T_TestName= $r["T_TestName"] ;
|
||||
$sasCode = $r["T_TestSasCode"];
|
||||
if ( isset($arr_child[$sasCode]) ) {
|
||||
$the_childs = $arr_child[$sasCode];
|
||||
$p_rows[$idx]['child_test'] = json_encode($the_childs,true);
|
||||
if ( isset($arr_nat[$sasCode] )) {
|
||||
$p_rows[$idx]['nat_test'] = "[" . $arr_nat[$sasCode] . "]";
|
||||
}
|
||||
unset($p_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($p_rows[$idx]["T_TestSasCode"]);
|
||||
} else {
|
||||
unset($p_rows[$idx]);
|
||||
}
|
||||
}
|
||||
//Paket Panel / Profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_PacketID T_TestID, T_PacketName T_TestName, 'N' IsFromPanel, 0 Nat_TestID,
|
||||
0 T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, T_PacketOriginalPrice T_PriceAmount, 0 T_PriceDisc,
|
||||
(T_PacketOriginalPrice - T_PacketPrice) T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketPrice T_PriceTotal, 'Y' T_TestForceSell, 'Y' is_packet, T_PacketID packet_id,
|
||||
T_PacketType px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
$mouID Ss_PriceMouM_MouID
|
||||
from
|
||||
t_packet
|
||||
where
|
||||
T_PacketIsActive = 'Y'
|
||||
and T_PacketM_MouID = ?";
|
||||
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$pn_rows = $qry->result_array();
|
||||
foreach($pn_rows as $idx => $pnr) {
|
||||
$packetID = $pnr["packet_id"];
|
||||
//child test
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID,
|
||||
$mouID T_PriceM_MouID, 0 T_PricePriority, T_PacketDetailPrice T_PriceAmount,
|
||||
0 T_PriceDisc, 0 T_PriceDiscRp, T_PacketDetailPrice T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketDetailPrice T_PriceTotal,
|
||||
'Y' T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite, T_TestSasCode
|
||||
from t_packetdetail
|
||||
join t_test on T_PacketDetailT_TestID = T_TestID
|
||||
and T_PacketDetailIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_PacketDetailT_PacketID = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($packetID));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$ct_rows = $qry->result_array();
|
||||
$p_nat_test = array();
|
||||
foreach($ct_rows as $ct_idx => $cr) {
|
||||
$sasCode = $cr["T_TestSasCode"] . '%';
|
||||
$sql = "select distinct T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array();
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = intval( $nr["T_TestNat_TestID"]);
|
||||
$p_nat_test[]= intval( $nr["T_TestNat_TestID"]);
|
||||
}
|
||||
$ct_rows[$ct_idx]['nat_test'] = json_encode($t_rows,JSON_NUMERIC_CHECK);
|
||||
}
|
||||
if (count($ct_rows) > 0 ) {
|
||||
$x_arr = array();
|
||||
foreach($ct_rows as $x_cr) {
|
||||
$x_arr[] = $x_cr;
|
||||
}
|
||||
$pn_rows[$idx]['child_test'] = json_encode($x_arr,true);
|
||||
$pn_rows[$idx]['nat_test'] = json_encode($p_nat_test,true);
|
||||
}
|
||||
unset($pn_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($pn_rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
|
||||
$rows = array_merge($rows,$p_rows, $pn_rows);
|
||||
$qry = $this->db->query("delete from ss_price_mou where Ss_PriceMouM_MouID=?", array($mouID));
|
||||
if ( ! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$qry = $this->db->insert_batch("ss_price_mou", $rows);
|
||||
if ( ! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
return array(true, "OK");
|
||||
}
|
||||
public function edit($mouID,$testID,$cito) {
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("regional",true);
|
||||
|
||||
$sql = "select * from t_test where T_TestID = ? ";
|
||||
$qry = $this->db->query($sql, array($testID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "No Test $testID found");
|
||||
}
|
||||
$sasCode = $rows[0]["T_TestSasCode"];
|
||||
if ( strlen($sasCode) == 8 ) {
|
||||
$flagProfile = false;
|
||||
} else {
|
||||
$flagProfile = true;
|
||||
}
|
||||
|
||||
$sql = "select * from m_mou where M_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "No MOU $mouID found");
|
||||
}
|
||||
$mouName = $rows[0]["M_MouName"];
|
||||
$companyID = $rows[0]["M_MouM_CompanyID"];
|
||||
|
||||
$sql = "select distinct T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID and T_TestID = ?
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y' and T_PriceIsCito = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID <> 5
|
||||
where T_PriceM_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($testID, $cito, $mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
|
||||
foreach($rows as $idx => $r) {
|
||||
$nat_testType = $r["Nat_TestNat_TestTypeID"];
|
||||
switch($nat_testType) {
|
||||
case 1: //Single
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
case 3: //Multi
|
||||
case 4: //Panel
|
||||
$sasCode = $r["T_TestSasCode"] . '%';
|
||||
$sql = "select T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestIsResult = 'Y'
|
||||
and T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array($r["Nat_TestID"]);
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = $nr["T_TestNat_TestID"];
|
||||
}
|
||||
$rows[$idx]['nat_test'] = "[" . join(",",$t_rows) . "]";
|
||||
break;
|
||||
default :
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
}
|
||||
unset($rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
}
|
||||
if ( count($rows) > 0 ) {
|
||||
$r = $rows[0];
|
||||
unset($r["T_TestSasCode"]);
|
||||
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
||||
$this->db->where("T_TestID", $r["T_TestID"]);
|
||||
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
||||
$qry = $this->db->update("ss_price_mou",$r);
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
}
|
||||
$sasCode = substr($sasCode,0,8);
|
||||
foreach($rows as $idx => $r ) {
|
||||
if ( strlen($r["T_TestSasCode"]) > 8 ) {
|
||||
unset($rows[$idx]);
|
||||
} else {
|
||||
unset($rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
}
|
||||
if ($cito == 'Y' ) {
|
||||
return array(true,"OK",$rows);
|
||||
}
|
||||
// for non cito
|
||||
if($flagProfile ) {
|
||||
//wip profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, 0 T_PriceAmount, 0 T_PriceDisc, 0 T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, 0 T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PXR' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_test
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID and T_TestSasCode = ?
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID = 5
|
||||
where length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($sasCode));
|
||||
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$p_rows = $qry->result_array();
|
||||
|
||||
$sasCodeLike = $sasCode . "%";
|
||||
$sql = "select distinct substr(T_TestSasCode,1,8) parentCode, T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode,T_TestIsResult, T_TestCode
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y' and T_PriceIsCito = 'N'
|
||||
and T_TestSasCode like ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
where T_PriceM_MouID = ? ";
|
||||
$qry = $this->db->query($sql,array($sasCodeLike,$mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional child_test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_child = array();
|
||||
$p_codes = "'0'";
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
if ( ! isset($arr_child[$pCode])) {
|
||||
$arr_child[$pCode] = array();
|
||||
}
|
||||
$cCode = $r["T_TestSasCode"];
|
||||
$p_codes .= ", '$cCode'";
|
||||
unset($r["parentCode"]);
|
||||
$arr_child[$pCode][] = $r;
|
||||
}
|
||||
|
||||
$sql = "select substr(T_TestSasCode,1,8) parentCode,
|
||||
group_concat(distinct T_TestNat_TestID) nat
|
||||
from t_test
|
||||
where ( T_TestIsResult = 'Y' or T_TestIsPrice = 'Y' )
|
||||
and T_TestSasCode in ( $p_codes )
|
||||
and T_TestIsActive = 'Y'
|
||||
group by parentCode";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional nat_test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_nat = array();
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
//if ( ! isset($arr_nat[$pCode])) {
|
||||
// $arr_nat[$pCode] = array();
|
||||
//}
|
||||
$arr_nat[$pCode] = $r["nat"];
|
||||
}
|
||||
|
||||
$flag_error = false;
|
||||
foreach($p_rows as $idx => $r) {
|
||||
$T_TestName= $r["T_TestName"] ;
|
||||
$sasCode = $r["T_TestSasCode"];
|
||||
if ( isset($arr_child[$sasCode]) ) {
|
||||
$the_childs = $arr_child[$sasCode];
|
||||
$p_rows[$idx]['child_test'] = json_encode($the_childs,true);
|
||||
if ( isset($arr_nat[$sasCode] )) {
|
||||
$p_rows[$idx]['nat_test'] = "[" . $arr_nat[$sasCode] . "]";
|
||||
}
|
||||
unset($p_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($p_rows[$idx]["T_TestSasCode"]);
|
||||
} else {
|
||||
unset($p_rows[$idx]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach($p_rows as $r) {
|
||||
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
||||
$this->db->where("T_TestID", $r["T_TestID"]);
|
||||
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
||||
$qry = $this->db->update("ss_price_mou",$r);
|
||||
if (! $qry ) {
|
||||
return array(false, "Err Update Ss_priceMou " . print_r($this->db->error(),true));
|
||||
}
|
||||
}
|
||||
$rows = array_merge($rows,$p_rows);
|
||||
}
|
||||
//Update Panel yang mengandung Test
|
||||
$sql = "select
|
||||
distinct T_PacketDetailT_PacketID
|
||||
from
|
||||
t_packetdetail
|
||||
where T_PacketDetailIsActive = 'Y'
|
||||
and T_PacketDetailT_TestID = ?";
|
||||
$qry = $this->db->query($sql, array($testID));
|
||||
if (!$qry) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$packet_ids = "0";
|
||||
foreach($xrows as $r ) {
|
||||
$packet_ids .= "," . $r["T_PacketDetailT_PacketID"];
|
||||
}
|
||||
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_PacketID T_TestID, T_PacketName T_TestName, 'N' IsFromPanel, 0 Nat_TestID,
|
||||
0 T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, T_PacketOriginalPrice T_PriceAmount, 0 T_PriceDisc,
|
||||
(T_PacketOriginalPrice - T_PacketPrice) T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketPrice T_PriceTotal, 'Y' T_TestForceSell, 'Y' is_packet, T_PacketID packet_id,
|
||||
T_PacketType px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
$mouID Ss_PriceMouM_MouID
|
||||
from
|
||||
t_packet
|
||||
where
|
||||
T_PacketIsActive = 'Y' and T_PacketID in ( $packet_ids )
|
||||
and T_PacketM_MouID = ?";
|
||||
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$pn_rows = $qry->result_array();
|
||||
foreach($pn_rows as $idx => $pnr) {
|
||||
$packetID = $pnr["packet_id"];
|
||||
//child test
|
||||
$sql = "select $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID,
|
||||
$mouID T_PriceM_MouID, 0 T_PricePriority, T_PacketDetailPrice T_PriceAmount,
|
||||
0 T_PriceDisc, 0 T_PriceDiscRp, T_PacketDetailPrice T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketDetailPrice T_PriceTotal,
|
||||
'Y' T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite, T_TestSasCode
|
||||
from t_packetdetail
|
||||
join t_test on T_PacketDetailT_TestID = T_TestID
|
||||
and T_PacketDetailIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_PacketDetailT_PacketID = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
";
|
||||
$qry = $this->db->query($sql,array($packetID));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$ct_rows = $qry->result_array();
|
||||
$p_nat_test = array();
|
||||
foreach($ct_rows as $ct_idx => $cr) {
|
||||
$sasCode = $cr["T_TestSasCode"] . '%';
|
||||
$sql = "select distinct T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array();
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = intval( $nr["T_TestNat_TestID"]);
|
||||
$p_nat_test[]= intval( $nr["T_TestNat_TestID"]);
|
||||
}
|
||||
$ct_rows[$ct_idx]['nat_test'] = json_encode($t_rows,JSON_NUMERIC_CHECK);
|
||||
}
|
||||
if (count($ct_rows) > 0 ) {
|
||||
$x_arr = array();
|
||||
foreach($ct_rows as $x_cr) {
|
||||
$x_arr[] = $x_cr;
|
||||
}
|
||||
$pn_rows[$idx]['child_test'] = json_encode($x_arr,true);
|
||||
$pn_rows[$idx]['nat_test'] = json_encode($p_nat_test,true);
|
||||
}
|
||||
unset($pn_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($pn_rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
foreach($pn_rows as $r ) {
|
||||
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
||||
$this->db->where("T_TestID", $r["T_TestID"]);
|
||||
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
||||
$qry = $this->db->update("ss_price_mou",$r);
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
}
|
||||
$rows = array_merge($rows,$pn_rows);
|
||||
return array(true,"OK",$rows);
|
||||
}
|
||||
}
|
||||
559
one-api/application/libraries/SsPriceMou.php
Normal file
559
one-api/application/libraries/SsPriceMou.php
Normal file
@@ -0,0 +1,559 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
class SsPriceMou{
|
||||
|
||||
// retrun array status, message
|
||||
public function create($mouID) {
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("regional",true);
|
||||
|
||||
$sql = "select * from m_mou where M_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "MOU ID : $mouID not found");
|
||||
}
|
||||
$companyID = $rows[0]["M_MouM_CompanyID"];
|
||||
|
||||
$sql = "select distinct T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y'
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID <> 5
|
||||
where T_PriceM_MouID = ?
|
||||
and length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional select t_price " . print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$flag_error = false;
|
||||
foreach($rows as $idx => $r) {
|
||||
$nat_testType = $r["Nat_TestNat_TestTypeID"];
|
||||
switch($nat_testType) {
|
||||
case 1: //Single
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
case 3: //Multi
|
||||
case 4: //Panel
|
||||
$sasCode = $r["T_TestSasCode"] . '%';
|
||||
$sql = "select T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestIsResult = 'Y'
|
||||
and T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array($r["Nat_TestID"]);
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = $nr["T_TestNat_TestID"];
|
||||
}
|
||||
$rows[$idx]['nat_test'] = "[" . join(",",$t_rows) . "]";
|
||||
break;
|
||||
default :
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
}
|
||||
unset($rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
//Test Profile
|
||||
// wip profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, 0 T_PriceAmount, 0 T_PriceDisc, 0 T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, 0 T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PXR' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_test
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID = 5
|
||||
where length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$p_rows = $qry->result_array();
|
||||
|
||||
$sql = "select distinct substr(T_TestSasCode,1,8) parentCode, T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode,T_TestIsResult, T_TestCode
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y'
|
||||
and T_PriceIsCito = 'N'
|
||||
and length(T_TestSasCode) = 10
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
where T_PriceM_MouID = ? ";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional child test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_child = array();
|
||||
$p_codes = "'0'";
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
if ( ! isset($arr_child[$pCode])) {
|
||||
$arr_child[$pCode] = array();
|
||||
}
|
||||
$cCode = $r["T_TestSasCode"];
|
||||
$p_codes .= ", '$cCode'";
|
||||
unset($r["parentCode"]);
|
||||
$arr_child[$pCode][] = $r;
|
||||
}
|
||||
$sql = "select substr(T_TestSasCode,1,8) parentCode,
|
||||
group_concat(distinct T_TestNat_TestID) nat
|
||||
from t_test
|
||||
where ( T_TestIsResult = 'Y' or T_TestIsPrice = 'Y' )
|
||||
and T_TestSasCode in ( $p_codes )
|
||||
and T_TestIsActive = 'Y'
|
||||
group by parentCode";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_nat = array();
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
//if ( ! isset($arr_nat[$pCode])) {
|
||||
// $arr_nat[$pCode] = array();
|
||||
//}
|
||||
$arr_nat[$pCode] = $r["nat"];
|
||||
}
|
||||
$flag_error = false;
|
||||
foreach($p_rows as $idx => $r) {
|
||||
$T_TestName= $r["T_TestName"] ;
|
||||
$sasCode = $r["T_TestSasCode"];
|
||||
if ( isset($arr_child[$sasCode]) ) {
|
||||
$the_childs = $arr_child[$sasCode];
|
||||
$p_rows[$idx]['child_test'] = json_encode($the_childs,true);
|
||||
if ( isset($arr_nat[$sasCode] )) {
|
||||
$p_rows[$idx]['nat_test'] = "[" . $arr_nat[$sasCode] . "]";
|
||||
}
|
||||
unset($p_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($p_rows[$idx]["T_TestSasCode"]);
|
||||
} else {
|
||||
unset($p_rows[$idx]);
|
||||
}
|
||||
}
|
||||
//Paket Panel / Profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_PacketID T_TestID, T_PacketName T_TestName, 'N' IsFromPanel, 0 Nat_TestID,
|
||||
T_PacketID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, T_PacketOriginalBruto T_PriceAmount, 0 T_PriceDisc,
|
||||
(T_PacketOriginalBruto - T_PacketPrice) T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketPrice T_PriceTotal, 'Y' T_TestForceSell, 'Y' is_packet, T_PacketID packet_id,
|
||||
T_PacketType px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
$mouID Ss_PriceMouM_MouID
|
||||
from
|
||||
t_packet
|
||||
where
|
||||
T_PacketIsActive = 'Y'
|
||||
and T_PacketM_MouID = ?";
|
||||
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$pn_rows = $qry->result_array();
|
||||
foreach($pn_rows as $idx => $pnr) {
|
||||
$packetID = $pnr["packet_id"];
|
||||
//child test
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID,
|
||||
$mouID T_PriceM_MouID, 0 T_PricePriority, T_PacketDetailPriceAmount T_PriceAmount,
|
||||
T_PacketDetailPriceDisc T_PriceDisc, T_PacketDetailPriceDiscRp T_PriceDiscRp, T_PacketDetailPriceSubTotal T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketDetailPrice T_PriceTotal,
|
||||
'Y' T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite, T_TestSasCode
|
||||
from t_packetdetail
|
||||
join t_test on T_PacketDetailT_TestID = T_TestID
|
||||
and T_PacketDetailIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_PacketDetailT_PacketID = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($packetID));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$ct_rows = $qry->result_array();
|
||||
$p_nat_test = array();
|
||||
foreach($ct_rows as $ct_idx => $cr) {
|
||||
$sasCode = $cr["T_TestSasCode"] . '%';
|
||||
$sql = "select distinct T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array();
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = intval( $nr["T_TestNat_TestID"]);
|
||||
$p_nat_test[]= intval( $nr["T_TestNat_TestID"]);
|
||||
}
|
||||
$ct_rows[$ct_idx]['nat_test'] = json_encode($t_rows,JSON_NUMERIC_CHECK);
|
||||
}
|
||||
if (count($ct_rows) > 0 ) {
|
||||
$x_arr = array();
|
||||
foreach($ct_rows as $x_cr) {
|
||||
$x_arr[] = $x_cr;
|
||||
}
|
||||
$pn_rows[$idx]['child_test'] = json_encode($x_arr,true);
|
||||
$pn_rows[$idx]['nat_test'] = json_encode($p_nat_test,true);
|
||||
}
|
||||
unset($pn_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($pn_rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
|
||||
$rows = array_merge($rows,$p_rows, $pn_rows);
|
||||
$qry = $this->db->query("delete from ss_price_mou where Ss_PriceMouM_MouID=?", array($mouID));
|
||||
if ( ! $qry ) {
|
||||
return array(false, "Regional Delete : " . print_r($this->db->error(),true));
|
||||
}
|
||||
if ( count($rows) == 0 ) {
|
||||
return array(false,"Empty Data");
|
||||
}
|
||||
$qry = $this->db->insert_batch("ss_price_mou", $rows);
|
||||
if ( ! $qry ) {
|
||||
return array(false, "Regional Insert : " . print_r($this->db->error(),true));
|
||||
}
|
||||
return array(true, "OK");
|
||||
}
|
||||
public function edit($mouID,$testID,$cito) {
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("regional",true);
|
||||
|
||||
$sql = "select * from t_test where T_TestID = ? ";
|
||||
$qry = $this->db->query($sql, array($testID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "No Test $testID found");
|
||||
}
|
||||
$sasCode = $rows[0]["T_TestSasCode"];
|
||||
if ( strlen($sasCode) == 8 ) {
|
||||
$flagProfile = false;
|
||||
} else {
|
||||
$flagProfile = true;
|
||||
}
|
||||
|
||||
$sql = "select * from m_mou where M_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "No MOU $mouID found");
|
||||
}
|
||||
$mouName = $rows[0]["M_MouName"];
|
||||
$companyID = $rows[0]["M_MouM_CompanyID"];
|
||||
|
||||
$sql = "select distinct T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID and T_TestID = ?
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y' and T_PriceIsCito = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID <> 5
|
||||
where T_PriceM_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($testID, $cito, $mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
|
||||
foreach($rows as $idx => $r) {
|
||||
$nat_testType = $r["Nat_TestNat_TestTypeID"];
|
||||
switch($nat_testType) {
|
||||
case 1: //Single
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
case 3: //Multi
|
||||
case 4: //Panel
|
||||
$sasCode = $r["T_TestSasCode"] . '%';
|
||||
$sql = "select T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestIsResult = 'Y'
|
||||
and T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array($r["Nat_TestID"]);
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = $nr["T_TestNat_TestID"];
|
||||
}
|
||||
$rows[$idx]['nat_test'] = "[" . join(",",$t_rows) . "]";
|
||||
break;
|
||||
default :
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
}
|
||||
unset($rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
}
|
||||
if ( count($rows) > 0 ) {
|
||||
$r = $rows[0];
|
||||
unset($r["T_TestSasCode"]);
|
||||
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
||||
$this->db->where("T_TestID", $r["T_TestID"]);
|
||||
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
||||
$qry = $this->db->update("ss_price_mou",$r);
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
if ($this->db->affected_rows() == 0 ) {
|
||||
$this->db->insert("ss_price_mou", $r);
|
||||
}
|
||||
}
|
||||
$sasCode = substr($sasCode,0,8);
|
||||
foreach($rows as $idx => $r ) {
|
||||
if ( strlen($r["T_TestSasCode"]) > 8 ) {
|
||||
unset($rows[$idx]);
|
||||
} else {
|
||||
unset($rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
}
|
||||
if ($cito == 'Y' ) {
|
||||
return array(true,"OK",$rows);
|
||||
}
|
||||
// for non cito
|
||||
if($flagProfile ) {
|
||||
//wip profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, 0 T_PriceAmount, 0 T_PriceDisc, 0 T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, 0 T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PXR' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_test
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID and T_TestSasCode = ?
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID = 5
|
||||
where length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($sasCode));
|
||||
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$p_rows = $qry->result_array();
|
||||
|
||||
$sasCodeLike = $sasCode . "%";
|
||||
$sql = "select distinct substr(T_TestSasCode,1,8) parentCode, T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode,T_TestIsResult, T_TestCode
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y' and T_PriceIsCito = 'N'
|
||||
and T_TestSasCode like ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
where T_PriceM_MouID = ? ";
|
||||
$qry = $this->db->query($sql,array($sasCodeLike,$mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional child_test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_child = array();
|
||||
$p_codes = "'0'";
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
if ( ! isset($arr_child[$pCode])) {
|
||||
$arr_child[$pCode] = array();
|
||||
}
|
||||
$cCode = $r["T_TestSasCode"];
|
||||
$p_codes .= ", '$cCode'";
|
||||
unset($r["parentCode"]);
|
||||
$arr_child[$pCode][] = $r;
|
||||
}
|
||||
|
||||
$sql = "select substr(T_TestSasCode,1,8) parentCode,
|
||||
group_concat(distinct T_TestNat_TestID) nat
|
||||
from t_test
|
||||
where ( T_TestIsResult = 'Y' or T_TestIsPrice = 'Y' )
|
||||
and T_TestSasCode in ( $p_codes )
|
||||
and T_TestIsActive = 'Y'
|
||||
group by parentCode";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional nat_test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_nat = array();
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
//if ( ! isset($arr_nat[$pCode])) {
|
||||
// $arr_nat[$pCode] = array();
|
||||
//}
|
||||
$arr_nat[$pCode] = $r["nat"];
|
||||
}
|
||||
|
||||
$flag_error = false;
|
||||
foreach($p_rows as $idx => $r) {
|
||||
$T_TestName= $r["T_TestName"] ;
|
||||
$sasCode = $r["T_TestSasCode"];
|
||||
if ( isset($arr_child[$sasCode]) ) {
|
||||
$the_childs = $arr_child[$sasCode];
|
||||
$p_rows[$idx]['child_test'] = json_encode($the_childs,true);
|
||||
if ( isset($arr_nat[$sasCode] )) {
|
||||
$p_rows[$idx]['nat_test'] = "[" . $arr_nat[$sasCode] . "]";
|
||||
}
|
||||
unset($p_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($p_rows[$idx]["T_TestSasCode"]);
|
||||
} else {
|
||||
unset($p_rows[$idx]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach($p_rows as $r) {
|
||||
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
||||
$this->db->where("T_TestID", $r["T_TestID"]);
|
||||
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
||||
$qry = $this->db->update("ss_price_mou",$r);
|
||||
if (! $qry ) {
|
||||
return array(false, "Err Update Ss_priceMou " . print_r($this->db->error(),true));
|
||||
}
|
||||
if ($this->db->affected_rows() == 0 ) {
|
||||
$this->db->insert("ss_price_mou", $r);
|
||||
}
|
||||
}
|
||||
$rows = array_merge($rows,$p_rows);
|
||||
}
|
||||
//Update Panel yang mengandung Test
|
||||
$sql = "select
|
||||
distinct T_PacketDetailT_PacketID
|
||||
from
|
||||
t_packetdetail
|
||||
where T_PacketDetailIsActive = 'Y'
|
||||
and T_PacketDetailT_TestID = ?";
|
||||
$qry = $this->db->query($sql, array($testID));
|
||||
if (!$qry) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$packet_ids = "0";
|
||||
foreach($xrows as $r ) {
|
||||
$packet_ids .= "," . $r["T_PacketDetailT_PacketID"];
|
||||
}
|
||||
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_PacketID T_TestID, T_PacketName T_TestName, 'N' IsFromPanel, 0 Nat_TestID,
|
||||
T_PacketID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, T_PacketOriginalBruto T_PriceAmount, 0 T_PriceDisc,
|
||||
(T_PacketOriginalBruto - T_PacketPrice) T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketPrice T_PriceTotal, 'Y' T_TestForceSell, 'Y' is_packet, T_PacketID packet_id,
|
||||
T_PacketType px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
$mouID Ss_PriceMouM_MouID
|
||||
from
|
||||
t_packet
|
||||
where
|
||||
T_PacketIsActive = 'Y' and T_PacketID in ( $packet_ids )
|
||||
and T_PacketM_MouID = ?";
|
||||
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$pn_rows = $qry->result_array();
|
||||
foreach($pn_rows as $idx => $pnr) {
|
||||
$packetID = $pnr["packet_id"];
|
||||
//child test
|
||||
$sql = "select $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID,
|
||||
$mouID T_PriceM_MouID, 0 T_PricePriority, T_PacketDetailPriceAmount T_PriceAmount,
|
||||
T_PacketDetailPriceDisc T_PriceDisc, T_PacketDetailPriceDiscRp T_PriceDiscRp, T_PacketDetailPriceSubTotal T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketDetailPrice T_PriceTotal,
|
||||
'Y' T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite, T_TestSasCode
|
||||
from t_packetdetail
|
||||
join t_test on T_PacketDetailT_TestID = T_TestID
|
||||
and T_PacketDetailIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_PacketDetailT_PacketID = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
";
|
||||
$qry = $this->db->query($sql,array($packetID));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$ct_rows = $qry->result_array();
|
||||
$p_nat_test = array();
|
||||
foreach($ct_rows as $ct_idx => $cr) {
|
||||
$sasCode = $cr["T_TestSasCode"] . '%';
|
||||
$sql = "select distinct T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array();
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = intval( $nr["T_TestNat_TestID"]);
|
||||
$p_nat_test[]= intval( $nr["T_TestNat_TestID"]);
|
||||
}
|
||||
$ct_rows[$ct_idx]['nat_test'] = json_encode($t_rows,JSON_NUMERIC_CHECK);
|
||||
}
|
||||
if (count($ct_rows) > 0 ) {
|
||||
$x_arr = array();
|
||||
foreach($ct_rows as $x_cr) {
|
||||
$x_arr[] = $x_cr;
|
||||
}
|
||||
$pn_rows[$idx]['child_test'] = json_encode($x_arr,true);
|
||||
$pn_rows[$idx]['nat_test'] = json_encode($p_nat_test,true);
|
||||
}
|
||||
unset($pn_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($pn_rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
foreach($pn_rows as $r ) {
|
||||
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
||||
$this->db->where("T_TestID", $r["T_TestID"]);
|
||||
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
||||
$qry = $this->db->update("ss_price_mou",$r);
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
if ($this->db->affected_rows() == 0 ) {
|
||||
$this->db->insert("ss_price_mou", $r);
|
||||
}
|
||||
}
|
||||
$rows = array_merge($rows,$pn_rows);
|
||||
return array(true,"OK",$rows);
|
||||
}
|
||||
}
|
||||
52
one-api/application/libraries/SsPriceMouPx-dev.php
Normal file
52
one-api/application/libraries/SsPriceMouPx-dev.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
class SsPriceMouPx {
|
||||
|
||||
public function create($mouID) {
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("onedev",true);
|
||||
|
||||
$sql = "select * from ss_price_mou where Ss_PriceMouM_MouID = ? and px_type in ('PR','PXR')";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if ( ! $qry ) {
|
||||
return array(false, "Ss Price Mou " . print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$sql ="delete from ss_price_mou_px where Ss_PriceMouPxSs_PriceMouID in ( select Ss_PriceMouID from ss_price_mou
|
||||
where Ss_PriceMouM_MouID = ? )";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if ( ! $qry ) {
|
||||
return array(false, "Clear Ss Price Mou Px" . print_r($this->db->error(),true));
|
||||
}
|
||||
$a_data = array();
|
||||
foreach($rows as $r) {
|
||||
$j_ct = $r["child_test"];
|
||||
$ct = json_decode($j_ct,true);
|
||||
foreach($ct as $c) {
|
||||
$a_data[] = array(
|
||||
"Ss_PriceMouPxM_MouID" => $r["Ss_PriceMouM_MouID"],
|
||||
"Ss_PriceMouPxSs_PriceMouID" => $r["Ss_PriceMouID"],
|
||||
"Ss_PriceMouPxT_TestID" => $c["T_TestID"],
|
||||
"Ss_PriceMouPxT_TestName" => $c["T_TestName"],
|
||||
"Ss_PriceMouPxT_PriceIsCito" => $c["T_PriceIsCito"],
|
||||
"Ss_PriceMouPxT_PriceM_CompanyID" => $c["T_PriceM_CompanyID"],
|
||||
"Ss_PriceMouPxT_PricePriority" => $c["T_PricePriority"],
|
||||
"Ss_PriceMouPxT_PriceAmount" => $c["T_PriceAmount"],
|
||||
"Ss_PriceMouPxT_PriceDisc" => $c["T_PriceDisc"],
|
||||
"Ss_PriceMouPxT_PriceDiscRp" => $c["T_PriceDiscRp"],
|
||||
"Ss_PriceMouPxT_PriceSubTotal" => $c["T_PriceSubTotal"],
|
||||
"Ss_PriceMouPxT_PriceOther" => $c["T_PriceOther"],
|
||||
"Ss_PriceMouPxT_PriceTotal" => $c["T_PriceTotal"],
|
||||
"Ss_PriceMouPxT_TestForceSell" => $c["T_TestForSell"],
|
||||
"nat_test" => $c["nat_test"]
|
||||
);
|
||||
}
|
||||
}
|
||||
$qry = $this->db->insert_batch("ss_price_mou_px",$a_data);
|
||||
if ( ! $qry ) {
|
||||
return array(false, "Batch Ss Price Mou Px" . print_r($this->db->error(),true));
|
||||
}
|
||||
|
||||
return array(true, "");
|
||||
}
|
||||
}
|
||||
52
one-api/application/libraries/SsPriceMouPx.php
Normal file
52
one-api/application/libraries/SsPriceMouPx.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
class SsPriceMouPx {
|
||||
|
||||
public function create($mouID) {
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("regional",true);
|
||||
|
||||
$sql = "select * from ss_price_mou where Ss_PriceMouM_MouID = ? and px_type in ('PR','PXR')";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if ( ! $qry ) {
|
||||
return array(false, "Ss Price Mou " . print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$sql ="delete from ss_price_mou_px where Ss_PriceMouPxSs_PriceMouID in ( select Ss_PriceMouID from ss_price_mou
|
||||
where Ss_PriceMouM_MouID = ? )";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if ( ! $qry ) {
|
||||
return array(false, "Clear Ss Price Mou Px" . print_r($this->db->error(),true));
|
||||
}
|
||||
$a_data = array();
|
||||
foreach($rows as $r) {
|
||||
$j_ct = $r["child_test"];
|
||||
$ct = json_decode($j_ct,true);
|
||||
foreach($ct as $c) {
|
||||
$a_data[] = array(
|
||||
"Ss_PriceMouPxM_MouID" => $r["Ss_PriceMouM_MouID"],
|
||||
"Ss_PriceMouPxSs_PriceMouID" => $r["Ss_PriceMouID"],
|
||||
"Ss_PriceMouPxT_TestID" => $c["T_TestID"],
|
||||
"Ss_PriceMouPxT_TestName" => $c["T_TestName"],
|
||||
"Ss_PriceMouPxT_PriceIsCito" => $c["T_PriceIsCito"],
|
||||
"Ss_PriceMouPxT_PriceM_CompanyID" => $c["T_PriceM_CompanyID"],
|
||||
"Ss_PriceMouPxT_PricePriority" => $c["T_PricePriority"],
|
||||
"Ss_PriceMouPxT_PriceAmount" => $c["T_PriceAmount"],
|
||||
"Ss_PriceMouPxT_PriceDisc" => $c["T_PriceDisc"],
|
||||
"Ss_PriceMouPxT_PriceDiscRp" => $c["T_PriceDiscRp"],
|
||||
"Ss_PriceMouPxT_PriceSubTotal" => $c["T_PriceSubTotal"],
|
||||
"Ss_PriceMouPxT_PriceOther" => $c["T_PriceOther"],
|
||||
"Ss_PriceMouPxT_PriceTotal" => $c["T_PriceTotal"],
|
||||
"Ss_PriceMouPxT_TestForceSell" => $c["T_TestForSell"],
|
||||
"nat_test" => $c["nat_test"]
|
||||
);
|
||||
}
|
||||
}
|
||||
$qry = $this->db->insert_batch("ss_price_mou_px",$a_data);
|
||||
if ( ! $qry ) {
|
||||
return array(false, "Batch Ss Price Mou Px" . print_r($this->db->error(),true));
|
||||
}
|
||||
|
||||
return array(true, "");
|
||||
}
|
||||
}
|
||||
573
one-api/application/libraries/SsPriceMou_v2.php
Normal file
573
one-api/application/libraries/SsPriceMou_v2.php
Normal file
@@ -0,0 +1,573 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
class SsPriceMou_v2{
|
||||
|
||||
// retrun array status, message
|
||||
public function create($mouID) {
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("regional",true);
|
||||
|
||||
$sql = "select * from m_mou where M_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "MOU ID : $mouID not found");
|
||||
}
|
||||
$companyID = $rows[0]["M_MouM_CompanyID"];
|
||||
$sql = "select distinct T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y'
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID <> 5
|
||||
where T_PriceM_MouID = ?
|
||||
and length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional select t_price " . print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$flag_error = false;
|
||||
foreach($rows as $idx => $r) {
|
||||
$nat_testType = $r["Nat_TestNat_TestTypeID"];
|
||||
switch($nat_testType) {
|
||||
case 1: //Single
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
case 3: //Multi
|
||||
case 4: //Panel
|
||||
$sasCode = $r["T_TestSasCode"] . '%';
|
||||
$sql = "select T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestIsResult = 'Y'
|
||||
and T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array($r["Nat_TestID"]);
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = $nr["T_TestNat_TestID"];
|
||||
}
|
||||
$rows[$idx]['nat_test'] = "[" . join(",",$t_rows) . "]";
|
||||
break;
|
||||
default :
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
}
|
||||
unset($rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
//Test Profile
|
||||
// wip profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, 0 T_PriceAmount, 0 T_PriceDisc, 0 T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, 0 T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PXR' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_test
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID = 5
|
||||
where length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional Profile " . print_r($this->db->error(),true));
|
||||
}
|
||||
$p_rows = $qry->result_array();
|
||||
|
||||
$sql = "select distinct substr(T_TestSasCode,1,8) parentCode, T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode,T_TestIsResult, T_TestCode
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y'
|
||||
and T_PriceIsCito = 'N'
|
||||
and length(T_TestSasCode) = 10
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
where T_PriceM_MouID = ? ";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional child test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_child = array();
|
||||
$p_codes = "'0'";
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
if ( ! isset($arr_child[$pCode])) {
|
||||
$arr_child[$pCode] = array();
|
||||
}
|
||||
$cCode = $r["T_TestSasCode"];
|
||||
$p_codes .= ", '$cCode'";
|
||||
unset($r["parentCode"]);
|
||||
$arr_child[$pCode][] = $r;
|
||||
}
|
||||
$sql = "select substr(T_TestSasCode,1,8) parentCode,
|
||||
group_concat(distinct T_TestNat_TestID) nat
|
||||
from t_test
|
||||
where ( T_TestIsResult = 'Y' or T_TestIsPrice = 'Y' )
|
||||
and T_TestSasCode in ( $p_codes )
|
||||
and T_TestIsActive = 'Y'
|
||||
group by parentCode";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_nat = array();
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
//if ( ! isset($arr_nat[$pCode])) {
|
||||
// $arr_nat[$pCode] = array();
|
||||
//}
|
||||
$arr_nat[$pCode] = $r["nat"];
|
||||
}
|
||||
|
||||
|
||||
|
||||
$flag_error = false;
|
||||
foreach($p_rows as $idx => $r) {
|
||||
$T_TestName= $r["T_TestName"] ;
|
||||
$sasCode = $r["T_TestSasCode"];
|
||||
if ( isset($arr_child[$sasCode]) ) {
|
||||
$the_childs = $arr_child[$sasCode];
|
||||
$p_rows[$idx]['child_test'] = json_encode($the_childs,true);
|
||||
if ( isset($arr_nat[$sasCode] )) {
|
||||
$p_rows[$idx]['nat_test'] = "[" . $arr_nat[$sasCode] . "]";
|
||||
}
|
||||
unset($p_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($p_rows[$idx]["T_TestSasCode"]);
|
||||
} else {
|
||||
unset($p_rows[$idx]);
|
||||
}
|
||||
}
|
||||
|
||||
//Paket Panel / Profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_PacketID T_TestID, T_PacketName T_TestName, 'N' IsFromPanel, 0 Nat_TestID,
|
||||
T_PacketID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, T_PacketOriginalBruto T_PriceAmount, 0 T_PriceDisc,
|
||||
(T_PacketOriginalBruto - T_PacketPrice) T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketPrice T_PriceTotal, 'Y' T_TestForceSell, 'Y' is_packet, T_PacketID packet_id,
|
||||
T_PacketType px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
$mouID Ss_PriceMouM_MouID
|
||||
from
|
||||
t_packet
|
||||
where
|
||||
T_PacketIsActive = 'Y'
|
||||
and T_PacketM_MouID = ?";
|
||||
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$pn_rows = $qry->result_array();
|
||||
foreach($pn_rows as $idx => $pnr) {
|
||||
$packetID = $pnr["packet_id"];
|
||||
//child test
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID,
|
||||
$mouID T_PriceM_MouID, 0 T_PricePriority, T_PacketDetailPriceAmount T_PriceAmount,
|
||||
T_PacketDetailPriceDisc T_PriceDisc, T_PacketDetailPriceDiscRp T_PriceDiscRp, T_PacketDetailPriceSubTotal T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketDetailPrice T_PriceTotal,
|
||||
'Y' T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite, T_TestSasCode
|
||||
from t_packetdetail
|
||||
join t_test on T_PacketDetailT_TestID = T_TestID
|
||||
and T_PacketDetailIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_PacketDetailT_PacketID = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($packetID));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$ct_rows = $qry->result_array();
|
||||
$p_nat_test = array();
|
||||
foreach($ct_rows as $ct_idx => $cr) {
|
||||
$sasCode = $cr["T_TestSasCode"] . '%';
|
||||
$sql = "select distinct T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array();
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = intval( $nr["T_TestNat_TestID"]);
|
||||
$p_nat_test[]= intval( $nr["T_TestNat_TestID"]);
|
||||
}
|
||||
$ct_rows[$ct_idx]['nat_test'] = json_encode($t_rows,JSON_NUMERIC_CHECK);
|
||||
}
|
||||
if (count($ct_rows) > 0 ) {
|
||||
$x_arr = array();
|
||||
foreach($ct_rows as $x_cr) {
|
||||
$x_arr[] = $x_cr;
|
||||
}
|
||||
$pn_rows[$idx]['child_test'] = json_encode($x_arr,true);
|
||||
$pn_rows[$idx]['nat_test'] = json_encode($p_nat_test,true);
|
||||
}
|
||||
unset($pn_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($pn_rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
|
||||
$rows = array_merge($rows,$p_rows, $pn_rows);
|
||||
if ( count($rows) == 0 ) {
|
||||
return array(false,"Empty Data");
|
||||
}
|
||||
if ( ! $qry ) {
|
||||
return array(false, "Regional Delete : " . print_r($this->db->error(),true));
|
||||
}
|
||||
foreach($rows as $r) {
|
||||
$sql = "delete from ss_price_mou where T_PriceM_MouID = ? and T_TestID = ? and T_PriceIsCito=? and px_type=?";
|
||||
$this->db->query($sql, array($mouID,$r["T_TestID"], $r["T_PriceIsCito"], $r["px_type"]));
|
||||
unset($r["Nat_TestNat_TestTypeID"]);
|
||||
unset($r["T_TestSasCode"]);
|
||||
$qry = $this->db->insert("ss_price_mou", $r);
|
||||
if ( ! $qry ) {
|
||||
return array(false, "Regional Insert : " . print_r($this->db->error(),true));
|
||||
}
|
||||
}
|
||||
return array(true, "OK");
|
||||
}
|
||||
public function edit($mouID,$testID,$cito) {
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("regional",true);
|
||||
|
||||
$sql = "select * from t_test where T_TestID = ? ";
|
||||
$qry = $this->db->query($sql, array($testID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "No Test $testID found");
|
||||
}
|
||||
$sasCode = $rows[0]["T_TestSasCode"];
|
||||
if ( strlen($sasCode) == 8 ) {
|
||||
$flagProfile = false;
|
||||
} else {
|
||||
$flagProfile = true;
|
||||
}
|
||||
|
||||
$sql = "select * from m_mou where M_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "No MOU $mouID found");
|
||||
}
|
||||
$mouName = $rows[0]["M_MouName"];
|
||||
$companyID = $rows[0]["M_MouM_CompanyID"];
|
||||
|
||||
$sql = "select distinct T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID and T_TestID = ?
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y' and T_PriceIsCito = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID <> 5
|
||||
where T_PriceM_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($testID, $cito, $mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
foreach($rows as $idx => $r) {
|
||||
$nat_testType = $r["Nat_TestNat_TestTypeID"];
|
||||
switch($nat_testType) {
|
||||
case 1: //Single
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
case 3: //Multi
|
||||
case 4: //Panel
|
||||
$sasCode = $r["T_TestSasCode"] . '%';
|
||||
$sql = "select T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestIsResult = 'Y'
|
||||
and T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array($r["Nat_TestID"]);
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = $nr["T_TestNat_TestID"];
|
||||
}
|
||||
$rows[$idx]['nat_test'] = "[" . join(",",$t_rows) . "]";
|
||||
break;
|
||||
default :
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
}
|
||||
unset($rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
}
|
||||
if ( count($rows) > 0 ) {
|
||||
// echo $r["T_TestID"];
|
||||
$r = $rows[0];
|
||||
unset($r["T_TestSasCode"]);
|
||||
/*
|
||||
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
||||
$this->db->where("T_TestID", $r["T_TestID"]);
|
||||
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
||||
$qry = $this->db->update("ss_price_mou",$r);
|
||||
*/
|
||||
$sql = "delete from ss_price_mou where T_PriceM_MouID = ? and T_TestID = ? and T_PriceIsCito=? and px_type=?";
|
||||
$this->db->query($sql, array($r["T_PriceM_MouID"],$r["T_TestID"], $r["T_PriceIsCito"],$r["px_type"]));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
//if ($this->db->affected_rows() == 0 ) {
|
||||
$this->db->insert("ss_price_mou", $r);
|
||||
//}
|
||||
}
|
||||
$sasCode = substr($sasCode,0,8);
|
||||
foreach($rows as $idx => $r ) {
|
||||
if ( strlen($r["T_TestSasCode"]) > 8 ) {
|
||||
unset($rows[$idx]);
|
||||
} else {
|
||||
unset($rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
}
|
||||
if ($cito == 'Y' ) {
|
||||
return array(true,"OK",$rows);
|
||||
}
|
||||
// for non cito
|
||||
if($flagProfile ) {
|
||||
//wip profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, 0 T_PriceAmount, 0 T_PriceDisc, 0 T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, 0 T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PXR' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_test
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID and T_TestSasCode = ?
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID = 5
|
||||
where length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($sasCode));
|
||||
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$p_rows = $qry->result_array();
|
||||
|
||||
$sasCodeLike = $sasCode . "%";
|
||||
$sql = "select distinct substr(T_TestSasCode,1,8) parentCode, T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode,T_TestIsResult, T_TestCode
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y' and T_PriceIsCito = 'N'
|
||||
and T_TestSasCode like ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
where T_PriceM_MouID = ? ";
|
||||
$qry = $this->db->query($sql,array($sasCodeLike,$mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional child_test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_child = array();
|
||||
$p_codes = "'0'";
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
if ( ! isset($arr_child[$pCode])) {
|
||||
$arr_child[$pCode] = array();
|
||||
}
|
||||
$cCode = $r["T_TestSasCode"];
|
||||
$p_codes .= ", '$cCode'";
|
||||
unset($r["parentCode"]);
|
||||
$arr_child[$pCode][] = $r;
|
||||
}
|
||||
|
||||
$sql = "select substr(T_TestSasCode,1,8) parentCode,
|
||||
group_concat(distinct T_TestNat_TestID) nat
|
||||
from t_test
|
||||
where ( T_TestIsResult = 'Y' or T_TestIsPrice = 'Y' )
|
||||
and T_TestSasCode in ( $p_codes )
|
||||
and T_TestIsActive = 'Y'
|
||||
group by parentCode";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional nat_test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_nat = array();
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
//if ( ! isset($arr_nat[$pCode])) {
|
||||
// $arr_nat[$pCode] = array();
|
||||
//}
|
||||
$arr_nat[$pCode] = $r["nat"];
|
||||
}
|
||||
|
||||
$flag_error = false;
|
||||
foreach($p_rows as $idx => $r) {
|
||||
$T_TestName= $r["T_TestName"] ;
|
||||
$sasCode = $r["T_TestSasCode"];
|
||||
if ( isset($arr_child[$sasCode]) ) {
|
||||
$the_childs = $arr_child[$sasCode];
|
||||
$p_rows[$idx]['child_test'] = json_encode($the_childs,true);
|
||||
if ( isset($arr_nat[$sasCode] )) {
|
||||
$p_rows[$idx]['nat_test'] = "[" . $arr_nat[$sasCode] . "]";
|
||||
}
|
||||
unset($p_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($p_rows[$idx]["T_TestSasCode"]);
|
||||
} else {
|
||||
unset($p_rows[$idx]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach($p_rows as $r) {
|
||||
/*
|
||||
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
||||
$this->db->where("T_TestID", $r["T_TestID"]);
|
||||
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
||||
$qry = $this->db->update("ss_price_mou",$r);
|
||||
*/
|
||||
$sql = "delete from ss_price_mou where T_PriceM_MouID = ? and T_TestID = ? and T_PriceIsCito=? and px_type=?";
|
||||
$this->db->query($sql, array($r["T_PriceM_MouID"],$r["T_TestID"], $r["T_PriceIsCito"], $r["px_type"]));
|
||||
if (! $qry ) {
|
||||
return array(false, "Err Update Ss_priceMou " . print_r($this->db->error(),true));
|
||||
}
|
||||
//if ($this->db->affected_rows() == 0 ) {
|
||||
$this->db->insert("ss_price_mou", $r);
|
||||
//}
|
||||
}
|
||||
$rows = array_merge($rows,$p_rows);
|
||||
}
|
||||
//Update Panel yang mengandung Test
|
||||
$sql = "select
|
||||
distinct T_PacketDetailT_PacketID
|
||||
from
|
||||
t_packetdetail
|
||||
where T_PacketDetailIsActive = 'Y'
|
||||
and T_PacketDetailT_TestID = ?";
|
||||
$qry = $this->db->query($sql, array($testID));
|
||||
if (!$qry) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$packet_ids = "0";
|
||||
foreach($xrows as $r ) {
|
||||
$packet_ids .= "," . $r["T_PacketDetailT_PacketID"];
|
||||
}
|
||||
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_PacketID T_TestID, T_PacketName T_TestName, 'N' IsFromPanel, 0 Nat_TestID,
|
||||
T_PacketID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, T_PacketOriginalBruto T_PriceAmount, 0 T_PriceDisc,
|
||||
(T_PacketOriginalBruto - T_PacketPrice) T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketPrice T_PriceTotal, 'Y' T_TestForceSell, 'Y' is_packet, T_PacketID packet_id,
|
||||
T_PacketType px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
$mouID Ss_PriceMouM_MouID
|
||||
from
|
||||
t_packet
|
||||
where
|
||||
T_PacketIsActive = 'Y' and T_PacketID in ( $packet_ids )
|
||||
and T_PacketM_MouID = ?";
|
||||
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$pn_rows = $qry->result_array();
|
||||
foreach($pn_rows as $idx => $pnr) {
|
||||
$packetID = $pnr["packet_id"];
|
||||
//child test
|
||||
$sql = "select $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID,
|
||||
$mouID T_PriceM_MouID, 0 T_PricePriority, T_PacketDetailPriceAmount T_PriceAmount,
|
||||
T_PacketDetailPriceDisc T_PriceDisc, T_PacketDetailPriceDiscRp T_PriceDiscRp, T_PacketDetailPriceSubTotal T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketDetailPrice T_PriceTotal,
|
||||
'Y' T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite, T_TestSasCode
|
||||
from t_packetdetail
|
||||
join t_test on T_PacketDetailT_TestID = T_TestID
|
||||
and T_PacketDetailIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_PacketDetailT_PacketID = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
";
|
||||
$qry = $this->db->query($sql,array($packetID));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$ct_rows = $qry->result_array();
|
||||
$p_nat_test = array();
|
||||
foreach($ct_rows as $ct_idx => $cr) {
|
||||
$sasCode = $cr["T_TestSasCode"] . '%';
|
||||
$sql = "select distinct T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array();
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = intval( $nr["T_TestNat_TestID"]);
|
||||
$p_nat_test[]= intval( $nr["T_TestNat_TestID"]);
|
||||
}
|
||||
$ct_rows[$ct_idx]['nat_test'] = json_encode($t_rows,JSON_NUMERIC_CHECK);
|
||||
}
|
||||
if (count($ct_rows) > 0 ) {
|
||||
$x_arr = array();
|
||||
foreach($ct_rows as $x_cr) {
|
||||
$x_arr[] = $x_cr;
|
||||
}
|
||||
$pn_rows[$idx]['child_test'] = json_encode($x_arr,true);
|
||||
$pn_rows[$idx]['nat_test'] = json_encode($p_nat_test,true);
|
||||
}
|
||||
unset($pn_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($pn_rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
foreach($pn_rows as $r ) {
|
||||
$sql = "delete from ss_price_mou where T_PriceM_MouID = ? and T_TestID = ? and T_PriceIsCito=? and px_type=?";
|
||||
$this->db->query($sql, array($r["T_PriceM_MouID"],$r["T_TestID"], $r["T_PriceIsCito"],$r["px_type"]));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
//if ($this->db->affected_rows() == 0 ) {
|
||||
$this->db->insert("ss_price_mou", $r);
|
||||
//}
|
||||
}
|
||||
$rows = array_merge($rows,$pn_rows);
|
||||
return array(true,"OK",$rows);
|
||||
}
|
||||
}
|
||||
575
one-api/application/libraries/SsPriceMou_v4.php
Normal file
575
one-api/application/libraries/SsPriceMou_v4.php
Normal file
@@ -0,0 +1,575 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
class SsPriceMou_v4{
|
||||
|
||||
// retrun array status, message
|
||||
public function create($mouID) {
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("regional",true);
|
||||
|
||||
$sql = "select * from m_mou where M_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "MOU ID : $mouID not found");
|
||||
}
|
||||
$companyID = $rows[0]["M_MouM_CompanyID"];
|
||||
$sql = "select distinct T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y'
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID <> 5
|
||||
where T_PriceM_MouID = ?
|
||||
and length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional select t_price " . print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$flag_error = false;
|
||||
foreach($rows as $idx => $r) {
|
||||
$nat_testType = $r["Nat_TestNat_TestTypeID"];
|
||||
switch($nat_testType) {
|
||||
case 1: //Single
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
case 3: //Multi
|
||||
case 4: //Panel
|
||||
$sasCode = $r["T_TestSasCode"] . '%';
|
||||
$sql = "select T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestIsResult = 'Y'
|
||||
and T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array($r["Nat_TestID"]);
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = $nr["T_TestNat_TestID"];
|
||||
}
|
||||
$rows[$idx]['nat_test'] = "[" . join(",",$t_rows) . "]";
|
||||
break;
|
||||
default :
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
}
|
||||
unset($rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
//Test Profile
|
||||
// wip profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, 0 T_PriceAmount, 0 T_PriceDisc, 0 T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, 0 T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PXR' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_test
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID = 5
|
||||
where length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional Profile " . print_r($this->db->error(),true));
|
||||
}
|
||||
$p_rows = $qry->result_array();
|
||||
|
||||
$sql = "select distinct substr(T_TestSasCode,1,8) parentCode, T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode,T_TestIsResult, T_TestCode
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y'
|
||||
and T_PriceIsCito = 'N'
|
||||
and length(T_TestSasCode) = 10
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
where T_PriceM_MouID = ? ";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional child test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_child = array();
|
||||
$p_codes = "'0'";
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
if ( ! isset($arr_child[$pCode])) {
|
||||
$arr_child[$pCode] = array();
|
||||
}
|
||||
$cCode = $r["T_TestSasCode"];
|
||||
$p_codes .= ", '$cCode'";
|
||||
unset($r["parentCode"]);
|
||||
$arr_child[$pCode][] = $r;
|
||||
}
|
||||
$sql = "select substr(T_TestSasCode,1,8) parentCode,
|
||||
group_concat(distinct T_TestNat_TestID) nat
|
||||
from t_test
|
||||
where ( T_TestIsResult = 'Y' or T_TestIsPrice = 'Y' )
|
||||
and T_TestSasCode in ( $p_codes )
|
||||
and T_TestIsActive = 'Y'
|
||||
group by parentCode";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_nat = array();
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
//if ( ! isset($arr_nat[$pCode])) {
|
||||
// $arr_nat[$pCode] = array();
|
||||
//}
|
||||
$arr_nat[$pCode] = $r["nat"];
|
||||
}
|
||||
|
||||
|
||||
|
||||
$flag_error = false;
|
||||
foreach($p_rows as $idx => $r) {
|
||||
$T_TestName= $r["T_TestName"] ;
|
||||
$sasCode = $r["T_TestSasCode"];
|
||||
if ( isset($arr_child[$sasCode]) ) {
|
||||
$the_childs = $arr_child[$sasCode];
|
||||
$p_rows[$idx]['child_test'] = json_encode($the_childs,true);
|
||||
if ( isset($arr_nat[$sasCode] )) {
|
||||
$p_rows[$idx]['nat_test'] = "[" . $arr_nat[$sasCode] . "]";
|
||||
}
|
||||
unset($p_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($p_rows[$idx]["T_TestSasCode"]);
|
||||
} else {
|
||||
unset($p_rows[$idx]);
|
||||
}
|
||||
}
|
||||
|
||||
//Paket Panel / Profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_PacketID T_TestID, T_PacketName T_TestName, 'N' IsFromPanel, 0 Nat_TestID,
|
||||
T_PacketID T_PriceT_TestID, T_PacketIsCito T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, T_PacketOriginalBruto T_PriceAmount, 0 T_PriceDisc,
|
||||
(T_PacketOriginalBruto - T_PacketPrice) T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketPrice T_PriceTotal, 'Y' T_TestForceSell, 'Y' is_packet, T_PacketID packet_id,
|
||||
T_PacketType px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
$mouID Ss_PriceMouM_MouID
|
||||
from
|
||||
t_packet
|
||||
where
|
||||
T_PacketIsActive = 'Y'
|
||||
and T_PacketM_MouID = ?";
|
||||
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$pn_rows = $qry->result_array();
|
||||
foreach($pn_rows as $idx => $pnr) {
|
||||
$packetID = $pnr["packet_id"];
|
||||
//child test
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, T_PacketIsCito T_PriceIsCito, $companyID T_PriceM_CompanyID,
|
||||
$mouID T_PriceM_MouID, 0 T_PricePriority, T_PacketDetailPriceAmount T_PriceAmount,
|
||||
T_PacketDetailPriceDisc T_PriceDisc, T_PacketDetailPriceDiscRp T_PriceDiscRp, T_PacketDetailPriceSubTotal T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketDetailPrice T_PriceTotal,
|
||||
'Y' T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite, T_TestSasCode
|
||||
from t_packetdetail
|
||||
join t_packet on T_PacketID = T_PacketDetailT_PacketID
|
||||
join t_test on T_PacketDetailT_TestID = T_TestID
|
||||
and T_PacketDetailIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_PacketDetailT_PacketID = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($packetID));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$ct_rows = $qry->result_array();
|
||||
$p_nat_test = array();
|
||||
foreach($ct_rows as $ct_idx => $cr) {
|
||||
$sasCode = $cr["T_TestSasCode"] . '%';
|
||||
$sql = "select distinct T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array();
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = intval( $nr["T_TestNat_TestID"]);
|
||||
$p_nat_test[]= intval( $nr["T_TestNat_TestID"]);
|
||||
}
|
||||
$ct_rows[$ct_idx]['nat_test'] = json_encode($t_rows,JSON_NUMERIC_CHECK);
|
||||
}
|
||||
if (count($ct_rows) > 0 ) {
|
||||
$x_arr = array();
|
||||
foreach($ct_rows as $x_cr) {
|
||||
$x_arr[] = $x_cr;
|
||||
}
|
||||
$pn_rows[$idx]['child_test'] = json_encode($x_arr,true);
|
||||
$pn_rows[$idx]['nat_test'] = json_encode($p_nat_test,true);
|
||||
}
|
||||
unset($pn_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($pn_rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
|
||||
$rows = array_merge($rows,$p_rows, $pn_rows);
|
||||
if ( count($rows) == 0 ) {
|
||||
return array(false,"Empty Data");
|
||||
}
|
||||
if ( ! $qry ) {
|
||||
return array(false, "Regional Delete : " . print_r($this->db->error(),true));
|
||||
}
|
||||
foreach($rows as $r) {
|
||||
$sql = "delete from ss_price_mou where T_PriceM_MouID = ? and T_TestID = ? and T_PriceIsCito=? and px_type=?";
|
||||
$this->db->query($sql, array($mouID,$r["T_TestID"], $r["T_PriceIsCito"], $r["px_type"]));
|
||||
unset($r["Nat_TestNat_TestTypeID"]);
|
||||
unset($r["T_TestSasCode"]);
|
||||
$qry = $this->db->insert("ss_price_mou", $r);
|
||||
if ( ! $qry ) {
|
||||
return array(false, "Regional Insert : " . print_r($this->db->error(),true));
|
||||
}
|
||||
}
|
||||
return array(true, "OK");
|
||||
}
|
||||
public function edit($mouID,$testID,$cito) {
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("regional",true);
|
||||
|
||||
$sql = "select * from t_test where T_TestID = ? ";
|
||||
$qry = $this->db->query($sql, array($testID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "No Test $testID found");
|
||||
}
|
||||
$sasCode = $rows[0]["T_TestSasCode"];
|
||||
if ( strlen($sasCode) == 8 ) {
|
||||
$flagProfile = false;
|
||||
} else {
|
||||
$flagProfile = true;
|
||||
}
|
||||
|
||||
$sql = "select * from m_mou where M_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "No MOU $mouID found");
|
||||
}
|
||||
$mouName = $rows[0]["M_MouName"];
|
||||
$companyID = $rows[0]["M_MouM_CompanyID"];
|
||||
|
||||
$sql = "select distinct T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID and T_TestID = ?
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y' and T_PriceIsCito = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID <> 5
|
||||
where T_PriceM_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($testID, $cito, $mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
|
||||
foreach($rows as $idx => $r) {
|
||||
$nat_testType = $r["Nat_TestNat_TestTypeID"];
|
||||
switch($nat_testType) {
|
||||
case 1: //Single
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
case 3: //Multi
|
||||
case 4: //Panel
|
||||
$sasCode = $r["T_TestSasCode"] . '%';
|
||||
$sql = "select T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestIsResult = 'Y'
|
||||
and T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array($r["Nat_TestID"]);
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = $nr["T_TestNat_TestID"];
|
||||
}
|
||||
$rows[$idx]['nat_test'] = "[" . join(",",$t_rows) . "]";
|
||||
break;
|
||||
default :
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
}
|
||||
unset($rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
}
|
||||
if ( count($rows) > 0 ) {
|
||||
$r = $rows[0];
|
||||
unset($r["T_TestSasCode"]);
|
||||
/*
|
||||
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
||||
$this->db->where("T_TestID", $r["T_TestID"]);
|
||||
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
||||
$qry = $this->db->update("ss_price_mou",$r);
|
||||
*/
|
||||
$sql = "delete from ss_price_mou where T_PriceM_MouID = ? and T_TestID = ? and T_PriceIsCito=? and px_type=?";
|
||||
$this->db->query($sql, array($r["T_PriceM_MouID"],$r["T_TestID"], $r["T_PriceIsCito"],$r["px_type"]));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
//if ($this->db->affected_rows() == 0 ) {
|
||||
$this->db->insert("ss_price_mou", $r);
|
||||
//}
|
||||
}
|
||||
$sasCode = substr($sasCode,0,8);
|
||||
foreach($rows as $idx => $r ) {
|
||||
if ( strlen($r["T_TestSasCode"]) > 8 ) {
|
||||
unset($rows[$idx]);
|
||||
} else {
|
||||
unset($rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
}
|
||||
if ($cito == 'Y' ) {
|
||||
return array(true,"OK",$rows);
|
||||
}
|
||||
// for non cito
|
||||
if($flagProfile ) {
|
||||
//wip profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, 0 T_PriceAmount, 0 T_PriceDisc, 0 T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, 0 T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PXR' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_test
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID and T_TestSasCode = ?
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID = 5
|
||||
where length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($sasCode));
|
||||
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$p_rows = $qry->result_array();
|
||||
|
||||
$sasCodeLike = $sasCode . "%";
|
||||
$sql = "select distinct substr(T_TestSasCode,1,8) parentCode, T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode,T_TestIsResult, T_TestCode
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y' and T_PriceIsCito = 'N'
|
||||
and T_TestSasCode like ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
where T_PriceM_MouID = ? ";
|
||||
$qry = $this->db->query($sql,array($sasCodeLike,$mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional child_test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_child = array();
|
||||
$p_codes = "'0'";
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
if ( ! isset($arr_child[$pCode])) {
|
||||
$arr_child[$pCode] = array();
|
||||
}
|
||||
$cCode = $r["T_TestSasCode"];
|
||||
$p_codes .= ", '$cCode'";
|
||||
unset($r["parentCode"]);
|
||||
$arr_child[$pCode][] = $r;
|
||||
}
|
||||
|
||||
$sql = "select substr(T_TestSasCode,1,8) parentCode,
|
||||
group_concat(distinct T_TestNat_TestID) nat
|
||||
from t_test
|
||||
where ( T_TestIsResult = 'Y' or T_TestIsPrice = 'Y' )
|
||||
and T_TestSasCode in ( $p_codes )
|
||||
and T_TestIsActive = 'Y'
|
||||
group by parentCode";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional nat_test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_nat = array();
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
//if ( ! isset($arr_nat[$pCode])) {
|
||||
// $arr_nat[$pCode] = array();
|
||||
//}
|
||||
$arr_nat[$pCode] = $r["nat"];
|
||||
}
|
||||
|
||||
$flag_error = false;
|
||||
foreach($p_rows as $idx => $r) {
|
||||
$T_TestName= $r["T_TestName"] ;
|
||||
$sasCode = $r["T_TestSasCode"];
|
||||
if ( isset($arr_child[$sasCode]) ) {
|
||||
$the_childs = $arr_child[$sasCode];
|
||||
$p_rows[$idx]['child_test'] = json_encode($the_childs,true);
|
||||
if ( isset($arr_nat[$sasCode] )) {
|
||||
$p_rows[$idx]['nat_test'] = "[" . $arr_nat[$sasCode] . "]";
|
||||
}
|
||||
unset($p_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($p_rows[$idx]["T_TestSasCode"]);
|
||||
} else {
|
||||
unset($p_rows[$idx]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach($p_rows as $r) {
|
||||
/*
|
||||
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
||||
$this->db->where("T_TestID", $r["T_TestID"]);
|
||||
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
||||
$qry = $this->db->update("ss_price_mou",$r);
|
||||
*/
|
||||
$sql = "delete from ss_price_mou where T_PriceM_MouID = ? and T_TestID = ? and T_PriceIsCito=? and px_type=?";
|
||||
$this->db->query($sql, array($r["T_PriceM_MouID"],$r["T_TestID"], $r["T_PriceIsCito"],$r["px_type"]));
|
||||
if (! $qry ) {
|
||||
return array(false, "Err Update Ss_priceMou " . print_r($this->db->error(),true));
|
||||
}
|
||||
//if ($this->db->affected_rows() == 0 ) {
|
||||
$this->db->insert("ss_price_mou", $r);
|
||||
//}
|
||||
}
|
||||
$rows = array_merge($rows,$p_rows);
|
||||
}
|
||||
//Update Panel yang mengandung Test
|
||||
$sql = "select
|
||||
distinct T_PacketDetailT_PacketID
|
||||
from
|
||||
t_packetdetail
|
||||
where T_PacketDetailIsActive = 'Y'
|
||||
and T_PacketDetailT_TestID = ?";
|
||||
$qry = $this->db->query($sql, array($testID));
|
||||
if (!$qry) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$packet_ids = "0";
|
||||
foreach($xrows as $r ) {
|
||||
$packet_ids .= "," . $r["T_PacketDetailT_PacketID"];
|
||||
}
|
||||
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_PacketID T_TestID, T_PacketName T_TestName, 'N' IsFromPanel, 0 Nat_TestID,
|
||||
T_PacketID T_PriceT_TestID, T_PacketIsCito T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, T_PacketOriginalBruto T_PriceAmount, 0 T_PriceDisc,
|
||||
(T_PacketOriginalBruto - T_PacketPrice) T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketPrice T_PriceTotal, 'Y' T_TestForceSell, 'Y' is_packet, T_PacketID packet_id,
|
||||
T_PacketType px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
$mouID Ss_PriceMouM_MouID
|
||||
from
|
||||
t_packet
|
||||
where
|
||||
T_PacketIsActive = 'Y' and T_PacketID in ( $packet_ids )
|
||||
and T_PacketM_MouID = ?";
|
||||
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$pn_rows = $qry->result_array();
|
||||
foreach($pn_rows as $idx => $pnr) {
|
||||
$packetID = $pnr["packet_id"];
|
||||
//child test
|
||||
$sql = "select $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, T_PacketIsCito T_PriceIsCito, $companyID T_PriceM_CompanyID,
|
||||
$mouID T_PriceM_MouID, 0 T_PricePriority, T_PacketDetailPriceAmount T_PriceAmount,
|
||||
T_PacketDetailPriceDisc T_PriceDisc, T_PacketDetailPriceDiscRp T_PriceDiscRp, T_PacketDetailPriceSubTotal T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketDetailPrice T_PriceTotal,
|
||||
'Y' T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite, T_TestSasCode
|
||||
from t_packetdetail
|
||||
join t_packet on T_PacketID = T_PacketDetailT_PacketID
|
||||
join t_test on T_PacketDetailT_TestID = T_TestID
|
||||
and T_PacketDetailIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_PacketDetailT_PacketID = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
";
|
||||
$qry = $this->db->query($sql,array($packetID));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$ct_rows = $qry->result_array();
|
||||
$p_nat_test = array();
|
||||
foreach($ct_rows as $ct_idx => $cr) {
|
||||
$sasCode = $cr["T_TestSasCode"] . '%';
|
||||
$sql = "select distinct T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array();
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = intval( $nr["T_TestNat_TestID"]);
|
||||
$p_nat_test[]= intval( $nr["T_TestNat_TestID"]);
|
||||
}
|
||||
$ct_rows[$ct_idx]['nat_test'] = json_encode($t_rows,JSON_NUMERIC_CHECK);
|
||||
}
|
||||
if (count($ct_rows) > 0 ) {
|
||||
$x_arr = array();
|
||||
foreach($ct_rows as $x_cr) {
|
||||
$x_arr[] = $x_cr;
|
||||
}
|
||||
$pn_rows[$idx]['child_test'] = json_encode($x_arr,true);
|
||||
$pn_rows[$idx]['nat_test'] = json_encode($p_nat_test,true);
|
||||
}
|
||||
unset($pn_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($pn_rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
foreach($pn_rows as $r ) {
|
||||
$sql = "delete from ss_price_mou where T_PriceM_MouID = ? and T_TestID = ? and T_PriceIsCito=? and px_type=?";
|
||||
$this->db->query($sql, array($r["T_PriceM_MouID"],$r["T_TestID"], $r["T_PriceIsCito"],$r["px_type"]));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
//if ($this->db->affected_rows() == 0 ) {
|
||||
$this->db->insert("ss_price_mou", $r);
|
||||
//}
|
||||
}
|
||||
$rows = array_merge($rows,$pn_rows);
|
||||
return array(true,"OK",$rows);
|
||||
}
|
||||
}
|
||||
547
one-api/application/libraries/SsPrieMou-dev.php
Normal file
547
one-api/application/libraries/SsPrieMou-dev.php
Normal file
@@ -0,0 +1,547 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
class SsPriceMou{
|
||||
|
||||
// retrun array status, message
|
||||
public function create($mouID) {
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("regional",true);
|
||||
|
||||
$sql = "select * from m_mou where M_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "MOU ID : $mouID not found");
|
||||
}
|
||||
$companyID = $rows[0]["M_MouM_CompanyID"];
|
||||
|
||||
$sql = "select distinct T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y'
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID <> 5
|
||||
where T_PriceM_MouID = ?
|
||||
and length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional select t_price " . print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$flag_error = false;
|
||||
foreach($rows as $idx => $r) {
|
||||
$nat_testType = $r["Nat_TestNat_TestTypeID"];
|
||||
switch($nat_testType) {
|
||||
case 1: //Single
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
case 3: //Multi
|
||||
case 4: //Panel
|
||||
$sasCode = $r["T_TestSasCode"] . '%';
|
||||
$sql = "select T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestIsResult = 'Y'
|
||||
and T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array($r["Nat_TestID"]);
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = $nr["T_TestNat_TestID"];
|
||||
}
|
||||
$rows[$idx]['nat_test'] = "[" . join(",",$t_rows) . "]";
|
||||
break;
|
||||
default :
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
}
|
||||
unset($rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
//Test Profile
|
||||
// wip profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, 0 T_PriceAmount, 0 T_PriceDisc, 0 T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, 0 T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PXR' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_test
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID = 5
|
||||
where length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$p_rows = $qry->result_array();
|
||||
|
||||
$sql = "select distinct substr(T_TestSasCode,1,8) parentCode, T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode,T_TestIsResult, T_TestCode
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y'
|
||||
and T_PriceIsCito = 'N'
|
||||
and length(T_TestSasCode) = 10
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
where T_PriceM_MouID = ? ";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional child test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_child = array();
|
||||
$p_codes = "'0'";
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
if ( ! isset($arr_child[$pCode])) {
|
||||
$arr_child[$pCode] = array();
|
||||
}
|
||||
$cCode = $r["T_TestSasCode"];
|
||||
$p_codes .= ", '$cCode'";
|
||||
unset($r["parentCode"]);
|
||||
$arr_child[$pCode][] = $r;
|
||||
}
|
||||
$sql = "select substr(T_TestSasCode,1,8) parentCode,
|
||||
group_concat(distinct T_TestNat_TestID) nat
|
||||
from t_test
|
||||
where ( T_TestIsResult = 'Y' or T_TestIsPrice = 'Y' )
|
||||
and T_TestSasCode in ( $p_codes )
|
||||
and T_TestIsActive = 'Y'
|
||||
group by parentCode";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_nat = array();
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
//if ( ! isset($arr_nat[$pCode])) {
|
||||
// $arr_nat[$pCode] = array();
|
||||
//}
|
||||
$arr_nat[$pCode] = $r["nat"];
|
||||
}
|
||||
$flag_error = false;
|
||||
foreach($p_rows as $idx => $r) {
|
||||
$T_TestName= $r["T_TestName"] ;
|
||||
$sasCode = $r["T_TestSasCode"];
|
||||
if ( isset($arr_child[$sasCode]) ) {
|
||||
$the_childs = $arr_child[$sasCode];
|
||||
$p_rows[$idx]['child_test'] = json_encode($the_childs,true);
|
||||
if ( isset($arr_nat[$sasCode] )) {
|
||||
$p_rows[$idx]['nat_test'] = "[" . $arr_nat[$sasCode] . "]";
|
||||
}
|
||||
unset($p_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($p_rows[$idx]["T_TestSasCode"]);
|
||||
} else {
|
||||
unset($p_rows[$idx]);
|
||||
}
|
||||
}
|
||||
//Paket Panel / Profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_PacketID T_TestID, T_PacketName T_TestName, 'N' IsFromPanel, 0 Nat_TestID,
|
||||
T_PacketID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, T_PacketOriginalBruto T_PriceAmount, 0 T_PriceDisc,
|
||||
(T_PacketOriginalBruto - T_PacketPrice) T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketPrice T_PriceTotal, 'Y' T_TestForceSell, 'Y' is_packet, T_PacketID packet_id,
|
||||
T_PacketType px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
$mouID Ss_PriceMouM_MouID
|
||||
from
|
||||
t_packet
|
||||
where
|
||||
T_PacketIsActive = 'Y'
|
||||
and T_PacketM_MouID = ?";
|
||||
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$pn_rows = $qry->result_array();
|
||||
foreach($pn_rows as $idx => $pnr) {
|
||||
$packetID = $pnr["packet_id"];
|
||||
//child test
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID,
|
||||
$mouID T_PriceM_MouID, 0 T_PricePriority, T_PacketDetailPriceAmount T_PriceAmount,
|
||||
T_PacketDetailPriceDisc T_PriceDisc, T_PacketDetailPriceDiscRp T_PriceDiscRp, T_PacketDetailPriceSubTotal T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketDetailPrice T_PriceTotal,
|
||||
'Y' T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite, T_TestSasCode
|
||||
from t_packetdetail
|
||||
join t_test on T_PacketDetailT_TestID = T_TestID
|
||||
and T_PacketDetailIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_PacketDetailT_PacketID = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($packetID));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$ct_rows = $qry->result_array();
|
||||
$p_nat_test = array();
|
||||
foreach($ct_rows as $ct_idx => $cr) {
|
||||
$sasCode = $cr["T_TestSasCode"] . '%';
|
||||
$sql = "select distinct T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array();
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = intval( $nr["T_TestNat_TestID"]);
|
||||
$p_nat_test[]= intval( $nr["T_TestNat_TestID"]);
|
||||
}
|
||||
$ct_rows[$ct_idx]['nat_test'] = json_encode($t_rows,JSON_NUMERIC_CHECK);
|
||||
}
|
||||
if (count($ct_rows) > 0 ) {
|
||||
$x_arr = array();
|
||||
foreach($ct_rows as $x_cr) {
|
||||
$x_arr[] = $x_cr;
|
||||
}
|
||||
$pn_rows[$idx]['child_test'] = json_encode($x_arr,true);
|
||||
$pn_rows[$idx]['nat_test'] = json_encode($p_nat_test,true);
|
||||
}
|
||||
unset($pn_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($pn_rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
|
||||
$rows = array_merge($rows,$p_rows, $pn_rows);
|
||||
$qry = $this->db->query("delete from ss_price_mou where Ss_PriceMouM_MouID=?", array($mouID));
|
||||
if ( ! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$qry = $this->db->insert_batch("ss_price_mou", $rows);
|
||||
if ( ! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
return array(true, "OK");
|
||||
}
|
||||
public function edit($mouID,$testID,$cito) {
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("regional",true);
|
||||
|
||||
$sql = "select * from t_test where T_TestID = ? ";
|
||||
$qry = $this->db->query($sql, array($testID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "No Test $testID found");
|
||||
}
|
||||
$sasCode = $rows[0]["T_TestSasCode"];
|
||||
if ( strlen($sasCode) == 8 ) {
|
||||
$flagProfile = false;
|
||||
} else {
|
||||
$flagProfile = true;
|
||||
}
|
||||
|
||||
$sql = "select * from m_mou where M_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "No MOU $mouID found");
|
||||
}
|
||||
$mouName = $rows[0]["M_MouName"];
|
||||
$companyID = $rows[0]["M_MouM_CompanyID"];
|
||||
|
||||
$sql = "select distinct T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID and T_TestID = ?
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y' and T_PriceIsCito = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID <> 5
|
||||
where T_PriceM_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($testID, $cito, $mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
|
||||
foreach($rows as $idx => $r) {
|
||||
$nat_testType = $r["Nat_TestNat_TestTypeID"];
|
||||
switch($nat_testType) {
|
||||
case 1: //Single
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
case 3: //Multi
|
||||
case 4: //Panel
|
||||
$sasCode = $r["T_TestSasCode"] . '%';
|
||||
$sql = "select T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestIsResult = 'Y'
|
||||
and T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array($r["Nat_TestID"]);
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = $nr["T_TestNat_TestID"];
|
||||
}
|
||||
$rows[$idx]['nat_test'] = "[" . join(",",$t_rows) . "]";
|
||||
break;
|
||||
default :
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
}
|
||||
unset($rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
}
|
||||
if ( count($rows) > 0 ) {
|
||||
$r = $rows[0];
|
||||
unset($r["T_TestSasCode"]);
|
||||
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
||||
$this->db->where("T_TestID", $r["T_TestID"]);
|
||||
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
||||
$qry = $this->db->update("ss_price_mou",$r);
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
}
|
||||
$sasCode = substr($sasCode,0,8);
|
||||
foreach($rows as $idx => $r ) {
|
||||
if ( strlen($r["T_TestSasCode"]) > 8 ) {
|
||||
unset($rows[$idx]);
|
||||
} else {
|
||||
unset($rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
}
|
||||
if ($cito == 'Y' ) {
|
||||
return array(true,"OK",$rows);
|
||||
}
|
||||
// for non cito
|
||||
if($flagProfile ) {
|
||||
//wip profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, 0 T_PriceAmount, 0 T_PriceDisc, 0 T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, 0 T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PXR' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_test
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID and T_TestSasCode = ?
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID = 5
|
||||
where length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($sasCode));
|
||||
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$p_rows = $qry->result_array();
|
||||
|
||||
$sasCodeLike = $sasCode . "%";
|
||||
$sql = "select distinct substr(T_TestSasCode,1,8) parentCode, T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode,T_TestIsResult, T_TestCode
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y' and T_PriceIsCito = 'N'
|
||||
and T_TestSasCode like ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
where T_PriceM_MouID = ? ";
|
||||
$qry = $this->db->query($sql,array($sasCodeLike,$mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional child_test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_child = array();
|
||||
$p_codes = "'0'";
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
if ( ! isset($arr_child[$pCode])) {
|
||||
$arr_child[$pCode] = array();
|
||||
}
|
||||
$cCode = $r["T_TestSasCode"];
|
||||
$p_codes .= ", '$cCode'";
|
||||
unset($r["parentCode"]);
|
||||
$arr_child[$pCode][] = $r;
|
||||
}
|
||||
|
||||
$sql = "select substr(T_TestSasCode,1,8) parentCode,
|
||||
group_concat(distinct T_TestNat_TestID) nat
|
||||
from t_test
|
||||
where ( T_TestIsResult = 'Y' or T_TestIsPrice = 'Y' )
|
||||
and T_TestSasCode in ( $p_codes )
|
||||
and T_TestIsActive = 'Y'
|
||||
group by parentCode";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional nat_test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_nat = array();
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
//if ( ! isset($arr_nat[$pCode])) {
|
||||
// $arr_nat[$pCode] = array();
|
||||
//}
|
||||
$arr_nat[$pCode] = $r["nat"];
|
||||
}
|
||||
|
||||
$flag_error = false;
|
||||
foreach($p_rows as $idx => $r) {
|
||||
$T_TestName= $r["T_TestName"] ;
|
||||
$sasCode = $r["T_TestSasCode"];
|
||||
if ( isset($arr_child[$sasCode]) ) {
|
||||
$the_childs = $arr_child[$sasCode];
|
||||
$p_rows[$idx]['child_test'] = json_encode($the_childs,true);
|
||||
if ( isset($arr_nat[$sasCode] )) {
|
||||
$p_rows[$idx]['nat_test'] = "[" . $arr_nat[$sasCode] . "]";
|
||||
}
|
||||
unset($p_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($p_rows[$idx]["T_TestSasCode"]);
|
||||
} else {
|
||||
unset($p_rows[$idx]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach($p_rows as $r) {
|
||||
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
||||
$this->db->where("T_TestID", $r["T_TestID"]);
|
||||
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
||||
$qry = $this->db->update("ss_price_mou",$r);
|
||||
if (! $qry ) {
|
||||
return array(false, "Err Update Ss_priceMou " . print_r($this->db->error(),true));
|
||||
}
|
||||
}
|
||||
$rows = array_merge($rows,$p_rows);
|
||||
}
|
||||
//Update Panel yang mengandung Test
|
||||
$sql = "select
|
||||
distinct T_PacketDetailT_PacketID
|
||||
from
|
||||
t_packetdetail
|
||||
where T_PacketDetailIsActive = 'Y'
|
||||
and T_PacketDetailT_TestID = ?";
|
||||
$qry = $this->db->query($sql, array($testID));
|
||||
if (!$qry) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$packet_ids = "0";
|
||||
foreach($xrows as $r ) {
|
||||
$packet_ids .= "," . $r["T_PacketDetailT_PacketID"];
|
||||
}
|
||||
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_PacketID T_TestID, T_PacketName T_TestName, 'N' IsFromPanel, 0 Nat_TestID,
|
||||
T_PacketID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, T_PacketOriginalBruto T_PriceAmount, 0 T_PriceDisc,
|
||||
(T_PacketOriginalBruto - T_PacketPrice) T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketPrice T_PriceTotal, 'Y' T_TestForceSell, 'Y' is_packet, T_PacketID packet_id,
|
||||
T_PacketType px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
$mouID Ss_PriceMouM_MouID
|
||||
from
|
||||
t_packet
|
||||
where
|
||||
T_PacketIsActive = 'Y' and T_PacketID in ( $packet_ids )
|
||||
and T_PacketM_MouID = ?";
|
||||
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$pn_rows = $qry->result_array();
|
||||
foreach($pn_rows as $idx => $pnr) {
|
||||
$packetID = $pnr["packet_id"];
|
||||
//child test
|
||||
$sql = "select $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID,
|
||||
$mouID T_PriceM_MouID, 0 T_PricePriority, T_PacketDetailPriceAmount T_PriceAmount,
|
||||
T_PacketDetailPriceDisc T_PriceDisc, T_PacketDetailPriceDiscRp T_PriceDiscRp, T_PacketDetailPriceSubTotal T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketDetailPrice T_PriceTotal,
|
||||
'Y' T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite, T_TestSasCode
|
||||
from t_packetdetail
|
||||
join t_test on T_PacketDetailT_TestID = T_TestID
|
||||
and T_PacketDetailIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_PacketDetailT_PacketID = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
";
|
||||
$qry = $this->db->query($sql,array($packetID));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$ct_rows = $qry->result_array();
|
||||
$p_nat_test = array();
|
||||
foreach($ct_rows as $ct_idx => $cr) {
|
||||
$sasCode = $cr["T_TestSasCode"] . '%';
|
||||
$sql = "select distinct T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array();
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = intval( $nr["T_TestNat_TestID"]);
|
||||
$p_nat_test[]= intval( $nr["T_TestNat_TestID"]);
|
||||
}
|
||||
$ct_rows[$ct_idx]['nat_test'] = json_encode($t_rows,JSON_NUMERIC_CHECK);
|
||||
}
|
||||
if (count($ct_rows) > 0 ) {
|
||||
$x_arr = array();
|
||||
foreach($ct_rows as $x_cr) {
|
||||
$x_arr[] = $x_cr;
|
||||
}
|
||||
$pn_rows[$idx]['child_test'] = json_encode($x_arr,true);
|
||||
$pn_rows[$idx]['nat_test'] = json_encode($p_nat_test,true);
|
||||
}
|
||||
unset($pn_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($pn_rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
foreach($pn_rows as $r ) {
|
||||
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
||||
$this->db->where("T_TestID", $r["T_TestID"]);
|
||||
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
||||
$qry = $this->db->update("ss_price_mou",$r);
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
}
|
||||
$rows = array_merge($rows,$pn_rows);
|
||||
return array(true,"OK",$rows);
|
||||
}
|
||||
}
|
||||
11
one-api/application/libraries/Synctablev1.php
Normal file
11
one-api/application/libraries/Synctablev1.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
class Synctabhlev1 {
|
||||
public function update($table,$records,$id,$url) {
|
||||
|
||||
}
|
||||
public function insert() {
|
||||
}
|
||||
function post($url, $param) {
|
||||
}
|
||||
}
|
||||
11
one-api/application/libraries/index.html
Normal file
11
one-api/application/libraries/index.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user