first commit -> move some files from one-api

This commit is contained in:
2026-05-06 13:37:10 +07:00
parent a3144382c5
commit 55c6ed9779
7940 changed files with 628870 additions and 0 deletions

View File

@@ -0,0 +1,230 @@
<?php
defined("BASEPATH") or exit("No direct script access allowed");
class Autosamplingverif
{
function __construct()
{
$CI = &get_instance();
$this->db_onedev = $CI->load->database("default", true);
}
function clean_mysqli_connection( $dbc )
{
while( mysqli_more_results($dbc) )
{
if(mysqli_next_result($dbc))
{
$result = mysqli_use_result($dbc);
if( get_class($result) == 'mysqli_stmt' )
{
mysqli_stmt_free_result($result);
}
else
{
unset($result);
}
}
}
}
function doaction($rst_id,$samplingtime,$userid){
$sql = "call sp_fo_barcode_generate_again_not_exist(" . $rst_id . ")";
$this->db_onedev->query($sql);
$this->clean_mysqli_connection($this->db_onedev->conn_id);
$sql = "SELECT *
FROM t_orderheader
JOIN t_orderheaderaddon ON T_OrderHeaderAddOnT_OrderHeaderID = T_OrderHeaderID
WHERE T_OrderHeaderID = {$rst_id}";
//echo $sql;
$row_addon = $this->db_onedev->query($sql)->row_array();
$readytime = date('Y-m-d H:i:s', strtotime($samplingtime));
//echo $readytime;
$sql = "UPDATE t_ordersample
SET
T_OrderSampleSampling = 'Y',
T_OrderSampleSamplingDate = DATE('{$samplingtime}'),
T_OrderSampleSamplingTime = TIME('{$samplingtime}'),
T_OrderSampleSamplingUserID = {$userid},
T_OrderSampleReceive = 'Y',
T_OrderSampleReceiveDate = DATE('{$samplingtime}'),
T_OrderSampleReceiveTime = TIME('{$samplingtime}'),
T_OrderSampleReadyToProcessDateTime = '{$readytime}',
T_OrderSampleVerification = 'Y',
T_OrderSampleVerificationDate = CURDATE(),
T_OrderSampleVerificationTime = CURTIME(),
T_OrderSampleVerificationUserID = {$userid},
T_OrderSampleSendHandling = 'Y',
T_OrderSampleSendHandlingDate = CURDATE(),
T_OrderSampleSendHandlingTime = CURTIME(),
T_OrderSampleSendHandlingUserID = {$userid},
T_OrderSampleReceiveUserID = {$userid},
T_OrderSampleReceiveHandling = 'Y',
T_OrderSampleReceiveHandlingDate = CURDATE(),
T_OrderSampleReceiveHandlingTime = CURTIME(),
T_OrderSampleReceiveHandlingUserID = {$userid}
WHERE
T_OrderSampleT_OrderHeaderID = {$rst_id}";
$upd_ordersample = $this->db_onedev->query($sql);
//echo $sql;
$sql = "SELECT *
FROM t_ordersample
JOIN t_barcodelab ON T_OrderSampleT_BarcodeLabID = T_BarcodeLabID AND T_BarcodeLabIsActive = 'Y'
JOIN t_sampletype ON T_SampleTypeID = T_OrderSampleT_SampleTypeID
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID
WHERE
T_OrderSampleT_OrderHeaderID = {$rst_id} AND
T_OrderSampleIsActive = 'Y'";
$data_loop = $this->db_onedev->query($sql)->result_array();
if ($data_loop) {
foreach ($data_loop as $ks => $vs) {
$sql = "INSERT INTO t_ordersamplereq(
T_OrderSampleReqT_OrderHeaderID,
T_OrderSampleReqT_SampleStationID,
T_OrderSampleReqT_OrderSampleID,
T_OrderSampleReqNat_PositionID,
T_OrderSampleReqStatus,
T_OrderSampleReqs,
T_OrderSampleReqUserID,
T_OrderSampleReqCreated
)
VALUES(
{$rst_id},
{$vs['T_SampleStationID']},
{$vs['T_OrderSampleID']},
'2',
'Y',
'[]',
{$userid},
NOW()
)ON DUPLICATE KEY UPDATE
T_OrderSampleReqStatus = 'Y',
T_OrderSampleReqs = '[]',
T_OrderSampleReqUserID = {$userid}";
//echo $sql;
$this->db_onedev->query($sql);
$sql = "INSERT INTO sample_by_step(
SampleByStepM_StatusSampleCode,
SampleByStepT_OrderHeaderID,
SampleByStepT_BarcodeLabID,
SampleByStepRequirementStatus,
SampleByStepRequirements,
SampleByStepUserID,
SampleByStepDateTime
)
VALUES(
'SAMPLING.Sampling.Sampled',
{$rst_id},
{$vs['T_BarcodeLabID']},
'Y',
'[]',
{$userid},
'{$row_addon['T_OrderHeaderAddOnOnlySampleTime']}'
)";
$this->db_onedev->query($sql);
$sql = "INSERT INTO sample_by_step(
SampleByStepM_StatusSampleCode,
SampleByStepT_OrderHeaderID,
SampleByStepT_BarcodeLabID,
SampleByStepRequirementStatus,
SampleByStepRequirements,
SampleByStepUserID,
SampleByStepDateTime
)
VALUES(
'SAMPLING.Sampling.Received',
{$rst_id},
{$vs['T_BarcodeLabID']},
'Y',
'[]',
{$userid},
'{$row_addon['T_OrderHeaderAddOnOnlySampleTime']}'
)";
$this->db_onedev->query($sql);
$sql = "INSERT INTO sample_by_step(
SampleByStepM_StatusSampleCode,
SampleByStepT_OrderHeaderID,
SampleByStepT_BarcodeLabID,
SampleByStepRequirementStatus,
SampleByStepRequirements,
SampleByStepUserID,
SampleByStepDateTime
)
VALUES(
'SAMPLING.Verification.Verify',
{$prm['sample']['T_OrderHeaderID']},
{$prm['sample']['T_BarcodeLabID']},
'{$prm['sample']['requirement_status']}',
'{$requirements}',
{$userid},
NOW()
)";
$this->db_onedev->query($sql);
$sql = "INSERT INTO sample_by_step(
SampleByStepM_StatusSampleCode,
SampleByStepT_OrderHeaderID,
SampleByStepT_BarcodeLabID,
SampleByStepRequirementStatus,
SampleByStepRequirements,
SampleByStepUserID,
SampleByStepDateTime
)
VALUES(
'SAMPLING.Verification.To.Handling',
{$prm['sample']['T_OrderHeaderID']},
{$prm['sample']['T_BarcodeLabID']},
'{$prm['sample']['requirement_status']}',
'{$requirements}',
{$userid},
NOW()
)";
$this->db_onedev->query($sql);
$sql = "INSERT INTO sample_by_step(
SampleByStepM_StatusSampleCode,
SampleByStepT_OrderHeaderID,
SampleByStepT_BarcodeLabID,
SampleByStepRequirementStatus,
SampleByStepRequirements,
SampleByStepUserID,
SampleByStepDateTime
)
VALUES(
'SAMPLING.Handling.From.Verification',
{$prm['sample']['T_OrderHeaderID']},
{$prm['sample']['T_BarcodeLabID']},
'{$prm['sample']['requirement_status']}',
'{$requirements}',
{$userid},
NOW()
)";
$this->db_onedev->query($sql);
$query = " INSERT INTO t_sampling_queue_last_status (
T_SamplingQueueLastStatusT_SampleStationID,
T_SamplingQueueLastStatusT_OrderHeaderID,
T_SamplingQueueLastStatusT_SamplingQueueStatusID,
T_SamplingQueueLastStatusUserID)
VALUES(
{$vs['T_SampleStationID']},
{$rst_id},
'5',
{$userid})
ON DUPLICATE KEY UPDATE
T_SamplingQueueLastStatusT_SamplingQueueStatusID = 5,
T_SamplingQueueLastStatusUserID = {$userid}";
//echo $query;
$this->db_onedev->query($query);
}
}
}
}

View File

@@ -0,0 +1,14 @@
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
require_once APPPATH."/third_party/PHPExcel/Classes/PHPExcel.php";
require_once APPPATH."/third_party/PHPExcel/Classes/PHPExcel/IOFactory.php";
class Excel extends PHPExcel {
public function __construct() {
parent::__construct();
}
}
?>

View 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;
}
}

View 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
);
}
}

View File

@@ -0,0 +1,162 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Kapus{
public function calc($date,$userID = 3)
{
$CI =& get_instance();
$this->db = $CI->load->database("onedev",true);
//cek if current date is posted
$this->db->trans_start();
$sql = "select * from sys_f_kapus_sum where sysFKapusSumDate = ?
and sysFKapusIsActive = 'Y' ";
$qry = $this->db->query($sql , array($date));
$sysFKapusSumID = 0;
if ($qry ) {
$rows = $qry->result_array();
if ( count($rows) > 0 ) {
$sysFKapusSumID = $rows[0]["sysFKapusSumID"];
if ($rows[0]["sysFKapusSumIsPosted"] == "Y" ) {
return array("status" => "ERR" , "message" => "Kapus at $date already posted");
}
}
}
$sql = "select * from sys_kapus limit 0,1";
$qry = $this->db->query($sql);
if (! $qry ) {
$this->db->trans_rollback();
return array("status" => "ERR" , "message" => "Invalid Kapus Setting" . print_r($this->db->error(),true));
}
$rows = $qry->result_array();
if (count($rows) == 0 ) {
$this->db->trans_rollback();
return array("status" => "ERR" , "message" => "Invalid Kapus Setting");
}
$companyID = $rows[0]["sysKaPusM_CompanyID"] . "," . $rows[0]["sysKaPusM_CompanyID2"];
$paymentTypeID = $rows[0]["sysKaPusM_PaymentTypeID"];
$targetPct = $rows[0]["sysKaPusPct"];
// get kapus
$sql = "select sum(F_PaymentDetailAmount) TotalAmount,
sum(F_PaymentDetailAmount - F_PaymentDetailAmount mod 500 ) TotalAmountAfterRounding
from t_orderheader
join f_payment on T_OrderHeaderID = F_PaymentT_OrderHeaderID
and F_PaymentIsActive = 'Y' and T_OrderHeaderIsActive = 'Y'
and date(T_OrderHeaderDate) = date(?)
and F_PaymentDate = date(?)
join f_paymentdetail on F_PaymentID = F_PaymentDetailF_PaymentID
and F_PaymentDetailM_PaymentTypeID = ?
and F_PaymentDetailIsActive = 'Y' ";
$qry = $this->db->query($sql, array($date,$date, $paymentTypeID));
if (! $qry ) {
$this->db->trans_rollback();
return array("status" => "ERR" , "message" => "Error get total payment " . print_r($this->db->error(),true));
}
$rows = $qry->result_array();
if (count($rows) == 0 ) {
$this->db->trans_rollback();
return array("status" => "OK" , "message" => "No Payment Type , $paymentTypeID , $date ");
}
// seluruh kas
$totalAmount = $rows[0]["TotalAmount"];
$totalAmountAfterRounding = $rows[0]["TotalAmountAfterRounding"];
if ($totalAmount == 0 ) {
$this->db->trans_rollback();
return array("status" => "OK" , "message" => "Total Amount Zero ");
}
$sql = "drop table if exists xtmp_kapus";
$qry = $this->db->query($sql);
if (! $qry ) {
$this->db->trans_rollback();
return array("status" => "ERR" , "message" => "Drop Tmp table " . print_r($this->db->error(),true));
}
$sql = "
create temporary table xtmp_kapus
select F_PaymentT_OrderHeaderID,
cast(sum(F_PaymentDetailAmount) as decimal(15,0)) Total
from f_payment
join t_orderheader on F_PaymentT_OrderHeaderID = T_OrderHeaderID and T_OrderHeaderM_CompanyID in ($companyID)
join f_paymentdetail on F_PaymentDetailF_PaymentID = F_PaymentID and F_PaymentDetailIsActive = 'Y'
and F_PaymentIsActive = 'Y'
where F_PaymentDate = ? and F_PaymentDetailM_PaymentTypeID = ?
group by F_PaymentT_OrderHeaderID";
$qry = $this->db->query($sql, array($date,$paymentTypeID));
if (! $qry ) {
$this->db->trans_rollback();
return array("status" => "ERR" , "message" => "Create Tmp table " . print_r($this->db->error(),true));
}
$sql = "
select T_OrderHeaderID,
cast(T_OrderHeaderTotal as decimal(15,0) ) as T_OrderHeaderTotal ,
cast(T_OrderHeaderTotal - T_OrderHeaderTotal mod 500 as decimal(15,0) ) as T_OrderHeaderTotalAfterRounding
from t_orderheader
join xtmp_kapus on T_OrderHeaderID = F_PaymentT_OrderHeaderID
and Total = T_OrderHeaderTotal
and date(T_OrderHeaderDate) = ?
order by T_OrderHeaderID";
$qry = $this->db->query($sql, array($date));
if (! $qry ) {
$this->db->trans_rollback();
return array("status" => "ERR" , "message" => "Error get detail payment " . print_r($this->db->error(),true));
}
$rows = $qry->result_array();
if ($sysFKapusSumID == 0) {
$sql = "insert into sys_f_kapus_sum(sysFKapusSumDate, sysFKapusSumUserID,sysFKapusSumTargetPct,
sysFKapusSumTotal, sysFKapusSumTotalAfterRounding) values(?,?,?,?,?)";
$qry = $this->db->query($sql,array($date, $userID, $targetPct, $totalAmount, $totalAmountAfterRounding));
if (! $qry ) {
$this->db->trans_rollback();
return array("status" => "ERR" , "message" => "Error create sysFKapusSum " . print_r($this->db->error(),true));
}
$sysFKapusSumID = $this->db->insert_id();
}
$qry = $this->db->query("update sys_f_kapus set sysFKapusIsActive='N' where sysFKapusSysFKapusSumID=?", array($sysFKapusSumID));
if (! $qry ) {
$this->db->trans_rollback();
return array("status" => "ERR" , "message" => "Error reset sysFKapus " . print_r($this->db->error(),true));
}
$sql_i = "insert into sys_f_kapus( sysFKapusT_OrderHeaderID, sysFKapusAmount, sysFKapusRunAmount,
sysFKapusAmountAfterRounding,
sysFKapusM_UserID, sysFKapusDate, sysFKapusPct, sysFKapusSysFKapusSumID )
values(?,?,?, ?, ?,?,?,?)";
$curPct = 0;
$sum_total = 0;
$sum_total_after_rounding = 0;
foreach($rows as $r) {
$x_id = $r["T_OrderHeaderID"];
$x_total = $r["T_OrderHeaderTotal"];
$x_total_after_rounding = $r["T_OrderHeaderTotalAfterRounding"];
$sum_total += $x_total;
$sum_total_after_rounding += $x_total_after_rounding;
$curPct = $sum_total / $totalAmount * 100 ;
$qry = $this->db->query($sql_i, array($x_id, $x_total, $sum_total,
$x_total_after_rounding,
$userID,$date, $curPct,$sysFKapusSumID ) );
if (! $qry ) {
$this->db->trans_rollback();
return array("status" => "ERR" , "message" => "Error insert sys_f_kapus " . print_r($this->db->error(),true));
}
if ($curPct >= $targetPct ) {
break;
}
}
$sql = "update sys_f_kapus_sum set sysFKapusSumAmount = ? , sysFKapusSumActualPct = ? ,
sysFKapusSumTargetPct = ?, sysFKapusSumAmountAfterRounding = ?
where sysFKapusSumID = ?";
$qry = $this->db->query($sql, array($sum_total, $curPct, $targetPct, $sum_total_after_rounding, $sysFKapusSumID));
if (! $qry ) {
$this->db->trans_rollback();
return array("status" => "ERR" , "message" => "Error update sysFKapusSum " . print_r($this->db->error(),true));
}
$this->db->trans_commit();
return array("status" => "OK" , "message" => "");
}
}

