Files
shopee-apps/application/delete/controllers/ManageDpPenjualan.php
T
2026-06-13 16:02:07 +10:00

234 lines
7.5 KiB
PHP

<?php
use Restserver\Libraries\REST_Controller;
defined('BASEPATH') or exit('No direct script access allowed');
require APPPATH . 'libraries/REST_Controller.php';
require APPPATH . 'libraries/Format.php';
class ManageDpPenjualan extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->model('ModelDpPenjualan', 'DpPenjualan');
$this->load->model('ModelPiutangDagang', 'Pda');
$this->load->library(['datatables', 'form_validation']);
$this->form_validation->set_error_delimiters('', '');
}
public function output_json($data, $encode = true)
{
if ($encode) $data = json_encode($data);
$this->output->set_content_type('application/json')->set_output($data);
}
public function index()
{
$dppenjualan = $this->DpPenjualan->getDataDpPenjualan();
$pda = $this->Pda->getDataPiutangDagangDetail();
$data = [
'sidebar' => "menu accounting",
'navChild' => "",
'dppenjualan' => $dppenjualan,
'pda' => $pda
];
$this->load->view('proses/DpPenjualan', $data);
}
//Step Two, Input Transaksi
public function tambahTransaksi($id) {
$transaksi = $this->DpPenjualan->getDataDetailDpPenjualan($id);
$title = $this->DpPenjualan->getTitleDPJ($id);
$id_pelanggan = $this->Pda->getDataDPJ($id);
$id_pelanggan = $id_pelanggan[0]['PELANGGAN_ID'];
$pda = $this->Pda->getDataPiutangDagangDPJ($id_pelanggan);
$data = [
'sidebar' => "menu accounting",
'navChild' => "",
'transaksi' => $transaksi,
'id_dpj' => $id,
'title1' => $title[0]['KODE_DPJ'],
'title2' => $title[0]['DEBIT'],
'title3' => $title[0]['KREDIT'],
'pda' => $pda
];
$this->load->view('proses/DetailDpPenjualan', $data);
}
public function kodeDetailDPJ() {
$kk = $this->DpPenjualan->getKodeDetailDPJ();
if (is_array($kk) || is_object($kk)) {
foreach ($kk as $row) {
if ($row['KODE'] == null) {
return "DDPJ/000001";
} else {
$str = (string) $row['KODE'];
$panjang = 6;
$data = substr($str, 5, $panjang);
$ko = (int) $data + 1;
$str = (string) $ko;
$panjang = 11 - strlen($str);
$data = "DDPJ/000000";
$data = substr($data, 0, $panjang) . $str;
return $data;
}
}
}
}
public function kodeDetailPDA() {
$kk = $this->DpPenjualan->getKodeDetailPDA();
if (is_array($kk) || is_object($kk)) {
foreach ($kk as $row) {
if ($row['KODE'] == null) {
return "DPDA/000001";
} else {
$str = (string) $row['KODE'];
$panjang = 6;
$data = substr($str, 5, $panjang);
$ko = (int) $data + 1;
$str = (string) $ko;
$panjang = 11 - strlen($str);
$data = "DPDA/000000";
$data = substr($data, 0, $panjang) . $str;
return $data;
}
}
}
}
public function savetransaksi() {
//Step Input Transaksi
$method = $this->input->post('method');
$id_ddpj = $this->input->post('id');
$id_dpj = $this->input->post('id_dpj');
$id_pda = $this->input->post('id_pda');
$kredit_ddpj = $this->input->post('kredit_ddpj');
$kode_ddpj = $this->kodeDetailDPJ();
$kode_dpda = $this->kodeDetailPDA();
$datadpj = $this->DpPenjualan->getDataDpPenjualan($id_dpj);
$nominal_dpj = $datadpj[0]['NOMINAL_DPJ'];
$blockcon_dpj = $datadpj[0]['BLOCKCON'];
$id_pelanggan = $datadpj[0]['PELANGGAN_ID'];
$sisa1 = $nominal_dpj-$blockcon_dpj;
$datapda = $this->DpPenjualan->getDataPiutangDagang($id_pda);
$nominal_pda = $datapda[0]['NOMINAL_PDA'];
$blockcon_pda = $datapda[0]['BLOCKCON'];
$sisa2 = $nominal_pda-$blockcon_pda;
if ($sisa1<$kredit_ddpj) {
$this->session->set_flashdata('flashdpj', 'ditambah');
redirect($_SERVER['HTTP_REFERER']);
}
if ($sisa2<$kredit_ddpj) {
$this->session->set_flashdata('flashpda', 'ditambah');
redirect($_SERVER['HTTP_REFERER']);
}
$input = [
'DPJ_ID' => $id_dpj,
'PDA_ID' => $id_pda,
'KREDIT_DDPJ' => $kredit_ddpj,
'KODE_DDPJ' => $kode_ddpj
];
$action = $this->DpPenjualan->create('detail_dpj', $input);
$input = [
'KODE_BUKTI' => $kode_ddpj,
'PDA_ID' => $id_pda,
'KREDIT_DPDA' => $kredit_ddpj,
'KODE_DPDA' => $kode_dpda
];
$action = $this->DpPenjualan->create('detail_pda', $input);
//Step Ambil Data Lama
$id_ddpj = $this->DpPenjualan->getIDDDPJ();
$id_dpda = $this->DpPenjualan->getIDDPDA();
$datadpj = $this->DpPenjualan->getDataDPJ($id_ddpj[0]['ID_DDPJ']);
$blockcon_dpj = $datadpj[0]['BLOCKCON'];
$blockcon_dpj = $blockcon_dpj+$kredit_ddpj;
$datapda = $this->DpPenjualan->getDataPDA($id_dpda[0]['ID_DPDA']);
$blockcon_pda = $datapda[0]['BLOCKCON'];
$blockcon_pda = $blockcon_pda+$kredit_ddpj;
$datapelanggan = $this->DpPenjualan->getDataPelanggan($id_pelanggan);
$saldo_pelanggan = $datapelanggan[0]['SALDO_PELANGGAN'];
$hutang_pelanggan = $datapelanggan[0]['HUTANG_PELANGGAN'];
$saldo_pelanggan = $saldo_pelanggan-$kredit_ddpj;
$hutang_pelanggan = $hutang_pelanggan-$kredit_ddpj;
$update = [
'BLOCKCON' => $blockcon_dpj
];
$action = $this->DpPenjualan->update('dp_penjualan', $update, 'ID_DPJ', $id_dpj);
$update = [
'BLOCKCON' => $blockcon_pda
];
$action = $this->DpPenjualan->update('piutang_dagang', $update, 'ID_PDA', $id_pda);
$update = [
'HUTANG_PELANGGAN' => $hutang_pelanggan,
'SALDO_PELANGGAN' => $saldo_pelanggan
];
$action = $this->DpPenjualan->update('pelanggan', $update, 'ID_PELANGGAN', $id_pelanggan);
if ($action) {
$this->session->set_flashdata('flash', 'ditambah');
redirect($_SERVER['HTTP_REFERER']);
} else {
$this->session->set_flashdata('flashgagal', 'ditambah');
redirect($_SERVER['HTTP_REFERER']);
}
}
public function resetdpj() {
$id = $this->input->post('id');
//Step Reset Saldo Data Blockcon di DPJ dan PDA
$dataddpj = $this->DpPenjualan->getDataDDPJ($id);
$id_dpj = $dataddpj[0]['DPJ_ID'];
$id_pda = $dataddpj[0]['PDA_ID'];
$kredit_ddpj = $dataddpj[0]['KREDIT_DDPJ'];
$kode_ddpj = $dataddpj[0]['KODE_DDPJ'];
$datadpj = $this->DpPenjualan->getDpPenjualan($id_dpj);
$id_pelanggan = $datadpj[0]['PELANGGAN_ID'];
$blockcon_dpj = $datadpj[0]['BLOCKCON'];
$blockcon_dpj = $blockcon_dpj-$kredit_ddpj;
$datapda = $this->DpPenjualan->getDataPiutangDagang($id_pda);
$blockcon_pda = $datapda[0]['BLOCKCON'];
$blockcon_pda = $blockcon_pda-$kredit_ddpj;
$datapelanggan = $this->DpPenjualan->getDataPelanggan($id_pelanggan);
$hutang_pelanggan = $datapelanggan[0]['HUTANG_PELANGGAN'];
$saldo_pelanggan = $datapelanggan[0]['SALDO_PELANGGAN'];
$hutang_pelanggan = $hutang_pelanggan+$kredit_ddpj;
$saldo_pelanggan = $saldo_pelanggan+$kredit_ddpj;
$update = [
'BLOCKCON' => $blockcon_dpj
];
$action = $this->DpPenjualan->update('dp_penjualan', $update, 'ID_DPJ', $id_dpj);
$update = [
'BLOCKCON' => $blockcon_pda
];
$action = $this->DpPenjualan->update('piutang_dagang', $update, 'ID_PDA', $id_pda);
$update = [
'HUTANG_PELANGGAN' => $hutang_pelanggan,
'SALDO_PELANGGAN' => $saldo_pelanggan
];
$action = $this->DpPenjualan->update('pelanggan', $update, 'ID_PELANGGAN', $id_pelanggan);
//Step Hapus Data
$action = $this->DpPenjualan->delete('detail_dpj',$id,'ID_DDPJ');
$action = $this->DpPenjualan->hapusDetailPda($kode_ddpj);
$this->session->set_flashdata('flash', 'direset');
redirect($_SERVER['HTTP_REFERER']);
}
}