Files
BE_CPONE/application/controllers/fix/keu/Ss_piutang.php
2026-04-27 10:26:26 +07:00

89 lines
2.8 KiB
PHP

<?php
class Ss_Piutang extends MY_Controller {
function __construct()
{
parent::__construct();
}
function now() {
return date("Y-m-d H:i:s");
}
function b1($start,$end) {
$this->db->trans_begin();
$sql = "select
SsPiutangID
from
ss_piutang
left join order_px
on SsPiutangT_OrderHeaderID = OrderPxT_OrderHeaderID
where
SsPiutangType = 'B1'
and SsPiutangIsActive = 'Y'
and OrderPxT_OrderHeaderID is null
and SsPiutangDate >= ?
and SsPiutangDate <= ?";
$qry = $this->db->query($sql, array($start,$end));
if(!$qry) {
echo "{$this->now()} ERR Get B1 : | {$this->db->error()['message']} |\n" . $this->db->last_query() . "\n";
exit;
}
$rows = $qry->result_array();
$s_ids = "";
foreach($rows as $r) {
if ($s_ids != "") $s_ids .= ",";
$s_ids .= $r["SsPiutangID"];
}
if ($s_ids == "") {
echo "{$this->now()} No B1 record\n";
$this->db->trans_rollback();
exit;
}
//ss_piutang
$sql = "update ss_piutang set SsPiutangIsActive = 'N' where SsPiutangID in ($s_ids) ";
$qry = $this->db->query($sql);
if(!$qry) {
echo "{$this->now()} ERR Update Ss_Piutang : " . $this->db->last_query() . "\n";
$this->db->trans_rollback();
exit;
}
echo "SS Piutang : Non Active-kan {$this->db->affected_rows()} \n";
//ss_piutang_packet
$sql = "delete from ss_piutang_packet where SsPiutangPacketSsPiutangID in ($s_ids)";
$qry = $this->db->query($sql);
if(!$qry) {
echo "{$this->now()} ERR Delete Ss_Piutang_Packet : " . $this->db->last_query() . "\n";
$this->db->trans_rollback();
exit;
}
echo "{$this->now()} SS Piutang Packet : deleted {$this->db->affected_rows()} \n";
//ss_piutang_payment
$sql = "update ss_piutang_payment set SsPiutangPaymentIsActive='N' where SsPiutangPaymentSsPiutangID in ($s_ids)";
$qry = $this->db->query($sql);
if(!$qry) {
echo "{$this->now()} ERR Update Ss_Piutang_Payment : " . $this->db->last_query() . "\n";
$this->db->trans_rollback();
exit;
}
echo "{$this->now()} SS Piutang Payment : updated {$this->db->affected_rows()} \n";
//ss_piutang_test
$sql = "delete from ss_piutang_payment where SsPiutangPaymentSsPiutangID in ($s_ids)";
$qry = $this->db->query($sql);
if(!$qry) {
echo "{$this->now()} ERR Delete Ss_Piutang_Payment : " . $this->db->last_query() . "\n";
$this->db->trans_rollback();
exit;
}
echo "{$this->now()} SS Piutang Payment : deleted {$this->db->affected_rows()} \n";
$this->db->trans_commit();
}
}