View File

@@ -0,0 +1,14 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Mcu{
// param
// array ( T_OrderHeaderID => Array( T_SampleTypeID
//
function export($param) {
$CI =& get_instance();
$this->db = $CI->load->database("onedev",true);
foreach($param as $orderHeaderID => $samples ) {
$s_samples = impode(",",$samples);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,184 @@
<?php
defined("BASEPATH") or exit("No direct script access allowed");
class NatPatientLib
{
//dev
var $NAT_PATIENT_API = "http://10.9.8.249/one-api/nat_patient/r_api/";
//prod
//var $NAT_PATIENT_API = "http://192.168.50.250/one-api/nat_patient/r_api/";
function __construct()
{
$CI = &get_instance();
$this->db = $CI->load->database("default", true);
}
//remote => status : Y|N Y confirm N, not confirm.
/*
create table m_patient_nat_validation(
M_PatientNatValidationID int not null auto_increment primary key,
M_PatientNatValidationM_PatientID int,
M_PatientNatValidationM_UserID int,
M_PatientNatValidationM_UserUsername varchar(100),
M_PatientNatValidationIsActive char(1) default 'Y',
M_PatientNatValidationCreated datetime default current_timestamp(),
M_PatientNatValidationLastUpdated datetime default current_timestamp() on update current_timestamp(),
key(M_PatientNatValidationM_PatientID),
key(M_PatientNatValidationIsActive),
);
create table m_patient_nat_log (
M_PatientNatLogID int not null auto_increment primary key,
M_PatientNatLogDate datetime default current_timestamp(),
M_PatientNatLogStatus enum('New','Retry','Sent'),
M_PatientNatLogLastUpdated datetime default current_timestamp() on update current_timestamp(),
M_PatientNatLogJson text,
key(M_PatientNatLogDate),
key(M_PatientNatLogStatus)
);
*/
function save_nasional($userName,$patient) {
$resp = $this->get_branch();
if ($resp["status"] != "OK") {
return $resp;
}
$param = ["M_BranchID" => $resp["branchID"],
"M_BranchCode" => $resp["branchCode"],
"Username" => $userName,
"patient" => $patient ];
$z_param = gzcompress(json_encode($param));
$url = $this->NAT_PATIENT_API . "/update_from_local";
$zresp = $this->post($url, $z_param);
$jresp = gzuncompress($zresp);
$resp = json_decode($jresp, true);
if (!isset($resp["status"])) {
$resp["status"] = "ERR";
$resp["message"] = $zresp;
}
return $resp;
}
function confirm($localM_PatientID, $arr_remote, $userID, $userName)
{
$payload = [
"userID" => $userID,
"userName" => $userName,
"lokalM_PatientID" => $localM_PatientID,
"remote" => $arr_remote,
];
$jsonPayload = json_encode($payload);
$sql = "insert into m_patient_nat_log(M_PatientNatLogStatus,M_PatientNatLogJson)
values('New',?)";
$qry = $this->db->query($sql, [$jsonPayload]);
if (!$qry) {
return [
"status" => "ERR",
"message" => $this->db->error()["message"],
];
}
return ["status" => "OK"];
}
function check_connection()
{
$start = date("Y-m-d H:i:s");
$url = $this->NAT_PATIENT_API . "/check_connection";
$zresp = $this->post($url, ["dummy" => "load"]);
$jresp = gzuncompress($zresp);
$resp = json_decode($jresp, true);
if (!isset($resp["status"])) {
$resp["status"] = "ERR";
$resp["message"] = $zresp;
}
$stop = date("Y-m-d H:i:s");
$resp["start"] = $start;
$resp["stop"] = $stop;
return $resp;
}
function get_branch()
{
$sql =
"select M_BranchID, M_BranchCode from m_branch where M_BranchIsActive = 'Y' and M_BranchIsDefault='Y'";
$qry = $this->db->query($sql);
if (!$qry) {
return [
"status" => "ERR",
"message" =>
$this->db->error()["message"] .
"|\n" .
$this->db->last_query(),
];
}
$rows = $qry->result_array();
if (count($rows) == 0) {
return ["status" => "ERR", "message" => "No Default Branch"];
}
return [
"status" => "OK",
"branchID" => $rows[0]["M_BranchID"],
"branchCode" => $rows[0]["M_BranchCode"],
];
}
function search($query)
{
$start = date("Y-m-d H:i:s");
$url = $this->NAT_PATIENT_API . "/search_bizone";
$jparam = json_encode(["search" => $query]);
$zresp = $this->post($url, $jparam);
$jresp = gzuncompress($zresp);
$resp = json_decode($jresp, true);
if (!isset($resp["status"])) {
$resp["status"] = "ERR";
$resp["message"] = $zresp;
}
$stop = date("Y-m-d H:i:s");
$resp["start"] = $start;
$resp["stop"] = $stop;
return $resp;
}
// param array ->
function search_by_nik($param)
{
$start = date("Y-m-d H:i:s");
$url = $this->NAT_PATIENT_API . "/search_by_nik";
$resp = $this->get_branch();
if ($resp["status"] != "OK") {
return $resp;
}
$jparam = json_encode($param);
$zresp = $this->post($url, $jparam);
$jresp = gzuncompress($zresp);
$resp = json_decode($jresp, true);
if (!isset($resp["status"])) {
$resp["status"] = "ERR";
$resp["message"] = $zresp;
}
$stop = date("Y-m-d H:i:s");
$resp["start"] = $start;
$resp["stop"] = $stop;
return $resp;
}
public function post($url, $data)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/text",
"Content-Length: " . strlen($data),
]);
$result = curl_exec($ch);
if (curl_error($ch) != "") {
echo json_encode([
"status" => "ERR",
"message" => "Http Error : " . curl_error($ch),
]);
curl_close($ch);
exit();
}
curl_close($ch);
return $result;
}
}

View File

@@ -0,0 +1,113 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class ResultCalc{
public function auto($id)
{
$CI =& get_instance();
$this->db = $CI->load->database("onedev",true);
$sql = "select
T_TestCalculationID,T_TestCalculationFormula,
T_OrderDetailID, T_OrderDetailT_TestID, T_TestNat_TestID Nat_TestID,
T_TestCalculationID,T_OrderDetailResult,
fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) / 365 AgeInYear,
T_TestCalculationNat_SexID
from t_orderdetail
join t_orderheader on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
and T_OrderHeaderID = ?
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
join t_test on T_OrderDetailT_TestID = T_TestID
and T_OrderDetailIsActive = 'Y' and T_TestIsActive = 'Y'
join t_testcalculation on T_TestNat_TestID = T_TestCalculationNat_TestID
and T_TestCalculationIsActive = 'Y'
and (
T_TestCalculationNat_SexID = M_PatientM_SexID
or
T_TestCalculationNat_SexID = 0
)
";
$sql_det = "select T_TestCalculationDetailCode, T_OrderDetailResult
from
t_testcalculation_detail td
join t_testcalculation on T_TestCalculationID = T_TestCalculationDetailT_TestCalculationID
and T_TestCalculationID = ?
join t_test t on td.T_TestCalculationDetailNat_TestID = T_TestNat_TestID
left join t_orderdetail on T_TestID = T_OrderDetailT_TestID and T_OrderDetailIsActive = 'Y'
and T_OrderDetailT_OrderHeaderID = ?
where T_OrderDetailID is not null";
$qry = $this->db->query($sql, array($id));
$rows = $qry->result_array();
if ( count($rows) > 0 ) {
foreach($rows as $r) {
$tc_id = $r["T_TestCalculationID"];
$formula = $r["T_TestCalculationFormula"];
$qry_det = $this->db->query($sql_det, array($tc_id, $id));
$drows = $qry_det->result_array();
$have_all = true;
$have_one = false;
$formula = str_replace("AGE",$r["AgeInYear"], $formula);
$flag_recursive = false;
if (strpos($formula,"[REC]") > -1 ) {
$flag_recursive = true;
}
if ( ! $flag_recursive ) {
if( trim($r["T_OrderDetailResult"]) != "") continue;
}
$formula = str_replace("[REC]","", $formula);
foreach($drows as $dr) {
$code = $dr["T_TestCalculationDetailCode"];
$value = $dr["T_OrderDetailResult"];
if($dr["T_OrderDetailResult"] == "" ) {
$have_all = false;
break;
}
$have_one = true;
$formula = str_replace($code, $value,$formula);
}
if ($have_all && $have_one) {
eval("\$f_value = $formula;");
//formating
//echo "\n$f_value ..";
//file_put_contents("/xtmp/formula",$f_value. "\n",FILE_APPEND);
if (is_numeric($f_value)) {
$f_value = $this->format_value($f_value,$r["Nat_TestID"]);
}
//file_put_contents("/xtmp/formula",$f_value. "\n",FILE_APPEND);
$od_id = $r["T_OrderDetailID"];
$sql = "update t_orderdetail set T_OrderDetailResult = ?
where T_OrderDetailID = ?";
$this->db->query($sql, array($f_value,$od_id));
}
}
}
}
function format_value($f_value, $nat_test_id){
$CI =& get_instance();
$this->db = $CI->load->database("onedev",true);
$sql = "select * from m_instrumentmethode
where M_InstrumentMethodeIsActive = 'Y'
and M_InstrumentMethodeNat_TestID = ?
limit 0,1";
$qry = $this->db->query($sql, array($nat_test_id) );
if ($qry) {
$rows = $qry->result_array();
if (count($rows) > 0 ) {
if ($f_value > 0 ) {
$fmt = $rows[0]["M_InstrumentMethodeResultFormatAboveSF"];
} else {
$fmt = $rows[0]["M_InstrumentMethodeResultFormatSF"];
}
$idx = strpos($fmt,".");
$dec = strlen($fmt) - $idx;
if ($dec > 0 ) $dec = $dec -1;
return number_format($f_value,$dec);
}
}
return number_format($f_value,0,".",",");
}
}

View File

@@ -0,0 +1,107 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class ResultCalc{
public function auto($id)
{
$CI =& get_instance();
$this->db = $CI->load->database("onedev",true);
$sql = "select
T_TestCalculationID,T_TestCalculationFormula,
T_OrderDetailID, T_OrderDetailT_TestID, T_TestNat_TestID Nat_TestID,
T_TestCalculationID,T_OrderDetailResult,
fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) / 365 AgeInYear,
T_TestCalculationNat_SexID
from t_orderdetail
join t_orderheader on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
and T_OrderHeaderID = ?
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
join t_test on T_OrderDetailT_TestID = T_TestID
and T_OrderDetailIsActive = 'Y' and T_TestIsActive = 'Y'
join t_testcalculation on T_TestNat_TestID = T_TestCalculationNat_TestID
and T_TestCalculationIsActive = 'Y'
and (
T_TestCalculationNat_SexID = M_PatientM_SexID
or
T_TestCalculationNat_SexID = 0
)
";
$sql_det = "select T_TestCalculationDetailCode, T_OrderDetailResult
from
t_testcalculation_detail td
join t_testcalculation on T_TestCalculationID = T_TestCalculationDetailT_TestCalculationID
and T_TestCalculationID = ?
join t_test t on td.T_TestCalculationDetailNat_TestID = T_TestNat_TestID
left join t_orderdetail on T_TestID = T_OrderDetailT_TestID and T_OrderDetailIsActive = 'Y'
and T_OrderDetailT_OrderHeaderID = ?
where T_OrderDetailID is not null";
$qry = $this->db->query($sql, array($id));
$rows = $qry->result_array();
if ( count($rows) > 0 ) {
foreach($rows as $r) {
$tc_id = $r["T_TestCalculationID"];
$qry_det = $this->db->query($sql_det, array($tc_id, $id));
$drows = $qry_det->result_array();
$formula = $r["T_TestCalculationFormula"];
$have_all = true;
$have_one = false;
$formula = str_replace("AGE",$r["AgeInYear"], $formula);
$flag_recursive = false;
if (strpos($formula,"[REC]") > -1 ) {
$flag_recursive = true;
}
if ( ! $flag_recursive ) {
if( $r["T_OrderDetailResult"] != "") continue;
}
$formula = str_replace("[REC]","", $formula);
foreach($drows as $dr) {
if($dr["T_OrderDetailResult"] == "" ) {
$have_all = false;
break;
}
$have_one = true;
$code = $dr["T_TestCalculationDetailCode"];
$value = $dr["T_OrderDetailResult"];
$formula = str_replace($code, $value,$formula);
}
if ($have_all && $have_one) {
eval("\$f_value = $formula;");
file_put_contents("/xtmp/formula",$formula . "\n",FILE_APPEND);
//formating
$f_value = $this->format_value($f_value,$r["Nat_TestID"]);
$od_id = $r["T_OrderDetailID"];
$sql = "update t_orderdetail set T_OrderDetailResult = ?
where T_OrderDetailID = ?";
$this->db->query($sql, array($f_value,$od_id));
}
}
}
}
function format_value($f_value, $nat_test_id){
$CI =& get_instance();
$this->db = $CI->load->database("onedev",true);
$sql = "select * from m_instrumentmethode
where M_InstrumentMethodeIsActive = 'Y'
and M_InstrumentMethodeNat_TestID = ?
limit 0,1";
$qry = $this->db->query($sql, array($nat_test_id) );
if ($qry) {
$rows = $qry->result_array();
if (count($rows) > 0 ) {
if ($f_value > 0 ) {
$fmt = $rows[0]["M_InstrumentMethodeResultFormatAboveSF"];
} else {
$fmt = $rows[0]["M_InstrumentMethodeResultFormatSF"];
}
$idx = strpos($fmt,".");
$dec = strlen($fmt) - $idx;
if ($dec > 0 ) $dec = $dec -1;
return number_format($f_value,$dec);
}
}
return number_format($f_value,0,".",",");
}
}

