Initial import
This commit is contained in:
171
application/controllers/fix/Sspiutang.php
Normal file
171
application/controllers/fix/Sspiutang.php
Normal file
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
class Sspiutang extends CI_Controller
|
||||
{
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
$this->db = $this->load->database("onedev", true);
|
||||
}
|
||||
function index() {
|
||||
echo "Fix Rujukan";
|
||||
}
|
||||
function check($sdate,$edate) {
|
||||
$sql = "select
|
||||
SsPiutangType,
|
||||
T_OrderHeaderLabNumber,
|
||||
fn_get_name(T_OrderHeaderM_PatientID) PatientName,
|
||||
SsPiutangID, SsPiutangDate, SsPiutangT_OrderHeaderID,
|
||||
cast(SsPiutangTotal as decimal(15,0)) as SsPiutangTotal ,
|
||||
cast( sum(SsPiutangTestTotal) as decimal(15,0) ) as SumSsPiutangTestTotal
|
||||
from ss_piutang
|
||||
join ss_piutang_test
|
||||
on SsPiutangID = SsPiutangTestSsPiutangID
|
||||
join t_orderheader on SsPiutangT_OrderHeaderID = T_OrderHeaderID
|
||||
where
|
||||
ssPiutangDate >= ? and SsPiutangDate <= ?
|
||||
and SsPiutangIsActive = 'Y'
|
||||
and SsPiutangType in ('A1','A2','A3')
|
||||
and T_OrderHeaderIsActive = 'Y'
|
||||
group by SsPiutangID,SsPiutangT_OrderHeaderID
|
||||
having SsPiutangTotal <> SumSsPiutangTestTotal
|
||||
and SumSsPiutangTestTotal > 0
|
||||
";
|
||||
$qry = $this->db->query($sql,array($sdate,$edate));
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
foreach($rows as $r) {
|
||||
$orderheaderID = $r["SsPiutangT_OrderHeaderID"];
|
||||
$ssPiutangID = $r["SsPiutangID"];
|
||||
$noreg = $r["T_OrderHeaderLabNumber"];
|
||||
$name = $r["PatientName"];
|
||||
$tgl = $r["SsPiutangDate"];
|
||||
$piutangTotal = $r["SsPiutangTotal"];
|
||||
$testTotal = $r["SumSsPiutangTestTotal"];
|
||||
|
||||
$sql = "select
|
||||
T_OrderDetailT_TestName,T_OrderDetailT_TestID,
|
||||
T_OrderDetailT_TestIsPrice, T_OrderDetailPrice,
|
||||
T_OrderDetailDiscTotal, T_OrderDetailTotal
|
||||
from
|
||||
t_orderdetail
|
||||
where T_OrderDetailT_OrderHeaderID = ?
|
||||
and T_OrderDetailIsActive = 'Y'
|
||||
and T_OrderDetailPrice > 0
|
||||
and T_OrderDetailT_TestID not in (
|
||||
select SsPiutangTestT_TestID
|
||||
from ss_piutang_test
|
||||
where SsPiutangTestSsPiutangID = ?
|
||||
)";
|
||||
$qry = $this->db->query($sql,array($orderheaderID, $ssPiutangID));
|
||||
echo "\n============\n";
|
||||
echo "$tgl \t $noreg \t $name \t\t $piutangTotal\n";
|
||||
echo " \t \t piutang_test \t\t $testTotal\n";
|
||||
if ($qry) {
|
||||
$drows = $qry->result_array();
|
||||
foreach($drows as $dr) {
|
||||
$test = $dr["T_OrderDetailT_TestName"];
|
||||
$total = $dr["T_OrderDetailTotal"];
|
||||
echo " \t \t $test \t\t $total\n";
|
||||
$testTotal += $total;
|
||||
}
|
||||
echo " \t \t Sum \t\t $testTotal\n";
|
||||
} else {
|
||||
$date = date("Y-m-d H:i:s");
|
||||
$msg = print_r($this->db->error(),true);
|
||||
echo "$date err : $msg \n";
|
||||
}
|
||||
echo "-----------\n";
|
||||
}
|
||||
} else {
|
||||
$date = date("Y-m-d H:i:s");
|
||||
$msg = print_r($this->db->error(),true);
|
||||
echo "$date err : $msg \n";
|
||||
}
|
||||
}
|
||||
function fix($sdate,$edate) {
|
||||
$sql = "select
|
||||
SsPiutangType,
|
||||
T_OrderHeaderLabNumber,
|
||||
fn_get_name(T_OrderHeaderM_PatientID) PatientName,
|
||||
SsPiutangID, SsPiutangDate, SsPiutangT_OrderHeaderID,
|
||||
cast(SsPiutangTotal as decimal(15,0)) as SsPiutangTotal ,
|
||||
cast( sum(SsPiutangTestTotal) as decimal(15,0) ) as SumSsPiutangTestTotal
|
||||
from ss_piutang
|
||||
join ss_piutang_test
|
||||
on SsPiutangID = SsPiutangTestSsPiutangID
|
||||
join t_orderheader on SsPiutangT_OrderHeaderID = T_OrderHeaderID
|
||||
where
|
||||
ssPiutangDate >= ? and SsPiutangDate <= ?
|
||||
and SsPiutangIsActive = 'Y'
|
||||
and SsPiutangType in ('A1','A2','A3')
|
||||
and T_OrderHeaderIsActive = 'Y'
|
||||
group by SsPiutangID,SsPiutangT_OrderHeaderID
|
||||
having SsPiutangTotal <> SumSsPiutangTestTotal
|
||||
and SumSsPiutangTestTotal > 0
|
||||
";
|
||||
$qry = $this->db->query($sql,array($sdate,$edate));
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
foreach($rows as $r) {
|
||||
$orderheaderID = $r["SsPiutangT_OrderHeaderID"];
|
||||
$ssPiutangID = $r["SsPiutangID"];
|
||||
$noreg = $r["T_OrderHeaderLabNumber"];
|
||||
$name = $r["PatientName"];
|
||||
$tgl = $r["SsPiutangDate"];
|
||||
$piutangTotal = $r["SsPiutangTotal"];
|
||||
$testTotal = $r["SumSsPiutangTestTotal"];
|
||||
|
||||
$sql = "select
|
||||
T_OrderDetailT_TestName,T_OrderDetailT_TestID,
|
||||
T_OrderDetailT_TestIsPrice, T_OrderDetailPrice,
|
||||
T_OrderDetailDiscTotal, T_OrderDetailTotal
|
||||
from
|
||||
t_orderdetail
|
||||
where T_OrderDetailT_OrderHeaderID = ?
|
||||
and T_OrderDetailIsActive = 'Y'
|
||||
and T_OrderDetailPrice > 0
|
||||
and T_OrderDetailT_TestID not in (
|
||||
select SsPiutangTestT_TestID
|
||||
from ss_piutang_test
|
||||
where SsPiutangTestSsPiutangID = ?
|
||||
)";
|
||||
$qry = $this->db->query($sql,array($orderheaderID, $ssPiutangID));
|
||||
echo "\n============\n";
|
||||
echo "$tgl \t $noreg \t $name \t\t $piutangTotal\n";
|
||||
echo " \t \t piutang_test \t\t $testTotal\n";
|
||||
if ($qry) {
|
||||
$drows = $qry->result_array();
|
||||
foreach($drows as $dr) {
|
||||
$test = $dr["T_OrderDetailT_TestName"];
|
||||
$total = $dr["T_OrderDetailTotal"];
|
||||
echo " \t \t $test \t\t $total\n";
|
||||
$testTotal += $total;
|
||||
$sql = "insert into ss_piutang_test(SsPiutangTestSsPiutangID,
|
||||
SsPiutangTestT_TestID, SsPiutangTestPrice, SsPiutangTestDiscTotal,
|
||||
SsPiutangTestTotal)
|
||||
values(?, ?,?,?, ?)";
|
||||
$testID = $dr["T_OrderDetailT_TestID"];
|
||||
$r_price = $dr["T_OrderDetailPrice"];
|
||||
$r_disc = $dr["T_OrderDetailDiscTotal"];
|
||||
$r_total = $dr["T_OrderDetailTotal"];
|
||||
$iqry = $this->db->query($sql, array($ssPiutangID, $testID, $r_price, $r_disc, $r_total));
|
||||
if (!$iqry) {
|
||||
$date = date("Y-m-d H:i:s");
|
||||
$msg = print_r($this->db->error(),true);
|
||||
echo "$date err : $msg \n";
|
||||
}
|
||||
}
|
||||
echo " \t \t Sum \t\t $testTotal\n";
|
||||
} else {
|
||||
$date = date("Y-m-d H:i:s");
|
||||
$msg = print_r($this->db->error(),true);
|
||||
echo "$date err : $msg \n";
|
||||
}
|
||||
echo "-----------\n";
|
||||
}
|
||||
} else {
|
||||
$date = date("Y-m-d H:i:s");
|
||||
$msg = print_r($this->db->error(),true);
|
||||
echo "$date err : $msg \n";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user