1723 lines
72 KiB
PHP
1723 lines
72 KiB
PHP
<?php
|
|
|
|
class Regionalpiutang extends MY_Controller
|
|
{
|
|
var $db;
|
|
public function index()
|
|
{
|
|
echo "Piutang API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
// $this->db = $this->load->database("default", true);
|
|
$this->db->query("use one_dash");
|
|
}
|
|
|
|
function corss()
|
|
{
|
|
global $_SERVER;
|
|
if (isset($_SERVER["HTTP_ORIGIN"])) {
|
|
header("Access-Control-Allow-Origin: " . $_SERVER["HTTP_ORIGIN"]);
|
|
} else {
|
|
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, Authorization"
|
|
);
|
|
if (
|
|
isset($_SERVER["REQUEST_METHOD"]) &&
|
|
$_SERVER["REQUEST_METHOD"] == "OPTIONS"
|
|
) {
|
|
http_response_code(200);
|
|
echo json_encode("OK");
|
|
exit();
|
|
}
|
|
}
|
|
|
|
public function getClassificationNumber($number_param_x)
|
|
{
|
|
$this->corss();
|
|
// $number_fix = 0;
|
|
// if ($number_param < 0) {
|
|
// $number_fix = $number_param * -1;
|
|
// } else {
|
|
// $number_fix = $number_param;
|
|
// }
|
|
|
|
$number_param = abs($number_param_x);
|
|
$string = "Puluhan";
|
|
|
|
if ($number_param >= 1000000000) {
|
|
// echo "Angka ini dalam miliar";
|
|
$number_format = $number_param / 1000000000;
|
|
$formatted_number_fix = number_format($number_format, 2);
|
|
$string = ($number_param_x >= 0 ? '' : '-') . $formatted_number_fix . " M";
|
|
} elseif ($number_param >= 1000000) {
|
|
// echo "Angka ini dalam juta";
|
|
$number_format = $number_param / 1000000;
|
|
$formatted_number_fix = number_format($number_format, 2);
|
|
$string = ($number_param_x >= 0 ? '' : '-') . $formatted_number_fix . " Juta";
|
|
} elseif ($number_param >= 1000) {
|
|
// echo "Angka ini dalam ribuan";
|
|
$number_format = $number_param / 1000;
|
|
$formatted_number_fix = number_format($number_format, 2);
|
|
$string = ($number_param_x >= 0 ? '' : '-') . $formatted_number_fix . " Ribu";
|
|
} elseif ($number_param >= 100) {
|
|
$number_format = $number_param / 100;
|
|
$formatted_number_fix = number_format($number_format, 2);
|
|
$string = ($number_param_x >= 0 ? '' : '-') . $formatted_number_fix . " Ratus";
|
|
} else {
|
|
// echo "Angka ini dalam ratusan";
|
|
$number_format = $number_param / 10;
|
|
$formatted_number_fix = number_format($number_format, 2);
|
|
$string = ($number_param_x >= 0 ? '' : '-') . $formatted_number_fix . " Puluh";
|
|
}
|
|
|
|
return $string;
|
|
}
|
|
|
|
public function list_color_bar_chart_v1($index, $list_scope)
|
|
{
|
|
$this->corss();
|
|
// diurutkan M_Branch ASC
|
|
$listColor = [
|
|
"#100003",
|
|
"#39000B",
|
|
"#49000F",
|
|
"#610014",
|
|
"#720017",
|
|
"#6A0000",
|
|
"#820000",
|
|
"#9B0000",
|
|
"#B30000",
|
|
"#C00",
|
|
"#D40026",
|
|
"#EC0030",
|
|
"#E40000",
|
|
"#FC0000",
|
|
"#FF0606",
|
|
"#FF1E1E",
|
|
"#FF4747",
|
|
"#FF2E2E",
|
|
"#FF4747",
|
|
"#FF5757",
|
|
"#FF5F5F",
|
|
"#FF7070",
|
|
"#FF8080",
|
|
"#FF9090",
|
|
];
|
|
|
|
// define default color grey jika list scope != listColor
|
|
if ($list_scope != count($listColor)) {
|
|
if (intval($list_scope) > count($listColor)) {
|
|
$greyCount = count($list_scope) - count($listColor);
|
|
$greyColors = array_fill(0, $greyCount, "#888888");
|
|
$resultColor = array_merge($listColor, $greyColors);
|
|
$listColor = $resultColor;
|
|
} else {
|
|
$listColor[$index];
|
|
}
|
|
} else {
|
|
$listColor[$index];
|
|
}
|
|
|
|
return $listColor[$index];
|
|
}
|
|
|
|
public function list_color_bar_chart($index, $list_scope)
|
|
{
|
|
$this->corss();
|
|
// diurutkan S_RegionalName ASC
|
|
$listColor = [
|
|
"#D00000",
|
|
"#FFBA08",
|
|
"#1B998B",
|
|
"#5D2E8C",
|
|
"#3185FC",
|
|
"#FF7B9C",
|
|
];
|
|
|
|
// define default color grey jika list scope != listColor
|
|
if ($list_scope != count($listColor)) {
|
|
if ($list_scope > count($listColor)) {
|
|
$greyCount = count($list_scope) - count($listColor);
|
|
$greyColors = array_fill(0, $greyCount, "#888888");
|
|
$resultColor = array_merge($listColor, $greyColors);
|
|
$listColor = $resultColor;
|
|
} else {
|
|
$listColor[$index];
|
|
}
|
|
} else {
|
|
$listColor[$index];
|
|
}
|
|
|
|
return $listColor[$index];
|
|
}
|
|
|
|
public function formatAngkaJuta($angka)
|
|
{
|
|
return "Rp " . number_format($angka / 1000000, 2, ',', '.') . ' Juta';
|
|
}
|
|
|
|
public function getQuarterByFilter($waktu)
|
|
{
|
|
if ($waktu == "Q1") {
|
|
$quarterResult = "1";
|
|
} elseif ($waktu == "Q2") {
|
|
$quarterResult = "2";
|
|
} elseif ($waktu == "Q3") {
|
|
$quarterResult = "3";
|
|
} elseif ($waktu == "Q4") {
|
|
$quarterResult = "4";
|
|
} else {
|
|
$quarterResult = "";
|
|
}
|
|
|
|
$result = $quarterResult;
|
|
|
|
return $result;
|
|
}
|
|
|
|
// regional start
|
|
public function reg_total_piutang_bar_chart_no_group_xold1($debug = "", $debugRegID = "0")
|
|
{
|
|
$this->corss();
|
|
// total pendapatan nat_sales
|
|
// *) di tambah dengan tahun - 1
|
|
// di berikan diff dalam persen , jika sebelumnya 0 ( belum ada data ) di kasih 100
|
|
|
|
try {
|
|
// if (!$this->isLogin) {
|
|
// $this->sys_error("Invalid Token");
|
|
// exit;
|
|
// }
|
|
|
|
$date_now = date('Y-m-d');
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
$regID = "0";
|
|
if (isset($prm['reg_id'])) {
|
|
$regID = $prm["reg_id"];
|
|
}
|
|
if ($debugRegID != "0") {
|
|
$regID = $debugRegID;
|
|
}
|
|
|
|
$sql_branch_list = "SELECT M_BranchID, M_BranchName
|
|
from m_branch
|
|
where M_BranchIsActive = 'Y'
|
|
order by M_BranchName ASC";
|
|
$qry_branch_list = $this->db->query($sql_branch_list);
|
|
if (!$qry_branch_list) {
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $this->db->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$last_qry_branch_list = $this->db->last_query();
|
|
$rst_branch_list = $qry_branch_list->result_array();
|
|
|
|
// nat_sales
|
|
$sql_nat_sales = "SELECT ifnull(SUM(`Nat_SalesTotal`), 0) AS a,
|
|
M_BranchID as M_BranchID, M_BranchName as M_BranchName
|
|
FROM `nat_sales`
|
|
JOIN m_branch
|
|
ON Nat_SalesM_BranchID = M_BranchID
|
|
AND M_BranchIsActive = 'Y'
|
|
AND `Nat_SalesYear` = YEAR('$date_now')
|
|
AND Nat_SalesIsActive = 'Y'
|
|
JOIN s_regional
|
|
ON M_BranchS_RegionalID = S_RegionalID
|
|
AND S_RegionalIsActive = 'Y'
|
|
AND S_RegionalID = $regID
|
|
GROUP BY M_BranchID
|
|
ORDER BY M_BranchName ASC";
|
|
|
|
$qry_nat_sales = $this->db->query($sql_nat_sales);
|
|
if (!$qry_nat_sales) {
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $this->db->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$last_qry_nat_sales = $this->db->last_query();
|
|
$rst_nat_sales = $qry_nat_sales->result_array();
|
|
|
|
// nat_payment
|
|
$sql_nat_payment = "SELECT ifnull(SUM(Nat_PaymentTotal),0) AS b,
|
|
M_BranchID as M_BranchID, M_BranchName as M_BranchName
|
|
FROM nat_payment
|
|
JOIN m_branch
|
|
ON Nat_PaymentM_BranchID = M_BranchID
|
|
AND M_BranchIsActive = 'Y'
|
|
AND Nat_PaymentOrderYear = year('$date_now')
|
|
AND Nat_PaymentIsActive = 'Y'
|
|
JOIN s_regional
|
|
ON M_BranchS_RegionalID = S_RegionalID
|
|
AND S_RegionalIsActive = 'Y'
|
|
AND S_RegionalID = $regID
|
|
GROUP BY M_BranchID
|
|
ORDER BY M_BranchName ASC";
|
|
|
|
$qry_nat_payment = $this->db->query($sql_nat_payment);
|
|
if (!$qry_nat_payment) {
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $this->db->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$last_qry_nat_payment = $this->db->last_query();
|
|
$rst_nat_payment = $qry_nat_payment->result_array();
|
|
|
|
$list_scope = [];
|
|
$value_of_scope = [];
|
|
$result = [];
|
|
$list_color = [];
|
|
$hasil_tmp = [];
|
|
|
|
// klu nat_sales tidak kosong di push
|
|
if (count($rst_nat_sales) > 0) {
|
|
foreach ($rst_nat_sales as $key => $value) {
|
|
$hasil_tmp[] = [
|
|
"alias" => "a",
|
|
"value" => $value['a'],
|
|
"M_BranchID" => $value['M_BranchID'],
|
|
"M_BranchName" => $value['M_BranchName']
|
|
];
|
|
}
|
|
}
|
|
|
|
// klu nat_payment tidak kosong di push
|
|
if (count($rst_nat_payment) > 0) {
|
|
foreach ($rst_nat_payment as $key => $value) {
|
|
$hasil_tmp[] = [
|
|
"alias" => "b",
|
|
"value" => $value['b'],
|
|
"M_BranchID" => $value['M_BranchID'],
|
|
"M_BranchName" => $value['M_BranchName']
|
|
];
|
|
}
|
|
}
|
|
|
|
// grup M_BranchID dari array hasil_tmp
|
|
$grouped = [];
|
|
foreach ($hasil_tmp as $item) {
|
|
$alias = $item["alias"];
|
|
$M_BranchID = $item["M_BranchID"];
|
|
$value = $item["value"];
|
|
$M_BranchName = $item['M_BranchName'];
|
|
|
|
if (!isset($grouped[$M_BranchID][$alias])) {
|
|
$grouped[$M_BranchID][$alias] = [
|
|
"value" => 0,
|
|
"M_BranchName" => $item["M_BranchName"],
|
|
];
|
|
}
|
|
|
|
// sum group by berdasarkan alias dan regional
|
|
$grouped[$M_BranchID][$alias]["value"] += $value;
|
|
}
|
|
|
|
// hitung selisih a - b
|
|
$hasil_baru = [];
|
|
foreach ($grouped as $M_BranchID => $vx) {
|
|
// klu a & b set
|
|
if (isset($vx["a"]) && isset($vx["b"])) {
|
|
$value = $vx["a"]["value"] - $vx["b"]["value"];
|
|
$hasil_baru[] = [
|
|
"M_BranchID" => $M_BranchID,
|
|
"M_BranchName" => $vx["a"]["M_BranchName"],
|
|
"value" => $value,
|
|
];
|
|
} else {
|
|
// klu b tidak set
|
|
if (isset($vx['a']) && !isset($vx['b'])) {
|
|
$value = $vx["a"]["value"] - 0;
|
|
$hasil_baru[] = [
|
|
"M_BranchID" => $M_BranchID,
|
|
"M_BranchName" => $vx["a"]["M_BranchName"],
|
|
"value" => $value,
|
|
];
|
|
} else {
|
|
$value = 0;
|
|
$hasil_baru[] = [
|
|
"M_BranchID" => $M_BranchID,
|
|
"M_BranchName" => $vx["a"]["M_BranchName"],
|
|
"value" => $value,
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|
|
// check kalau sudah ada value di array hasil_baru maka tidak ditambahkan
|
|
// klu blm ada di tambahkan dengan nilai value 0
|
|
if (count($rst_branch_list) > 0) {
|
|
// Buat array asosiatif sementara yang akan digunakan untuk melacak M_BranchID yang sudah ada
|
|
$existingRegionalIDs = array_column($hasil_baru, 'M_BranchID');
|
|
|
|
foreach ($rst_branch_list as $key => $value) {
|
|
// Periksa apakah M_BranchID sudah ada dalam $existingRegionalIDs
|
|
if (!in_array($value['M_BranchID'], $existingRegionalIDs)) {
|
|
$hasil_baru[] = [
|
|
"value" => 0,
|
|
"M_BranchID" => $value['M_BranchID'],
|
|
"M_BranchName" => $value['M_BranchName']
|
|
];
|
|
|
|
// Tambahkan M_BranchID baru ke $existingRegionalIDs
|
|
$existingRegionalIDs[] = $value['M_BranchID'];
|
|
}
|
|
}
|
|
}
|
|
|
|
// Ekstrak M_BranchName ke dalam array terpisah untuk pengurutan
|
|
$M_BranchName = array_column($hasil_baru, 'M_BranchName');
|
|
|
|
// Urutkan $hasil_baru berdasarkan M_BranchName
|
|
array_multisort($M_BranchName, SORT_ASC, $hasil_baru);
|
|
|
|
$new_branch_list = [];
|
|
if (count($rst_branch_list) > 0) {
|
|
foreach ($rst_branch_list as $key => $value) {
|
|
$new_branch_list[] = $value['M_BranchName'];
|
|
}
|
|
}
|
|
|
|
$new_list_scope = array_merge($new_branch_list, $list_scope);
|
|
$new_list_scope = array_unique($new_list_scope);
|
|
|
|
// // masukkan ke array value_of_scope yg fix
|
|
if (count($hasil_baru) > 0) {
|
|
foreach ($hasil_baru as $key => $vx) {
|
|
$string_val = $vx['value'];
|
|
$value_of_scope[] = "$string_val";
|
|
// list color
|
|
$list_color[] = $this->list_color_bar_chart($key, $new_list_scope);
|
|
}
|
|
|
|
// // TESTING COLOR DEFAULT
|
|
// $x1 = [
|
|
// 'Bali Raya',
|
|
// 'Balikpapan Raya',
|
|
// 'Bandung Raya',
|
|
// 'Cirebon Raya',
|
|
// 'Jakarta Raya',
|
|
// 'Madiun Raya',
|
|
// 'Magelang Raya',
|
|
// 'Makassar Raya',
|
|
// 'Manado Raya',
|
|
// 'Medan Raya',
|
|
// 'Padang Raya',
|
|
// 'Palembang Raya',
|
|
// 'Pekanbaru Raya',
|
|
// 'Pontianak Raya',
|
|
// 'Prospek',
|
|
// 'Salatiga Raya',
|
|
// 'Semarang Raya',
|
|
// 'Sima Jember',
|
|
// 'Sima Kediri',
|
|
// 'Sima Malang',
|
|
// 'Surabaya Raya',
|
|
// 'Tasik Raya',
|
|
// 'Tegal Raya',
|
|
// 'Yogyaraya',
|
|
// 'Bali Raya',
|
|
// 'Balikpapan Raya',
|
|
// 'Bandung Raya',
|
|
// 'Cirebon Raya',
|
|
// 'Jakarta Raya',
|
|
// 'Madiun Raya',
|
|
// 'Magelang Raya',
|
|
// 'Makassar Raya',
|
|
// 'Manado Raya',
|
|
// 'Medan Raya',
|
|
// 'Padang Raya',
|
|
// 'Palembang Raya',
|
|
// 'Pekanbaru Raya',
|
|
// 'Pontianak Raya',
|
|
// 'Prospek',
|
|
// 'Salatiga Raya',
|
|
// 'Semarang Raya',
|
|
// 'Sima Jember',
|
|
// 'Sima Kediri',
|
|
// 'Sima Malang',
|
|
// 'Surabaya Raya',
|
|
// 'Tasik Raya',
|
|
// 'Tegal Raya',
|
|
// 'Yogyaraya',
|
|
// ];
|
|
// for ($i = 0; $i < count($x1); $i++) {
|
|
// // $value_of_scope[] = $rst_tahun_berjalan[$i]['total_sales_tahun_berjalan'];
|
|
// // $list_scope[] = $rst_tahun_berjalan[$i]['S_RegionalName'];
|
|
// $list_color[] = $this->list_color_bar_chart($i, count($x1));
|
|
// }
|
|
}
|
|
|
|
$result = array(
|
|
"value_of_scope" => $value_of_scope,
|
|
"list_scope" => $new_list_scope,
|
|
"bar_chart_color" => $list_color,
|
|
);
|
|
|
|
// $result = array(
|
|
// "value_of_scope" => [],
|
|
// "list_scope" => [],
|
|
// "bar_chart_color" => [],
|
|
// );
|
|
|
|
if ($debug != "") {
|
|
$result = array(
|
|
"rst_nat_sales" => $rst_nat_sales,
|
|
"rst_nat_payment" => $rst_nat_payment,
|
|
"hasil_tmp" => $hasil_tmp,
|
|
"hasil_baru" => $hasil_baru,
|
|
"value_of_scope" => $value_of_scope,
|
|
"list_scope" => $new_list_scope,
|
|
"bar_chart_color" => $list_color,
|
|
"last_qry_nat_sales" => $last_qry_nat_sales,
|
|
"last_qry_nat_payment" => $last_qry_nat_payment,
|
|
"last_qry_branch_list" => $last_qry_branch_list,
|
|
);
|
|
|
|
echo "<pre>";
|
|
print_r($result);
|
|
echo "</pre>";
|
|
exit;
|
|
}
|
|
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function reg_total($debug = "", $debugRegID = "0", $debugfilter_waktu = "")
|
|
{
|
|
$this->corss();
|
|
try {
|
|
// if (!$this->isLogin) {
|
|
// $this->sys_error("Invalid Token");
|
|
// exit;
|
|
// }
|
|
// $param = $this->sys_input;
|
|
|
|
$prm = $this->sys_input;
|
|
// $regID adalah filter scope
|
|
$regID = "0";
|
|
$filter_waktu = "";
|
|
$where_tahun_berjalan_a = "";
|
|
$where_tahun_berjalan_b = "";
|
|
$where_year_min_1_a = "";
|
|
$where_year_min_1_b = "";
|
|
|
|
$date_now = date('Y-m-d');
|
|
$end_date_year_min_1 = date('Y-m-d', strtotime($date_now . ' -1 year'));
|
|
|
|
if (isset($prm['filter_scope'])) {
|
|
$regID = $prm["filter_scope"];
|
|
}
|
|
|
|
if (isset($prm['filter_waktu'])) {
|
|
$filter_waktu = $prm["filter_waktu"];
|
|
}
|
|
|
|
if ($debugRegID != "0") {
|
|
$regID = $debugRegID;
|
|
}
|
|
|
|
if ($debug != "") {
|
|
$regID = $debugRegID;
|
|
$filter_waktu = $debugfilter_waktu;
|
|
if ($filter_waktu != "") {
|
|
if ($filter_waktu != 'YTD') {
|
|
// bukan Year To Date
|
|
|
|
if (strpos($filter_waktu, 'Q') !== false || strpos($filter_waktu, 'q') !== false) {
|
|
$quarterResult = $this->getQuarterByFilter($filter_waktu);
|
|
if ($quarterResult != '-') {
|
|
$where_tahun_berjalan_a = " AND Nat_SalesQuarter = ($quarterResult)";
|
|
$where_year_min_1_a = " AND Nat_SalesQuarter = ($quarterResult)";
|
|
|
|
// $where_tahun_berjalan_b = " AND Nat_PaymentQuarter = ($quarterResult)";
|
|
// $where_year_min_1_b = " AND Nat_PaymentQuarter = ($quarterResult)";
|
|
|
|
$where_tahun_berjalan_b = " AND Nat_PaymentOrderQuarter = ($quarterResult)";
|
|
$where_year_min_1_b = " AND Nat_PaymentOrderQuarter = ($quarterResult)";
|
|
}
|
|
}
|
|
} else {
|
|
if ($filter_waktu == "YTD") {
|
|
// jika Year To Date
|
|
// klu berjalan, 1 januari 2023 - 4 oktober 2023 ( date now )
|
|
// klu end date year - 1 , 1 januari 2022 - (date now - 1)
|
|
$berjalan_a = date('Y-01-01');
|
|
|
|
$end_date_a = date('Y-01-01', strtotime('-1 year'));
|
|
$end_date_b = date('Y-m-d', strtotime('-1 year'));
|
|
|
|
// berjalan
|
|
// Nat_SalesDay >= '2023-01-01' AND Nat_SalesDay <= '2023-10-04'
|
|
// Nat_SalesYear` = year('$date_now')
|
|
// AND Nat_SalesDay >= '$berjalan_a' AND Nat_SalesDay <= '$date_now'
|
|
$where_tahun_berjalan_a = " AND Nat_SalesIsActive = 'Y'
|
|
AND `Nat_SalesYear` = year('$date_now')
|
|
AND (`Nat_SalesDay` >= '$berjalan_a' AND `Nat_SalesDay` <= '$date_now')";
|
|
|
|
// end date year - 1
|
|
// Nat_SalesDay >= '2022-01-01' AND Nat_SalesDay <= '2022-10-04'
|
|
|
|
$where_year_min_1_a = " AND Nat_SalesIsActive = 'Y'
|
|
AND `Nat_SalesYear` = year('$date_now') - 1
|
|
AND (`Nat_SalesDay` >= '$end_date_a' AND `Nat_SalesDay` <= DATE(NOW() - INTERVAL 1 YEAR))";
|
|
|
|
$where_tahun_berjalan_b = " AND Nat_PaymentIsActive = 'Y'
|
|
AND `Nat_PaymentOrderYear` = year('$date_now')
|
|
AND (`Nat_PaymentOrderDay` >= '$berjalan_a' AND `Nat_PaymentOrderDay` <= '$date_now')";
|
|
|
|
$where_year_min_1_b = " AND Nat_PaymentIsActive = 'Y'
|
|
AND `Nat_PaymentOrderYear` = year('$date_now') - 1
|
|
AND (`Nat_PaymentOrderDay` >= '$end_date_a' AND `Nat_PaymentOrderDay` <= DATE(NOW() - INTERVAL 1 YEAR))";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($filter_waktu != "") {
|
|
if ($filter_waktu != 'YTD') {
|
|
// bukan Year To Date
|
|
|
|
if (strpos($filter_waktu, 'Q') !== false || strpos($filter_waktu, 'q') !== false) {
|
|
$quarterResult = $this->getQuarterByFilter($filter_waktu);
|
|
if ($quarterResult != '-') {
|
|
$where_tahun_berjalan_a = "
|
|
AND Nat_SalesIsActive = 'Y'
|
|
AND Nat_SalesQuarter = ($quarterResult)";
|
|
|
|
$where_year_min_1_a = " AND Nat_SalesIsActive = 'Y'
|
|
AND Nat_SalesQuarter = ($quarterResult)";
|
|
|
|
// $where_tahun_berjalan_b = " AND Nat_PaymentQuarter = ($quarterResult)";
|
|
// $where_year_min_1_b = " AND Nat_PaymentQuarter = ($quarterResult)";
|
|
|
|
$where_tahun_berjalan_b = " AND Nat_PaymentIsActive = 'Y'
|
|
AND Nat_PaymentOrderQuarter = ($quarterResult)
|
|
AND Nat_PaymentQuarter = ($quarterResult)";
|
|
|
|
$where_year_min_1_b = " AND Nat_PaymentIsActive = 'Y'
|
|
AND Nat_PaymentOrderQuarter = ($quarterResult)
|
|
AND Nat_PaymentQuarter = ($quarterResult)";
|
|
}
|
|
}
|
|
} else {
|
|
if ($filter_waktu == "YTD") {
|
|
// jika Year To Date
|
|
// klu berjalan, 1 januari 2023 - 4 oktober 2023 ( date now )
|
|
// klu end date year - 1 , 1 januari 2022 - (date now - 1)
|
|
$berjalan_a = date('Y-01-01');
|
|
|
|
$end_date_a = date('Y-01-01', strtotime('-1 year'));
|
|
$end_date_b = date('Y-m-d', strtotime('-1 year'));
|
|
|
|
// berjalan
|
|
// Nat_SalesDay >= '2023-01-01' AND Nat_SalesDay <= '2023-10-04'
|
|
// Nat_SalesYear` = year('$date_now')
|
|
// AND Nat_SalesDay >= '$berjalan_a' AND Nat_SalesDay <= '$date_now'
|
|
$where_tahun_berjalan_a = " AND Nat_SalesIsActive = 'Y'
|
|
AND `Nat_SalesYear` = year('$date_now')
|
|
AND (`Nat_SalesDay` >= '$berjalan_a' AND `Nat_SalesDay` <= '$date_now')";
|
|
|
|
// end date year - 1
|
|
// Nat_SalesDay >= '2022-01-01' AND Nat_SalesDay <= '2022-10-04'
|
|
|
|
$where_year_min_1_a = " AND Nat_SalesIsActive = 'Y'
|
|
AND `Nat_SalesYear` = year('$date_now') - 1
|
|
AND (`Nat_SalesDay` >= '$end_date_a' AND `Nat_SalesDay` <= DATE(NOW() - INTERVAL 1 YEAR))";
|
|
|
|
$where_tahun_berjalan_b = " AND Nat_PaymentIsActive = 'Y'
|
|
AND `Nat_PaymentOrderYear` = year('$date_now')
|
|
AND (`Nat_PaymentOrderDay` >= '$berjalan_a' AND `Nat_PaymentOrderDay` <= '$date_now')
|
|
AND `Nat_PaymentYear` = year('$date_now')
|
|
AND (`Nat_PaymentDay` >= '$berjalan_a' AND `Nat_PaymentDay` <= '$date_now')
|
|
";
|
|
|
|
$where_year_min_1_b = " AND Nat_PaymentIsActive = 'Y'
|
|
AND `Nat_PaymentOrderYear` = year('$date_now') - 1
|
|
AND (`Nat_PaymentOrderDay` >= '$end_date_a' AND `Nat_PaymentOrderDay` <= DATE(NOW() - INTERVAL 1 YEAR))
|
|
AND `Nat_PaymentYear` = year('$date_now') - 1
|
|
AND (`Nat_PaymentDay` >= '$end_date_a' AND `Nat_PaymentDay` <= DATE(NOW() - INTERVAL 1 YEAR))
|
|
";
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// tahun berjalan
|
|
$sql_tahun_berjalan_a = "SELECT ifnull(SUM(`Nat_SalesTotal`),0) AS a
|
|
FROM `nat_sales`
|
|
JOIN m_branch ON M_BranchID = Nat_SalesM_BranchID
|
|
AND M_BranchIsActive = 'Y'
|
|
AND Nat_SalesIsActive = 'Y'
|
|
AND `Nat_SalesYear` = year('$date_now')
|
|
$where_tahun_berjalan_a
|
|
JOIN s_regional ON S_RegionalID = M_BranchS_RegionalID
|
|
AND S_RegionalIsActive = 'Y'
|
|
AND S_RegionalID = $regID
|
|
";
|
|
|
|
$qry_tahun_berjalan_a = $this->db->query($sql_tahun_berjalan_a, []);
|
|
if (!$qry_tahun_berjalan_a) {
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $this->db->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$last_qry_tahun_berjalan_a = $this->db->last_query();
|
|
$rst_tahun_berjalan_a = $qry_tahun_berjalan_a->result_array();
|
|
|
|
$sql_tahun_berjalan_b = "SELECT ifnull(SUM(Nat_PaymentTotal),0) AS b
|
|
FROM nat_payment
|
|
JOIN m_branch
|
|
ON M_BranchID = Nat_PaymentM_BranchID
|
|
AND M_BranchIsActive = 'Y'
|
|
AND Nat_PaymentIsActive = 'Y'
|
|
AND Nat_PaymentOrderYear = year('$date_now')
|
|
$where_tahun_berjalan_b
|
|
JOIN s_regional
|
|
ON S_RegionalID = M_BranchS_RegionalID
|
|
AND S_RegionalIsActive = 'Y'
|
|
AND S_RegionalID = $regID";
|
|
|
|
$qry_tahun_berjalan_b = $this->db->query($sql_tahun_berjalan_b, []);
|
|
if (!$qry_tahun_berjalan_b) {
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $this->db->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$last_qry_tahun_berjalan_b = $this->db->last_query();
|
|
$rst_tahun_berjalan_b = $qry_tahun_berjalan_b->result_array();
|
|
|
|
$rst_piutang_berjalan = $rst_tahun_berjalan_a[0]['a'] - $rst_tahun_berjalan_b[0]['b'];
|
|
|
|
// year min 1
|
|
$sql_year_min_1_a = "SELECT ifnull(SUM(`Nat_SalesTotal`),0) AS a
|
|
FROM `nat_sales`
|
|
JOIN m_branch ON M_BranchID = Nat_SalesM_BranchID
|
|
AND M_BranchIsActive = 'Y'
|
|
AND Nat_SalesIsActive = 'Y'
|
|
AND `Nat_SalesYear` = year('$date_now') - 1
|
|
AND Nat_SalesDay <= DATE(NOW() - INTERVAL 1 YEAR)
|
|
AND Nat_SalesIsActive = 'Y'
|
|
$where_year_min_1_a
|
|
JOIN s_regional ON S_RegionalID = M_BranchS_RegionalID
|
|
AND S_RegionalIsActive = 'Y'
|
|
AND S_RegionalID = $regID
|
|
";
|
|
|
|
$qry_year_min_1_a = $this->db->query($sql_year_min_1_a, []);
|
|
if (!$qry_year_min_1_a) {
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $this->db->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$last_qry_year_min_1_a = $this->db->last_query();
|
|
$rst_year_min_1_a = $qry_year_min_1_a->result_array();
|
|
|
|
$sql_year_min_1_b = "SELECT ifnull(SUM(Nat_PaymentTotal),0) AS b
|
|
FROM nat_payment
|
|
JOIN m_branch
|
|
ON M_BranchID = Nat_PaymentM_BranchID
|
|
AND M_BranchIsActive = 'Y'
|
|
AND Nat_PaymentIsActive = 'Y'
|
|
AND Nat_PaymentOrderYear = year('$date_now') - 1
|
|
AND Nat_PaymentDay <= DATE(NOW() - INTERVAL 1 YEAR)
|
|
AND Nat_PaymentIsActive = 'Y'
|
|
$where_year_min_1_b
|
|
JOIN s_regional
|
|
ON S_RegionalID = M_BranchS_RegionalID
|
|
AND S_RegionalIsActive = 'Y'
|
|
AND S_RegionalID = $regID ";
|
|
|
|
$qry_year_min_1_b = $this->db->query($sql_year_min_1_b, []);
|
|
if (!$qry_year_min_1_b) {
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $this->db->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$last_qry_year_min_1_b = $this->db->last_query();
|
|
$rst_year_min_1_b = $qry_year_min_1_b->result_array();
|
|
|
|
$rst_piutang_year_min_1 = $rst_year_min_1_a[0]['a'] - $rst_year_min_1_b[0]['b'];
|
|
|
|
// calculate piutang nat total
|
|
$diff_total_piutang = ($rst_piutang_berjalan) -
|
|
($rst_piutang_year_min_1);
|
|
$diff_persen = 0.0;
|
|
$keterangan = "-";
|
|
|
|
// $formatted_number = $this->getClassificationNumber($diff_total_piutang);
|
|
$formatted_number = $this->getClassificationNumber($rst_piutang_berjalan);
|
|
|
|
// kalau tahun lalu 0 maka 100%
|
|
if (($rst_piutang_year_min_1) == 0) {
|
|
$diff_persen = 100;
|
|
} else {
|
|
// $persentase = (($tahun_sekarang - $tahun_lalu) / $tahun_lalu) * 100;
|
|
$diff_persen_calculate = ($diff_total_piutang / ($rst_piutang_year_min_1)) * 100;
|
|
$diff_persen = number_format($diff_persen_calculate, 0);
|
|
}
|
|
|
|
// set keterangan & prefix
|
|
if ($rst_piutang_year_min_1 < 1) {
|
|
$keterangan = "-";
|
|
} else {
|
|
if (($rst_piutang_berjalan) > ($rst_piutang_year_min_1)) {
|
|
$keterangan = "up";
|
|
} else {
|
|
if (($rst_piutang_year_min_1) > ($rst_piutang_berjalan)) {
|
|
$keterangan = "down";
|
|
}
|
|
}
|
|
}
|
|
|
|
$total_piutang_fix = "Rp. " . $formatted_number;
|
|
|
|
$result = array(
|
|
"total" => $total_piutang_fix,
|
|
"persen" => $diff_persen . " %",
|
|
"keterangan" => $keterangan,
|
|
"last_qry_tahun_berjalan_a" => $last_qry_tahun_berjalan_a,
|
|
"last_qry_tahun_berjalan_b" => $last_qry_tahun_berjalan_b,
|
|
"last_qry_year_min_1_a" => $last_qry_year_min_1_a,
|
|
"last_qry_year_min_1_b" => $last_qry_year_min_1_b
|
|
);
|
|
|
|
if ($debug != "") {
|
|
$result = array(
|
|
"piutang_berjalan" => $rst_piutang_berjalan,
|
|
"piutang_year_min_1" => $rst_piutang_year_min_1,
|
|
"piutang_berjalan_abs" => abs($rst_piutang_berjalan),
|
|
"piutang_year_min_1_abs" => abs($rst_piutang_year_min_1),
|
|
"total_reformat" => $rst_piutang_berjalan,
|
|
"total" => $total_piutang_fix,
|
|
"persen" => $diff_persen . " %",
|
|
"keterangan" => $keterangan,
|
|
"last_qry_tahun_berjalan_a" => $last_qry_tahun_berjalan_a,
|
|
"last_qry_tahun_berjalan_b" => $last_qry_tahun_berjalan_b,
|
|
"last_qry_year_min_1_a" => $last_qry_year_min_1_a,
|
|
"last_qry_year_min_1_b" => $last_qry_year_min_1_b
|
|
);
|
|
|
|
echo "<pre>";
|
|
print_r($result);
|
|
echo "</pre>";
|
|
exit;
|
|
}
|
|
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function reg_total_piutang_bar_chart_no_group_oldv1($debug = "", $debugRegID = "0", $debugfilter_waktu = "")
|
|
{
|
|
$this->corss();
|
|
// total pendapatan nat_sales
|
|
// *) di tambah dengan tahun - 1
|
|
// di berikan diff dalam persen , jika sebelumnya 0 ( belum ada data ) di kasih 100
|
|
|
|
try {
|
|
// if (!$this->isLogin) {
|
|
// $this->sys_error("Invalid Token");
|
|
// exit;
|
|
// }
|
|
|
|
$date_now = date('Y-m-d');
|
|
$filter_waktu = "";
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
$regID = "0";
|
|
|
|
$where_tahun_berjalan = "
|
|
AND `Nat_SalesYear` = YEAR('$date_now')
|
|
AND Nat_SalesIsActive = 'Y'";
|
|
|
|
$where_year_min_1 = "
|
|
AND Nat_PaymentOrderYear = year('$date_now')
|
|
AND Nat_PaymentIsActive = 'Y'";
|
|
|
|
if (isset($prm['filter_scope'])) {
|
|
$regID = ($prm["filter_scope"] == "0" || $prm["filter_scope"] == 0) ? "-" : $prm["filter_scope"];
|
|
}
|
|
|
|
if (isset($prm['filter_waktu'])) {
|
|
$filter_waktu = $prm["filter_waktu"];
|
|
}
|
|
|
|
if ($debugRegID != "0") {
|
|
// $regID = $debugRegID;
|
|
$regID = ($debugRegID == "0" || $debugRegID == 0) ? "-" : $debugRegID;
|
|
}
|
|
|
|
if ($debug != "") {
|
|
$filter_waktu = $debugfilter_waktu;
|
|
if ($filter_waktu != "") {
|
|
if ($filter_waktu != 'YTD') {
|
|
// bukan Year To Date
|
|
|
|
if (strpos($filter_waktu, 'Q') !== false || strpos($filter_waktu, 'q') !== false) {
|
|
$quarterResult = $this->getQuarterByFilter($filter_waktu);
|
|
if ($quarterResult != '-') {
|
|
$where_tahun_berjalan = " AND Nat_SalesQuarter = ($quarterResult)
|
|
AND `Nat_SalesYear` = YEAR('$date_now')";
|
|
$where_year_min_1 = " AND Nat_PaymentOrderQuarter = ($quarterResult)
|
|
AND Nat_PaymentOrderYear = year('$date_now')";
|
|
}
|
|
}
|
|
} else {
|
|
if ($filter_waktu == "YTD") {
|
|
// jika Year To Date
|
|
// klu berjalan, 1 januari 2023 - 4 oktober 2023 ( date now )
|
|
// klu end date year - 1 , 1 januari 2022 - (date now - 1)
|
|
$berjalan_a = date('Y-01-01');
|
|
|
|
$end_date_a = date('Y-01-01', strtotime('-1 year'));
|
|
$end_date_b = date('Y-m-d', strtotime('-1 year'));
|
|
|
|
// berjalan
|
|
// Nat_SalesDay >= '2023-01-01' AND Nat_SalesDay <= '2023-10-04'
|
|
// Nat_SalesYear` = year('$date_now')
|
|
// AND Nat_SalesDay >= '$berjalan_a' AND Nat_SalesDay <= '$date_now'
|
|
$where_tahun_berjalan = " AND Nat_SalesIsActive = 'Y'
|
|
AND `Nat_SalesYear` = year('$date_now')
|
|
AND (`Nat_SalesDay` >= '$berjalan_a' AND `Nat_SalesDay` <= '$date_now')";
|
|
|
|
$where_year_min_1 = " AND Nat_PaymentIsActive = 'Y'
|
|
AND `Nat_PaymentOrderYear` = year('$date_now') - 1
|
|
AND (`Nat_PaymentOrderDay` >= '$end_date_a' AND `Nat_PaymentOrderDay` <= DATE(NOW() - INTERVAL 1 YEAR))
|
|
AND `Nat_PaymentYear` = year('$date_now') - 1
|
|
AND (`Nat_PaymentDay` >= '$end_date_a' AND `Nat_PaymentDay` <= DATE(NOW() - INTERVAL 1 YEAR))
|
|
";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($filter_waktu != "") {
|
|
if ($filter_waktu != 'YTD') {
|
|
// bukan Year To Date
|
|
|
|
if (strpos($filter_waktu, 'Q') !== false || strpos($filter_waktu, 'q') !== false) {
|
|
$quarterResult = $this->getQuarterByFilter($filter_waktu);
|
|
if ($quarterResult != '-') {
|
|
$where_tahun_berjalan = " AND Nat_SalesQuarter = ($quarterResult)
|
|
AND `Nat_SalesYear` = YEAR('$date_now')";
|
|
$where_year_min_1 = " AND Nat_PaymentOrderQuarter = ($quarterResult)
|
|
AND Nat_PaymentOrderYear = year('$date_now')";
|
|
}
|
|
}
|
|
} else {
|
|
if ($filter_waktu == "YTD") {
|
|
// jika Year To Date
|
|
// klu berjalan, 1 januari 2023 - 4 oktober 2023 ( date now )
|
|
// klu end date year - 1 , 1 januari 2022 - (date now - 1)
|
|
$berjalan_a = date('Y-01-01');
|
|
|
|
$end_date_a = date('Y-01-01', strtotime('-1 year'));
|
|
$end_date_b = date('Y-m-d', strtotime('-1 year'));
|
|
|
|
// berjalan
|
|
// Nat_SalesDay >= '2023-01-01' AND Nat_SalesDay <= '2023-10-04'
|
|
// Nat_SalesYear` = year('$date_now')
|
|
// AND Nat_SalesDay >= '$berjalan_a' AND Nat_SalesDay <= '$date_now'
|
|
$where_tahun_berjalan = " AND Nat_SalesIsActive = 'Y'
|
|
AND `Nat_SalesYear` = year('$date_now')
|
|
AND (`Nat_SalesDay` >= '$berjalan_a' AND `Nat_SalesDay` <= '$date_now')";
|
|
|
|
$where_year_min_1 = " AND Nat_PaymentIsActive = 'Y'
|
|
AND `Nat_PaymentOrderYear` = year('$date_now') - 1
|
|
AND (`Nat_PaymentOrderDay` >= '$end_date_a' AND `Nat_PaymentOrderDay` <= DATE(NOW() - INTERVAL 1 YEAR))
|
|
AND `Nat_PaymentYear` = year('$date_now') - 1
|
|
AND (`Nat_PaymentDay` >= '$end_date_a' AND `Nat_PaymentDay` <= DATE(NOW() - INTERVAL 1 YEAR))
|
|
";
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
$sql_branch_list = "SELECT M_BranchID, M_BranchName
|
|
from m_branch
|
|
where M_BranchIsActive = 'Y'
|
|
order by M_BranchName ASC";
|
|
$qry_branch_list = $this->db->query($sql_branch_list);
|
|
if (!$qry_branch_list) {
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $this->db->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$last_qry_branch_list = $this->db->last_query();
|
|
$rst_branch_list = $qry_branch_list->result_array();
|
|
|
|
// nat_sales
|
|
$sql_nat_sales = "SELECT ifnull(SUM(`Nat_SalesTotal`), 0) AS a,
|
|
M_BranchID as M_BranchID, M_BranchName as M_BranchName
|
|
FROM `nat_sales`
|
|
JOIN m_branch
|
|
ON Nat_SalesM_BranchID = M_BranchID
|
|
AND M_BranchIsActive = 'Y'
|
|
$where_tahun_berjalan
|
|
JOIN s_regional
|
|
ON M_BranchS_RegionalID = S_RegionalID
|
|
AND S_RegionalIsActive = 'Y'
|
|
AND S_RegionalID = $regID
|
|
GROUP BY M_BranchID
|
|
ORDER BY M_BranchName ASC";
|
|
|
|
$qry_nat_sales = $this->db->query($sql_nat_sales);
|
|
if (!$qry_nat_sales) {
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $this->db->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$last_qry_nat_sales = $this->db->last_query();
|
|
$rst_nat_sales = $qry_nat_sales->result_array();
|
|
|
|
// nat_payment
|
|
$sql_nat_payment = "SELECT ifnull(SUM(Nat_PaymentTotal),0) AS b,
|
|
M_BranchID as M_BranchID, M_BranchName as M_BranchName
|
|
FROM nat_payment
|
|
JOIN m_branch
|
|
ON Nat_PaymentM_BranchID = M_BranchID
|
|
AND M_BranchIsActive = 'Y'
|
|
$where_year_min_1
|
|
JOIN s_regional
|
|
ON M_BranchS_RegionalID = S_RegionalID
|
|
AND S_RegionalIsActive = 'Y'
|
|
AND S_RegionalID = $regID
|
|
GROUP BY M_BranchID
|
|
ORDER BY M_BranchName ASC";
|
|
|
|
$qry_nat_payment = $this->db->query($sql_nat_payment);
|
|
if (!$qry_nat_payment) {
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $this->db->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$last_qry_nat_payment = $this->db->last_query();
|
|
$rst_nat_payment = $qry_nat_payment->result_array();
|
|
|
|
$list_scope = [];
|
|
$value_of_scope = [];
|
|
$result = [];
|
|
$list_color = [];
|
|
$hasil_tmp = [];
|
|
|
|
// klu nat_sales tidak kosong di push
|
|
if (count($rst_nat_sales) > 0) {
|
|
foreach ($rst_nat_sales as $key => $value) {
|
|
$hasil_tmp[] = [
|
|
"alias" => "a",
|
|
"value" => $value['a'],
|
|
"M_BranchID" => $value['M_BranchID'],
|
|
"M_BranchName" => $value['M_BranchName']
|
|
];
|
|
}
|
|
}
|
|
|
|
// klu nat_payment tidak kosong di push
|
|
if (count($rst_nat_payment) > 0) {
|
|
foreach ($rst_nat_payment as $key => $value) {
|
|
$hasil_tmp[] = [
|
|
"alias" => "b",
|
|
"value" => $value['b'],
|
|
"M_BranchID" => $value['M_BranchID'],
|
|
"M_BranchName" => $value['M_BranchName']
|
|
];
|
|
}
|
|
}
|
|
|
|
// grup M_BranchID dari array hasil_tmp
|
|
$grouped = [];
|
|
foreach ($hasil_tmp as $item) {
|
|
$alias = $item["alias"];
|
|
$M_BranchID = $item["M_BranchID"];
|
|
$value = $item["value"];
|
|
$M_BranchName = $item['M_BranchName'];
|
|
|
|
if (!isset($grouped[$M_BranchID][$alias])) {
|
|
$grouped[$M_BranchID][$alias] = [
|
|
"value" => 0,
|
|
"M_BranchName" => $item["M_BranchName"],
|
|
];
|
|
}
|
|
|
|
// sum group by berdasarkan alias dan regional
|
|
$grouped[$M_BranchID][$alias]["value"] += $value;
|
|
}
|
|
|
|
// hitung selisih a - b
|
|
$hasil_baru = [];
|
|
foreach ($grouped as $M_BranchID => $vx) {
|
|
// klu a & b set
|
|
if (isset($vx["a"]) && isset($vx["b"])) {
|
|
$value = $vx["a"]["value"] - $vx["b"]["value"];
|
|
$hasil_baru[] = [
|
|
"M_BranchID" => $M_BranchID,
|
|
"M_BranchName" => $vx["a"]["M_BranchName"],
|
|
"value" => $value,
|
|
];
|
|
} else {
|
|
// klu b tidak set
|
|
if (isset($vx['a']) && !isset($vx['b'])) {
|
|
$value = $vx["a"]["value"] - 0;
|
|
$hasil_baru[] = [
|
|
"M_BranchID" => $M_BranchID,
|
|
"M_BranchName" => $vx["a"]["M_BranchName"],
|
|
"value" => $value,
|
|
];
|
|
} else {
|
|
$value = 0;
|
|
$hasil_baru[] = [
|
|
"M_BranchID" => $M_BranchID,
|
|
"M_BranchName" => $vx["a"]["M_BranchName"],
|
|
"value" => $value,
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|
|
// check kalau sudah ada value di array hasil_baru maka tidak ditambahkan
|
|
// klu blm ada di tambahkan dengan nilai value 0
|
|
// if (count($rst_branch_list) > 0) {
|
|
// // Buat array asosiatif sementara yang akan digunakan untuk melacak M_BranchID yang sudah ada
|
|
// $existingRegionalIDs = array_column($hasil_baru, 'M_BranchID');
|
|
|
|
// foreach ($rst_branch_list as $key => $value) {
|
|
// // Periksa apakah M_BranchID sudah ada dalam $existingRegionalIDs
|
|
// if (!in_array($value['M_BranchID'], $existingRegionalIDs)) {
|
|
// $hasil_baru[] = [
|
|
// "value" => 0,
|
|
// "M_BranchID" => $value['M_BranchID'],
|
|
// "M_BranchName" => $value['M_BranchName']
|
|
// ];
|
|
|
|
// // Tambahkan M_BranchID baru ke $existingRegionalIDs
|
|
// $existingRegionalIDs[] = $value['M_BranchID'];
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// Ekstrak M_BranchName ke dalam array terpisah untuk pengurutan
|
|
$M_BranchName = array_column($hasil_baru, 'M_BranchName');
|
|
|
|
// Urutkan $hasil_baru berdasarkan M_BranchName
|
|
array_multisort($M_BranchName, SORT_ASC, $hasil_baru);
|
|
|
|
$new_branch_list = [];
|
|
if (count($hasil_baru) > 0) {
|
|
foreach ($hasil_baru as $key => $vx) {
|
|
$new_branch_list[] = $vx['M_BranchName'];
|
|
}
|
|
}
|
|
|
|
$new_list_scope = array_merge($new_branch_list, $list_scope);
|
|
$new_list_scope = array_unique($new_list_scope);
|
|
|
|
// // masukkan ke array value_of_scope yg fix
|
|
if (count($hasil_baru) > 0) {
|
|
foreach ($hasil_baru as $key => $vx) {
|
|
$string_val = $vx['value'];
|
|
$value_of_scope[] = "$string_val";
|
|
// list color
|
|
$list_color[] = $this->list_color_bar_chart($key, count($new_list_scope));
|
|
}
|
|
|
|
// // TESTING COLOR DEFAULT
|
|
// $x1 = [
|
|
// 'Bali Raya',
|
|
// 'Balikpapan Raya',
|
|
// 'Bandung Raya',
|
|
// 'Cirebon Raya',
|
|
// 'Jakarta Raya',
|
|
// 'Madiun Raya',
|
|
// 'Magelang Raya',
|
|
// 'Makassar Raya',
|
|
// 'Manado Raya',
|
|
// 'Medan Raya',
|
|
// 'Padang Raya',
|
|
// 'Palembang Raya',
|
|
// 'Pekanbaru Raya',
|
|
// 'Pontianak Raya',
|
|
// 'Prospek',
|
|
// 'Salatiga Raya',
|
|
// 'Semarang Raya',
|
|
// 'Sima Jember',
|
|
// 'Sima Kediri',
|
|
// 'Sima Malang',
|
|
// 'Surabaya Raya',
|
|
// 'Tasik Raya',
|
|
// 'Tegal Raya',
|
|
// 'Yogyaraya',
|
|
// 'Bali Raya',
|
|
// 'Balikpapan Raya',
|
|
// 'Bandung Raya',
|
|
// 'Cirebon Raya',
|
|
// 'Jakarta Raya',
|
|
// 'Madiun Raya',
|
|
// 'Magelang Raya',
|
|
// 'Makassar Raya',
|
|
// 'Manado Raya',
|
|
// 'Medan Raya',
|
|
// 'Padang Raya',
|
|
// 'Palembang Raya',
|
|
// 'Pekanbaru Raya',
|
|
// 'Pontianak Raya',
|
|
// 'Prospek',
|
|
// 'Salatiga Raya',
|
|
// 'Semarang Raya',
|
|
// 'Sima Jember',
|
|
// 'Sima Kediri',
|
|
// 'Sima Malang',
|
|
// 'Surabaya Raya',
|
|
// 'Tasik Raya',
|
|
// 'Tegal Raya',
|
|
// 'Yogyaraya',
|
|
// ];
|
|
// for ($i = 0; $i < count($x1); $i++) {
|
|
// // $value_of_scope[] = $rst_tahun_berjalan[$i]['total_sales_tahun_berjalan'];
|
|
// // $list_scope[] = $rst_tahun_berjalan[$i]['S_RegionalName'];
|
|
// $list_color[] = $this->list_color_bar_chart($i, count($x1));
|
|
// }
|
|
}
|
|
|
|
$result = array(
|
|
"value_of_scope" => $value_of_scope,
|
|
"list_scope" => $new_list_scope,
|
|
"bar_chart_color" => $list_color,
|
|
"last_qry_nat_sales" => $last_qry_nat_sales,
|
|
"last_qry_nat_payment" => $last_qry_nat_payment,
|
|
"last_qry_branch_list" => $last_qry_branch_list,
|
|
);
|
|
|
|
// $result = array(
|
|
// "value_of_scope" => [],
|
|
// "list_scope" => [],
|
|
// "bar_chart_color" => [],
|
|
// );
|
|
|
|
if ($debug != "") {
|
|
$result = array(
|
|
"rst_nat_sales" => $rst_nat_sales,
|
|
"rst_nat_payment" => $rst_nat_payment,
|
|
"hasil_tmp" => $hasil_tmp,
|
|
"hasil_baru" => $hasil_baru,
|
|
"value_of_scope" => $value_of_scope,
|
|
"list_scope" => $new_list_scope,
|
|
"bar_chart_color" => $list_color,
|
|
"last_qry_nat_sales" => $last_qry_nat_sales,
|
|
"last_qry_nat_payment" => $last_qry_nat_payment,
|
|
"last_qry_branch_list" => $last_qry_branch_list,
|
|
);
|
|
|
|
echo "<pre>";
|
|
print_r($result);
|
|
echo "</pre>";
|
|
exit;
|
|
}
|
|
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function reg_total_piutang_bar_chart_no_group($debug = "", $debugRegID = "0", $debugfilter_waktu = "")
|
|
{
|
|
$this->corss();
|
|
// total pendapatan nat_sales
|
|
// *) di tambah dengan tahun - 1
|
|
// di berikan diff dalam persen , jika sebelumnya 0 ( belum ada data ) di kasih 100
|
|
|
|
try {
|
|
// if (!$this->isLogin) {
|
|
// $this->sys_error("Invalid Token");
|
|
// exit;
|
|
// }
|
|
|
|
$date_now = date('Y-m-d');
|
|
$filter_waktu = "";
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
$regID = "0";
|
|
|
|
$where_tahun_berjalan = "
|
|
AND `Nat_SalesYear` = YEAR('$date_now')
|
|
AND Nat_SalesIsActive = 'Y'";
|
|
|
|
$where_year_min_1 = "
|
|
AND Nat_PaymentOrderYear = year('$date_now')
|
|
AND Nat_PaymentIsActive = 'Y'";
|
|
|
|
if (isset($prm['filter_scope'])) {
|
|
$regID = ($prm["filter_scope"] == "0" || $prm["filter_scope"] == 0) ? "-" : $prm["filter_scope"];
|
|
}
|
|
|
|
if (isset($prm['filter_waktu'])) {
|
|
$filter_waktu = $prm["filter_waktu"];
|
|
}
|
|
|
|
if ($debugRegID != "0") {
|
|
// $regID = $debugRegID;
|
|
$regID = ($debugRegID == "0" || $debugRegID == 0) ? "-" : $debugRegID;
|
|
}
|
|
|
|
if ($debug != "") {
|
|
$filter_waktu = $debugfilter_waktu;
|
|
if ($filter_waktu != "") {
|
|
if ($filter_waktu != 'YTD') {
|
|
// bukan Year To Date
|
|
|
|
if (strpos($filter_waktu, 'Q') !== false || strpos($filter_waktu, 'q') !== false) {
|
|
$quarterResult = $this->getQuarterByFilter($filter_waktu);
|
|
if ($quarterResult != '-') {
|
|
// $where_tahun_berjalan = " AND Nat_SalesQuarter = ($quarterResult)
|
|
// AND `Nat_SalesYear` = YEAR('$date_now')";
|
|
// $where_year_min_1 = " AND Nat_PaymentOrderQuarter = ($quarterResult)
|
|
// AND Nat_PaymentOrderYear = year('$date_now')";
|
|
|
|
$where_tahun_berjalan = "
|
|
AND Nat_SalesIsActive = 'Y'
|
|
AND Nat_SalesQuarter = ($quarterResult)
|
|
AND `Nat_SalesYear` = YEAR('$date_now')
|
|
";
|
|
|
|
|
|
$where_year_min_1 = "
|
|
AND Nat_PaymentIsActive = 'Y'
|
|
AND Nat_PaymentOrderQuarter = ($quarterResult)
|
|
AND Nat_PaymentQuarter = ($quarterResult)
|
|
AND Nat_PaymentOrderYear = year('$date_now')
|
|
AND `Nat_PaymentYear` = year('$date_now')
|
|
";
|
|
}
|
|
}
|
|
} else {
|
|
if ($filter_waktu == "YTD") {
|
|
// jika Year To Date
|
|
// klu berjalan, 1 januari 2023 - 4 oktober 2023 ( date now )
|
|
// klu end date year - 1 , 1 januari 2022 - (date now - 1)
|
|
$berjalan_a = date('Y-01-01');
|
|
|
|
$end_date_a = date('Y-01-01', strtotime('-1 year'));
|
|
$end_date_b = date('Y-m-d', strtotime('-1 year'));
|
|
|
|
// berjalan
|
|
// Nat_SalesDay >= '2023-01-01' AND Nat_SalesDay <= '2023-10-04'
|
|
// Nat_SalesYear` = year('$date_now')
|
|
// AND Nat_SalesDay >= '$berjalan_a' AND Nat_SalesDay <= '$date_now'
|
|
$where_tahun_berjalan = " AND Nat_SalesIsActive = 'Y'
|
|
AND `Nat_SalesYear` = year('$date_now')
|
|
AND (`Nat_SalesDay` >= '$berjalan_a' AND `Nat_SalesDay` <= '$date_now')";
|
|
|
|
$where_year_min_1 = " AND Nat_PaymentIsActive = 'Y'
|
|
AND `Nat_PaymentOrderYear` = year('$date_now')
|
|
AND (`Nat_PaymentOrderDay` >= '$berjalan_a'
|
|
AND `Nat_PaymentOrderDay` <= '$date_now')
|
|
AND `Nat_PaymentYear` = year('$date_now')
|
|
AND (`Nat_PaymentDay` >= '$berjalan_a'
|
|
AND `Nat_PaymentDay` <= <= '$date_now')
|
|
";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($filter_waktu != "") {
|
|
if ($filter_waktu != 'YTD') {
|
|
// bukan Year To Date
|
|
|
|
if (strpos($filter_waktu, 'Q') !== false || strpos($filter_waktu, 'q') !== false) {
|
|
$quarterResult = $this->getQuarterByFilter($filter_waktu);
|
|
if ($quarterResult != '-') {
|
|
$where_tahun_berjalan = "
|
|
AND Nat_SalesIsActive = 'Y'
|
|
AND Nat_SalesQuarter = ($quarterResult)
|
|
AND `Nat_SalesYear` = YEAR('$date_now')
|
|
";
|
|
|
|
|
|
$where_year_min_1 = "
|
|
AND Nat_PaymentIsActive = 'Y'
|
|
AND Nat_PaymentOrderQuarter = ($quarterResult)
|
|
AND Nat_PaymentQuarter = ($quarterResult)
|
|
AND Nat_PaymentOrderYear = year('$date_now')
|
|
AND `Nat_PaymentYear` = year('$date_now')
|
|
";
|
|
}
|
|
}
|
|
} else {
|
|
if ($filter_waktu == "YTD") {
|
|
// jika Year To Date
|
|
// klu berjalan, 1 januari 2023 - 4 oktober 2023 ( date now )
|
|
// klu end date year - 1 , 1 januari 2022 - (date now - 1)
|
|
$berjalan_a = date('Y-01-01');
|
|
|
|
$end_date_a = date('Y-01-01', strtotime('-1 year'));
|
|
$end_date_b = date('Y-m-d', strtotime('-1 year'));
|
|
|
|
// berjalan
|
|
// Nat_SalesDay >= '2023-01-01' AND Nat_SalesDay <= '2023-10-04'
|
|
// Nat_SalesYear` = year('$date_now')
|
|
// AND Nat_SalesDay >= '$berjalan_a' AND Nat_SalesDay <= '$date_now'
|
|
$where_tahun_berjalan = " AND Nat_SalesIsActive = 'Y'
|
|
AND `Nat_SalesYear` = year('$date_now')
|
|
AND (`Nat_SalesDay` >= '$berjalan_a'
|
|
AND `Nat_SalesDay` <= '$date_now')
|
|
";
|
|
|
|
$where_year_min_1 = " AND Nat_PaymentIsActive = 'Y'
|
|
AND `Nat_PaymentOrderYear` = year('$date_now')
|
|
AND (`Nat_PaymentOrderDay` >= '$berjalan_a'
|
|
AND `Nat_PaymentOrderDay` <= '$date_now')
|
|
AND `Nat_PaymentYear` = year('$date_now')
|
|
AND (`Nat_PaymentDay` >= '$berjalan_a'
|
|
AND `Nat_PaymentDay` <= '$date_now')
|
|
";
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
$sql_branch_list = "SELECT M_BranchID, M_BranchName
|
|
from m_branch
|
|
where M_BranchIsActive = 'Y'
|
|
order by M_BranchName ASC";
|
|
$qry_branch_list = $this->db->query($sql_branch_list);
|
|
if (!$qry_branch_list) {
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $this->db->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$last_qry_branch_list = $this->db->last_query();
|
|
$rst_branch_list = $qry_branch_list->result_array();
|
|
|
|
// nat_sales
|
|
$sql_nat_sales = "SELECT ifnull(SUM(`Nat_SalesTotal`), 0) AS a,
|
|
M_BranchID as M_BranchID, M_BranchName as M_BranchName
|
|
FROM `nat_sales`
|
|
JOIN m_branch
|
|
ON Nat_SalesM_BranchID = M_BranchID
|
|
AND M_BranchIsActive = 'Y'
|
|
$where_tahun_berjalan
|
|
JOIN s_regional
|
|
ON M_BranchS_RegionalID = S_RegionalID
|
|
AND S_RegionalIsActive = 'Y'
|
|
AND S_RegionalID = $regID
|
|
GROUP BY M_BranchID
|
|
ORDER BY M_BranchName ASC";
|
|
|
|
$qry_nat_sales = $this->db->query($sql_nat_sales);
|
|
if (!$qry_nat_sales) {
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $this->db->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$last_qry_nat_sales = $this->db->last_query();
|
|
$rst_nat_sales = $qry_nat_sales->result_array();
|
|
|
|
// nat_payment
|
|
$sql_nat_payment = "SELECT ifnull(SUM(Nat_PaymentTotal),0) AS b,
|
|
M_BranchID as M_BranchID, M_BranchName as M_BranchName
|
|
FROM nat_payment
|
|
JOIN m_branch
|
|
ON Nat_PaymentM_BranchID = M_BranchID
|
|
AND M_BranchIsActive = 'Y'
|
|
$where_year_min_1
|
|
JOIN s_regional
|
|
ON M_BranchS_RegionalID = S_RegionalID
|
|
AND S_RegionalIsActive = 'Y'
|
|
AND S_RegionalID = $regID
|
|
GROUP BY M_BranchID
|
|
ORDER BY M_BranchName ASC";
|
|
|
|
$qry_nat_payment = $this->db->query($sql_nat_payment);
|
|
if (!$qry_nat_payment) {
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $this->db->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$last_qry_nat_payment = $this->db->last_query();
|
|
$rst_nat_payment = $qry_nat_payment->result_array();
|
|
|
|
$list_scope = [];
|
|
$value_of_scope = [];
|
|
$result = [];
|
|
$list_color = [];
|
|
$hasil_tmp = [];
|
|
|
|
// klu nat_sales tidak kosong di push
|
|
if (count($rst_nat_sales) > 0) {
|
|
foreach ($rst_nat_sales as $key => $value) {
|
|
$hasil_tmp[] = [
|
|
"alias" => "a",
|
|
"value" => $value['a'],
|
|
"M_BranchID" => $value['M_BranchID'],
|
|
"M_BranchName" => $value['M_BranchName']
|
|
];
|
|
}
|
|
}
|
|
|
|
// klu nat_payment tidak kosong di push
|
|
if (count($rst_nat_payment) > 0) {
|
|
foreach ($rst_nat_payment as $key => $value) {
|
|
$hasil_tmp[] = [
|
|
"alias" => "b",
|
|
"value" => $value['b'],
|
|
"M_BranchID" => $value['M_BranchID'],
|
|
"M_BranchName" => $value['M_BranchName']
|
|
];
|
|
}
|
|
}
|
|
|
|
// grup M_BranchID dari array hasil_tmp
|
|
$grouped = [];
|
|
foreach ($hasil_tmp as $item) {
|
|
$alias = $item["alias"];
|
|
$M_BranchID = $item["M_BranchID"];
|
|
$value = $item["value"];
|
|
$M_BranchName = $item['M_BranchName'];
|
|
|
|
if (!isset($grouped[$M_BranchID][$alias])) {
|
|
$grouped[$M_BranchID][$alias] = [
|
|
"value" => 0,
|
|
"M_BranchName" => $item["M_BranchName"],
|
|
];
|
|
}
|
|
|
|
// sum group by berdasarkan alias dan regional
|
|
$grouped[$M_BranchID][$alias]["value"] += $value;
|
|
}
|
|
|
|
// hitung selisih a - b
|
|
$hasil_baru = [];
|
|
foreach ($grouped as $M_BranchID => $vx) {
|
|
// klu a & b set
|
|
if (isset($vx["a"]) && isset($vx["b"])) {
|
|
$value = $vx["a"]["value"] - $vx["b"]["value"];
|
|
$hasil_baru[] = [
|
|
"M_BranchID" => $M_BranchID,
|
|
"M_BranchName" => $vx["a"]["M_BranchName"],
|
|
"value" => $value,
|
|
];
|
|
} else {
|
|
// klu b tidak set
|
|
if (isset($vx['a']) && !isset($vx['b'])) {
|
|
$value = $vx["a"]["value"] - 0;
|
|
$hasil_baru[] = [
|
|
"M_BranchID" => $M_BranchID,
|
|
"M_BranchName" => $vx["a"]["M_BranchName"],
|
|
"value" => $value,
|
|
];
|
|
} else {
|
|
$value = 0;
|
|
$hasil_baru[] = [
|
|
"M_BranchID" => $M_BranchID,
|
|
"M_BranchName" => $vx["a"]["M_BranchName"],
|
|
"value" => $value,
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|
|
// check kalau sudah ada value di array hasil_baru maka tidak ditambahkan
|
|
// klu blm ada di tambahkan dengan nilai value 0
|
|
// if (count($rst_branch_list) > 0) {
|
|
// // Buat array asosiatif sementara yang akan digunakan untuk melacak M_BranchID yang sudah ada
|
|
// $existingRegionalIDs = array_column($hasil_baru, 'M_BranchID');
|
|
|
|
// foreach ($rst_branch_list as $key => $value) {
|
|
// // Periksa apakah M_BranchID sudah ada dalam $existingRegionalIDs
|
|
// if (!in_array($value['M_BranchID'], $existingRegionalIDs)) {
|
|
// $hasil_baru[] = [
|
|
// "value" => 0,
|
|
// "M_BranchID" => $value['M_BranchID'],
|
|
// "M_BranchName" => $value['M_BranchName']
|
|
// ];
|
|
|
|
// // Tambahkan M_BranchID baru ke $existingRegionalIDs
|
|
// $existingRegionalIDs[] = $value['M_BranchID'];
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// Ekstrak M_BranchName ke dalam array terpisah untuk pengurutan
|
|
$M_BranchName = array_column($hasil_baru, 'M_BranchName');
|
|
|
|
// Urutkan $hasil_baru berdasarkan M_BranchName
|
|
array_multisort($M_BranchName, SORT_ASC, $hasil_baru);
|
|
|
|
$new_branch_list = [];
|
|
if (count($hasil_baru) > 0) {
|
|
foreach ($hasil_baru as $key => $vx) {
|
|
$new_branch_list[] = $vx['M_BranchName'];
|
|
}
|
|
}
|
|
|
|
$new_list_scope = array_merge($new_branch_list, $list_scope);
|
|
$new_list_scope = array_unique($new_list_scope);
|
|
|
|
// // masukkan ke array value_of_scope yg fix
|
|
if (count($hasil_baru) > 0) {
|
|
foreach ($hasil_baru as $key => $vx) {
|
|
$string_val = $vx['value'];
|
|
$value_of_scope[] = "$string_val";
|
|
// list color
|
|
$list_color[] = $this->list_color_bar_chart($key, count($new_list_scope));
|
|
}
|
|
|
|
// // TESTING COLOR DEFAULT
|
|
// $x1 = [
|
|
// 'Bali Raya',
|
|
// 'Balikpapan Raya',
|
|
// 'Bandung Raya',
|
|
// 'Cirebon Raya',
|
|
// 'Jakarta Raya',
|
|
// 'Madiun Raya',
|
|
// 'Magelang Raya',
|
|
// 'Makassar Raya',
|
|
// 'Manado Raya',
|
|
// 'Medan Raya',
|
|
// 'Padang Raya',
|
|
// 'Palembang Raya',
|
|
// 'Pekanbaru Raya',
|
|
// 'Pontianak Raya',
|
|
// 'Prospek',
|
|
// 'Salatiga Raya',
|
|
// 'Semarang Raya',
|
|
// 'Sima Jember',
|
|
// 'Sima Kediri',
|
|
// 'Sima Malang',
|
|
// 'Surabaya Raya',
|
|
// 'Tasik Raya',
|
|
// 'Tegal Raya',
|
|
// 'Yogyaraya',
|
|
// 'Bali Raya',
|
|
// 'Balikpapan Raya',
|
|
// 'Bandung Raya',
|
|
// 'Cirebon Raya',
|
|
// 'Jakarta Raya',
|
|
// 'Madiun Raya',
|
|
// 'Magelang Raya',
|
|
// 'Makassar Raya',
|
|
// 'Manado Raya',
|
|
// 'Medan Raya',
|
|
// 'Padang Raya',
|
|
// 'Palembang Raya',
|
|
// 'Pekanbaru Raya',
|
|
// 'Pontianak Raya',
|
|
// 'Prospek',
|
|
// 'Salatiga Raya',
|
|
// 'Semarang Raya',
|
|
// 'Sima Jember',
|
|
// 'Sima Kediri',
|
|
// 'Sima Malang',
|
|
// 'Surabaya Raya',
|
|
// 'Tasik Raya',
|
|
// 'Tegal Raya',
|
|
// 'Yogyaraya',
|
|
// ];
|
|
// for ($i = 0; $i < count($x1); $i++) {
|
|
// // $value_of_scope[] = $rst_tahun_berjalan[$i]['total_sales_tahun_berjalan'];
|
|
// // $list_scope[] = $rst_tahun_berjalan[$i]['S_RegionalName'];
|
|
// $list_color[] = $this->list_color_bar_chart($i, count($x1));
|
|
// }
|
|
}
|
|
|
|
$result = array(
|
|
"value_of_scope" => $value_of_scope,
|
|
"list_scope" => $new_list_scope,
|
|
"bar_chart_color" => $list_color,
|
|
"last_qry_nat_sales" => $last_qry_nat_sales,
|
|
"last_qry_nat_payment" => $last_qry_nat_payment,
|
|
"last_qry_branch_list" => $last_qry_branch_list,
|
|
);
|
|
|
|
// $result = array(
|
|
// "value_of_scope" => [],
|
|
// "list_scope" => [],
|
|
// "bar_chart_color" => [],
|
|
// );
|
|
|
|
if ($debug != "") {
|
|
$result = array(
|
|
"rst_nat_sales" => $rst_nat_sales,
|
|
"rst_nat_payment" => $rst_nat_payment,
|
|
"hasil_tmp" => $hasil_tmp,
|
|
"hasil_baru" => $hasil_baru,
|
|
"value_of_scope" => $value_of_scope,
|
|
"list_scope" => $new_list_scope,
|
|
"bar_chart_color" => $list_color,
|
|
"last_qry_nat_sales" => $last_qry_nat_sales,
|
|
"last_qry_nat_payment" => $last_qry_nat_payment,
|
|
"last_qry_branch_list" => $last_qry_branch_list,
|
|
);
|
|
|
|
echo "<pre>";
|
|
print_r($result);
|
|
echo "</pre>";
|
|
exit;
|
|
}
|
|
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
// regional end
|
|
}
|