View File

@@ -0,0 +1,110 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class ResultCalc{
public function auto($id)
{
$CI =& get_instance();
$this->db = $CI->load->database("onedev",true);
$sql = "select
T_TestCalculationID,T_TestCalculationFormula,
T_OrderDetailID, T_OrderDetailT_TestID, T_TestNat_TestID Nat_TestID,
T_TestCalculationID,T_OrderDetailResult,
fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) / 365 AgeInYear,
T_TestCalculationNat_SexID
from t_orderdetail
join t_orderheader on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
and T_OrderHeaderID = ?
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
join t_test on T_OrderDetailT_TestID = T_TestID
and T_OrderDetailIsActive = 'Y' and T_TestIsActive = 'Y'
join t_testcalculation on T_TestNat_TestID = T_TestCalculationNat_TestID
and T_TestCalculationIsActive = 'Y'
and (
T_TestCalculationNat_SexID = M_PatientM_SexID
or
T_TestCalculationNat_SexID = 0
)
";
$sql_det = "select T_TestCalculationDetailCode, T_OrderDetailResult
from
t_testcalculation_detail td
join t_testcalculation on T_TestCalculationID = T_TestCalculationDetailT_TestCalculationID
and T_TestCalculationID = ?
join t_test t on td.T_TestCalculationDetailNat_TestID = T_TestNat_TestID
left join t_orderdetail on T_TestID = T_OrderDetailT_TestID and T_OrderDetailIsActive = 'Y'
and T_OrderDetailT_OrderHeaderID = ?
where T_OrderDetailID is not null";
$qry = $this->db->query($sql, array($id));
$rows = $qry->result_array();
if ( count($rows) > 0 ) {
foreach($rows as $r) {
$tc_id = $r["T_TestCalculationID"];
$qry_det = $this->db->query($sql_det, array($tc_id, $id));
$drows = $qry_det->result_array();
$formula = $r["T_TestCalculationFormula"];
$have_all = true;
$have_one = false;
$formula = str_replace("AGE",$r["AgeInYear"], $formula);
$flag_recursive = false;
if (strpos($formula,"[REC]") > -1 ) {
$flag_recursive = true;
}
//echo "$formula " . $r["T_OrderDetailResult"] . "\n";
if ( ! $flag_recursive ) {
if( trim($r["T_OrderDetailResult"]) != "") continue;
}
$formula = str_replace("[REC]","", $formula);
foreach($drows as $dr) {
$code = $dr["T_TestCalculationDetailCode"];
$value = $dr["T_OrderDetailResult"];
//echo "$code , $value , $formula \n";
if($dr["T_OrderDetailResult"] == "" ) {
$have_all = false;
break;
}
$have_one = true;
$formula = str_replace($code, $value,$formula);
}
if ($have_all && $have_one) {
eval("\$f_value = $formula;");
//formating
//echo "\n$f_value ..";
$f_value = $this->format_value($f_value,$r["Nat_TestID"]);
$od_id = $r["T_OrderDetailID"];
$sql = "update t_orderdetail set T_OrderDetailResult = ?
where T_OrderDetailID = ?";
$this->db->query($sql, array($f_value,$od_id));
}
}
}
}
function format_value($f_value, $nat_test_id){
$CI =& get_instance();
$this->db = $CI->load->database("onedev",true);
$sql = "select * from m_instrumentmethode
where M_InstrumentMethodeIsActive = 'Y'
and M_InstrumentMethodeNat_TestID = ?
limit 0,1";
$qry = $this->db->query($sql, array($nat_test_id) );
if ($qry) {
$rows = $qry->result_array();
if (count($rows) > 0 ) {
if ($f_value > 0 ) {
$fmt = $rows[0]["M_InstrumentMethodeResultFormatAboveSF"];
} else {
$fmt = $rows[0]["M_InstrumentMethodeResultFormatSF"];
}
$idx = strpos($fmt,".");
$dec = strlen($fmt) - $idx;
if ($dec > 0 ) $dec = $dec -1;
return number_format($f_value,$dec);
}
}
return number_format($f_value,0,".",",");
}
}

View File

@@ -0,0 +1,175 @@
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class ResultCalc
{
public function auto($id, $debug = "")
{
$CI = &get_instance();
$this->db = $CI->load->database("onedev", true);
$sql = "select
T_TestCalculationID,T_TestCalculationFormula,
T_OrderDetailID, T_OrderDetailT_TestID, T_TestNat_TestID Nat_TestID,
T_TestCalculationID,T_OrderDetailResult,
fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) / 365 AgeInYear,
T_TestCalculationNat_SexID,
T_OrderDetailT_TestName
from t_orderdetail
join t_orderheader on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
and T_OrderHeaderID = ?
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
join t_test on T_OrderDetailT_TestID = T_TestID
and T_OrderDetailIsActive = 'Y' and T_TestIsActive = 'Y'
join t_testcalculation on T_TestNat_TestID = T_TestCalculationNat_TestID
and T_TestCalculationIsActive = 'Y'
and (
T_TestCalculationNat_SexID = M_PatientM_SexID
or
T_TestCalculationNat_SexID = 0
)
";
$sql_det = "select T_OrderDetailT_TestName, T_TestCalculationDetailCode, T_OrderDetailResult
from
t_testcalculation_detail td
join t_testcalculation on T_TestCalculationID = T_TestCalculationDetailT_TestCalculationID
and T_TestCalculationID = ? and T_TestCalculationDetailIsActive = 'Y'
join t_test t on td.T_TestCalculationDetailNat_TestID = T_TestNat_TestID
left join t_orderdetail on T_TestID = T_OrderDetailT_TestID and T_OrderDetailIsActive = 'Y'
and T_OrderDetailT_OrderHeaderID = ?
Order by T_TestCalculationDetailCode,T_OrderDetailResult desc";
//where T_OrderDetailID is not null";
$qry = $this->db->query($sql, array($id));
$date = date("Y-m-d H:i:s");
//file_put_contents("/xtmp/debug-calc.log", "$date : {$this->db->last_query()} \n");
$rows = $qry->result_array();
if ($debug != "") {
print_r($rows);
}
if (count($rows) > 0) {
foreach ($rows as $r) {
$tc_id = $r["T_TestCalculationID"];
$qry_det = $this->db->query($sql_det, array($tc_id, $id));
$drows = $qry_det->result_array();
$formula = $r["T_TestCalculationFormula"];
$have_all = true;
$have_one = false;
$formula = str_replace("AGE", $r["AgeInYear"], $formula);
$flag_recursive = false;
if (strpos($formula, "[REC]") > -1) {
$flag_recursive = true;
}
if (!$flag_recursive) {
if (trim($r["T_OrderDetailResult"]) != "") continue;
}
$formula = str_replace("[REC]", "", $formula);
$org_formula = $formula;
$s_code_value = "";
$tc_name = $r["T_OrderDetailT_TestName"];
$arr_code = array();
$arr_param = [];
foreach ($drows as $dr) {
$code = $dr["T_TestCalculationDetailCode"];
$value = $dr["T_OrderDetailResult"];
$s_code_value .= "^$code=$value";
$arr_param[] = $code;
if (isset($arr_code[$code])) continue;
$arr_code[$code] = "exist";
if ($dr["T_OrderDetailResult"] == "" || $dr["T_OrderDetailResult"] == "-") {
$have_all = false;
break;
}
$arr_code[$code] = $value;
$have_one = true;
$formula = str_replace($code, $value, $formula);
}
$have_all = true;
if (count($arr_param) == 0) $have_all = false;
foreach($arr_param as $p) {
if ($debug != "") {
echo "code $p : ";
}
if (!isset($arr_code[$p])) {
if ($debug != "") {
echo "not exists \n";
}
$have_all = false;
break;
} else {
if ($arr_code[$p] == "exist") {
$have_all = false;
}
if ($debug != "") {
echo "exists : {$arr_code[$p]} \n";
}
}
}
if ($debug != "") {
echo "$formula " . $r["T_OrderDetailResult"] . "\n";
echo "-- have one : " . $have_one ? "Y" : "N";
echo "\n";
echo "-- have all : " . $have_all ? "Y" : "N";
echo "\n";
}
if ($have_all && $have_one) {
$date = date("Y-m-d H:i:s");
try {
// file_put_contents("/xtmp/debug-calc.log", "$date : $tc_name => \$f_value = $formula; \n");
// file_put_contents("/xtmp/debug-calc.log", "$date : Formula : $org_formula\n",FILE_APPEND);
// file_put_contents("/xtmp/debug-calc.log", print_r($drows,true),FILE_APPEND);
eval("\$f_value = $formula;");
//formating
$f_value = $this->format_value($f_value, $r["Nat_TestID"]);
if (is_numeric($f_value)) {
$f_value = $this->format_value($f_value, $r["Nat_TestID"]);
}
$od_id = $r["T_OrderDetailID"];
$sql = "update t_orderdetail set T_OrderDetailResult = ?
where T_OrderDetailID = ?";
$this->db->query($sql, array($f_value, $od_id));
if ($tc_id == 2) {
$sql = "insert into t_order_calc(T_OrderCalcT_OrderDetailID,
T_OrderCalcFormula,T_OrderCalcResult) values(?,?,?)";
$this->db->query($sql, array($od_id, $formula . " | " . $s_code_value, $f_value));
}
} catch (Exception $e) {
//print_r($e);
}
}
}
}
}
function format_value($f_value, $nat_test_id)
{
$CI = &get_instance();
$this->db = $CI->load->database("onedev", true);
$sql = "select * from m_instrumentmethode
where M_InstrumentMethodeIsActive = 'Y'
and M_InstrumentMethodeNat_TestID = ?
limit 0,1";
$qry = $this->db->query($sql, array($nat_test_id));
if ($qry) {
$rows = $qry->result_array();
if (count($rows) > 0) {
if ($f_value > 0) {
$fmt = $rows[0]["M_InstrumentMethodeResultFormatAboveSF"];
} else {
$fmt = $rows[0]["M_InstrumentMethodeResultFormatSF"];
}
$idx = strpos($fmt, ".");
$dec = strlen($fmt) - $idx;
if ($dec > 0) $dec = $dec - 1;
return number_format($f_value, $dec);
}
}
return number_format($f_value, 0, ".", ",");
}
}

View File

@@ -0,0 +1,116 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class ResultCalcv2 {
public function auto($id)
{
$CI =& get_instance();
$this->db = $CI->load->database("onedev",true);
$sql = "select
T_TestCalculationID,T_TestCalculationFormula,
T_OrderDetailID, T_OrderDetailT_TestID, T_TestNat_TestID Nat_TestID,
T_TestCalculationID,T_OrderDetailResult,
fn_global_age_count_day(M_PatientDOB, date(T_OrderHeaderDate)) / 365 AgeInYear,
T_TestCalculationNat_SexID
from t_orderdetail
join t_orderheader on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
and T_OrderHeaderID = ?
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
join t_test on T_OrderDetailT_TestID = T_TestID
and T_OrderDetailIsActive = 'Y' and T_TestIsActive = 'Y'
join t_testcalculation on T_TestNat_TestID = T_TestCalculationNat_TestID
and T_TestCalculationIsActive = 'Y'
and (
T_TestCalculationNat_SexID = M_PatientM_SexID
or
T_TestCalculationNat_SexID = 0
)
";
$sql_det = "select T_TestCalculationDetailCode, T_OrderDetailResult
from
t_testcalculation_detail td
join t_testcalculation on T_TestCalculationID = T_TestCalculationDetailT_TestCalculationID
and T_TestCalculationID = ?
join t_test t on td.T_TestCalculationDetailNat_TestID = T_TestNat_TestID
left join t_orderdetail on T_TestID = T_OrderDetailT_TestID and T_OrderDetailIsActive = 'Y'
and T_OrderDetailT_OrderHeaderID = ?
where T_OrderDetailID is not null";
$qry = $this->db->query($sql, array($id));
$rows = $qry->result_array();
if ( count($rows) > 0 ) {
foreach($rows as $r) {
$tc_id = $r["T_TestCalculationID"];
$qry_det = $this->db->query($sql_det, array($tc_id, $id));
$drows = $qry_det->result_array();
$formula = $r["T_TestCalculationFormula"];
$have_all = true;
$have_one = false;
$formula = str_replace("AGE",$r["AgeInYear"], $formula);
$flag_recursive = false;
if (strpos($formula,"[REC]") > -1 ) {
$flag_recursive = true;
}
echo "$formula " . $r["T_OrderDetailResult"] . "\n";
if ( ! $flag_recursive ) {
if( trim($r["T_OrderDetailResult"]) != "") continue;
}
$formula = str_replace("[REC]","", $formula);
foreach($drows as $dr) {
$code = $dr["T_TestCalculationDetailCode"];
$value = $dr["T_OrderDetailResult"];
echo "$code , $value , $formula \n";
if($dr["T_OrderDetailResult"] == "" ) {
$have_all = false;
break;
}
$have_one = true;
$formula = str_replace($code, $value,$formula);
}
if ($have_all && $have_one) {
eval("\$f_value = $formula;");
//formating
echo "\n$f_value ..";
$f_value = $this->format_value($f_value,$r["Nat_TestID"]);
if (is_numeric($f_value)) {
$f_value = $this->format_value($f_value,$r["Nat_TestID"]);
}
$od_id = $r["T_OrderDetailID"];
$sql = "update t_orderdetail set T_OrderDetailResult = ?
where T_OrderDetailID = ?";
$this->db->query($sql, array($f_value,$od_id));
$sql = "insert into t_order_calc(T_OrderCalcT_OrderDetailID,
T_OrderCalcFormula,T_OrderCalcResult) values(?,?,?)";
$this->db->query($sql, array($od_id,$formula,$f_value));
}
}
}
}
function format_value($f_value, $nat_test_id){
$CI =& get_instance();
$this->db = $CI->load->database("onedev",true);
$sql = "select * from m_instrumentmethode
where M_InstrumentMethodeIsActive = 'Y'
and M_InstrumentMethodeNat_TestID = ?
limit 0,1";
$qry = $this->db->query($sql, array($nat_test_id) );
if ($qry) {
$rows = $qry->result_array();
if (count($rows) > 0 ) {
if ($f_value > 0 ) {
$fmt = $rows[0]["M_InstrumentMethodeResultFormatAboveSF"];
} else {
$fmt = $rows[0]["M_InstrumentMethodeResultFormatSF"];
}
$idx = strpos($fmt,".");
$dec = strlen($fmt) - $idx;
if ($dec > 0 ) $dec = $dec -1;
return number_format($f_value,$dec);
}
}
return number_format($f_value,0,".",",");
}
}

