first commit -> move some files from one-api
This commit is contained in:
4
.htaccess
Normal file
4
.htaccess
Normal file
@@ -0,0 +1,4 @@
|
||||
RewriteEngine on
|
||||
RewriteBase /one-api/
|
||||
RewriteCond $1 !^(index\.php|assets|user_guide|robots\.txt)
|
||||
RewriteRule ^(.*)$ /one-api/index.php/$1 [L]
|
||||
294
Timesheet.php
Normal file
294
Timesheet.php
Normal file
@@ -0,0 +1,294 @@
|
||||
<?php
|
||||
require FCPATH . "vendor/ripcord/ripcord.php";
|
||||
require FCPATH . "vendor/ripcord/ripcord_client.php";
|
||||
|
||||
class Odoo extends MY_Controller
|
||||
{
|
||||
var $db_odoo, $url, $username, $uid, $model, $password, $common;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->url = "http://odoo.sismedika.com";
|
||||
$this->db_odoo = "odoo16_sismedika";
|
||||
$this->username = "admin@sismedika.com";
|
||||
$this->password = "duD#Z36qH5ctmRRD";
|
||||
$this->common = ripcord::client("{$this->url}/xmlrpc/2/common");
|
||||
$this->uid = $this->common->authenticate($this->db_odoo, $this->username, $this->password, array());
|
||||
$this->model = ripcord::client("{$this->url}/xmlrpc/2/object");
|
||||
$this->db->query("use one_support");
|
||||
}
|
||||
function get_implementation($project_id = 70, $date = "")
|
||||
{
|
||||
if ($date == "") $date = date("Y-m-d");
|
||||
$sdate = $date . " 00:00:01";
|
||||
$edate = $date . " 23:59:59";
|
||||
$arg = array();
|
||||
$kwarg = array(
|
||||
"limit" => 10,
|
||||
"offset" => 0,
|
||||
"order" => "",
|
||||
"count_limit" => 11,
|
||||
"fields" => [
|
||||
"id",
|
||||
"name",
|
||||
"description",
|
||||
],
|
||||
//"domain"=>[["stage_id","ilike","implementation"]]
|
||||
// "domain"
|
||||
);
|
||||
$resp = $this->model->execute_kw(
|
||||
$this->db_odoo,
|
||||
$this->uid,
|
||||
$this->password,
|
||||
"project.task",
|
||||
"web_search_read",
|
||||
array(array(
|
||||
"&",
|
||||
["display_project_id", "=", $project_id],
|
||||
"&",
|
||||
["date_last_stage_update", ">=", $sdate],
|
||||
"&",
|
||||
["date_last_stage_update", "<=", $edate],
|
||||
["stage_id", "ilike", "implementation"]
|
||||
)),
|
||||
$kwarg
|
||||
);
|
||||
$arr_ticket = [];
|
||||
if (isset($resp["records"])) {
|
||||
foreach ($resp["records"] as $r) {
|
||||
$desc = $r["description"];
|
||||
$name = $r["name"];
|
||||
$id = $r["id"];
|
||||
$tiket = "";
|
||||
if (preg_match("/ No. Tiket : <b>(.+)<\/b><br> Cabang/", $desc, $match)) {
|
||||
$tiket = $match[1];
|
||||
if (in_array($tiket,$arr_ticket)) {
|
||||
echo date("Y-m-d H:i:s") . " Ticket # $tiket duplicate \n";
|
||||
continue;
|
||||
}
|
||||
$arr_ticket[]= $tiket;
|
||||
}
|
||||
if ($tiket != "") {
|
||||
$rec = $this->get_ticketing($tiket);
|
||||
if ($rec["TicketingStatus"] != "IMPLEMENTATION") {
|
||||
$ticketID = $rec["TicketingID"];
|
||||
$sender = $rec["TicketingSender"];
|
||||
$cabang = $rec["M_BranchName"];
|
||||
$hasil = "";
|
||||
if (preg_match("/(Hasil.*:.+)/", $desc, $match)) {
|
||||
$hasil = strip_tags($match[1]);
|
||||
$hasil = str_replace(" ","",$hasil);
|
||||
}
|
||||
$impl_msg = "
|
||||
Pengirim : $sender
|
||||
No. Tiket : $tiket
|
||||
Issue : $name
|
||||
Cabang : $cabang
|
||||
Status : Selesai
|
||||
$hasil
|
||||
|
||||
Silahkan di cek kembali
|
||||
Terima Kasih\n";
|
||||
echo date("Y-m-d H:i:s") . " Done Ticket # $tiket from $sender \n";
|
||||
$this->wa_to_sasone_done($impl_msg);
|
||||
$this->update_ticketing($ticketID, "IMPLEMENTATION", $ticketID);
|
||||
sleep(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function get_message($taskID)
|
||||
{
|
||||
$arg = [
|
||||
"thread_id" => $taskID,
|
||||
"thread_model" => "project_task",
|
||||
"limit" => 30
|
||||
];
|
||||
$resp = $this->model->execute_kw(
|
||||
$this->db_odoo,
|
||||
$this->uid,
|
||||
$this->password,
|
||||
"mail.thread",
|
||||
"read",
|
||||
array($arg)
|
||||
);
|
||||
print_r($resp);
|
||||
}
|
||||
function wa_to_sasone_done(
|
||||
$msg
|
||||
) {
|
||||
$this->load->library("Wa_sas");
|
||||
//$hp = "6287823783747";
|
||||
//$hp="6282113702602-1584412485@g.us";
|
||||
//bisone supporter
|
||||
$hp="6281328282909-1583223560@g.us";
|
||||
$resp = $this->wa_sas->send_message($hp, $msg, true);
|
||||
}
|
||||
function update_ticketing($ticketID, $status, $taskID)
|
||||
{
|
||||
$sql = "update ticketing set TicketingStatus = ?,
|
||||
TicketingOdooTaskID=?
|
||||
where ticketingID = ?";
|
||||
$qry = $this->db->query($sql, [$status, $taskID, $taskID]);
|
||||
if (!$qry) {
|
||||
echo "Error update ticketing $ticketID\n";
|
||||
exit;
|
||||
}
|
||||
echo $this->db->last_query() . "\n";
|
||||
}
|
||||
function get_ticketing($tiket)
|
||||
{
|
||||
$sql = "select TicketingID,TicketingStatus ,
|
||||
M_BranchName, TicketingSender
|
||||
from
|
||||
ticketing
|
||||
join m_branch on TicketingM_BranchCode = M_BranchCode
|
||||
and TicketingNumber = ?
|
||||
";
|
||||
$qry = $this->db->query($sql, [$tiket]);
|
||||
if (!$qry) {
|
||||
echo "Error get ticketing $tiket\n";
|
||||
exit;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "Error get ticketing $tiket\n";
|
||||
exit;
|
||||
}
|
||||
return $rows[0];
|
||||
}
|
||||
function create_ts()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
$date = $prm["date"];
|
||||
$time = $prm["time"];
|
||||
$employee_id = $prm["employee_id"];
|
||||
$task_id = $prm["task_id"];
|
||||
$project_id = $prm["project_id"];
|
||||
$description = $prm["description"];
|
||||
|
||||
$arg = array(
|
||||
"name" => $description,
|
||||
"date" => $date,
|
||||
"unit_amount" => $time,
|
||||
"user_id" => $this->uid,
|
||||
"task_id" => $task_id,
|
||||
"project_id" => $project_id,
|
||||
"employee_id" => $employee_id
|
||||
);
|
||||
|
||||
$resp = $this->model->execute_kw(
|
||||
$this->db_odoo,
|
||||
$this->uid,
|
||||
$this->password,
|
||||
"account.analytic.line",
|
||||
"create",
|
||||
array($arg)
|
||||
);
|
||||
print_r($resp);
|
||||
if (!is_numeric($resp)) {
|
||||
echo json_encode(["status" => "ERR", "message" => json_encode($resp)]);
|
||||
} else {
|
||||
echo json_encode(
|
||||
[
|
||||
"status" => "OK",
|
||||
"ts_id" => $resp
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
function create_task()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
$title = $prm["title"];
|
||||
$description = $prm["description"];
|
||||
$project_id = $prm["project_id"];
|
||||
if ($project_id == "") $project_id = 70;
|
||||
$images = $prm["images"];
|
||||
if (is_array($images)) {
|
||||
foreach ($images as $img) {
|
||||
$description .= "<br/>" .
|
||||
"<img class=\"img-fluid\" src=\"$img\">";
|
||||
}
|
||||
}
|
||||
$users = $prm["users"];
|
||||
if ($users == "") {
|
||||
$users = [
|
||||
44,
|
||||
41,
|
||||
42
|
||||
];
|
||||
}
|
||||
$arg = array(
|
||||
"sun" => $this->bool_day("sun"),
|
||||
"mon" => $this->bool_day("mon"),
|
||||
"tue" => $this->bool_day("tue"),
|
||||
"wed" => $this->bool_day("wed"),
|
||||
"thu" => $this->bool_day("thu"),
|
||||
"fri" => $this->bool_day("fri"),
|
||||
"sat" => $this->bool_day("sat"),
|
||||
"recurrence_id" => false,
|
||||
"parent_id" => false,
|
||||
"company_id" => 1,
|
||||
"stage_id" => 443,
|
||||
"personal_stage_type_id" => false,
|
||||
"recurrence_update" => "this",
|
||||
"priority" => "0",
|
||||
"name" => "$title",
|
||||
"kanban_state" => "normal",
|
||||
"project_id" => $project_id,
|
||||
"display_project_id" => false,
|
||||
"milestone_id" => false,
|
||||
"user_ids" => [
|
||||
[
|
||||
6,
|
||||
false,
|
||||
$users
|
||||
]
|
||||
],
|
||||
"active" => true,
|
||||
"partner_id" => false,
|
||||
"partner_phone" => false,
|
||||
"date_deadline" => false,
|
||||
"tag_ids" => [
|
||||
[
|
||||
6,
|
||||
false,
|
||||
[]
|
||||
]
|
||||
],
|
||||
"task_properties" => [],
|
||||
"description" => $description,
|
||||
"planned_hours" => 0,
|
||||
"timesheet_ids" => [],
|
||||
"child_ids" => [],
|
||||
);
|
||||
$resp = $this->model->execute_kw(
|
||||
$this->db_odoo,
|
||||
$this->uid,
|
||||
$this->password,
|
||||
"project.task",
|
||||
"create",
|
||||
array($arg)
|
||||
);
|
||||
if (!is_numeric($resp)) {
|
||||
echo json_encode(["status" => "ERR", "message" => json_encode($resp)]);
|
||||
} else {
|
||||
echo json_encode(
|
||||
[
|
||||
"status" => "OK",
|
||||
"task_id" => $resp
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
function bool_day($inp_dow)
|
||||
{
|
||||
$dow = strtolower(date("D", strtotime("now")));
|
||||
if ($inp_dow == $dow) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
6
application/.htaccess
Normal file
6
application/.htaccess
Normal file
@@ -0,0 +1,6 @@
|
||||
<IfModule authz_core_module>
|
||||
Require all denied
|
||||
</IfModule>
|
||||
<IfModule !authz_core_module>
|
||||
Deny from all
|
||||
</IfModule>
|
||||
11
application/cache/index.html
vendored
Normal file
11
application/cache/index.html
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
135
application/config/autoload.php
Normal file
135
application/config/autoload.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| AUTO-LOADER
|
||||
| -------------------------------------------------------------------
|
||||
| This file specifies which systems should be loaded by default.
|
||||
|
|
||||
| In order to keep the framework as light-weight as possible only the
|
||||
| absolute minimal resources are loaded by default. For example,
|
||||
| the database is not connected to automatically since no assumption
|
||||
| is made regarding whether you intend to use it. This file lets
|
||||
| you globally define which systems you would like loaded with every
|
||||
| request.
|
||||
|
|
||||
| -------------------------------------------------------------------
|
||||
| Instructions
|
||||
| -------------------------------------------------------------------
|
||||
|
|
||||
| These are the things you can load automatically:
|
||||
|
|
||||
| 1. Packages
|
||||
| 2. Libraries
|
||||
| 3. Drivers
|
||||
| 4. Helper files
|
||||
| 5. Custom config files
|
||||
| 6. Language files
|
||||
| 7. Models
|
||||
|
|
||||
*/
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| Auto-load Packages
|
||||
| -------------------------------------------------------------------
|
||||
| Prototype:
|
||||
|
|
||||
| $autoload['packages'] = array(APPPATH.'third_party', '/usr/local/shared');
|
||||
|
|
||||
*/
|
||||
$autoload['packages'] = array();
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| Auto-load Libraries
|
||||
| -------------------------------------------------------------------
|
||||
| These are the classes located in system/libraries/ or your
|
||||
| application/libraries/ directory, with the addition of the
|
||||
| 'database' library, which is somewhat of a special case.
|
||||
|
|
||||
| Prototype:
|
||||
|
|
||||
| $autoload['libraries'] = array('database', 'email', 'session');
|
||||
|
|
||||
| You can also supply an alternative library name to be assigned
|
||||
| in the controller:
|
||||
|
|
||||
| $autoload['libraries'] = array('user_agent' => 'ua');
|
||||
*/
|
||||
$autoload['libraries'] = array();
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| Auto-load Drivers
|
||||
| -------------------------------------------------------------------
|
||||
| These classes are located in system/libraries/ or in your
|
||||
| application/libraries/ directory, but are also placed inside their
|
||||
| own subdirectory and they extend the CI_Driver_Library class. They
|
||||
| offer multiple interchangeable driver options.
|
||||
|
|
||||
| Prototype:
|
||||
|
|
||||
| $autoload['drivers'] = array('cache');
|
||||
|
|
||||
| You can also supply an alternative property name to be assigned in
|
||||
| the controller:
|
||||
|
|
||||
| $autoload['drivers'] = array('cache' => 'cch');
|
||||
|
|
||||
*/
|
||||
$autoload['drivers'] = array();
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| Auto-load Helper Files
|
||||
| -------------------------------------------------------------------
|
||||
| Prototype:
|
||||
|
|
||||
| $autoload['helper'] = array('url', 'file');
|
||||
*/
|
||||
$autoload['helper'] = array();
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| Auto-load Config files
|
||||
| -------------------------------------------------------------------
|
||||
| Prototype:
|
||||
|
|
||||
| $autoload['config'] = array('config1', 'config2');
|
||||
|
|
||||
| NOTE: This item is intended for use ONLY if you have created custom
|
||||
| config files. Otherwise, leave it blank.
|
||||
|
|
||||
*/
|
||||
$autoload['config'] = array();
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| Auto-load Language files
|
||||
| -------------------------------------------------------------------
|
||||
| Prototype:
|
||||
|
|
||||
| $autoload['language'] = array('lang1', 'lang2');
|
||||
|
|
||||
| NOTE: Do not include the "_lang" part of your file. For example
|
||||
| "codeigniter_lang.php" would be referenced as array('codeigniter');
|
||||
|
|
||||
*/
|
||||
$autoload['language'] = array();
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| Auto-load Models
|
||||
| -------------------------------------------------------------------
|
||||
| Prototype:
|
||||
|
|
||||
| $autoload['model'] = array('first_model', 'second_model');
|
||||
|
|
||||
| You can also supply an alternative model name to be assigned
|
||||
| in the controller:
|
||||
|
|
||||
| $autoload['model'] = array('first_model' => 'first');
|
||||
*/
|
||||
$autoload['model'] = array();
|
||||
523
application/config/config.php
Normal file
523
application/config/config.php
Normal file
@@ -0,0 +1,523 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Base Site URL
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| URL to your CodeIgniter root. Typically this will be your base URL,
|
||||
| WITH a trailing slash:
|
||||
|
|
||||
| http://example.com/
|
||||
|
|
||||
| WARNING: You MUST set this value!
|
||||
|
|
||||
| If it is not set, then CodeIgniter will try guess the protocol and path
|
||||
| your installation, but due to security concerns the hostname will be set
|
||||
| to $_SERVER['SERVER_ADDR'] if available, or localhost otherwise.
|
||||
| The auto-detection mechanism exists only for convenience during
|
||||
| development and MUST NOT be used in production!
|
||||
|
|
||||
| If you need to allow multiple domains, remember that this file is still
|
||||
| a PHP script and you can easily do that on your own.
|
||||
|
|
||||
*/
|
||||
$config['base_url'] = '';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Index File
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Typically this will be your index.php file, unless you've renamed it to
|
||||
| something else. If you are using mod_rewrite to remove the page set this
|
||||
| variable so that it is blank.
|
||||
|
|
||||
*/
|
||||
$config['index_page'] = 'index.php';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| URI PROTOCOL
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This item determines which server global should be used to retrieve the
|
||||
| URI string. The default setting of 'REQUEST_URI' works for most servers.
|
||||
| If your links do not seem to work, try one of the other delicious flavors:
|
||||
|
|
||||
| 'REQUEST_URI' Uses $_SERVER['REQUEST_URI']
|
||||
| 'QUERY_STRING' Uses $_SERVER['QUERY_STRING']
|
||||
| 'PATH_INFO' Uses $_SERVER['PATH_INFO']
|
||||
|
|
||||
| WARNING: If you set this to 'PATH_INFO', URIs will always be URL-decoded!
|
||||
*/
|
||||
$config['uri_protocol'] = 'REQUEST_URI';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| URL suffix
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option allows you to add a suffix to all URLs generated by CodeIgniter.
|
||||
| For more information please see the user guide:
|
||||
|
|
||||
| https://codeigniter.com/user_guide/general/urls.html
|
||||
*/
|
||||
$config['url_suffix'] = '';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Language
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This determines which set of language files should be used. Make sure
|
||||
| there is an available translation if you intend to use something other
|
||||
| than english.
|
||||
|
|
||||
*/
|
||||
$config['language'] = 'english';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Character Set
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This determines which character set is used by default in various methods
|
||||
| that require a character set to be provided.
|
||||
|
|
||||
| See http://php.net/htmlspecialchars for a list of supported charsets.
|
||||
|
|
||||
*/
|
||||
$config['charset'] = 'UTF-8';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Enable/Disable System Hooks
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| If you would like to use the 'hooks' feature you must enable it by
|
||||
| setting this variable to TRUE (boolean). See the user guide for details.
|
||||
|
|
||||
*/
|
||||
$config['enable_hooks'] = FALSE;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Class Extension Prefix
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This item allows you to set the filename/classname prefix when extending
|
||||
| native libraries. For more information please see the user guide:
|
||||
|
|
||||
| https://codeigniter.com/user_guide/general/core_classes.html
|
||||
| https://codeigniter.com/user_guide/general/creating_libraries.html
|
||||
|
|
||||
*/
|
||||
$config['subclass_prefix'] = 'MY_';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Composer auto-loading
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Enabling this setting will tell CodeIgniter to look for a Composer
|
||||
| package auto-loader script in application/vendor/autoload.php.
|
||||
|
|
||||
| $config['composer_autoload'] = TRUE;
|
||||
|
|
||||
| Or if you have your vendor/ directory located somewhere else, you
|
||||
| can opt to set a specific path as well:
|
||||
|
|
||||
| $config['composer_autoload'] = '/path/to/vendor/autoload.php';
|
||||
|
|
||||
| For more information about Composer, please visit http://getcomposer.org/
|
||||
|
|
||||
| Note: This will NOT disable or override the CodeIgniter-specific
|
||||
| autoloading (application/config/autoload.php)
|
||||
*/
|
||||
$config['composer_autoload'] = false;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Allowed URL Characters
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This lets you specify which characters are permitted within your URLs.
|
||||
| When someone tries to submit a URL with disallowed characters they will
|
||||
| get a warning message.
|
||||
|
|
||||
| As a security measure you are STRONGLY encouraged to restrict URLs to
|
||||
| as few characters as possible. By default only these are allowed: a-z 0-9~%.:_-
|
||||
|
|
||||
| Leave blank to allow all characters -- but only if you are insane.
|
||||
|
|
||||
| The configured value is actually a regular expression character group
|
||||
| and it will be executed as: ! preg_match('/^[<permitted_uri_chars>]+$/i
|
||||
|
|
||||
| DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!!
|
||||
|
|
||||
*/
|
||||
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Enable Query Strings
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| By default CodeIgniter uses search-engine friendly segment based URLs:
|
||||
| example.com/who/what/where/
|
||||
|
|
||||
| You can optionally enable standard query string based URLs:
|
||||
| example.com?who=me&what=something&where=here
|
||||
|
|
||||
| Options are: TRUE or FALSE (boolean)
|
||||
|
|
||||
| The other items let you set the query string 'words' that will
|
||||
| invoke your controllers and its functions:
|
||||
| example.com/index.php?c=controller&m=function
|
||||
|
|
||||
| Please note that some of the helpers won't work as expected when
|
||||
| this feature is enabled, since CodeIgniter is designed primarily to
|
||||
| use segment based URLs.
|
||||
|
|
||||
*/
|
||||
$config['enable_query_strings'] = FALSE;
|
||||
$config['controller_trigger'] = 'c';
|
||||
$config['function_trigger'] = 'm';
|
||||
$config['directory_trigger'] = 'd';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Allow $_GET array
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| By default CodeIgniter enables access to the $_GET array. If for some
|
||||
| reason you would like to disable it, set 'allow_get_array' to FALSE.
|
||||
|
|
||||
| WARNING: This feature is DEPRECATED and currently available only
|
||||
| for backwards compatibility purposes!
|
||||
|
|
||||
*/
|
||||
$config['allow_get_array'] = TRUE;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Error Logging Threshold
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| You can enable error logging by setting a threshold over zero. The
|
||||
| threshold determines what gets logged. Threshold options are:
|
||||
|
|
||||
| 0 = Disables logging, Error logging TURNED OFF
|
||||
| 1 = Error Messages (including PHP errors)
|
||||
| 2 = Debug Messages
|
||||
| 3 = Informational Messages
|
||||
| 4 = All Messages
|
||||
|
|
||||
| You can also pass an array with threshold levels to show individual error types
|
||||
|
|
||||
| array(2) = Debug Messages, without Error Messages
|
||||
|
|
||||
| For a live site you'll usually only enable Errors (1) to be logged otherwise
|
||||
| your log files will fill up very fast.
|
||||
|
|
||||
*/
|
||||
$config['log_threshold'] = 0;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Error Logging Directory Path
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Leave this BLANK unless you would like to set something other than the default
|
||||
| application/logs/ directory. Use a full server path with trailing slash.
|
||||
|
|
||||
*/
|
||||
$config['log_path'] = '';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Log File Extension
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The default filename extension for log files. The default 'php' allows for
|
||||
| protecting the log files via basic scripting, when they are to be stored
|
||||
| under a publicly accessible directory.
|
||||
|
|
||||
| Note: Leaving it blank will default to 'php'.
|
||||
|
|
||||
*/
|
||||
$config['log_file_extension'] = '';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Log File Permissions
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The file system permissions to be applied on newly created log files.
|
||||
|
|
||||
| IMPORTANT: This MUST be an integer (no quotes) and you MUST use octal
|
||||
| integer notation (i.e. 0700, 0644, etc.)
|
||||
*/
|
||||
$config['log_file_permissions'] = 0644;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Date Format for Logs
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Each item that is logged has an associated date. You can use PHP date
|
||||
| codes to set your own date formatting
|
||||
|
|
||||
*/
|
||||
$config['log_date_format'] = 'Y-m-d H:i:s';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Error Views Directory Path
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Leave this BLANK unless you would like to set something other than the default
|
||||
| application/views/errors/ directory. Use a full server path with trailing slash.
|
||||
|
|
||||
*/
|
||||
$config['error_views_path'] = '';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cache Directory Path
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Leave this BLANK unless you would like to set something other than the default
|
||||
| application/cache/ directory. Use a full server path with trailing slash.
|
||||
|
|
||||
*/
|
||||
$config['cache_path'] = '';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cache Include Query String
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Whether to take the URL query string into consideration when generating
|
||||
| output cache files. Valid options are:
|
||||
|
|
||||
| FALSE = Disabled
|
||||
| TRUE = Enabled, take all query parameters into account.
|
||||
| Please be aware that this may result in numerous cache
|
||||
| files generated for the same page over and over again.
|
||||
| array('q') = Enabled, but only take into account the specified list
|
||||
| of query parameters.
|
||||
|
|
||||
*/
|
||||
$config['cache_query_string'] = FALSE;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Encryption Key
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| If you use the Encryption class, you must set an encryption key.
|
||||
| See the user guide for more info.
|
||||
|
|
||||
| https://codeigniter.com/user_guide/libraries/encryption.html
|
||||
|
|
||||
*/
|
||||
$config['encryption_key'] = '';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Variables
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| 'sess_driver'
|
||||
|
|
||||
| The storage driver to use: files, database, redis, memcached
|
||||
|
|
||||
| 'sess_cookie_name'
|
||||
|
|
||||
| The session cookie name, must contain only [0-9a-z_-] characters
|
||||
|
|
||||
| 'sess_expiration'
|
||||
|
|
||||
| The number of SECONDS you want the session to last.
|
||||
| Setting to 0 (zero) means expire when the browser is closed.
|
||||
|
|
||||
| 'sess_save_path'
|
||||
|
|
||||
| The location to save sessions to, driver dependent.
|
||||
|
|
||||
| For the 'files' driver, it's a path to a writable directory.
|
||||
| WARNING: Only absolute paths are supported!
|
||||
|
|
||||
| For the 'database' driver, it's a table name.
|
||||
| Please read up the manual for the format with other session drivers.
|
||||
|
|
||||
| IMPORTANT: You are REQUIRED to set a valid save path!
|
||||
|
|
||||
| 'sess_match_ip'
|
||||
|
|
||||
| Whether to match the user's IP address when reading the session data.
|
||||
|
|
||||
| WARNING: If you're using the database driver, don't forget to update
|
||||
| your session table's PRIMARY KEY when changing this setting.
|
||||
|
|
||||
| 'sess_time_to_update'
|
||||
|
|
||||
| How many seconds between CI regenerating the session ID.
|
||||
|
|
||||
| 'sess_regenerate_destroy'
|
||||
|
|
||||
| Whether to destroy session data associated with the old session ID
|
||||
| when auto-regenerating the session ID. When set to FALSE, the data
|
||||
| will be later deleted by the garbage collector.
|
||||
|
|
||||
| Other session cookie settings are shared with the rest of the application,
|
||||
| except for 'cookie_prefix' and 'cookie_httponly', which are ignored here.
|
||||
|
|
||||
*/
|
||||
$config['sess_driver'] = 'files';
|
||||
$config['sess_cookie_name'] = 'ci_session';
|
||||
$config['sess_expiration'] = 7200;
|
||||
$config['sess_save_path'] = NULL;
|
||||
$config['sess_match_ip'] = FALSE;
|
||||
$config['sess_time_to_update'] = 300;
|
||||
$config['sess_regenerate_destroy'] = FALSE;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cookie Related Variables
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| 'cookie_prefix' = Set a cookie name prefix if you need to avoid collisions
|
||||
| 'cookie_domain' = Set to .your-domain.com for site-wide cookies
|
||||
| 'cookie_path' = Typically will be a forward slash
|
||||
| 'cookie_secure' = Cookie will only be set if a secure HTTPS connection exists.
|
||||
| 'cookie_httponly' = Cookie will only be accessible via HTTP(S) (no javascript)
|
||||
|
|
||||
| Note: These settings (with the exception of 'cookie_prefix' and
|
||||
| 'cookie_httponly') will also affect sessions.
|
||||
|
|
||||
*/
|
||||
$config['cookie_prefix'] = '';
|
||||
$config['cookie_domain'] = '';
|
||||
$config['cookie_path'] = '/';
|
||||
$config['cookie_secure'] = FALSE;
|
||||
$config['cookie_httponly'] = FALSE;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Standardize newlines
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Determines whether to standardize newline characters in input data,
|
||||
| meaning to replace \r\n, \r, \n occurrences with the PHP_EOL value.
|
||||
|
|
||||
| WARNING: This feature is DEPRECATED and currently available only
|
||||
| for backwards compatibility purposes!
|
||||
|
|
||||
*/
|
||||
$config['standardize_newlines'] = FALSE;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Global XSS Filtering
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Determines whether the XSS filter is always active when GET, POST or
|
||||
| COOKIE data is encountered
|
||||
|
|
||||
| WARNING: This feature is DEPRECATED and currently available only
|
||||
| for backwards compatibility purposes!
|
||||
|
|
||||
*/
|
||||
$config['global_xss_filtering'] = FALSE;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cross Site Request Forgery
|
||||
|--------------------------------------------------------------------------
|
||||
| Enables a CSRF cookie token to be set. When set to TRUE, token will be
|
||||
| checked on a submitted form. If you are accepting user data, it is strongly
|
||||
| recommended CSRF protection be enabled.
|
||||
|
|
||||
| 'csrf_token_name' = The token name
|
||||
| 'csrf_cookie_name' = The cookie name
|
||||
| 'csrf_expire' = The number in seconds the token should expire.
|
||||
| 'csrf_regenerate' = Regenerate token on every submission
|
||||
| 'csrf_exclude_uris' = Array of URIs which ignore CSRF checks
|
||||
*/
|
||||
$config['csrf_protection'] = FALSE;
|
||||
$config['csrf_token_name'] = 'csrf_test_name';
|
||||
$config['csrf_cookie_name'] = 'csrf_cookie_name';
|
||||
$config['csrf_expire'] = 7200;
|
||||
$config['csrf_regenerate'] = TRUE;
|
||||
$config['csrf_exclude_uris'] = array();
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Output Compression
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Enables Gzip output compression for faster page loads. When enabled,
|
||||
| the output class will test whether your server supports Gzip.
|
||||
| Even if it does, however, not all browsers support compression
|
||||
| so enable only if you are reasonably sure your visitors can handle it.
|
||||
|
|
||||
| Only used if zlib.output_compression is turned off in your php.ini.
|
||||
| Please do not use it together with httpd-level output compression.
|
||||
|
|
||||
| VERY IMPORTANT: If you are getting a blank page when compression is enabled it
|
||||
| means you are prematurely outputting something to your browser. It could
|
||||
| even be a line of whitespace at the end of one of your scripts. For
|
||||
| compression to work, nothing can be sent before the output buffer is called
|
||||
| by the output class. Do not 'echo' any values with compression enabled.
|
||||
|
|
||||
*/
|
||||
$config['compress_output'] = FALSE;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Master Time Reference
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Options are 'local' or any PHP supported timezone. This preference tells
|
||||
| the system whether to use your server's local time as the master 'now'
|
||||
| reference, or convert it to the configured one timezone. See the 'date
|
||||
| helper' page of the user guide for information regarding date handling.
|
||||
|
|
||||
*/
|
||||
$config['time_reference'] = 'local';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Rewrite PHP Short Tags
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| If your PHP installation does not have short tag support enabled CI
|
||||
| can rewrite the tags on-the-fly, enabling you to utilize that syntax
|
||||
| in your view files. Options are TRUE or FALSE (boolean)
|
||||
|
|
||||
| Note: You need to have eval() enabled for this to work.
|
||||
|
|
||||
*/
|
||||
$config['rewrite_short_tags'] = FALSE;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Reverse Proxy IPs
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| If your server is behind a reverse proxy, you must whitelist the proxy
|
||||
| IP addresses from which CodeIgniter should trust headers such as
|
||||
| HTTP_X_FORWARDED_FOR and HTTP_CLIENT_IP in order to properly identify
|
||||
| the visitor's IP address.
|
||||
|
|
||||
| You can use both an array or a comma-separated list of proxy addresses,
|
||||
| as well as specifying whole subnets. Here are a few examples:
|
||||
|
|
||||
| Comma-separated: '10.0.1.200,192.168.5.0/24'
|
||||
| Array: array('10.0.1.200', '192.168.5.0/24')
|
||||
*/
|
||||
$config['proxy_ips'] = '';
|
||||
85
application/config/constants.php
Normal file
85
application/config/constants.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Display Debug backtrace
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| If set to TRUE, a backtrace will be displayed along with php errors. If
|
||||
| error_reporting is disabled, the backtrace will not display, regardless
|
||||
| of this setting
|
||||
|
|
||||
*/
|
||||
defined('SHOW_DEBUG_BACKTRACE') OR define('SHOW_DEBUG_BACKTRACE', TRUE);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| File and Directory Modes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These prefs are used when checking and setting modes when working
|
||||
| with the file system. The defaults are fine on servers with proper
|
||||
| security, but you may wish (or even need) to change the values in
|
||||
| certain environments (Apache running a separate process for each
|
||||
| user, PHP under CGI with Apache suEXEC, etc.). Octal values should
|
||||
| always be used to set the mode correctly.
|
||||
|
|
||||
*/
|
||||
defined('FILE_READ_MODE') OR define('FILE_READ_MODE', 0644);
|
||||
defined('FILE_WRITE_MODE') OR define('FILE_WRITE_MODE', 0666);
|
||||
defined('DIR_READ_MODE') OR define('DIR_READ_MODE', 0755);
|
||||
defined('DIR_WRITE_MODE') OR define('DIR_WRITE_MODE', 0755);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| File Stream Modes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These modes are used when working with fopen()/popen()
|
||||
|
|
||||
*/
|
||||
defined('FOPEN_READ') OR define('FOPEN_READ', 'rb');
|
||||
defined('FOPEN_READ_WRITE') OR define('FOPEN_READ_WRITE', 'r+b');
|
||||
defined('FOPEN_WRITE_CREATE_DESTRUCTIVE') OR define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb'); // truncates existing file data, use with care
|
||||
defined('FOPEN_READ_WRITE_CREATE_DESTRUCTIVE') OR define('FOPEN_READ_WRITE_CREATE_DESTRUCTIVE', 'w+b'); // truncates existing file data, use with care
|
||||
defined('FOPEN_WRITE_CREATE') OR define('FOPEN_WRITE_CREATE', 'ab');
|
||||
defined('FOPEN_READ_WRITE_CREATE') OR define('FOPEN_READ_WRITE_CREATE', 'a+b');
|
||||
defined('FOPEN_WRITE_CREATE_STRICT') OR define('FOPEN_WRITE_CREATE_STRICT', 'xb');
|
||||
defined('FOPEN_READ_WRITE_CREATE_STRICT') OR define('FOPEN_READ_WRITE_CREATE_STRICT', 'x+b');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Exit Status Codes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Used to indicate the conditions under which the script is exit()ing.
|
||||
| While there is no universal standard for error codes, there are some
|
||||
| broad conventions. Three such conventions are mentioned below, for
|
||||
| those who wish to make use of them. The CodeIgniter defaults were
|
||||
| chosen for the least overlap with these conventions, while still
|
||||
| leaving room for others to be defined in future versions and user
|
||||
| applications.
|
||||
|
|
||||
| The three main conventions used for determining exit status codes
|
||||
| are as follows:
|
||||
|
|
||||
| Standard C/C++ Library (stdlibc):
|
||||
| http://www.gnu.org/software/libc/manual/html_node/Exit-Status.html
|
||||
| (This link also contains other GNU-specific conventions)
|
||||
| BSD sysexits.h:
|
||||
| http://www.gsp.com/cgi-bin/man.cgi?section=3&topic=sysexits
|
||||
| Bash scripting:
|
||||
| http://tldp.org/LDP/abs/html/exitcodes.html
|
||||
|
|
||||
*/
|
||||
defined('EXIT_SUCCESS') OR define('EXIT_SUCCESS', 0); // no errors
|
||||
defined('EXIT_ERROR') OR define('EXIT_ERROR', 1); // generic error
|
||||
defined('EXIT_CONFIG') OR define('EXIT_CONFIG', 3); // configuration error
|
||||
defined('EXIT_UNKNOWN_FILE') OR define('EXIT_UNKNOWN_FILE', 4); // file not found
|
||||
defined('EXIT_UNKNOWN_CLASS') OR define('EXIT_UNKNOWN_CLASS', 5); // unknown class
|
||||
defined('EXIT_UNKNOWN_METHOD') OR define('EXIT_UNKNOWN_METHOD', 6); // unknown class member
|
||||
defined('EXIT_USER_INPUT') OR define('EXIT_USER_INPUT', 7); // invalid user input
|
||||
defined('EXIT_DATABASE') OR define('EXIT_DATABASE', 8); // database error
|
||||
defined('EXIT__AUTO_MIN') OR define('EXIT__AUTO_MIN', 9); // lowest automatically-assigned error code
|
||||
defined('EXIT__AUTO_MAX') OR define('EXIT__AUTO_MAX', 125); // highest automatically-assigned error code
|
||||
185
application/config/database-mcu.php
Normal file
185
application/config/database-mcu.php
Normal file
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| DATABASE CONNECTIVITY SETTINGS
|
||||
| -------------------------------------------------------------------
|
||||
| This file will contain the settings needed to access your database.
|
||||
|
|
||||
| For complete instructions please consult the 'Database Connection'
|
||||
| page of the User Guide.
|
||||
|
|
||||
| -------------------------------------------------------------------
|
||||
| EXPLANATION OF VARIABLES
|
||||
| -------------------------------------------------------------------
|
||||
|
|
||||
| ['dsn'] The full DSN string describe a connection to the database.
|
||||
| ['hostname'] The hostname of your database server.
|
||||
| ['username'] The username used to connect to the database
|
||||
| ['password'] The password used to connect to the database
|
||||
| ['database'] The name of the database you want to connect to
|
||||
| ['dbdriver'] The database driver. e.g.: mysqli.
|
||||
| Currently supported:
|
||||
| cubrid, ibase, mssql, mysql, mysqli, oci8,
|
||||
| odbc, pdo, postgre, sqlite, sqlite3, sqlsrv
|
||||
| ['dbprefix'] You can add an optional prefix, which will be added
|
||||
| to the table name when using the Query Builder class
|
||||
| ['pconnect'] TRUE/FALSE - Whether to use a persistent connection
|
||||
| ['db_debug'] TRUE/FALSE - Whether database errors should be displayed.
|
||||
| ['cache_on'] TRUE/FALSE - Enables/disables query caching
|
||||
| ['cachedir'] The path to the folder where cache files should be stored
|
||||
| ['char_set'] The character set used in communicating with the database
|
||||
| ['dbcollat'] The character collation used in communicating with the database
|
||||
| NOTE: For MySQL and MySQLi databases, this setting is only used
|
||||
| as a backup if your server is running PHP < 5.2.3 or MySQL < 5.0.7
|
||||
| (and in table creation queries made with DB Forge).
|
||||
| There is an incompatibility in PHP with mysql_real_escape_string() which
|
||||
| can make your site vulnerable to SQL injection if you are using a
|
||||
| multi-byte character set and are running versions lower than these.
|
||||
| Sites using Latin-1 or UTF-8 database character set and collation are unaffected.
|
||||
| ['swap_pre'] A default table prefix that should be swapped with the dbprefix
|
||||
| ['encrypt'] Whether or not to use an encrypted connection.
|
||||
|
|
||||
| 'mysql' (deprecated), 'sqlsrv' and 'pdo/sqlsrv' drivers accept TRUE/FALSE
|
||||
| 'mysqli' and 'pdo/mysql' drivers accept an array with the following options:
|
||||
|
|
||||
| 'ssl_key' - Path to the private key file
|
||||
| 'ssl_cert' - Path to the public key certificate file
|
||||
| 'ssl_ca' - Path to the certificate authority file
|
||||
| 'ssl_capath' - Path to a directory containing trusted CA certificates in PEM format
|
||||
| 'ssl_cipher' - List of *allowed* ciphers to be used for the encryption, separated by colons (':')
|
||||
| 'ssl_verify' - TRUE/FALSE; Whether verify the server certificate or not ('mysqli' only)
|
||||
|
|
||||
| ['compress'] Whether or not to use client compression (MySQL only)
|
||||
| ['stricton'] TRUE/FALSE - forces 'Strict Mode' connections
|
||||
| - good for ensuring strict SQL while developing
|
||||
| ['ssl_options'] Used to set various SSL options that can be used when making SSL connections.
|
||||
| ['failover'] array - A array with 0 or more data for connections if the main should fail.
|
||||
| ['save_queries'] TRUE/FALSE - Whether to "save" all executed queries.
|
||||
| NOTE: Disabling this will also effectively disable both
|
||||
| $this->db->last_query() and profiling of DB queries.
|
||||
| When you run a query, with this setting set to TRUE (default),
|
||||
| CodeIgniter will store the SQL statement for debugging purposes.
|
||||
| However, this may cause high memory usage, especially if you run
|
||||
| a lot of SQL queries ... disable this to avoid that problem.
|
||||
|
|
||||
| The $active_group variable lets you choose which connection group to
|
||||
| make active. By default there is only one group (the 'default' group).
|
||||
|
|
||||
| The $query_builder variables lets you determine whether or not to load
|
||||
| the query builder class.
|
||||
*/
|
||||
$active_group = 'default';
|
||||
$query_builder = TRUE;
|
||||
|
||||
$db['default'] = array(
|
||||
'dsn' => '',
|
||||
'hostname' => 'localhost',
|
||||
'username' => 'root',
|
||||
'password' => 'mcupramita123321',
|
||||
'database' => 'one',
|
||||
'dbdriver' => 'mysqli',
|
||||
'dbprefix' => '',
|
||||
'pconnect' => FALSE,
|
||||
'db_debug' => FALSE,
|
||||
'cache_on' => FALSE,
|
||||
'cachedir' => '',
|
||||
'char_set' => 'utf8',
|
||||
'dbcollat' => 'utf8_general_ci',
|
||||
'swap_pre' => '',
|
||||
'encrypt' => FALSE,
|
||||
'compress' => FALSE,
|
||||
'stricton' => FALSE,
|
||||
'failover' => array(),
|
||||
'save_queries' => TRUE
|
||||
);
|
||||
|
||||
|
||||
$db['onedev'] = array(
|
||||
'dsn' => '',
|
||||
'hostname' => 'localhost',
|
||||
'username' => 'root',
|
||||
'password' => 'mcupramita123321',
|
||||
'database' => 'one',
|
||||
'dbdriver' => 'mysqli',
|
||||
'dbprefix' => '',
|
||||
'pconnect' => FALSE,
|
||||
'db_debug' => FALSE,
|
||||
'cache_on' => FALSE,
|
||||
'cachedir' => '',
|
||||
'char_set' => 'utf8',
|
||||
'dbcollat' => 'utf8_general_ci',
|
||||
'swap_pre' => '',
|
||||
'encrypt' => FALSE,
|
||||
'compress' => FALSE,
|
||||
'stricton' => FALSE,
|
||||
'failover' => array(),
|
||||
'save_queries' => TRUE
|
||||
);
|
||||
|
||||
$db['clinicdev'] = array(
|
||||
'dsn' => '',
|
||||
'hostname' => 'localhost',
|
||||
'username' => 'root',
|
||||
'password' => 'mcupramita123321',
|
||||
'database' => 'one_clinic',
|
||||
'dbdriver' => 'mysqli',
|
||||
'dbprefix' => '',
|
||||
'pconnect' => FALSE,
|
||||
'db_debug' => FALSE,
|
||||
'cache_on' => FALSE,
|
||||
'cachedir' => '',
|
||||
'char_set' => 'utf8',
|
||||
'dbcollat' => 'utf8_general_ci',
|
||||
'swap_pre' => '',
|
||||
'encrypt' => FALSE,
|
||||
'compress' => FALSE,
|
||||
'stricton' => FALSE,
|
||||
'failover' => array(),
|
||||
'save_queries' => TRUE
|
||||
);
|
||||
|
||||
$db['antrione'] = array(
|
||||
'dsn' => '',
|
||||
'hostname' => 'localhost',
|
||||
'username' => 'root',
|
||||
'password' => 'mcupramita123321',
|
||||
'database' => 'antrione',
|
||||
'dbdriver' => 'mysqli',
|
||||
'dbprefix' => '',
|
||||
'pconnect' => FALSE,
|
||||
'db_debug' => FALSE,
|
||||
'cache_on' => FALSE,
|
||||
'cachedir' => '',
|
||||
'char_set' => 'utf8',
|
||||
'dbcollat' => 'utf8_general_ci',
|
||||
'swap_pre' => '',
|
||||
'encrypt' => FALSE,
|
||||
'compress' => FALSE,
|
||||
'stricton' => FALSE,
|
||||
'failover' => array(),
|
||||
'save_queries' => TRUE
|
||||
);
|
||||
|
||||
$db['onelog'] = array(
|
||||
'dsn' => '',
|
||||
'hostname' => 'localhost',
|
||||
'username' => 'root',
|
||||
'password' => 'mcupramita123321',
|
||||
'database' => 'one_log',
|
||||
'dbdriver' => 'mysqli',
|
||||
'dbprefix' => '',
|
||||
'pconnect' => FALSE,
|
||||
'db_debug' => FALSE,
|
||||
'cache_on' => FALSE,
|
||||
'cachedir' => '',
|
||||
'char_set' => 'utf8',
|
||||
'dbcollat' => 'utf8_general_ci',
|
||||
'swap_pre' => '',
|
||||
'encrypt' => FALSE,
|
||||
'compress' => FALSE,
|
||||
'stricton' => FALSE,
|
||||
'failover' => array(),
|
||||
'save_queries' => TRUE
|
||||
);
|
||||
1926
application/config/database.php
Normal file
1926
application/config/database.php
Normal file
File diff suppressed because it is too large
Load Diff
24
application/config/doctypes.php
Normal file
24
application/config/doctypes.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
$_doctypes = array(
|
||||
'xhtml11' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
|
||||
'xhtml1-strict' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
|
||||
'xhtml1-trans' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
|
||||
'xhtml1-frame' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
|
||||
'xhtml-basic11' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">',
|
||||
'html5' => '<!DOCTYPE html>',
|
||||
'html4-strict' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
|
||||
'html4-trans' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">',
|
||||
'html4-frame' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">',
|
||||
'mathml1' => '<!DOCTYPE math SYSTEM "http://www.w3.org/Math/DTD/mathml1/mathml.dtd">',
|
||||
'mathml2' => '<!DOCTYPE math PUBLIC "-//W3C//DTD MathML 2.0//EN" "http://www.w3.org/Math/DTD/mathml2/mathml2.dtd">',
|
||||
'svg10' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">',
|
||||
'svg11' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">',
|
||||
'svg11-basic' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Basic//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-basic.dtd">',
|
||||
'svg11-tiny' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Tiny//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny.dtd">',
|
||||
'xhtml-math-svg-xh' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">',
|
||||
'xhtml-math-svg-sh' => '<!DOCTYPE svg:svg PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">',
|
||||
'xhtml-rdfa-1' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">',
|
||||
'xhtml-rdfa-2' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">'
|
||||
);
|
||||
103
application/config/foreign_chars.php
Normal file
103
application/config/foreign_chars.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| Foreign Characters
|
||||
| -------------------------------------------------------------------
|
||||
| This file contains an array of foreign characters for transliteration
|
||||
| conversion used by the Text helper
|
||||
|
|
||||
*/
|
||||
$foreign_characters = array(
|
||||
'/ä|æ|ǽ/' => 'ae',
|
||||
'/ö|œ/' => 'oe',
|
||||
'/ü/' => 'ue',
|
||||
'/Ä/' => 'Ae',
|
||||
'/Ü/' => 'Ue',
|
||||
'/Ö/' => 'Oe',
|
||||
'/À|Á|Â|Ã|Ä|Å|Ǻ|Ā|Ă|Ą|Ǎ|Α|Ά|Ả|Ạ|Ầ|Ẫ|Ẩ|Ậ|Ằ|Ắ|Ẵ|Ẳ|Ặ|А/' => 'A',
|
||||
'/à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª|α|ά|ả|ạ|ầ|ấ|ẫ|ẩ|ậ|ằ|ắ|ẵ|ẳ|ặ|а/' => 'a',
|
||||
'/Б/' => 'B',
|
||||
'/б/' => 'b',
|
||||
'/Ç|Ć|Ĉ|Ċ|Č/' => 'C',
|
||||
'/ç|ć|ĉ|ċ|č/' => 'c',
|
||||
'/Д/' => 'D',
|
||||
'/д/' => 'd',
|
||||
'/Ð|Ď|Đ|Δ/' => 'Dj',
|
||||
'/ð|ď|đ|δ/' => 'dj',
|
||||
'/È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě|Ε|Έ|Ẽ|Ẻ|Ẹ|Ề|Ế|Ễ|Ể|Ệ|Е|Э/' => 'E',
|
||||
'/è|é|ê|ë|ē|ĕ|ė|ę|ě|έ|ε|ẽ|ẻ|ẹ|ề|ế|ễ|ể|ệ|е|э/' => 'e',
|
||||
'/Ф/' => 'F',
|
||||
'/ф/' => 'f',
|
||||
'/Ĝ|Ğ|Ġ|Ģ|Γ|Г|Ґ/' => 'G',
|
||||
'/ĝ|ğ|ġ|ģ|γ|г|ґ/' => 'g',
|
||||
'/Ĥ|Ħ/' => 'H',
|
||||
'/ĥ|ħ/' => 'h',
|
||||
'/Ì|Í|Î|Ï|Ĩ|Ī|Ĭ|Ǐ|Į|İ|Η|Ή|Ί|Ι|Ϊ|Ỉ|Ị|И|Ы/' => 'I',
|
||||
'/ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı|η|ή|ί|ι|ϊ|ỉ|ị|и|ы|ї/' => 'i',
|
||||
'/Ĵ/' => 'J',
|
||||
'/ĵ/' => 'j',
|
||||
'/Ķ|Κ|К/' => 'K',
|
||||
'/ķ|κ|к/' => 'k',
|
||||
'/Ĺ|Ļ|Ľ|Ŀ|Ł|Λ|Л/' => 'L',
|
||||
'/ĺ|ļ|ľ|ŀ|ł|λ|л/' => 'l',
|
||||
'/М/' => 'M',
|
||||
'/м/' => 'm',
|
||||
'/Ñ|Ń|Ņ|Ň|Ν|Н/' => 'N',
|
||||
'/ñ|ń|ņ|ň|ʼn|ν|н/' => 'n',
|
||||
'/Ò|Ó|Ô|Õ|Ō|Ŏ|Ǒ|Ő|Ơ|Ø|Ǿ|Ο|Ό|Ω|Ώ|Ỏ|Ọ|Ồ|Ố|Ỗ|Ổ|Ộ|Ờ|Ớ|Ỡ|Ở|Ợ|О/' => 'O',
|
||||
'/ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º|ο|ό|ω|ώ|ỏ|ọ|ồ|ố|ỗ|ổ|ộ|ờ|ớ|ỡ|ở|ợ|о/' => 'o',
|
||||
'/П/' => 'P',
|
||||
'/п/' => 'p',
|
||||
'/Ŕ|Ŗ|Ř|Ρ|Р/' => 'R',
|
||||
'/ŕ|ŗ|ř|ρ|р/' => 'r',
|
||||
'/Ś|Ŝ|Ş|Ș|Š|Σ|С/' => 'S',
|
||||
'/ś|ŝ|ş|ș|š|ſ|σ|ς|с/' => 's',
|
||||
'/Ț|Ţ|Ť|Ŧ|τ|Т/' => 'T',
|
||||
'/ț|ţ|ť|ŧ|т/' => 't',
|
||||
'/Þ|þ/' => 'th',
|
||||
'/Ù|Ú|Û|Ũ|Ū|Ŭ|Ů|Ű|Ų|Ư|Ǔ|Ǖ|Ǘ|Ǚ|Ǜ|Ũ|Ủ|Ụ|Ừ|Ứ|Ữ|Ử|Ự|У/' => 'U',
|
||||
'/ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ|υ|ύ|ϋ|ủ|ụ|ừ|ứ|ữ|ử|ự|у/' => 'u',
|
||||
'/Ƴ|Ɏ|Ỵ|Ẏ|Ӳ|Ӯ|Ў|Ý|Ÿ|Ŷ|Υ|Ύ|Ϋ|Ỳ|Ỹ|Ỷ|Ỵ|Й/' => 'Y',
|
||||
'/ẙ|ʏ|ƴ|ɏ|ỵ|ẏ|ӳ|ӯ|ў|ý|ÿ|ŷ|ỳ|ỹ|ỷ|ỵ|й/' => 'y',
|
||||
'/В/' => 'V',
|
||||
'/в/' => 'v',
|
||||
'/Ŵ/' => 'W',
|
||||
'/ŵ/' => 'w',
|
||||
'/Ź|Ż|Ž|Ζ|З/' => 'Z',
|
||||
'/ź|ż|ž|ζ|з/' => 'z',
|
||||
'/Æ|Ǽ/' => 'AE',
|
||||
'/ß/' => 'ss',
|
||||
'/IJ/' => 'IJ',
|
||||
'/ij/' => 'ij',
|
||||
'/Œ/' => 'OE',
|
||||
'/ƒ/' => 'f',
|
||||
'/ξ/' => 'ks',
|
||||
'/π/' => 'p',
|
||||
'/β/' => 'v',
|
||||
'/μ/' => 'm',
|
||||
'/ψ/' => 'ps',
|
||||
'/Ё/' => 'Yo',
|
||||
'/ё/' => 'yo',
|
||||
'/Є/' => 'Ye',
|
||||
'/є/' => 'ye',
|
||||
'/Ї/' => 'Yi',
|
||||
'/Ж/' => 'Zh',
|
||||
'/ж/' => 'zh',
|
||||
'/Х/' => 'Kh',
|
||||
'/х/' => 'kh',
|
||||
'/Ц/' => 'Ts',
|
||||
'/ц/' => 'ts',
|
||||
'/Ч/' => 'Ch',
|
||||
'/ч/' => 'ch',
|
||||
'/Ш/' => 'Sh',
|
||||
'/ш/' => 'sh',
|
||||
'/Щ/' => 'Shch',
|
||||
'/щ/' => 'shch',
|
||||
'/Ъ|ъ|Ь|ь/' => '',
|
||||
'/Ю/' => 'Yu',
|
||||
'/ю/' => 'yu',
|
||||
'/Я/' => 'Ya',
|
||||
'/я/' => 'ya'
|
||||
);
|
||||
13
application/config/hooks.php
Normal file
13
application/config/hooks.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------------
|
||||
| Hooks
|
||||
| -------------------------------------------------------------------------
|
||||
| This file lets you define "hooks" to extend CI without hacking the core
|
||||
| files. Please see the user guide for info:
|
||||
|
|
||||
| https://codeigniter.com/user_guide/general/hooks.html
|
||||
|
|
||||
*/
|
||||
11
application/config/index.html
Normal file
11
application/config/index.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
19
application/config/memcached.php
Normal file
19
application/config/memcached.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------------
|
||||
| Memcached settings
|
||||
| -------------------------------------------------------------------------
|
||||
| Your Memcached servers can be specified below.
|
||||
|
|
||||
| See: https://codeigniter.com/user_guide/libraries/caching.html#memcached
|
||||
|
|
||||
*/
|
||||
$config = array(
|
||||
'default' => array(
|
||||
'hostname' => '127.0.0.1',
|
||||
'port' => '11211',
|
||||
'weight' => '1',
|
||||
),
|
||||
);
|
||||
84
application/config/migration.php
Normal file
84
application/config/migration.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Enable/Disable Migrations
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Migrations are disabled by default for security reasons.
|
||||
| You should enable migrations whenever you intend to do a schema migration
|
||||
| and disable it back when you're done.
|
||||
|
|
||||
*/
|
||||
$config['migration_enabled'] = FALSE;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Migration Type
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Migration file names may be based on a sequential identifier or on
|
||||
| a timestamp. Options are:
|
||||
|
|
||||
| 'sequential' = Sequential migration naming (001_add_blog.php)
|
||||
| 'timestamp' = Timestamp migration naming (20121031104401_add_blog.php)
|
||||
| Use timestamp format YYYYMMDDHHIISS.
|
||||
|
|
||||
| Note: If this configuration value is missing the Migration library
|
||||
| defaults to 'sequential' for backward compatibility with CI2.
|
||||
|
|
||||
*/
|
||||
$config['migration_type'] = 'timestamp';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Migrations table
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This is the name of the table that will store the current migrations state.
|
||||
| When migrations runs it will store in a database table which migration
|
||||
| level the system is at. It then compares the migration level in this
|
||||
| table to the $config['migration_version'] if they are not the same it
|
||||
| will migrate up. This must be set.
|
||||
|
|
||||
*/
|
||||
$config['migration_table'] = 'migrations';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Auto Migrate To Latest
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| If this is set to TRUE when you load the migrations class and have
|
||||
| $config['migration_enabled'] set to TRUE the system will auto migrate
|
||||
| to your latest migration (whatever $config['migration_version'] is
|
||||
| set to). This way you do not have to call migrations anywhere else
|
||||
| in your code to have the latest migration.
|
||||
|
|
||||
*/
|
||||
$config['migration_auto_latest'] = FALSE;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Migrations version
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This is used to set migration version that the file system should be on.
|
||||
| If you run $this->migration->current() this is the version that schema will
|
||||
| be upgraded / downgraded to.
|
||||
|
|
||||
*/
|
||||
$config['migration_version'] = 0;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Migrations Path
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Path to your migrations folder.
|
||||
| Typically, it will be within your application path.
|
||||
| Also, writing permission is required within the migrations path.
|
||||
|
|
||||
*/
|
||||
$config['migration_path'] = APPPATH.'migrations/';
|
||||
184
application/config/mimes.php
Normal file
184
application/config/mimes.php
Normal file
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| MIME TYPES
|
||||
| -------------------------------------------------------------------
|
||||
| This file contains an array of mime types. It is used by the
|
||||
| Upload class to help identify allowed file types.
|
||||
|
|
||||
*/
|
||||
return array(
|
||||
'hqx' => array('application/mac-binhex40', 'application/mac-binhex', 'application/x-binhex40', 'application/x-mac-binhex40'),
|
||||
'cpt' => 'application/mac-compactpro',
|
||||
'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel', 'text/plain'),
|
||||
'bin' => array('application/macbinary', 'application/mac-binary', 'application/octet-stream', 'application/x-binary', 'application/x-macbinary'),
|
||||
'dms' => 'application/octet-stream',
|
||||
'lha' => 'application/octet-stream',
|
||||
'lzh' => 'application/octet-stream',
|
||||
'exe' => array('application/octet-stream', 'application/x-msdownload'),
|
||||
'class' => 'application/octet-stream',
|
||||
'psd' => array('application/x-photoshop', 'image/vnd.adobe.photoshop'),
|
||||
'so' => 'application/octet-stream',
|
||||
'sea' => 'application/octet-stream',
|
||||
'dll' => 'application/octet-stream',
|
||||
'oda' => 'application/oda',
|
||||
'pdf' => array('application/pdf', 'application/force-download', 'application/x-download', 'binary/octet-stream'),
|
||||
'ai' => array('application/pdf', 'application/postscript'),
|
||||
'eps' => 'application/postscript',
|
||||
'ps' => 'application/postscript',
|
||||
'smi' => 'application/smil',
|
||||
'smil' => 'application/smil',
|
||||
'mif' => 'application/vnd.mif',
|
||||
'xls' => array('application/vnd.ms-excel', 'application/msexcel', 'application/x-msexcel', 'application/x-ms-excel', 'application/x-excel', 'application/x-dos_ms_excel', 'application/xls', 'application/x-xls', 'application/excel', 'application/download', 'application/vnd.ms-office', 'application/msword'),
|
||||
'ppt' => array('application/powerpoint', 'application/vnd.ms-powerpoint', 'application/vnd.ms-office', 'application/msword'),
|
||||
'pptx' => array('application/vnd.openxmlformats-officedocument.presentationml.presentation', 'application/x-zip', 'application/zip'),
|
||||
'wbxml' => 'application/wbxml',
|
||||
'wmlc' => 'application/wmlc',
|
||||
'dcr' => 'application/x-director',
|
||||
'dir' => 'application/x-director',
|
||||
'dxr' => 'application/x-director',
|
||||
'dvi' => 'application/x-dvi',
|
||||
'gtar' => 'application/x-gtar',
|
||||
'gz' => 'application/x-gzip',
|
||||
'gzip' => 'application/x-gzip',
|
||||
'php' => array('application/x-httpd-php', 'application/php', 'application/x-php', 'text/php', 'text/x-php', 'application/x-httpd-php-source'),
|
||||
'php4' => 'application/x-httpd-php',
|
||||
'php3' => 'application/x-httpd-php',
|
||||
'phtml' => 'application/x-httpd-php',
|
||||
'phps' => 'application/x-httpd-php-source',
|
||||
'js' => array('application/x-javascript', 'text/plain'),
|
||||
'swf' => 'application/x-shockwave-flash',
|
||||
'sit' => 'application/x-stuffit',
|
||||
'tar' => 'application/x-tar',
|
||||
'tgz' => array('application/x-tar', 'application/x-gzip-compressed'),
|
||||
'z' => 'application/x-compress',
|
||||
'xhtml' => 'application/xhtml+xml',
|
||||
'xht' => 'application/xhtml+xml',
|
||||
'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed', 'application/s-compressed', 'multipart/x-zip'),
|
||||
'rar' => array('application/x-rar', 'application/rar', 'application/x-rar-compressed'),
|
||||
'mid' => 'audio/midi',
|
||||
'midi' => 'audio/midi',
|
||||
'mpga' => 'audio/mpeg',
|
||||
'mp2' => 'audio/mpeg',
|
||||
'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'),
|
||||
'aif' => array('audio/x-aiff', 'audio/aiff'),
|
||||
'aiff' => array('audio/x-aiff', 'audio/aiff'),
|
||||
'aifc' => 'audio/x-aiff',
|
||||
'ram' => 'audio/x-pn-realaudio',
|
||||
'rm' => 'audio/x-pn-realaudio',
|
||||
'rpm' => 'audio/x-pn-realaudio-plugin',
|
||||
'ra' => 'audio/x-realaudio',
|
||||
'rv' => 'video/vnd.rn-realvideo',
|
||||
'wav' => array('audio/x-wav', 'audio/wave', 'audio/wav'),
|
||||
'bmp' => array('image/bmp', 'image/x-bmp', 'image/x-bitmap', 'image/x-xbitmap', 'image/x-win-bitmap', 'image/x-windows-bmp', 'image/ms-bmp', 'image/x-ms-bmp', 'application/bmp', 'application/x-bmp', 'application/x-win-bitmap'),
|
||||
'gif' => 'image/gif',
|
||||
'jpeg' => array('image/jpeg', 'image/pjpeg'),
|
||||
'jpg' => array('image/jpeg', 'image/pjpeg'),
|
||||
'jpe' => array('image/jpeg', 'image/pjpeg'),
|
||||
'jp2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
|
||||
'j2k' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
|
||||
'jpf' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
|
||||
'jpg2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
|
||||
'jpx' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
|
||||
'jpm' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
|
||||
'mj2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
|
||||
'mjp2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
|
||||
'png' => array('image/png', 'image/x-png'),
|
||||
'tiff' => 'image/tiff',
|
||||
'tif' => 'image/tiff',
|
||||
'css' => array('text/css', 'text/plain'),
|
||||
'html' => array('text/html', 'text/plain'),
|
||||
'htm' => array('text/html', 'text/plain'),
|
||||
'shtml' => array('text/html', 'text/plain'),
|
||||
'txt' => 'text/plain',
|
||||
'text' => 'text/plain',
|
||||
'log' => array('text/plain', 'text/x-log'),
|
||||
'rtx' => 'text/richtext',
|
||||
'rtf' => 'text/rtf',
|
||||
'xml' => array('application/xml', 'text/xml', 'text/plain'),
|
||||
'xsl' => array('application/xml', 'text/xsl', 'text/xml'),
|
||||
'mpeg' => 'video/mpeg',
|
||||
'mpg' => 'video/mpeg',
|
||||
'mpe' => 'video/mpeg',
|
||||
'qt' => 'video/quicktime',
|
||||
'mov' => 'video/quicktime',
|
||||
'avi' => array('video/x-msvideo', 'video/msvideo', 'video/avi', 'application/x-troff-msvideo'),
|
||||
'movie' => 'video/x-sgi-movie',
|
||||
'doc' => array('application/msword', 'application/vnd.ms-office'),
|
||||
'docx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/msword', 'application/x-zip'),
|
||||
'dot' => array('application/msword', 'application/vnd.ms-office'),
|
||||
'dotx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/msword'),
|
||||
'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/vnd.ms-excel', 'application/msword', 'application/x-zip'),
|
||||
'word' => array('application/msword', 'application/octet-stream'),
|
||||
'xl' => 'application/excel',
|
||||
'eml' => 'message/rfc822',
|
||||
'json' => array('application/json', 'text/json'),
|
||||
'pem' => array('application/x-x509-user-cert', 'application/x-pem-file', 'application/octet-stream'),
|
||||
'p10' => array('application/x-pkcs10', 'application/pkcs10'),
|
||||
'p12' => 'application/x-pkcs12',
|
||||
'p7a' => 'application/x-pkcs7-signature',
|
||||
'p7c' => array('application/pkcs7-mime', 'application/x-pkcs7-mime'),
|
||||
'p7m' => array('application/pkcs7-mime', 'application/x-pkcs7-mime'),
|
||||
'p7r' => 'application/x-pkcs7-certreqresp',
|
||||
'p7s' => 'application/pkcs7-signature',
|
||||
'crt' => array('application/x-x509-ca-cert', 'application/x-x509-user-cert', 'application/pkix-cert'),
|
||||
'crl' => array('application/pkix-crl', 'application/pkcs-crl'),
|
||||
'der' => 'application/x-x509-ca-cert',
|
||||
'kdb' => 'application/octet-stream',
|
||||
'pgp' => 'application/pgp',
|
||||
'gpg' => 'application/gpg-keys',
|
||||
'sst' => 'application/octet-stream',
|
||||
'csr' => 'application/octet-stream',
|
||||
'rsa' => 'application/x-pkcs7',
|
||||
'cer' => array('application/pkix-cert', 'application/x-x509-ca-cert'),
|
||||
'3g2' => 'video/3gpp2',
|
||||
'3gp' => array('video/3gp', 'video/3gpp'),
|
||||
'mp4' => 'video/mp4',
|
||||
'm4a' => 'audio/x-m4a',
|
||||
'f4v' => array('video/mp4', 'video/x-f4v'),
|
||||
'flv' => 'video/x-flv',
|
||||
'webm' => 'video/webm',
|
||||
'aac' => 'audio/x-acc',
|
||||
'm4u' => 'application/vnd.mpegurl',
|
||||
'm3u' => 'text/plain',
|
||||
'xspf' => 'application/xspf+xml',
|
||||
'vlc' => 'application/videolan',
|
||||
'wmv' => array('video/x-ms-wmv', 'video/x-ms-asf'),
|
||||
'au' => 'audio/x-au',
|
||||
'ac3' => 'audio/ac3',
|
||||
'flac' => 'audio/x-flac',
|
||||
'ogg' => array('audio/ogg', 'video/ogg', 'application/ogg'),
|
||||
'kmz' => array('application/vnd.google-earth.kmz', 'application/zip', 'application/x-zip'),
|
||||
'kml' => array('application/vnd.google-earth.kml+xml', 'application/xml', 'text/xml'),
|
||||
'ics' => 'text/calendar',
|
||||
'ical' => 'text/calendar',
|
||||
'zsh' => 'text/x-scriptzsh',
|
||||
'7z' => array('application/x-7z-compressed', 'application/x-compressed', 'application/x-zip-compressed', 'application/zip', 'multipart/x-zip'),
|
||||
'7zip' => array('application/x-7z-compressed', 'application/x-compressed', 'application/x-zip-compressed', 'application/zip', 'multipart/x-zip'),
|
||||
'cdr' => array('application/cdr', 'application/coreldraw', 'application/x-cdr', 'application/x-coreldraw', 'image/cdr', 'image/x-cdr', 'zz-application/zz-winassoc-cdr'),
|
||||
'wma' => array('audio/x-ms-wma', 'video/x-ms-asf'),
|
||||
'jar' => array('application/java-archive', 'application/x-java-application', 'application/x-jar', 'application/x-compressed'),
|
||||
'svg' => array('image/svg+xml', 'application/xml', 'text/xml'),
|
||||
'vcf' => 'text/x-vcard',
|
||||
'srt' => array('text/srt', 'text/plain'),
|
||||
'vtt' => array('text/vtt', 'text/plain'),
|
||||
'ico' => array('image/x-icon', 'image/x-ico', 'image/vnd.microsoft.icon'),
|
||||
'odc' => 'application/vnd.oasis.opendocument.chart',
|
||||
'otc' => 'application/vnd.oasis.opendocument.chart-template',
|
||||
'odf' => 'application/vnd.oasis.opendocument.formula',
|
||||
'otf' => 'application/vnd.oasis.opendocument.formula-template',
|
||||
'odg' => 'application/vnd.oasis.opendocument.graphics',
|
||||
'otg' => 'application/vnd.oasis.opendocument.graphics-template',
|
||||
'odi' => 'application/vnd.oasis.opendocument.image',
|
||||
'oti' => 'application/vnd.oasis.opendocument.image-template',
|
||||
'odp' => 'application/vnd.oasis.opendocument.presentation',
|
||||
'otp' => 'application/vnd.oasis.opendocument.presentation-template',
|
||||
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
|
||||
'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template',
|
||||
'odt' => 'application/vnd.oasis.opendocument.text',
|
||||
'odm' => 'application/vnd.oasis.opendocument.text-master',
|
||||
'ott' => 'application/vnd.oasis.opendocument.text-template',
|
||||
'oth' => 'application/vnd.oasis.opendocument.text-web'
|
||||
);
|
||||
14
application/config/mongo_db.php
Normal file
14
application/config/mongo_db.php
Normal file
@@ -0,0 +1,14 @@
|
||||
$config['mongo_db']['active'] = 'default';
|
||||
$config['mongo_db']['default']['no_auth'] = false;
|
||||
$config['mongo_db']['default']['hostname'] = 'localhost';
|
||||
$config['mongo_db']['default']['port'] = '27017';
|
||||
$config['mongo_db']['default']['username'] = 'one';
|
||||
$config['mongo_db']['default']['password'] = 'sasone102938';
|
||||
$config['mongo_db']['default']['database'] = '';
|
||||
$config['mongo_db']['default']['db_debug'] = TRUE;
|
||||
$config['mongo_db']['default']['return_as'] = 'array';
|
||||
$config['mongo_db']['default']['write_concerns'] = (int)1;
|
||||
$config['mongo_db']['default']['journal'] = TRUE;
|
||||
$config['mongo_db']['default']['read_preference'] = 'primary';
|
||||
$config['mongo_db']['default']['read_concern'] = 'local'; //'local', 'majority' or 'linearizable'
|
||||
$config['mongo_db']['default']['legacy_support'] = TRUE;
|
||||
14
application/config/profiler.php
Normal file
14
application/config/profiler.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------------
|
||||
| Profiler Sections
|
||||
| -------------------------------------------------------------------------
|
||||
| This file lets you determine whether or not various sections of Profiler
|
||||
| data are displayed when the Profiler is enabled.
|
||||
| Please see the user guide for info:
|
||||
|
|
||||
| https://codeigniter.com/user_guide/general/profiling.html
|
||||
|
|
||||
*/
|
||||
54
application/config/routes.php
Normal file
54
application/config/routes.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------------
|
||||
| URI ROUTING
|
||||
| -------------------------------------------------------------------------
|
||||
| This file lets you re-map URI requests to specific controller functions.
|
||||
|
|
||||
| Typically there is a one-to-one relationship between a URL string
|
||||
| and its corresponding controller class/method. The segments in a
|
||||
| URL normally follow this pattern:
|
||||
|
|
||||
| example.com/class/method/id/
|
||||
|
|
||||
| In some instances, however, you may want to remap this relationship
|
||||
| so that a different class/function is called than the one
|
||||
| corresponding to the URL.
|
||||
|
|
||||
| Please see the user guide for complete details:
|
||||
|
|
||||
| https://codeigniter.com/user_guide/general/routing.html
|
||||
|
|
||||
| -------------------------------------------------------------------------
|
||||
| RESERVED ROUTES
|
||||
| -------------------------------------------------------------------------
|
||||
|
|
||||
| There are three reserved routes:
|
||||
|
|
||||
| $route['default_controller'] = 'welcome';
|
||||
|
|
||||
| This route indicates which controller class should be loaded if the
|
||||
| URI contains no data. In the above example, the "welcome" class
|
||||
| would be loaded.
|
||||
|
|
||||
| $route['404_override'] = 'errors/page_missing';
|
||||
|
|
||||
| This route will tell the Router which controller/method to use if those
|
||||
| provided in the URL cannot be matched to a valid route.
|
||||
|
|
||||
| $route['translate_uri_dashes'] = FALSE;
|
||||
|
|
||||
| This is not exactly a route, but allows you to automatically route
|
||||
| controller and method names that contain dashes. '-' isn't a valid
|
||||
| class or method name character, so it requires translation.
|
||||
| When you set this option to TRUE, it will replace ALL dashes in the
|
||||
| controller and method URI segments.
|
||||
|
|
||||
| Examples: my-controller/index -> my_controller/index
|
||||
| my-controller/my-method -> my_controller/my_method
|
||||
*/
|
||||
$route['default_controller'] = 'welcome';
|
||||
$route['404_override'] = '';
|
||||
$route['translate_uri_dashes'] = FALSE;
|
||||
64
application/config/smileys.php
Normal file
64
application/config/smileys.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| SMILEYS
|
||||
| -------------------------------------------------------------------
|
||||
| This file contains an array of smileys for use with the emoticon helper.
|
||||
| Individual images can be used to replace multiple smileys. For example:
|
||||
| :-) and :) use the same image replacement.
|
||||
|
|
||||
| Please see user guide for more info:
|
||||
| https://codeigniter.com/user_guide/helpers/smiley_helper.html
|
||||
|
|
||||
*/
|
||||
$smileys = array(
|
||||
|
||||
// smiley image name width height alt
|
||||
|
||||
':-)' => array('grin.gif', '19', '19', 'grin'),
|
||||
':lol:' => array('lol.gif', '19', '19', 'LOL'),
|
||||
':cheese:' => array('cheese.gif', '19', '19', 'cheese'),
|
||||
':)' => array('smile.gif', '19', '19', 'smile'),
|
||||
';-)' => array('wink.gif', '19', '19', 'wink'),
|
||||
';)' => array('wink.gif', '19', '19', 'wink'),
|
||||
':smirk:' => array('smirk.gif', '19', '19', 'smirk'),
|
||||
':roll:' => array('rolleyes.gif', '19', '19', 'rolleyes'),
|
||||
':-S' => array('confused.gif', '19', '19', 'confused'),
|
||||
':wow:' => array('surprise.gif', '19', '19', 'surprised'),
|
||||
':bug:' => array('bigsurprise.gif', '19', '19', 'big surprise'),
|
||||
':-P' => array('tongue_laugh.gif', '19', '19', 'tongue laugh'),
|
||||
'%-P' => array('tongue_rolleye.gif', '19', '19', 'tongue rolleye'),
|
||||
';-P' => array('tongue_wink.gif', '19', '19', 'tongue wink'),
|
||||
':P' => array('raspberry.gif', '19', '19', 'raspberry'),
|
||||
':blank:' => array('blank.gif', '19', '19', 'blank stare'),
|
||||
':long:' => array('longface.gif', '19', '19', 'long face'),
|
||||
':ohh:' => array('ohh.gif', '19', '19', 'ohh'),
|
||||
':grrr:' => array('grrr.gif', '19', '19', 'grrr'),
|
||||
':gulp:' => array('gulp.gif', '19', '19', 'gulp'),
|
||||
'8-/' => array('ohoh.gif', '19', '19', 'oh oh'),
|
||||
':down:' => array('downer.gif', '19', '19', 'downer'),
|
||||
':red:' => array('embarrassed.gif', '19', '19', 'red face'),
|
||||
':sick:' => array('sick.gif', '19', '19', 'sick'),
|
||||
':shut:' => array('shuteye.gif', '19', '19', 'shut eye'),
|
||||
':-/' => array('hmm.gif', '19', '19', 'hmmm'),
|
||||
'>:(' => array('mad.gif', '19', '19', 'mad'),
|
||||
':mad:' => array('mad.gif', '19', '19', 'mad'),
|
||||
'>:-(' => array('angry.gif', '19', '19', 'angry'),
|
||||
':angry:' => array('angry.gif', '19', '19', 'angry'),
|
||||
':zip:' => array('zip.gif', '19', '19', 'zipper'),
|
||||
':kiss:' => array('kiss.gif', '19', '19', 'kiss'),
|
||||
':ahhh:' => array('shock.gif', '19', '19', 'shock'),
|
||||
':coolsmile:' => array('shade_smile.gif', '19', '19', 'cool smile'),
|
||||
':coolsmirk:' => array('shade_smirk.gif', '19', '19', 'cool smirk'),
|
||||
':coolgrin:' => array('shade_grin.gif', '19', '19', 'cool grin'),
|
||||
':coolhmm:' => array('shade_hmm.gif', '19', '19', 'cool hmm'),
|
||||
':coolmad:' => array('shade_mad.gif', '19', '19', 'cool mad'),
|
||||
':coolcheese:' => array('shade_cheese.gif', '19', '19', 'cool cheese'),
|
||||
':vampire:' => array('vampire.gif', '19', '19', 'vampire'),
|
||||
':snake:' => array('snake.gif', '19', '19', 'snake'),
|
||||
':exclaim:' => array('exclaim.gif', '19', '19', 'exclaim'),
|
||||
':question:' => array('question.gif', '19', '19', 'question')
|
||||
|
||||
);
|
||||
214
application/config/user_agents.php
Normal file
214
application/config/user_agents.php
Normal file
@@ -0,0 +1,214 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| USER AGENT TYPES
|
||||
| -------------------------------------------------------------------
|
||||
| This file contains four arrays of user agent data. It is used by the
|
||||
| User Agent Class to help identify browser, platform, robot, and
|
||||
| mobile device data. The array keys are used to identify the device
|
||||
| and the array values are used to set the actual name of the item.
|
||||
*/
|
||||
$platforms = array(
|
||||
'windows nt 10.0' => 'Windows 10',
|
||||
'windows nt 6.3' => 'Windows 8.1',
|
||||
'windows nt 6.2' => 'Windows 8',
|
||||
'windows nt 6.1' => 'Windows 7',
|
||||
'windows nt 6.0' => 'Windows Vista',
|
||||
'windows nt 5.2' => 'Windows 2003',
|
||||
'windows nt 5.1' => 'Windows XP',
|
||||
'windows nt 5.0' => 'Windows 2000',
|
||||
'windows nt 4.0' => 'Windows NT 4.0',
|
||||
'winnt4.0' => 'Windows NT 4.0',
|
||||
'winnt 4.0' => 'Windows NT',
|
||||
'winnt' => 'Windows NT',
|
||||
'windows 98' => 'Windows 98',
|
||||
'win98' => 'Windows 98',
|
||||
'windows 95' => 'Windows 95',
|
||||
'win95' => 'Windows 95',
|
||||
'windows phone' => 'Windows Phone',
|
||||
'windows' => 'Unknown Windows OS',
|
||||
'android' => 'Android',
|
||||
'blackberry' => 'BlackBerry',
|
||||
'iphone' => 'iOS',
|
||||
'ipad' => 'iOS',
|
||||
'ipod' => 'iOS',
|
||||
'os x' => 'Mac OS X',
|
||||
'ppc mac' => 'Power PC Mac',
|
||||
'freebsd' => 'FreeBSD',
|
||||
'ppc' => 'Macintosh',
|
||||
'linux' => 'Linux',
|
||||
'debian' => 'Debian',
|
||||
'sunos' => 'Sun Solaris',
|
||||
'beos' => 'BeOS',
|
||||
'apachebench' => 'ApacheBench',
|
||||
'aix' => 'AIX',
|
||||
'irix' => 'Irix',
|
||||
'osf' => 'DEC OSF',
|
||||
'hp-ux' => 'HP-UX',
|
||||
'netbsd' => 'NetBSD',
|
||||
'bsdi' => 'BSDi',
|
||||
'openbsd' => 'OpenBSD',
|
||||
'gnu' => 'GNU/Linux',
|
||||
'unix' => 'Unknown Unix OS',
|
||||
'symbian' => 'Symbian OS'
|
||||
);
|
||||
|
||||
|
||||
// The order of this array should NOT be changed. Many browsers return
|
||||
// multiple browser types so we want to identify the sub-type first.
|
||||
$browsers = array(
|
||||
'OPR' => 'Opera',
|
||||
'Flock' => 'Flock',
|
||||
'Edge' => 'Edge',
|
||||
'Chrome' => 'Chrome',
|
||||
// Opera 10+ always reports Opera/9.80 and appends Version/<real version> to the user agent string
|
||||
'Opera.*?Version' => 'Opera',
|
||||
'Opera' => 'Opera',
|
||||
'MSIE' => 'Internet Explorer',
|
||||
'Internet Explorer' => 'Internet Explorer',
|
||||
'Trident.* rv' => 'Internet Explorer',
|
||||
'Shiira' => 'Shiira',
|
||||
'Firefox' => 'Firefox',
|
||||
'Chimera' => 'Chimera',
|
||||
'Phoenix' => 'Phoenix',
|
||||
'Firebird' => 'Firebird',
|
||||
'Camino' => 'Camino',
|
||||
'Netscape' => 'Netscape',
|
||||
'OmniWeb' => 'OmniWeb',
|
||||
'Safari' => 'Safari',
|
||||
'Mozilla' => 'Mozilla',
|
||||
'Konqueror' => 'Konqueror',
|
||||
'icab' => 'iCab',
|
||||
'Lynx' => 'Lynx',
|
||||
'Links' => 'Links',
|
||||
'hotjava' => 'HotJava',
|
||||
'amaya' => 'Amaya',
|
||||
'IBrowse' => 'IBrowse',
|
||||
'Maxthon' => 'Maxthon',
|
||||
'Ubuntu' => 'Ubuntu Web Browser'
|
||||
);
|
||||
|
||||
$mobiles = array(
|
||||
// legacy array, old values commented out
|
||||
'mobileexplorer' => 'Mobile Explorer',
|
||||
// 'openwave' => 'Open Wave',
|
||||
// 'opera mini' => 'Opera Mini',
|
||||
// 'operamini' => 'Opera Mini',
|
||||
// 'elaine' => 'Palm',
|
||||
'palmsource' => 'Palm',
|
||||
// 'digital paths' => 'Palm',
|
||||
// 'avantgo' => 'Avantgo',
|
||||
// 'xiino' => 'Xiino',
|
||||
'palmscape' => 'Palmscape',
|
||||
// 'nokia' => 'Nokia',
|
||||
// 'ericsson' => 'Ericsson',
|
||||
// 'blackberry' => 'BlackBerry',
|
||||
// 'motorola' => 'Motorola'
|
||||
|
||||
// Phones and Manufacturers
|
||||
'motorola' => 'Motorola',
|
||||
'nokia' => 'Nokia',
|
||||
'palm' => 'Palm',
|
||||
'iphone' => 'Apple iPhone',
|
||||
'ipad' => 'iPad',
|
||||
'ipod' => 'Apple iPod Touch',
|
||||
'sony' => 'Sony Ericsson',
|
||||
'ericsson' => 'Sony Ericsson',
|
||||
'blackberry' => 'BlackBerry',
|
||||
'cocoon' => 'O2 Cocoon',
|
||||
'blazer' => 'Treo',
|
||||
'lg' => 'LG',
|
||||
'amoi' => 'Amoi',
|
||||
'xda' => 'XDA',
|
||||
'mda' => 'MDA',
|
||||
'vario' => 'Vario',
|
||||
'htc' => 'HTC',
|
||||
'samsung' => 'Samsung',
|
||||
'sharp' => 'Sharp',
|
||||
'sie-' => 'Siemens',
|
||||
'alcatel' => 'Alcatel',
|
||||
'benq' => 'BenQ',
|
||||
'ipaq' => 'HP iPaq',
|
||||
'mot-' => 'Motorola',
|
||||
'playstation portable' => 'PlayStation Portable',
|
||||
'playstation 3' => 'PlayStation 3',
|
||||
'playstation vita' => 'PlayStation Vita',
|
||||
'hiptop' => 'Danger Hiptop',
|
||||
'nec-' => 'NEC',
|
||||
'panasonic' => 'Panasonic',
|
||||
'philips' => 'Philips',
|
||||
'sagem' => 'Sagem',
|
||||
'sanyo' => 'Sanyo',
|
||||
'spv' => 'SPV',
|
||||
'zte' => 'ZTE',
|
||||
'sendo' => 'Sendo',
|
||||
'nintendo dsi' => 'Nintendo DSi',
|
||||
'nintendo ds' => 'Nintendo DS',
|
||||
'nintendo 3ds' => 'Nintendo 3DS',
|
||||
'wii' => 'Nintendo Wii',
|
||||
'open web' => 'Open Web',
|
||||
'openweb' => 'OpenWeb',
|
||||
|
||||
// Operating Systems
|
||||
'android' => 'Android',
|
||||
'symbian' => 'Symbian',
|
||||
'SymbianOS' => 'SymbianOS',
|
||||
'elaine' => 'Palm',
|
||||
'series60' => 'Symbian S60',
|
||||
'windows ce' => 'Windows CE',
|
||||
|
||||
// Browsers
|
||||
'obigo' => 'Obigo',
|
||||
'netfront' => 'Netfront Browser',
|
||||
'openwave' => 'Openwave Browser',
|
||||
'mobilexplorer' => 'Mobile Explorer',
|
||||
'operamini' => 'Opera Mini',
|
||||
'opera mini' => 'Opera Mini',
|
||||
'opera mobi' => 'Opera Mobile',
|
||||
'fennec' => 'Firefox Mobile',
|
||||
|
||||
// Other
|
||||
'digital paths' => 'Digital Paths',
|
||||
'avantgo' => 'AvantGo',
|
||||
'xiino' => 'Xiino',
|
||||
'novarra' => 'Novarra Transcoder',
|
||||
'vodafone' => 'Vodafone',
|
||||
'docomo' => 'NTT DoCoMo',
|
||||
'o2' => 'O2',
|
||||
|
||||
// Fallback
|
||||
'mobile' => 'Generic Mobile',
|
||||
'wireless' => 'Generic Mobile',
|
||||
'j2me' => 'Generic Mobile',
|
||||
'midp' => 'Generic Mobile',
|
||||
'cldc' => 'Generic Mobile',
|
||||
'up.link' => 'Generic Mobile',
|
||||
'up.browser' => 'Generic Mobile',
|
||||
'smartphone' => 'Generic Mobile',
|
||||
'cellphone' => 'Generic Mobile'
|
||||
);
|
||||
|
||||
// There are hundreds of bots but these are the most common.
|
||||
$robots = array(
|
||||
'googlebot' => 'Googlebot',
|
||||
'msnbot' => 'MSNBot',
|
||||
'baiduspider' => 'Baiduspider',
|
||||
'bingbot' => 'Bing',
|
||||
'slurp' => 'Inktomi Slurp',
|
||||
'yahoo' => 'Yahoo',
|
||||
'ask jeeves' => 'Ask Jeeves',
|
||||
'fastcrawler' => 'FastCrawler',
|
||||
'infoseek' => 'InfoSeek Robot 1.0',
|
||||
'lycos' => 'Lycos',
|
||||
'yandex' => 'YandexBot',
|
||||
'mediapartners-google' => 'MediaPartners Google',
|
||||
'CRAZYWEBCRAWLER' => 'Crazy Webcrawler',
|
||||
'adsbot-google' => 'AdsBot Google',
|
||||
'feedfetcher-google' => 'Feedfetcher Google',
|
||||
'curious george' => 'Curious George',
|
||||
'ia_archiver' => 'Alexa Crawler',
|
||||
'MJ12bot' => 'Majestic-12',
|
||||
'Uptimebot' => 'Uptimebot'
|
||||
);
|
||||
@@ -0,0 +1,283 @@
|
||||
<?php
|
||||
|
||||
class PurchaseRequest extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "Purchase Request/Cashier API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
|
||||
$query = "SELECT prd.*,
|
||||
ure.M_UserFullName AS M_RequesterFullName,
|
||||
uap.M_UserFullName AS M_ApproverFullName,
|
||||
uco.M_UserFullName AS M_ConfirmerFullName
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS ure ON prd.PurchaseRequestCreatedUserID = ure.M_UserID
|
||||
INNER JOIN m_user AS uap ON prd.PurchaseRequestApprovedBy = uap.M_userID
|
||||
LEFT JOIN m_user AS uco ON prd.PurchaseRequestConfirmedBy = uco.M_userID
|
||||
WHERE prd.PurchaseRequestDirectIsActive = 'Y'
|
||||
AND prd.PurchaseRequestDirectStatus NOT IN ('Pending', 'Draft')
|
||||
AND PurchaseRequestDirectNumber LIKE '%" . $payload["search"] . "%'";
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS ure ON prd.PurchaseRequestCreatedUserID = ure.M_UserID
|
||||
INNER JOIN m_user AS uap ON prd.PurchaseRequestApprovedBy = uap.M_userID
|
||||
LEFT JOIN m_user AS uco ON prd.PurchaseRequestConfirmedBy = uco.M_userID
|
||||
WHERE prd.PurchaseRequestDirectIsActive = 'Y'
|
||||
AND prd.PurchaseRequestDirectStatus NOT IN ('Pending', 'Draft')
|
||||
AND PurchaseRequestDirectNumber LIKE '%" . $payload["search"] . "%'";
|
||||
|
||||
if ((isset($payload["startDate"]) && isset($payload["endDate"])) && (trim($payload["startDate"]) !== "" && trim($payload["endDate"]) !== "")) {
|
||||
$query .= " AND (PurchaseRequestDirectDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59' OR PurchaseRequestDirectDateUse BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
$queryCount .= " AND (PurchaseRequestDirectDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59' OR PurchaseRequestDirectDateUse BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
}
|
||||
|
||||
if ($payload["status"]) {
|
||||
$query .= " AND PurchaseRequestDirectStatus = {$payload["status"]}";
|
||||
$queryCount .= " AND PurchaseRequestDirectStatus = {$payload["status"]}";
|
||||
}
|
||||
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$numberLimit = 30;
|
||||
$numberOffset = 0;
|
||||
if ($payload["currentPage"] > 0) {
|
||||
$numberOffset = ($payload["currentPage"] - 1) * $numberLimit;
|
||||
}
|
||||
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
$totalPage = ceil($totalCount / $numberLimit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$query .= " ORDER BY PurchaseRequestDirectNumber DESC
|
||||
LIMIT {$numberLimit} OFFSET {$numberOffset}";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $totalPage,
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function searchDetail()
|
||||
{
|
||||
try {
|
||||
// Validasi token
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
|
||||
$query = "SELECT *,
|
||||
ROW_NUMBER() OVER(ORDER BY PurchaseRequestDirectDetailID) RowNumber
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$totalCount = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request detail", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
$query .= " ORDER BY PurchaseRequestDirectDetailStatus ASC,
|
||||
PurchaseRequestDirectDetailID ASC";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function paidRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectStatus = 'Paid',
|
||||
PurchaseRequestDirectTotalPaid = {$payload['PRPaid']},
|
||||
PurchaseRequestPaidDate = NOW(),
|
||||
PurchaseRequestPaidBy = {$userId},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectStatus = 'Approved'
|
||||
AND PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("paid error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rowQuery = "SELECT prd.*,
|
||||
ure.M_UserFullName AS M_RequesterFullName,
|
||||
uap.M_UserFullName AS M_ApproverFullName,
|
||||
uco.M_UserFullName AS M_ConfirmerFullName
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS ure ON prd.PurchaseRequestCreatedUserID = ure.M_UserID
|
||||
INNER JOIN m_user AS uap ON prd.PurchaseRequestApprovedBy = uap.M_userID
|
||||
LEFT JOIN m_user AS uco ON prd.PurchaseRequestConfirmedBy = uco.M_userID
|
||||
WHERE prd.PurchaseRequestDirectIsActive = 'Y'
|
||||
AND prd.PurchaseRequestDirectStatus NOT IN ('Pending', 'Draft')
|
||||
AND prd.PurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($rowQuery, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("paid error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => $exec->result_array());
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function realitationRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailStatus = 'Received',
|
||||
PurchaseRequestDirectDetailLastUpdated = NOW(),
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailStatus = 'Ordered'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectStatus = 'Completed',
|
||||
PurchaseRequestDirectTotalRealitation = {$payload["PRRealitation"]},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectStatus = 'Paid'
|
||||
AND PurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("paid error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rowQuery = "SELECT prd.*,
|
||||
ure.M_UserFullName AS M_RequesterFullName,
|
||||
uap.M_UserFullName AS M_ApproverFullName,
|
||||
uco.M_UserFullName AS M_ConfirmerFullName
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS ure ON prd.PurchaseRequestCreatedUserID = ure.M_UserID
|
||||
INNER JOIN m_user AS uap ON prd.PurchaseRequestApprovedBy = uap.M_userID
|
||||
LEFT JOIN m_user AS uco ON prd.PurchaseRequestConfirmedBy = uco.M_userID
|
||||
WHERE prd.PurchaseRequestDirectIsActive = 'Y'
|
||||
AND prd.PurchaseRequestDirectStatus NOT IN ('Pending', 'Draft')
|
||||
AND prd.PurchaseRequestDirectID = {$payload["PRID"]}";
|
||||
$exec = $this->db->query($rowQuery, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("paid error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => $exec->result_array());
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,805 @@
|
||||
<?php
|
||||
|
||||
class PurchaseRequestDirect extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "Purchase Request/Requester API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
/* if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
*/
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$startdate = $payload["startdate"];
|
||||
$enddate = $payload["enddate"];
|
||||
|
||||
$query = "SELECT pv.*,
|
||||
M_BranchID,
|
||||
M_BranchCode,
|
||||
M_BranchName,
|
||||
CONCAT(cs.coaAccountNo, ' | ', cs.coaDescription) as CoaSource,
|
||||
-- CONCAT(ce.coaAccountNo, ' | ', ce.coaDescription) as CoaExpense,
|
||||
CONCAT(ct.coaAccountNo, ' | ', ct.coaDescription) as CoaTemporary,
|
||||
cs.coaDescription coaDescriptionSource,
|
||||
-- ce.coaDescription coaDescriptionExpense,
|
||||
ct.coaDescription coaDescriptionTemporary,
|
||||
cs.coaAccountNo coaAccountNoSource,
|
||||
-- ce.coaAccountNo coaAccountNoExpense,
|
||||
ct.coaAccountNo coaAccountNoTemporary
|
||||
FROM payment_voucher as pv
|
||||
LEFT JOIN m_branch ON M_BranchCode = PaymentVoucherM_BranchCode
|
||||
JOIN coa cs ON cs.coaID = PaymentVoucherCoaSourceID
|
||||
-- JOIN coa ce ON ce.coaID = PaymentVoucherCoaExpenseID
|
||||
JOIN coa ct ON ct.coaID = PaymentVoucherCoaTemporaryID
|
||||
WHERE PaymentVoucherIsActive = 'Y'
|
||||
AND DATE(PaymentVoucherDate) BETWEEN '{$startdate}' AND '{$enddate}'
|
||||
AND (PaymentVoucherNumber LIKE '%" . $payload["search"] . "%')";
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM payment_voucher as pv
|
||||
WHERE PaymentVoucherIsActive = 'Y'
|
||||
AND DATE(PaymentVoucherDate) BETWEEN '{$startdate}' AND '{$enddate}'
|
||||
AND (PaymentVoucherNumber LIKE '%" . $payload["search"] . "%')";
|
||||
|
||||
if ((isset($payload["startDate"]) && isset($payload["endDate"])) && (trim($payload["startDate"]) !== "" && trim($payload["endDate"]) !== "")) {
|
||||
$query .= " AND (PaymentVoucherDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
$queryCount .= " AND (PaymentVoucherDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
}
|
||||
|
||||
if ($payload["status"] !== 'All') {
|
||||
$query .= " AND PaymentVoucherStatus = '{$payload["status"]}'";
|
||||
$queryCount .= " AND PaymentVoucherStatus = '{$payload["status"]}'";
|
||||
}
|
||||
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$numberLimit = 20;
|
||||
$numberOffset = 0;
|
||||
if ($payload["currentPage"] > 0) {
|
||||
$numberOffset = ($payload["currentPage"] - 1) * $numberLimit;
|
||||
}
|
||||
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
$totalPage = ceil($totalCount / $numberLimit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select payment voucher", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
$query .= " ORDER BY PaymentVoucherDate DESC
|
||||
LIMIT {$numberLimit} OFFSET {$numberOffset}";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select payment voucher", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $totalPage,
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function searchDetail()
|
||||
{
|
||||
try {
|
||||
/* if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
*/
|
||||
|
||||
$payload = $this->sys_input;
|
||||
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM payment_voucher_detail
|
||||
WHERE PaymentVoucherDetailIsActive = 'Y'
|
||||
AND PaymentVoucherDetailPaymentVoucherID = {$payload['ID']}";
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$totalCount = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select payment voucher detail", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = "SELECT payment_voucher_detail.*,
|
||||
ROW_NUMBER() OVER(ORDER BY PaymentVoucherDetailID) RowNumber,
|
||||
PurchaseRequestDirectID,
|
||||
PurchaseRequestDirectNumber,
|
||||
PurchaseRequestDirectTotalRealitation,
|
||||
PurchaseRequestDirectAccountFilled
|
||||
FROM payment_voucher_detail
|
||||
LEFT JOIN purchase_request_direct ON PurchaseRequestDirectID = PaymentVoucherDetailPurchaseRequestDirectID
|
||||
WHERE PaymentVoucherDetailIsActive = 'Y'
|
||||
AND PaymentVoucherDetailPaymentVoucherID = {$payload['ID']}";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select payment voucher detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function voucherDetailItem() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$para = $this->sys_input;
|
||||
|
||||
$sql = "SELECT
|
||||
PurchaseDirectCategoryID,
|
||||
PurchaseDirectCategoryName,
|
||||
PurchaseRequestDirectDescription,
|
||||
PurchaseRequestDirectDetailID,
|
||||
PurchaseRequestDirectDetailItemUnitID,
|
||||
PurchaseRequestDirectDetailTotalEstimationPrice,
|
||||
PurchaseRequestDirectDetailPurchaseRequestDirectID,
|
||||
IFNULL(PurchaseRequestDirectDetailAccount, '') as account_number,
|
||||
'' as err_message
|
||||
FROM purchase_request_direct_detail
|
||||
JOIN purchase_direct_category ON PurchaseDirectCategoryID = PurchaseRequestDirectDetailPurchaseRequestDirectCategoryID
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = ?";
|
||||
$que = $this->db->query($sql, [$para['PRDirectID']]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get detail item voucher purchase request direct");
|
||||
exit;
|
||||
}
|
||||
$data = $que->result_array();
|
||||
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getBranch()
|
||||
{
|
||||
try {
|
||||
$payload = $this->sys_input;
|
||||
$query = "SELECT DISTINCT
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'
|
||||
AND (M_BranchCode LIKE '%" . $payload["search"] . "%' OR M_BranchName LIKE '%" . $payload["search"] . "%')
|
||||
ORDER BY M_BranchName ASC";
|
||||
$exec = $this->db->query($query, []);
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select branch", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getCoa()
|
||||
{
|
||||
try {
|
||||
$payload = $this->sys_input;
|
||||
$query = "SELECT * FROM coa
|
||||
WHERE coaIsActive = 'Y' AND coaIsInput = 'Y'
|
||||
AND (coaAccountNo LIKE '%" . $payload["search"] . "%' OR coaDescription LIKE '%" . $payload["search"] . "%')
|
||||
ORDER BY coaAccountNo ASC";
|
||||
$exec = $this->db->query($query, []);
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select coa", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getPurchase()
|
||||
{
|
||||
try {
|
||||
$payload = $this->sys_input;
|
||||
$query = "SELECT prd.*, u.M_UserUsername as user_request
|
||||
FROM purchase_request_direct prd
|
||||
JOIN m_user u ON prd.PurchaseRequestCreatedUserID = u.M_UserID
|
||||
WHERE prd.PurchaseRequestDirectIsActive = 'Y'
|
||||
AND prd.PurchaseRequestDirectApprovedBy IS NOT NULL
|
||||
AND prd.PurchaseRequestDirectM_BranchCode = '{$payload["branchcode"]}'
|
||||
AND prd.PurchaseRequestDirectID not in (
|
||||
select PaymentVoucherDetailPurchaseRequestDirectID from payment_voucher
|
||||
JOIN payment_voucher_detail ON PaymentVoucherDetailPaymentVoucherID = PaymentVoucherID AND PaymentVoucherDetailIsActive = 'Y'
|
||||
where PaymentVoucherIsActive = 'Y')
|
||||
ORDER BY prd.PurchaseRequestDirectNumber ASC";
|
||||
$exec = $this->db->query($query, []);
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select branch", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getTotalApproved()
|
||||
{
|
||||
try {
|
||||
$payload = $this->sys_input;
|
||||
$total = 0;
|
||||
$query = "SELECT COUNT(*) as total
|
||||
FROM purchase_request_direct
|
||||
WHERE PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestDirectApprovedBy IS NOT NULL
|
||||
AND PurchaseRequestDirectM_BranchCode = '{$payload["branchcode"]}'
|
||||
AND PurchaseRequestDirectID not in (
|
||||
select PaymentVoucherDetailPurchaseRequestDirectID from payment_voucher
|
||||
JOIN payment_voucher_detail ON PaymentVoucherDetailPaymentVoucherID = PaymentVoucherID AND PaymentVoucherDetailIsActive = 'Y'
|
||||
where PaymentVoucherIsActive = 'Y')";
|
||||
$exec = $this->db->query($query);
|
||||
if ($exec) {
|
||||
$total = $exec->row()->total;
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select branch", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $total,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function save()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$pdSql = "SELECT `fn_numbering`('PV') AS PV";
|
||||
$exec = $this->db->query($pdSql, []);
|
||||
$pd = "";
|
||||
$dateNow = date('Y-m-d');
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("payment voucher insert error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$pd = $exec->result_array()[0]["PV"];
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO payment_voucher(
|
||||
PaymentVoucherDate,
|
||||
PaymentVoucherNumber,
|
||||
PaymentVoucherM_BranchCode,
|
||||
PaymentVoucherCoaSourceID,
|
||||
PaymentVoucherCoaExpenseID,
|
||||
PaymentVoucherCoaTemporaryID,
|
||||
PaymentVoucherTotal,
|
||||
PaymentVoucherStatus,
|
||||
PaymentVoucherUserID,
|
||||
PaymentVoucherCreated,
|
||||
PaymentVoucherLastUpdated)
|
||||
VALUES ('{$dateNow}',
|
||||
'{$pd}',
|
||||
'{$payload['BranchCode']}',
|
||||
'{$payload['CoaSourceID']}',
|
||||
'{$payload['CoaExpenseID']}',
|
||||
'{$payload['CoaTemporaryID']}',
|
||||
'{$payload['total']}',
|
||||
'Draft',
|
||||
{$userId},
|
||||
now(),
|
||||
now())";
|
||||
$exec = $this->db->query($sql);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("payment voucher insert error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$last_id = $this->db->insert_id();
|
||||
foreach ($payload['details'] as $k => $v) {
|
||||
$sql = "INSERT INTO payment_voucher_detail(
|
||||
PaymentVoucherDetailPaymentVoucherID,
|
||||
PaymentVoucherDetailPurchaseRequestDirectID,
|
||||
PaymentVoucherDetailTotal,
|
||||
PaymentVoucherDetailUserID,
|
||||
PaymentVoucherDetailCreated,
|
||||
PaymentVoucherDetailLastUpdated)
|
||||
VALUES ('{$last_id}',
|
||||
'{$v['PurchaseRequestDirectID']}',
|
||||
'{$v['PurchaseRequestDirectTotalRealitation']}',
|
||||
{$userId},
|
||||
now(),
|
||||
now())";
|
||||
$exec = $this->db->query($sql);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("payment voucher detail insert error", $this->db);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
|
||||
$newInsert = "SELECT * FROM payment_voucher WHERE PaymentVoucherNumber = '{$pd}' AND PaymentVoucherIsActive = 'Y'";
|
||||
$records = $this->db->query($newInsert, [])->result_array();
|
||||
|
||||
$result = array("total" => 1, "records" => $records);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function update()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE payment_voucher SET
|
||||
PaymentVoucherM_BranchCode = '{$payload['BranchCode']}',
|
||||
PaymentVoucherCoaSourceID = '{$payload['CoaSourceID']}',
|
||||
PaymentVoucherCoaExpenseID = '{$payload['CoaExpenseID']}',
|
||||
PaymentVoucherCoaTemporaryID = '{$payload['CoaTemporaryID']}',
|
||||
PaymentVoucherTotal = '{$payload['total']}',
|
||||
PaymentVoucherUserID = {$userId},
|
||||
PaymentVoucherLastUpdated = now()
|
||||
WHERE PaymentVoucherID = {$payload['ID']}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("payment voucher update error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "DELETE FROM payment_voucher_detail WHERE PaymentVoucherDetailPaymentVoucherID = {$payload['ID']}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("payment voucher detail delete error", $this->db);
|
||||
exit;
|
||||
}
|
||||
foreach ($payload['details'] as $k => $v) {
|
||||
$sql = "INSERT INTO payment_voucher_detail(
|
||||
PaymentVoucherDetailPaymentVoucherID,
|
||||
PaymentVoucherDetailPurchaseRequestDirectID,
|
||||
PaymentVoucherDetailTotal,
|
||||
PaymentVoucherDetailUserID,
|
||||
PaymentVoucherDetailCreated,
|
||||
PaymentVoucherDetailLastUpdated)
|
||||
VALUES ('{$payload['ID']}',
|
||||
'{$v['PurchaseRequestDirectID']}',
|
||||
'{$v['PurchaseRequestDirectTotalRealitation']}',
|
||||
{$userId},
|
||||
now(),
|
||||
now())";
|
||||
$exec = $this->db->query($sql);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("payment voucher detail insert error", $this->db);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
|
||||
$newUpdate = "SELECT * FROM payment_voucher WHERE PaymentVoucherID = {$payload['ID']} AND PaymentVoucherIsActive = 'Y'";
|
||||
$records = $this->db->query($newUpdate, [])->result_array();
|
||||
|
||||
$result = array("total" => 1, "records" => $records);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function delete()
|
||||
{
|
||||
try {
|
||||
/* if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE payment_voucher SET
|
||||
PaymentVoucherIsActive = 'N'
|
||||
WHERE PaymentVoucherID = {$payload['ID']}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("payment voucher delete error", $this->db);
|
||||
exit;
|
||||
}
|
||||
$sql = "UPDATE payment_voucher_detail SET
|
||||
PaymentVoucherDetailIsActive = 'N'
|
||||
WHERE PaymentVoucherDetailPaymentVoucherID = {$payload['ID']}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("payment voucher detail delete error", $this->db);
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xId" => 0));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function orderRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sqlDetail = "UPDATE payment_voucher_detail SET
|
||||
PaymentVoucherDetailLastUpdated = NOW(),
|
||||
PaymentVoucherDetailLastUpdatedUserID = {$userId}
|
||||
WHERE PaymentVoucherDetailPaymentVoucherID = {$payload["ID"]}
|
||||
AND PaymentVoucherDetailIsActive = 'Y'
|
||||
AND PaymentVoucherDetailStatus = 'Pending'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order payment voucher error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE payment_voucher SET
|
||||
PaymentVoucherStatus = 'Pending',
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PaymentVoucherID = {$payload["ID"]}
|
||||
AND PaymentVoucherIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order payment voucher error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$sql = "SELECT *,
|
||||
ROW_NUMBER() OVER(ORDER BY PaymentVoucherNumber) RowNumber
|
||||
FROM payment_voucher
|
||||
WHERE PaymentVoucherIsActive = 'Y'
|
||||
AND PaymentVoucherUserID = {$userId}
|
||||
AND PaymentVoucherID = {$payload["ID"]}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
$row = [];
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order payment voucher error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$row = $exec->result_array();
|
||||
}
|
||||
$result = array("total" => 1, "records" => $row);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function saveAccountDetail() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$param = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
foreach ($param['detail'] as $key => $obj) {
|
||||
$sql = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailAccount = ?,
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID = ?,
|
||||
PurchaseRequestDirectDetailLastUpdated = NOW()
|
||||
WHERE PurchaseRequestDirectDetailID = ? ";
|
||||
$que = $this->db->query($sql, [
|
||||
$obj['account_number'], $userId,
|
||||
$obj['PurchaseRequestDirectDetailID']
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update account item voucher", $this->db);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$sqlheader = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectAccountFilled = 'Y'
|
||||
WHERE PurchaseRequestDirectID = ?";
|
||||
$queheader = $this->db->query($sqlheader, [$param['PRDID']]);
|
||||
if (!$queheader) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] update header status account is filled", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("[Success]");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getPurchaseUpdate()
|
||||
{
|
||||
try {
|
||||
// if (!$this->isLogin) {
|
||||
// $this->sys_error("Invalid Token");
|
||||
// }
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$query = "SELECT *, 'N' as flag_isadd
|
||||
FROM purchase_request_direct
|
||||
WHERE PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestDirectApprovedBy IS NOT NULL
|
||||
AND PurchaseRequestDirectM_BranchCode = '{$payload["branchcode"]}'";
|
||||
$exec = $this->db->query($query, []);
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select request", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
// print_r($rows);
|
||||
// exit;
|
||||
|
||||
foreach ($rows as $k => $v) {
|
||||
$PurchaseRequestDirectID = $v["PurchaseRequestDirectID"];
|
||||
$sql = "SELECT *
|
||||
FROM payment_voucher_detail
|
||||
WHERE PaymentVoucherDetailIsActive = 'Y'
|
||||
AND PaymentVoucherDetailPurchaseRequestDirectID = {$PurchaseRequestDirectID}";
|
||||
$qry = $this->db->query($sql, []);
|
||||
if ($qry) {
|
||||
$rows_detail = $qry->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
// print_r($rows_detail);
|
||||
// exit;
|
||||
|
||||
if (count($rows_detail) > 0) {
|
||||
$rows[$k]['flag_isadd'] = 'Y';
|
||||
}
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getPurchaseUpdateNew()
|
||||
{
|
||||
try {
|
||||
// if (!$this->isLogin) {
|
||||
// $this->sys_error("Invalid Token");
|
||||
// }
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$query = "SELECT *, 'N' as flag_isadd
|
||||
FROM purchase_request_direct
|
||||
WHERE PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestDirectApprovedBy IS NOT NULL
|
||||
AND PurchaseRequestDirectM_BranchCode = '{$payload["branchcode"]}'
|
||||
AND PurchaseRequestDirectID not in (
|
||||
select PaymentVoucherDetailPurchaseRequestDirectID
|
||||
from payment_voucher
|
||||
JOIN payment_voucher_detail ON PaymentVoucherDetailPaymentVoucherID = PaymentVoucherID AND PaymentVoucherDetailIsActive = 'Y'
|
||||
where PaymentVoucherIsActive = 'Y' AND
|
||||
PaymentVoucherDetailPaymentVoucherID <> '{$payload["ID"]}' AND
|
||||
PaymentVoucherM_BranchCode = '{$payload["branchcode"]}'
|
||||
|
||||
union
|
||||
select PaymentVoucherDetailPurchaseRequestDirectID
|
||||
from payment_voucher
|
||||
JOIN payment_voucher_detail ON PaymentVoucherDetailPaymentVoucherID = PaymentVoucherID AND PaymentVoucherDetailIsActive = 'Y'
|
||||
where PaymentVoucherIsActive = 'Y' AND
|
||||
PaymentVoucherDetailPaymentVoucherID = '{$payload["ID"]}' AND
|
||||
PaymentVoucherM_BranchCode = '{$payload["branchcode"]}'
|
||||
|
||||
|
||||
)
|
||||
UNION
|
||||
SELECT purchase_request_direct.*, 'Y' as flag_isadd
|
||||
FROM payment_voucher_detail
|
||||
JOIN purchase_request_direct ON PurchaseRequestDirectID = PaymentVoucherDetailPurchaseRequestDirectID
|
||||
WHERE PaymentVoucherDetailIsActive = 'Y' AND PaymentVoucherDetailPaymentVoucherID = '{$payload["ID"]}'";
|
||||
$exec = $this->db->query($query, []);
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select request", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function moveToKasir() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$param = $this->sys_input;
|
||||
|
||||
$sql = "UPDATE payment_voucher SET
|
||||
PaymentVoucherStatus = 'Draft'
|
||||
WHERE PaymentVoucherID = ?";
|
||||
$que = $this->db->query($sql, $param['ID']);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] edit voucher status to draft");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("Success");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
class PurchaseRequestDirectAdjusment extends MY_Controller {
|
||||
var $db;
|
||||
public function index() {
|
||||
echo "Purchase Request Direct Adjustment";
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function search() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$param = $this->sys_input;
|
||||
|
||||
$keyword = '%';
|
||||
if ($param['search'] != '') {
|
||||
$keyword = $param['search'] . '%';
|
||||
}
|
||||
|
||||
$sql = "SELECT pv.* ,
|
||||
M_BranchID,
|
||||
M_BranchCode,
|
||||
M_BranchName,
|
||||
CONCAT(cs.coaAccountNo, ' | ', cs.coaDescription) as CoaSource,
|
||||
CONCAT(ct.coaAccountNo, ' | ', ct.coaDescription) as CoaTemporary,
|
||||
cs.coaDescription coaDescriptionSource,
|
||||
ct.coaDescription coaDescriptionTemporary,
|
||||
cs.coaAccountNo coaAccountNoSource,
|
||||
ct.coaAccountNo coaAccountNoTemporary
|
||||
FROM payment_voucher as pv
|
||||
LEFT JOIN m_branch ON M_BranchCode = PaymentVoucherM_BranchCode
|
||||
JOIN coa cs ON cs.coaID = PaymentVoucherCoaSourceID
|
||||
JOIN coa ct ON ct.coaID = PaymentVoucherCoaTemporaryID
|
||||
WHERE PaymentVoucherIsActive = 'Y'
|
||||
AND DATE(PaymentVoucherDate) BETWEEN DATE(?) AND DATE(?)
|
||||
AND PaymentVoucherNumber LIKE ?";
|
||||
$que = $this->db->query($sql, [$param['startdate'], $param['enddate'], $keyword]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get data voucher");
|
||||
exit;
|
||||
}
|
||||
$data = $que->result_array();
|
||||
$result = array(
|
||||
'records' => $data
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function searchDetail() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$param = $this->sys_input;
|
||||
|
||||
$sql = "SELECT payment_voucher_detail.*,
|
||||
ROW_NUMBER() OVER(ORDER BY PaymentVoucherDetailID) RowNumber,
|
||||
PurchaseRequestDirectID,
|
||||
PurchaseRequestDirectNumber,
|
||||
PurchaseRequestDirectTotalRealitation,
|
||||
PurchaseRequestDirectAdjustment,
|
||||
PurchaseRequestDirectAdjustmentAccount,
|
||||
PurchaseRequestDirectAccountFilled
|
||||
FROM payment_voucher_detail
|
||||
LEFT JOIN purchase_request_direct ON PurchaseRequestDirectID = PaymentVoucherDetailPurchaseRequestDirectID
|
||||
WHERE PaymentVoucherDetailIsActive = 'Y'
|
||||
AND PaymentVoucherDetailPaymentVoucherID = ?";
|
||||
$que = $this->db->query($sql, [$param['ID']]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get data voucher");
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$result = array(
|
||||
'records' => $que->result_array()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function updateAdjustment() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$param = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
|
||||
$this->db->trans_begin();
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectAdjustment = ?,
|
||||
PurchaseRequestDirectAdjustmentAccount = ?,
|
||||
PurchaseRequestLastUpdatedUserID = ?,
|
||||
PurchaseRequestLastUpdated = NOW()
|
||||
WHERE PurchaseRequestDirectID = ?";
|
||||
$que = $this->db->query($sql, [
|
||||
$param['price_adj'], $param['account_adj'],
|
||||
$user['M_UserID'], $param['prd_id']
|
||||
]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] get data voucher");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok('success');
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function approveRealisasi() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$param = $this->sys_input;
|
||||
|
||||
$this->db->trans_begin();
|
||||
$sql = "UPDATE payment_voucher SET
|
||||
PaymentVoucherRealitationApproved = 'Y'
|
||||
WHERE PaymentVoucherID = ?";
|
||||
$que = $this->db->query($sql, [$param['ID']]);
|
||||
if (!$que) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("[Error] aprrove realisasi");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("Success approve realisasi");
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getListAccount() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT *
|
||||
FROM coa
|
||||
WHERE coaIsActive = 'Y'
|
||||
AND coaIsInput = 'Y'
|
||||
AND coaAccountNo LIKE '111%'
|
||||
ORDER BY coaAccountNo ASC";
|
||||
$que = $this->db->query($sql, []);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get listing of accounts");
|
||||
exit;
|
||||
}
|
||||
$data = $que->result_array();
|
||||
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
43
application/controllers/mockup/purchase/faktur/Faktur.http
Normal file
43
application/controllers/mockup/purchase/faktur/Faktur.http
Normal file
@@ -0,0 +1,43 @@
|
||||
@host = https://accone.aplikasi.web.id/one-api/mockup/purchase/faktur/Faktur
|
||||
@token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjM4MiIsIk1fVXNlclVzZXJuYW1lIjoia2FjYWJhZGl0eWEiLCJNX1VzZXJHcm91cERhc2hib2FyZCI6Im9uZS11aVwvdGVzdFwvdnVleFwvYWNjb25lLXB1cmNoYXNlLXJlcXVlc3Qta2FjYWIiLCJNX1VzZXJEZWZhdWx0VF9TYW1wbGVTdGF0aW9uSUQiOiIwIiwiTV9TdGFmZk5hbWUiOiJLYWNhYiBBZGl0eWEiLCJpc19jb3VyaWVyIjoiTiIsInRpbWVfYXV0b2xvZ291dCI6IjEyMCIsIk1fVXNlckxvY2F0aW9uSUQiOiIzOSIsIk1fVXNlckxvY2F0aW9uRmxhZyI6IkIiLCJTX1JlZ2lvbmFsTmFtZSI6IlN1cmFiYXlhIFJheWEiLCJTX1JlZ2lvbmFsSUQiOiI2IiwiTV9CcmFuY2hOYW1lIjoiUHJhbWl0YSBBZGl0eWF3YXJtYW4iLCJNX0JyYW5jaENvZGUiOiJMQSIsIk1fQnJhbmNoSUQiOiIxNCIsImxvZ2luTGV2ZWwiOiJicmFuY2giLCJNX0JyYW5jaENvbXBhbnlJRCI6IjEiLCJNX0JyYW5jaENvbXBhbnlOYW1lIjoiUFQgUFJBTUlUQSIsImlwIjoiMTM5LjAuOTcuMTA4IiwiYWdlbnQiOiJNb3ppbGxhXC81LjAgKFgxMTsgTGludXggeDg2XzY0OyBydjoxMzkuMCkgR2Vja29cLzIwMTAwMTAxIEZpcmVmb3hcLzEzOS4wIiwidmVyc2lvbiI6InYyIiwibGFzdC1sb2dpbiI6IjIwMjUtMDctMDEgMTQ6MjQ6MzciLCJNX1NhdGVsbGl0ZUlEIjowfQ.NCSVDCZiAFZJIB8KkekX-Jw9ANZD5cpH7xfec7q7jrg"
|
||||
|
||||
### Lookup RO
|
||||
POST {{host}}/LookupRO
|
||||
|
||||
{
|
||||
"poID":"15",
|
||||
"supplierID":"3",
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
### Lookup Item RO
|
||||
POST {{host}}/LookupItemRO
|
||||
|
||||
{
|
||||
"poID":"15",
|
||||
"roID":"16",
|
||||
"name":"",
|
||||
"currpage":1,
|
||||
"token" : {{token}}
|
||||
}
|
||||
|
||||
### Lookup List RO
|
||||
POST {{host}}/LookupListFaktur
|
||||
|
||||
{
|
||||
"page":1,
|
||||
"nomor":"",
|
||||
"status":"All",
|
||||
"enddate":"2025-07-01",
|
||||
"date":"2025-07-01",
|
||||
"supplier":"0",
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
### Lookup PO
|
||||
POST {{host}}/LookupPO
|
||||
|
||||
{
|
||||
"supID" : 6,
|
||||
"token" : {{token}}
|
||||
}
|
||||
1550
application/controllers/mockup/purchase/faktur/Faktur.php
Normal file
1550
application/controllers/mockup/purchase/faktur/Faktur.php
Normal file
File diff suppressed because it is too large
Load Diff
1582
application/controllers/mockup/purchase/faktur/Fakturv2.php
Normal file
1582
application/controllers/mockup/purchase/faktur/Fakturv2.php
Normal file
File diff suppressed because it is too large
Load Diff
1704
application/controllers/mockup/purchase/faktur/Fakturv3.php
Normal file
1704
application/controllers/mockup/purchase/faktur/Fakturv3.php
Normal file
File diff suppressed because it is too large
Load Diff
1786
application/controllers/mockup/purchase/faktur/Fakturv4.php
Normal file
1786
application/controllers/mockup/purchase/faktur/Fakturv4.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,644 @@
|
||||
<?php
|
||||
class PurchaseRequestListing extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
echo "LISTING PURCHASE REQUEST";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function list_purchaserequest_old19Juni2025()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$para = $this->sys_input;
|
||||
$startdate = $para["startdate"];
|
||||
$enddate = $para["enddate"];
|
||||
$regional = $para["regional"];
|
||||
|
||||
$branch = $para['branch'];
|
||||
$cabang = "";
|
||||
if ($branch == "ALL" || $branch == "") {
|
||||
$cabang = "%%";
|
||||
} else {
|
||||
$cabang = "%" . $branch . "%";
|
||||
}
|
||||
|
||||
$f_stat = [];
|
||||
$status = $para["status"];
|
||||
switch ($status) {
|
||||
case 'READ':
|
||||
$f_stat = ["Read", "X"];
|
||||
break;
|
||||
case 'NEW':
|
||||
$f_stat = ["Approved", "X"];
|
||||
break;
|
||||
default:
|
||||
$f_stat = ["Approved", "Read"];
|
||||
break;
|
||||
}
|
||||
|
||||
$currpage = $para["currpage"];
|
||||
$page = 0;
|
||||
$limit = 10;
|
||||
if ($currpage > 0) {
|
||||
$page = ($currpage - 1) * $limit;
|
||||
}
|
||||
|
||||
$sqltotal = "SELECT COUNT(DISTINCT PurchaseRequestDetailID) as total
|
||||
FROM purchase_request
|
||||
JOIN purchase_request_detail ON PurchaseRequestDetailPurchaseRequestID = PurchaseRequestID
|
||||
AND PurchaseRequestDetailIsActive = 'Y'
|
||||
JOIN s_regional ON S_RegionalID = PurchaseRequestS_RegionalID
|
||||
AND S_RegionalIsActive = 'Y'
|
||||
JOIN m_item ON M_ItemID = PurchaseRequestDetailM_ItemID
|
||||
AND M_ItemIsActive = 'Y'
|
||||
LEFT JOIN m_branch ON M_BranchCode = PurchaseRequestM_BranchCode
|
||||
AND M_BranchIsActive = 'Y'
|
||||
LEFT JOIN warehouse ON WarehouseS_RegionalID = PurchaseRequestS_RegionalID
|
||||
AND WarehouseIsActive = 'Y'
|
||||
AND (WarehouseIsTransit != 'Y' OR WarehouseIsTransit IS NULL)
|
||||
LEFT JOIN stock ON StockItemId = M_ItemID
|
||||
AND StockWarehouseID = warehouse.WarehouseID
|
||||
LEFT JOIN purchase_request_flag ON PurchaseRequestFlagPurchaseRequestDetailID = PurchaseRequestDetailID
|
||||
AND PurchaseRequestFlagIsActive = 'Y'
|
||||
AND PurchaseRequestFlagIsClosed = 'N'
|
||||
WHERE PurchaseRequestDetailStatus IN (?,?)
|
||||
AND PurchaseRequestDate >= DATE(?)
|
||||
AND PurchaseRequestDate <= DATE(?)
|
||||
AND PurchaseRequestS_RegionalID = ?
|
||||
AND (? = '%%' OR
|
||||
(PurchaseRequestM_BranchCode LIKE ? OR
|
||||
(PurchaseRequestM_BranchCode IS NULL AND
|
||||
? = '%%')))
|
||||
-- GROUP BY PurchaseRequestDetailID
|
||||
ORDER BY
|
||||
PurchaseRequestDetailStatus ASC,
|
||||
PurchaseRequestDetailID DESC,
|
||||
PurchaseRequestDate DESC,
|
||||
PurchaseRequestFlagID DESC
|
||||
";
|
||||
$qrytot = $this->db->query($sqltotal, [
|
||||
$f_stat[0],
|
||||
$f_stat[1],
|
||||
$startdate,
|
||||
$enddate,
|
||||
$regional,
|
||||
$cabang,
|
||||
$cabang,
|
||||
$cabang
|
||||
]);
|
||||
$total = $qrytot->result_array()[0]['total'];
|
||||
|
||||
$sqldata = "SELECT
|
||||
COALESCE(PurchaseRequestFlagID, 'new') as PurchaseRequestFlagID,
|
||||
PurchaseRequestDate, PurchaseRequestNumber,
|
||||
S_RegionalID, S_RegionalName,
|
||||
COALESCE(M_BranchCode, '') AS M_BranchCode,
|
||||
COALESCE(M_BranchName, '') AS M_BranchName,
|
||||
PurchaseRequestDetailID, M_ItemID,
|
||||
PurchaseRequestDetailIsCito,
|
||||
M_ItemDesc, PurchaseRequestDetailQty,
|
||||
COALESCE(SUM(CASE WHEN warehouse.WarehouseID IS NOT NULL AND stock.StockItemId IS NOT NULL THEN stock.StockQty ELSE 0 END), 0) as StockQty,
|
||||
COALESCE(warehouse.WarehouseID, '') as StockWarehouseID,
|
||||
PurchaseRequestDetailStatus,
|
||||
COALESCE(PurchaseRequestFlagStatus, '') as PurchaseRequestFlagStatus
|
||||
FROM purchase_request
|
||||
JOIN purchase_request_detail ON PurchaseRequestDetailPurchaseRequestID = PurchaseRequestID
|
||||
AND PurchaseRequestDetailIsActive = 'Y'
|
||||
JOIN s_regional ON S_RegionalID = PurchaseRequestS_RegionalID
|
||||
AND S_RegionalIsActive = 'Y'
|
||||
JOIN m_item ON M_ItemID = PurchaseRequestDetailM_ItemID
|
||||
AND M_ItemIsActive = 'Y'
|
||||
LEFT JOIN m_branch ON M_BranchCode = PurchaseRequestM_BranchCode
|
||||
AND M_BranchIsActive = 'Y'
|
||||
LEFT JOIN warehouse ON WarehouseS_RegionalID = PurchaseRequestS_RegionalID
|
||||
AND WarehouseIsActive = 'Y'
|
||||
AND (WarehouseIsTransit != 'Y' OR WarehouseIsTransit IS NULL)
|
||||
LEFT JOIN stock ON StockItemId = M_ItemID
|
||||
AND StockWarehouseID = warehouse.WarehouseID
|
||||
LEFT JOIN purchase_request_flag ON PurchaseRequestFlagPurchaseRequestDetailID = PurchaseRequestDetailID
|
||||
AND PurchaseRequestFlagIsActive = 'Y'
|
||||
AND PurchaseRequestFlagIsClosed = 'N'
|
||||
WHERE PurchaseRequestDetailStatus IN (?,?)
|
||||
AND PurchaseRequestDate >= DATE(?)
|
||||
AND PurchaseRequestDate <= DATE(?)
|
||||
AND PurchaseRequestS_RegionalID = ?
|
||||
AND (? = '%%' OR
|
||||
(PurchaseRequestM_BranchCode LIKE ? OR
|
||||
(PurchaseRequestM_BranchCode IS NULL AND
|
||||
? = '%%')))
|
||||
GROUP BY PurchaseRequestDetailID
|
||||
ORDER BY PurchaseRequestDetailStatus ASC,
|
||||
PurchaseRequestDetailID DESC,
|
||||
PurchaseRequestDate DESC,
|
||||
PurchaseRequestFlagID DESC
|
||||
LIMIT ? OFFSET ?";
|
||||
$qrydata = $this->db->query($sqldata, [
|
||||
$f_stat[0],
|
||||
$f_stat[1],
|
||||
$startdate,
|
||||
$enddate,
|
||||
$regional,
|
||||
$cabang,
|
||||
$cabang,
|
||||
$cabang,
|
||||
$limit,
|
||||
$page
|
||||
]);
|
||||
$data = $qrydata->result_array();
|
||||
|
||||
$result = array(
|
||||
"records" => $data,
|
||||
"total" => $total
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $ex) {
|
||||
$message = $ex->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refactor 18 Juni 2025 by Mario
|
||||
* Whats new:
|
||||
* > Perhitungan stok mempertimbangkan:
|
||||
* > - Stock hanya diambil dari gudang regional
|
||||
* > - Stock hanya diambil dari gudang default (untuk handle kasus jakarta ada 2 gudang regional)
|
||||
* > - Mempertimbangkan unitItem sebelum menjumlahkan kuantitas stok karena ada PR dengan unit berbeda
|
||||
* > - Menghitung stok dengan subquery daripada join
|
||||
* > - Memperhatikan StockED untuk ItemCategoryID == 1 (Persediaan), jika ItemID dan ItemUnitID sama maka jumlah semua stok dari Gudang Regional selama StockED >= hari ini
|
||||
*/
|
||||
public function list_purchaserequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$para = $this->sys_input;
|
||||
$startdate = $para["startdate"];
|
||||
$enddate = $para["enddate"];
|
||||
$regional = $para["regional"];
|
||||
|
||||
$branch = $para['branch'];
|
||||
$cabang = "";
|
||||
if ($branch == "ALL" || $branch == "") {
|
||||
$cabang = "%%";
|
||||
} else {
|
||||
$cabang = "%" . $branch . "%";
|
||||
}
|
||||
|
||||
$f_stat = [];
|
||||
$status = $para["status"];
|
||||
switch ($status) {
|
||||
case 'READ':
|
||||
$f_stat = ["Read", "X"];
|
||||
break;
|
||||
case 'NEW':
|
||||
$f_stat = ["Approved", "X"];
|
||||
break;
|
||||
default:
|
||||
$f_stat = ["Approved", "Read"];
|
||||
break;
|
||||
}
|
||||
|
||||
$currpage = $para["currpage"];
|
||||
$page = 0;
|
||||
$limit = 10;
|
||||
if ($currpage > 0) {
|
||||
$page = ($currpage - 1) * $limit;
|
||||
}
|
||||
|
||||
$sqltotal = "SELECT COUNT(DISTINCT PurchaseRequestDetailID) as total
|
||||
FROM purchase_request_detail
|
||||
JOIN purchase_request ON PurchaseRequestDetailPurchaseRequestID = PurchaseRequestID
|
||||
AND PurchaseRequestDetailIsActive = 'Y'
|
||||
JOIN s_regional ON S_RegionalID = PurchaseRequestS_RegionalID
|
||||
AND S_RegionalIsActive = 'Y'
|
||||
JOIN m_item ON M_ItemID = PurchaseRequestDetailM_ItemID
|
||||
AND M_ItemIsActive = 'Y'
|
||||
LEFT JOIN m_branch ON M_BranchCode = PurchaseRequestM_BranchCode
|
||||
AND M_BranchIsActive = 'Y'
|
||||
LEFT JOIN itemunit unit_req ON unit_req.ItemUnitID = PurchaseRequestDetailItemUnitID
|
||||
AND unit_req.ItemUnitIsActive = 'Y'
|
||||
LEFT JOIN purchase_request_flag ON PurchaseRequestFlagPurchaseRequestDetailID = PurchaseRequestDetailID
|
||||
AND PurchaseRequestFlagIsActive = 'Y'
|
||||
AND PurchaseRequestFlagIsClosed = 'N'
|
||||
WHERE PurchaseRequestDetailStatus IN (?,?)
|
||||
AND PurchaseRequestDate >= DATE(?)
|
||||
AND PurchaseRequestDate <= DATE(?)
|
||||
AND PurchaseRequestS_RegionalID = ?
|
||||
AND (? = '%%' OR
|
||||
(PurchaseRequestM_BranchCode LIKE ? OR
|
||||
(PurchaseRequestM_BranchCode IS NULL AND
|
||||
? = '%%')))";
|
||||
$qrytot = $this->db->query($sqltotal, [
|
||||
$f_stat[0],
|
||||
$f_stat[1],
|
||||
$startdate,
|
||||
$enddate,
|
||||
$regional,
|
||||
$cabang,
|
||||
$cabang,
|
||||
$cabang
|
||||
]);
|
||||
$total = $qrytot->result_array()[0]['total'];
|
||||
|
||||
$sqldata = "SELECT
|
||||
COALESCE(PurchaseRequestFlagID, 'new') as PurchaseRequestFlagID,
|
||||
PurchaseRequestDate, PurchaseRequestNumber,
|
||||
S_RegionalID, S_RegionalName,
|
||||
COALESCE(M_BranchCode, '') AS M_BranchCode,
|
||||
COALESCE(M_BranchName, '') AS M_BranchName,
|
||||
PurchaseRequestDetailID, M_ItemID,
|
||||
PurchaseRequestDetailIsCito,
|
||||
M_ItemDesc, PurchaseRequestDetailQty,
|
||||
unit_req.ItemUnitName AS UnitRequest,
|
||||
unit_req.ItemUnitID AS UnitIDRequest,
|
||||
PurchaseRequestDetailStatus,
|
||||
COALESCE(PurchaseRequestFlagStatus, '') as PurchaseRequestFlagStatus
|
||||
FROM purchase_request_detail
|
||||
JOIN purchase_request ON PurchaseRequestDetailPurchaseRequestID = PurchaseRequestID
|
||||
AND PurchaseRequestDetailIsActive = 'Y'
|
||||
JOIN s_regional ON S_RegionalID = PurchaseRequestS_RegionalID
|
||||
AND S_RegionalIsActive = 'Y'
|
||||
LEFT JOIN m_branch ON M_BranchCode = PurchaseRequestM_BranchCode
|
||||
AND M_BranchIsActive = 'Y'
|
||||
JOIN m_item ON M_ItemID = PurchaseRequestDetailM_ItemID
|
||||
AND M_ItemIsActive = 'Y'
|
||||
JOIN itemunit unit_req ON unit_req.ItemUnitID = PurchaseRequestDetailItemUnitID
|
||||
AND unit_req.ItemUnitIsActive = 'Y'
|
||||
LEFT JOIN warehouse ON WarehouseS_RegionalID = PurchaseRequestS_RegionalID
|
||||
AND WarehouseIsActive = 'Y'
|
||||
AND (WarehouseIsTransit != 'Y' OR WarehouseIsTransit IS NULL)
|
||||
AND WarehouseM_BranchID = 0
|
||||
AND WarehouseIsDefault = 'Y'
|
||||
LEFT JOIN purchase_request_flag ON PurchaseRequestFlagPurchaseRequestDetailID = PurchaseRequestDetailID
|
||||
AND PurchaseRequestFlagIsActive = 'Y'
|
||||
AND PurchaseRequestFlagIsClosed = 'N'
|
||||
WHERE PurchaseRequestDetailStatus IN (?,?)
|
||||
AND PurchaseRequestDate >= DATE(?)
|
||||
AND PurchaseRequestDate <= DATE(?)
|
||||
AND PurchaseRequestS_RegionalID = ?
|
||||
AND (? = '%%' OR
|
||||
(PurchaseRequestM_BranchCode LIKE ? OR
|
||||
(PurchaseRequestM_BranchCode IS NULL AND
|
||||
? = '%%')))
|
||||
ORDER BY PurchaseRequestDetailStatus ASC,
|
||||
PurchaseRequestDetailID DESC,
|
||||
PurchaseRequestDate DESC,
|
||||
PurchaseRequestFlagID DESC
|
||||
LIMIT ? OFFSET ?";
|
||||
$qrydata = $this->db->query($sqldata, [
|
||||
$f_stat[0],
|
||||
$f_stat[1],
|
||||
$startdate,
|
||||
$enddate,
|
||||
$regional,
|
||||
$cabang,
|
||||
$cabang,
|
||||
$cabang,
|
||||
$limit,
|
||||
$page
|
||||
]);
|
||||
if (!$qrydata) {
|
||||
throw new Exception(json_encode($this->db->error()));
|
||||
}
|
||||
|
||||
// TODO: Hapus Last Query jika tidak diperlukan
|
||||
// $lastQuery = $this->db->last_query();
|
||||
$data = $qrydata->result_array();
|
||||
|
||||
// For each PR Detail, fetch the stock data across all units
|
||||
foreach ($data as &$row) {
|
||||
$stockSql = "SELECT
|
||||
SUM(s.StockQty) as QtyTotal,
|
||||
u.ItemUnitName,
|
||||
s.StockItemUnitID
|
||||
FROM stock s
|
||||
JOIN warehouse w ON s.StockWarehouseID = w.WarehouseID
|
||||
JOIN itemunit u ON s.StockItemUnitID = u.ItemUnitID
|
||||
WHERE s.StockItemId = ?
|
||||
AND w.WarehouseS_RegionalID = ?
|
||||
AND w.WarehouseIsActive = 'Y'
|
||||
AND (w.WarehouseIsTransit != 'Y' OR w.WarehouseIsTransit IS NULL)
|
||||
AND w.WarehouseM_BranchID = 0
|
||||
AND w.WarehouseIsDefault = 'Y'
|
||||
AND (
|
||||
? != 1
|
||||
OR (? = 1 AND (s.StockED IS NULL OR s.StockED >= CURDATE()))
|
||||
)
|
||||
GROUP BY s.StockItemUnitID, u.ItemUnitName";
|
||||
|
||||
$stockQry = $this->db->query($stockSql, [
|
||||
$row['M_ItemID'],
|
||||
$row['S_RegionalID'],
|
||||
$row['PurchaseRequestItemCategoryID'] ?? 0,
|
||||
$row['PurchaseRequestItemCategoryID'] ?? 0
|
||||
]);
|
||||
|
||||
if (!$stockQry) {
|
||||
throw new Exception(json_encode($this->db->error()));
|
||||
}
|
||||
|
||||
// Kalau item belum ada di stock, returnnya []
|
||||
|
||||
$row['StockQtyArray'] = $stockQry->result_array();
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $data,
|
||||
// "lastQuery" => $lastQuery,
|
||||
"total" => $total
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $ex) {
|
||||
$message = $ex->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function listing_regional()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$search = "%" . $prm['search'] . "%";
|
||||
|
||||
$sql = "SELECT S_RegionalID, S_RegionalName
|
||||
FROM s_regional WHERE S_RegionalIsActive = 'Y' AND S_RegionalName LIKE ?";
|
||||
$query = $this->db->query($sql, [$search]);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("error get listing regional");
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $query->result_array();
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"total" => sizeof($rows)
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $ex) {
|
||||
$message = $ex->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function listing_branch()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$regID = $prm['regionalID'];
|
||||
|
||||
$sql = "SELECT
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM m_branch
|
||||
WHERE M_BranchS_RegionalID = ? AND M_BranchIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$regID]);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("error get branch based on regional");
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $query->result_array();
|
||||
$result = array(
|
||||
"result" => $rows,
|
||||
"total" => sizeof($rows)
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $ex) {
|
||||
$message = $ex->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function insertstatus()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$prm = $this->sys_input;
|
||||
$reqnumber = $prm['reqnumber'];
|
||||
$reqdetailid = $prm['reqdetailid'];
|
||||
$regionalid = $prm['regionalid'];
|
||||
$branchcode = $prm['branchcode'];
|
||||
$qty = $prm['qty'];
|
||||
$stock = $prm['stock'];
|
||||
$status = $prm['status'];
|
||||
$UnitIDRequest = $prm['UnitIDRequest'];
|
||||
|
||||
/* Validasi ItemUnit Request dengan Stock */
|
||||
$stock = $this->calculateStockByItemUnitReq($stock, $UnitIDRequest);
|
||||
|
||||
$sqlin = "INSERT INTO purchase_request_flag (
|
||||
PurchaseRequestFlagPurchaseRequestDetailID,
|
||||
PurchaseRequestFlagS_RegionalID,
|
||||
PurchaseRequestFlagM_BranchCode,
|
||||
PurchaseRequestFlagQty,
|
||||
PurchaseRequestFlagQtyRest,
|
||||
PurchaseRequestFlagStatus,
|
||||
PurchaseRequestFlagUserID,
|
||||
PurchaseRequestFlagCreated
|
||||
) VALUES (?,?,?,?,?,?,?,NOW())";
|
||||
$query = $this->db->query($sqlin, [
|
||||
$reqdetailid,
|
||||
$regionalid,
|
||||
$branchcode,
|
||||
$qty,
|
||||
$qty,
|
||||
$status,
|
||||
$userid
|
||||
]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error insert status request");
|
||||
exit;
|
||||
}
|
||||
|
||||
$reqflagid = $this->db->insert_id();
|
||||
$sqlget = "SELECT * FROM purchase_request_flag WHERE PurchaseRequestFlagID = ?";
|
||||
$queget = $this->db->query($sqlget, [$reqdetailid]);
|
||||
if (!$queget) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error get latest inserted flag");
|
||||
exit;
|
||||
}
|
||||
$data = $queget->result_array()[0];
|
||||
$json = json_encode($data);
|
||||
|
||||
$sqlog = "INSERT INTO acc_one_log.purchaserequestflag_log (
|
||||
PurchaseRequestFlagLogPurchaseRequestFlagID,
|
||||
PurchaseRequestFlagLogStatus,
|
||||
PurchaseRequestFlagLogQty,
|
||||
PurchaseRequestFlagLogStock,
|
||||
PurchaseRequestFlagLogJson,
|
||||
PurchaseRequestFlagLogUserID,
|
||||
PurchaseRequestFlagLogCreated
|
||||
) VALUES (?, ?, ?, ?, ?, ?, NOW())";
|
||||
$quelog = $this->db->query($sqlog, [$reqflagid, $status, $qty, $stock, $json, $userid]);
|
||||
if (!$quelog) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error insert log purchase request flag");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sqlread = "UPDATE purchase_request_detail SET
|
||||
PurchaseRequestDetailStatus = 'Read'
|
||||
WHERE PurchaseRequestDetailID = ?";
|
||||
$queread = $this->db->query($sqlread, [$reqdetailid]);
|
||||
if (!$queread) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error update status purchase request detail to read");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sqlpart = "UPDATE purchase_request SET
|
||||
PurchaseRequestStatus = 'Partial'
|
||||
WHERE PurchaseRequestRefNumber = ?";
|
||||
$quepart = $this->db->query($sqlpart, [$reqnumber]);
|
||||
if (!$quepart) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error update status purchase request to partial");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("Success insert status request");
|
||||
|
||||
} catch (\Throwable $ex) {
|
||||
$message = $ex->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function changestatus()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$reqnumber = $prm['reqnumber'];
|
||||
$reqflagid = $prm['requestflagid'];
|
||||
$reqdetailid = $prm['reqdetailid'];
|
||||
$regionalid = $prm['regionalid'];
|
||||
$branchcode = $prm['branchcode'];
|
||||
$reqqty = $prm['qty'];
|
||||
$reqstock = $prm['stock'];
|
||||
$reqstatus = $prm['status'];
|
||||
$UnitIDRequest = $prm['UnitIDRequest'];
|
||||
|
||||
/* Validasi ItemUnit Request dengan Stock */
|
||||
$stock = $this->calculateStockByItemUnitReq($reqstock, $UnitIDRequest);
|
||||
|
||||
$sqlcha = "UPDATE purchase_request_flag SET
|
||||
PurchaseRequestFlagPurchaseRequestDetailID = ?,
|
||||
PurchaseRequestFlagS_RegionalID = ?,
|
||||
PurchaseRequestFlagM_BranchCode = ?,
|
||||
PurchaseRequestFlagQty = ?,
|
||||
PurchaseRequestFlagQtyRest = ?,
|
||||
PurchaseRequestFlagStatus = ?,
|
||||
PurchaseRequestFlagUserID = ?,
|
||||
PurchaseRequestFlagLastUpdated = NOW()
|
||||
WHERE PurchaseRequestFlagID = ?";
|
||||
$query = $this->db->query($sqlcha, [
|
||||
$reqdetailid,
|
||||
$regionalid,
|
||||
$branchcode,
|
||||
$reqqty,
|
||||
$reqqty,
|
||||
$reqstatus,
|
||||
$userid,
|
||||
$reqflagid
|
||||
]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error update status flag requset");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sqlget = "SELECT * FROM purchase_request_flag WHERE PurchaseRequestFlagID = ?";
|
||||
$queget = $this->db->query($sqlget, [$reqflagid]);
|
||||
if (!$queget) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error get data change");
|
||||
exit;
|
||||
}
|
||||
$data = $queget->result_array()[0];
|
||||
$json = json_encode($data);
|
||||
|
||||
$sqlog = "INSERT INTO acc_one_log.purchaserequestflag_log (
|
||||
PurchaseRequestFlagLogPurchaseRequestFlagID,
|
||||
PurchaseRequestFlagLogStatus,
|
||||
PurchaseRequestFlagLogQty,
|
||||
PurchaseRequestFlagLogStock,
|
||||
PurchaseRequestFlagLogJson,
|
||||
PurchaseRequestFlagLogUserID,
|
||||
PurchaseRequestFlagLogCreated
|
||||
) VALUES (?, ?, ?, ?, ?, ?, NOW())";
|
||||
$quelog = $this->db->query($sqlog, [$reqflagid, $reqstatus, $reqqty, $stock, $json, $userid]);
|
||||
if (!$quelog) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("error insert log purchase request flag");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$this->sys_ok("success");
|
||||
} catch (\Throwable $ex) {
|
||||
$message = $ex->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
private function calculateStockByItemUnitReq(array $stock, string $UnitIDRequest): int
|
||||
{
|
||||
// Cek $stock empty array atau tidak, jika iya $stok = 0
|
||||
if (!is_array($stock) || empty($stock)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Cari object di $stock di mana StockItemUnitID == $UnitIDRequest,
|
||||
// Jika tidak ada, set $stock = 0
|
||||
$equivalentStock = array_filter($stock, function ($item) use ($UnitIDRequest) {
|
||||
return $item['StockItemUnitID'] == $UnitIDRequest;
|
||||
});
|
||||
|
||||
if (empty($equivalentStock)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return array_values($equivalentStock)[0]['QtyTotal'] ?? 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,355 @@
|
||||
<?php
|
||||
|
||||
class PurchaseRequest extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "Purchase Request/Manager API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
|
||||
$query = "SELECT prd.*, mu.M_UserFullName as M_RequesterFullName
|
||||
FROM purchase_request_direct as prd
|
||||
JOIN m_user as mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectStatus != 'Draft'
|
||||
AND PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestDirectNumber LIKE '%" . $payload["search"] . "%'";
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM purchase_request_direct as prd
|
||||
JOIN m_user as mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectStatus != 'Draft'
|
||||
AND PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestDirectNumber LIKE '%" . $payload["search"] . "%'";
|
||||
|
||||
if ((isset($payload["startDate"]) && isset($payload["endDate"])) && (trim($payload["startDate"]) !== "" && trim($payload["endDate"]) !== "")) {
|
||||
$query .= " AND (PurchaseRequestDirectDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59' OR PurchaseRequestDirectDateUse BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
$queryCount .= " AND (PurchaseRequestDirectDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59' OR PurchaseRequestDirectDateUse BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
}
|
||||
|
||||
if ($payload["status"]) {
|
||||
$query .= " AND PurchaseRequestDirectStatus = {$payload["status"]}";
|
||||
$queryCount .= " AND PurchaseRequestDirectStatus = {$payload["status"]}";
|
||||
}
|
||||
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$numberLimit = 20;
|
||||
$numberOffset = 0;
|
||||
if ($payload["currentPage"] > 0) {
|
||||
$numberOffset = ($payload["currentPage"] - 1) * $numberLimit;
|
||||
}
|
||||
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
$totalPage = ceil($totalCount / $numberLimit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = $query . " ORDER BY PurchaseRequestDirectNumber DESC
|
||||
LIMIT {$numberLimit} OFFSET {$numberOffset}";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $totalPage,
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function searchDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$totalCount = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request detail", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = "SELECT *,
|
||||
ROW_NUMBER() OVER(ORDER BY PurchaseRequestDirectDetailID) RowNumber
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
ORDER BY PurchaseRequestDirectDetailStatus ASC,
|
||||
PurchaseRequestDirectDetailID ASC";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailIsActive = 'N',
|
||||
PurchaseRequestDirectDetailDeleted = NOW(),
|
||||
PurchaseRequestDirectDetailDeletedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailStatus = 'Pending'
|
||||
AND PurchaseRequestDirectDetailID = {$payload['PRDID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("reject request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$sqlTotalPrice = "SELECT SUM(PurchaseRequestDirectDetailTotalEstimationPrice) AS Total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlTotalPrice, []);
|
||||
$total = 0;
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$total = $exec->result_array()[0]["Total"] ?? 0;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectTotalEstimation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xPRDID" => $payload['PRDID']));
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function approveRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailStatus = 'Ordered',
|
||||
PurchaseRequestDirectDetailLastUpdated = NOW(),
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailStatus = 'Pending'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectNote = '{$payload['PRNote']}',
|
||||
PurchaseRequestDirectStatus = 'Approved',
|
||||
PurchaseRequestApprovedDate = NOW(),
|
||||
PurchaseRequestApprovedBy = {$userId},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectStatus = 'Pending'
|
||||
AND PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rowQuery = "SELECT prd.*,
|
||||
mu.M_UserFullName AS M_RequesterFullName
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($rowQuery, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => $exec->result_array());
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function rejectRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectStatus = 'Draft',
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectStatus = 'Pending'
|
||||
AND PurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("reject request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xPRID" => $payload["PRID"]));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function updateDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
$price = 0;
|
||||
|
||||
$sqlPrice = "SELECT PurchaseRequestDirectDetailEstimationPrice AS Price
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailID = {$payload['PRDID']}";
|
||||
$exec = $this->db->query($sqlPrice, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("update amount error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$price = $exec->result_array()[0]["Price"];
|
||||
}
|
||||
|
||||
$PRDTotal = $payload['PRDAmount'] * $price;
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailAmount = {$payload['PRDAmount']},
|
||||
PurchaseRequestDirectDetailTotalRealitationPrice = {$PRDTotal},
|
||||
PurchaseRequestDirectDetailLastUpdated = NOW(),
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailStatus = 'Pending'
|
||||
AND PurchaseRequestDirectDetailID = {$payload['PRDID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("update amount error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("PRDID" => $payload['PRDID']));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,398 @@
|
||||
<?php
|
||||
|
||||
class PurchaseRequestDirect extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "Purchase Request/Manager API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
|
||||
$query = "SELECT prd.*, mu.M_UserFullName as M_RequesterFullName
|
||||
FROM purchase_request_direct as prd
|
||||
JOIN m_user as mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectStatus != 'Draft'
|
||||
AND PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestDirectNumber LIKE '%" . $payload["search"] . "%'";
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM purchase_request_direct as prd
|
||||
JOIN m_user as mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectStatus != 'Draft'
|
||||
AND PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestDirectNumber LIKE '%" . $payload["search"] . "%'";
|
||||
|
||||
if ((isset($payload["startDate"]) && isset($payload["endDate"])) && (trim($payload["startDate"]) !== "" && trim($payload["endDate"]) !== "")) {
|
||||
$query .= " AND (PurchaseRequestDirectDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59' OR PurchaseRequestDirectDateUse BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
$queryCount .= " AND (PurchaseRequestDirectDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59' OR PurchaseRequestDirectDateUse BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
}
|
||||
|
||||
if ($payload["status"]) {
|
||||
$query .= " AND PurchaseRequestDirectStatus = {$payload["status"]}";
|
||||
$queryCount .= " AND PurchaseRequestDirectStatus = {$payload["status"]}";
|
||||
}
|
||||
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$numberLimit = 20;
|
||||
$numberOffset = 0;
|
||||
if ($payload["currentPage"] > 0) {
|
||||
$numberOffset = ($payload["currentPage"] - 1) * $numberLimit;
|
||||
}
|
||||
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
$totalPage = ceil($totalCount / $numberLimit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = $query . " ORDER BY PurchaseRequestDirectNumber DESC
|
||||
LIMIT {$numberLimit} OFFSET {$numberOffset}";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $totalPage,
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function searchDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$totalCount = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request detail", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = "SELECT *,
|
||||
ROW_NUMBER() OVER(ORDER BY PurchaseRequestDirectDetailID) RowNumber
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
ORDER BY PurchaseRequestDirectDetailStatus ASC,
|
||||
PurchaseRequestDirectDetailID ASC";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailIsActive = 'N',
|
||||
PurchaseRequestDirectDetailDeleted = NOW(),
|
||||
PurchaseRequestDirectDetailDeletedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailStatus = 'Pending'
|
||||
AND PurchaseRequestDirectDetailID = {$payload['PRDID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("reject request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$sqlTotalPrice = "SELECT SUM(PurchaseRequestDirectDetailTotalEstimationPrice) AS Total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlTotalPrice, []);
|
||||
$total = 0;
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$total = $exec->result_array()[0]["Total"] ?? 0;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectTotalEstimation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xPRDID" => $payload['PRDID']));
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function approveRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailStatus = 'Ordered',
|
||||
PurchaseRequestDirectDetailLastUpdated = NOW(),
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailStatus = 'Pending'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$total = 0;
|
||||
$query = "SELECT SUM(IF(PurchaseRequestDirectDetailTotalRealitationPrice IS NULL, PurchaseRequestDirectDetailTotalEstimationPrice,PurchaseRequestDirectDetailTotalRealitationPrice)) as total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($query);
|
||||
if ($exec) {
|
||||
$total = $exec->row()->total;
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase_request_direct_detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectNote = '{$payload['PRNote']}',
|
||||
PurchaseRequestDirectStatus = 'Approved',
|
||||
PurchaseRequestDirectApprovedDate = NOW(),
|
||||
PurchaseRequestDirectApprovedBy = {$userId},
|
||||
PurchaseRequestDirectTotalRealitation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectStatus = 'Pending'
|
||||
AND PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rowQuery = "SELECT prd.*,
|
||||
mu.M_UserFullName AS M_RequesterFullName
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($rowQuery, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => $exec->result_array());
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function rejectRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectStatus = 'Draft',
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectStatus = 'Pending'
|
||||
AND PurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("reject request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xPRID" => $payload["PRID"]));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function updateDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
/* $price = 0;
|
||||
|
||||
$sqlPrice = "SELECT PurchaseRequestDirectDetailEstimationPrice AS Price
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailID = {$payload['PRDID']}";
|
||||
$exec = $this->db->query($sqlPrice, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("update amount error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$price = $exec->result_array()[0]["Price"];
|
||||
}
|
||||
*/
|
||||
|
||||
$PRDTotal = $payload['PRDAmount'] * $payload['PRDPrice'];
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailAmount = {$payload['PRDAmount']},
|
||||
PurchaseRequestDirectDetailRealitationPrice = {$payload['PRDPrice']},
|
||||
PurchaseRequestDirectDetailTotalRealitationPrice = {$PRDTotal},
|
||||
PurchaseRequestDirectDetailLastUpdated = NOW(),
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailID = {$payload['PRDID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("update amount error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$total = 0;
|
||||
$query = "SELECT SUM(IF(PurchaseRequestDirectDetailTotalRealitationPrice IS NULL, PurchaseRequestDirectDetailTotalEstimationPrice,PurchaseRequestDirectDetailTotalRealitationPrice)) as total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($query);
|
||||
if ($exec) {
|
||||
$total = $exec->row()->total;
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase_request_direct_detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectTotalRealitation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase_request_direct request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("PRDID" => $payload['PRDID']));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,910 @@
|
||||
<?php
|
||||
|
||||
class PurchaseRequestDirectApproved extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "Purchase Request/Manager API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
$regionalID = $user['S_RegionalID'];
|
||||
$branchCode = $user['M_BranchCode'];
|
||||
$loginType = $user['M_UserLocationFlag'];
|
||||
$userID = $user['M_UserID'];
|
||||
$sql = "SELECT m_approve_level.* FROM m_user
|
||||
JOIN m_approve_level
|
||||
ON M_UserM_ApproveLevelID = M_ApproveLevelID
|
||||
WHERE M_UserID = ?;";
|
||||
$qry = $this->db->query($sql, [$userID]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error cek approval level");
|
||||
exit;
|
||||
}
|
||||
$approvalLevel = $qry->result_array();
|
||||
if (count($approvalLevel) == 0) {
|
||||
$result = array(
|
||||
'total' => 0,
|
||||
'records' => []
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
$totalStart = $approvalLevel[0]['M_ApproveLevelStartTotal'];
|
||||
$totalEnd = $approvalLevel[0]['M_ApproveLevelEndTotal'];
|
||||
$query = "SELECT prd.*, mu.M_UserUsername as M_RequesterFullName
|
||||
FROM purchase_request_direct as prd
|
||||
JOIN m_user as mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectStatus != 'Draft'
|
||||
AND PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestDirectTotalEstimation BETWEEN $totalStart AND $totalEnd
|
||||
AND PurchaseRequestDirectNumber LIKE '%" . $payload["search"] . "%'";
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM purchase_request_direct as prd
|
||||
JOIN m_user as mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectStatus != 'Draft'
|
||||
AND PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestDirectTotalEstimation BETWEEN $totalStart AND $totalEnd
|
||||
AND PurchaseRequestDirectNumber LIKE '%" . $payload["search"] . "%'";
|
||||
|
||||
if ((isset($payload["startDate"]) && isset($payload["endDate"])) && (trim($payload["startDate"]) !== "" && trim($payload["endDate"]) !== "")) {
|
||||
$query .= " AND (PurchaseRequestDirectDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59' OR PurchaseRequestDirectDateUse BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
$queryCount .= " AND (PurchaseRequestDirectDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59' OR PurchaseRequestDirectDateUse BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
}
|
||||
|
||||
if ($payload["status"]) {
|
||||
$query .= " AND PurchaseRequestDirectStatus = '{$payload["status"]}'";
|
||||
$queryCount .= " AND PurchaseRequestDirectStatus = '{$payload["status"]}'";
|
||||
}
|
||||
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$numberLimit = 5;
|
||||
$numberOffset = 0;
|
||||
if ($payload["currentPage"] > 0) {
|
||||
$numberOffset = ($payload["currentPage"] - 1) * $numberLimit;
|
||||
}
|
||||
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
$totalPage = ceil($totalCount / $numberLimit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = $query . " ORDER BY PurchaseRequestDirectNumber DESC
|
||||
LIMIT {$numberLimit} OFFSET {$numberOffset}";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $totalPage,
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function searchDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$totalCount = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request detail", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = "SELECT *,
|
||||
ItemUnitID,
|
||||
ItemUnitName,
|
||||
PurchaseDirectCategoryCode,
|
||||
PurchaseDirectCategoryName,
|
||||
ROW_NUMBER() OVER(ORDER BY PurchaseRequestDirectDetailID) RowNumber,
|
||||
'' as isAttachemnt,
|
||||
'' as dataAttachment
|
||||
FROM purchase_request_direct_detail
|
||||
JOIN purchase_direct_category ON PurchaseDirectCategoryID = PurchaseRequestDirectDetailPurchaseRequestDirectCategoryID
|
||||
LEFT JOIN itemunit ON PurchaseRequestDirectDetailItemUnitID = ItemUnitID
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
ORDER BY PurchaseRequestDirectDetailStatus ASC, PurchaseRequestDirectDetailID ASC";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
foreach ($rows as $key => $value) {
|
||||
if ($value['PurchaseDirectCategoryName'] !== "BBM") {
|
||||
$rows[$key]['PurchaseRequestDirectDetailAmount'] = intval($value['PurchaseRequestDirectDetailAmount']);
|
||||
$rows[$key]['PurchaseRequestDirectDetailAmountRequest'] = intval($value['PurchaseRequestDirectDetailAmountRequest']);
|
||||
$rows[$key]['PurchaseRequestDirectDetailEstimationPrice'] = intval($value['PurchaseRequestDirectDetailEstimationPrice']);
|
||||
$rows[$key]['PurchaseRequestDirectDetailRealitationPrice'] = intval($value['PurchaseRequestDirectDetailRealitationPrice']);
|
||||
$rows[$key]['PurchaseRequestDirectDetailTotalEstimationPrice'] = intval($value['PurchaseRequestDirectDetailTotalEstimationPrice']);
|
||||
$rows[$key]['PurchaseRequestDirectDetailTotalRealitationPrice'] = intval($value['PurchaseRequestDirectDetailTotalRealitationPrice']);
|
||||
}
|
||||
|
||||
$sql = "SELECT PurchaseDirectAttachmentID,
|
||||
PurchaseDirectAttachmentPurchaseRequestDirectDetailID,
|
||||
PurchaseDirectAttachmentName
|
||||
FROM purchase_direct_attachment
|
||||
WHERE PurchaseDirectAttachmentIsActive = 'Y'
|
||||
AND PurchaseDirectAttachmentPurchaseRequestDirectDetailID = ?";
|
||||
$qry = $this->db->query($sql, [$value['PurchaseRequestDirectDetailID']]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase_direct_attachment", $this->db);
|
||||
exit;
|
||||
}
|
||||
// echo $this->db->last_query();
|
||||
// exit;
|
||||
|
||||
$rowsdata = $qry->result_array();
|
||||
|
||||
if (count($rowsdata) > 0) {
|
||||
$rows[$key]['isAttachemnt'] = true;
|
||||
$rows[$key]['dataAttachment'] = $rowsdata;
|
||||
} else {
|
||||
$rows[$key]['isAttachemnt'] = false;
|
||||
$rows[$key]['dataAttachment'] = [];
|
||||
}
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function getlevel()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
$regionalID = $user['S_RegionalID'];
|
||||
$branchCode = $user['M_BranchCode'];
|
||||
$loginType = $user['M_UserLocationFlag'];
|
||||
$userID = $user['M_UserID'];
|
||||
$sql = "SELECT m_approve_level.* FROM m_user
|
||||
JOIN m_approve_level
|
||||
ON M_UserM_ApproveLevelID = M_ApproveLevelID
|
||||
WHERE M_UserID = ?";
|
||||
$qry = $this->db->query($sql, [$userID]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error cek approval level");
|
||||
exit;
|
||||
}
|
||||
$approvalLevel = $qry->result_array();
|
||||
if (count($approvalLevel) == 0) {
|
||||
$result = array(
|
||||
'total' => 0,
|
||||
'records' => []
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
} else {
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => $approvalLevel,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function deleteDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailIsActive = 'N',
|
||||
PurchaseRequestDirectDetailDeleted = NOW(),
|
||||
PurchaseRequestDirectDetailDeletedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailStatus = 'Pending'
|
||||
AND PurchaseRequestDirectDetailID = {$payload['PRDID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("reject request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$sqlTotalPrice = "SELECT SUM(PurchaseRequestDirectDetailTotalEstimationPrice) AS Total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlTotalPrice, []);
|
||||
$total = 0;
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$total = $exec->result_array()[0]["Total"] ?? 0;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectTotalEstimation = {$total},
|
||||
PurchaseRequestDirectTotalRealitation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xPRDID" => $payload['PRDID']));
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function approveRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailStatus = 'Ordered',
|
||||
PurchaseRequestDirectDetailLastUpdated = NOW(),
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailStatus = 'Pending'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$total = 0;
|
||||
$query = "SELECT SUM(IF(PurchaseRequestDirectDetailTotalRealitationPrice IS NULL, PurchaseRequestDirectDetailTotalEstimationPrice,PurchaseRequestDirectDetailTotalRealitationPrice)) as total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($query);
|
||||
if ($exec) {
|
||||
$total = $exec->row()->total;
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase_request_direct_detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectNote = '{$payload['PRNote']}',
|
||||
PurchaseRequestDirectStatus = 'Approved',
|
||||
PurchaseRequestDirectApprovedDate = NOW(),
|
||||
PurchaseRequestDirectApprovedBy = {$userId},
|
||||
PurchaseRequestDirectTotalRealitation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectStatus = 'Pending'
|
||||
AND PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rowQuery = "SELECT prd.*,
|
||||
mu.M_UserFullName AS M_RequesterFullName
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($rowQuery, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
$datas_log = array();
|
||||
$sql = "SELECT * FROM purchase_request_direct WHERE PurchaseRequestDirectID = ? AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$payload['PRID']]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$header = $query->row_array();
|
||||
|
||||
|
||||
$datas_log['header'] = $header;
|
||||
$sql = "SELECT *
|
||||
FROM purchase_request_direct_detail
|
||||
JOIN itemunit ON PurchaseRequestDirectDetailItemUnitID = ItemUnitID
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = ? AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$payload['PRID']]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request detail select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$details = $query->result_array();
|
||||
$datas_log['details'] = $details;
|
||||
|
||||
$rowQuery = "SELECT prd.*,
|
||||
mu.M_UserFullName AS M_RequesterFullName
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($rowQuery, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Notification
|
||||
$this->readNotif("A", $userId, $payload['PRID']);
|
||||
|
||||
$messages = "Purchase Request Direct dengan kode " . $header['PurchaseRequestDirectNumber'] . " telah di approved";
|
||||
$this->insert_act_log("PRD", "Approved", $messages, $payload['PRID'], $this->safeJsonEncode($datas_log), $userId);
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => $exec->result_array());
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function rejectRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectStatus = 'Draft',
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectStatus = 'Pending'
|
||||
AND PurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("reject request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
$datas_log = array();
|
||||
$sql = "SELECT * FROM purchase_request_direct WHERE PurchaseRequestDirectID = ? AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$payload['PRID']]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$header = $query->row_array();
|
||||
|
||||
|
||||
$datas_log['header'] = $header;
|
||||
$sql = "SELECT *
|
||||
FROM purchase_request_direct_detail
|
||||
JOIN itemunit ON PurchaseRequestDirectDetailItemUnitID = ItemUnitID
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = ? AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$payload['PRID']]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request detail select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$details = $query->result_array();
|
||||
$datas_log['details'] = $details;
|
||||
|
||||
$rowQuery = "SELECT prd.*,
|
||||
mu.M_UserFullName AS M_RequesterFullName
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($rowQuery, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Notification
|
||||
$this->readNotif("R", $userId, $payload['PRID']);
|
||||
|
||||
$messages = "Purchase Request Direct dengan kode " . $header['PurchaseRequestDirectNumber'] . " telah di reject";
|
||||
$this->insert_act_log("PRD", "Reject", $messages, $payload['PRID'], $this->safeJsonEncode($datas_log), $userId);
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xPRID" => $payload["PRID"]));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function unApproveRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectStatus = 'Pending',
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectStatus = 'Approved'
|
||||
AND PurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("unapprove request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
$datas_log = array();
|
||||
$sql = "SELECT * FROM purchase_request_direct WHERE PurchaseRequestDirectID = ? AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$payload['PRID']]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$header = $query->row_array();
|
||||
|
||||
|
||||
$datas_log['header'] = $header;
|
||||
$sql = "SELECT *
|
||||
FROM purchase_request_direct_detail
|
||||
JOIN itemunit ON PurchaseRequestDirectDetailItemUnitID = ItemUnitID
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = ? AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$payload['PRID']]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request detail select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$details = $query->result_array();
|
||||
$datas_log['details'] = $details;
|
||||
|
||||
$rowQuery = "SELECT prd.*,
|
||||
mu.M_UserFullName AS M_RequesterFullName
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($rowQuery, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Notification
|
||||
$this->readNotif("U", $userId, $payload['PRID']);
|
||||
|
||||
$messages = "Purchase Request Direct dengan kode " . $header['PurchaseRequestDirectNumber'] . " telah di unappprove";
|
||||
$this->insert_act_log("PRD", "Unapprove", $messages, $payload['PRID'], $this->safeJsonEncode($datas_log), $userId);
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xPRID" => $payload["PRID"]));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function updateDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
/* $price = 0;
|
||||
|
||||
$sqlPrice = "SELECT PurchaseRequestDirectDetailEstimationPrice AS Price
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailID = {$payload['PRDID']}";
|
||||
$exec = $this->db->query($sqlPrice, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("update amount error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$price = $exec->result_array()[0]["Price"];
|
||||
}
|
||||
*/
|
||||
|
||||
// $PRDTotal = $payload['PRDAmount'] * $payload['PRDPrice'];
|
||||
$PRDTotal = $payload['PRDTotal'];
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailAmount = {$payload['PRDAmount']},
|
||||
PurchaseRequestDirectDetailRealitationPrice = {$payload['PRDPrice']},
|
||||
PurchaseRequestDirectDetailTotalRealitationPrice = {$PRDTotal},
|
||||
PurchaseRequestDirectDetailLastUpdated = NOW(),
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailID = {$payload['PRDID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("update amount error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$total = 0;
|
||||
$query = "SELECT SUM(IF(PurchaseRequestDirectDetailTotalRealitationPrice IS NULL, PurchaseRequestDirectDetailTotalEstimationPrice,PurchaseRequestDirectDetailTotalRealitationPrice)) as total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($query);
|
||||
if ($exec) {
|
||||
$total = $exec->row()->total;
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase_request_direct_detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectTotalRealitation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase_request_direct request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("PRDID" => $payload['PRDID']));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
private function safeJsonEncode($data)
|
||||
{
|
||||
// Coba encode data ke JSON
|
||||
$jsonData = json_encode($data);
|
||||
|
||||
// Cek apakah terjadi error saat encode
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
$errorMsg = json_last_error_msg();
|
||||
error_log("JSON encode error: " . $errorMsg);
|
||||
|
||||
// Lakukan sanitasi dan perbaikan data
|
||||
$fixedData = $this->fixJsonEncodeIssues($data, $errorMsg);
|
||||
|
||||
// Coba encode lagi setelah diperbaiki
|
||||
$jsonData = json_encode($fixedData);
|
||||
|
||||
// Jika masih error, log dan kembalikan objek kosong
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
error_log("Failed to fix JSON encode issues: " . json_last_error_msg());
|
||||
// Kembalikan objek kosong jika masih gagal
|
||||
return '{}';
|
||||
}
|
||||
}
|
||||
|
||||
return $jsonData;
|
||||
}
|
||||
|
||||
// Fungsi untuk memperbaiki masalah encoding JSON
|
||||
private function fixJsonEncodeIssues($data, $errorMsg)
|
||||
{
|
||||
// Buat salinan data untuk dimodifikasi
|
||||
$fixedData = $data;
|
||||
|
||||
// Tangani berbagai jenis error
|
||||
if (strpos($errorMsg, 'Malformed UTF-8') !== false) {
|
||||
// Perbaiki masalah karakter UTF-8
|
||||
$fixedData = $this->fixUTF8Issues($fixedData);
|
||||
} else if (strpos($errorMsg, 'Inf and NaN cannot be JSON encoded') !== false) {
|
||||
// Perbaiki masalah nilai Infinity atau NaN
|
||||
$fixedData = $this->fixInfNanIssues($fixedData);
|
||||
} else {
|
||||
// Konversi semua nilai numerik menjadi string untuk menghindari masalah presisi
|
||||
$fixedData = $this->convertNumericValuesToStrings($fixedData);
|
||||
|
||||
// Perbaiki masalah referensi recursif
|
||||
$fixedData = $this->fixRecursiveReferences($fixedData);
|
||||
}
|
||||
|
||||
return $fixedData;
|
||||
}
|
||||
|
||||
// Perbaiki masalah karakter UTF-8
|
||||
private function fixUTF8Issues($data)
|
||||
{
|
||||
if (is_string($data)) {
|
||||
return mb_convert_encoding($data, 'UTF-8', 'UTF-8');
|
||||
} else if (is_array($data)) {
|
||||
foreach ($data as $key => $value) {
|
||||
$data[$key] = $this->fixUTF8Issues($value);
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
// Perbaiki masalah nilai Infinity atau NaN
|
||||
private function fixInfNanIssues($data)
|
||||
{
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $key => $value) {
|
||||
if (is_float($value) && (is_nan($value) || is_infinite($value))) {
|
||||
$data[$key] = (string)$value; // Konversi ke string
|
||||
} else if (is_array($value)) {
|
||||
$data[$key] = $this->fixInfNanIssues($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
// Perbaiki masalah referensi recursif
|
||||
private function fixRecursiveReferences($data, $depth = 0)
|
||||
{
|
||||
// Batasi kedalaman rekursi untuk menghindari infinite loop
|
||||
if ($depth > 50) {
|
||||
return "[MAX_DEPTH_REACHED]";
|
||||
}
|
||||
|
||||
if (is_array($data)) {
|
||||
$result = [];
|
||||
foreach ($data as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$result[$key] = $this->fixRecursiveReferences($value, $depth + 1);
|
||||
} else {
|
||||
$result[$key] = $value;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
// Cari dan konversi numerik ke string secara rekursif
|
||||
private function convertNumericValuesToStrings($data)
|
||||
{
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$data[$key] = $this->convertNumericValuesToStrings($value);
|
||||
} else if (is_numeric($value)) {
|
||||
$data[$key] = (string)$value;
|
||||
} else if (is_bool($value)) {
|
||||
$data[$key] = $value ? "true" : "false";
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
function insert_act_log($code, $status, $description, $refId, $data, $userId)
|
||||
{
|
||||
$sql = "INSERT INTO user_activity(
|
||||
UserActivityCode,
|
||||
UserActivityStatus,
|
||||
UserActivityDescription,
|
||||
UserActivityRefID,
|
||||
UserActivityData,
|
||||
UserActivityUserID,
|
||||
UserActivityCreated)
|
||||
VALUES (?,?,?,?,?,?,?)";
|
||||
$query = $this->db->query($sql, [$code, $status, $description, $refId, $data, $userId, date("Y-m-d H:i:s")]);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("user activity", $this->db);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// read notification
|
||||
function readNotif($type, $userId, $refID)
|
||||
{
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
// cari user penerima notifikasi
|
||||
if ($type == "U") {
|
||||
$sql_get = "SELECT PurchaseRequestDirectID,
|
||||
M_UserID,
|
||||
M_UserUsername,
|
||||
NotificationID,
|
||||
NotificationDetailID,
|
||||
NotificationDetailStatus,
|
||||
NotificationDetailM_UserID,
|
||||
NotificationDetailM_ApproveLevelID
|
||||
FROM purchase_request_direct
|
||||
JOIN notification ON NotificationRefID = PurchaseRequestDirectID
|
||||
JOIN notification_detail ON NotificationID = NotificationDetailNotificationID
|
||||
AND NotificationDetailStatus = 'read'
|
||||
JOIN m_user ON NotificationUserID = M_UserID
|
||||
AND M_UserIsActive = 'Y'
|
||||
WHERE PurchaseRequestDirectID = ?
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql_get, [$refID]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select user notification error", $this->db);
|
||||
exit;
|
||||
}
|
||||
$rowsuser = $qry->result_array();
|
||||
} else {
|
||||
$sql_get = "SELECT PurchaseRequestDirectID,
|
||||
M_UserID,
|
||||
M_UserUsername,
|
||||
NotificationID,
|
||||
NotificationDetailID,
|
||||
NotificationDetailStatus,
|
||||
NotificationDetailM_UserID,
|
||||
NotificationDetailM_ApproveLevelID
|
||||
FROM purchase_request_direct
|
||||
JOIN notification ON NotificationRefID = PurchaseRequestDirectID
|
||||
JOIN notification_detail ON NotificationID = NotificationDetailNotificationID
|
||||
AND NotificationDetailStatus = 'unread'
|
||||
JOIN m_user ON NotificationUserID = M_UserID
|
||||
AND M_UserIsActive = 'Y'
|
||||
WHERE PurchaseRequestDirectID = ?
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql_get, [$refID]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("select user notification error", $this->db);
|
||||
exit;
|
||||
}
|
||||
$rowsuser = $qry->result_array();
|
||||
}
|
||||
|
||||
|
||||
foreach ($rowsuser as $user) {
|
||||
|
||||
if ($type == "A") {
|
||||
// verifikasi manager
|
||||
$sql = "UPDATE notification_detail SET
|
||||
NotificationDetailStatus = 'read',
|
||||
NotificationDetailLastUpdated = NOW(),
|
||||
NotificationDetailUserID = ?
|
||||
WHERE NotificationDetailNotificationID = ?";
|
||||
$qry = $this->db->query($sql, [$userId, $user["NotificationID"]]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("update notification error", $this->db);
|
||||
exit;
|
||||
}
|
||||
} else if ($type == "R") {
|
||||
$sql = "UPDATE notification_detail SET
|
||||
NotificationDetailStatus = 'read',
|
||||
NotificationDetailLastUpdated = NOW(),
|
||||
NotificationDetailUserID = ?
|
||||
WHERE NotificationDetailNotificationID = ?";
|
||||
$qry = $this->db->query($sql, [$userId, $user["NotificationID"]]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("update notification error", $this->db);
|
||||
exit;
|
||||
}
|
||||
} else if ($type == "U") {
|
||||
$sql = "UPDATE notification_detail SET
|
||||
NotificationDetailStatus = 'unread',
|
||||
NotificationDetailLastUpdated = NOW(),
|
||||
NotificationDetailUserID = ?
|
||||
WHERE NotificationDetailNotificationID = ?";
|
||||
$qry = $this->db->query($sql, [$userId, $user["NotificationID"]]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("update notification error", $this->db);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,815 @@
|
||||
<?php
|
||||
|
||||
class PurchaseRequestDirectApprovedNota extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "Purchase Request/Manager API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
$regionalID = $user['S_RegionalID'];
|
||||
$branchCode = $user['M_BranchCode'];
|
||||
$loginType = $user['M_UserLocationFlag'];
|
||||
$userID = $user['M_UserID'];
|
||||
$sql = "SELECT m_approve_level.* FROM m_user
|
||||
JOIN m_approve_level
|
||||
ON M_UserM_ApproveLevelID = M_ApproveLevelID
|
||||
WHERE M_UserID = ?;";
|
||||
$qry = $this->db->query($sql, [$userID]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error cek approval level");
|
||||
exit;
|
||||
}
|
||||
$approvalLevel = $qry->result_array();
|
||||
if (count($approvalLevel) == 0) {
|
||||
$result = array(
|
||||
'total' => 0,
|
||||
'records' => []
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
$totalStart = $approvalLevel[0]['M_ApproveLevelStartTotal'];
|
||||
$totalEnd = $approvalLevel[0]['M_ApproveLevelEndTotal'];
|
||||
$query = "SELECT prd.*, mu.M_UserFullName as M_RequesterFullName
|
||||
FROM purchase_request_direct as prd
|
||||
JOIN m_user as mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectStatus != 'Draft'
|
||||
AND PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestDirectTotalEstimation BETWEEN $totalStart AND $totalEnd
|
||||
AND PurchaseRequestDirectID IN (
|
||||
SELECT PurchaseRequestDirectDetailPurchaseRequestDirectID
|
||||
FROM purchase_direct_attachment
|
||||
JOIN purchase_request_direct_detail ON PurchaseDirectAttachmentPurchaseRequestDirectDetailID = PurchaseRequestDirectDetailID
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
WHERE PurchaseDirectAttachmentIsActive = 'Y'
|
||||
)
|
||||
AND PurchaseRequestDirectNumber LIKE '%" . $payload["search"] . "%'";
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM purchase_request_direct as prd
|
||||
JOIN m_user as mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectStatus != 'Draft'
|
||||
AND PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestDirectTotalEstimation BETWEEN $totalStart AND $totalEnd
|
||||
AND PurchaseRequestDirectID IN (
|
||||
SELECT PurchaseRequestDirectDetailPurchaseRequestDirectID
|
||||
FROM purchase_direct_attachment
|
||||
JOIN purchase_request_direct_detail ON PurchaseDirectAttachmentPurchaseRequestDirectDetailID = PurchaseRequestDirectDetailID
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
WHERE PurchaseDirectAttachmentIsActive = 'Y'
|
||||
)
|
||||
AND PurchaseRequestDirectNumber LIKE '%" . $payload["search"] . "%'";
|
||||
|
||||
if ((isset($payload["startDate"]) && isset($payload["endDate"])) && (trim($payload["startDate"]) !== "" && trim($payload["endDate"]) !== "")) {
|
||||
$query .= " AND (PurchaseRequestDirectDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59' OR PurchaseRequestDirectDateUse BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
$queryCount .= " AND (PurchaseRequestDirectDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59' OR PurchaseRequestDirectDateUse BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
}
|
||||
|
||||
if ($payload["status"]) {
|
||||
$query .= " AND PurchaseRequestDirectStatus = {$payload["status"]}";
|
||||
$queryCount .= " AND PurchaseRequestDirectStatus = {$payload["status"]}";
|
||||
}
|
||||
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$numberLimit = 20;
|
||||
$numberOffset = 0;
|
||||
if ($payload["currentPage"] > 0) {
|
||||
$numberOffset = ($payload["currentPage"] - 1) * $numberLimit;
|
||||
}
|
||||
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
$totalPage = ceil($totalCount / $numberLimit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = $query . " ORDER BY PurchaseRequestDirectNumber DESC
|
||||
LIMIT {$numberLimit} OFFSET {$numberOffset}";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $totalPage,
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function searchDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$totalCount = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request detail", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = "SELECT *,
|
||||
ROW_NUMBER() OVER(ORDER BY PurchaseRequestDirectDetailID) RowNumber,
|
||||
'' as isAttachemnt,
|
||||
'' as dataAttachment
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
ORDER BY PurchaseRequestDirectDetailStatus ASC,
|
||||
PurchaseRequestDirectDetailID ASC";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
foreach ($rows as $key => $value) {
|
||||
$sql = "SELECT PurchaseDirectAttachmentID,
|
||||
PurchaseDirectAttachmentPurchaseRequestDirectDetailID,
|
||||
PurchaseDirectAttachmentName
|
||||
FROM purchase_direct_attachment
|
||||
WHERE PurchaseDirectAttachmentIsActive = 'Y'
|
||||
AND PurchaseDirectAttachmentPurchaseRequestDirectDetailID = ?";
|
||||
$qry = $this->db->query($sql, [$value['PurchaseRequestDirectDetailID']]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase_direct_attachment", $this->db);
|
||||
exit;
|
||||
}
|
||||
// echo $this->db->last_query();
|
||||
// exit;
|
||||
|
||||
$rowsdata = $qry->result_array();
|
||||
|
||||
if (count($rowsdata) > 0) {
|
||||
$rows[$key]['isAttachemnt'] = true;
|
||||
$rows[$key]['dataAttachment'] = $rowsdata;
|
||||
} else {
|
||||
$rows[$key]['isAttachemnt'] = false;
|
||||
$rows[$key]['dataAttachment'] = [];
|
||||
}
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function getlevel()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$user = $this->sys_user;
|
||||
$regionalID = $user['S_RegionalID'];
|
||||
$branchCode = $user['M_BranchCode'];
|
||||
$loginType = $user['M_UserLocationFlag'];
|
||||
$userID = $user['M_UserID'];
|
||||
$sql = "SELECT m_approve_level.* FROM m_user
|
||||
JOIN m_approve_level
|
||||
ON M_UserM_ApproveLevelID = M_ApproveLevelID
|
||||
WHERE M_UserID = ?";
|
||||
$qry = $this->db->query($sql, [$userID]);
|
||||
if (!$qry) {
|
||||
$this->sys_error_db("Error cek approval level");
|
||||
exit;
|
||||
}
|
||||
$approvalLevel = $qry->result_array();
|
||||
if (count($approvalLevel) == 0) {
|
||||
$result = array(
|
||||
'total' => 0,
|
||||
'records' => []
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
} else {
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => $approvalLevel,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function deleteDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailIsActive = 'N',
|
||||
PurchaseRequestDirectDetailDeleted = NOW(),
|
||||
PurchaseRequestDirectDetailDeletedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailStatus = 'Pending'
|
||||
AND PurchaseRequestDirectDetailID = {$payload['PRDID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("reject request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$sqlTotalPrice = "SELECT SUM(PurchaseRequestDirectDetailTotalEstimationPrice) AS Total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlTotalPrice, []);
|
||||
$total = 0;
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$total = $exec->result_array()[0]["Total"] ?? 0;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectTotalEstimation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xPRDID" => $payload['PRDID']));
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function approveRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailStatus = 'Ordered',
|
||||
PurchaseRequestDirectDetailLastUpdated = NOW(),
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailStatus = 'Pending'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$total = 0;
|
||||
$query = "SELECT SUM(IF(PurchaseRequestDirectDetailTotalRealitationPrice IS NULL, PurchaseRequestDirectDetailTotalEstimationPrice,PurchaseRequestDirectDetailTotalRealitationPrice)) as total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($query);
|
||||
if ($exec) {
|
||||
$total = $exec->row()->total;
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase_request_direct_detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectNote = '{$payload['PRNote']}',
|
||||
PurchaseRequestDirectStatus = 'Approved',
|
||||
PurchaseRequestDirectApprovedDate = NOW(),
|
||||
PurchaseRequestDirectApprovedBy = {$userId},
|
||||
PurchaseRequestDirectTotalRealitation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectStatus = 'Pending'
|
||||
AND PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rowQuery = "SELECT prd.*,
|
||||
mu.M_UserFullName AS M_RequesterFullName
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($rowQuery, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
$datas_log = array();
|
||||
$sql = "SELECT * FROM purchase_request_direct WHERE PurchaseRequestDirectID = ? AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$payload['PRID']]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$header = $query->row_array();
|
||||
|
||||
|
||||
$datas_log['header'] = $header;
|
||||
$sql = "SELECT *
|
||||
FROM purchase_request_direct_detail
|
||||
JOIN itemunit ON PurchaseRequestDirectDetailItemUnitID = ItemUnitID
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = ? AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$payload['PRID']]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request detail select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$details = $query->result_array();
|
||||
$datas_log['details'] = $details;
|
||||
|
||||
$rowQuery = "SELECT prd.*,
|
||||
mu.M_UserFullName AS M_RequesterFullName
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($rowQuery, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
$messages = "Purchase Request Direct dengan kode " . $header['PurchaseRequestDirectNumber'] . " telah di approved";
|
||||
$this->insert_act_log("PRD", "Approved", $messages, $payload['PRID'], $this->safeJsonEncode($datas_log), $userId);
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => $exec->result_array());
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function approveRequestNota()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectNotaStatus = 'Approved',
|
||||
PurchaseRequestDirectNotaApprovedDate = NOW(),
|
||||
PurchaseRequestDirectNotaApprovedBy = {$userId},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectNotaStatus = 'Pending'
|
||||
AND PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rowQuery = "SELECT prd.*,
|
||||
mu.M_UserFullName AS M_RequesterFullName
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($rowQuery, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
$datas_log = array();
|
||||
$sql = "SELECT * FROM purchase_request_direct WHERE PurchaseRequestDirectID = ? AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$payload['PRID']]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$header = $query->row_array();
|
||||
|
||||
|
||||
$datas_log['header'] = $header;
|
||||
$sql = "SELECT *
|
||||
FROM purchase_request_direct_detail
|
||||
JOIN itemunit ON PurchaseRequestDirectDetailItemUnitID = ItemUnitID
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = ? AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$payload['PRID']]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request detail select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$details = $query->result_array();
|
||||
$datas_log['details'] = $details;
|
||||
|
||||
$rowQuery = "SELECT prd.*,
|
||||
mu.M_UserFullName AS M_RequesterFullName
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($rowQuery, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
$messages = "Purchase Request Direct Nota dengan kode " . $header['PurchaseRequestDirectNumber'] . " telah di approved";
|
||||
$this->insert_act_log("PRD", "Approved", $messages, $payload['PRID'], $this->safeJsonEncode($datas_log), $userId);
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => $exec->result_array());
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function rejectRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectStatus = 'Draft',
|
||||
PurchaseRequestDirectNotaStatus = 'Draft',
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectStatus = 'Pending'
|
||||
AND PurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("reject request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
$datas_log = array();
|
||||
$sql = "SELECT * FROM purchase_request_direct WHERE PurchaseRequestDirectID = ? AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$payload['PRID']]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$header = $query->row_array();
|
||||
|
||||
|
||||
$datas_log['header'] = $header;
|
||||
$sql = "SELECT *
|
||||
FROM purchase_request_direct_detail
|
||||
JOIN itemunit ON PurchaseRequestDirectDetailItemUnitID = ItemUnitID
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = ? AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$payload['PRID']]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request detail select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$details = $query->result_array();
|
||||
$datas_log['details'] = $details;
|
||||
|
||||
$rowQuery = "SELECT prd.*,
|
||||
mu.M_UserFullName AS M_RequesterFullName
|
||||
FROM purchase_request_direct AS prd
|
||||
INNER JOIN m_user AS mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($rowQuery, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("approve request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
$messages = "Purchase Request Direct dengan kode " . $header['PurchaseRequestDirectNumber'] . " telah di reject";
|
||||
$this->insert_act_log("PRD", "Reject", $messages, $payload['PRID'], $this->safeJsonEncode($datas_log), $userId);
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xPRID" => $payload["PRID"]));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function updateDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
/* $price = 0;
|
||||
|
||||
$sqlPrice = "SELECT PurchaseRequestDirectDetailEstimationPrice AS Price
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailID = {$payload['PRDID']}";
|
||||
$exec = $this->db->query($sqlPrice, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("update amount error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$price = $exec->result_array()[0]["Price"];
|
||||
}
|
||||
*/
|
||||
|
||||
$PRDTotal = $payload['PRDAmount'] * $payload['PRDPrice'];
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailAmount = {$payload['PRDAmount']},
|
||||
PurchaseRequestDirectDetailRealitationPrice = {$payload['PRDPrice']},
|
||||
PurchaseRequestDirectDetailTotalRealitationPrice = {$PRDTotal},
|
||||
PurchaseRequestDirectDetailLastUpdated = NOW(),
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailID = {$payload['PRDID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("update amount error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$total = 0;
|
||||
$query = "SELECT SUM(IF(PurchaseRequestDirectDetailTotalRealitationPrice IS NULL, PurchaseRequestDirectDetailTotalEstimationPrice,PurchaseRequestDirectDetailTotalRealitationPrice)) as total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($query);
|
||||
if ($exec) {
|
||||
$total = $exec->row()->total;
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase_request_direct_detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectTotalRealitation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase_request_direct request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("PRDID" => $payload['PRDID']));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
private function safeJsonEncode($data)
|
||||
{
|
||||
// Coba encode data ke JSON
|
||||
$jsonData = json_encode($data);
|
||||
|
||||
// Cek apakah terjadi error saat encode
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
$errorMsg = json_last_error_msg();
|
||||
error_log("JSON encode error: " . $errorMsg);
|
||||
|
||||
// Lakukan sanitasi dan perbaikan data
|
||||
$fixedData = $this->fixJsonEncodeIssues($data, $errorMsg);
|
||||
|
||||
// Coba encode lagi setelah diperbaiki
|
||||
$jsonData = json_encode($fixedData);
|
||||
|
||||
// Jika masih error, log dan kembalikan objek kosong
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
error_log("Failed to fix JSON encode issues: " . json_last_error_msg());
|
||||
// Kembalikan objek kosong jika masih gagal
|
||||
return '{}';
|
||||
}
|
||||
}
|
||||
|
||||
return $jsonData;
|
||||
}
|
||||
|
||||
// Fungsi untuk memperbaiki masalah encoding JSON
|
||||
private function fixJsonEncodeIssues($data, $errorMsg)
|
||||
{
|
||||
// Buat salinan data untuk dimodifikasi
|
||||
$fixedData = $data;
|
||||
|
||||
// Tangani berbagai jenis error
|
||||
if (strpos($errorMsg, 'Malformed UTF-8') !== false) {
|
||||
// Perbaiki masalah karakter UTF-8
|
||||
$fixedData = $this->fixUTF8Issues($fixedData);
|
||||
} else if (strpos($errorMsg, 'Inf and NaN cannot be JSON encoded') !== false) {
|
||||
// Perbaiki masalah nilai Infinity atau NaN
|
||||
$fixedData = $this->fixInfNanIssues($fixedData);
|
||||
} else {
|
||||
// Konversi semua nilai numerik menjadi string untuk menghindari masalah presisi
|
||||
$fixedData = $this->convertNumericValuesToStrings($fixedData);
|
||||
|
||||
// Perbaiki masalah referensi recursif
|
||||
$fixedData = $this->fixRecursiveReferences($fixedData);
|
||||
}
|
||||
|
||||
return $fixedData;
|
||||
}
|
||||
|
||||
// Perbaiki masalah karakter UTF-8
|
||||
private function fixUTF8Issues($data)
|
||||
{
|
||||
if (is_string($data)) {
|
||||
return mb_convert_encoding($data, 'UTF-8', 'UTF-8');
|
||||
} else if (is_array($data)) {
|
||||
foreach ($data as $key => $value) {
|
||||
$data[$key] = $this->fixUTF8Issues($value);
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
// Perbaiki masalah nilai Infinity atau NaN
|
||||
private function fixInfNanIssues($data)
|
||||
{
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $key => $value) {
|
||||
if (is_float($value) && (is_nan($value) || is_infinite($value))) {
|
||||
$data[$key] = (string)$value; // Konversi ke string
|
||||
} else if (is_array($value)) {
|
||||
$data[$key] = $this->fixInfNanIssues($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
// Perbaiki masalah referensi recursif
|
||||
private function fixRecursiveReferences($data, $depth = 0)
|
||||
{
|
||||
// Batasi kedalaman rekursi untuk menghindari infinite loop
|
||||
if ($depth > 50) {
|
||||
return "[MAX_DEPTH_REACHED]";
|
||||
}
|
||||
|
||||
if (is_array($data)) {
|
||||
$result = [];
|
||||
foreach ($data as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$result[$key] = $this->fixRecursiveReferences($value, $depth + 1);
|
||||
} else {
|
||||
$result[$key] = $value;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
// Cari dan konversi numerik ke string secara rekursif
|
||||
private function convertNumericValuesToStrings($data)
|
||||
{
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$data[$key] = $this->convertNumericValuesToStrings($value);
|
||||
} else if (is_numeric($value)) {
|
||||
$data[$key] = (string)$value;
|
||||
} else if (is_bool($value)) {
|
||||
$data[$key] = $value ? "true" : "false";
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
function insert_act_log($code, $status, $description, $refId, $data, $userId)
|
||||
{
|
||||
$sql = "INSERT INTO user_activity(
|
||||
UserActivityCode,
|
||||
UserActivityStatus,
|
||||
UserActivityDescription,
|
||||
UserActivityRefID,
|
||||
UserActivityData,
|
||||
UserActivityUserID,
|
||||
UserActivityCreated)
|
||||
VALUES (?,?,?,?,?,?,?)";
|
||||
$query = $this->db->query($sql, [$code, $status, $description, $refId, $data, $userId, date("Y-m-d H:i:s")]);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("user activity", $this->db);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
213
application/controllers/mockup/purchase/order/PurchaseOrder.http
Normal file
213
application/controllers/mockup/purchase/order/PurchaseOrder.http
Normal file
@@ -0,0 +1,213 @@
|
||||
@token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjM4MCIsIk1fVXNlclVzZXJuYW1lIjoicmVnc2J5IiwiTV9Vc2VyR3JvdXBEYXNoYm9hcmQiOiJvbmUtdWlcL3Rlc3RcL3Z1ZXhcL2FjYy1vbmUtanVybmFsXC8iLCJNX1VzZXJEZWZhdWx0VF9TYW1wbGVTdGF0aW9uSUQiOiIwIiwiTV9TdGFmZk5hbWUiOiJTdGFmZiBSZWdpb25hbCIsImlzX2NvdXJpZXIiOiJOIiwidGltZV9hdXRvbG9nb3V0IjoiMTIwIiwiTV9Vc2VyTG9jYXRpb25JRCI6IjM3IiwiTV9Vc2VyTG9jYXRpb25GbGFnIjoiUiIsIlNfUmVnaW9uYWxOYW1lIjoiU3VyYWJheWEgUmF5YSIsIlNfUmVnaW9uYWxJRCI6IjYiLCJNX0JyYW5jaE5hbWUiOiIiLCJNX0JyYW5jaENvZGUiOiIiLCJNX0JyYW5jaElEIjoiMCIsImxvZ2luTGV2ZWwiOiJyZWdpb25hbCIsIk1fQnJhbmNoQ29tcGFueUlEIjoiMSIsIk1fQnJhbmNoQ29tcGFueU5hbWUiOiJQVCBQUkFNSVRBIiwiaXAiOiIxMzkuMTk1LjEyMi4yMzUiLCJhZ2VudCI6Ik1vemlsbGFcLzUuMCAoWDExOyBMaW51eCB4ODZfNjQ7IHJ2OjEzNy4wKSBHZWNrb1wvMjAxMDAxMDEgRmlyZWZveFwvMTM3LjAiLCJ2ZXJzaW9uIjoidjIiLCJsYXN0LWxvZ2luIjoiMjAyNS0wNi0wNCAxMzoyMDowNSIsIk1fU2F0ZWxsaXRlSUQiOjB9.hm6JtstjaQOzb7oDSXQ-oMWuX_jFQZH-HDr3r3OzPac"
|
||||
|
||||
@host = accone.aplikasi.web.id/one-api
|
||||
|
||||
POST https://{{host}}/mockup/purchase/order/PurchaseOrder/index/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjMiLCJNX1VzZXJVc2VybmFtZSI6ImFkbWluICIsIk1fVXNlckdyb3VwRGFzaGJvYXJkIjoidGVzdFwvdnVleFwvb25lLWZvLXJlZ2lzdHJhdGlvbi12MzFcLyIsIk1fVXNlckRlZmF1bHRUX1NhbXBsZVN0YXRpb25JRCI6IjAiLCJNX1N0YWZmTmFtZSI6IkFETUlOIiwiaXNfY291cmllciI6Ik4iLCJ0aW1lX2F1dG9sb2dvdXQiOiIxMjAiLCJpcCI6IjE0OS4xMTMuOTUuMTUzIiwiYWdlbnQiOiJNb3ppbGxhXC81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXRcLzUzNy4zNiAoS0hUTUwsIGxpa2UgR2Vja28pIENocm9tZVwvMTI4LjAuMC4wIFNhZmFyaVwvNTM3LjM2IEVkZ1wvMTI4LjAuMC4wIiwidmVyc2lvbiI6InYyIiwibGFzdC1sb2dpbiI6IjIwMjQtMDktMDIgMTE6MzY6MDgiLCJNX1NhdGVsbGl0ZUlEIjowfQ.38owLzgSjtoley0Vz9W9silF4vfp7hrJEQqytYHf8P0"
|
||||
}
|
||||
|
||||
###
|
||||
// listing data
|
||||
POST https://{{host}}/mockup/purchase/order/PurchaseOrder/search/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"currentPage": 1,
|
||||
"search": "",
|
||||
"startDate": "2025-06-04",
|
||||
"endDate": "2025-06-04",
|
||||
"status": "All",
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
###
|
||||
// get supplier
|
||||
POST https://{{host}}/mockup/purchase/order/PurchaseOrder/getSupplier/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"search": "",
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
###
|
||||
// get warehouse
|
||||
POST https://{{host}}/mockup/purchase/order/PurchaseOrder/getWarehouse/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"search": "",
|
||||
"regionalId": 8,
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
###
|
||||
// get item old
|
||||
POST https://{{host}}/mockup/purchase/order/PurchaseOrder/getItem_old/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"search":"",
|
||||
"currentPage":1,
|
||||
"supplierID":"3",
|
||||
"itemCategoryID":"1",
|
||||
"regionalId":"6",
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
###
|
||||
// get item
|
||||
POST https://{{host}}/mockup/purchase/order/PurchaseOrder/getItem_new/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"search":"",
|
||||
"currentPage":1,
|
||||
"supplierID":"7",
|
||||
"itemCategoryID":"1",
|
||||
"regionalId":"6",
|
||||
"token": {{token}}
|
||||
}
|
||||
###
|
||||
// get item
|
||||
POST https://{{host}}/mockup/purchase/order/PurchaseOrder/getItem/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"search":"",
|
||||
"currentPage":1,
|
||||
"supplierID":"7",
|
||||
"itemCategoryID":"1",
|
||||
"regionalId":"6",
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
###
|
||||
// get item update
|
||||
POST https://{{host}}/mockup/purchase/order/PurchaseOrder/getItemUpdate/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"POID": 89,
|
||||
"token": {{ token }}
|
||||
}
|
||||
|
||||
###
|
||||
// save order
|
||||
POST https://{{host}}/mockup/purchase/order/PurchaseOrder/saveOrder/
|
||||
Content-Type: application/json
|
||||
|
||||
{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjM4MCIsIk1fVXNlclVzZXJuYW1lIjoicmVnc2J5IiwiTV9Vc2VyR3JvdXBEYXNoYm9hcmQiOiJvbmUtdWlcL3Rlc3RcL3Z1ZXhcL2FjYy1vbmUtanVybmFsXC8iLCJNX1VzZXJEZWZhdWx0VF9TYW1wbGVTdGF0aW9uSUQiOiIwIiwiTV9TdGFmZk5hbWUiOiJTdGFmZiBSZWdpb25hbCIsImlzX2NvdXJpZXIiOiJOIiwidGltZV9hdXRvbG9nb3V0IjoiMTIwIiwiTV9Vc2VyTG9jYXRpb25JRCI6IjM3IiwiTV9Vc2VyTG9jYXRpb25GbGFnIjoiUiIsIlNfUmVnaW9uYWxOYW1lIjoiU3VyYWJheWEgUmF5YSIsIlNfUmVnaW9uYWxJRCI6IjYiLCJNX0JyYW5jaE5hbWUiOiIiLCJNX0JyYW5jaENvZGUiOiIiLCJNX0JyYW5jaElEIjoiMCIsImxvZ2luTGV2ZWwiOiJyZWdpb25hbCIsIk1fQnJhbmNoQ29tcGFueUlEIjoiMSIsIk1fQnJhbmNoQ29tcGFueU5hbWUiOiJQVCBQUkFNSVRBIiwiaXAiOiIxMzkuMTk1LjEyMS4xOTgiLCJhZ2VudCI6Ik1vemlsbGFcLzUuMCAoWDExOyBMaW51eCB4ODZfNjQ7IHJ2OjEzOS4wKSBHZWNrb1wvMjAxMDAxMDEgRmlyZWZveFwvMTM5LjAiLCJ2ZXJzaW9uIjoidjIiLCJsYXN0LWxvZ2luIjoiMjAyNS0wNi0yNCAxMzoyMDo0MiIsIk1fU2F0ZWxsaXRlSUQiOjB9.8aaMsJjOaczgBzjx7wOBzQ6l8qDlPBACwxjOVUMZGx0","Date":"2025-06-24","RefNumber":"23123","SupplierID":"7","ItemCategoryID":"1","TaxPercent":0,"PaymentTerm":0,"DiscountPercent":0,"DiscountAmount":0,"WarehouseType":"Single","WarehouseID":"49","Note":"","SubTotal":12417736.5,"TaxPercentPph":0,"TaxPercentPpn":0,"TaxAmount":0,"TaxAmountPph":0,"TaxAmountPpn":0,"GrandTotal":12417736.5,"ShippingCost":0,"ShippingCostStatus":true,"Summary":[{"keyID":"10_33","M_ItemID":"10","PurchaseOrderID":0,"PurchaseOrderSummaryID":0,"M_ItemCode":null,"M_ItemDesc":"ELECSYS T PSA - 4641655190","discount":"0","discountType":"R","PoItemUnitID":"33","ItemUnitCode":"UI230033","PoItemUnitName":"DUS","TotalPoQty":3,"Price":4139245.5,"RealPrice":4139245.5,"PriceAfterDiscount":4139245.5,"Total":12417736.5,"Details":[{"PurchaseRequestFlagID":"192","BranchCode":"LE","UnprocessFlagQty":"3","PurchaseRequestDetailID":"296","PurchaseRequestID":"172","RequestQty":"3","M_ItemID":"10","M_ItemCode":null,"M_ItemDesc":"ELECSYS T PSA - 4641655190","ReqItemUnitID":"12","ReqItemUnitName":"KIT","PoItemUnitID":"33","PoItemUnitName":"DUS","Price":"4139245.5","S_RegionalName":"Surabaya Raya","S_RegionalID":"6","WarehouseID":"44","WarehouseName":"WH034 Gudang Cabang 1 - Pramita Ngagel Jaya","M_BranchName":"Pramita Ngagel Jaya","M_BranchID":"13","PurchaseRequestNumber":"PR25060081","discount":"0","discountType":"R","PoQty":1,"UnitReqPoConvertStatus":"success","UnitReqPoConvertMsg":"Berhasil mapping konversi Req 3 ke PO 1 DUS","Total":4139245.5,"keyID":"10_","DefaultPurchase":{"ItemUnitID":"33","ItemUnitCode":"UI230033","ItemUnitName":"DUS","ItemUnitMapIsPurchase":"Y","ItemUnitMapMin":"0","ItemUnitMapM_ItemID":"10","UnitConvertAmount":"10","SupplierPricePrice":"4139245.5","isPurchased":"Y"},"warehouse":{"WarehouseID":"49","WarehouseCode":"WH039","WarehouseName":"WH039 Gudang Cabang 1 - Pramita HR. Muhammad","WarehouseType":"B","WarehouseIsDefault":"Y","WarehouseS_RegionalID":"6","WarehouseM_BranchID":"18","S_RegionalID":"6","S_RegionalName":"Surabaya Raya"}},{"PurchaseRequestFlagID":"191","BranchCode":"LE","UnprocessFlagQty":"10","PurchaseRequestDetailID":"297","PurchaseRequestID":"173","RequestQty":"12","M_ItemID":"10","M_ItemCode":null,"M_ItemDesc":"ELECSYS T PSA - 4641655190","ReqItemUnitID":"12","ReqItemUnitName":"KIT","PoItemUnitID":"33","PoItemUnitName":"DUS","Price":"4139245.5","S_RegionalName":"Surabaya Raya","S_RegionalID":"6","WarehouseID":"44","WarehouseName":"WH034 Gudang Cabang 1 - Pramita Ngagel Jaya","M_BranchName":"Pramita Ngagel Jaya","M_BranchID":"13","PurchaseRequestNumber":"PR25060082","discount":"0","discountType":"R","PoQty":2,"UnitReqPoConvertStatus":"success","UnitReqPoConvertMsg":"Berhasil mapping konversi Req 12 ke PO 2 DUS","Total":8278491,"keyID":"10_","DefaultPurchase":{"ItemUnitID":"33","ItemUnitCode":"UI230033","ItemUnitName":"DUS","ItemUnitMapIsPurchase":"Y","ItemUnitMapMin":"0","ItemUnitMapM_ItemID":"10","UnitConvertAmount":"10","SupplierPricePrice":"4139245.5","isPurchased":"Y"},"warehouse":{"WarehouseID":"49","WarehouseCode":"WH039","WarehouseName":"WH039 Gudang Cabang 1 - Pramita HR. Muhammad","WarehouseType":"B","WarehouseIsDefault":"Y","WarehouseS_RegionalID":"6","WarehouseM_BranchID":"18","S_RegionalID":"6","S_RegionalName":"Surabaya Raya"}}]}]}
|
||||
|
||||
###
|
||||
// update order
|
||||
POST https://{{host}}/mockup/purchase/order/PurchaseOrder/updateOrder/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"token": {{token}},
|
||||
"ID": "",
|
||||
"Date": "",
|
||||
"RefNumber": "",
|
||||
"SupplierID": "",
|
||||
"TaxPercentPph": "",
|
||||
"TaxPercentPpn": "",
|
||||
"PaymentTerm": "",
|
||||
"DiscountPercent": "",
|
||||
"DiscountAmount": "",
|
||||
"WarehouseType": "",
|
||||
"WarehouseID": "",
|
||||
"Note": "",
|
||||
"SubTotal": "",
|
||||
"TaxAmount": "",
|
||||
"GrandTotal": "",
|
||||
"Details": [
|
||||
{
|
||||
"PurchaseRequestID": "",
|
||||
"PurchaseRequestDetailID": "",
|
||||
"PurchaseRequestFlagID": "",
|
||||
"ItemID": "",
|
||||
"RequestQty": "",
|
||||
"Qty": "",
|
||||
"Price": "",
|
||||
"Total": "",
|
||||
"WarehouseID": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
###
|
||||
// delete order
|
||||
POST https://{{host}}/mockup/purchase/order/PurchaseOrder/deleteOrder/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"PurchaseOrderId": 48,
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
###
|
||||
// get item update
|
||||
POST https://{{host}}/mockup/purchase/order/PurchaseOrder/getItemUpdate/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjMiLCJNX1VzZXJVc2VybmFtZSI6ImFkbWluICIsIk1fVXNlckdyb3VwRGFzaGJvYXJkIjoidGVzdFwvdnVleFwvb25lLWZvLXJlZ2lzdHJhdGlvbi12MzFcLyIsIk1fVXNlckRlZmF1bHRUX1NhbXBsZVN0YXRpb25JRCI6IjAiLCJNX1N0YWZmTmFtZSI6IkFETUlOIiwiaXNfY291cmllciI6Ik4iLCJ0aW1lX2F1dG9sb2dvdXQiOiIxMjAiLCJpcCI6IjE0OS4xMTMuOTUuMTUzIiwiYWdlbnQiOiJNb3ppbGxhXC81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXRcLzUzNy4zNiAoS0hUTUwsIGxpa2UgR2Vja28pIENocm9tZVwvMTI4LjAuMC4wIFNhZmFyaVwvNTM3LjM2IEVkZ1wvMTI4LjAuMC4wIiwidmVyc2lvbiI6InYyIiwibGFzdC1sb2dpbiI6IjIwMjQtMDktMDIgMTE6MzY6MDgiLCJNX1NhdGVsbGl0ZUlEIjowfQ.38owLzgSjtoley0Vz9W9silF4vfp7hrJEQqytYHf8P0",
|
||||
"supplierID": "1",
|
||||
"regionalId": "8",
|
||||
"search": ""
|
||||
}
|
||||
|
||||
###
|
||||
// request order
|
||||
POST https://{{host}}/mockup/purchase/order/PurchaseOrder/requestOrder/
|
||||
Content-Type: application/json
|
||||
|
||||
|
||||
{
|
||||
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjMiLCJNX1VzZXJVc2VybmFtZSI6ImFkbWluICIsIk1fVXNlckdyb3VwRGFzaGJvYXJkIjoidGVzdFwvdnVleFwvb25lLWZvLXJlZ2lzdHJhdGlvbi12MzFcLyIsIk1fVXNlckRlZmF1bHRUX1NhbXBsZVN0YXRpb25JRCI6IjAiLCJNX1N0YWZmTmFtZSI6IkFETUlOIiwiaXNfY291cmllciI6Ik4iLCJ0aW1lX2F1dG9sb2dvdXQiOiIxMjAiLCJpcCI6IjE0OS4xMTMuOTUuMTUzIiwiYWdlbnQiOiJNb3ppbGxhXC81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXRcLzUzNy4zNiAoS0hUTUwsIGxpa2UgR2Vja28pIENocm9tZVwvMTI4LjAuMC4wIFNhZmFyaVwvNTM3LjM2IEVkZ1wvMTI4LjAuMC4wIiwidmVyc2lvbiI6InYyIiwibGFzdC1sb2dpbiI6IjIwMjQtMDktMDIgMTE6MzY6MDgiLCJNX1NhdGVsbGl0ZUlEIjowfQ.38owLzgSjtoley0Vz9W9silF4vfp7hrJEQqytYHf8P0",
|
||||
"ID": ""
|
||||
}
|
||||
|
||||
### Test isValidMultiple Warehouse
|
||||
### Should return True karena UnitRequest = UnitPurchase
|
||||
GET https://{{host}}/mockup/purchase/order/PurchaseOrder/isValidMultipleWarehouse/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"PurchaseRequestDetailIDs" : [288, 289],
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
### Test isValidMultiple Warehouse
|
||||
### Should return True karena ada konversi dan RequestQty kelipatan UnitConvertAmount
|
||||
GET https://{{host}}/mockup/purchase/order/PurchaseOrder/isValidMultipleWarehouse/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"PurchaseRequestDetailIDs" : [288, 289, 290],
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
### Test isValidMultiple Warehouse
|
||||
### Should return False karena ada item yang tidak ada unitconvertnya
|
||||
GET https://{{host}}/mockup/purchase/order/PurchaseOrder/isValidMultipleWarehouse/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"PurchaseRequestDetailIDs" : [288, 289, 295],
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
### Test isValidMultiple Warehouse
|
||||
### Should return False karena ada item yang RequestQty bukan kelipatan UnitConvertAmount
|
||||
GET https://{{host}}/mockup/purchase/order/PurchaseOrder/isValidMultipleWarehouse/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"PurchaseRequestDetailIDs" : [291,292],
|
||||
"token": {{token}}
|
||||
}
|
||||
2432
application/controllers/mockup/purchase/order/PurchaseOrder.php
Normal file
2432
application/controllers/mockup/purchase/order/PurchaseOrder.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
|
||||
class PurchaseOrderAset extends MY_Controller {
|
||||
var $db;
|
||||
public function index() {
|
||||
echo "Purchase Order Aset API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
## QUERY ##
|
||||
public function getListSupplier() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
SupplierID,
|
||||
SupplierName
|
||||
FROM supplier
|
||||
WHERE SupplierIsActive = 'Y'";
|
||||
$que = $this->db->query($sql, []);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] get data supplier");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data = $que->result_array();
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$this->sys_error($exc->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function getListCabang() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$user = $this->sys_user;
|
||||
|
||||
$sql = "SELECT
|
||||
M_BranchID,
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'
|
||||
AND M_BranchS_RegionalID = ?";
|
||||
$que = $this->db->query($sql, [$user['S_RegionalID']]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] failed get list cabang");
|
||||
exit;
|
||||
}
|
||||
|
||||
$data = $que->result_array();
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$this->sys_error($exc->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function searchRequestAset() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$para = $this->sys_input;
|
||||
|
||||
$keyword = "%";
|
||||
if ($para['search'] != '') {
|
||||
$keyword .= $para['search'] . "%";
|
||||
}
|
||||
|
||||
$limit = 10;
|
||||
$offset = 0;
|
||||
if ($para['currpage'] > 0) {
|
||||
$offset = ($para['currpage'] - 1) * $limit;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
PurchaseRequestID,
|
||||
PurchaseRequestNumber,
|
||||
PurchaseRequestDetailID,
|
||||
PurchaseRequestFlagID,
|
||||
PurchaseRequestFlagM_BranchCode AS BranchCode,
|
||||
PurchaseRequestItemCategoryID AS ItemCategoryID,
|
||||
PurchaseRequestFlagQtyRest - PurchaseRequestFlagQtyProses AS UnprocessFlagQty,
|
||||
PurchaseRequestDetailQty AS RequestQty,
|
||||
PurchaseRequestDetailQty AS OriginalQty,
|
||||
M_BranchName,
|
||||
M_ItemID,
|
||||
M_ItemCode,
|
||||
M_ItemDesc,
|
||||
ItemUnitID,
|
||||
ItemUnitName,
|
||||
SupplierPricePrice as SupplierPrice
|
||||
FROM purchase_request
|
||||
JOIN purchase_request_detail ON PurchaseRequestDetailPurchaseRequestID = PurchaseRequestID
|
||||
AND PurchaseRequestDetailIsActive = 'Y'
|
||||
AND PurchaseRequestM_BranchCode = ?
|
||||
AND PurchaseRequestItemCategoryID = '3' -- id category item asset
|
||||
AND PurchaseRequestNumber LIKE ?
|
||||
JOIN purchase_request_flag ON PurchaseRequestFlagPurchaseRequestDetailID = PurchaseRequestDetailID
|
||||
AND PurchaseRequestFlagStatus = 'PO'
|
||||
AND PurchaseRequestFlagIsActive = 'Y'
|
||||
JOIN m_item ON M_ItemID = PurchaseRequestDetailM_ItemID
|
||||
JOIN itemunit ON ItemUnitID = PurchaseRequestDetailItemUnitID
|
||||
JOIN supplier_price ON SupplierPriceSupplierID = ?
|
||||
AND SupplierPriceM_ItemID = M_ItemID
|
||||
AND SupplierPriceItemUnitID = ItemUnitID
|
||||
AND SupplierPriceIsActive = 'Y'
|
||||
JOIN m_branch ON M_BranchCode = PurchaseRequestFlagM_BranchCode
|
||||
AND M_BranchIsActive = 'Y'
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM purchase_order_detail
|
||||
JOIN purchase_order ON PurchaseOrderDetailPurchaseOrderID = PurchaseOrderID
|
||||
AND PurchaseOrderStatus = 'Approved'
|
||||
AND PurchaseOrderIsActive = 'Y'
|
||||
AND PurchaseOrderDetailIsActive = 'Y'
|
||||
WHERE PurchaseOrderDetailPurchaseRequestDetailID = PurchaseRequestDetailID
|
||||
)";
|
||||
|
||||
$sql_data = $sql . " LIMIT ? OFFSET ? ";
|
||||
$que_data = $this->db->query($sql_data, [
|
||||
$para['branchcode'], $keyword, $para['supplierID'],
|
||||
$limit, $offset
|
||||
]);
|
||||
if (!$que_data) {
|
||||
$this->sys_error_db("[Error] get daftar request data");
|
||||
exit;
|
||||
}
|
||||
$data = $que_data->result_array();
|
||||
|
||||
$sql_total = "SELECT COUNT(*) AS total FROM ($sql) AS x";
|
||||
$que_total = $this->db->query($sql_total, [
|
||||
$para['branchcode'], $keyword, $para['supplierID']
|
||||
]);
|
||||
if (!$que_total) {
|
||||
$this->sys_error_db("[Error] get total request aset");
|
||||
exit;
|
||||
}
|
||||
$total = $que_total->row_array()['total'];
|
||||
|
||||
$out = [
|
||||
"records" => $data,
|
||||
"total" => $total
|
||||
];
|
||||
|
||||
$this->sys_ok($out);
|
||||
} catch (Exception $exc) {
|
||||
$this->sys_error($exc->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function getUserApproveLevel() {
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("invalid token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$user = $this->sys_user;
|
||||
$sql = "SELECT M_UserM_ApproveLevelID FROM m_user
|
||||
WHERE M_UserIsActive = 'Y' AND M_UserID = ? ";
|
||||
$que = $this->db->query($sql, [$user['M_UserID']]);
|
||||
if (!$que) {
|
||||
$this->sys_error_db("[Error] failed get approval level user");
|
||||
exit;
|
||||
}
|
||||
$data = $que->row_array();
|
||||
$this->sys_ok($data);
|
||||
} catch (Exception $exc) {
|
||||
$this->sys_error($exc->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
2936
application/controllers/mockup/purchase/order/PurchaseOrderV2.php
Normal file
2936
application/controllers/mockup/purchase/order/PurchaseOrderV2.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,42 @@
|
||||
|
||||
POST https://{{host}}/mockup/purchase/receivesuratjalan/ReceiveSuratJalan/ListingSuratJalan/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjM1NCIsIk1fVXNlclVzZXJuYW1lIjoiYWRtbWF0cmFtYW4iLCJNX1VzZXJHcm91cERhc2hib2FyZCI6Im9uZS11aVwvdGVzdFwvdnVleFwvYWNjLW9uZS1qdXJuYWxcLyIsIk1fVXNlckRlZmF1bHRUX1NhbXBsZVN0YXRpb25JRCI6IjAiLCJNX1N0YWZmTmFtZSI6IkFETUlOIiwiaXNfY291cmllciI6Ik4iLCJ0aW1lX2F1dG9sb2dvdXQiOiIxMjAiLCJNX1VzZXJMb2NhdGlvbklEIjoiMTIiLCJNX1VzZXJMb2NhdGlvbkZsYWciOiJCIiwiU19SZWdpb25hbE5hbWUiOiJKYWthcnRhIFJheWEiLCJTX1JlZ2lvbmFsSUQiOiI4IiwiTV9CcmFuY2hOYW1lIjoiUHJhbWl0YSBNYXRyYW1hbiIsIk1fQnJhbmNoQ29kZSI6IkJBIiwiTV9CcmFuY2hJRCI6IjIzIiwibG9naW5MZXZlbCI6ImJyYW5jaCIsIk1fQnJhbmNoQ29tcGFueUlEIjoiMSIsIk1fQnJhbmNoQ29tcGFueU5hbWUiOiJQVCBQUkFNSVRBIiwiaXAiOiIxMzkuMC45Ny42NCIsImFnZW50IjoiTW96aWxsYVwvNS4wIChXaW5kb3dzIE5UIDEwLjA7IFdpbjY0OyB4NjQpIEFwcGxlV2ViS2l0XC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWVcLzEzNC4wLjAuMCBTYWZhcmlcLzUzNy4zNiIsInZlcnNpb24iOiJ2MiIsImxhc3QtbG9naW4iOiIyMDI1LTAzLTEyIDEzOjM3OjQ2IiwiTV9TYXRlbGxpdGVJRCI6MH0.i4gLQdofhvPCKYd5uHuEsYI0y_rova7BIjjAc4tbP3I",
|
||||
"startdate": "2025-03-01",
|
||||
"enddate": "2025-03-13",
|
||||
"branchcode": "ALL",
|
||||
"status": "All",
|
||||
"search": "",
|
||||
"currpage": 1
|
||||
}
|
||||
|
||||
###
|
||||
POST https://{{host}}/mockup/purchase/receivesuratjalan/ReceiveSuratJalan/GetTFDataDetail/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjM1NCIsIk1fVXNlclVzZXJuYW1lIjoiYWRtbWF0cmFtYW4iLCJNX1VzZXJHcm91cERhc2hib2FyZCI6Im9uZS11aVwvdGVzdFwvdnVleFwvYWNjLW9uZS1qdXJuYWxcLyIsIk1fVXNlckRlZmF1bHRUX1NhbXBsZVN0YXRpb25JRCI6IjAiLCJNX1N0YWZmTmFtZSI6IkFETUlOIiwiaXNfY291cmllciI6Ik4iLCJ0aW1lX2F1dG9sb2dvdXQiOiIxMjAiLCJNX1VzZXJMb2NhdGlvbklEIjoiMTIiLCJNX1VzZXJMb2NhdGlvbkZsYWciOiJCIiwiU19SZWdpb25hbE5hbWUiOiJKYWthcnRhIFJheWEiLCJTX1JlZ2lvbmFsSUQiOiI4IiwiTV9CcmFuY2hOYW1lIjoiUHJhbWl0YSBNYXRyYW1hbiIsIk1fQnJhbmNoQ29kZSI6IkJBIiwiTV9CcmFuY2hJRCI6IjIzIiwibG9naW5MZXZlbCI6ImJyYW5jaCIsIk1fQnJhbmNoQ29tcGFueUlEIjoiMSIsIk1fQnJhbmNoQ29tcGFueU5hbWUiOiJQVCBQUkFNSVRBIiwiaXAiOiIxMzkuMC45Ny42NCIsImFnZW50IjoiTW96aWxsYVwvNS4wIChXaW5kb3dzIE5UIDEwLjA7IFdpbjY0OyB4NjQpIEFwcGxlV2ViS2l0XC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWVcLzEzNC4wLjAuMCBTYWZhcmlcLzUzNy4zNiIsInZlcnNpb24iOiJ2MiIsImxhc3QtbG9naW4iOiIyMDI1LTAzLTEyIDEzOjM3OjQ2IiwiTV9TYXRlbGxpdGVJRCI6MH0.i4gLQdofhvPCKYd5uHuEsYI0y_rova7BIjjAc4tbP3I",
|
||||
"SuratJalanID": 2,
|
||||
"currpagedetail": 1
|
||||
}
|
||||
|
||||
###
|
||||
POST https://{{host}}/mockup/purchase/receivesuratjalan/ReceiveSuratJalan/UpdateSuratJalan/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjM1NCIsIk1fVXNlclVzZXJuYW1lIjoiYWRtbWF0cmFtYW4iLCJNX1VzZXJHcm91cERhc2hib2FyZCI6Im9uZS11aVwvdGVzdFwvdnVleFwvYWNjLW9uZS1qdXJuYWxcLyIsIk1fVXNlckRlZmF1bHRUX1NhbXBsZVN0YXRpb25JRCI6IjAiLCJNX1N0YWZmTmFtZSI6IkFETUlOIiwiaXNfY291cmllciI6Ik4iLCJ0aW1lX2F1dG9sb2dvdXQiOiIxMjAiLCJNX1VzZXJMb2NhdGlvbklEIjoiMTIiLCJNX1VzZXJMb2NhdGlvbkZsYWciOiJCIiwiU19SZWdpb25hbE5hbWUiOiJKYWthcnRhIFJheWEiLCJTX1JlZ2lvbmFsSUQiOiI4IiwiTV9CcmFuY2hOYW1lIjoiUHJhbWl0YSBNYXRyYW1hbiIsIk1fQnJhbmNoQ29kZSI6IkJBIiwiTV9CcmFuY2hJRCI6IjIzIiwibG9naW5MZXZlbCI6ImJyYW5jaCIsIk1fQnJhbmNoQ29tcGFueUlEIjoiMSIsIk1fQnJhbmNoQ29tcGFueU5hbWUiOiJQVCBQUkFNSVRBIiwiaXAiOiIxMzkuMC45Ny42NCIsImFnZW50IjoiTW96aWxsYVwvNS4wIChXaW5kb3dzIE5UIDEwLjA7IFdpbjY0OyB4NjQpIEFwcGxlV2ViS2l0XC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWVcLzEzNC4wLjAuMCBTYWZhcmlcLzUzNy4zNiIsInZlcnNpb24iOiJ2MiIsImxhc3QtbG9naW4iOiIyMDI1LTAzLTEyIDEzOjM3OjQ2IiwiTV9TYXRlbGxpdGVJRCI6MH0.i4gLQdofhvPCKYd5uHuEsYI0y_rova7BIjjAc4tbP3I",
|
||||
"suratJalanID": "23",
|
||||
"goodTransferID": "20",
|
||||
"notereceive": "tess",
|
||||
}
|
||||
|
||||
###
|
||||
POST https://{{host}}/mockup/purchase/receivesuratjalan/ReceiveSuratJalan/GenerateJurnal/6
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,91 @@
|
||||
@host = https://accone.aplikasi.web.id/one-api/mockup/purchase/requester/PurchaseRequestPersediaan
|
||||
@token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjM4MCIsIk1fVXNlclVzZXJuYW1lIjoicmVnc2J5IiwiTV9Vc2VyR3JvdXBEYXNoYm9hcmQiOiJvbmUtdWlcL3Rlc3RcL3Z1ZXhcL2FjYy1vbmUtanVybmFsXC8iLCJNX1VzZXJEZWZhdWx0VF9TYW1wbGVTdGF0aW9uSUQiOiIwIiwiTV9TdGFmZk5hbWUiOiJTdGFmZiBSZWdpb25hbCIsImlzX2NvdXJpZXIiOiJOIiwidGltZV9hdXRvbG9nb3V0IjoiMTIwIiwiTV9Vc2VyTG9jYXRpb25JRCI6IjM3IiwiTV9Vc2VyTG9jYXRpb25GbGFnIjoiUiIsIlNfUmVnaW9uYWxOYW1lIjoiU3VyYWJheWEgUmF5YSIsIlNfUmVnaW9uYWxJRCI6IjYiLCJNX0JyYW5jaE5hbWUiOiIiLCJNX0JyYW5jaENvZGUiOiIiLCJNX0JyYW5jaElEIjoiMCIsImxvZ2luTGV2ZWwiOiJyZWdpb25hbCIsIk1fQnJhbmNoQ29tcGFueUlEIjoiMSIsIk1fQnJhbmNoQ29tcGFueU5hbWUiOiJQVCBQUkFNSVRBIiwiaXAiOiIxNDkuMTEzLjEwMi4yOCIsImFnZW50IjoiTW96aWxsYVwvNS4wIChYMTE7IExpbnV4IHg4Nl82NDsgcnY6MTM3LjApIEdlY2tvXC8yMDEwMDEwMSBGaXJlZm94XC8xMzcuMCIsInZlcnNpb24iOiJ2MiIsImxhc3QtbG9naW4iOiIyMDI1LTA2LTEwIDA4OjUyOjIwIiwiTV9TYXRlbGxpdGVJRCI6MH0.C1y8mxuCzwJOXHuKFNk5mpkJ72lY2GFTjOlZ9Tx5AWc"
|
||||
|
||||
### Save and Request Purchase (Create with Pending status)
|
||||
POST {{host}}/saveAndDoPurchaseRequest
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"itemcategory": "1",
|
||||
"PRDateUse": "2025-06-15",
|
||||
"PRRegional": "REG001",
|
||||
"PRBranch": "BR001",
|
||||
"PRDescription": "Urgent office supplies needed",
|
||||
"items": [
|
||||
{
|
||||
"itemId": 101,
|
||||
"itemCode": "ITM001",
|
||||
"itemDesc": "Printer Paper A4",
|
||||
"unitId": 1,
|
||||
"unitCode": "BOX",
|
||||
"unitName": "Box",
|
||||
"qty": 5,
|
||||
"detailId": 0
|
||||
},
|
||||
{
|
||||
"itemId": 102,
|
||||
"itemCode": "ITM002",
|
||||
"itemDesc": "Stapler",
|
||||
"unitId": 2,
|
||||
"unitCode": "PCS",
|
||||
"unitName": "Pieces",
|
||||
"qty": 10,
|
||||
"detailId": 0
|
||||
}
|
||||
],
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
### For comparison: Regular Save Purchase Request
|
||||
POST {{host}}/savePurchaseRequest
|
||||
Content-Type: application/json
|
||||
Authorization: Bearer YOUR_AUTH_TOKEN_HERE
|
||||
|
||||
{
|
||||
"itemcategory": "1",
|
||||
"PRDateUse": "2025-06-15",
|
||||
"PRRegional": "REG001",
|
||||
"PRBranch": "BR001",
|
||||
"PRDescription": "Regular office supplies order",
|
||||
"items": [
|
||||
{
|
||||
"itemId": 101,
|
||||
"itemCode": "ITM001",
|
||||
"itemDesc": "Printer Paper A4",
|
||||
"unitId": 1,
|
||||
"unitCode": "BOX",
|
||||
"unitName": "Box",
|
||||
"qty": 5,
|
||||
"detailId": 0
|
||||
}
|
||||
],
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
### For comparison: Update Purchase Request with Pending status
|
||||
POST http://localhost/accone/BE/purchase/requester/PurchaseRequestPersediaan/updatePurchaseRequest
|
||||
Content-Type: application/json
|
||||
Authorization: Bearer YOUR_AUTH_TOKEN_HERE
|
||||
|
||||
{
|
||||
"PRID": 123,
|
||||
"PRNumber": "PR202506-001",
|
||||
"itemtype": "1",
|
||||
"PRDateUse": "2025-06-15",
|
||||
"PRRegional": "REG001",
|
||||
"PRBranch": "BR001",
|
||||
"PRDescription": "Updated office supplies",
|
||||
"act": "pending",
|
||||
"items": [
|
||||
{
|
||||
"itemId": 101,
|
||||
"itemCode": "ITM001",
|
||||
"itemDesc": "Printer Paper A4",
|
||||
"unitId": 1,
|
||||
"unitCode": "BOX",
|
||||
"unitName": "Box",
|
||||
"qty": 10,
|
||||
"detailId": 456
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,607 @@
|
||||
<?php
|
||||
|
||||
class PurchaseRequest extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "Purchase Request/Requester API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$query = "SELECT prd.*, mu.M_UserFullName as M_RequesterFullName
|
||||
FROM purchase_request_direct as prd
|
||||
JOIN m_user as mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestCreatedUserID = {$userId}
|
||||
AND PurchaseRequestDirectNumber LIKE '%" . $payload["search"] . "%'";
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM purchase_request_direct as prd
|
||||
JOIN m_user as mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestCreatedUserID = {$userId}
|
||||
AND PurchaseRequestDirectNumber LIKE '%" . $payload["search"] . "%'";
|
||||
|
||||
if ((isset($payload["startDate"]) && isset($payload["endDate"])) && (trim($payload["startDate"]) !== "" && trim($payload["endDate"]) !== "")) {
|
||||
$query .= " AND (PurchaseRequestDirectDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59' OR PurchaseRequestDirectDateUse BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
$queryCount .= " AND (PurchaseRequestDirectDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59' OR PurchaseRequestDirectDateUse BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
}
|
||||
|
||||
if ($payload["status"]) {
|
||||
$query .= " AND PurchaseRequestDirectStatus = {$payload["status"]}";
|
||||
$queryCount .= " AND PurchaseRequestDirectStatus = {$payload["status"]}";
|
||||
}
|
||||
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$numberLimit = 20;
|
||||
$numberOffset = 0;
|
||||
if ($payload["currentPage"] > 0) {
|
||||
$numberOffset = ($payload["currentPage"] - 1) * $numberLimit;
|
||||
}
|
||||
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
$totalPage = ceil($totalCount / $numberLimit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
$query .= " ORDER BY PurchaseRequestDirectNumber DESC
|
||||
LIMIT {$numberLimit} OFFSET {$numberOffset}";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $totalPage,
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function searchDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$totalCount = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request detail", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = "SELECT *,
|
||||
ROW_NUMBER() OVER(ORDER BY PurchaseRequestDirectDetailID) RowNumber
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
ORDER BY PurchaseRequestDirectDetailStatus ASC,
|
||||
PurchaseRequestDirectDetailID ASC";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getBranch()
|
||||
{
|
||||
try {
|
||||
$query = "SELECT DISTINCT
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'
|
||||
ORDER BY M_BranchName ASC";
|
||||
$exec = $this->db->query($query, []);
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select branch", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function saveRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$pdSql = "SELECT `fn_numbering`('PD') AS PD";
|
||||
$exec = $this->db->query($pdSql, []);
|
||||
$pd = "";
|
||||
$dateNow = date('Y-m-d');
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request insert error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$pd = $exec->result_array()[0]["PD"];
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO purchase_request_direct(
|
||||
PurchaseRequestDirectNumber,
|
||||
PurchaseRequestDirectDate,
|
||||
PurchaseRequestDirectDateUse,
|
||||
PurchaseRequestDirectM_BranchCode,
|
||||
PurchaseRequestDirectDescription,
|
||||
PurchaseRequestDirectNote,
|
||||
PurchaseRequestDirectTotalEstimation,
|
||||
PurchaseRequestDirectTotalPaid,
|
||||
PurchaseRequestDirectTotalRealitation,
|
||||
PurchaseRequestDirectStatus,
|
||||
PurchaseRequestApprovedDate,
|
||||
PurchaseRequestApprovedBy,
|
||||
PurchaseRequestConfirmedDate,
|
||||
PurchaseRequestConfirmedBy,
|
||||
PurchaseRequestPaidDate,
|
||||
PurchaseRequestPaidBy,
|
||||
PurchaseRequestDirectIsActive,
|
||||
PurchaseRequestCreated,
|
||||
PurchaseRequestLastUpdated,
|
||||
PurchaseRequestDeleted,
|
||||
PurchaseRequestCreatedUserID,
|
||||
PurchaseRequestLastUpdatedUserID,
|
||||
PurchaseRequestDeletedUserID
|
||||
) VALUES ('{$pd}', '{$dateNow}', '{$payload['PRDateUse']}', '{$payload['PRBranch']}', '{$payload['PRDescription']}', NULL, 0, 0, 0, 'Draft', NULL, NULL, NULL, NULL, NULL, NULL, 'Y', NOW(), NULL, NULL, {$userId}, NULL, NULL)";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request insert error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$newInsert = "SELECT * FROM purchase_request_direct WHERE PurchaseRequestDirectNumber = '{$pd}' AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$records = $this->db->query($newInsert, [])->result_array();
|
||||
|
||||
$result = array("total" => 1, "records" => $records);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function updateRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectDateUse = '{$payload['PRDateUse']}',
|
||||
PurchaseRequestDirectM_BranchCode = '{$payload['PRBranch']}',
|
||||
PurchaseRequestDirectDescription = '{$payload['PRDescription']}',
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request update error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$newUpdate = "SELECT * FROM purchase_request_direct WHERE PurchaseRequestDirectID = {$payload['PRID']} AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$records = $this->db->query($newUpdate, [])->result_array();
|
||||
|
||||
$result = array("total" => 1, "records" => $records);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDeleted = NOW(),
|
||||
PurchaseRequestDeletedUserID = {$userId},
|
||||
PurchaseRequestDirectIsActive = 'N'
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request delete error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xId" => 0));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function saveDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
$PRDTotalPrice = intval($payload['PRDAmountRequest']) * intval($payload['PRDEstimationPrice']);
|
||||
|
||||
$query = "SELECT COUNT(*) as exist
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDescription = '{$payload['PRDDescriptionDetail']}'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exist = $this->db->query($query, []);
|
||||
if ($exist) {
|
||||
$row = $exist->row()->exist;
|
||||
} else {
|
||||
$this->sys_error_db("exist error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($row == 0) {
|
||||
$sql = "INSERT INTO purchase_request_direct_detail(
|
||||
PurchaseRequestDirectDetailPurchaseRequestDirectID,
|
||||
PurchaseRequestDirectDescription,
|
||||
PurchaseRequestDirectDetailAmountRequest,
|
||||
PurchaseRequestDirectDetailAmount,
|
||||
PurchaseRequestDirectDetailEstimationPrice,
|
||||
PurchaseRequestDirectDetailTotalEstimationPrice,
|
||||
PurchaseRequestDirectDetailTotalRealitationPrice,
|
||||
PurchaseRequestDirectDetailStatus,
|
||||
PurchaseRequestDirectDetailIsActive,
|
||||
PurchaseRequestDirectDetailCreated,
|
||||
PurchaseRequestDirectDetailLastUpdated,
|
||||
PurchaseRequestDirectDetailDeleted,
|
||||
PurchaseRequestDirectDetailCreatedUserID,
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID,
|
||||
PurchaseRequestDirectDetailDeletedUserID
|
||||
) VALUES ({$payload['PRID']}, '{$payload['PRDDescriptionDetail']}', {$payload['PRDAmountRequest']}, NULL, {$payload['PRDEstimationPrice']}, {$PRDTotalPrice}, NULL, 'Pending', 'Y', NOW(), NULL, NULL, {$userId}, NULL, NULL)";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("request insert error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$sqlTotalPrice = "SELECT SUM(PurchaseRequestDirectDetailTotalEstimationPrice) AS Total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlTotalPrice, []);
|
||||
$total = 0;
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$total = $exec->result_array()[0]["Total"];
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectTotalEstimation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$result = array("total" => 1, "records" => array("xId" => 0));
|
||||
$this->sys_ok($result);
|
||||
} else {
|
||||
$errors = array();
|
||||
if ($row != 0) {
|
||||
array_push($errors, array('msg' => 'Data sudah ada'));
|
||||
}
|
||||
|
||||
$result = array("total" => -1, "errors" => $errors, "records" => array('status' => 'ERROR'));
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function updateDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
$PRDTotalPrice = intval($payload["PRDAmountRequest"]) * intval($payload["PRDEstimationPrice"]);
|
||||
|
||||
|
||||
$sql = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDescription = '{$payload["PRDDescriptionDetail"]}',
|
||||
PurchaseRequestDirectDetailAmountRequest = {$payload["PRDAmountRequest"]},
|
||||
PurchaseRequestDirectDetailEstimationPrice = {$payload["PRDEstimationPrice"]},
|
||||
PurchaseRequestDirectDetailTotalEstimationPrice = {$PRDTotalPrice},
|
||||
PurchaseRequestDirectDetailLastUpdated = NOW(),
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailID = {$payload["PRDID"]}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("request update error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$sqlTotalPrice = "SELECT SUM(PurchaseRequestDirectDetailTotalEstimationPrice) AS Total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlTotalPrice, []);
|
||||
$total = 0;
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$total = $exec->result_array()[0]["Total"];
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectTotalEstimation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$result = array("total" => 1, "records" => array("xId" => $payload["PRDID"]));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailDeleted = NOW(),
|
||||
PurchaseRequestDirectDetailDeletedUserID = {$userId},
|
||||
PurchaseRequestDirectDetailIsActive = 'N'
|
||||
WHERE PurchaseRequestDirectDetailID = {$payload["PRDID"]}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("request delete error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$sqlTotalPrice = "SELECT SUM(PurchaseRequestDirectDetailTotalEstimationPrice) AS Total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlTotalPrice, []);
|
||||
$total = 0;
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$total = $exec->result_array()[0]["Total"] ?? 0;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectTotalEstimation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xId" => 0));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function orderRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailLastUpdated = NOW(),
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailStatus = 'Pending'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectStatus = 'Pending',
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$sql = "SELECT *,
|
||||
ROW_NUMBER() OVER(ORDER BY PurchaseRequestDirectNumber) RowNumber
|
||||
FROM purchase_request_direct
|
||||
WHERE PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestCreatedUserID = {$userId}
|
||||
AND PurchaseRequestDirectID = {$payload["PRID"]}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
$row = [];
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$row = $exec->result_array();
|
||||
}
|
||||
$result = array("total" => 1, "records" => $row);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,951 @@
|
||||
<?php
|
||||
|
||||
class PurchaseRequestDirect extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "Purchase Request/Requester API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$query = "SELECT prd.*, mu.M_UserFullName as M_RequesterFullName,
|
||||
S_RegionalID,
|
||||
S_RegionalName,
|
||||
M_BranchID,
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM purchase_request_direct as prd
|
||||
JOIN m_user as mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
LEFT JOIN s_regional ON S_RegionalID = PurchaseRequestDirectS_RegionalID
|
||||
LEFT JOIN m_branch ON M_BranchCode = PurchaseRequestDirectM_BranchCode
|
||||
WHERE PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestCreatedUserID = {$userId}
|
||||
AND PurchaseRequestDirectNumber LIKE '%" . $payload["search"] . "%'";
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM purchase_request_direct as prd
|
||||
JOIN m_user as mu ON prd.PurchaseRequestCreatedUserID = mu.M_UserID
|
||||
WHERE PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestCreatedUserID = {$userId}
|
||||
AND PurchaseRequestDirectNumber LIKE '%" . $payload["search"] . "%'";
|
||||
|
||||
if ((isset($payload["startDate"]) && isset($payload["endDate"])) && (trim($payload["startDate"]) !== "" && trim($payload["endDate"]) !== "")) {
|
||||
$query .= " AND (PurchaseRequestDirectDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59' OR PurchaseRequestDirectDateUse BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
$queryCount .= " AND (PurchaseRequestDirectDate BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59' OR PurchaseRequestDirectDateUse BETWEEN '{$payload["startDate"]} 00:00:00' AND '{$payload["endDate"]} 23:59:59')";
|
||||
}
|
||||
|
||||
if ($payload["status"]) {
|
||||
$query .= " AND PurchaseRequestDirectStatus = {$payload["status"]}";
|
||||
$queryCount .= " AND PurchaseRequestDirectStatus = {$payload["status"]}";
|
||||
}
|
||||
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$numberLimit = 20;
|
||||
$numberOffset = 0;
|
||||
if ($payload["currentPage"] > 0) {
|
||||
$numberOffset = ($payload["currentPage"] - 1) * $numberLimit;
|
||||
}
|
||||
|
||||
$totalCount = 0;
|
||||
$totalPage = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
$totalPage = ceil($totalCount / $numberLimit);
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
$query .= " ORDER BY PurchaseRequestDirectNumber DESC
|
||||
LIMIT {$numberLimit} OFFSET {$numberOffset}";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $totalPage,
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function searchDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$payload = $this->sys_input;
|
||||
|
||||
$queryCount = "SELECT count(*) as total
|
||||
FROM purchase_request_direct_detail
|
||||
LEFT JOIN itemunit ON PurchaseRequestDirectDetailItemUnitID = ItemUnitID
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($queryCount, []);
|
||||
|
||||
$totalCount = 0;
|
||||
|
||||
if ($exec) {
|
||||
$totalCount = $exec->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request detail", $this->db);;
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = "SELECT *,
|
||||
ItemUnitID,
|
||||
ItemUnitName,
|
||||
ROW_NUMBER() OVER(ORDER BY PurchaseRequestDirectDetailID) RowNumber
|
||||
FROM purchase_request_direct_detail
|
||||
LEFT JOIN itemunit ON PurchaseRequestDirectDetailItemUnitID = ItemUnitID
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
ORDER BY PurchaseRequestDirectDetailStatus ASC,
|
||||
PurchaseRequestDirectDetailID ASC";
|
||||
$exec = $this->db->query($query, []);
|
||||
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select purchase request detail", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"totalFilter" => $totalCount,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getRegionalBranchByUser()
|
||||
{
|
||||
try {
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$query = "SELECT DISTINCT
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'
|
||||
ORDER BY M_BranchName ASC";
|
||||
$exec = $this->db->query($query, []);
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select branch", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getBranch()
|
||||
{
|
||||
try {
|
||||
$query = "SELECT DISTINCT
|
||||
M_BranchCode,
|
||||
M_BranchName
|
||||
FROM m_branch
|
||||
WHERE M_BranchIsActive = 'Y'
|
||||
ORDER BY M_BranchName ASC";
|
||||
$exec = $this->db->query($query, []);
|
||||
if ($exec) {
|
||||
$rows = $exec->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("select branch", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function saveRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$pdSql = "SELECT `fn_numbering`('PD') AS PD";
|
||||
$exec = $this->db->query($pdSql, []);
|
||||
$pd = "";
|
||||
$dateNow = date('Y-m-d');
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request insert error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$pd = $exec->result_array()[0]["PD"];
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO purchase_request_direct(
|
||||
PurchaseRequestDirectNumber,
|
||||
PurchaseRequestDirectDate,
|
||||
PurchaseRequestDirectDateUse,
|
||||
PurchaseRequestDirectS_RegionalID,
|
||||
PurchaseRequestDirectM_BranchCode,
|
||||
PurchaseRequestDirectDescription,
|
||||
PurchaseRequestDirectNote,
|
||||
PurchaseRequestDirectTotalEstimation,
|
||||
PurchaseRequestDirectTotalPaid,
|
||||
PurchaseRequestDirectTotalRealitation,
|
||||
PurchaseRequestDirectStatus,
|
||||
PurchaseRequestDirectApprovedDate,
|
||||
PurchaseRequestDirectApprovedBy,
|
||||
PurchaseRequestConfirmedDate,
|
||||
PurchaseRequestConfirmedBy,
|
||||
PurchaseRequestPaidDate,
|
||||
PurchaseRequestPaidBy,
|
||||
PurchaseRequestDirectIsActive,
|
||||
PurchaseRequestCreated,
|
||||
PurchaseRequestLastUpdated,
|
||||
PurchaseRequestDeleted,
|
||||
PurchaseRequestCreatedUserID,
|
||||
PurchaseRequestLastUpdatedUserID,
|
||||
PurchaseRequestDeletedUserID
|
||||
) VALUES ('{$pd}', '{$dateNow}', '{$payload['PRDateUse']}', '{$payload['PRRegional']}', '{$payload['PRBranch']}', '{$payload['PRDescription']}', NULL, 0, 0, 0, 'Draft', NULL, NULL, NULL, NULL, NULL, NULL, 'Y', NOW(), NULL, NULL, {$userId}, NULL, NULL)";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request insert error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$prId = $this->db->insert_id();
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$newInsert = "SELECT * FROM purchase_request_direct WHERE PurchaseRequestDirectID = '{$prId}' AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$records = $this->db->query($newInsert, [])->result_array();
|
||||
|
||||
$sql = "SELECT * FROM purchase_request_direct
|
||||
JOIN m_user ON M_UserID = PurchaseRequestCreatedUserID
|
||||
WHERE PurchaseRequestDirectID = ?";
|
||||
$query = $this->db->query($sql, [$prId]);
|
||||
$row = $query->row_array();
|
||||
$data = array("header" => $row);
|
||||
$message = "Nomor PRD: " . $row["PurchaseRequestDirectNumber"] . " berhasil dibuat oleh " . $row["M_UserUsername"];
|
||||
$this->insert_act_log("PRD", "NEW", $message, $prId, $this->safeJsonEncode($data), $userId);
|
||||
|
||||
$result = array("total" => 1, "records" => $records);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function updateRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
$messages_log = [];
|
||||
$datas_log = [];
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
$prDateUse = isset($payload["PRDateUse"]) ? $payload["PRDateUse"] : "";
|
||||
$prId = isset($payload["PRID"]) ? $payload["PRID"] : "";
|
||||
$prDateUse = date("Y-m-d", strtotime($prDateUse));
|
||||
if ($prDateUse == "" || $prDateUse == null) {
|
||||
$this->sys_error("Invalid PR Date Use");
|
||||
exit;
|
||||
}
|
||||
$prDescription = isset($payload["PRDescription"]) ? $payload["PRDescription"] : "";
|
||||
$PRBranch = isset($payload["PRBranch"]) ? $payload["PRBranch"] : "";
|
||||
$sql = "SELECT *
|
||||
FROM purchase_request_direct
|
||||
WHERE PurchaseRequestDirectID = ? AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$prId]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request direct", $this->db);
|
||||
exit;
|
||||
}
|
||||
$row = $query->row_array();
|
||||
|
||||
|
||||
$datas_log['header'] = $row;
|
||||
|
||||
if ($row["PurchaseRequestDirectDateUse"] != $prDateUse) {
|
||||
$messages_log[] = "Perubahan tanggal PR: " . $row["PurchaseRequestDirectDateUse"] . " menjadi " . $prDateUse;
|
||||
}
|
||||
if ($row["PurchaseRequestDirectDescription"] != $prDescription) {
|
||||
$messages_log[] = "Perubahan keterangan PR: " . $row["PurchaseRequestDirectDescription"] . " menjadi " . $prDescription;
|
||||
}
|
||||
if ($row["PurchaseRequestDirectM_BranchCode"] != $PRBranch) {
|
||||
$messages_log[] = "Perubahan kode cabang PR: " . $row["PurchaseRequestDirectM_BranchCode"] . " menjadi " . $PRBranch;
|
||||
}
|
||||
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectDateUse = '{$payload['PRDateUse']}',
|
||||
PurchaseRequestDirectM_BranchCode = '{$payload['PRBranch']}',
|
||||
PurchaseRequestDirectDescription = '{$payload['PRDescription']}',
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request update error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$newUpdate = "SELECT * FROM purchase_request_direct WHERE PurchaseRequestDirectID = {$payload['PRID']} AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$records = $this->db->query($newUpdate, [])->result_array();
|
||||
|
||||
if (count($messages_log) > 0) {
|
||||
$message = "Perubahan PR Pembelian Langsung: " . $prNumber . "\n";
|
||||
$message .= implode("\n", $messages_log);
|
||||
} else {
|
||||
$message = "PR Pembelian Langsung: " . $prNumber . " tanpa perubahan";
|
||||
}
|
||||
|
||||
$datas_log = $this->convertNumericValuesToStrings($datas_log);
|
||||
$this->insert_act_log("PRNP", "Update", $message, $prId, $this->safeJsonEncode($datas_log), $userId);
|
||||
|
||||
$result = array("total" => 1, "records" => $records);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$prId = $payload['PRID'];
|
||||
|
||||
$datas_log = array();
|
||||
$sql = "SELECT * FROM purchase_request_direct WHERE PurchaseRequestDirectID = ? AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$prId]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$header = $query->row_array();
|
||||
|
||||
|
||||
$datas_log['header'] = $header;
|
||||
$sql = "SELECT *
|
||||
FROM purchase_request_direct_detail
|
||||
JOIN itemunit ON ItemUnitID = PurchaseRequestDirectDetailItemUnitID
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = ? AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, [$prId]);
|
||||
if (!$query) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request detail select", $this->db);
|
||||
exit;
|
||||
}
|
||||
$details = $query->result_array();
|
||||
$datas_log['details'] = $details;
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDeleted = NOW(),
|
||||
PurchaseRequestDeletedUserID = {$userId},
|
||||
PurchaseRequestDirectIsActive = 'N'
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request delete error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailDeleted = NOW(),
|
||||
PurchaseRequestDirectDetailDeletedUserID = {$userId},
|
||||
PurchaseRequestDirectDetailIsActive = 'N'
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("purchase request detail delete error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$messages = "Purchase Request Pembelian langsung dengan kode " . $header["PurchaseRequestDirectNumber"] . " sudah dihapus";
|
||||
$this->insert_act_log("PRNP", "Delete", $messages, $prId, $this->safeJsonEncode($datas_log), $userId);
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xId" => 0));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function saveDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
$PRDTotalPrice = intval($payload['PRDAmountRequest']) * intval($payload['PRDEstimationPrice']);
|
||||
|
||||
$query = "SELECT COUNT(*) as exist
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDescription = '{$payload['PRDDescriptionDetail']}'
|
||||
AND PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}";
|
||||
$exist = $this->db->query($query, []);
|
||||
if ($exist) {
|
||||
$row = $exist->row()->exist;
|
||||
} else {
|
||||
$this->sys_error_db("exist error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($row == 0) {
|
||||
$sql = "INSERT INTO purchase_request_direct_detail(
|
||||
PurchaseRequestDirectDetailPurchaseRequestDirectID,
|
||||
PurchaseRequestDirectDetailItemUnitID,
|
||||
PurchaseRequestDirectDescription,
|
||||
PurchaseRequestDirectDetailAmountRequest,
|
||||
PurchaseRequestDirectDetailAmount,
|
||||
PurchaseRequestDirectDetailEstimationPrice,
|
||||
PurchaseRequestDirectDetailTotalEstimationPrice,
|
||||
PurchaseRequestDirectDetailTotalRealitationPrice,
|
||||
PurchaseRequestDirectDetailStatus,
|
||||
PurchaseRequestDirectDetailIsActive,
|
||||
PurchaseRequestDirectDetailCreated,
|
||||
PurchaseRequestDirectDetailLastUpdated,
|
||||
PurchaseRequestDirectDetailDeleted,
|
||||
PurchaseRequestDirectDetailCreatedUserID,
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID,
|
||||
PurchaseRequestDirectDetailDeletedUserID
|
||||
) VALUES ({$payload['PRID']}, {$payload['PRDItemUnitID']}, '{$payload['PRDDescriptionDetail']}', {$payload['PRDAmountRequest']}, NULL, {$payload['PRDEstimationPrice']}, {$PRDTotalPrice}, NULL, 'Pending', 'Y', NOW(), NULL, NULL, {$userId}, NULL, NULL)";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("request insert error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$sqlTotalPrice = "SELECT SUM(PurchaseRequestDirectDetailTotalEstimationPrice) AS Total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlTotalPrice, []);
|
||||
$total = 0;
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$total = $exec->result_array()[0]["Total"];
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectTotalEstimation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload['PRID']}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
}
|
||||
$prId = $payload['PRID'];
|
||||
$sql = "SELECT * FROM purchase_request_direct
|
||||
JOIN m_user ON M_UserID = PurchaseRequestCreatedUserID
|
||||
WHERE PurchaseRequestDirectID = ?";
|
||||
$query = $this->db->query($sql, [$prId]);
|
||||
$row = $query->row_array();
|
||||
|
||||
$sql = "SELECT * FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = ?";
|
||||
$query = $this->db->query($sql, [$prId]);
|
||||
$rows = $query->row_array();
|
||||
|
||||
$data = array(
|
||||
"header" => $row,
|
||||
"details" => $rows
|
||||
);
|
||||
$message = "Penambahan Item Nomor PRD: " . $row["PurchaseRequestDirectNumber"] . " oleh " . $row["M_UserUsername"]
|
||||
. " Item : " . $payload['PRDDescriptionDetail'] . " jumlah : " . $payload['PRDAmountRequest'] . "harga : " . $payload['PRDAmountRequest'];
|
||||
$this->insert_act_log("PRD", "NEW", $message, $prId, $this->safeJsonEncode($data), $userId);
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$result = array("total" => 1, "records" => array("xId" => 0));
|
||||
$this->sys_ok($result);
|
||||
} else {
|
||||
$errors = array();
|
||||
if ($row != 0) {
|
||||
array_push($errors, array('msg' => 'Data sudah ada'));
|
||||
}
|
||||
|
||||
$result = array("total" => -1, "errors" => $errors, "records" => array('status' => 'ERROR'));
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function updateDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
$PRDTotalPrice = intval($payload["PRDAmountRequest"]) * intval($payload["PRDEstimationPrice"]);
|
||||
|
||||
|
||||
|
||||
$sql = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailItemUnitID = {$payload["PRDItemUnitID"]},
|
||||
PurchaseRequestDirectDescription = '{$payload["PRDDescriptionDetail"]}',
|
||||
PurchaseRequestDirectDetailAmountRequest = {$payload["PRDAmountRequest"]},
|
||||
PurchaseRequestDirectDetailEstimationPrice = {$payload["PRDEstimationPrice"]},
|
||||
PurchaseRequestDirectDetailTotalEstimationPrice = {$PRDTotalPrice},
|
||||
PurchaseRequestDirectDetailLastUpdated = NOW(),
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailID = {$payload["PRDID"]}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("request update error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$sqlTotalPrice = "SELECT SUM(PurchaseRequestDirectDetailTotalEstimationPrice) AS Total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlTotalPrice, []);
|
||||
$total = 0;
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$total = $exec->result_array()[0]["Total"];
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectTotalEstimation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$result = array("total" => 1, "records" => array("xId" => $payload["PRDID"]));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteDetail()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sql = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailDeleted = NOW(),
|
||||
PurchaseRequestDirectDetailDeletedUserID = {$userId},
|
||||
PurchaseRequestDirectDetailIsActive = 'N'
|
||||
WHERE PurchaseRequestDirectDetailID = {$payload["PRDID"]}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("request delete error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$sqlTotalPrice = "SELECT SUM(PurchaseRequestDirectDetailTotalEstimationPrice) AS Total
|
||||
FROM purchase_request_direct_detail
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'";
|
||||
$exec = $this->db->query($sqlTotalPrice, []);
|
||||
$total = 0;
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$total = $exec->result_array()[0]["Total"] ?? 0;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectTotalEstimation = {$total},
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array("total" => 1, "records" => array("xId" => 0));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function orderRequest()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
}
|
||||
|
||||
$this->db->trans_begin();
|
||||
|
||||
$payload = $this->sys_input;
|
||||
$userId = $this->sys_user["M_UserID"];
|
||||
|
||||
$sqlDetail = "UPDATE purchase_request_direct_detail SET
|
||||
PurchaseRequestDirectDetailLastUpdated = NOW(),
|
||||
PurchaseRequestDirectDetailLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectDetailPurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
AND PurchaseRequestDirectDetailStatus = 'Pending'";
|
||||
$exec = $this->db->query($sqlDetail, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE purchase_request_direct SET
|
||||
PurchaseRequestDirectStatus = 'Pending',
|
||||
PurchaseRequestLastUpdated = NOW(),
|
||||
PurchaseRequestLastUpdatedUserID = {$userId}
|
||||
WHERE PurchaseRequestDirectID = {$payload["PRID"]}
|
||||
AND PurchaseRequestDirectIsActive = 'Y'";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
|
||||
$sql = "SELECT *,
|
||||
ROW_NUMBER() OVER(ORDER BY PurchaseRequestDirectNumber) RowNumber
|
||||
FROM purchase_request_direct
|
||||
WHERE PurchaseRequestDirectIsActive = 'Y'
|
||||
AND PurchaseRequestCreatedUserID = {$userId}
|
||||
AND PurchaseRequestDirectID = {$payload["PRID"]}";
|
||||
$exec = $this->db->query($sql, []);
|
||||
|
||||
$row = [];
|
||||
if (!$exec) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("order purchase request error", $this->db);
|
||||
exit;
|
||||
} else {
|
||||
$row = $exec->result_array();
|
||||
}
|
||||
$result = array("total" => 1, "records" => $row);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function getUnit()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$search = isset($prm["search"]) ? $prm["search"] : "";
|
||||
|
||||
$sql = "SELECT
|
||||
ItemUnitID,
|
||||
ItemUnitCode,
|
||||
ItemUnitName,
|
||||
ItemUnitCreated,
|
||||
ItemUnitLastUpdated,
|
||||
ItemUnitIsActive,
|
||||
ItemUnitUserID
|
||||
FROM itemunit
|
||||
WHERE ItemUnitIsActive = 'Y'
|
||||
AND ItemUnitName LIKE '%$search%'
|
||||
ORDER BY ItemUnitName ASC";
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
if (!$query) {
|
||||
$this->sys_error_db("item unit list", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $query->result_array();
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function insert_act_log($code, $status, $description, $refId, $data, $userId)
|
||||
{
|
||||
$sql = "INSERT INTO user_activity(
|
||||
UserActivityCode,
|
||||
UserActivityStatus,
|
||||
UserActivityDescription,
|
||||
UserActivityRefID,
|
||||
UserActivityData,
|
||||
UserActivityUserID,
|
||||
UserActivityCreated)
|
||||
VALUES (?,?,?,?,?,?,?)";
|
||||
$query = $this->db->query($sql, [$code, $status, $description, $refId, $data, $userId, date("Y-m-d H:i:s")]);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("user activity", $this->db);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
private function safeJsonEncode($data)
|
||||
{
|
||||
// Coba encode data ke JSON
|
||||
$jsonData = json_encode($data);
|
||||
|
||||
// Cek apakah terjadi error saat encode
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
$errorMsg = json_last_error_msg();
|
||||
error_log("JSON encode error: " . $errorMsg);
|
||||
|
||||
// Lakukan sanitasi dan perbaikan data
|
||||
$fixedData = $this->fixJsonEncodeIssues($data, $errorMsg);
|
||||
|
||||
// Coba encode lagi setelah diperbaiki
|
||||
$jsonData = json_encode($fixedData);
|
||||
|
||||
// Jika masih error, log dan kembalikan objek kosong
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
error_log("Failed to fix JSON encode issues: " . json_last_error_msg());
|
||||
// Kembalikan objek kosong jika masih gagal
|
||||
return '{}';
|
||||
}
|
||||
}
|
||||
|
||||
return $jsonData;
|
||||
}
|
||||
|
||||
// Fungsi untuk memperbaiki masalah encoding JSON
|
||||
private function fixJsonEncodeIssues($data, $errorMsg)
|
||||
{
|
||||
// Buat salinan data untuk dimodifikasi
|
||||
$fixedData = $data;
|
||||
|
||||
// Tangani berbagai jenis error
|
||||
if (strpos($errorMsg, 'Malformed UTF-8') !== false) {
|
||||
// Perbaiki masalah karakter UTF-8
|
||||
$fixedData = $this->fixUTF8Issues($fixedData);
|
||||
} else if (strpos($errorMsg, 'Inf and NaN cannot be JSON encoded') !== false) {
|
||||
// Perbaiki masalah nilai Infinity atau NaN
|
||||
$fixedData = $this->fixInfNanIssues($fixedData);
|
||||
} else {
|
||||
// Konversi semua nilai numerik menjadi string untuk menghindari masalah presisi
|
||||
$fixedData = $this->convertNumericValuesToStrings($fixedData);
|
||||
|
||||
// Perbaiki masalah referensi recursif
|
||||
$fixedData = $this->fixRecursiveReferences($fixedData);
|
||||
}
|
||||
|
||||
return $fixedData;
|
||||
}
|
||||
|
||||
// Perbaiki masalah karakter UTF-8
|
||||
private function fixUTF8Issues($data)
|
||||
{
|
||||
if (is_string($data)) {
|
||||
return mb_convert_encoding($data, 'UTF-8', 'UTF-8');
|
||||
} else if (is_array($data)) {
|
||||
foreach ($data as $key => $value) {
|
||||
$data[$key] = $this->fixUTF8Issues($value);
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
// Perbaiki masalah nilai Infinity atau NaN
|
||||
private function fixInfNanIssues($data)
|
||||
{
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $key => $value) {
|
||||
if (is_float($value) && (is_nan($value) || is_infinite($value))) {
|
||||
$data[$key] = (string)$value; // Konversi ke string
|
||||
} else if (is_array($value)) {
|
||||
$data[$key] = $this->fixInfNanIssues($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
// Perbaiki masalah referensi recursif
|
||||
private function fixRecursiveReferences($data, $depth = 0)
|
||||
{
|
||||
// Batasi kedalaman rekursi untuk menghindari infinite loop
|
||||
if ($depth > 50) {
|
||||
return "[MAX_DEPTH_REACHED]";
|
||||
}
|
||||
|
||||
if (is_array($data)) {
|
||||
$result = [];
|
||||
foreach ($data as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$result[$key] = $this->fixRecursiveReferences($value, $depth + 1);
|
||||
} else {
|
||||
$result[$key] = $value;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
// Cari dan konversi numerik ke string secara rekursif
|
||||
private function convertNumericValuesToStrings($data)
|
||||
{
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$data[$key] = $this->convertNumericValuesToStrings($value);
|
||||
} else if (is_numeric($value)) {
|
||||
$data[$key] = (string)$value;
|
||||
} else if (is_bool($value)) {
|
||||
$data[$key] = $value ? "true" : "false";
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1348
application/controllers/mockup/purchase/suratjalan/SuratJalan.php
Normal file
1348
application/controllers/mockup/purchase/suratjalan/SuratJalan.php
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,540 @@
|
||||
@token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjM4MCIsIk1fVXNlclVzZXJuYW1lIjoicmVnc2J5IiwiTV9Vc2VyR3JvdXBEYXNoYm9hcmQiOiJvbmUtdWlcL3Rlc3RcL3Z1ZXhcL2FjYy1vbmUtanVybmFsXC8iLCJNX1VzZXJEZWZhdWx0VF9TYW1wbGVTdGF0aW9uSUQiOiIwIiwiTV9TdGFmZk5hbWUiOiJTdGFmZiBSZWdpb25hbCIsImlzX2NvdXJpZXIiOiJOIiwidGltZV9hdXRvbG9nb3V0IjoiMTIwIiwiTV9Vc2VyTG9jYXRpb25JRCI6IjM3IiwiTV9Vc2VyTG9jYXRpb25GbGFnIjoiUiIsIlNfUmVnaW9uYWxOYW1lIjoiU3VyYWJheWEgUmF5YSIsIlNfUmVnaW9uYWxJRCI6IjYiLCJNX0JyYW5jaE5hbWUiOiIiLCJNX0JyYW5jaENvZGUiOiIiLCJNX0JyYW5jaElEIjoiMCIsImxvZ2luTGV2ZWwiOiJyZWdpb25hbCIsIk1fQnJhbmNoQ29tcGFueUlEIjoiMSIsIk1fQnJhbmNoQ29tcGFueU5hbWUiOiJQVCBQUkFNSVRBIiwiaXAiOiIxMzkuMTkyLjE0OS4xODYiLCJhZ2VudCI6Ik1vemlsbGFcLzUuMCAoWDExOyBMaW51eCB4ODZfNjQ7IHJ2OjEzOS4wKSBHZWNrb1wvMjAxMDAxMDEgRmlyZWZveFwvMTM5LjAiLCJ2ZXJzaW9uIjoidjIiLCJsYXN0LWxvZ2luIjoiMjAyNS0wNy0wOCAxMDo0MjoyMCIsIk1fU2F0ZWxsaXRlSUQiOjB9.0_H99mFpJ4ij8tgaWGmR85T16r_55il3q7bY1RRJ_JQ"
|
||||
|
||||
@host = https://accone.aplikasi.web.id/one-api/mockup/purchase/transfer/TransferRequest
|
||||
|
||||
### get branches
|
||||
POST {{host}}/getBranches/
|
||||
|
||||
{
|
||||
"S_RegionalID": 8,
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
### get status
|
||||
GET {{ host }}/getStatus
|
||||
|
||||
{
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
### search
|
||||
POST {{ host }}/search
|
||||
|
||||
{
|
||||
"startDate": "2025-01-01",
|
||||
"endDate": "2025-02-28",
|
||||
"M_BranchCode": "BA",
|
||||
"StatusName": "",
|
||||
"current_page": 0,
|
||||
"search": "",
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
### getDraftDetail
|
||||
POST {{host}}/getDraftDetail
|
||||
|
||||
{
|
||||
"token" : {{token}},
|
||||
"goodTfID" : 30
|
||||
}
|
||||
|
||||
### delete
|
||||
POST {{ host }}/deleteTfRequest
|
||||
|
||||
{
|
||||
"GoodsTfID": 1,
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
### get details
|
||||
POST {{ host }}/getDetails
|
||||
|
||||
{
|
||||
"S_RegionalID": 8,
|
||||
"M_BranchCode": "BA",
|
||||
"token": {{token}}
|
||||
}
|
||||
|
||||
|
||||
### Get List Detail
|
||||
POST {{host}}/getListDetail
|
||||
|
||||
{
|
||||
"token": {{token}},
|
||||
"currpage":1,
|
||||
"regionalid":"6",
|
||||
"branchcodedestin":"LA",
|
||||
"branchIDorigin":"0"
|
||||
}
|
||||
|
||||
### Get Batch Listing
|
||||
POST {{host}}/getItemBatchListing
|
||||
|
||||
{
|
||||
"itemid":"1",
|
||||
"unitid":"33",
|
||||
"batchno":"",
|
||||
"token": {{token}},
|
||||
"regionalid":"6",
|
||||
"branchid":"0"
|
||||
}
|
||||
|
||||
### Unpack Stock
|
||||
POST {{host}}/unpackingStock
|
||||
|
||||
{
|
||||
"StockStockNumber" : "SN2507006",
|
||||
"StockBatchNo" : "B20250701002",
|
||||
"UnpackQty" : 2,
|
||||
"ToItemUnitID" : 2,
|
||||
"UnitConvertAmount" : 10,
|
||||
"token" : {{token}},
|
||||
"isDebug" : true
|
||||
}
|
||||
|
||||
### Create TF Request
|
||||
### 1 Item 1 Batch
|
||||
POST {{host}}/createTFRequest
|
||||
|
||||
{
|
||||
"token": {{token}},
|
||||
"S_RegionalID" : "6",
|
||||
"M_BranchCode" : "LA",
|
||||
"GoodsTfNotes" : "Req 5 BOTOL, TF 2 BOTOL",
|
||||
"GoodsTfDate" : "2025-07-03",
|
||||
"GoodsTfStatus" : "Draft",
|
||||
"detail": [
|
||||
{
|
||||
"PurchaseRequestDate": "2025-06-30",
|
||||
"PurchaseRequestNumber": "PR25060105",
|
||||
"PurchaseRequestDetailM_ItemID": "1",
|
||||
"PurchaseRequestDetailItemUnitID": "2",
|
||||
"M_ItemDesc": "ABBOTT CHOLESTEROL 2 - 1000 T (4S92.20 )",
|
||||
"RequestItemUnitID": "2",
|
||||
"RequestItemUnitName": "BOTOL",
|
||||
"PurchaseRequestFlagID": "22",
|
||||
"PurchaseRequestFlagQty": "5",
|
||||
"PurchaseRequestFlagQtyRest": 2,
|
||||
"PurchaseRequestFlagStatus": "TF,PO",
|
||||
"StockGudang": [
|
||||
{
|
||||
"StockItemUnitID": "33",
|
||||
"StockItemUnitName": "DUS",
|
||||
"StockQty": "11",
|
||||
"StockBatchNo": "B20250701002",
|
||||
"StockED": "2025-11-28",
|
||||
"StockStockNumber": "SN2507011",
|
||||
"StockItemPrice": "1761914"
|
||||
},
|
||||
{
|
||||
"StockItemUnitID": "2",
|
||||
"StockItemUnitName": "BOTOL",
|
||||
"StockQty": "10",
|
||||
"StockBatchNo": "B20250701002",
|
||||
"StockED": "2025-11-28",
|
||||
"StockStockNumber": "SN2507011",
|
||||
"StockItemPrice": "176191.4"
|
||||
},
|
||||
{
|
||||
"StockItemUnitID": "33",
|
||||
"StockItemUnitName": "DUS",
|
||||
"StockQty": "2",
|
||||
"StockBatchNo": "B001",
|
||||
"StockED": "2025-11-30",
|
||||
"StockStockNumber": "SN2506077",
|
||||
"StockItemPrice": "1761914"
|
||||
}
|
||||
],
|
||||
"MustUnpack": false,
|
||||
"UnpackData": {
|
||||
"CanUnpack": true,
|
||||
"Reason": "Direct unit match available - no conversion needed"
|
||||
},
|
||||
"ItemRequest": [
|
||||
{
|
||||
"WarehouseID": "9",
|
||||
"WarehouseName": "Gudang Regional 1",
|
||||
"StockID": "40",
|
||||
"StockStockNumber": "SN2507011",
|
||||
"StockItemID": "1",
|
||||
"StockItemUnitID": "2",
|
||||
"ItemUnitName": "BOTOL",
|
||||
"StockItemPrice": "176191.4",
|
||||
"StockBatchNo": "B20250701002",
|
||||
"StockED": "2025-11-28",
|
||||
"StockQty": "10",
|
||||
"QtyReq": "2"
|
||||
}
|
||||
],
|
||||
"QtyFilled": 2
|
||||
}
|
||||
],
|
||||
"isDebug": true
|
||||
}
|
||||
|
||||
|
||||
### Create TF Request
|
||||
### 2 Item each 1 Batch
|
||||
POST {{host}}/createTFRequest
|
||||
|
||||
{
|
||||
"token": {{token}},
|
||||
"S_RegionalID": "6",
|
||||
"M_BranchCode": "LA",
|
||||
"GoodsTfNotes": "",
|
||||
"GoodsTfDate": "2025-07-03",
|
||||
"GoodsTfStatus": "Draft",
|
||||
"detail": [
|
||||
{
|
||||
"PurchaseRequestDate": "2025-06-26",
|
||||
"PurchaseRequestNumber": "PR25060096",
|
||||
"PurchaseRequestDetailM_ItemID": "13",
|
||||
"PurchaseRequestDetailItemUnitID": "3",
|
||||
"M_ItemDesc": "VITEX 2 GN - 21341",
|
||||
"RequestItemUnitID": "3",
|
||||
"RequestItemUnitName": "BOX",
|
||||
"PurchaseRequestFlagID": "13",
|
||||
"PurchaseRequestFlagQty": "2",
|
||||
"PurchaseRequestFlagQtyRest": 2,
|
||||
"PurchaseRequestFlagStatus": "TF",
|
||||
"StockGudang": [
|
||||
{
|
||||
"StockItemUnitID": "3",
|
||||
"StockItemUnitName": "BOX",
|
||||
"StockQty": "6",
|
||||
"StockBatchNo": "B20250626005",
|
||||
"StockED": "2025-12-31",
|
||||
"StockStockNumber": "SN2506069",
|
||||
"StockItemPrice": "0"
|
||||
}
|
||||
],
|
||||
"MustUnpack": false,
|
||||
"UnpackData": {
|
||||
"CanUnpack": true,
|
||||
"Reason": "Direct unit match available - no conversion needed"
|
||||
},
|
||||
"ItemRequest": [
|
||||
{
|
||||
"WarehouseID": "9",
|
||||
"WarehouseName": "Gudang Regional 1",
|
||||
"StockID": "9",
|
||||
"StockStockNumber": "SN2506069",
|
||||
"StockItemID": "13",
|
||||
"StockItemUnitID": "3",
|
||||
"ItemUnitName": "BOX",
|
||||
"StockItemPrice": "0",
|
||||
"StockBatchNo": "B20250626005",
|
||||
"StockED": "2025-12-31",
|
||||
"StockQty": "6",
|
||||
"QtyReq": "2"
|
||||
}
|
||||
],
|
||||
"QtyFilled": 2
|
||||
},
|
||||
{
|
||||
"PurchaseRequestDate": "2025-06-30",
|
||||
"PurchaseRequestNumber": "PR25060105",
|
||||
"PurchaseRequestDetailM_ItemID": "1",
|
||||
"PurchaseRequestDetailItemUnitID": "2",
|
||||
"M_ItemDesc": "ABBOTT CHOLESTEROL 2 - 1000 T (4S92.20 )",
|
||||
"RequestItemUnitID": "2",
|
||||
"RequestItemUnitName": "BOTOL",
|
||||
"PurchaseRequestFlagID": "22",
|
||||
"PurchaseRequestFlagQty": "5",
|
||||
"PurchaseRequestFlagQtyRest": 4,
|
||||
"PurchaseRequestFlagStatus": "TF,PO",
|
||||
"StockGudang": [
|
||||
{
|
||||
"StockItemUnitID": "33",
|
||||
"StockItemUnitName": "DUS",
|
||||
"StockQty": "11",
|
||||
"StockBatchNo": "B20250701002",
|
||||
"StockED": "2025-11-28",
|
||||
"StockStockNumber": "SN2507011",
|
||||
"StockItemPrice": "1761914"
|
||||
},
|
||||
{
|
||||
"StockItemUnitID": "2",
|
||||
"StockItemUnitName": "BOTOL",
|
||||
"StockQty": "10",
|
||||
"StockBatchNo": "B20250701002",
|
||||
"StockED": "2025-11-28",
|
||||
"StockStockNumber": "SN2507011",
|
||||
"StockItemPrice": "176191.4"
|
||||
},
|
||||
{
|
||||
"StockItemUnitID": "33",
|
||||
"StockItemUnitName": "DUS",
|
||||
"StockQty": "2",
|
||||
"StockBatchNo": "B001",
|
||||
"StockED": "2025-11-30",
|
||||
"StockStockNumber": "SN2506077",
|
||||
"StockItemPrice": "1761914"
|
||||
}
|
||||
],
|
||||
"MustUnpack": false,
|
||||
"UnpackData": {
|
||||
"CanUnpack": true,
|
||||
"Reason": "Direct unit match available - no conversion needed"
|
||||
},
|
||||
"ItemRequest": [
|
||||
{
|
||||
"WarehouseID": "9",
|
||||
"WarehouseName": "Gudang Regional 1",
|
||||
"StockID": "40",
|
||||
"StockStockNumber": "SN2507011",
|
||||
"StockItemID": "1",
|
||||
"StockItemUnitID": "2",
|
||||
"ItemUnitName": "BOTOL",
|
||||
"StockItemPrice": "176191.4",
|
||||
"StockBatchNo": "B20250701002",
|
||||
"StockED": "2025-11-28",
|
||||
"StockQty": "10",
|
||||
"QtyReq": "4"
|
||||
}
|
||||
],
|
||||
"QtyFilled": 4
|
||||
}
|
||||
],
|
||||
"isDebug": true
|
||||
}
|
||||
|
||||
### Create TF Request
|
||||
POST {{host}}/createTFRequest
|
||||
|
||||
{
|
||||
"token": {{token}},
|
||||
"S_RegionalID": "6",
|
||||
"M_BranchCode": "LA",
|
||||
"GoodsTfNotes": "Tes ambil req",
|
||||
"GoodsTfDate": "2025-07-08",
|
||||
"GoodsTfStatus": "Verified",
|
||||
"detail": [
|
||||
{
|
||||
"PurchaseRequestDate": "2025-07-08",
|
||||
"PurchaseRequestNumber": "PR25070019",
|
||||
"PurchaseRequestDetailM_ItemID": "1",
|
||||
"PurchaseRequestDetailItemUnitID": "33",
|
||||
"M_ItemDesc": "ABBOTT CHOLESTEROL 2 - 1000 T (4S92.20 )",
|
||||
"RequestItemUnitID": "33",
|
||||
"RequestItemUnitName": "DUS",
|
||||
"PurchaseRequestFlagID": "61",
|
||||
"PurchaseRequestFlagQty": "2",
|
||||
"PurchaseRequestFlagQtyRest": 2,
|
||||
"PurchaseRequestFlagStatus": "TF",
|
||||
"StockGudang": [
|
||||
{
|
||||
"StockID": "23",
|
||||
"StockItemUnitID": "33",
|
||||
"StockItemUnitName": "DUS",
|
||||
"StockQty": "9",
|
||||
"StockBatchNo": "B20250701002",
|
||||
"StockED": "2025-11-28",
|
||||
"StockStockNumber": "SN2507006",
|
||||
"StockItemPrice": "1761914"
|
||||
},
|
||||
{
|
||||
"StockID": "47",
|
||||
"StockItemUnitID": "2",
|
||||
"StockItemUnitName": "BOTOL",
|
||||
"StockQty": "5",
|
||||
"StockBatchNo": "B20250701002",
|
||||
"StockED": "2025-11-28",
|
||||
"StockStockNumber": "SN2507018",
|
||||
"StockItemPrice": "176191.4"
|
||||
},
|
||||
{
|
||||
"StockID": "53",
|
||||
"StockItemUnitID": "2",
|
||||
"StockItemUnitName": "BOTOL",
|
||||
"StockQty": "10",
|
||||
"StockBatchNo": "B001",
|
||||
"StockED": "2025-11-30",
|
||||
"StockStockNumber": "SN2507024",
|
||||
"StockItemPrice": "176191.4"
|
||||
},
|
||||
{
|
||||
"StockID": "17",
|
||||
"StockItemUnitID": "33",
|
||||
"StockItemUnitName": "DUS",
|
||||
"StockQty": "1",
|
||||
"StockBatchNo": "B001",
|
||||
"StockED": "2025-11-30",
|
||||
"StockStockNumber": "SN2506077",
|
||||
"StockItemPrice": "1761914"
|
||||
}
|
||||
],
|
||||
"CanDirectUse": true,
|
||||
"CanUnpack": false,
|
||||
"UnpackData": {
|
||||
"M_ItemID": "1",
|
||||
"CanUnpack": false,
|
||||
"ReasonCannotUnpack": "Tidak ditemukan konversi dari unit stock yang tersedia ke unit request DUS"
|
||||
},
|
||||
"ItemRequest": [
|
||||
{
|
||||
"WarehouseID": "9",
|
||||
"WarehouseName": "Gudang Regional 1",
|
||||
"StockID": "23",
|
||||
"StockStockNumber": "SN2507006",
|
||||
"StockItemID": "1",
|
||||
"StockItemUnitID": "33",
|
||||
"ItemUnitName": "DUS",
|
||||
"StockItemPrice": "1761914",
|
||||
"StockBatchNo": "B20250701002",
|
||||
"StockED": "2025-11-28",
|
||||
"StockQty": "9",
|
||||
"QtyReq": "1"
|
||||
},
|
||||
{
|
||||
"WarehouseID": "9",
|
||||
"WarehouseName": "Gudang Regional 1",
|
||||
"StockID": "17",
|
||||
"StockStockNumber": "SN2506077",
|
||||
"StockItemID": "1",
|
||||
"StockItemUnitID": "33",
|
||||
"ItemUnitName": "DUS",
|
||||
"StockItemPrice": "1761914",
|
||||
"StockBatchNo": "B001",
|
||||
"StockED": "2025-11-30",
|
||||
"StockQty": "1",
|
||||
"QtyReq": "1"
|
||||
}
|
||||
],
|
||||
"QtyFilled": 2
|
||||
},
|
||||
{
|
||||
"PurchaseRequestDate": "2025-07-08",
|
||||
"PurchaseRequestNumber": "PR25070020",
|
||||
"PurchaseRequestDetailM_ItemID": "2",
|
||||
"PurchaseRequestDetailItemUnitID": "3",
|
||||
"M_ItemDesc": "STANDART F NS 1 Ag FIA - SD BIOSENSOR ( 10DEN10D )",
|
||||
"RequestItemUnitID": "3",
|
||||
"RequestItemUnitName": "BOX",
|
||||
"PurchaseRequestFlagID": "62",
|
||||
"PurchaseRequestFlagQty": "1",
|
||||
"PurchaseRequestFlagQtyRest": 1,
|
||||
"PurchaseRequestFlagStatus": "TF",
|
||||
"StockGudang": [
|
||||
{
|
||||
"StockID": "50",
|
||||
"StockItemUnitID": "29",
|
||||
"StockItemUnitName": "TES",
|
||||
"StockQty": "10",
|
||||
"StockBatchNo": "B20250704001",
|
||||
"StockED": "2025-12-31",
|
||||
"StockStockNumber": "SN2507021",
|
||||
"StockItemPrice": "17848.8"
|
||||
},
|
||||
{
|
||||
"StockID": "49",
|
||||
"StockItemUnitID": "3",
|
||||
"StockItemUnitName": "BOX",
|
||||
"StockQty": "2",
|
||||
"StockBatchNo": "B20250704001",
|
||||
"StockED": "2025-12-31",
|
||||
"StockStockNumber": "SN2507020",
|
||||
"StockItemPrice": "89244"
|
||||
}
|
||||
],
|
||||
"CanDirectUse": true,
|
||||
"CanUnpack": false,
|
||||
"UnpackData": {
|
||||
"M_ItemID": "2",
|
||||
"CanUnpack": false,
|
||||
"ReasonCannotUnpack": "Tidak ditemukan konversi dari unit stock yang tersedia ke unit request BOX"
|
||||
},
|
||||
"ItemRequest": [
|
||||
{
|
||||
"WarehouseID": "9",
|
||||
"WarehouseName": "Gudang Regional 1",
|
||||
"StockID": "49",
|
||||
"StockStockNumber": "SN2507020",
|
||||
"StockItemID": "2",
|
||||
"StockItemUnitID": "3",
|
||||
"ItemUnitName": "BOX",
|
||||
"StockItemPrice": "89244",
|
||||
"StockBatchNo": "B20250704001",
|
||||
"StockED": "2025-12-31",
|
||||
"StockQty": "2",
|
||||
"QtyReq": "1"
|
||||
}
|
||||
],
|
||||
"QtyFilled": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
### Update TF Request
|
||||
POST {{host}}/updateTfRequest
|
||||
|
||||
{
|
||||
"token": {{token}},
|
||||
"S_RegionalID": "6",
|
||||
"M_BranchCode": "LE",
|
||||
"GoodsTfID": "27",
|
||||
"GoodsTfNum": "TRB202507080008",
|
||||
"GoodsTfNotes": "Test Update lalu Verif",
|
||||
"GoodsTfDate": "2025-07-08",
|
||||
"GoodsTfStatus": "Verified",
|
||||
"detail": [
|
||||
{
|
||||
"PurchaseRequestDate": "2025-07-08",
|
||||
"PurchaseRequestNumber": "PR25070021",
|
||||
"PurchaseRequestDetailM_ItemID": "1",
|
||||
"PurchaseRequestDetailItemUnitID": "2",
|
||||
"M_ItemDesc": "ABBOTT CHOLESTEROL 2 - 1000 T (4S92.20 )",
|
||||
"ItemUnitName": "BOTOL",
|
||||
"StockGudang": "23",
|
||||
"PurchaseRequestFlagID": "63",
|
||||
"PurchaseRequestFlagQty": "15",
|
||||
"PurchaseRequestFlagQtyRest": "5",
|
||||
"PurchaseRequestFlagStatus": "TF",
|
||||
"ItemRequest": [
|
||||
{
|
||||
"WarehouseID": "9",
|
||||
"WarehouseName": "Gudang Regional 1",
|
||||
"StockID": "47",
|
||||
"StockStockNumber": "SN2507018",
|
||||
"StockItemID": "1",
|
||||
"StockItemUnitID": "2",
|
||||
"ItemUnitName": "BOTOL",
|
||||
"StockItemPrice": "176191.4",
|
||||
"StockBatchNo": "B20250701002",
|
||||
"StockED": "2025-11-28",
|
||||
"StockQty": "5",
|
||||
"QtyReq": "5"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"PurchaseRequestDate": "2025-07-08",
|
||||
"PurchaseRequestNumber": "PR25070022",
|
||||
"PurchaseRequestDetailM_ItemID": "2",
|
||||
"PurchaseRequestDetailItemUnitID": "29",
|
||||
"M_ItemDesc": "STANDART F NS 1 Ag FIA - SD BIOSENSOR ( 10DEN10D )",
|
||||
"ItemUnitName": "TES",
|
||||
"StockGudang": "11",
|
||||
"PurchaseRequestFlagID": "64",
|
||||
"PurchaseRequestFlagQty": "5",
|
||||
"PurchaseRequestFlagQtyRest": "5",
|
||||
"PurchaseRequestFlagStatus": "TF",
|
||||
"ItemRequest": [
|
||||
{
|
||||
"WarehouseID": "9",
|
||||
"WarehouseName": "Gudang Regional 1",
|
||||
"StockID": "50",
|
||||
"StockStockNumber": "SN2507021",
|
||||
"StockItemID": "2",
|
||||
"StockItemUnitID": "29",
|
||||
"ItemUnitName": "TES",
|
||||
"StockItemPrice": "17848.8",
|
||||
"StockBatchNo": "B20250704001",
|
||||
"StockED": "2025-12-31",
|
||||
"StockQty": "10",
|
||||
"QtyReq": "5"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
1740
application/controllers/mockup/purchase/transfer/TransferRequest.php
Normal file
1740
application/controllers/mockup/purchase/transfer/TransferRequest.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
@host = https://accone.aplikasi.web.id/one-api/mockup/purchase/transfer/TransferRequestNP/createTfRequest
|
||||
@token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjM4MCIsIk1fVXNlclVzZXJuYW1lIjoicmVnc2J5IiwiTV9Vc2VyR3JvdXBEYXNoYm9hcmQiOiJvbmUtdWlcL3Rlc3RcL3Z1ZXhcL2FjYy1vbmUtanVybmFsXC8iLCJNX1VzZXJEZWZhdWx0VF9TYW1wbGVTdGF0aW9uSUQiOiIwIiwiTV9TdGFmZk5hbWUiOiJTdGFmZiBSZWdpb25hbCIsImlzX2NvdXJpZXIiOiJOIiwidGltZV9hdXRvbG9nb3V0IjoiMTIwIiwiTV9Vc2VyTG9jYXRpb25JRCI6IjM3IiwiTV9Vc2VyTG9jYXRpb25GbGFnIjoiUiIsIlNfUmVnaW9uYWxOYW1lIjoiU3VyYWJheWEgUmF5YSIsIlNfUmVnaW9uYWxJRCI6IjYiLCJNX0JyYW5jaE5hbWUiOiIiLCJNX0JyYW5jaENvZGUiOiIiLCJNX0JyYW5jaElEIjoiMCIsImxvZ2luTGV2ZWwiOiJyZWdpb25hbCIsIk1fQnJhbmNoQ29tcGFueUlEIjoiMSIsIk1fQnJhbmNoQ29tcGFueU5hbWUiOiJQVCBQUkFNSVRBIiwiaXAiOiIxMzkuMTkyLjE0OS4xODYiLCJhZ2VudCI6Ik1vemlsbGFcLzUuMCAoWDExOyBMaW51eCB4ODZfNjQ7IHJ2OjEzOS4wKSBHZWNrb1wvMjAxMDAxMDEgRmlyZWZveFwvMTM5LjAiLCJ2ZXJzaW9uIjoidjIiLCJsYXN0LWxvZ2luIjoiMjAyNS0wNy0wOCAxMDo0MjoyMCIsIk1fU2F0ZWxsaXRlSUQiOjB9.0_H99mFpJ4ij8tgaWGmR85T16r_55il3q7bY1RRJ_JQ"
|
||||
|
||||
###
|
||||
POST {{host}}/createTfRequest
|
||||
|
||||
{"token": {{token}},"S_RegionalID":"6","M_BranchCode":"LA","DivisionID":"12","GoodsTfNotes":"Tes create langsung verif","GoodsTfDate":"2025-07-08","GoodsTfStatus":"Verified","detail":[{"PurchaseRequestDate":"2025-07-08","PurchaseRequestNumber":"PR25070024","PurchaseRequestDetailM_ItemID":"33","PurchaseRequestDetailItemUnitID":"19","M_ItemDesc":"MEJA KERJA","ItemUnitName":"PCS","PurchaseRequestFlagID":"67","PurchaseRequestFlagQty":"2","PurchaseRequestFlagQtyRest":2,"StockGudang":"10","PurchaseRequestFlagStatus":"TF","ItemRequest":[{"WarehouseID":"9","WarehouseName":"Gudang Regional 1","StockID":"13","StockStockNumber":"SN2506073","StockWarehouseID":"9","StockItemID":"33","StockItemUnitID":"19","StockItemPrice":"300000","ItemUnitName":"PCS","StockQty":"10","QtyReq":"2"}],"QtyFilled":2},{"PurchaseRequestDate":"2025-07-08","PurchaseRequestNumber":"PR25070025","PurchaseRequestDetailM_ItemID":"35","PurchaseRequestDetailItemUnitID":"19","M_ItemDesc":"MEJA KOMPUTER","ItemUnitName":"PCS","PurchaseRequestFlagID":"68","PurchaseRequestFlagQty":"2","PurchaseRequestFlagQtyRest":1,"StockGudang":"8","PurchaseRequestFlagStatus":"TF","ItemRequest":[{"WarehouseID":"9","WarehouseName":"Gudang Regional 1","StockID":"12","StockStockNumber":"SN2506072","StockWarehouseID":"9","StockItemID":"35","StockItemUnitID":"19","StockItemPrice":"450000","ItemUnitName":"PCS","StockQty":"8","QtyReq":"1"}],"QtyFilled":1}]}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
2430
application/controllers/mockup/receive-item-po/ReceiveItemPoV2.php
Normal file
2430
application/controllers/mockup/receive-item-po/ReceiveItemPoV2.php
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,10 @@
|
||||
@host = https://accone.aplikasi.web.id/one-api/mockup/receive-item-po/receiveitempo
|
||||
@token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjM4MiIsIk1fVXNlclVzZXJuYW1lIjoia2FjYWJhZGl0eWEiLCJNX1VzZXJHcm91cERhc2hib2FyZCI6Im9uZS11aVwvdGVzdFwvdnVleFwvYWNjb25lLXB1cmNoYXNlLXJlcXVlc3Qta2FjYWIiLCJNX1VzZXJEZWZhdWx0VF9TYW1wbGVTdGF0aW9uSUQiOiIwIiwiTV9TdGFmZk5hbWUiOiJLYWNhYiBBZGl0eWEiLCJpc19jb3VyaWVyIjoiTiIsInRpbWVfYXV0b2xvZ291dCI6IjEyMCIsIk1fVXNlckxvY2F0aW9uSUQiOiIzOSIsIk1fVXNlckxvY2F0aW9uRmxhZyI6IkIiLCJTX1JlZ2lvbmFsTmFtZSI6IlN1cmFiYXlhIFJheWEiLCJTX1JlZ2lvbmFsSUQiOiI2IiwiTV9CcmFuY2hOYW1lIjoiUHJhbWl0YSBBZGl0eWF3YXJtYW4iLCJNX0JyYW5jaENvZGUiOiJMQSIsIk1fQnJhbmNoSUQiOiIxNCIsImxvZ2luTGV2ZWwiOiJicmFuY2giLCJNX0JyYW5jaENvbXBhbnlJRCI6IjEiLCJNX0JyYW5jaENvbXBhbnlOYW1lIjoiUFQgUFJBTUlUQSIsImlwIjoiMTM5LjAuOTcuMTA4IiwiYWdlbnQiOiJNb3ppbGxhXC81LjAgKFgxMTsgTGludXggeDg2XzY0OyBydjoxMzkuMCkgR2Vja29cLzIwMTAwMTAxIEZpcmVmb3hcLzEzOS4wIiwidmVyc2lvbiI6InYyIiwibGFzdC1sb2dpbiI6IjIwMjUtMDctMDEgMTQ6MjQ6MzciLCJNX1NhdGVsbGl0ZUlEIjowfQ.NCSVDCZiAFZJIB8KkekX-Jw9ANZD5cpH7xfec7q7jrg"
|
||||
|
||||
### get Item PO yang mau di RO
|
||||
POST {{host}}/getItem
|
||||
|
||||
{
|
||||
"token": {{token}},
|
||||
"POID":"16"
|
||||
}
|
||||
3354
application/controllers/mockup/receive-item-po/Receiveitempo.php
Normal file
3354
application/controllers/mockup/receive-item-po/Receiveitempo.php
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
133
application/core/MY_Controller-bkp-autologout.php
Normal file
133
application/core/MY_Controller-bkp-autologout.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
class MY_Controller extends CI_Controller {
|
||||
var $db_onedev;
|
||||
var $sys_user;
|
||||
var $sys_input;
|
||||
var $isLogin;
|
||||
var $one_salt = '545';
|
||||
var $SECRET_KEY = "--one_api-secret-2019-04-01";
|
||||
|
||||
var $group_lab = "1";
|
||||
var $lang_default_code = "ID";
|
||||
|
||||
public function broadcast($prm){
|
||||
file_get_contents('http://127.0.0.1:9090/broadcast/' . $prm);
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
//for preflight
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
|
||||
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
|
||||
//for disable cached
|
||||
header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
|
||||
header('Pragma: no-cache');
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
global $_SERVER;
|
||||
if ( isset($_SERVER["REQUEST_METHOD"]) && $_SERVER["REQUEST_METHOD"] == "OPTIONS") {
|
||||
exit;
|
||||
}
|
||||
$this->sys_user = array(
|
||||
"isExists" => false,
|
||||
"user" => array(
|
||||
"userName" => "",
|
||||
"userLogin" => "",
|
||||
"userID" => 0
|
||||
)
|
||||
);
|
||||
error_reporting(0);
|
||||
$this->sys_input = json_decode($this->input->raw_input_stream,true);
|
||||
if (! $this->sys_input ) {
|
||||
if ( count($this->input->post()) > 0 ) {
|
||||
$this->sys_input = $this->input->post();
|
||||
} else {
|
||||
$this->sys_input = $this->input->get();
|
||||
}
|
||||
}
|
||||
$this->load->library("Jwt");
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (! isset($prm["token"])) {
|
||||
$this->isLogin = false;
|
||||
} else {
|
||||
$user = JWT::decode($prm["token"],$this->SECRET_KEY,true);
|
||||
unset($this->sys_input["token"]);
|
||||
$user = json_decode(json_encode($user),true);
|
||||
if ($user["M_UserID"] > 0 ) {
|
||||
$this->isLogin = true;
|
||||
}
|
||||
$this->sys_user = $user;
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
$query = $this->db_onedev->query("update m_user SET M_UserLastAccess = now() WHERE M_UserID = ?",array($user["M_UserID"]));
|
||||
if (!$query) {
|
||||
$message = $this->db_onedev->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
//update last accessed
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
$this->isLogin = false;
|
||||
}
|
||||
$this->load->database();
|
||||
|
||||
}
|
||||
public function sys_debug() {
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
}
|
||||
public function sys_error_db($message,$db = false) {
|
||||
if (! $db ) {
|
||||
echo json_encode(
|
||||
array(
|
||||
"status" => "ERR",
|
||||
"message" => $message,
|
||||
"query" => $this->db->last_query(),
|
||||
"db_error" => $this->db->error()
|
||||
)
|
||||
);
|
||||
} else {
|
||||
echo json_encode(
|
||||
array(
|
||||
"status" => "ERR",
|
||||
"message" => $message,
|
||||
"query" => $db->last_query(),
|
||||
"db_error" => $db->error()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
public function sys_error($message) {
|
||||
echo json_encode(
|
||||
array(
|
||||
"status" => "ERR",
|
||||
"message" => $message
|
||||
)
|
||||
);
|
||||
}
|
||||
public function sys_ok($data) {
|
||||
echo json_encode(
|
||||
array(
|
||||
"status" => "OK",
|
||||
"data" => $data
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function clean_mysqli_connection( $dbc )
|
||||
{
|
||||
while( mysqli_more_results($dbc) )
|
||||
{
|
||||
if(mysqli_next_result($dbc))
|
||||
{
|
||||
$result = mysqli_use_result($dbc);
|
||||
|
||||
unset($result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
141
application/core/MY_Controller.php
Normal file
141
application/core/MY_Controller.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
class MY_Controller extends CI_Controller {
|
||||
var $db_onedev;
|
||||
var $db_inventory;
|
||||
var $db_inventory_log;
|
||||
var $db_bloodbank;
|
||||
var $db_onex;
|
||||
var $sys_user;
|
||||
var $sys_input;
|
||||
var $isLogin;
|
||||
var $one_salt = '545';
|
||||
var $SECRET_KEY = "--one_api-secret-2019-04-01";
|
||||
|
||||
var $group_lab = "1";
|
||||
var $lang_default_code = "ID";
|
||||
|
||||
public function broadcast($prm){
|
||||
file_get_contents('http://127.0.0.1:9090/broadcast/' . $prm);
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
//for preflight
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
|
||||
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
|
||||
//for disable cached
|
||||
header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
|
||||
header('Pragma: no-cache');
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
global $_SERVER;
|
||||
if ( isset($_SERVER["REQUEST_METHOD"]) && $_SERVER["REQUEST_METHOD"] == "OPTIONS") {
|
||||
exit;
|
||||
}
|
||||
$this->sys_user = array(
|
||||
"isExists" => false,
|
||||
"user" => array(
|
||||
"userName" => "",
|
||||
"userLogin" => "",
|
||||
"userID" => 0
|
||||
)
|
||||
);
|
||||
error_reporting(0);
|
||||
$this->sys_input = json_decode($this->input->raw_input_stream,true);
|
||||
if (! $this->sys_input ) {
|
||||
if ( count($this->input->post()) > 0 ) {
|
||||
$this->sys_input = $this->input->post();
|
||||
} else {
|
||||
$this->sys_input = $this->input->get();
|
||||
}
|
||||
}
|
||||
$this->load->library("Jwt");
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (! isset($prm["token"])) {
|
||||
$this->isLogin = false;
|
||||
} else {
|
||||
$user = JWT::decode($prm["token"],$this->SECRET_KEY,true);
|
||||
unset($this->sys_input["token"]);
|
||||
$user = json_decode(json_encode($user),true);
|
||||
if ($user["M_UserID"] > 0 ) {
|
||||
$this->isLogin = true;
|
||||
}
|
||||
$this->sys_user = $user;
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
$this->db_inventory = $this->load->database("inventory", true);
|
||||
$this->db_inventory_log = $this->load->database("inventory_log", true);
|
||||
$this->db_bloodbank = $this->load->database("bloodbank", true);
|
||||
$this->db_onex = "one_aditya";
|
||||
$query = $this->db_onedev->query("update m_user SET M_UserLastAccess = now() WHERE M_UserID = ?",array($user["M_UserID"]));
|
||||
if (!$query) {
|
||||
$message = $this->db_onedev->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
//update last accessed
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
$this->isLogin = false;
|
||||
}
|
||||
$this->load->database();
|
||||
|
||||
}
|
||||
public function sys_debug() {
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
}
|
||||
public function sys_error_db($message,$db = false) {
|
||||
if (! $db ) {
|
||||
echo json_encode(
|
||||
array(
|
||||
"status" => "ERR",
|
||||
"message" => $message,
|
||||
"query" => $this->db->last_query(),
|
||||
"db_error" => $this->db->error()
|
||||
)
|
||||
);
|
||||
} else {
|
||||
echo json_encode(
|
||||
array(
|
||||
"status" => "ERR",
|
||||
"message" => $message,
|
||||
"query" => $db->last_query(),
|
||||
"db_error" => $db->error()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
public function sys_error($message) {
|
||||
echo json_encode(
|
||||
array(
|
||||
"status" => "ERR",
|
||||
"message" => $message
|
||||
)
|
||||
);
|
||||
}
|
||||
public function sys_ok($data) {
|
||||
echo json_encode(
|
||||
array(
|
||||
"status" => "OK",
|
||||
"data" => $data
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function clean_mysqli_connection( $dbc )
|
||||
{
|
||||
while( mysqli_more_results($dbc) )
|
||||
{
|
||||
if(mysqli_next_result($dbc))
|
||||
{
|
||||
$result = mysqli_use_result($dbc);
|
||||
|
||||
unset($result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
11
application/core/index.html
Normal file
11
application/core/index.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
11
application/helpers/index.html
Normal file
11
application/helpers/index.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
11
application/hooks/index.html
Normal file
11
application/hooks/index.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
11
application/index.html
Normal file
11
application/index.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
11
application/language/english/index.html
Normal file
11
application/language/english/index.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
11
application/language/index.html
Normal file
11
application/language/index.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
230
application/libraries/Autosamplingverif.php
Normal file
230
application/libraries/Autosamplingverif.php
Normal 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
14
application/libraries/Excel.php
Normal file
14
application/libraries/Excel.php
Normal 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();
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
279
application/libraries/ImageManipulator.php
Normal file
279
application/libraries/ImageManipulator.php
Normal file
@@ -0,0 +1,279 @@
|
||||
<?php
|
||||
class ImageManipulator
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* @var resource
|
||||
*/
|
||||
protected $image;
|
||||
|
||||
/**
|
||||
* Image manipulator constructor
|
||||
*
|
||||
* @param string $file OPTIONAL Path to image file or image data as string
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($file = null)
|
||||
{
|
||||
if (null !== $file) {
|
||||
if (is_file($file)) {
|
||||
$this->setImageFile($file);
|
||||
} else {
|
||||
$this->setImageString($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set image resource from file
|
||||
*
|
||||
* @param string $file Path to image file
|
||||
* @return ImageManipulator for a fluent interface
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function setImageFile($file)
|
||||
{
|
||||
if (!(is_readable($file) && is_file($file))) {
|
||||
throw new InvalidArgumentException("Image file $file is not readable");
|
||||
}
|
||||
|
||||
if (is_resource($this->image)) {
|
||||
imagedestroy($this->image);
|
||||
}
|
||||
|
||||
list ($this->width, $this->height, $type) = getimagesize($file);
|
||||
|
||||
switch ($type) {
|
||||
case IMAGETYPE_GIF :
|
||||
$this->image = imagecreatefromgif($file);
|
||||
break;
|
||||
case IMAGETYPE_JPEG :
|
||||
$this->image = imagecreatefromjpeg($file);
|
||||
break;
|
||||
case IMAGETYPE_PNG :
|
||||
$this->image = imagecreatefrompng($file);
|
||||
break;
|
||||
default :
|
||||
throw new InvalidArgumentException("Image type $type not supported");
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set image resource from string data
|
||||
*
|
||||
* @param string $data
|
||||
* @return ImageManipulator for a fluent interface
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function setImageString($data)
|
||||
{
|
||||
if (is_resource($this->image)) {
|
||||
imagedestroy($this->image);
|
||||
}
|
||||
|
||||
if (!$this->image = imagecreatefromstring($data)) {
|
||||
throw new RuntimeException('Cannot create image from data string');
|
||||
}
|
||||
$this->width = imagesx($this->image);
|
||||
$this->height = imagesy($this->image);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resamples the current image
|
||||
*
|
||||
* @param int $width New width
|
||||
* @param int $height New height
|
||||
* @param bool $constrainProportions Constrain current image proportions when resizing
|
||||
* @return ImageManipulator for a fluent interface
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function resample($width, $height, $constrainProportions = true)
|
||||
{
|
||||
if (!is_resource($this->image)) {
|
||||
throw new RuntimeException('No image set');
|
||||
}
|
||||
if ($constrainProportions) {
|
||||
if ($this->height >= $this->width) {
|
||||
$width = round($height / $this->height * $this->width);
|
||||
} else {
|
||||
$height = round($width / $this->width * $this->height);
|
||||
}
|
||||
}
|
||||
$temp = imagecreatetruecolor($width, $height);
|
||||
imagecopyresampled($temp, $this->image, 0, 0, 0, 0, $width, $height, $this->width, $this->height);
|
||||
return $this->_replace($temp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enlarge canvas
|
||||
*
|
||||
* @param int $width Canvas width
|
||||
* @param int $height Canvas height
|
||||
* @param array $rgb RGB colour values
|
||||
* @param int $xpos X-Position of image in new canvas, null for centre
|
||||
* @param int $ypos Y-Position of image in new canvas, null for centre
|
||||
* @return ImageManipulator for a fluent interface
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function enlargeCanvas($width, $height, array $rgb = array(), $xpos = null, $ypos = null)
|
||||
{
|
||||
if (!is_resource($this->image)) {
|
||||
throw new RuntimeException('No image set');
|
||||
}
|
||||
|
||||
$width = max($width, $this->width);
|
||||
$height = max($height, $this->height);
|
||||
|
||||
$temp = imagecreatetruecolor($width, $height);
|
||||
if (count($rgb) == 3) {
|
||||
$bg = imagecolorallocate($temp, $rgb[0], $rgb[1], $rgb[2]);
|
||||
imagefill($temp, 0, 0, $bg);
|
||||
}
|
||||
|
||||
if (null === $xpos) {
|
||||
$xpos = round(($width - $this->width) / 2);
|
||||
}
|
||||
if (null === $ypos) {
|
||||
$ypos = round(($height - $this->height) / 2);
|
||||
}
|
||||
|
||||
imagecopy($temp, $this->image, (int) $xpos, (int) $ypos, 0, 0, $this->width, $this->height);
|
||||
return $this->_replace($temp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Crop image
|
||||
*
|
||||
* @param int|array $x1 Top left x-coordinate of crop box or array of coordinates
|
||||
* @param int $y1 Top left y-coordinate of crop box
|
||||
* @param int $x2 Bottom right x-coordinate of crop box
|
||||
* @param int $y2 Bottom right y-coordinate of crop box
|
||||
* @return ImageManipulator for a fluent interface
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function crop($x1, $y1 = 0, $x2 = 0, $y2 = 0)
|
||||
{
|
||||
if (!is_resource($this->image)) {
|
||||
throw new RuntimeException('No image set');
|
||||
}
|
||||
if (is_array($x1) && 4 == count($x1)) {
|
||||
list($x1, $y1, $x2, $y2) = $x1;
|
||||
}
|
||||
|
||||
$x1 = max($x1, 0);
|
||||
$y1 = max($y1, 0);
|
||||
|
||||
$x2 = min($x2, $this->width);
|
||||
$y2 = min($y2, $this->height);
|
||||
|
||||
$width = $x2 - $x1;
|
||||
$height = $y2 - $y1;
|
||||
|
||||
$temp = imagecreatetruecolor($width, $height);
|
||||
imagecopy($temp, $this->image, 0, 0, $x1, $y1, $width, $height);
|
||||
|
||||
return $this->_replace($temp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace current image resource with a new one
|
||||
*
|
||||
* @param resource $res New image resource
|
||||
* @return ImageManipulator for a fluent interface
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
protected function _replace($res)
|
||||
{
|
||||
if (!is_resource($res)) {
|
||||
throw new UnexpectedValueException('Invalid resource');
|
||||
}
|
||||
if (is_resource($this->image)) {
|
||||
imagedestroy($this->image);
|
||||
}
|
||||
$this->image = $res;
|
||||
$this->width = imagesx($res);
|
||||
$this->height = imagesy($res);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save current image to file
|
||||
*
|
||||
* @param string $fileName
|
||||
* @return void
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function save($fileName, $type = IMAGETYPE_JPEG)
|
||||
{
|
||||
$dir = dirname($fileName);
|
||||
if (!is_dir($dir)) {
|
||||
if (!mkdir($dir, 0755, true)) {
|
||||
throw new RuntimeException('Error creating directory ' . $dir);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
switch ($type) {
|
||||
case IMAGETYPE_GIF :
|
||||
if (!imagegif($this->image, $fileName)) {
|
||||
throw new RuntimeException;
|
||||
}
|
||||
break;
|
||||
case IMAGETYPE_PNG :
|
||||
if (!imagepng($this->image, $fileName)) {
|
||||
throw new RuntimeException;
|
||||
}
|
||||
break;
|
||||
case IMAGETYPE_JPEG :
|
||||
default :
|
||||
if (!imagejpeg($this->image, $fileName, 95)) {
|
||||
throw new RuntimeException;
|
||||
}
|
||||
}
|
||||
} catch (Exception $ex) {
|
||||
throw new RuntimeException('Error saving image file to ' . $fileName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the GD image resource
|
||||
*
|
||||
* @return resource
|
||||
*/
|
||||
public function getResource()
|
||||
{
|
||||
return $this->image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current image resource width
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getWidth()
|
||||
{
|
||||
return $this->width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current image height
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getHeight()
|
||||
{
|
||||
return $this->height;
|
||||
}
|
||||
}
|
||||
196
application/libraries/Jwt.php
Normal file
196
application/libraries/Jwt.php
Normal file
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* JSON Web Token implementation, based on this spec:
|
||||
* http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-06
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Authentication
|
||||
* @package Authentication_JWT
|
||||
* @author Neuman Vong <neuman@twilio.com>
|
||||
* @author Anant Narayanan <anant@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause 3-clause BSD
|
||||
* @link https://github.com/firebase/php-jwt
|
||||
*/
|
||||
class JWT
|
||||
{
|
||||
/**
|
||||
* Decodes a JWT string into a PHP object.
|
||||
*
|
||||
* @param string $jwt The JWT
|
||||
* @param string|null $key The secret key
|
||||
* @param bool $verify Don't skip verification process
|
||||
*
|
||||
* @return object The JWT's payload as a PHP object
|
||||
* @throws UnexpectedValueException Provided JWT was invalid
|
||||
* @throws DomainException Algorithm was not provided
|
||||
*
|
||||
* @uses jsonDecode
|
||||
* @uses urlsafeB64Decode
|
||||
*/
|
||||
public static function decode($jwt, $key = null, $verify = true)
|
||||
{
|
||||
$tks = explode('.', $jwt);
|
||||
if (count($tks) != 3) {
|
||||
throw new UnexpectedValueException('Wrong number of segments');
|
||||
}
|
||||
list($headb64, $bodyb64, $cryptob64) = $tks;
|
||||
if (null === ($header = JWT::jsonDecode(JWT::urlsafeB64Decode($headb64)))) {
|
||||
throw new UnexpectedValueException('Invalid segment encoding');
|
||||
}
|
||||
if (null === $payload = JWT::jsonDecode(JWT::urlsafeB64Decode($bodyb64))) {
|
||||
throw new UnexpectedValueException('Invalid segment encoding');
|
||||
}
|
||||
$sig = JWT::urlsafeB64Decode($cryptob64);
|
||||
if ($verify) {
|
||||
if (empty($header->alg)) {
|
||||
throw new DomainException('Empty algorithm');
|
||||
}
|
||||
if ($sig != JWT::sign("$headb64.$bodyb64", $key, $header->alg)) {
|
||||
throw new UnexpectedValueException('Signature verification failed');
|
||||
}
|
||||
}
|
||||
return $payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts and signs a PHP object or array into a JWT string.
|
||||
*
|
||||
* @param object|array $payload PHP object or array
|
||||
* @param string $key The secret key
|
||||
* @param string $algo The signing algorithm. Supported
|
||||
* algorithms are 'HS256', 'HS384' and 'HS512'
|
||||
*
|
||||
* @return string A signed JWT
|
||||
* @uses jsonEncode
|
||||
* @uses urlsafeB64Encode
|
||||
*/
|
||||
public static function encode($payload, $key, $algo = 'HS256')
|
||||
{
|
||||
$header = array('typ' => 'JWT', 'alg' => $algo);
|
||||
|
||||
$segments = array();
|
||||
$segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($header));
|
||||
$segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($payload));
|
||||
$signing_input = implode('.', $segments);
|
||||
|
||||
$signature = JWT::sign($signing_input, $key, $algo);
|
||||
$segments[] = JWT::urlsafeB64Encode($signature);
|
||||
|
||||
return implode('.', $segments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign a string with a given key and algorithm.
|
||||
*
|
||||
* @param string $msg The message to sign
|
||||
* @param string $key The secret key
|
||||
* @param string $method The signing algorithm. Supported
|
||||
* algorithms are 'HS256', 'HS384' and 'HS512'
|
||||
*
|
||||
* @return string An encrypted message
|
||||
* @throws DomainException Unsupported algorithm was specified
|
||||
*/
|
||||
public static function sign($msg, $key, $method = 'HS256')
|
||||
{
|
||||
$methods = array(
|
||||
'HS256' => 'sha256',
|
||||
'HS384' => 'sha384',
|
||||
'HS512' => 'sha512',
|
||||
);
|
||||
if (empty($methods[$method])) {
|
||||
throw new DomainException('Algorithm not supported');
|
||||
}
|
||||
return hash_hmac($methods[$method], $msg, $key, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode a JSON string into a PHP object.
|
||||
*
|
||||
* @param string $input JSON string
|
||||
*
|
||||
* @return object Object representation of JSON string
|
||||
* @throws DomainException Provided string was invalid JSON
|
||||
*/
|
||||
public static function jsonDecode($input)
|
||||
{
|
||||
$obj = json_decode($input);
|
||||
if (function_exists('json_last_error') && $errno = json_last_error()) {
|
||||
JWT::_handleJsonError($errno);
|
||||
} else if ($obj === null && $input !== 'null') {
|
||||
throw new DomainException('Null result with non-null input');
|
||||
}
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode a PHP object into a JSON string.
|
||||
*
|
||||
* @param object|array $input A PHP object or array
|
||||
*
|
||||
* @return string JSON representation of the PHP object or array
|
||||
* @throws DomainException Provided object could not be encoded to valid JSON
|
||||
*/
|
||||
public static function jsonEncode($input)
|
||||
{
|
||||
$json = json_encode($input);
|
||||
if (function_exists('json_last_error') && $errno = json_last_error()) {
|
||||
JWT::_handleJsonError($errno);
|
||||
} else if ($json === 'null' && $input !== null) {
|
||||
throw new DomainException('Null result with non-null input');
|
||||
}
|
||||
return $json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode a string with URL-safe Base64.
|
||||
*
|
||||
* @param string $input A Base64 encoded string
|
||||
*
|
||||
* @return string A decoded string
|
||||
*/
|
||||
public static function urlsafeB64Decode($input)
|
||||
{
|
||||
$remainder = strlen($input) % 4;
|
||||
if ($remainder) {
|
||||
$padlen = 4 - $remainder;
|
||||
$input .= str_repeat('=', $padlen);
|
||||
}
|
||||
return base64_decode(strtr($input, '-_', '+/'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode a string with URL-safe Base64.
|
||||
*
|
||||
* @param string $input The string you want encoded
|
||||
*
|
||||
* @return string The base64 encode of what you passed in
|
||||
*/
|
||||
public static function urlsafeB64Encode($input)
|
||||
{
|
||||
return str_replace('=', '', strtr(base64_encode($input), '+/', '-_'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to create a JSON error.
|
||||
*
|
||||
* @param int $errno An error number from json_last_error()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function _handleJsonError($errno)
|
||||
{
|
||||
$messages = array(
|
||||
JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
|
||||
JSON_ERROR_CTRL_CHAR => 'Unexpected control character found',
|
||||
JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON'
|
||||
);
|
||||
throw new DomainException(
|
||||
isset($messages[$errno])
|
||||
? $messages[$errno]
|
||||
: 'Unknown JSON error: ' . $errno
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
162
application/libraries/Kapus.php
Normal file
162
application/libraries/Kapus.php
Normal 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" => "");
|
||||
}
|
||||
|
||||
}
|
||||
14
application/libraries/Mcu.php
Normal file
14
application/libraries/Mcu.php
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
2020
application/libraries/Mongo_db.php
Normal file
2020
application/libraries/Mongo_db.php
Normal file
File diff suppressed because it is too large
Load Diff
184
application/libraries/NatPatientLib.php
Normal file
184
application/libraries/NatPatientLib.php
Normal 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;
|
||||
}
|
||||
}
|
||||
113
application/libraries/Resultcalc-bkp.php
Normal file
113
application/libraries/Resultcalc-bkp.php
Normal 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,".",",");
|
||||
}
|
||||
}
|
||||
107
application/libraries/Resultcalc-new.php
Normal file
107
application/libraries/Resultcalc-new.php
Normal 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,".",",");
|
||||
}
|
||||
}
|
||||
110
application/libraries/Resultcalc-riau.php
Normal file
110
application/libraries/Resultcalc-riau.php
Normal 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,".",",");
|
||||
}
|
||||
}
|
||||
175
application/libraries/Resultcalc.php
Normal file
175
application/libraries/Resultcalc.php
Normal 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, ".", ",");
|
||||
}
|
||||
}
|
||||
116
application/libraries/Resultcalcv2.php
Normal file
116
application/libraries/Resultcalcv2.php
Normal 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,".",",");
|
||||
}
|
||||
}
|
||||
49
application/libraries/Sas_s3.php
Normal file
49
application/libraries/Sas_s3.php
Normal 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;
|
||||
}
|
||||
}
|
||||
584
application/libraries/Satu_sehat.php
Normal file
584
application/libraries/Satu_sehat.php
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
244
application/libraries/Satusehat.php
Normal file
244
application/libraries/Satusehat.php
Normal 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
547
application/libraries/SsPriceMou.php
Normal file
547
application/libraries/SsPriceMou.php
Normal file
@@ -0,0 +1,547 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
class SsPriceMou{
|
||||
|
||||
// retrun array status, message
|
||||
public function create($mouID) {
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("onedev",true);
|
||||
|
||||
$sql = "select * from m_mou where M_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "MOU ID : $mouID not found");
|
||||
}
|
||||
$companyID = $rows[0]["M_MouM_CompanyID"];
|
||||
|
||||
$sql = "select distinct T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y'
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID <> 5
|
||||
where T_PriceM_MouID = ?
|
||||
and length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional select t_price " . print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$flag_error = false;
|
||||
foreach($rows as $idx => $r) {
|
||||
$nat_testType = $r["Nat_TestNat_TestTypeID"];
|
||||
switch($nat_testType) {
|
||||
case 1: //Single
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
case 3: //Multi
|
||||
case 4: //Panel
|
||||
$sasCode = $r["T_TestSasCode"] . '%';
|
||||
$sql = "select T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestIsResult = 'Y'
|
||||
and T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array($r["Nat_TestID"]);
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = $nr["T_TestNat_TestID"];
|
||||
}
|
||||
$rows[$idx]['nat_test'] = "[" . join(",",$t_rows) . "]";
|
||||
break;
|
||||
default :
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
}
|
||||
unset($rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
//Test Profile
|
||||
// wip profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, 0 T_PriceAmount, 0 T_PriceDisc, 0 T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, 0 T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PXR' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_test
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID = 5
|
||||
where length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$p_rows = $qry->result_array();
|
||||
|
||||
$sql = "select distinct substr(T_TestSasCode,1,8) parentCode, T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode,T_TestIsResult, T_TestCode
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y'
|
||||
and T_PriceIsCito = 'N'
|
||||
and length(T_TestSasCode) = 10
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
where T_PriceM_MouID = ? ";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional child test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_child = array();
|
||||
$p_codes = "'0'";
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
if ( ! isset($arr_child[$pCode])) {
|
||||
$arr_child[$pCode] = array();
|
||||
}
|
||||
$cCode = $r["T_TestSasCode"];
|
||||
$p_codes .= ", '$cCode'";
|
||||
unset($r["parentCode"]);
|
||||
$arr_child[$pCode][] = $r;
|
||||
}
|
||||
$sql = "select substr(T_TestSasCode,1,8) parentCode,
|
||||
group_concat(distinct T_TestNat_TestID) nat
|
||||
from t_test
|
||||
where ( T_TestIsResult = 'Y' or T_TestIsPrice = 'Y' )
|
||||
and T_TestSasCode in ( $p_codes )
|
||||
and T_TestIsActive = 'Y'
|
||||
group by parentCode";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_nat = array();
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
//if ( ! isset($arr_nat[$pCode])) {
|
||||
// $arr_nat[$pCode] = array();
|
||||
//}
|
||||
$arr_nat[$pCode] = $r["nat"];
|
||||
}
|
||||
$flag_error = false;
|
||||
foreach($p_rows as $idx => $r) {
|
||||
$T_TestName= $r["T_TestName"] ;
|
||||
$sasCode = $r["T_TestSasCode"];
|
||||
if ( isset($arr_child[$sasCode]) ) {
|
||||
$the_childs = $arr_child[$sasCode];
|
||||
$p_rows[$idx]['child_test'] = json_encode($the_childs,true);
|
||||
if ( isset($arr_nat[$sasCode] )) {
|
||||
$p_rows[$idx]['nat_test'] = "[" . $arr_nat[$sasCode] . "]";
|
||||
}
|
||||
unset($p_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($p_rows[$idx]["T_TestSasCode"]);
|
||||
} else {
|
||||
unset($p_rows[$idx]);
|
||||
}
|
||||
}
|
||||
//Paket Panel / Profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_PacketID T_TestID, T_PacketName T_TestName, 'N' IsFromPanel, 0 Nat_TestID,
|
||||
T_PacketID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, T_PacketOriginalBruto T_PriceAmount, 0 T_PriceDisc,
|
||||
(T_PacketOriginalBruto - T_PacketPrice) T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketPrice T_PriceTotal, 'Y' T_TestForceSell, 'Y' is_packet, T_PacketID packet_id,
|
||||
T_PacketType px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
$mouID Ss_PriceMouM_MouID
|
||||
from
|
||||
t_packet
|
||||
where
|
||||
T_PacketIsActive = 'Y'
|
||||
and T_PacketM_MouID = ?";
|
||||
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$pn_rows = $qry->result_array();
|
||||
foreach($pn_rows as $idx => $pnr) {
|
||||
$packetID = $pnr["packet_id"];
|
||||
//child test
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID,
|
||||
$mouID T_PriceM_MouID, 0 T_PricePriority, T_PacketDetailPriceAmount T_PriceAmount,
|
||||
T_PacketDetailPriceDisc T_PriceDisc, T_PacketDetailPriceDiscRp T_PriceDiscRp, T_PacketDetailPriceSubTotal T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketDetailPrice T_PriceTotal,
|
||||
'Y' T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite, T_TestSasCode
|
||||
from t_packetdetail
|
||||
join t_test on T_PacketDetailT_TestID = T_TestID
|
||||
and T_PacketDetailIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_PacketDetailT_PacketID = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($packetID));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$ct_rows = $qry->result_array();
|
||||
$p_nat_test = array();
|
||||
foreach($ct_rows as $ct_idx => $cr) {
|
||||
$sasCode = $cr["T_TestSasCode"] . '%';
|
||||
$sql = "select distinct T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array();
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = intval( $nr["T_TestNat_TestID"]);
|
||||
$p_nat_test[]= intval( $nr["T_TestNat_TestID"]);
|
||||
}
|
||||
$ct_rows[$ct_idx]['nat_test'] = json_encode($t_rows,JSON_NUMERIC_CHECK);
|
||||
}
|
||||
if (count($ct_rows) > 0 ) {
|
||||
$x_arr = array();
|
||||
foreach($ct_rows as $x_cr) {
|
||||
$x_arr[] = $x_cr;
|
||||
}
|
||||
$pn_rows[$idx]['child_test'] = json_encode($x_arr,true);
|
||||
$pn_rows[$idx]['nat_test'] = json_encode($p_nat_test,true);
|
||||
}
|
||||
unset($pn_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($pn_rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
|
||||
$rows = array_merge($rows,$p_rows, $pn_rows);
|
||||
$qry = $this->db->query("delete from ss_price_mou where Ss_PriceMouM_MouID=?", array($mouID));
|
||||
if ( ! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
$qry = $this->db->insert_batch("ss_price_mou", $rows);
|
||||
if ( ! $qry ) {
|
||||
return array(false, "Regional " . print_r($this->db->error(),true));
|
||||
}
|
||||
return array(true, "OK");
|
||||
}
|
||||
public function edit($mouID,$testID,$cito) {
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("onedev",true);
|
||||
|
||||
$sql = "select * from t_test where T_TestID = ? ";
|
||||
$qry = $this->db->query($sql, array($testID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "No Test $testID found");
|
||||
}
|
||||
$sasCode = $rows[0]["T_TestSasCode"];
|
||||
if ( strlen($sasCode) == 8 ) {
|
||||
$flagProfile = false;
|
||||
} else {
|
||||
$flagProfile = true;
|
||||
}
|
||||
|
||||
$sql = "select * from m_mou where M_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0 ) {
|
||||
return array(false, "No MOU $mouID found");
|
||||
}
|
||||
$mouName = $rows[0]["M_MouName"];
|
||||
$companyID = $rows[0]["M_MouM_CompanyID"];
|
||||
|
||||
$sql = "select distinct T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID and T_TestID = ?
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y' and T_PriceIsCito = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID <> 5
|
||||
where T_PriceM_MouID = ?";
|
||||
$qry = $this->db->query($sql, array($testID, $cito, $mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
|
||||
foreach($rows as $idx => $r) {
|
||||
$nat_testType = $r["Nat_TestNat_TestTypeID"];
|
||||
switch($nat_testType) {
|
||||
case 1: //Single
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
case 3: //Multi
|
||||
case 4: //Panel
|
||||
$sasCode = $r["T_TestSasCode"] . '%';
|
||||
$sql = "select T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestIsResult = 'Y'
|
||||
and T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array($r["Nat_TestID"]);
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = $nr["T_TestNat_TestID"];
|
||||
}
|
||||
$rows[$idx]['nat_test'] = "[" . join(",",$t_rows) . "]";
|
||||
break;
|
||||
default :
|
||||
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
|
||||
break;
|
||||
}
|
||||
unset($rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
}
|
||||
if ( count($rows) > 0 ) {
|
||||
$r = $rows[0];
|
||||
unset($r["T_TestSasCode"]);
|
||||
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
||||
$this->db->where("T_TestID", $r["T_TestID"]);
|
||||
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
||||
$qry = $this->db->update("ss_price_mou",$r);
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
}
|
||||
$sasCode = substr($sasCode,0,8);
|
||||
foreach($rows as $idx => $r ) {
|
||||
if ( strlen($r["T_TestSasCode"]) > 8 ) {
|
||||
unset($rows[$idx]);
|
||||
} else {
|
||||
unset($rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
}
|
||||
if ($cito == 'Y' ) {
|
||||
return array(true,"OK",$rows);
|
||||
}
|
||||
// for non cito
|
||||
if($flagProfile ) {
|
||||
//wip profile
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, 0 T_PriceAmount, 0 T_PriceDisc, 0 T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, 0 T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PXR' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
|
||||
from t_test
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID and T_TestSasCode = ?
|
||||
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID = 5
|
||||
where length(T_TestSasCode) = 8 ";
|
||||
$qry = $this->db->query($sql, array($sasCode));
|
||||
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$p_rows = $qry->result_array();
|
||||
|
||||
$sasCodeLike = $sasCode . "%";
|
||||
$sql = "select distinct substr(T_TestSasCode,1,8) parentCode, T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
|
||||
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
|
||||
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
Nat_TestNat_TestTypeID, T_TestSasCode,T_TestIsResult, T_TestCode
|
||||
from t_price
|
||||
join t_test on T_PriceT_TestID = T_TestID
|
||||
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_TestIsPrice = 'Y' and T_PriceIsCito = 'N'
|
||||
and T_TestSasCode like ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
where T_PriceM_MouID = ? ";
|
||||
$qry = $this->db->query($sql,array($sasCodeLike,$mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional child_test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_child = array();
|
||||
$p_codes = "'0'";
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
if ( ! isset($arr_child[$pCode])) {
|
||||
$arr_child[$pCode] = array();
|
||||
}
|
||||
$cCode = $r["T_TestSasCode"];
|
||||
$p_codes .= ", '$cCode'";
|
||||
unset($r["parentCode"]);
|
||||
$arr_child[$pCode][] = $r;
|
||||
}
|
||||
|
||||
$sql = "select substr(T_TestSasCode,1,8) parentCode,
|
||||
group_concat(distinct T_TestNat_TestID) nat
|
||||
from t_test
|
||||
where ( T_TestIsResult = 'Y' or T_TestIsPrice = 'Y' )
|
||||
and T_TestSasCode in ( $p_codes )
|
||||
and T_TestIsActive = 'Y'
|
||||
group by parentCode";
|
||||
$qry = $this->db->query($sql,array($mouID));
|
||||
if (!$qry ) {
|
||||
return array(false, "Regional nat_test " . print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$arr_nat = array();
|
||||
foreach($xrows as $r ) {
|
||||
$pCode = $r["parentCode"];
|
||||
//if ( ! isset($arr_nat[$pCode])) {
|
||||
// $arr_nat[$pCode] = array();
|
||||
//}
|
||||
$arr_nat[$pCode] = $r["nat"];
|
||||
}
|
||||
|
||||
$flag_error = false;
|
||||
foreach($p_rows as $idx => $r) {
|
||||
$T_TestName= $r["T_TestName"] ;
|
||||
$sasCode = $r["T_TestSasCode"];
|
||||
if ( isset($arr_child[$sasCode]) ) {
|
||||
$the_childs = $arr_child[$sasCode];
|
||||
$p_rows[$idx]['child_test'] = json_encode($the_childs,true);
|
||||
if ( isset($arr_nat[$sasCode] )) {
|
||||
$p_rows[$idx]['nat_test'] = "[" . $arr_nat[$sasCode] . "]";
|
||||
}
|
||||
unset($p_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($p_rows[$idx]["T_TestSasCode"]);
|
||||
} else {
|
||||
unset($p_rows[$idx]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach($p_rows as $r) {
|
||||
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
||||
$this->db->where("T_TestID", $r["T_TestID"]);
|
||||
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
||||
$qry = $this->db->update("ss_price_mou",$r);
|
||||
if (! $qry ) {
|
||||
return array(false, "Err Update Ss_priceMou " . print_r($this->db->error(),true));
|
||||
}
|
||||
}
|
||||
$rows = array_merge($rows,$p_rows);
|
||||
}
|
||||
//Update Panel yang mengandung Test
|
||||
$sql = "select
|
||||
distinct T_PacketDetailT_PacketID
|
||||
from
|
||||
t_packetdetail
|
||||
where T_PacketDetailIsActive = 'Y'
|
||||
and T_PacketDetailT_TestID = ?";
|
||||
$qry = $this->db->query($sql, array($testID));
|
||||
if (!$qry) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
$packet_ids = "0";
|
||||
foreach($xrows as $r ) {
|
||||
$packet_ids .= "," . $r["T_PacketDetailT_PacketID"];
|
||||
}
|
||||
|
||||
$sql = "select distinct $mouID T_PriceM_MouID, T_PacketID T_TestID, T_PacketName T_TestName, 'N' IsFromPanel, 0 Nat_TestID,
|
||||
T_PacketID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
|
||||
0 T_PricePriority, T_PacketOriginalBruto T_PriceAmount, 0 T_PriceDisc,
|
||||
(T_PacketOriginalBruto - T_PacketPrice) T_PriceDiscRp, 0 T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketPrice T_PriceTotal, 'Y' T_TestForceSell, 'Y' is_packet, T_PacketID packet_id,
|
||||
T_PacketType px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
|
||||
$mouID Ss_PriceMouM_MouID
|
||||
from
|
||||
t_packet
|
||||
where
|
||||
T_PacketIsActive = 'Y' and T_PacketID in ( $packet_ids )
|
||||
and T_PacketM_MouID = ?";
|
||||
|
||||
$qry = $this->db->query($sql, array($mouID));
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$pn_rows = $qry->result_array();
|
||||
foreach($pn_rows as $idx => $pnr) {
|
||||
$packetID = $pnr["packet_id"];
|
||||
//child test
|
||||
$sql = "select $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
|
||||
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID,
|
||||
$mouID T_PriceM_MouID, 0 T_PricePriority, T_PacketDetailPriceAmount T_PriceAmount,
|
||||
T_PacketDetailPriceDisc T_PriceDisc, T_PacketDetailPriceDiscRp T_PriceDiscRp, T_PacketDetailPriceSubTotal T_PriceSubTotal,
|
||||
0 T_PriceOther, T_PacketDetailPrice T_PriceTotal,
|
||||
'Y' T_TestForceSell, 'N' is_packet, 0 packet_id,
|
||||
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite, T_TestSasCode
|
||||
from t_packetdetail
|
||||
join t_test on T_PacketDetailT_TestID = T_TestID
|
||||
and T_PacketDetailIsActive = 'Y' and T_TestIsActive = 'Y'
|
||||
and T_PacketDetailT_PacketID = ?
|
||||
join nat_test on T_TestNat_TestID = Nat_TestID
|
||||
and Nat_TestIsActive = 'Y'
|
||||
";
|
||||
$qry = $this->db->query($sql,array($packetID));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$ct_rows = $qry->result_array();
|
||||
$p_nat_test = array();
|
||||
foreach($ct_rows as $ct_idx => $cr) {
|
||||
$sasCode = $cr["T_TestSasCode"] . '%';
|
||||
$sql = "select distinct T_TestNat_TestID
|
||||
from t_test
|
||||
where T_TestSasCode like ?
|
||||
and T_TestIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,array($sasCode));
|
||||
if (!$qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
$nt_rows = $qry->result_array();
|
||||
$t_rows = array();
|
||||
foreach($nt_rows as $nr) {
|
||||
$t_rows[] = intval( $nr["T_TestNat_TestID"]);
|
||||
$p_nat_test[]= intval( $nr["T_TestNat_TestID"]);
|
||||
}
|
||||
$ct_rows[$ct_idx]['nat_test'] = json_encode($t_rows,JSON_NUMERIC_CHECK);
|
||||
}
|
||||
if (count($ct_rows) > 0 ) {
|
||||
$x_arr = array();
|
||||
foreach($ct_rows as $x_cr) {
|
||||
$x_arr[] = $x_cr;
|
||||
}
|
||||
$pn_rows[$idx]['child_test'] = json_encode($x_arr,true);
|
||||
$pn_rows[$idx]['nat_test'] = json_encode($p_nat_test,true);
|
||||
}
|
||||
unset($pn_rows[$idx]["Nat_TestNat_TestTypeID"]);
|
||||
unset($pn_rows[$idx]["T_TestSasCode"]);
|
||||
}
|
||||
foreach($pn_rows as $r ) {
|
||||
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
|
||||
$this->db->where("T_TestID", $r["T_TestID"]);
|
||||
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
|
||||
$qry = $this->db->update("ss_price_mou",$r);
|
||||
if (! $qry ) {
|
||||
return array(false, print_r($this->db->error(),true));
|
||||
}
|
||||
}
|
||||
$rows = array_merge($rows,$pn_rows);
|
||||
return array(true,"OK",$rows);
|
||||
}
|
||||
}
|
||||
52
application/libraries/SsPriceMouPx.php
Normal file
52
application/libraries/SsPriceMouPx.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
class SsPriceMouPx {
|
||||
|
||||
public function create($mouID) {
|
||||
$CI =& get_instance();
|
||||
$this->db = $CI->load->database("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, "");
|
||||
}
|
||||
}
|
||||
249
application/libraries/Txbranchstatus-cabang.php
Normal file
249
application/libraries/Txbranchstatus-cabang.php
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
300
application/libraries/Txbranchstatus.php
Normal file
300
application/libraries/Txbranchstatus.php
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
296
application/libraries/Txbranchstatus_updated.php
Normal file
296
application/libraries/Txbranchstatus_updated.php
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
63
application/libraries/Wa_krmv3.php
Normal file
63
application/libraries/Wa_krmv3.php
Normal 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);
|
||||
}
|
||||
}
|
||||
159
application/libraries/Wa_sas.php
Normal file
159
application/libraries/Wa_sas.php
Normal 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;
|
||||
}
|
||||
}
|
||||
127
application/libraries/his/Simrs.php
Normal file
127
application/libraries/his/Simrs.php
Normal 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;
|
||||
}}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user