View File

@@ -0,0 +1,49 @@
<?php
require FCPATH . "vendor/aws_v3/aws-autoloader.php";
date_default_timezone_set("Asia/Jakarta");
class Sas_s3
{
var $bucket;
var $s3;
var $endpoint = "https://is3.cloudhost.id";
function __construct()
{
$this->bucket = "audio-sample";
$this->s3 = new Aws\S3\S3Client([
"region" => "us-east-1",
"endpoint" => $this->endpoint,
"use_path_style_endpoint" => true,
"credentials" => [
"key" => "DLBFBBB8R22W4B5IE7PC",
"secret" => "byCv726DN1TCQvLVHdSLMJg3K0i3Ajhm4rXPAVCu"
]
]);
}
function create_bucket($bucket)
{
$result = $this->s3->createBucket(["Bucket" => $bucket]);
return $result;
}
function upload($bucket, $key, $contentType, $body)
{
$result = $this->s3->putObject(
[
"Bucket" => $bucket,
"Key" => $key,
"Body" => $body,
"ContentType" => $contentType
]
);
return $result;
}
// avail : 10 minutes
function show_url($bucket, $key, $avail)
{
$cmd = $this->s3->getCommand("GetObject", ['Bucket' => $bucket, 'Key' => $key]);
$request = $this->s3->createPresignedRequest($cmd, '+20 minutes');
$presignedUrl = $request->getUri();
return $presignedUrl;
}
}

View File

@@ -0,0 +1,584 @@
<?php
class Satu_sehat
{
var $base_url, $base_consent_url, $base_oauth_url;
var $is_staging, $organizationID;
var $key, $secret;
var $tz;
var $db, $dbname;
function __construct()
{
$this->tz = "+07:00";
$this->is_staging = false;
$this->base_url = "https://api-satusehat.kemkes.go.id/fhir-r4/v1";
$this->base_oauth_url = "https://api-satusehat.kemkes.go.id/oauth2/v1";
$this->base_consent_url = "https://api-satusehat.dto.kemkes.go.id/consent/v1";
$CI = &get_instance();
$this->db = $CI->load->database("default", true);
$this->dbname = "one_health";
if ($this->is_staging) {
$this->base_url = "https://api-satusehat-stg.kemkes.go.id/fhir-r4/v1";
$this->base_oauth_url = "https://api-satusehat-stg.kemkes.go.id/oauth2/v1";
$this->base_consent_url = "https://api-satusehat-stg.dto.kemkes.go.id/consent/v1";
$this->dbname = "one_health_dev";
}
$this->get_organization_id();
}
function load_clinic()
{
$this->dbname = "one_health_clinic";
}
function ss_organization()
{
$this->get_organization_id();
$o_resp = $this->ss_get("/Organization/{$this->organizationID}");
$resp = $this->objToArray($o_resp);
$id = $resp["id"];
$name = $resp["name"];
$x_type = $resp["type"][0]["coding"][0];
$type = $x_type["display"];
$code = $x_type["code"];
$system = $x_type["system"];
return json_encode([
"ID" => $id,
"Name" => $name,
"Type" => $type,
"CodeSystem" => $code . " | " . $system,
]);
}
function search_practicioner_by_nik($nik, $debug = "")
{
$service = "/Practitioner?identifier=https://fhir.kemkes.go.id/id/nik|" . $nik;
$o_resp = $this->ss_get($service, $debug);
$resp = $this->objToArray($o_resp);
if (count($resp["entry"]) > 0) {
$rs = $resp["entry"][0]["resource"];
return json_encode([
"status" => "OK",
"ihsID" => $rs["id"],
"name" => $rs["name"][0]["text"]
]);
}
return json_encode([
"status" => "ERR",
"message" => "Practitioner not found [$nik]"
]);
}
function search_patient_by_nik($nik, $debug = "")
{
$service = "/Patient?identifier=https://fhir.kemkes.go.id/id/nik|" . $nik;
$resp = $this->ss_get($service);
if ($debug != "") {
echo "resp : ";
print_r($resp);
}
$a_resp = $this->objToArray($resp);
if (isset($a_resp["entry"][0]["resource"]["id"])) {
return $a_resp["entry"][0]["resource"]["id"];
}
return "";
}
function location_by_organization($organizationIhsID, $debug = "")
{
$service = "/Location?organization=" . $organizationIhsID;
$resp = $this->ss_get($service);
if ($debug != "") {
echo "resp : ";
print_r($resp);
}
$a_resp = $this->objToArray($resp);
return $a_resp;
}
function location_create(
$code,
$name,
$description,
$address,
$city,
$kodePos,
$administrativeCode,
$rt,
$rw,
$phone,
$type,
$partOf = "",
$email = "",
$fax = "",
$url = "",
$long = "",
$lat = ""
) {
$this->get_organization_id();
$organizationID = $this->organizationID;
list($type_code, $type_display) = explode("^", $type);
$telecom = [];
$telecom[] = ["system" => "phone", "value" => "$phone", "use" => "work"];
if ($fax != "") $telecom[] = ["system" => "fax", "value" => "$fax", "use" => "work"];
if ($email != "") $telecom[] = ["system" => "email", "value" => "$email"];
if ($url != "") $telecom[] = ["system" => "url", "value" => "$url"];
$provCode = substr($administrativeCode, 0, 2);
$cityCode = substr($administrativeCode, 0, 4);
$districtCode = substr($administrativeCode, 0, 7);
$villageCode = substr($administrativeCode, 0, 10);
$data = [
"resourceType" => "Location",
"identifier" => [
[
"system" => "http://sys-ids.kemkes.go.id/location/{$organizationID}",
"value" => "$code",
],
],
"status" => "active",
"name" => "$name",
"description" => "$description",
"mode" => "instance",
"telecom" => $telecom,
"address" => [
"use" => "work",
"line" => [
$address,
],
"city" => "$city",
"postalCode" => "$kodePos",
"country" => "ID",
"extension" => [
[
"url" =>
"https://fhir.kemkes.go.id/r4/StructureDefinition/administrativeCode",
"extension" => [
["url" => "province", "valueCode" => $provCode],
["url" => "city", "valueCode" => $cityCode],
["url" => "district", "valueCode" => "$districtCode"],
["url" => "village", "valueCode" => "$villageCode"],
["url" => "rt", "valueCode" => "$rt"],
["url" => "rw", "valueCode" => "$rw"],
],
],
],
],
"physicalType" => [
"coding" => [
[
"system" =>
"http://terminology.hl7.org/CodeSystem/location-physical-type",
"code" => "$type_code",
"display" => "$type_display",
],
],
],
"position" => [
"longitude" => intval($long),
"latitude" => intval($lat),
"altitude" => 0,
],
"managingOrganization" => ["reference" => "Organization/{$organizationID}"],
];
if ($partOf != "") {
$data["partOf"] = [
"reference" => "Location/$partOf"
];
}
$service = "/Location";
$resp = $this->ss_post($service, $data);
$oresp = $this->objToArray($resp);
if (!isset($oresp["id"])) {
header("Content-Type: text/plain");
print_r($data);
print_r($resp);
}
return $oresp;
}
function location_nonactive(
$ihsID
) {
$this->get_organization_id();
$data = [
[
"op" => "replace",
"path" => "/status",
"value" => "inactive"
]
];
$service = "/Location/$ihsID";
$resp = $this->ss_patch($service, $data);
return $this->objToArray($resp);
}
function get_location($locationID)
{
}
function encounter_by_id($encounterID)
{
$this->get_organization_id();
$service = "/Encounter/$";
$resp = $this->ss_get($service);
return $this->objToArray($resp);
}
function encounter_by_subject($patientIhsID)
{
$this->get_organization_id();
$service = "/Encounter?subject=$patientIhsID";
$resp = $this->ss_get($service);
return $this->objToArray($resp);
}
function encounter(
$orderDate,
$patientIhsID,
$patientName,
$doctorIhsID,
$doctorName,
$locationID,
$locationName,
$labNumber,
$tz = "+07:00",
$payload_only = false
) {
$service = "/Encounter";
$xdate = substr($orderDate, 0, 10) . "T" . substr($orderDate, 11) . $tz;
$this->get_organization_id();
$param = $this->encounter_param(
$patientIhsID,
$patientName,
$doctorIhsID,
$doctorName,
$locationID,
$locationName,
$this->organizationID,
$labNumber,
$xdate
);
$payload = json_encode($param);
if ($payload_only) {
return ["", "", $payload, ""];
}
$jresp = $this->ss_post($service, $param);
$resp = $this->objToArray($jresp);
$response = json_encode($resp);
if (is_array($resp) && isset($resp["id"])) {
$encounterResponseID = $resp["id"];
return [$encounterResponseID, "", $payload, $response];
} else {
return ["", $response, $payload, $response];
}
}
function encounter_param(
$patientIhs,
$patientName,
$dpjpIhs,
$dpjpName,
$locationIhs,
$locationName,
$organizationID,
$orderHeaderNumber,
$dateTime // 2022-06-14T07:00:00+07:00
) {
if ($this->is_staging) {
$dpjpIhs = "N10000001";
$dpjpName = "Dokter Bronsig";
}
$encounterParam = [
"resourceType" => "Encounter",
"status" => "arrived",
"class" => [
"system" => "http://terminology.hl7.org/CodeSystem/v3-ActCode",
"code" => "AMB",
"display" => "ambulatory"
],
"subject" => [
"reference" => "Patient/{$patientIhs}",
"display" => "$patientName"
],
"participant" => [
[
"type" => [
[
"coding" => [
[
"system" => "http://terminology.hl7.org/CodeSystem/v3-ParticipationType",
"code" => "ATND",
"display" => "attender"
]
]
]
],
"individual" => [
"reference" => "Practitioner/{$dpjpIhs}",
"display" => "$dpjpName"
]
]
],
"period" => [
"start" => "$dateTime",
],
"location" => [
[
"location" => [
"reference" => "Location/$locationIhs",
"display" => "$locationName"
]
]
],
"statusHistory" => [
[
"status" => "arrived",
"period" => [
"start" => $dateTime
]
]
],
"serviceProvider" => [
"reference" => "Organization/{$organizationID}"
],
"identifier" => [
[
"system" => "http://sys-ids.kemkes.go.id/encounter/{$organizationID}",
"value" => "$orderHeaderNumber"
]
]
];
return $encounterParam;
}
// helper
function get_organization_id()
{
$sql = "SELECT organizationID
FROM {$this->dbname}.organization
JOIN m_branch ON organizationM_BranchID = M_BranchID AND M_BranchIsDefault = 'Y' AND M_BranchIsActive = 'Y'
WHERE organizationIsActive = 'Y'";
$qry = $this->db->query($sql);
if (!$qry) {
return;
}
$rows = $qry->result_array();
if (count($rows) > 0) {
$this->organizationID = $rows[0]["organizationID"];
}
}
function ss_patch($service, $data)
{
$token = $this->get_token();
$authorization = "Authorization: Bearer " . $token;
$xbase_url = $this->base_url;
$url = $xbase_url . "$service";
$ch = curl_init($url);
# Setup request to send json via POST.
$payload = json_encode($data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json-patch+json', $authorization));
# Return response instead of printing.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
# Send request.
$result = curl_exec($ch);
curl_close($ch);
# Print response.
$data_rst = json_decode($result);
return $data_rst;
}
function get_client_key($debug = "")
{
$sql = "select * from {$this->dbname}.client where clientIsActive = 'Y'";
$qry = $this->db->query($sql);
if (!$qry) {
return [false, "", ""];
}
$rows = $qry->result_array();
if (count($rows) == 0) {
if ($debug != "") {
print_r([false, "", ""]);
}
return [false, "", ""];
}
if ($debug != "") {
print_r([true, $rows[0]["clientKey"], $rows[0]["clientSecret"]]);
}
return [true, $rows[0]["clientKey"], $rows[0]["clientSecret"]];
}
function reset_token()
{
$sql = "delete from {$this->dbname}.token ";
$qry = $this->db->query($sql);
if (!$qry) {
echo "ERR : " . $this->db->error()["message"];
echo " " . $this->db->last_query();
exit;
}
}
function put_token()
{
$auth_url = $this->base_oauth_url;
$url = $auth_url . "/accesstoken?grant_type=client_credentials";
list($status, $key, $secret) = $this->get_client_key();
$data = [
"client_id" => $key,
"client_secret" => $secret
];
$ch = curl_init($url);
$post_data = http_build_query($data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
if ($result) {
$token_rst = json_decode($result);
$sql = "select count(*) as xcount, tokenID
from {$this->dbname}.token
where
tokenIsActive = 'y'
";
$qry = $this->db->query($sql);
if (!$qry) {
echo "get count token error";
exit;
}
$rst_count = $qry->row_array();
// print_r($token_rst);
if ($rst_count['xcount'] > 0) {
$sql = "update {$this->dbname}.token set tokenValue = ?, tokenExpired = date_add(now(), interval 50 minute)
where tokenID = ?";
$qry = $this->db->query($sql, [$token_rst->access_token, $rst_count['tokenID']]);
if (!$qry) {
$this->sys_error_db("refresh token error", $this->db->last_query());
exit;
}
} else {
$sql = "update {$this->dbname}.token set tokenIsActive = 'N' where tokenIsActive = 'Y'";
$qry = $this->db->query($sql);
if (!$qry) {
echo "nonactive token error";
exit;
}
$sql = "insert into {$this->dbname}.token(tokenValue,tokenExpired) values(?,date_add(now(), interval 50 minute))";
$qry = $this->db->query($sql, [$token_rst->access_token]);
if (!$qry) {
echo "insert token error";
exit;
}
}
$sql = "select tokenValue
from {$this->dbname}.token
where
tokenIsActive = 'Y' limit 1
";
$qry = $this->db->query($sql);
if (!$qry) {
echo "get token error";
exit;
}
return $qry->row()->tokenValue;
}
}
function get_token()
{
$sql = "SELECT COUNT(*) as xcount, tokenValue
FROM {$this->dbname}.token
WHERE tokenIsActive = 'Y' AND NOW() < tokenExpired AND tokenValue IS NOT NULL ";
$qry = $this->db->query($sql);
$this->check_error($qry, "select token");
$data_token = $qry->row_array();
//print_r($data_token);
if ($data_token['xcount'] > 0) {
return $data_token['tokenValue'];
} else {
return $this->put_token();
}
}
function ss_post($service, $data)
{
$token = $this->get_token();
$authorization = "Authorization: Bearer " . $token;
$xbase_url = $this->base_url;
$url = $xbase_url . "$service";
$ch = curl_init($url);
# Setup request to send json via POST.
$payload = json_encode($data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', $authorization));
# Return response instead of printing.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
# Send request.
$result = curl_exec($ch);
curl_close($ch);
# Print response.
$data_rst = json_decode($result);
return $data_rst;
}
function ss_get($service, $debug = "")
{
$token = $this->get_token();
$authorization = "Authorization: Bearer " . $token;
$xbase_url = $this->base_url;
$url = $xbase_url . "$service";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', $authorization));
# Return response instead of printing.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
# Send request.
$result = curl_exec($ch);
curl_close($ch);
# Print response.
if ($debug != "") {
echo "url : $url \n";
print_r($result);
}
$data_rst = json_decode($result);
return $data_rst;
}
protected function objToArray($obj)
{
if (!is_object($obj) && !is_array($obj)) {
return $obj;
}
foreach ($obj as $key => $value) {
$arr[$key] = $this->objToArray($value);
}
return $arr;
}
function check_error($qry, $stage)
{
if (!$qry) {
echo json_encode([
"status" => "ERR",
"message" => $this->db->error(),
"sql" => $this->db->last_query()
]);
exit;
}
}
}

View File

@@ -0,0 +1,244 @@
<?php
defined("BASEPATH") or exit("No direct script access allowed");
class Satusehat
{
//var $xbase_url = "https://api-satusehat-dev.dto.kemkes.go.id/fhir-r4/v1";
function __construct()
{
$CI = &get_instance();
$this->db_onedev = $CI->load->database("default", true);
}
function clean_mysqli_connection( $dbc )
{
while( mysqli_more_results($dbc) )
{
if(mysqli_next_result($dbc))
{
$result = mysqli_use_result($dbc);
if( get_class($result) == 'mysqli_stmt' )
{
mysqli_stmt_free_result($result);
}
else
{
unset($result);
}
}
}
}
/*function get_token(){
$sql = "SELECT COUNT(*) as xcount, tokenValue
FROM one_health.token
WHERE tokenIsActive = 'Y' AND NOW() < tokenExpired AND tokenValue IS NOT NULL
";
$qry = $this->db_onedev->query($sql);
if (!$qry) {
echo "select token error";
exit;
}
$data_token = $qry->row_array();
//print_r($data_token);
if($data_token['xcount'] > 0){
return $data_token['tokenValue'];
}else{
return $this->putx_token();
}
}*/
function get_new_token(){
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api-satusehat-dev.dto.kemkes.go.id/oauth2/v1/accesstoken?grant_type=client_credentials',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => 'client_id=6PukKqO0RQqu0cKBOC8EKGcXQySfPR4aVkiVmuTgkx5xvva4&client_secret=89ZqsmY3z5W7rVscHTp9gJoAWWiAZG4A2unS3maTw3DxBFxTdaRsSeTUbD8mRN3p',
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
}
function put_token(){
$auth_url = "https://api-satusehat-dev.dto.kemkes.go.id/oauth2/v1";
//API URL
$url = $auth_url."/accesstoken?grant_type=client_credentials";
//echo $url;
$data = [
"client_id" => "6PukKqO0RQqu0cKBOC8EKGcXQySfPR4aVkiVmuTgkx5xvva4",
"client_secret" => "89ZqsmY3z5W7rVscHTp9gJoAWWiAZG4A2unS3maTw3DxBFxTdaRsSeTUbD8mRN3p"
];
$ch = curl_init($url);
# Setup request to send json via POST.
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch,CURLOPT_HTTPHEADER,
array(
'Content-Type: application/x-www-form-urlencoded'
)
);
# Return response instead of printing.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
# Send request.
$result = curl_exec($ch);
curl_close($ch);
# Print response.
print_r($result);
//echo $token_rst->access_token;
if($result){
$token_rst = json_decode($result);
$sql = "SELECT COUNT(*) as xcount, tokenID
FROM one_health.token
WHERE
tokenIsActive = 'Y'
";
$qry = $this->db_onedev->query($sql);
if (!$qry) {
echo "get count token error";
exit;
}
$rst_count = $qry->row_array();
if($rst_count['xcount'] > 0){
$sql = "UPDATE one_health.token SET tokenValue = ?, tokenExpired = DATE_ADD(NOW(), INTERVAL 50 MINUTE)
WHERE tokenID = ?";
$qry = $this->db_onedev->query($sql, [$token_rst->access_token,$rst_count['tokenID']]);
if (!$qry) {
$this->sys_error_db("refresh token error", $this->db_onedev->last_query());
exit;
}
}else{
$sql = "UPDATE one_health.token SET tokenIsActive = 'N' WHERE tokenIsActive = 'Y'";
$qry = $this->db_onedev->query($sql);
if (!$qry) {
echo "nonactive token error";
exit;
}
$sql = "INSERT INTO one_health.token(tokenValue,tokenExpired) VALUES(?,DATE_ADD(NOW(), INTERVAL 50 MINUTE))";
$qry = $this->db_onedev->query($sql, [$token_rst->access_token]);
if (!$qry) {
echo "insert token error";
exit;
}
}
$sql = "SELECT tokenValue
FROM one_health.token
WHERE
tokenIsActive = 'Y' LIMIT 1
";
$qry = $this->db_onedev->query($sql);
if (!$qry) {
echo "get token error";
exit;
}
return $qry->row()->tokenValue;
}
}
/*function search_practicioner_by_nik($nik){
$sql = "SELECT tokenValue
FROM one_health.token
WHERE
tokenIsActive = 'Y' LIMIT 1
";
$qry = $this->db_onedev->query($sql);
if (!$qry) {
echo "get token error";
exit;
}
$token = $qry->row()->tokenValue;
$authorization = "Authorization: Bearer ".$token;
//API URL
$url = $this->xbase_url."/Practitioner?identifier=https://fhir.kemkes.go.id/id/nik|".$nik;
//echo $url;
$ch = curl_init($url);
# Setup request to send json via POST.
//$payload = json_encode($data);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , $authorization ));
# Return response instead of printing.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
# Send request.
$result = curl_exec($ch);
curl_close($ch);
# Print response.
$data_rst = json_decode($result);
print_r($result);
return $data_rst;
}*/
function gen_uuid() {
return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
// 32 bits for "time_low"
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
// 16 bits for "time_mid"
mt_rand( 0, 0xffff ),
// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 4
mt_rand( 0, 0x0fff ) | 0x4000,
// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
mt_rand( 0, 0x3fff ) | 0x8000,
// 48 bits for "node"
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
);
}
protected function objToArray($obj)
{
// Not an object or array
if (!is_object($obj) && !is_array($obj)) {
return $obj;
}
// Parse array
foreach ($obj as $key => $value) {
$arr[$key] = $this->objToArray($value);
}
// Return parsed array
return $arr;
}
}

View 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);
}
}

View 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, "");
}
}

View File

@@ -0,0 +1,249 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class TxBranchStatus{
public function update_multi($stage,$ids ,$username)
{
$CI =& get_instance();
$this->db = $CI->load->database("onedev",true);
$s_ids = join(",",$ids);
$sql = "select T_OrderDetailT_TestID, T_OrderDetailT_OrderHeaderID
from
t_orderdetail
where T_OrderDetailID in ($s_ids) ";
$qry = $this->db->query($sql);
$incomingRefID = 0;
$s_detail_ids = "0";
$s_child_ids = "0";
if ($qry) {
$rows = $qry->result_array();
if(count($rows) > 0 ) {
$headerID = $rows[0]["T_OrderDetailT_OrderHeaderID"];
$s_test = "0";
foreach($rows as $r) {
$s_test .= "," . $r["T_OrderDetailT_TestID"];
}
$sql = "select incomingRefDetailID , incomingRefDetailIncomingRefID
from incoming_ref_detail
where incomingRefDetailNewT_OrderHeaderID = ?
and incomingRefDetailT_TestID in ($s_test) ";
$qryd = $this->db->query($sql, array($headerID));
$flag_found = false;
if($qryd) {
$rowsd = $qryd->result_array();
if ( count($rowsd) > 0 ) {
$incomingRefID = $rowsd[0]["incomingRefDetailIncomingRefID"];
foreach($rowsd as $r) {
$s_detail_ids .= "," . $r["incomingRefDetailID"];
}
}
}
//check child
if(! $flag_found ) {
$sql = "select incomingRefChildID , incomingRefChildIncomingRefID
from incoming_ref_child
where incomingRefChildNewT_OrderHeaderID = ?
and incomingRefChildT_TestID in ($s_test) ";
$qryd = $this->db->query($sql, array($headerID));
if($qryd) {
$rowsd = $qryd->result_array();
if ( count($rowsd) > 0 ) {
$incomingRefID = $rowsd[0]["incomingRefChildIncomingRefID"];
foreach($rowsd as $r) {
$s_child_ids .= "," . $r["incomingRefChildID"];
}
}
}
}
}
}
if ($s_detail_ids == "0" && $s_child_ids == "0" ) {
return false;
}
$sql = "select M_BranchID, M_BranchIPAddress
from m_branch
join incoming_ref
on M_BranchID = incomingRefM_BranchID
where incomingRefID = ?";
$qry = $this->db->query($sql, array($incomingRefID));
$branchID = 0;
if ($qry) {
$rows = $qry->result_array();
if(count($rows)>0) {
$branchID = $rows[0]["M_BranchID"];
$branchIPAddress = $rows[0]["M_BranchIPAddress"];
}
}
if ($branchID == 0 ) {
return false;
}
$note = "$stage by $username";
if ($s_detail_ids!= "0" ) {
$sql = "select
incomingRefT_RefDeliveryOrderID,
incomingRefDetailT_OrderDetailID,
incomingRefDetailStatus,
T_OrderDetailResult,
T_OrderDetailNat_NormalValueID,
T_OrderDetailVerification,
T_OrderDetailValidation,
? note
from incoming_ref_detail
join incoming_ref on incomingRefID = incomingRefDetailIncomingRefID
and incomingRefDetailID in ($s_detail_ids)
left join t_orderdetail on incomingRefDetailNewT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
and T_OrderDetailIsActive = 'Y' and incomingRefDetailT_TestID = T_OrderDetailT_TestID";
$qry = $this->db->query($sql, array($note));
if ($qry) {
$rows = $qry->result_array();
$param = json_encode($rows);
//insert to
$sql = "insert into tx_branch_status(TxBranchStatusStage, TxBranchStatusM_BranchID,
TxBranchStatusM_BranchIP, TxBranchStatusJson,TxBranchStatusNote )
values (?,?,?,?,?)";
$qry = $this->db->query($sql, array($stage,$branchID, $branchIPAddress, $param, $note));
}
}
if ($s_child_ids!= "0" ) {
$sql = "select
incomingRefT_RefDeliveryOrderID,
incomingRefChildT_OrderDetailID incomingRefDetailT_OrderDetailID,
'' incomingRefDetailStatus,
T_OrderDetailResult,
T_OrderDetailNat_NormalValueID,
T_OrderDetailVerification,
T_OrderDetailValidation,
? note
from incoming_ref_child
join incoming_ref on incomingRefID = incomingRefChildIncomingRefID
and incomingRefChildID in ($s_child_ids)
left join t_orderdetail on incomingRefChildNewT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
and T_OrderDetailIsActive = 'Y' and incomingRefChildT_TestID = T_OrderDetailT_TestID";
$qry = $this->db->query($sql, array($note));
if ($qry) {
$rows = $qry->result_array();
$param = json_encode($rows);
//insert to
$sql = "insert into tx_branch_status(TxBranchStatusStage, TxBranchStatusM_BranchID,
TxBranchStatusM_BranchIP, TxBranchStatusJson,TxBranchStatusNote )
values (?,?,?,?,?)";
$qry = $this->db->query($sql, array($stage,$branchID, $branchIPAddress, $param, $note));
}
}
}
public function update($stage,$orderDetailID,$username)
{
$CI =& get_instance();
$this->db = $CI->load->database("onedev",true);
$sql = "select T_OrderDetailT_TestID, T_OrderDetailT_OrderHeaderID
from
t_orderdetail
where T_OrderDetailID = ? ";
$qry = $this->db->query($sql, array($orderDetailID));
$incomingRefID = 0;
$incomingRefDetailID = 0;
$flag_child = false;
if ($qry) {
$rows = $qry->result_array();
$flag_found = false;
if(count($rows) > 0 ) {
$headerID = $rows[0]["T_OrderDetailT_OrderHeaderID"];
$testID = $rows[0]["T_OrderDetailT_TestID"];
$sql = "select incomingRefDetailID , incomingRefDetailIncomingRefID
from incoming_ref_detail
where incomingRefDetailNewT_OrderHeaderID = ?
and incomingRefDetailT_TestID = ?";
$qryd = $this->db->query($sql, array($headerID,$testID));
if($qryd) {
$rowsd = $qryd->result_array();
if ( count($rowsd) > 0 ) {
$incomingRefID = $rowsd[0]["incomingRefDetailIncomingRefID"];
$incomingRefDetailID = $rowsd[0]["incomingRefDetailID"];
$flag_found = true;
}
}
//check child
if(! $flag_found ) {
$sql = "select incomingRefChildID , incomingRefChildIncomingRefID
from incoming_ref_child
where incomingRefChildNewT_OrderHeaderID = ?
and incomingRefChildT_TestID = ?";
$qryd = $this->db->query($sql, array($headerID,$testID));
if($qryd) {
$rowsd = $qryd->result_array();
if ( count($rowsd) > 0 ) {
$incomingRefID = $rowsd[0]["incomingRefChildIncomingRefID"];
$incomingRefDetailID = $rowsd[0]["incomingRefChildID"];
$flag_found = true;
$flag_child = true;
}
}
}
}
}
if ($incomingRefDetailID == 0 || $incomingRefDetailID == "") {
return false;
}
$sql = "select M_BranchID, M_BranchIPAddress
from m_branch
join incoming_ref
on M_BranchID = incomingRefM_BranchID
where incomingRefID = ?";
$qry = $this->db->query($sql, array($incomingRefID));
$branchID = 0;
if ($qry) {
$rows = $qry->result_array();
if(count($rows)>0) {
$branchID = $rows[0]["M_BranchID"];
$branchIPAddress = $rows[0]["M_BranchIPAddress"];
}
}
if ($branchID == 0 ) {
return false;
}
$note = "$stage by $username";
$sql = "select
incomingRefT_RefDeliveryOrderID,
incomingRefDetailT_OrderDetailID,
incomingRefDetailStatus,
T_OrderDetailResult,
T_OrderDetailNat_NormalValueID,
T_OrderDetailVerification,
T_OrderDetailValidation,
? note
from incoming_ref_detail
join incoming_ref on incomingRefID = incomingRefDetailIncomingRefID
and incomingRefDetailID = ?
left join t_orderdetail on incomingRefDetailNewT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
and T_OrderDetailIsActive = 'Y' and incomingRefDetailT_TestID = T_OrderDetailT_TestID";
if ($flag_child ) {
$sql = "select
incomingRefT_RefDeliveryOrderID,
incomingRefChildT_OrderDetailID incomingRefDetailT_OrderDetailID,
'' incomingRefDetailStatus,
T_OrderDetailResult,
T_OrderDetailNat_NormalValueID,
T_OrderDetailVerification,
T_OrderDetailValidation,
? note
from incoming_ref_child
join incoming_ref on incomingRefID = incomingRefChildIncomingRefID
and incomingRefChildID = ?
left join t_orderdetail on incomingRefChildNewT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
and T_OrderDetailIsActive = 'Y' and incomingRefChildT_TestID = T_OrderDetailT_TestID";
}
$qry = $this->db->query($sql, array($note, $incomingRefDetailID));
if ($qry) {
$rows = $qry->result_array();
$param = json_encode($rows);
//insert to
$sql = "insert into tx_branch_status(TxBranchStatusStage, TxBranchStatusM_BranchID,
TxBranchStatusM_BranchIP, TxBranchStatusJson,TxBranchStatusNote )
values (?,?,?,?,?)";
$qry = $this->db->query($sql, array($stage,$branchID, $branchIPAddress, $param, $note));
}
}
}

View File

@@ -0,0 +1,300 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class TxBranchStatus{
public function update_multi($stage,$ids ,$username)
{
$CI =& get_instance();
$this->db = $CI->load->database("onedev",true);
$s_ids = join(",",$ids);
$sql = "select T_OrderDetailT_TestID, T_OrderDetailT_OrderHeaderID
from
t_orderdetail
where T_OrderDetailID in ($s_ids) ";
$qry = $this->db->query($sql);
$incomingRefID = 0;
$s_detail_ids = "0";
$s_child_ids = "0";
$headerID = 0;
if ($qry) {
$rows = $qry->result_array();
if(count($rows) > 0 ) {
$headerID = $rows[0]["T_OrderDetailT_OrderHeaderID"];
$s_test = "0";
foreach($rows as $r) {
$s_test .= "," . $r["T_OrderDetailT_TestID"];
}
$sql = "select incomingRefDetailID , incomingRefDetailIncomingRefID
from incoming_ref_detail
where incomingRefDetailNewT_OrderHeaderID = ?
and incomingRefDetailT_TestID in ($s_test) ";
$qryd = $this->db->query($sql, array($headerID));
$flag_found = false;
if($qryd) {
$rowsd = $qryd->result_array();
if ( count($rowsd) > 0 ) {
$incomingRefID = $rowsd[0]["incomingRefDetailIncomingRefID"];
foreach($rowsd as $r) {
$s_detail_ids .= "," . $r["incomingRefDetailID"];
}
}
}
//check child
if(! $flag_found ) {
$sql = "select incomingRefChildID , incomingRefChildIncomingRefID
from incoming_ref_child
where incomingRefChildNewT_OrderHeaderID = ?
and incomingRefChildT_TestID in ($s_test) ";
$qryd = $this->db->query($sql, array($headerID));
if($qryd) {
$rowsd = $qryd->result_array();
if ( count($rowsd) > 0 ) {
$incomingRefID = $rowsd[0]["incomingRefChildIncomingRefID"];
foreach($rowsd as $r) {
$s_child_ids .= "," . $r["incomingRefChildID"];
}
}
}
}
}
}
if ($s_detail_ids == "0" && $s_child_ids == "0" ) {
return false;
}
$sql = "select M_BranchID, M_BranchIPAddress
from m_branch
join incoming_ref
on M_BranchID = incomingRefM_BranchID
where incomingRefID = ?";
$qry = $this->db->query($sql, array($incomingRefID));
$branchID = 0;
if ($qry) {
$rows = $qry->result_array();
if(count($rows)>0) {
$branchID = $rows[0]["M_BranchID"];
$branchIPAddress = $rows[0]["M_BranchIPAddress"];
}
}
if ($branchID == 0 ) {
return false;
}
$val_note = "";
$val_note_int = "";
if ($headerID > 0 ) {
$sql = "select T_OrderHeaderAddOnValidationNote, T_OrderHeaderAddOnValidationInternal
from t_orderheaderaddon
where T_orderHeaderAddOnT_OrderHeaderID = ?";
$qry = $this->db->query($sql,array($headerID));
if ($qry) {
$rows = $qry->result_array();
if (count($rows) > 0 ) {
$val_note = $rows[0]["T_OrderHeaderAddOnValidationNote"];
$val_note_int = $rows[0]["T_OrderHeaderAddOnValidationInternal"];
if ( $val_note == null ) $val_note = "";
if ( $val_note_int == null ) $val_note_int = "";
}
}
}
$note = "$stage by $username";
if ($s_detail_ids!= "0" ) {
$sql = "select
incomingRefT_RefDeliveryOrderID,
incomingRefDetailID,
incomingRefDetailT_OrderDetailID,
incomingRefDetailStatus,
T_OrderDetailResult,
T_OrderDetailNat_NormalValueID,
T_OrderDetailVerification,
T_OrderDetailValidation,
T_OrderDetailNote,
? note,
? validation_note,
? validation_note_internal
from incoming_ref_detail
join incoming_ref on incomingRefID = incomingRefDetailIncomingRefID
and incomingRefDetailID in ($s_detail_ids)
left join t_orderdetail on incomingRefDetailNewT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
and T_OrderDetailIsActive = 'Y' and incomingRefDetailT_TestID = T_OrderDetailT_TestID";
$qry = $this->db->query($sql, array($note,$val_note,$val_note_int));
if ($qry) {
$rows = $qry->result_array();
$param = json_encode($rows);
//insert to
$sql = "insert into tx_branch_status(TxBranchStatusStage, TxBranchStatusM_BranchID,
TxBranchStatusM_BranchIP, TxBranchStatusJson,TxBranchStatusNote )
values (?,?,?,?,?)";
$qry = $this->db->query($sql, array($stage,$branchID, $branchIPAddress, $param, $note));
}
}
if ($s_child_ids!= "0" ) {
$sql = "select
incomingRefT_RefDeliveryOrderID,
incomingRefChildID,
incomingRefChildT_OrderDetailID incomingRefDetailT_OrderDetailID,
'' incomingRefDetailStatus,
T_OrderDetailResult,
T_OrderDetailNat_NormalValueID,
T_OrderDetailVerification,
T_OrderDetailValidation,
T_OrderDetailNote,
? note,
? validation_note,
? validation_note_internal
from incoming_ref_child
join incoming_ref on incomingRefID = incomingRefChildIncomingRefID
and incomingRefChildID in ($s_child_ids)
left join t_orderdetail on incomingRefChildNewT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
and T_OrderDetailIsActive = 'Y' and incomingRefChildT_TestID = T_OrderDetailT_TestID";
$qry = $this->db->query($sql, array($note,$val_note,$val_note_int));
if ($qry) {
$rows = $qry->result_array();
$param = json_encode($rows);
//insert to
$sql = "insert into tx_branch_status(TxBranchStatusStage, TxBranchStatusM_BranchID,
TxBranchStatusM_BranchIP, TxBranchStatusJson,TxBranchStatusNote )
values (?,?,?,?,?)";
$qry = $this->db->query($sql, array($stage,$branchID, $branchIPAddress, $param, $note));
}
}
}
public function update($stage,$orderDetailID,$username)
{
$CI =& get_instance();
$this->db = $CI->load->database("onedev",true);
$sql = "select T_OrderDetailT_TestID, T_OrderDetailT_OrderHeaderID
from
t_orderdetail
where T_OrderDetailID = ? ";
$qry = $this->db->query($sql, array($orderDetailID));
$incomingRefID = 0;
$incomingRefDetailID = 0;
$flag_child = false;
if ($qry) {
$rows = $qry->result_array();
$flag_found = false;
if(count($rows) > 0 ) {
$headerID = $rows[0]["T_OrderDetailT_OrderHeaderID"];
$testID = $rows[0]["T_OrderDetailT_TestID"];
$sql = "select incomingRefDetailID , incomingRefDetailIncomingRefID
from incoming_ref_detail
where incomingRefDetailNewT_OrderHeaderID = ?
and incomingRefDetailT_TestID = ?";
$qryd = $this->db->query($sql, array($headerID,$testID));
if($qryd) {
$rowsd = $qryd->result_array();
if ( count($rowsd) > 0 ) {
$incomingRefID = $rowsd[0]["incomingRefDetailIncomingRefID"];
$incomingRefDetailID = $rowsd[0]["incomingRefDetailID"];
$flag_found = true;
}
}
//check child
if(! $flag_found ) {
$sql = "select incomingRefChildID , incomingRefChildIncomingRefID
from incoming_ref_child
where incomingRefChildNewT_OrderHeaderID = ?
and incomingRefChildT_TestID = ?";
$qryd = $this->db->query($sql, array($headerID,$testID));
if($qryd) {
$rowsd = $qryd->result_array();
if ( count($rowsd) > 0 ) {
$incomingRefID = $rowsd[0]["incomingRefChildIncomingRefID"];
$incomingRefDetailID = $rowsd[0]["incomingRefChildID"];
$flag_found = true;
$flag_child = true;
}
}
}
}
}
if ($incomingRefDetailID == 0 || $incomingRefDetailID == "") {
return false;
}
$sql = "select M_BranchID, M_BranchIPAddress
from m_branch
join incoming_ref
on M_BranchID = incomingRefM_BranchID
where incomingRefID = ?";
$qry = $this->db->query($sql, array($incomingRefID));
$branchID = 0;
if ($qry) {
$rows = $qry->result_array();
if(count($rows)>0) {
$branchID = $rows[0]["M_BranchID"];
$branchIPAddress = $rows[0]["M_BranchIPAddress"];
}
}
if ($branchID == 0 ) {
return false;
}
$val_note = "";
$val_note_int = "";
if ($headerID > 0 ) {
$sql = "select T_OrderHeaderAddOnValidationNote, T_OrderHeaderAddOnValidationInternal
from t_orderheaderaddon
where T_orderHeaderAddOnT_OrderHeaderID = ?";
$qry = $this->db->query($sql,array($headerID));
if ($qry) {
$rows = $qry->result_array();
if (count($rows) > 0 ) {
$val_note = $rows[0]["T_OrderHeaderAddOnValidationNote"];
$val_note_int = $rows[0]["T_OrderHeaderAddOnValidationInternal"];
if ( $val_note == null ) $val_note = "";
if ( $val_note_int == null ) $val_note_int = "";
}
}
}
$note = "$stage by $username";
$sql = "select
incomingRefT_RefDeliveryOrderID,
incomingRefDetailID,
incomingRefDetailT_OrderDetailID,
incomingRefDetailStatus,
T_OrderDetailResult,
T_OrderDetailNat_NormalValueID,
T_OrderDetailVerification,
T_OrderDetailValidation,
T_OrderDetailNote,
? note,
? validation_note,
? validation_note_internal
from incoming_ref_detail
join incoming_ref on incomingRefID = incomingRefDetailIncomingRefID
and incomingRefDetailID = ?
left join t_orderdetail on incomingRefDetailNewT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
and T_OrderDetailIsActive = 'Y' and incomingRefDetailT_TestID = T_OrderDetailT_TestID";
if ($flag_child ) {
$sql = "select
incomingRefT_RefDeliveryOrderID,
incomingRefChildID,
incomingRefChildT_OrderDetailID incomingRefDetailT_OrderDetailID,
'' incomingRefDetailStatus,
T_OrderDetailResult,
T_OrderDetailNat_NormalValueID,
T_OrderDetailVerification,
T_OrderDetailValidation,
T_OrderDetailNote,
? note,
? validation_note,
? validation_note_internal
from incoming_ref_child
join incoming_ref on incomingRefID = incomingRefChildIncomingRefID
and incomingRefChildID = ?
left join t_orderdetail on incomingRefChildNewT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
and T_OrderDetailIsActive = 'Y' and incomingRefChildT_TestID = T_OrderDetailT_TestID";
}
$qry = $this->db->query($sql, array($note, $val_note, $val_note_int, $incomingRefDetailID));
if ($qry) {
$rows = $qry->result_array();
$param = json_encode($rows);
//insert to
$sql = "insert into tx_branch_status(TxBranchStatusStage, TxBranchStatusM_BranchID,
TxBranchStatusM_BranchIP, TxBranchStatusJson,TxBranchStatusNote )
values (?,?,?,?,?)";
$qry = $this->db->query($sql, array($stage,$branchID, $branchIPAddress, $param, $note));
}
}
}

View File

@@ -0,0 +1,296 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class TxBranchStatus{
public function update_multi($stage,$ids ,$username)
{
$CI =& get_instance();
$this->db = $CI->load->database("onedev",true);
$s_ids = join(",",$ids);
$sql = "select T_OrderDetailT_TestID, T_OrderDetailT_OrderHeaderID
from
t_orderdetail
where T_OrderDetailID in ($s_ids) ";
$qry = $this->db->query($sql);
$incomingRefID = 0;
$s_detail_ids = "0";
$s_child_ids = "0";
$headerID = 0;
if ($qry) {
$rows = $qry->result_array();
if(count($rows) > 0 ) {
$headerID = $rows[0]["T_OrderDetailT_OrderHeaderID"];
$s_test = "0";
foreach($rows as $r) {
$s_test .= "," . $r["T_OrderDetailT_TestID"];
}
$sql = "select incomingRefDetailID , incomingRefDetailIncomingRefID
from incoming_ref_detail
where incomingRefDetailNewT_OrderHeaderID = ?
and incomingRefDetailT_TestID in ($s_test) ";
$qryd = $this->db->query($sql, array($headerID));
$flag_found = false;
if($qryd) {
$rowsd = $qryd->result_array();
if ( count($rowsd) > 0 ) {
$incomingRefID = $rowsd[0]["incomingRefDetailIncomingRefID"];
foreach($rowsd as $r) {
$s_detail_ids .= "," . $r["incomingRefDetailID"];
}
}
}
//check child
if(! $flag_found ) {
$sql = "select incomingRefChildID , incomingRefChildIncomingRefID
from incoming_ref_child
where incomingRefChildNewT_OrderHeaderID = ?
and incomingRefChildT_TestID in ($s_test) ";
$qryd = $this->db->query($sql, array($headerID));
if($qryd) {
$rowsd = $qryd->result_array();
if ( count($rowsd) > 0 ) {
$incomingRefID = $rowsd[0]["incomingRefChildIncomingRefID"];
foreach($rowsd as $r) {
$s_child_ids .= "," . $r["incomingRefChildID"];
}
}
}
}
}
}
if ($s_detail_ids == "0" && $s_child_ids == "0" ) {
return false;
}
$sql = "select M_BranchID, M_BranchIPAddress
from m_branch
join incoming_ref
on M_BranchID = incomingRefM_BranchID
where incomingRefID = ?";
$qry = $this->db->query($sql, array($incomingRefID));
$branchID = 0;
if ($qry) {
$rows = $qry->result_array();
if(count($rows)>0) {
$branchID = $rows[0]["M_BranchID"];
$branchIPAddress = $rows[0]["M_BranchIPAddress"];
}
}
if ($branchID == 0 ) {
return false;
}
$val_note = "";
$val_note_int = "";
if ($headerID > 0 ) {
$sql = "select T_OrderHeaderAddOnValidationNote, T_OrderHeaderAddOnValidationInternal
from t_orderheaderaddon
where T_orderHeaderAddOnT_OrderHeaderID = ?";
$qry = $this->db->query($sql,array($headerID));
if ($qry) {
$rows = $qry->result_array();
if (count($rows) > 0 ) {
$val_note = $rows[0]["T_OrderHeaderAddOnValidationNote"];
$val_note_int = $rows[0]["T_OrderHeaderAddOnValidationInternal"];
if ( $val_note == null ) $val_note = "";
if ( $val_note_int == null ) $val_note_int = "";
}
}
}
$note = "$stage by $username";
if ($s_detail_ids!= "0" ) {
$sql = "select
incomingRefT_RefDeliveryOrderID,
incomingRefDetailT_OrderDetailID,
incomingRefDetailStatus,
T_OrderDetailResult,
T_OrderDetailNat_NormalValueID,
T_OrderDetailVerification,
T_OrderDetailValidation,
T_OrderDetailNote,
? note,
? validation_note,
? validation_note_internal
from incoming_ref_detail
join incoming_ref on incomingRefID = incomingRefDetailIncomingRefID
and incomingRefDetailID in ($s_detail_ids)
left join t_orderdetail on incomingRefDetailNewT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
and T_OrderDetailIsActive = 'Y' and incomingRefDetailT_TestID = T_OrderDetailT_TestID";
$qry = $this->db->query($sql, array($note,$val_note,$val_note_int));
if ($qry) {
$rows = $qry->result_array();
$param = json_encode($rows);
//insert to
$sql = "insert into tx_branch_status(TxBranchStatusStage, TxBranchStatusM_BranchID,
TxBranchStatusM_BranchIP, TxBranchStatusJson,TxBranchStatusNote )
values (?,?,?,?,?)";
$qry = $this->db->query($sql, array($stage,$branchID, $branchIPAddress, $param, $note));
}
}
if ($s_child_ids!= "0" ) {
$sql = "select
incomingRefT_RefDeliveryOrderID,
incomingRefChildT_OrderDetailID incomingRefDetailT_OrderDetailID,
'' incomingRefDetailStatus,
T_OrderDetailResult,
T_OrderDetailNat_NormalValueID,
T_OrderDetailVerification,
T_OrderDetailValidation,
T_OrderDetailNote,
? note,
? validation_note,
? validation_note_internal
from incoming_ref_child
join incoming_ref on incomingRefID = incomingRefChildIncomingRefID
and incomingRefChildID in ($s_child_ids)
left join t_orderdetail on incomingRefChildNewT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
and T_OrderDetailIsActive = 'Y' and incomingRefChildT_TestID = T_OrderDetailT_TestID";
$qry = $this->db->query($sql, array($note,$val_note,$val_note_int));
if ($qry) {
$rows = $qry->result_array();
$param = json_encode($rows);
//insert to
$sql = "insert into tx_branch_status(TxBranchStatusStage, TxBranchStatusM_BranchID,
TxBranchStatusM_BranchIP, TxBranchStatusJson,TxBranchStatusNote )
values (?,?,?,?,?)";
$qry = $this->db->query($sql, array($stage,$branchID, $branchIPAddress, $param, $note));
}
}
}
public function update($stage,$orderDetailID,$username)
{
$CI =& get_instance();
$this->db = $CI->load->database("onedev",true);
$sql = "select T_OrderDetailT_TestID, T_OrderDetailT_OrderHeaderID
from
t_orderdetail
where T_OrderDetailID = ? ";
$qry = $this->db->query($sql, array($orderDetailID));
$incomingRefID = 0;
$incomingRefDetailID = 0;
$flag_child = false;
if ($qry) {
$rows = $qry->result_array();
$flag_found = false;
if(count($rows) > 0 ) {
$headerID = $rows[0]["T_OrderDetailT_OrderHeaderID"];
$testID = $rows[0]["T_OrderDetailT_TestID"];
$sql = "select incomingRefDetailID , incomingRefDetailIncomingRefID
from incoming_ref_detail
where incomingRefDetailNewT_OrderHeaderID = ?
and incomingRefDetailT_TestID = ?";
$qryd = $this->db->query($sql, array($headerID,$testID));
if($qryd) {
$rowsd = $qryd->result_array();
if ( count($rowsd) > 0 ) {
$incomingRefID = $rowsd[0]["incomingRefDetailIncomingRefID"];
$incomingRefDetailID = $rowsd[0]["incomingRefDetailID"];
$flag_found = true;
}
}
//check child
if(! $flag_found ) {
$sql = "select incomingRefChildID , incomingRefChildIncomingRefID
from incoming_ref_child
where incomingRefChildNewT_OrderHeaderID = ?
and incomingRefChildT_TestID = ?";
$qryd = $this->db->query($sql, array($headerID,$testID));
if($qryd) {
$rowsd = $qryd->result_array();
if ( count($rowsd) > 0 ) {
$incomingRefID = $rowsd[0]["incomingRefChildIncomingRefID"];
$incomingRefDetailID = $rowsd[0]["incomingRefChildID"];
$flag_found = true;
$flag_child = true;
}
}
}
}
}
if ($incomingRefDetailID == 0 || $incomingRefDetailID == "") {
return false;
}
$sql = "select M_BranchID, M_BranchIPAddress
from m_branch
join incoming_ref
on M_BranchID = incomingRefM_BranchID
where incomingRefID = ?";
$qry = $this->db->query($sql, array($incomingRefID));
$branchID = 0;
if ($qry) {
$rows = $qry->result_array();
if(count($rows)>0) {
$branchID = $rows[0]["M_BranchID"];
$branchIPAddress = $rows[0]["M_BranchIPAddress"];
}
}
if ($branchID == 0 ) {
return false;
}
$val_note = "";
$val_note_int = "";
if ($headerID > 0 ) {
$sql = "select T_OrderHeaderAddOnValidationNote, T_OrderHeaderAddOnValidationInternal
from t_orderheaderaddon
where T_orderHeaderAddOnT_OrderHeaderID = ?";
$qry = $this->db->query($sql,array($headerID));
if ($qry) {
$rows = $qry->result_array();
if (count($rows) > 0 ) {
$val_note = $rows[0]["T_OrderHeaderAddOnValidationNote"];
$val_note_int = $rows[0]["T_OrderHeaderAddOnValidationInternal"];
if ( $val_note == null ) $val_note = "";
if ( $val_note_int == null ) $val_note_int = "";
}
}
}
$note = "$stage by $username";
$sql = "select
incomingRefT_RefDeliveryOrderID,
incomingRefDetailT_OrderDetailID,
incomingRefDetailStatus,
T_OrderDetailResult,
T_OrderDetailNat_NormalValueID,
T_OrderDetailVerification,
T_OrderDetailValidation,
T_OrderDetailNote,
? note,
? validation_note,
? validation_note_internal
from incoming_ref_detail
join incoming_ref on incomingRefID = incomingRefDetailIncomingRefID
and incomingRefDetailID = ?
left join t_orderdetail on incomingRefDetailNewT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
and T_OrderDetailIsActive = 'Y' and incomingRefDetailT_TestID = T_OrderDetailT_TestID";
if ($flag_child ) {
$sql = "select
incomingRefT_RefDeliveryOrderID,
incomingRefChildT_OrderDetailID incomingRefDetailT_OrderDetailID,
'' incomingRefDetailStatus,
T_OrderDetailResult,
T_OrderDetailNat_NormalValueID,
T_OrderDetailVerification,
T_OrderDetailValidation,
T_OrderDetailNote,
? note,
? validation_note,
? validation_note_internal
from incoming_ref_child
join incoming_ref on incomingRefID = incomingRefChildIncomingRefID
and incomingRefChildID = ?
left join t_orderdetail on incomingRefChildNewT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
and T_OrderDetailIsActive = 'Y' and incomingRefChildT_TestID = T_OrderDetailT_TestID";
}
$qry = $this->db->query($sql, array($note, $val_note, $val_note_int, $incomingRefDetailID));
if ($qry) {
$rows = $qry->result_array();
$param = json_encode($rows);
//insert to
$sql = "insert into tx_branch_status(TxBranchStatusStage, TxBranchStatusM_BranchID,
TxBranchStatusM_BranchIP, TxBranchStatusJson,TxBranchStatusNote )
values (?,?,?,?,?)";
$qry = $this->db->query($sql, array($stage,$branchID, $branchIPAddress, $param, $note));
}
}
}

View File

@@ -0,0 +1,63 @@
<?php
include_once BASEPATH . "../vendor/kirim_pesan/ClientV3.php";
use KrmPesan\ClientV3;
class Wa_krmv3
{
var $id_token = "eyJraWQiOiJnUFdURUFqekZLTmFnTGhSa28rbGszeEhRMCtEWm42Z29XcDR1ZEhvV0RZPSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiIyNTJjNGZiYS0xMGFhLTQ1NzUtOTZjYy01ZDBiZjdmMzE0MDQiLCJjb2duaXRvOmdyb3VwcyI6WyJ1c2VyIiwiREVWIzYyODUyMzY4MTEzMzAiXSwiZW1haWxfdmVyaWZpZWQiOnRydWUsImlzcyI6Imh0dHBzOlwvXC9jb2duaXRvLWlkcC5hcC1zb3V0aGVhc3QtMS5hbWF6b25hd3MuY29tXC9hcC1zb3V0aGVhc3QtMV9Fa0M0emJUVXUiLCJjb2duaXRvOnVzZXJuYW1lIjoiMjUyYzRmYmEtMTBhYS00NTc1LTk2Y2MtNWQwYmY3ZjMxNDA0Iiwib3JpZ2luX2p0aSI6ImJjZTcxZTY4LWVhZTYtNGE3MC05ZjA5LTE5MjEyNjFmMWYxNyIsImF1ZCI6IjIybXZnMnNhc2Y5aDZsbTVhdWk4YjByN2pqIiwiZXZlbnRfaWQiOiI3MDMxYjQ0Ni00MjBjLTQ4ZjktOGIzMi1mMGZiMzFlYjUzNzgiLCJ0b2tlbl91c2UiOiJpZCIsImF1dGhfdGltZSI6MTY5ODkxMjk1MiwibmFtZSI6IlByYW1pdGEgTGFiIiwiZXhwIjoxNjk4OTk5MzUyLCJpYXQiOjE2OTg5MTI5NTIsImp0aSI6IjU5NjZhZTVjLTkyZDAtNGYxYS05NzVhLTVhMjFjZjlhNjAxZCIsImVtYWlsIjoiaW5mb0BwcmFtaXRhLmNvLmlkIn0.FrIVco9oW4QSwPWWSpUc-CyNGm3hjoDXtrKECBLdKdbyJsX0Qws48S2AXbQ7gqb8dSLpH4tFUyM5boTOxYR55bc8QuN6hF9n9-1QOFfKGyLA37tSdVE-9bziycIUQ5g0cqBH_3eFebAaeDIIYKr6Tu_bs0ZAuRqvjLqj8mSoDNrDaeOhVLKMfFUwXtesjxkOV0TvV_OFQ4_96Q4Kk3wul7R2mJTuONsDa8u1UgWFVrcmRKYzq_qSs6K5eFD_kekRpZrMkNeC4ch3fvP1ZQ3z2SsNVwvLtpRYdFiEYuV91jYtZC33WR6dOL1d-wUdowNXfdGrQlAHOah2NyDbDuF96Q";
var $refresh_token = "eyJjdHkiOiJKV1QiLCJlbmMiOiJBMjU2R0NNIiwiYWxnIjoiUlNBLU9BRVAifQ.bTjo6WiUaTZjjUohwGi0M52we5pG-yrqauLHRrFrHD5CTItWuFnceFCtt8l-rxwST9jvBC3VqkOvRkP2sA1M-U4jt0LSP1aJl5dTNo2ejxvCRGyvw7Un5ykM1XqvxYWzVrWC5hi-Jf87sJco2myJqjlHAiPiHmH-vvrcdSiMjEnu83jatHmGimQQzZUq6xKjn6UW5Ok0bEKqOJMh3Lo_32WHpH01G1i26Iz35Dn9yKbzL3wam52tuD3pbTA98fYXeMZGOf0jjJAt-Xk2DAOYiKrkqY6nWW8nuqKqT71PUxKDTooB77qd9F1pqmMG_r97pWXMzpIzO5O1w34jb2cymQ.fLP07rW7cC79w1rm.oMv0SEleK1pi4p-FbjmABIc39N8KRRp6l3cTSi1ndmM4wnnjwLbV9XLYpVPZZ9oz2zhZH9p7h3POgUKzazm4raP_pRA-SeyrqKQZa6U5cACeRmRbIdPMXInjACxiyaSD09rwP3_htgIpz0urTzWt9d0zMXdaczORdSPcC-GHtanHPfDVkr-u9dYG2ZYeJmx-u0NIi2OmgnqUiBJmD5gx1LdzFnrmTizrVeAnxA_fB8FF0isHTLUo3imAgGGG9dgYa_dSodqdWpK9rgX5AtVe5NVAzqudACx5KwOfM7EpwLhaLFI-RA4KXB2OQlMAU3TqBvBjt89Gs6AMtBaFxKg3HWxkOiynLX4hV8I4WnEWhYoAN6sOBcuW6h2Dhqxpd9fDYQdS1VqmgZkBrNzMnmcb91F6QmPs5jMqMK2aL7S_T9I9L6y-ci6OCdDmpwlwM5wsiIK7PBdI367sgWE9-oXGvGopiV_e17FJRqLWItnEjPJoel3hr5jcil5LAie4VGBjUOCY50PjP_gRdxdtwrWgBZu48AuNekHGXlQKy_QyOgLK0WAtXBms0_-VvpUyOKVWOt27ExxweayKfDeLpkX8uh-Iy7VXK2tDUVky7EHCZirQccb93Y0hNaxpEqto0fm12RzycHGye0ScbPh1NoeAcqc77lI6-TmtfcBiweDALrUVriQIMRcbnOrQNSBazYMVVQiNsXrsrBs36yqKV60Y5cScG9d7sq83N9ENLM90Q2XYATnLlE_wOMa9WpYNkNo62fMZQZDNCdzRXcnZNjJvAXhxmlqdCpceg_TbbYmOSge6iq2Qz5gprdbsf89cD-EbgqHUfhZlbQ1wZtTcO0DepY4K3jwseF3CXJbksbfNMGLYVjrIRSeCbOoKJ1EcQqVfP56F9kSAvohOQBTrWQU74pJI9S_m_Gzx21y9eJXbM9XNHhguU2ZcmXFOZSZ65-JApQqdao2gNjkfq-WZQwrW-RctUv2XRUV6MJjkIysx3zpnS8r5zmSYqqcj929aAI7LiL7c2VtMgQLJNiw0023LovrgU2QzMGu8dNw790wAwNv7X8C_oMTEk44aKFMaG2MRvjuO6jPv7qRqDIi6igzhk4lJuGA1gYPGFLBu68CdBgpA3FxVtmxJhXDCr4rfgtJ7XY1TWBe_gjqHw3c_FMhLOjBzD25mGC-vWwSdLpwaCrkvz3B73yl0PJXvfl_PQdiW8UzrIRZ-J1KKnBv0n5lEj3W4Ahy6v0IwcYxRdkkUHKu87r_MFNJQlRJiiXeFuHpxb5IVF-Xb6IGj0wxhbCzQKaMX1N91xogecORoUncx1mGl8HuHyflQphtp2fj9mkWf6tEyJcLX5rVD09sbG5QIc2aWZGK7WrVPx7iezEwmVOSGYs6Bb8KJfb33KlsFo0hHMm00VRhGwV2PxgCw1GJX7GzCuWeInkCOL4_7Z3CSwKceu0-FlSFcfFr4OdALzSVMthRg_Jle.tSoFTKWQVTvUfZgSkaTyuQ";
var $device_id = "ap-southeast-1_60ed15bd-eb92-4d89-a5e0-85595ac26530";
var $template = "qrorder";
var $client;
function __construct()
{
$this->client = new ClientV3([
"deviceId" => $this->device_id,
"refreshToken" => $this->refresh_token,
"idToken" => $this->id_token
]);
}
function upload($url)
{
//create tmp file
$fname = tempnam("/tmp", "rpt") . "-rpt.pdf";
file_put_contents($fname, file_get_contents($url));
$resp = $this->client->upload($fname);
unlink($fname);
return $resp;
}
function send_qrcode($phone, $url, $name, $date)
{
$urlImg = $this->upload($url);
$message = [$name, $date];
$resp = $this->client->sendMessageTemplateImage($phone, $this->template, "id", $message, $urlImg);
return json_decode($resp, true);
}
function send_otp($phone, $otp)
{
$resp = $this->client->sendMessageTemplateAuthentication($phone, "pramitamobileotp", "id", $otp);
return json_decode($resp, true);
}
function send_rujukan_external_process($phone, $phone_cabang)
{
$message = [$phone_cabang];
$resp = $this->client->sendMessageTemplateText($phone, "rujukan01", "id", $message);
return json_decode($resp, true);
}
function send_eform($phone, $kode_cabang, $nolab, $type = "")
{
$message = [$kode_cabang, $nolab];
$resp = $this->client->sendMessageTemplateText($phone, "eform_fisik", "id", $message);
return json_decode($resp, true);
}
function send_msg_button($phone, $url)
{
$body = ["hello", "world", "there"];
$resp = $this->client->sendMessageTemplateButton($phone, "sample-message-button", "id", $body, $url);
return json_decode($resp, true);
}
}

View File

@@ -0,0 +1,159 @@
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Wa_sas
{
var $username, $host, $password;
function __construct()
{
// $this->host = "http://sasdev.jala.my.id:3000/send/";
//$this->host = "http://139.59.235.205:3000/send/";
$this->host = "http://devkedungdoro.aplikasi.web.id:7001/send/";
$this->username = "sasdev";
$this->password = "sasdev!#102938";
}
function fix_phone($phone)
{
//remove - and space
$phone = str_replace("-", "", $phone);
$phone = str_replace(" ", "", $phone);
//remove 1st +
if (substr($phone, 0, 1) == "+") {
$phone = substr($phone, 1);
}
if (substr($phone, 0, 1) == "0") {
$phone = "62" . substr($phone, 1);
}
if (substr($phone, 0, 2) != "62") {
$phone = "62" . $phone;
}
return $phone;
}
function send_image_group(
$phone,
$caption,
$url_image,
$contentType,
$file_name,
$extension,
$view_once = false,
$compress = false
) {
$tmpFile = tempnam(sys_get_temp_dir(), 'sasdev') . ".$extension";
file_put_contents($tmpFile, file_get_contents($url_image));
$data = [
"phone" => $phone,
"caption" => $caption,
"view_once" => $view_once,
"compress" => $compress,
"image" => curl_file_create($tmpFile, $contentType, $file_name)
];
$ch = curl_init($this->host . "image");
//curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_USERPWD, $this->username . ":" . $this->password);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
$return = curl_exec($ch);
curl_close($ch);
unlink($tmpFile);
$j_return = json_decode($return, true);
if (json_last_error() != 0) {
return ["code" => "ERROR", "message" => "Error Json Decode : $return"];
}
return $j_return;
}
function send_message($phone, $message, $is_group = false)
{
$data = [
"phone" => $is_group ? $phone : $this->fix_phone($phone),
"message" => $message
];
$ch = curl_init($this->host . "message");
curl_setopt($ch, CURLOPT_USERPWD, $this->username . ":" . $this->password);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$return = curl_exec($ch);
curl_close($ch);
$j_return = json_decode($return, true);
if (json_last_error() != 0) {
return ["code" => "ERROR", "message" => "Error Json Decode : $return"];
}
return $j_return;
}
function send_image(
$phone,
$caption,
$url_image,
$contentType,
$file_name,
$extension,
$view_once = false,
$compress = false
) {
$tmpFile = tempnam(sys_get_temp_dir(), 'sasdev') . ".$extension";
file_put_contents($tmpFile, file_get_contents($url_image));
$data = [
"phone" => $this->fix_phone($phone),
"caption" => $caption,
"view_once" => $view_once,
"compress" => $compress,
"image" => curl_file_create($tmpFile, $contentType, $file_name)
];
$ch = curl_init($this->host . "image");
//curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_USERPWD, $this->username . ":" . $this->password);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
$return = curl_exec($ch);
curl_close($ch);
unlink($tmpFile);
$j_return = json_decode($return, true);
if (json_last_error() != 0) {
return ["code" => "ERROR", "message" => "Error Json Decode : $return"];
}
return $j_return;
}
function send_file(
$phone,
$caption,
$url_file,
$contentType,
$file_name,
$extension,
$compress = false
) {
$tmpFile = tempnam(sys_get_temp_dir(), 'sasdev') . ".$extension";
file_put_contents($tmpFile, file_get_contents($url_file));
$data = [
"phone" => $this->fix_phone($phone),
"caption" => $caption,
"compress" => $compress,
"file" => curl_file_create($tmpFile, $contentType, $file_name)
];
$ch = curl_init($this->host . "file");
//curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_USERPWD, $this->username . ":" . $this->password);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
$return = curl_exec($ch);
curl_close($ch);
unlink($tmpFile);
$j_return = json_decode($return, true);
if (json_last_error() != 0) {
return ["code" => "ERROR", "message" => "Error Json Decode : $return"];
}
return $j_return;
}
}

View File

@@ -0,0 +1,127 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Simrs {
function __construct()
{
$this->HisEndPoint = "http://34.101.132.130:8080/query";
$this->Timeout = 10;
$this->token = "";
$this->userName = "adiet";
$this->password = "qwerty";
}
function get_token() {
if (! file_exists("/tmp/his-token.json")) {
$this->login($this->userName,$this->password);
} else {
$jtoken = file_get_contents("/tmp/his-token.json");
$token = json_decode($jtoken,true);
$expired = $token["expired"];
if ($expired - time() > 180 ) {
return "{$token["token"]}";
} else {
$new_token = $this->login("x");
return $new_token;
}
}
}
function login($debug = "") {
list($is_ok,$enc_password)= $this->gql(
"mutation",
"passwordEncrypt",
["password" => "String!"],
["password" => $this->password],
"",
"",
$debug
);
if(! $is_ok) {
if ($debug != "") echo "Error : {$this->password} => $enc_password\n";
return false;
}
list($is_ok,$tokenResponse)= $this->gql(
"mutation",
"userLogin",
["userName" => "String!", "password" => "String!"],
["userName" => $this->userName, "password" => $enc_password],
"userID token expired",
"",
$debug
);
if(!$is_ok) return false;
file_put_contents("/tmp/his-token.json",json_encode($tokenResponse));
return $tokenResponse["token"];
}
function gql($type, $name, $param, $variable, $return = "",
$token = "",
$debug = "")
{
$prm_gql= "";
$prm_body = "";
foreach($param as $k => $v) {
if ($prm_gql!= "") $prm_gql .= ",";
$prm_gql.= '$' . $k . ":" . $v;
if ($prm_body != "") $prm_body .= ",";
$prm_body .= $k . ":$" . $k;
}
$body = [];
if ($return == "") {
$body["query"] = "{$type}($prm_gql){{$name}($prm_body)}";
} else {
$body["query"] = "{$type}($prm_gql){ {$name}($prm_body){ $return } }";
}
$body["variables"] = $variable;
$gql_body = json_encode($body);
if($debug != "") {
echo "Debug GQL: $gql_body \n";
}
$resp =$this->post($gql_body,$token);
if($debug != "") {
echo "Response GQL: $resp \n";
}
$j_resp = json_decode($resp,true);
if ($j_resp !== false) {
if ($j_resp["data"] != null) {
$result = $j_resp["data"][$name];
if ($debug != "") {
print_r($result);
}
return [true,$result];
} else {
return [false,json_encode($j_resp["error"])];
}
}
return [false,$resp];
}
function post($data,$token = "")
{
$ch = curl_init($this->HisEndPoint);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->Timeout / 2);
curl_setopt($ch, CURLOPT_TIMEOUT, $this->Timeout);
if ($token == "") {
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/json",
"Content-Length: " . strlen($data),
]);
} else {
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer $token",
"Content-Type: application/json",
"Content-Length: " . strlen($data),
]);
}
$result = curl_exec($ch);
if (curl_error($ch) != "") {
return "ERROR SIMRS HIS API {$this->HisEndPoint} : " . curl_error($ch) . "\n";
}
curl_close($ch);
return $result;
}}

View File

@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>