5982 lines
196 KiB
PHP
5982 lines
196 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 ManagePenjualan extends CI_Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('ModelDashboard', 'Dashboard');
|
|
$this->load->model('ModelPenjualan', 'Penjualan');
|
|
$this->load->model('AllModels', 'Amod');
|
|
$this->load->library(['datatables', 'form_validation']);
|
|
$this->form_validation->set_error_delimiters('', '');
|
|
$this->Dashboard->ceklogin();
|
|
}
|
|
public function output_json($data, $encode = true)
|
|
{
|
|
if ($encode) $data = json_encode($data);
|
|
$this->output->set_content_type('application/json')->set_output($data);
|
|
}
|
|
|
|
//Controller Transaksi Penjualan
|
|
public function dataOrder_Sales_A1() { // [1]
|
|
$jabatan = $this->session->userdata('jabatan');
|
|
$level = $this->session->userdata('level');
|
|
$id_corp = NULL;
|
|
$id_sales = $this->session->userdata('id_karyawan');
|
|
$id_so = NULL;
|
|
$username = $this->session->userdata('username');
|
|
|
|
$datCorp = $this->Penjualan->getData_Corp_So($id_corp, $level);
|
|
$datPelanggan = $this->Penjualan->getData_Pelanggan_byID();
|
|
$datPeminjaman = $this->Penjualan->getData_Peminjaman_byJENIS($level);
|
|
|
|
//Set Data berdasarkan ID atau Jabatan
|
|
if ($id_sales=="1" OR $jabatan=="ADMIN ITP" OR $id_sales=="9" OR $id_sales=="43") {
|
|
$datPenjualan = $this->Penjualan->getData_SalesOrder_Null_All($id_sales, $id_so, $level);
|
|
if ($id_sales==1) {
|
|
$datKaryawan = $this->Penjualan->getData_Karyawan_SalesPcm();
|
|
} else if ($jabatan=="ADMIN ITP") {
|
|
$datKaryawan = $this->Penjualan->getData_Karyawan_SalesItp();
|
|
} else if ($id_sales=="9" OR $id_sales=="43") {
|
|
$datKaryawan = $this->Penjualan->getData_Karyawan_SugengInclude($id_sales);
|
|
$datPenjualan = $this->Penjualan->getData_SalesOrder_Null_SugengInclude($id_sales);
|
|
}
|
|
} else {
|
|
$datPenjualan = $this->Penjualan->getData_SalesOrder_Null($id_sales, $id_so, $level);
|
|
$datKaryawan = NULL;
|
|
}
|
|
|
|
//Set Jumlah SO
|
|
if ($id_sales==1 OR $jabatan=="ADMIN ITP") {
|
|
$countSo = $this->Penjualan->getCount_SalesOrder_NotNull_Not1_Not5($id_sales, $level);
|
|
$countNull = $this->Penjualan->getCount_SalesOrder_Null($id_sales, $level);
|
|
} else {
|
|
$countSo = $this->Penjualan->getCount_SalesOrder_NotNull_Not1_Not5($id_sales);
|
|
$countNull = $this->Penjualan->getCount_SalesOrder_Null($id_sales);
|
|
}
|
|
|
|
//Set Nilai SO
|
|
$no = 0;
|
|
foreach ($datPenjualan as $key) {
|
|
$sumSo = $this->Penjualan->getSum_DaftarOrder_bySO($key['ID_SO']);
|
|
$datPenjualan[$no++] += ['NILAISO' => $sumSo[0]['TOTAL']];
|
|
}
|
|
|
|
$data = [
|
|
'sidebar' => "menu penjualan",
|
|
'navChild' => "penjualan step1",
|
|
'penjualan' => $datPenjualan,
|
|
'corp' => $datCorp,
|
|
'karyawan' => $datKaryawan,
|
|
'pelanggan' => $datPelanggan,
|
|
'peminjaman' => $datPeminjaman,
|
|
'countSo' => $countSo,
|
|
'countNull' => $countNull,
|
|
'jabatan' => $jabatan,
|
|
'username' => $username,
|
|
];
|
|
|
|
$this->load->view('proses/PenjualanOrder_Sales_A1', $data);
|
|
}
|
|
|
|
public function loginrevisi_Penjualan_SA1() { // [2]
|
|
$username = $this->input->post('username');
|
|
$password = $this->input->post('password');
|
|
$username_login = $this->session->userdata('username');
|
|
$nama_panggilan = $this->session->userdata('nama_panggilan');
|
|
$datKaryawan = $this->Penjualan->getData_Karyawan_forLogin($username, $password);
|
|
|
|
if ($datKaryawan == TRUE and $username == $username_login) {
|
|
$this->session->set_flashdata('username_pass_success', 'login');
|
|
redirect('ManagePenjualan/dataRevisi_Sales_SA1');
|
|
} else {
|
|
$this->session->set_flashdata('username_pass_error_revisi', "$nama_panggilan");
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
public function kodeSalesOrder() { // [3]
|
|
$kk = $this->Penjualan->getKode_SalesOrder();
|
|
$tgl = date('y');
|
|
if (is_array($kk) || is_object($kk)) {
|
|
foreach ($kk as $row) {
|
|
if ($row['KODE'] == null) {
|
|
return "SO".$tgl."000001";
|
|
} else {
|
|
$str = (string) $row['KODE'];
|
|
$tgl_lama = substr($str, 2, -6);
|
|
if ($tgl_lama!=$tgl) {
|
|
return "SO".$tgl."000001";
|
|
} else {
|
|
$panjang = 6;
|
|
$data = substr($str, 4, $panjang);
|
|
$ko = (int) $data + 1;
|
|
$str = (string) $ko;
|
|
$panjang = 10 - strlen($str);
|
|
$data = "SO".$tgl."000000";
|
|
$data = substr($data, 0, $panjang) . $str;
|
|
return $data;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function simpanorder_SA1() { // [4]
|
|
$method = $this->input->post('method');
|
|
$id_so = $this->input->post('id');
|
|
$id_corp = $this->input->post('id_corp');
|
|
$id_pelanggan = $this->input->post('id_pelanggan');
|
|
$id_peminjaman = $this->input->post('id_peminjaman');
|
|
$ppn_so = $this->input->post('ppn_so');
|
|
$po_so = $this->input->post('po_so');
|
|
$fee_so = $this->input->post('fee_so');
|
|
$gp_so = $this->input->post('radio_gp');
|
|
$jenis_so = $this->input->post('jenis_so');
|
|
$ongkir_so = $this->input->post('radio_ongkir');
|
|
$kode_so = $this->kodeSalesOrder();
|
|
$tgl = date('Y-m-d');
|
|
$tgl_now = date('d/m/Y H:i:s');
|
|
|
|
//Check apakah Nilai Fee bersifat Numeric
|
|
$check_fee = is_numeric($fee_so);
|
|
if ($check_fee==FALSE) {
|
|
$fee_so = 0;
|
|
}
|
|
|
|
//Check apakah Nilai PPN bersifat Numeric
|
|
$check_ppn = is_numeric($ppn_so);
|
|
if ($check_ppn==FALSE) {
|
|
$ppn_so = 0;
|
|
}
|
|
|
|
//Set Jika Fee Kosong
|
|
if ($fee_so=="") {
|
|
$fee_so = 0;
|
|
}
|
|
|
|
//Set Jika PPN Kosong
|
|
if ($ppn_so=="") {
|
|
$ppn_so = 0;
|
|
}
|
|
|
|
//Check apakah nilai PPN/Fee kurang dari 0
|
|
if ($ppn_so<0 OR $fee_so<0) {
|
|
$this->session->set_flashdata('not_zero_negative', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Set Nilai id_sales
|
|
if ($jenis_so==0) {
|
|
$id_sales = $this->session->userdata('id_karyawan');
|
|
} else if ($jenis_so==1) {
|
|
$id_sales = $this->input->post('id_sales');
|
|
}
|
|
|
|
if ($id_peminjaman!="") {
|
|
$datPeminjaman = $this->Penjualan->getData_Peminjaman_byID($id_peminjaman);
|
|
$id_pelanggan = $datPeminjaman[0]['PELANGGAN_ID'];
|
|
}
|
|
|
|
$po_so = strtoupper($po_so);
|
|
$input = [
|
|
'SALES_ID' => $id_sales,
|
|
'CORP_ID' => $id_corp,
|
|
'PELANGGAN_ID' => $id_pelanggan,
|
|
'KODE_SO' => $kode_so,
|
|
'TGL_CREATE' => $tgl_now,
|
|
'TGL_SO' => $tgl,
|
|
'FEE_SO' => $fee_so,
|
|
'PO_SO' => $po_so,
|
|
'PPN_SO' => $ppn_so,
|
|
'GP_SO' => $gp_so,
|
|
'ONGKIR_SO' => $ongkir_so
|
|
];
|
|
$action = $this->Penjualan->create('sales_order', $input);
|
|
|
|
if ($id_peminjaman!="") {
|
|
$id_so = $this->Penjualan->getID_SalesOrderMax();
|
|
$id_so = $id_so[0]['ID_SO'];
|
|
|
|
$datDaftarPinjam = $this->Penjualan->getData_DaftarPinjam_byPEMINJAMAN($id_peminjaman);
|
|
foreach ($datDaftarPinjam as $key) {
|
|
$datBarang = $this->Penjualan->getData_Barang_byID($key['BARANG_ID']);
|
|
$input = [
|
|
'SO_ID' => $id_so,
|
|
'BARANG_ID' => $key['BARANG_ID'],
|
|
'QTY_DO' => $key['QTY_DFP'],
|
|
'NAMA_DO' => $datBarang[0]['NAMA_BARANG'],
|
|
'HARGA_DO' => '0',
|
|
];
|
|
$action = $this->Penjualan->create('daftar_order', $input);
|
|
}
|
|
}
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function ubahorder_SA1() { // [5]
|
|
$method = $this->input->post('method');
|
|
$id_so = $this->input->post('id_soed');
|
|
$id_corp = $this->input->post('id_corped');
|
|
$id_pelanggan = $this->input->post('id_pelangganed');
|
|
$ppn_so = $this->input->post('ppn_soed');
|
|
$po_so = $this->input->post('po_soed');
|
|
$fee_so = $this->input->post('fee_soed');
|
|
$gp_so = $this->input->post('gp_soed');
|
|
$ongkir_so = $this->input->post('ongkir_soed');
|
|
$id_sales = $this->session->userdata('id_karyawan');
|
|
|
|
//Check Konsistensi Data
|
|
$datSo = $this->Penjualan->getData_SalesOrder_Null($id_sales, $id_so);
|
|
if ($datSo==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah nilai Fee Numeric
|
|
$check_fee = is_numeric($fee_so);
|
|
if ($check_fee==FALSE) {
|
|
$fee_so = 0;
|
|
}
|
|
|
|
//Check apakah nilai PPN Numeric
|
|
$check_ppn = is_numeric($ppn_so);
|
|
if ($check_ppn==FALSE) {
|
|
$ppn_so = 0;
|
|
}
|
|
|
|
//Set Fee jika dikosongi
|
|
if ($fee_so=="") {
|
|
$fee_so = 0;
|
|
}
|
|
|
|
//Set PPN jika dikosongi
|
|
if ($ppn_so=="") {
|
|
$ppn_so = 0;
|
|
}
|
|
|
|
//Check apakah PPN atau Fee nilainya dibawah 0
|
|
if ($ppn_so<0 OR $fee_so<0) {
|
|
$this->session->set_flashdata('not_zero_negative', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah Pelanggan yang baru tidak melebihi batas Limit Nota
|
|
if ($datSo[0]['PELANGGAN_ID']!=$id_pelanggan) {
|
|
$datPda = $this->Penjualan->getData_PiutangDagang_byPELANGGAN($id_pelanggan);
|
|
$datPelanggan = $this->Penjualan->getData_Pelanggan_byID($id_pelanggan);
|
|
$limit_pelanggan = $datPelanggan[0]['LIMIT_PELANGGAN'];
|
|
|
|
$totalSo = $this->Penjualan->getData_DaftarOrder_byPELANGGAN_Null_Not1_Not5($id_pelanggan);
|
|
$totalAktif = 0;
|
|
foreach ($totalSo as $key) {
|
|
$order = ($key['HARGA_DO']*$key['QTY_DO'])*(($key['PPN_SO']+100)/100);
|
|
$totalAktif = $totalAktif+$order;
|
|
}
|
|
|
|
$debetAktif = 0;
|
|
foreach ($datPda as $key) {
|
|
$debet = $key['DEBET_PDA'];
|
|
$debetAktif = $debetAktif+$debet;
|
|
}
|
|
|
|
$kreditAktif = 0;
|
|
foreach ($datPda as $key) {
|
|
$kredit = $key['KREDIT_PDA'];
|
|
$kreditAktif = $kreditAktif+$kredit;
|
|
}
|
|
|
|
$limit = $limit_pelanggan-$debetAktif-$totalAktif+$kreditAktif;
|
|
if ($limit<0) {
|
|
$this->session->set_flashdata('limit_pelbaru_check', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
$po_so = strtoupper($po_so);
|
|
$update = [
|
|
'CORP_ID' => $id_corp,
|
|
'PELANGGAN_ID' => $id_pelanggan,
|
|
'PPN_SO' => $ppn_so,
|
|
'FEE_SO' => $fee_so,
|
|
'PO_SO' => $po_so,
|
|
'GP_SO' => $gp_so,
|
|
'ONGKIR_SO' => $ongkir_so
|
|
];
|
|
$action = $this->Penjualan->update('sales_order', $update, 'ID_SO', $id_so);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'diubah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'diubah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function hapusorder_SA1() { // [6]
|
|
$id_so = $this->input->post('id');
|
|
$id_sales = $this->session->userdata('id_karyawan');
|
|
|
|
//Check Konsistensi Data
|
|
$datSo = $this->Penjualan->getData_SalesOrder_Null($id_sales, $id_so);
|
|
if ($datSo==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah ada data Daftar Order
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_bySO($id_so);
|
|
if ($datDo==TRUE) {
|
|
$this->session->set_flashdata('data_used_do', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah ada data Slip Manual
|
|
$datSm = $this->Penjualan->getData_SlipManual_bySO($id_so);
|
|
if ($datSm==TRUE) {
|
|
$this->session->set_flashdata('data_used_sm', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$action = $this->Penjualan->delete('sales_order',$id_so,'ID_SO');
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function dataOrder_Sales_A2($id) { //[7]
|
|
$penjualan = $this->Penjualan->getData_DaftarOrder_bySO($id);
|
|
$jabatan = $this->session->userdata('jabatan');
|
|
$level = $this->session->userdata('level');
|
|
$barang = $this->Penjualan->getBarang_TypeAll_NonJasa($level);
|
|
$jasa = $this->Penjualan->getBarang_TypeAll_NonQty();
|
|
$datSo = $this->Penjualan->getData_SalesOrder_byID($id);
|
|
|
|
//Nilai Semua SO yang sedang digunakan
|
|
$limit_pelanggan = $datSo[0]['LIMIT_PELANGGAN'];
|
|
$totalSo = $this->Penjualan->getData_DaftarOrder_byPELANGGAN_Null_Not1_Not5($datSo[0]['PELANGGAN_ID']);
|
|
$totalAktif = 0;
|
|
foreach ($totalSo as $key) {
|
|
$order = $key['HARGA_DO']*$key['QTY_DO'];
|
|
$totalAktif = $totalAktif+$order;
|
|
}
|
|
$totalAktif = (($datSo[0]['PPN_SO']+100)/100)*$totalAktif;
|
|
$totalAktif = round($totalAktif);
|
|
|
|
//Nilai Debet Kredit Keuangan Aktif
|
|
$datPda = $this->Penjualan->getData_PiutangDagang_byPELANGGAN($datSo[0]['PELANGGAN_ID']);
|
|
$debetAktif = 0;
|
|
$kreditAktif = 0;
|
|
foreach ($datPda as $key) {
|
|
$debet = $key['DEBET_PDA'];
|
|
$debetAktif = $debetAktif+$debet;
|
|
}
|
|
foreach ($datPda as $key) {
|
|
$kredit = $key['KREDIT_PDA'];
|
|
$kreditAktif = $kreditAktif+$kredit;
|
|
}
|
|
|
|
//Set Nilai Limit
|
|
$limit = $limit_pelanggan-$debetAktif-$totalAktif+$kreditAktif;
|
|
|
|
//Set Nilai Nominal Pda yang sedang aktif
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_bySO($id);
|
|
$nominal_pda = 0;
|
|
foreach ($datDo as $key) {
|
|
$piutang = $key['HARGA_DO']*$key['QTY_DO'];
|
|
$nominal_pda = $nominal_pda+$piutang;
|
|
}
|
|
|
|
$bruto = $nominal_pda;
|
|
$ppn_pda = $nominal_pda*($datSo[0]['PPN_SO']/100);
|
|
$nominal_pda = $nominal_pda*(($datSo[0]['PPN_SO']+100)/100);
|
|
$nominal_pda = round($nominal_pda);
|
|
|
|
$data = [
|
|
'sidebar' => "menu penjualan",
|
|
'navChild' => "penjualan step1",
|
|
'penjualan' => $penjualan,
|
|
'id_so' => $id,
|
|
'limit' => $limit,
|
|
'bruto' => $bruto,
|
|
'ppn_pda' => $ppn_pda,
|
|
'nominal_pda' => $nominal_pda,
|
|
'barang' => $barang,
|
|
'jasa' => $jasa,
|
|
'jabatan' => $jabatan,
|
|
'level' => $level,
|
|
'kode_so' => $datSo[0]['KODE_SO'],
|
|
'fee_so' => $datSo[0]['FEE_SO'],
|
|
'nama_pelanggan' => $datSo[0]['NAMA_PELANGGAN'],
|
|
'nama_kota' => $datSo[0]['NAMA_KOTA'],
|
|
];
|
|
|
|
$this->load->view('proses/PenjualanOrder_Sales_A2', $data);
|
|
}
|
|
|
|
public function simpanorder_SA2() { //[8]
|
|
$method = $this->input->post('method');
|
|
$id_so = $this->input->post('id_so');
|
|
$id = $this->input->post('id_do');
|
|
$id_barang = $this->input->post('id_barang');
|
|
$qty_do = $this->input->post('qty_do');
|
|
$harga_do = $this->input->post('harga_do');
|
|
$limit = $this->input->post('limit');
|
|
|
|
//Check Konsistensi Data
|
|
$datSo = $this->Penjualan->getData_SalesOrder_byID($id_so);
|
|
if ($datSo[0]['STATUS_SO']!=NULL AND $datSo[0]['STATUS_SO']!=6 AND $datSo[0]['STATUS_SO']!=7) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePenjualan/dataOrder_Sales_A1');
|
|
}
|
|
|
|
//Check apakah Kuantiti Kurang dari atau sama dengan 0
|
|
if ($qty_do<=0) {
|
|
$this->session->set_flashdata('not_zero_negative', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Set Koma menjadi titik
|
|
$harga_do = str_replace(',', '.', $harga_do);
|
|
|
|
//Check apakah nilai bersifat Numeric
|
|
$check_nilai = is_numeric($harga_do);
|
|
if ($check_nilai==FALSE) {
|
|
$harga_do = 0;
|
|
}
|
|
|
|
//Check apakah Total SO ditambah barang baru melebihi limit
|
|
$totalSo = ($qty_do*$harga_do)*(($datSo[0]['PPN_SO']+100)/100);
|
|
if ($limit<$totalSo) {
|
|
$this->session->set_flashdata('limit_check', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah ada Kode Barang yang sama
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_bySO_byBARANG($id_so, $id_barang);
|
|
if ($datDo==TRUE) {
|
|
$this->session->set_flashdata('twin_item', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$datBarang = $this->Penjualan->getData_Barang_byID($id_barang);
|
|
$input = [
|
|
'SO_ID' => $id_so,
|
|
'BARANG_ID' => $id_barang,
|
|
'QTY_DO' => $qty_do,
|
|
'HARGA_DO' => $harga_do,
|
|
'NAMA_DO' => $datBarang[0]['NAMA_BARANG'],
|
|
'KET_DO' => "",
|
|
];
|
|
$action = $this->Penjualan->create('daftar_order', $input);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function hapusorder_SA2() { //[9]
|
|
$method = $this->input->post('method');
|
|
$id_do = $this->input->post('id');
|
|
$id_karyawan = $this->session->userdata('id_karyawan');
|
|
|
|
//Check Konsistensi Data
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_byID($id_do);
|
|
if ($datDo==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check Konsistensi Data
|
|
$datSo = $this->Penjualan->getData_SalesOrder_byID($id_so);
|
|
if ($datSo[0]['STATUS_SO']!=NULL AND $datSo[0]['STATUS_SO']!=6 AND $datSo[0]['STATUS_SO']!=7) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePenjualan/dataOrder_Sales_A1');
|
|
}
|
|
|
|
$action = $this->Penjualan->delete('daftar_order', $id_do ,'ID_DO');
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function ubahorder_SA2() { //[100]
|
|
$method = $this->input->post('method');
|
|
$id_do = $this->input->post('id_do');
|
|
$id_so = $this->input->post('id_so');
|
|
$harga_do = $this->input->post('harga_doed');
|
|
$limit = $this->input->post('limit');
|
|
|
|
//Check Konsistensi Data
|
|
$datSo = $this->Penjualan->getData_SalesOrder_byID($id_so);
|
|
if ($datSo[0]['STATUS_SO']!=NULL AND $datSo[0]['STATUS_SO']!=6 AND $datSo[0]['STATUS_SO']!=7) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePenjualan/dataOrder_Sales_A1');
|
|
}
|
|
|
|
//Set Koma menjadi titik
|
|
$harga_do = str_replace(',', '.', $harga_do);
|
|
|
|
//Check apakah nilai bersifat Numeric
|
|
$check_nilai = is_numeric($harga_do);
|
|
if ($check_nilai==FALSE) {
|
|
$harga_do = 0;
|
|
}
|
|
|
|
//Check apakah Total SO ditambah barang baru melebihi limit
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_byID($id_do);
|
|
$totalSo = ($datDo[0]['QTY_DO']*$harga_do)*(($datSo[0]['PPN_SO']+100)/100);
|
|
if ($limit<$totalSo) {
|
|
$this->session->set_flashdata('limit_check', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$update = [
|
|
'HARGA_DO' => $harga_do,
|
|
];
|
|
$action = $this->Penjualan->update('daftar_order', $update, 'ID_DO', $id_do);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'diubah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'diubah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function proformaorder_SA2() { //[10]
|
|
$method = $this->input->post('method');
|
|
$id_so = $this->input->post('id_so');
|
|
$po_so = $this->input->post('po_so');
|
|
$ket_so_o = $this->input->post('ket_so_o');
|
|
$tgl = date('Y-m-d');
|
|
|
|
//Set Hilangkan Enter, dan perbesar tulisan
|
|
$ket_so_o = preg_replace('/\R+/', " " , $ket_so_o);
|
|
$po_so = strtoupper($po_so);
|
|
|
|
$update = [
|
|
'PO_SO' => $po_so,
|
|
'KET_SO_O' => $ket_so_o
|
|
];
|
|
$action = $this->Penjualan->update('sales_order', $update, 'ID_SO', $id_so);
|
|
|
|
$datSo = $this->Penjualan->getData_SalesOrder_byID($id_so);
|
|
$input = [
|
|
'SJ_INV' => '1',
|
|
'KODE_BUKTI' => $datSo[0]['KODE_SO'],
|
|
'SO_ID' => $id_so,
|
|
'TGL_CD' => $tgl
|
|
];
|
|
$action = $this->Penjualan->create('cetak_dokumen', $input);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('data_lock_print', 'diproses');
|
|
redirect('ManagePenjualan/dataOrder_Sales_A1');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'diproses');
|
|
redirect('ManagePenjualan/dataOrder_Sales_A1');
|
|
}
|
|
|
|
}
|
|
|
|
public function kunciorder_SA2() { //[11]
|
|
$method = $this->input->post('method');
|
|
$id_so = $this->input->post('id_so');
|
|
$limit = $this->input->post('limit');
|
|
$po_so = $this->input->post('po_so');
|
|
$ket_so_o = $this->input->post('ket_so_o');
|
|
$ket_so_g = $this->input->post('ket_so_g');
|
|
$ket_so_k = $this->input->post('ket_so_k');
|
|
$ket_so_t = $this->input->post('ket_so_t');
|
|
$ket_so_p = $this->input->post('ket_so_p');
|
|
$reminder_so = $this->input->post('reminder_so');
|
|
$id_sales = $this->session->userdata('id_karyawan');
|
|
$tgl = date('Y-m-d');
|
|
$tgl_now = date('d/m/Y H:i:s');
|
|
|
|
//Check Konsistensi Data
|
|
$datSo = $this->Penjualan->getData_SalesOrder_Null($id_sales, $id_so);
|
|
if ($datSo==FALSE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePenjualan/dataOrder_Sales_A1');
|
|
}
|
|
|
|
//Check apakah SO Melebihi Limit Kelompok
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_bySO($id_so);
|
|
$datPelanggan = $this->Penjualan->getData_Pelanggan_byID($datSo[0]['PELANGGAN_ID']);
|
|
if ($datPelanggan[0]['KELOMPOK_ID']!="0") {
|
|
$datKelompok = $this->Penjualan->getData_Pelanggan_byKELOMPOK($datPelanggan[0]['KELOMPOK_ID']);
|
|
foreach ($datKelompok as $key) {
|
|
$nama_kelompok = $key['NAMA_KELOMPOK'];
|
|
$datPda = $this->Penjualan->getData_PiutangDagang_byPELANGGAN($key['ID_PELANGGAN']);
|
|
$dataPelanggan = $this->Penjualan->getData_Pelanggan_byID($key['ID_PELANGGAN']);
|
|
$limit_pelanggan = $dataPelanggan[0]['LIMIT_PELANGGAN'];
|
|
|
|
$totalSo = $this->Penjualan->getData_DaftarOrder_byPELANGGAN_Null_Not1_Not5($key['ID_PELANGGAN']);
|
|
$totalAktif = 0;
|
|
foreach ($totalSo as $dat) {
|
|
$order = ($dat['HARGA_DO']*$dat['QTY_DO'])*(($dat['PPN_SO']+100)/100);
|
|
$totalAktif = $totalAktif+$order;
|
|
}
|
|
|
|
$debetAktif = 0;
|
|
foreach ($datPda as $dat) {
|
|
$debet = $dat['DEBET_PDA'];
|
|
$debetAktif = $debetAktif+$debet;
|
|
}
|
|
|
|
$kreditAktif = 0;
|
|
foreach ($datPda as $dat) {
|
|
$kredit = $dat['KREDIT_PDA'];
|
|
$kreditAktif = $kreditAktif+$kredit;
|
|
}
|
|
|
|
$nilai_doAktif = 0;
|
|
foreach ($datDo as $dat) {
|
|
$total_do = $dat['HARGA_DO']*$dat['QTY_DO'];
|
|
$nilai_doAktif = $nilai_doAktif+$total_do;
|
|
}
|
|
$nilai_doAktif = $nilai_doAktif*((100+$datSo[0]['PPN_SO'])/100);
|
|
|
|
$limit_akhir = $limit_pelanggan-$debetAktif-$totalAktif-$nilai_doAktif+$kreditAktif;
|
|
|
|
if ($limit_akhir<0) {
|
|
$this->session->set_flashdata('limit_group_check', "$nama_kelompok");
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($limit<0) {
|
|
$this->session->set_flashdata('limit_check', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Set Keterangan tanpa enter, dan memperbesar Nomor PO
|
|
$ket_so_o = preg_replace('/\R+/', " " , $ket_so_o);
|
|
$ket_so_g = preg_replace('/\R+/', " " , $ket_so_g);
|
|
$ket_so_k = preg_replace('/\R+/', " " , $ket_so_k);
|
|
$ket_so_t = preg_replace('/\R+/', " " , $ket_so_t);
|
|
$ket_so_p = preg_replace('/\R+/', " " , $ket_so_p);
|
|
$po_so = strtoupper($po_so);
|
|
|
|
if ($reminder_so=="") {
|
|
$reminder_so = $this->Penjualan->addTempoYear($tgl,1);
|
|
} else if ($reminder_so==12) {
|
|
$reminder_so = $this->Penjualan->addTempoYear($tgl,1);
|
|
} else if ($reminder_so==24) {
|
|
$reminder_so = $this->Penjualan->addTempoYear($tgl,2);
|
|
} else if ($reminder_so==36) {
|
|
$reminder_so = $this->Penjualan->addTempoYear($tgl,3);
|
|
} else {
|
|
$reminder_so = $this->Penjualan->addTempoMonth($tgl, $reminder_so);
|
|
}
|
|
|
|
if (strtotime($tgl)<strtotime($reminder_so)) {
|
|
$kode_so = $datSo[0]['KODE_SO'];
|
|
$nama_pelanggan = $datSo[0]['NAMA_PELANGGAN'];
|
|
$ket_notifikasi = "Reminder $kode_so $nama_pelanggan";
|
|
$input = [
|
|
'TGL_NOTIFIKASI' => $reminder_so,
|
|
'JENIS_NOTIFIKASI' => '4',
|
|
'KET_NOTIFIKASI' => $ket_notifikasi,
|
|
'SO_ID' => $id_so
|
|
];
|
|
$action = $this->Penjualan->create('notifikasi', $input);
|
|
|
|
$id_notifikasi = $this->Penjualan->getID_NotifikasiMax();
|
|
$id_notifikasi = $id_notifikasi[0]['ID_NOTIFIKASI'];
|
|
|
|
$input = [
|
|
'KARYAWAN_ID' => $id_sales,
|
|
'STATUS' => '0',
|
|
'NOTIFIKASI_ID' => $id_notifikasi
|
|
];
|
|
$action = $this->Penjualan->create('log_notifikasi', $input);
|
|
}
|
|
|
|
$update = [
|
|
'PO_SO' => $po_so,
|
|
'TGL_SO' => $tgl,
|
|
'TGL_CREATE' => $tgl_now,
|
|
'KET_SO_O' => $ket_so_o,
|
|
'KET_SO_G' => $ket_so_g,
|
|
'KET_SO_K' => $ket_so_k,
|
|
'KET_SO_T' => $ket_so_t,
|
|
'KET_SO_P' => $ket_so_p,
|
|
'REMINDER_SO' => $reminder_so,
|
|
'STATUS_SO' => '0'
|
|
];
|
|
$action = $this->Penjualan->update('sales_order', $update, 'ID_SO', $id_so);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('data_lock', 'dikunci');
|
|
redirect('ManagePenjualan/dataOrder_Sales_A1');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dikunci');
|
|
redirect('ManagePenjualan/dataOrder_Sales_A1');
|
|
}
|
|
|
|
}
|
|
|
|
public function dataOrder_Gudang_A1() { //[12]
|
|
$level = $this->session->userdata('level');
|
|
$jabatan = $this->session->userdata('jabatan');
|
|
$penjualan = $this->Penjualan->getData_SalesOrder_NotNull_Not1_Not2_Not3_Not5($level, $jabatan);
|
|
$countBeli = $this->Amod->getCount_Pembelian_1();
|
|
$tgl = date('Y-m-d');
|
|
|
|
$id_barang = NULL;
|
|
$bar = [];
|
|
foreach ($penjualan as $key) {
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_bySO($key['ID_SO']);
|
|
foreach ($datDo as $dat) {
|
|
if ($id_barang!=$dat['BARANG_ID']) {
|
|
$id_barang = $dat['BARANG_ID'];
|
|
array_push($bar, $id_barang);
|
|
}
|
|
}
|
|
}
|
|
|
|
$bar = array_unique($bar);
|
|
sort($bar);
|
|
|
|
$no = 0;
|
|
$barend = [];
|
|
foreach ($bar as $datkey) {
|
|
$qty = 0;
|
|
foreach ($penjualan as $key) {
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_bySO($key['ID_SO']);
|
|
foreach ($datDo as $dat) {
|
|
if ($dat['BARANG_ID']==$datkey) {
|
|
$qty = $qty+$dat['QTY_DO'];
|
|
}
|
|
}
|
|
}
|
|
$datBarang = $this->Penjualan->getData_Barang_byID($datkey);
|
|
$barend[$no++] = [
|
|
'BARANG' => $datkey,
|
|
'QTY' => $qty,
|
|
'JENIS' => $datBarang[0]['TYPE_JENIS'],
|
|
];
|
|
}
|
|
|
|
$no = 0;
|
|
foreach ($barend as $keydat) {
|
|
$datKuantiti = $this->Penjualan->getData_Kuantiti_byID($keydat['BARANG']);
|
|
if ($keydat['JENIS']==2) {
|
|
$stat = 1;
|
|
} else if ($datKuantiti[0]['PCM_KUANTITI']==0) {
|
|
$stat = 0;
|
|
} else if ($datKuantiti[0]['PCM_KUANTITI']<$keydat['QTY']) {
|
|
$stat = 2;
|
|
} else {
|
|
$stat = 1;
|
|
}
|
|
$barend[$no++] += ['STAT' => $stat];
|
|
}
|
|
|
|
$no = 0;
|
|
foreach ($penjualan as $dit) {
|
|
$nodo = 0;
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_bySO($dit['ID_SO']);
|
|
foreach ($datDo as $dut) {
|
|
foreach ($barend as $det) {
|
|
if ($det['BARANG']==$dut['BARANG_ID']) {
|
|
$datDo[$nodo++] += ['STAT' => $det['STAT']];
|
|
}
|
|
}
|
|
}
|
|
$penjualan[$no++] += ['DATDO' => $datDo];
|
|
}
|
|
|
|
$data = [
|
|
'sidebar' => "menu penjualan",
|
|
'navChild' => "penjualan step2",
|
|
'penjualan' => $penjualan,
|
|
'countSo' => count($penjualan),
|
|
'countBeli' => $countBeli,
|
|
'tgl' => $tgl,
|
|
];
|
|
$this->load->view('proses/PenjualanOrder_Gudang_A1', $data);
|
|
}
|
|
|
|
public function dataOrder_Gudang_A2_Proses($id) { //[14]
|
|
$level = $this->session->userdata('level');
|
|
$penjualan = $this->Penjualan->getData_DaftarOrder_bySO($id);
|
|
$datSo = $this->Penjualan->getData_SalesOrder_byID($id);
|
|
$datIoMasuk = $this->Penjualan->getData_TransaksiStock_bySO_Null_Jenis1($id);
|
|
$datIoKeluar = $this->Penjualan->getData_TransaksiStock_bySO_Null_Jenis0($id);
|
|
$barangKeluar = $this->Penjualan->getBarang_TypeAll_jenisKeluar($level);
|
|
$barangMasuk = $this->Penjualan->getBarang_TypeAll_jenisMasuk();
|
|
$datHpar = $this->Penjualan->getData_HargaPart_byID();
|
|
$datKaryawan = $this->Penjualan->getData_Karyawan_Qc();
|
|
|
|
//Set Real Jumlah SN Daftar Order
|
|
$no = 0;
|
|
foreach ($penjualan as $key) {
|
|
$qtyReal = $this->Penjualan->getQtyReal_SnJual_byDO($key['ID_DO']);
|
|
$penjualan[$no++] += ['REAL' => $qtyReal];
|
|
}
|
|
|
|
//Set Real Jumlah SN Transaksi Keluar
|
|
$no = 0;
|
|
foreach ($datIoKeluar as $key) {
|
|
$qtyReal = $this->Penjualan->getQtyReal_TransaksiStock0($key['ID_IO']);
|
|
$datIoKeluar[$no++] += ['REAL' => $qtyReal];
|
|
}
|
|
|
|
//Set Real Jumlah SN Transaksi Masuk
|
|
$no = 0;
|
|
foreach ($datIoMasuk as $key) {
|
|
$qtyReal = $this->Penjualan->getQtyReal_TransaksiStock1($key['ID_IO']);
|
|
$datIoMasuk[$no++] += ['REAL' => $qtyReal];
|
|
}
|
|
|
|
$data = [
|
|
'sidebar' => "menu penjualan",
|
|
'navChild' => "penjualan step2",
|
|
'penjualan' => $penjualan,
|
|
'id_so' => $id,
|
|
'kode_so' => $datSo[0]['KODE_SO'],
|
|
'ket_so_g' => $datSo[0]['KET_SO_G'],
|
|
'ket_so_k' => $datSo[0]['KET_SO_K'],
|
|
'ket_so_t' => $datSo[0]['KET_SO_T'],
|
|
'ket_so_p' => $datSo[0]['KET_SO_P'],
|
|
'nama_sales' => $datSo[0]['NAMA_PANGGILAN_KARYAWAN'],
|
|
'nama_pelanggan'=> $datSo[0]['NAMA_PELANGGAN'],
|
|
'nama_kota' => $datSo[0]['NAMA_KOTA'],
|
|
'masuk' => $datIoMasuk,
|
|
'keluar' => $datIoKeluar,
|
|
'barang_masuk' => $barangMasuk,
|
|
'barang_keluar' => $barangKeluar,
|
|
'potong_part' => $datHpar,
|
|
'qc' => $datKaryawan,
|
|
'level' => $level
|
|
];
|
|
$this->load->view('proses/PenjualanOrder_Gudang_A2_Proses', $data);
|
|
}
|
|
|
|
public function simpanorder_GA2() { //[15]
|
|
$method = $this->input->post('method');
|
|
$id_so = $this->input->post('id_so');
|
|
$jenis_io = $this->input->post('jenis_io');
|
|
$id_barang = $this->input->post('id_barang');
|
|
$qty_io = $this->input->post('qty_io');
|
|
$id_hpar = $this->input->post('id_hpar');
|
|
$ket_io = $this->input->post('ket_io');
|
|
$id_gudang = $this->session->userdata('id_karyawan');
|
|
$level = $this->session->userdata('level');
|
|
$tgl = date('Y-m-d');
|
|
|
|
//Check Konsistensi Data
|
|
$datSo = $this->Penjualan->getData_SalesOrder_0_7_8($id_so);
|
|
if ($datSo==FALSE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
}
|
|
|
|
//Check apakah menggunakan angka 0 atau dibawahnya
|
|
if ($qty_io<=0) {
|
|
$this->session->set_flashdata('not_zero_negative', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check jika keluar, lihat Kuantiti yang aktif
|
|
if ($jenis_io=="0") {
|
|
$datKuantiti = $this->Penjualan->getData_Kuantiti_byID($id_barang);
|
|
if ($level == 0) {
|
|
if ($datKuantiti[0]['PCM_KUANTITI']<$qty_io) {
|
|
$this->session->set_flashdata('over_qty', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
} else if ($level == 1) {
|
|
if ($datKuantiti[0]['ITP_KUANTITI']<$qty_io) {
|
|
$this->session->set_flashdata('over_qty', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
|
|
//Check apakah ada Kode Barang yang sama
|
|
$datIoMasuk = $this->Penjualan->getData_TransaksiStock_bySO_Null_Jenis1($id_so);
|
|
if ($datIoMasuk[0]['BARANG_ID']==$id_barang) {
|
|
$this->session->set_flashdata('twin_item', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah ada Kode Barang yang sama
|
|
$datIoKeluar = $this->Penjualan->getData_TransaksiStock_bySO_Null_Jenis0($id_so);
|
|
if ($datIoKeluar[0]['BARANG_ID']==$id_barang) {
|
|
$this->session->set_flashdata('twin_item', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
if ($jenis_io=="0") {
|
|
$datKuantiti = $this->Penjualan->getData_Kuantiti_byID($id_barang);
|
|
if ($level == 0) {
|
|
$pcm_kuantiti = $datKuantiti[0]['PCM_KUANTITI'];
|
|
$proses_kuantiti = $datKuantiti[0]['PROSES_KUANTITI'];
|
|
$pcm = $pcm_kuantiti-$qty_io;
|
|
$proses = $proses_kuantiti+$qty_io;
|
|
$update = [
|
|
'PCM_KUANTITI' => $pcm,
|
|
'PROSES_KUANTITI' => $proses
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $id_barang);
|
|
} else if ($level == 1) {
|
|
$itp_kuantiti = $datKuantiti[0]['ITP_KUANTITI'];
|
|
$proses_kuantiti = $datKuantiti[0]['PROSES_KUANTITI'];
|
|
$itp = $itp_kuantiti-$qty_io;
|
|
$proses = $proses_kuantiti+$qty_io;
|
|
$update = [
|
|
'ITP_KUANTITI' => $itp,
|
|
'PROSES_KUANTITI' => $proses
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $id_barang);
|
|
}
|
|
}
|
|
|
|
$ket_io = preg_replace('/\R+/', " " , $ket_io);
|
|
if ($jenis_io=="0") {
|
|
$input = [
|
|
'SO_ID' => $id_so,
|
|
'BARANG_ID' => $id_barang,
|
|
'QTY_IO' => $qty_io,
|
|
'KET_IO' => $ket_io,
|
|
'JENIS_IO' => $jenis_io,
|
|
'TGL_IO' => $tgl,
|
|
'GUDANG_ID' => $id_gudang,
|
|
'KODE_BUKTI' => $datSo[0]['KODE_SO']
|
|
];
|
|
$action = $this->Penjualan->create('transaksi_stock', $input);
|
|
} else if ($jenis_io=="1") {
|
|
$datHpar = $this->Penjualan->getData_HargaPart_byID($id_hpar);
|
|
$harga_io = $datHpar[0]['HPP_HPAR']/2;
|
|
$input = [
|
|
'SO_ID' => $id_so,
|
|
'BARANG_ID' => $id_barang,
|
|
'QTY_IO' => $qty_io,
|
|
'KET_IO' => $ket_io,
|
|
'JENIS_IO' => $jenis_io,
|
|
'TGL_IO' => $tgl,
|
|
'GUDANG_ID' => $id_gudang,
|
|
'HARGA_IO' => $harga_io,
|
|
'HPAR_ID' => $id_hpar,
|
|
'KODE_BUKTI' => $datSo[0]['KODE_SO']
|
|
];
|
|
$action = $this->Penjualan->create('transaksi_stock', $input);
|
|
}
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function hapusorder_GA2() { //[16]
|
|
$method = $this->input->post('method');
|
|
$id_io = $this->input->post('id');
|
|
$id_so = $this->input->post('id_so');
|
|
$level = $this->session->userdata('level');
|
|
|
|
//Check Konsistensi Data
|
|
$datSo = $this->Penjualan->getData_SalesOrder_0_7_8($id_so);
|
|
if ($datSo==FALSE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
}
|
|
|
|
//Check Konsistensi Data
|
|
$datIo = $this->Penjualan->getData_TransaksiStock_byID($id_io);
|
|
if ($datIo==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah SN sudah terisi
|
|
$datSnIo = $this->Penjualan->getData_SnIo_AllJenis($id_io);
|
|
if ($datSnIo==TRUE) {
|
|
$this->session->set_flashdata('sn_io', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
if ($datIo[0]['JENIS_IO']=="0") {
|
|
$datKuantiti = $this->Penjualan->getData_Kuantiti_byID($datIo[0]['BARANG_ID']);
|
|
if ($level == 0) {
|
|
$pcm_kuantiti = $datKuantiti[0]['PCM_KUANTITI'];
|
|
$proses_kuantiti = $datKuantiti[0]['PROSES_KUANTITI'];
|
|
$pcm = $pcm_kuantiti+$datIo[0]['QTY_IO'];
|
|
$proses = $proses_kuantiti-$datIo[0]['QTY_IO'];
|
|
$update = [
|
|
'PCM_KUANTITI' => $pcm,
|
|
'PROSES_KUANTITI' => $proses
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $datIo[0]['BARANG_ID']);
|
|
} else if ($level == 1) {
|
|
$itp_kuantiti = $datKuantiti[0]['ITP_KUANTITI'];
|
|
$proses_kuantiti = $datKuantiti[0]['PROSES_KUANTITI'];
|
|
$itp = $itp_kuantiti+$datIo[0]['QTY_IO'];
|
|
$proses = $proses_kuantiti-$datIo[0]['QTY_IO'];
|
|
$update = [
|
|
'ITP_KUANTITI' => $itp,
|
|
'PROSES_KUANTITI' => $proses
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $datIo[0]['BARANG_ID']);
|
|
}
|
|
}
|
|
|
|
$action = $this->Penjualan->delete('transaksi_stock', $id_io, 'ID_IO');
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function ketorder_GA2() { //[17]
|
|
$method = $this->input->post('method');
|
|
$id_do = $this->input->post('id_do');
|
|
$ket_do = $this->input->post('ket_do');
|
|
|
|
//Check Konsistensi Data
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_byID($id_do);
|
|
if ($datDo==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$ket_do = preg_replace('/\R+/', " " , $ket_do);
|
|
$update = [
|
|
'KET_DO' => $ket_do
|
|
];
|
|
$action = $this->Penjualan->update('daftar_order', $update, 'ID_DO', $id_do);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function tahanorder_GA2() { //[18]
|
|
$method = $this->input->post('method');
|
|
$id_so = $this->input->post('id_so');
|
|
$ket_so_a = $this->input->post('ket_so_a');
|
|
|
|
//Check Konsistensi Data
|
|
$datSo = $this->Penjualan->getData_SalesOrder_0_7($id_so);
|
|
if ($datSo==FALSE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
}
|
|
|
|
$ket_so_a = preg_replace('/\R+/', " " , $ket_so_a);
|
|
$update = [
|
|
'STATUS_SO' => '4',
|
|
'KET_SO_A' => $ket_so_a
|
|
];
|
|
$action = $this->Penjualan->update('sales_order', $update, 'ID_SO', $id_so);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('data_lock', 'ditahan');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'ditahan');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
}
|
|
|
|
}
|
|
|
|
public function parsialorder_in_GA2() { //[19]
|
|
$method = $this->input->post('method');
|
|
$id_so = $this->input->post('id_so');
|
|
|
|
//Check Konsistensi Data
|
|
$datSo = $this->Penjualan->getData_SalesOrder_0_7($id_so);
|
|
if ($datSo==FALSE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
}
|
|
|
|
//Check apakah sudah terisi SN
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_bySO($id_so);
|
|
foreach ($datDo as $key) {
|
|
$datSnJual = $this->Penjualan->getData_SnJual_byDO($key['ID_DO']);
|
|
if ($datSnJual==TRUE) {
|
|
$this->session->set_flashdata('sn_do', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
//Check apakah ada Data Keluar Masuk Barang
|
|
$datIo = $this->Penjualan->getData_TransaksiStock_bySO_AllStatus($id_so);
|
|
if ($datIo==TRUE) {
|
|
$this->session->set_flashdata('data_used_io', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$update = [
|
|
'STATUS_SO' => '8'
|
|
];
|
|
$action = $this->Penjualan->update('sales_order', $update, 'ID_SO', $id_so);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('data_lock', 'masuk Mode Parsial');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'masuk Mode Parsial');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
}
|
|
|
|
}
|
|
|
|
public function revisiproyek_GA2() { //[20]
|
|
$method = $this->input->post('method');
|
|
$id_so = $this->input->post('id_so');
|
|
|
|
//Check Konsistensi Data
|
|
$datSo = $this->Penjualan->getData_SalesOrder_0_7($id_so);
|
|
if ($datSo==FALSE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
}
|
|
|
|
//Check Keluar Masuk apakah ada barang Proyek
|
|
$datIo = $this->Penjualan->getData_TransaksiStock_bySO_Jenis0_JoinProyek($id_so);
|
|
if ($datIo==FALSE) {
|
|
$this->session->set_flashdata('proyek_error', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah Kuantiti Proses kurang dari Kuantiti Transaksi Stock, dan apakah ada data SN
|
|
foreach ($datIo as $key) {
|
|
$datKuantiti = $this->Penjualan->getData_Kuantiti_byID($key['BARANG_ID']);
|
|
if ($datKuantiti[0]['PROSES_KUANTITI']<$key['QTY_IO']) {
|
|
$this->session->set_flashdata('qty_error_proyek', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$datSnio = $this->Penjualan->getData_SnIo_0($key['ID_IO']);
|
|
if ($datSnio==TRUE) {
|
|
$this->session->set_flashdata('sn_io', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach ($datIo as $key) {
|
|
$datKuantiti = $this->Penjualan->getData_Kuantiti_byID($key['BARANG_ID']);
|
|
$proses_kuantiti = $datKuantiti[0]['PROSES_KUANTITI'];
|
|
$proyek_kuantiti = $datKuantiti[0]['PROYEK_KUANTITI'];
|
|
$proses = $proses_kuantiti-$key['QTY_IO'];
|
|
$proyek = $proyek_kuantiti+$key['QTY_IO'];
|
|
$update = [
|
|
'PROSES_KUANTITI' => $proses,
|
|
'PROYEK_KUANTITI' => $proyek
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
}
|
|
|
|
//Set ID Proyek siapa tahu tidak terbaca setelah dihapus.
|
|
$id_proyek = $datIo[0]['PROYEK_ID'];
|
|
$action = $this->Penjualan->delete('transaksi_stock', $id_proyek, 'PROYEK_ID');
|
|
|
|
$update = [
|
|
'STATUS_PROYEK' => NULL
|
|
];
|
|
$action = $this->Penjualan->update('proyek', $update, 'ID_PROYEK', $id_proyek);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'diproses');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'diproses');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function konsinyasi_in_GA2() { //[21]
|
|
$method = $this->input->post('method');
|
|
$id_so = $this->input->post('id_so');
|
|
|
|
//Check Konsistensi Data
|
|
$datSo = $this->Penjualan->getData_SalesOrder_0_7($id_so);
|
|
if ($datSo==FALSE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
}
|
|
|
|
//Check apakah ada Data Konsinyasi untuk Kode Pelanggan ini.
|
|
$datDaftarKonsi = $this->Penjualan->getData_DaftarKonsi_byPELANGGAN_groupBARANG_Status0($datSo[0]['PELANGGAN_ID']);
|
|
if ($datDaftarKonsi==FALSE) {
|
|
$this->session->set_flashdata('konsinyasi_error', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah SN Barang sudah terisi
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_bySO($id_so);
|
|
foreach ($datDo as $key) {
|
|
$datSnJual = $this->Penjualan->getData_SnJual_byDO($key['ID_DO']);
|
|
if ($datSnJual==TRUE) {
|
|
$this->session->set_flashdata('sn_do', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
//Check apakah ada Proses Keluar Masuk barang
|
|
$datIo = $this->Penjualan->getData_TransaksiStock_bySO_AllStatus($id_so);
|
|
if ($datIo==TRUE) {
|
|
$this->session->set_flashdata('data_used_io', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$update = [
|
|
'STATUS_SO' => '9'
|
|
];
|
|
$action = $this->Penjualan->update('sales_order', $update, 'ID_SO', $id_so);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('data_lock', 'masuk Proses Konsinyasi');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'masuk Proses Konsinyasi');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
}
|
|
|
|
}
|
|
|
|
public function kodePenjualan() { //[22]
|
|
$kk = $this->Penjualan->getKode_Penjualan();
|
|
$tgl = date('y/m');
|
|
if (is_array($kk) || is_object($kk)) {
|
|
foreach ($kk as $row) {
|
|
if ($row['KODE'] == null) {
|
|
return "PJ/$tgl/00001";
|
|
} else {
|
|
$str = (string) $row['KODE'];
|
|
$tgl_lama = substr($str, 3, -6);
|
|
if ($tgl_lama!=$tgl) {
|
|
return "PJ/$tgl/00001";
|
|
} else {
|
|
$panjang = 5;
|
|
$data = substr($str, 9, $panjang);
|
|
$ko = (int) $data + 1;
|
|
$str = (string) $ko;
|
|
$panjang = 14 - strlen($str);
|
|
$data = "PJ/$tgl/00000";
|
|
$data = substr($data, 0, $panjang) . $str;
|
|
return $data;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function kodeSJPenjualan($id) { //[23]
|
|
$datSo = $this->Penjualan->getData_SalesOrder_byID($id);
|
|
$id_corp = $datSo[0]['CORP_ID'];
|
|
if ($id_corp=="1") {
|
|
$corp="TMP";
|
|
$kk = $this->Penjualan->getKode_SJPenjualanTMP();
|
|
} else if ($id_corp=="2") {
|
|
$corp="DMT";
|
|
$kk = $this->Penjualan->getKode_SJPenjualanDMT();
|
|
} else if ($id_corp=="3") {
|
|
$corp="PCM";
|
|
$kk = $this->Penjualan->getKode_SJPenjualanPCM();
|
|
} else if ($id_corp=="4") {
|
|
$corp="SFT";
|
|
$kk = $this->Penjualan->getKode_SJPenjualanSFT();
|
|
} else if ($id_corp=="5") {
|
|
$corp="ITP";
|
|
$kk = $this->Penjualan->getKode_SJPenjualanITP();
|
|
}
|
|
$tgl = date('y');
|
|
if (is_array($kk) || is_object($kk)) {
|
|
foreach ($kk as $row) {
|
|
if ($row['KODE'] == null) {
|
|
return "SJ/$corp/".$tgl."000001";
|
|
} else {
|
|
$str = (string) $row['KODE'];
|
|
$tgl_lama = substr($str, 7, -6);
|
|
if ($tgl_lama!=$tgl) {
|
|
return "SJ/$corp/".$tgl."000001";
|
|
} else {
|
|
$panjang = 6;
|
|
$data = substr($str, 9, $panjang);
|
|
$ko = (int) $data + 1;
|
|
$str = (string) $ko;
|
|
$panjang = 15 - strlen($str);
|
|
$data = "SJ/$corp/".$tgl."000000";
|
|
$data = substr($data, 0, $panjang) . $str;
|
|
return $data;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function kodeINVPenjualan($id) { //[24]
|
|
$datSo = $this->Penjualan->getData_SalesOrder_byID($id);
|
|
$id_corp = $datSo[0]['CORP_ID'];
|
|
if ($id_corp=="1") {
|
|
$corp="TMP";
|
|
$kk = $this->Penjualan->getKode_INVPenjualanTMP();
|
|
} else if ($id_corp=="2") {
|
|
$corp="DMT";
|
|
$kk = $this->Penjualan->getKode_INVPenjualanDMT();
|
|
} else if ($id_corp=="3") {
|
|
$corp="PCM";
|
|
$kk = $this->Penjualan->getKode_INVPenjualanPCM();
|
|
} else if ($id_corp=="4") {
|
|
$corp="SFT";
|
|
$kk = $this->Penjualan->getKode_INVPenjualanSFT();
|
|
} else if ($id_corp=="5") {
|
|
$corp="ITP";
|
|
$kk = $this->Penjualan->getKode_INVPenjualanITP();
|
|
}
|
|
$tgl = date('y');
|
|
if (is_array($kk) || is_object($kk)) {
|
|
foreach ($kk as $row) {
|
|
if ($row['KODE'] == null) {
|
|
return "INV/$corp/".$tgl."000001";
|
|
} else {
|
|
$str = (string) $row['KODE'];
|
|
$tgl_lama = substr($str, 8, -6);
|
|
if ($tgl_lama!=$tgl) {
|
|
return "INV/$corp/".$tgl."000001";
|
|
} else {
|
|
$panjang = 6;
|
|
$data = substr($str, 10, $panjang);
|
|
$ko = (int) $data + 1;
|
|
$str = (string) $ko;
|
|
$panjang = 16 - strlen($str);
|
|
$data = "INV/$corp/".$tgl."000000";
|
|
$data = substr($data, 0, $panjang) . $str;
|
|
return $data;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function kunciorder_GA2() { //[25]
|
|
$method = $this->input->post('method');
|
|
$id_so = $this->input->post('id_so');
|
|
$karyawanqc = $this->input->post('karyawanqc');
|
|
$level = $this->session->userdata('level');
|
|
$tgl = date('Y-m-d');
|
|
|
|
//Check Data Konsistensi
|
|
$datSo = $this->Penjualan->getData_SalesOrder_0_7($id_so);
|
|
if ($datSo==FALSE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
}
|
|
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_bySO($id_so);
|
|
//Check Apakah SN sudah terisi, dan apakah jumlah Barang Stok masih ada.
|
|
foreach ($datDo as $key) {
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$qtyReal = $this->Penjualan->getQtyReal_DaftarOrder($key['ID_DO']);
|
|
if ($qtyReal<$key['QTY_DO']) {
|
|
$this->session->set_flashdata('sn_check', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$datSnj = $this->Penjualan->getData_SnJual_byDO($key['ID_DO']);
|
|
foreach ($datSnj as $dat) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_SnJual_byNAMA_AllStatus($dat['NAMA_SNJ']);
|
|
if ($datSnStock[0]['STATUS_SNSTOCK']!="0") {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
if ($key['TYPE_JENIS']!="2") {
|
|
$datKuantiti = $this->Penjualan->getData_Kuantiti_byID($key['BARANG_ID']);
|
|
if ($level ==0) {
|
|
if ($datKuantiti[0]['PCM_KUANTITI']<$key['QTY_DO']) {
|
|
$this->session->set_flashdata('over_qty', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
} else if ($level ==1) {
|
|
if ($datKuantiti[0]['ITP_KUANTITI']<$key['QTY_DO']) {
|
|
$this->session->set_flashdata('over_qty', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$datIo_0 = $this->Penjualan->getData_TransaksiStock_bySO_Null_Jenis0($id_so);
|
|
//Check apakah SN Keluar sudah diisi, dan apakah Stok Proses sudah benar.
|
|
foreach ($datIo_0 as $key) {
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$qtyReal = $this->Penjualan->getQtyReal_TransaksiStock0($key['ID_IO']);
|
|
if ($qtyReal<$key['QTY_IO']) {
|
|
$this->session->set_flashdata('sn_check_io', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$datSnIo = $this->Penjualan->getData_SnIo_byIO_0($key['ID_IO']);
|
|
foreach ($datSnIo as $dat) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_byNAMA_AllStatus($dat['NAMA_SNIO']);
|
|
if ($datSnStock[0]['STATUS_SNSTOCK']!="0") {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
if ($key['TYPE_JENIS']!="2") {
|
|
$datKuantiti = $this->Penjualan->getData_Kuantiti_byID($key['BARANG_ID']);
|
|
if ($datKuantiti[0]['PROSES_KUANTITI']<$key['QTY_IO']) {
|
|
$this->session->set_flashdata('over_qty', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
|
|
$datIo_1 = $this->Penjualan->getData_TransaksiStock_bySO_Null_Jenis1($id_so);
|
|
//Check apakah SN Masuk sudah diisi, dan apakah Stok Proses sudah benar.
|
|
foreach ($datIo_1 as $key) {
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$qtyReal = $this->Penjualan->getQtyReal_TransaksiStock1($key['ID_IO']);
|
|
if ($qtyReal<$key['QTY_IO']) {
|
|
$this->session->set_flashdata('sn_check_io', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$datSnIo = $this->Penjualan->getData_SnIo_byIO_1($key['ID_IO']);
|
|
foreach ($datSnIo as $dat) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_byNAMA_AllStatus($dat['NAMA_SNIO']);
|
|
if ($datSnStock[0]['STATUS_SNSTOCK']!=NULL) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$datPelanggan = $this->Penjualan->getData_Pelanggan_byID($datSo[0]['PELANGGAN_ID']);
|
|
$kode_penjualan = $this->kodePenjualan();
|
|
$sj_penjualan = $this->kodeSJPenjualan($id_so);
|
|
$inv_penjualan = $this->kodeINVPenjualan($id_so);
|
|
$tempo_penjualan = $this->Penjualan->addTempoDay($tgl, $datPelanggan[0]['TOP_PELANGGAN']);
|
|
|
|
$input = [
|
|
'SO_ID' => $id_so,
|
|
'TGL_PENJUALAN' => $tgl,
|
|
'KODE_PENJUALAN' => $kode_penjualan,
|
|
'SJ_PENJUALAN' => $sj_penjualan,
|
|
'INV_PENJUALAN' => $inv_penjualan,
|
|
'TEMPO_PENJUALAN' => $tempo_penjualan,
|
|
'STATUS_PENJUALAN' => '1'
|
|
];
|
|
$action = $this->Penjualan->create('penjualan', $input);
|
|
|
|
$datPenjualan = $this->Penjualan->getID_PenjualanMax();
|
|
$id_penjualan = $datPenjualan[0]['ID_PENJUALAN'];
|
|
|
|
foreach ($datIo_0 as $key) {
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$datSnIo = $this->Penjualan->getData_SnIo_byIO_0($key['ID_IO']);
|
|
foreach ($datSnIo as $dat) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_byNAMA_AllStatus($dat['NAMA_SNIO']);
|
|
$input = [
|
|
'TGL_HSN' => $tgl,
|
|
'KODE_BUKTI' => $kode_penjualan,
|
|
'SJ_HSN' => $sj_penjualan,
|
|
'INV_HSN' => $inv_penjualan,
|
|
'PELANGGAN_ID' => $datSo[0]['PELANGGAN_ID'],
|
|
'SNSTOCK_ID' => $datSnStock[0]['ID_SNSTOCK']
|
|
];
|
|
$action = $this->Penjualan->create('histori_sn', $input);
|
|
$update = [
|
|
'STATUS_SNSTOCK' => '1'
|
|
];
|
|
$action = $this->Penjualan->update('sn_stock', $update, 'ID_SNSTOCK', $datSnStock[0]['ID_SNSTOCK']);
|
|
}
|
|
}
|
|
|
|
$datKuantiti = $this->Penjualan->getData_Kuantiti_byID($key['BARANG_ID']);
|
|
$proses_kuantiti = $datKuantiti[0]['PROSES_KUANTITI'];
|
|
$global_kuantiti = $datKuantiti[0]['GLOBAL_KUANTITI'];
|
|
$proses = $proses_kuantiti-$key['QTY_IO'];
|
|
$global = $global_kuantiti-$key['QTY_IO'];
|
|
$input = [
|
|
'TGL_HQ' => $tgl,
|
|
'KODE_BUKTI' => $kode_penjualan,
|
|
'SJ_HQ' => $sj_penjualan,
|
|
'INV_HQ' => $inv_penjualan,
|
|
'BARANG_ID' => $key['BARANG_ID'],
|
|
'KELUAR_HQ' => $key['QTY_IO'],
|
|
'MASUK_HQ' => '0'
|
|
];
|
|
$action = $this->Penjualan->create('histori_kuantiti', $input);
|
|
$update = [
|
|
'PROSES_KUANTITI' => $proses,
|
|
'GLOBAL_KUANTITI' => $global
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
$update = [
|
|
'STATUS_IO' => "1"
|
|
];
|
|
$action = $this->Penjualan->update('transaksi_stock', $update, 'ID_IO', $key['ID_IO']);
|
|
}
|
|
|
|
foreach ($datIo_1 as $key) {
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$datSnIo = $this->Penjualan->getData_SnIo_byIO_1($key['ID_IO']);
|
|
foreach ($datSnIo as $dat) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_byNAMA_AllStatus($dat['NAMA_SNIO']);
|
|
$input = [
|
|
'TGL_HSN' => $tgl,
|
|
'KODE_BUKTI' => $datSo[0]['KODE_SO'],
|
|
'SNSTOCK_ID' => $datSnStock[0]['ID_SNSTOCK']
|
|
];
|
|
$action = $this->Penjualan->create('histori_sn', $input);
|
|
}
|
|
}
|
|
|
|
$datKuantiti = $this->Penjualan->getData_Kuantiti_byID($key['BARANG_ID']);
|
|
if ($level == 0) {
|
|
$pcm_kuantiti = $datKuantiti[0]['PCM_KUANTITI'];
|
|
$global_kuantiti = $datKuantiti[0]['GLOBAL_KUANTITI'];
|
|
$pcm = $pcm_kuantiti+$key['QTY_IO'];
|
|
$global = $global_kuantiti+$key['QTY_IO'];
|
|
} else if ($level == 1) {
|
|
$itp_kuantiti = $datKuantiti[0]['ITP_KUANTITI'];
|
|
$global_kuantiti = $datKuantiti[0]['GLOBAL_KUANTITI'];
|
|
$itp = $itp_kuantiti+$key['QTY_IO'];
|
|
$global = $global_kuantiti+$key['QTY_IO'];
|
|
}
|
|
|
|
$nilai_hq = $key['QTY_IO'] * $key['HARGA_IO'];
|
|
$input = [
|
|
'TGL_HQ' => $tgl,
|
|
'KODE_BUKTI' => $kode_penjualan,
|
|
'SJ_HQ' => $sj_penjualan,
|
|
'INV_HQ' => $inv_penjualan,
|
|
'NILAI_HQ' => $nilai_hq,
|
|
'IO_ID' => $key['ID_IO'],
|
|
'BARANG_ID' => $key['BARANG_ID'],
|
|
'MASUK_HQ' => $key['QTY_IO'],
|
|
'KELUAR_HQ' => '0'
|
|
];
|
|
$action = $this->Penjualan->create('histori_kuantiti', $input);
|
|
if ($level == 0) {
|
|
$update = [
|
|
'PCM_KUANTITI' => $pcm,
|
|
'GLOBAL_KUANTITI' => $global
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
} else if ($level == 1) {
|
|
$update = [
|
|
'ITP_KUANTITI' => $itp,
|
|
'GLOBAL_KUANTITI' => $global
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
}
|
|
|
|
$update = [
|
|
'STATUS_IO' => "1"
|
|
];
|
|
$action = $this->Penjualan->update('transaksi_stock', $update, 'ID_IO', $key['ID_IO']);
|
|
}
|
|
|
|
foreach ($datDo as $key) {
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$datSnj = $this->Penjualan->getData_SnJual_byDO($key['ID_DO']);
|
|
foreach ($datSnj as $dat) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_byNAMA_AllStatus($dat['NAMA_SNJ']);
|
|
$input = [
|
|
'TGL_HSN' => $tgl,
|
|
'KODE_BUKTI' => $kode_penjualan,
|
|
'SJ_HSN' => $sj_penjualan,
|
|
'INV_HSN' => $inv_penjualan,
|
|
'SNSTOCK_ID' => $datSnStock[0]['ID_SNSTOCK'],
|
|
'PELANGGAN_ID' => $key['PELANGGAN_ID'],
|
|
];
|
|
$action = $this->Penjualan->create('histori_sn', $input);
|
|
$update = [
|
|
'STATUS_SNSTOCK' => '1'
|
|
];
|
|
$action = $this->Penjualan->update('sn_stock', $update, 'ID_SNSTOCK', $datSnStock[0]['ID_SNSTOCK']);
|
|
}
|
|
}
|
|
|
|
if ($key['TYPE_JENIS']!="2") {
|
|
$datKuantiti = $this->Penjualan->getData_Kuantiti_byID($key['BARANG_ID']);
|
|
if ($level == 0) {
|
|
$pcm_kuantiti = $datKuantiti[0]['PCM_KUANTITI'];
|
|
$global_kuantiti = $datKuantiti[0]['GLOBAL_KUANTITI'];
|
|
$pcm = $pcm_kuantiti-$key['QTY_DO'];
|
|
$global = $global_kuantiti-$key['QTY_DO'];
|
|
} else if ($level == 1) {
|
|
$itp_kuantiti = $datKuantiti[0]['ITP_KUANTITI'];
|
|
$global_kuantiti = $datKuantiti[0]['GLOBAL_KUANTITI'];
|
|
$itp = $itp_kuantiti-$key['QTY_DO'];
|
|
$global = $global_kuantiti-$key['QTY_DO'];
|
|
}
|
|
$input = [
|
|
'TGL_HQ' => $tgl,
|
|
'KODE_BUKTI' => $kode_penjualan,
|
|
'SJ_HQ' => $sj_penjualan,
|
|
'INV_HQ' => $inv_penjualan,
|
|
'BARANG_ID' => $key['BARANG_ID'],
|
|
'KELUAR_HQ' => $key['QTY_DO'],
|
|
'MASUK_HQ' => '0'
|
|
];
|
|
$action = $this->Penjualan->create('histori_kuantiti', $input);
|
|
if ($level ==0) {
|
|
$update = [
|
|
'PCM_KUANTITI' => $pcm,
|
|
'GLOBAL_KUANTITI' => $global
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
} else if ($level ==1) {
|
|
$update = [
|
|
'ITP_KUANTITI' => $itp,
|
|
'GLOBAL_KUANTITI' => $global
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
}
|
|
}
|
|
|
|
if ($datPelanggan[0]['TYPE_PELANGGAN']=="1") {
|
|
$komisi_do = $key['KOMISI_DEALER'];
|
|
} else {
|
|
$komisi_do = $key['KOMISI_USER'];
|
|
}
|
|
|
|
$datBarang = $this->Penjualan->getData_Barang_byID($key['BARANG_ID']);
|
|
$update = [
|
|
'NAMA_DO' => $datBarang[0]['NAMA_BARANG'],
|
|
'KOMISI_DO' => $komisi_do,
|
|
];
|
|
$action = $this->Penjualan->update('daftar_order', $update, 'ID_DO', $key['ID_DO']);
|
|
}
|
|
|
|
foreach ($karyawanqc as $key) {
|
|
$input = [
|
|
'SO_ID' => $id_so,
|
|
'KARYAWAN_ID' => $key,
|
|
'TGL_QC' => $tgl
|
|
];
|
|
$action = $this->Penjualan->create('quality_control', $input);
|
|
}
|
|
|
|
$debet_pda = 0;
|
|
foreach ($datDo as $key) {
|
|
$subtotal = $key['QTY_DO']*$key['HARGA_DO'];
|
|
$debet_pda = $debet_pda+$subtotal;
|
|
}
|
|
|
|
$ppn_pda = $debet_pda*($datSo[0]['PPN_SO']/100);
|
|
$debet_pda = $debet_pda*((100+$datSo[0]['PPN_SO'])/100);
|
|
$debet_pda = round($debet_pda);
|
|
|
|
if ($level == 0) {
|
|
$update = [
|
|
'STATUS_SO' => '1',
|
|
'KET_SO_A' => NULL,
|
|
'TGL_SO' => $tgl,
|
|
'NILAI_SO' => $debet_pda
|
|
];
|
|
$action = $this->Penjualan->update('sales_order', $update, 'ID_SO', $id_so);
|
|
} else if ($level == 1) {
|
|
$tgl_selesai = date('d/m/Y H:i:s');
|
|
$tgl_ket = date('d/m/Y');
|
|
$id_kunci = $this->session->userdata('id_karyawan');
|
|
$ket_so_a = "Sudah diproses oleh ITP Tanggal $tgl_ket";
|
|
$update = [
|
|
'STATUS_SO' => '1',
|
|
'KET_SO_A' => NULL,
|
|
'TGL_SO' => $tgl,
|
|
'NILAI_SO' => $debet_pda,
|
|
'KET_SO_A' => $ket_so_a,
|
|
'KUNCI_ID' => $id_kunci,
|
|
'TS_SIAPKIRIM' => $tgl_selesai,
|
|
'TS_TERKUNCI' => $tgl_selesai,
|
|
'TS_TERKIRIM' => $tgl_selesai,
|
|
'TGL_KIRIM' => $tgl,
|
|
];
|
|
$action = $this->Penjualan->update('sales_order', $update, 'ID_SO', $id_so);
|
|
|
|
$input = [
|
|
'KARYAWAN_ID' => '21',
|
|
'SO_ID' => $id_so
|
|
];
|
|
$action = $this->Penjualan->create('jadwal_pengiriman', $input);
|
|
}
|
|
|
|
$ket_pda = "No Nota : $inv_penjualan";
|
|
$input = [
|
|
'TRANSAKSI_PDA' => '0',
|
|
'PENJUALAN_ID' => $id_penjualan,
|
|
'DEBET_PDA' => $debet_pda,
|
|
'KREDIT_PDA' => '0',
|
|
'KODE_BUKTI' => $kode_penjualan,
|
|
'PELANGGAN_ID' => $datSo[0]['PELANGGAN_ID'],
|
|
'TGL_PDA' => $tgl,
|
|
'KET_PDA' => $ket_pda
|
|
];
|
|
$action = $this->Penjualan->create('piutang_dagang', $input);
|
|
|
|
$update = [
|
|
'KET_PENJUALAN' => $ket_pda,
|
|
'KOP_ID' => $datSo[0]['CORP_ID'],
|
|
];
|
|
$action = $this->Penjualan->update('penjualan', $update, 'ID_PENJUALAN', $id_penjualan);
|
|
|
|
$datKaryawan = $this->Penjualan->getData_Karyawan_byID($datSo[0]['SALES_ID']);
|
|
$username = $datKaryawan[0]['USERNAME'];
|
|
$dateFull = date('Y-m-d H:i:s');
|
|
|
|
//Automatis Cetak SJ jika SO dari Service
|
|
if ($username=="service") {
|
|
$input = [
|
|
'SJ_INV' => '0',
|
|
'TGL_CD' => $tgl,
|
|
'KODE_BUKTI' => $sj_penjualan,
|
|
'PENJUALAN_ID' => $id_penjualan,
|
|
'STATUS_CD' => '0',
|
|
'TGL_CETAK' => $tgl,
|
|
'KARYAWAN_ID' => '1',
|
|
'LP_KARYAWAN' => $dateFull,
|
|
];
|
|
$action = $this->Penjualan->create('cetak_dokumen', $input);
|
|
} else {
|
|
$input = [
|
|
'SJ_INV' => '0',
|
|
'TGL_CD' => $tgl,
|
|
'KODE_BUKTI' => $sj_penjualan,
|
|
'PENJUALAN_ID' => $id_penjualan
|
|
];
|
|
$action = $this->Penjualan->create('cetak_dokumen', $input);
|
|
}
|
|
|
|
$input = [
|
|
'SJ_INV' => '1',
|
|
'DP_CD' => '0',
|
|
'TGL_CD' => $tgl,
|
|
'KODE_BUKTI' => $inv_penjualan,
|
|
'PENJUALAN_ID' => $id_penjualan
|
|
];
|
|
$action = $this->Penjualan->create('cetak_dokumen', $input);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('data_lock_print', 'dikunci');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dikunci');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
}
|
|
|
|
}
|
|
|
|
public function dataOrder_Gudang_A3_SO($id) { //[26]
|
|
$level = $this->session->userdata('level');
|
|
$penjualan = $this->Penjualan->getData_DaftarOrder_byID($id);
|
|
$max = $this->Penjualan->getQtyReal_DaftarOrder($id);
|
|
$datSnStock = $this->Penjualan->getData_SnStock_byBARANG($penjualan[0]['BARANG_ID'], $level);
|
|
|
|
$data = [
|
|
'sidebar' => "menu penjualan",
|
|
'navChild' => "penjualan step2",
|
|
'penjualan' => $penjualan,
|
|
'snstock' => $datSnStock,
|
|
'count_snstock' => count($datSnStock),
|
|
'id_do' => $id,
|
|
'qty' => $penjualan[0]['QTY_DO'],
|
|
'kode_barang' => $penjualan[0]['KODE_BARANG'],
|
|
'max' => $max,
|
|
];
|
|
|
|
$this->load->view('proses/PenjualanOrder_Gudang_A3_SO', $data);
|
|
}
|
|
|
|
public function viewSn_Penjualan_SO_Aktif() { //[27]
|
|
$id = $this->input->post('id');
|
|
$data = $this->Penjualan->getData_SnJual_byDO($id);
|
|
$this->output_json(['value' => 1, 'total' => sizeof($data), 'data' => $data]);
|
|
}
|
|
|
|
public function viewSn_Penjualan_SO_Limit() { //[28]
|
|
$id = $this->input->post('id');
|
|
$data = $this->Penjualan->getData_SnJual_byDO($id);
|
|
$this->output_json(['value' => 1, 'jumlah_data' => sizeof($data)]);
|
|
}
|
|
|
|
public function simpanorder_GA3() { //[29]
|
|
$id = $this->input->post('id_snj');
|
|
$id_do = $this->input->post('id_do');
|
|
$nama_snj = $this->input->post('nama_snj');
|
|
$nama_snj = strtoupper($nama_snj);
|
|
|
|
//Check Konsistensi Data
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_byID($id_do);
|
|
if ($datDo==FALSE) {
|
|
$this->output_json(['value' => 0]);
|
|
} else {
|
|
$value = 1;
|
|
}
|
|
|
|
if ($value==1) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_SnJual_byNAMA_AllStatus($nama_snj);
|
|
if ($datSnStock==FALSE) {
|
|
$value = 3;
|
|
} else {
|
|
$value = 1;
|
|
}
|
|
|
|
if ($value==3) {
|
|
$this->output_json(['value' => $value]);
|
|
} else if ($value==1) {
|
|
|
|
$id_snstock = $datSnStock[0]['ID_SNSTOCK'];
|
|
$datSnJual = $this->Penjualan->getData_SnJual_SnStock_byNAMA_0($nama_snj);
|
|
if ($datSnJual==TRUE) {
|
|
$value = 4;
|
|
} else {
|
|
$value = 1;
|
|
}
|
|
|
|
if ($value==4) {
|
|
$this->output_json(['value' => 4]);
|
|
} else if ($value==1) {
|
|
$barang_idDo = $datDo[0]['BARANG_ID'];
|
|
$barang_idSn = $datSnStock[0]['BARANG_ID'];
|
|
if ($barang_idDo!=$barang_idSn) {
|
|
$this->output_json(['value' => 5]);
|
|
} else {
|
|
$status_snstock = $datSnStock[0]['STATUS_SNSTOCK'];
|
|
if ($status_snstock==NULL) {
|
|
$qtyRealBefore = $this->Penjualan->getQtyReal_DaftarOrder($id_do);
|
|
if ($qtyRealBefore>=$datDo[0]['QTY_DO']) {
|
|
$this->output_json(['value' => 0]);
|
|
} else {
|
|
$input = [
|
|
'NAMA_SNJ' => $nama_snj,
|
|
'DO_ID' => $id_do
|
|
];
|
|
$action = $this->Penjualan->create('sn_jual', $input);
|
|
$update = [
|
|
'STATUS_SNSTOCK' => '0'
|
|
];
|
|
$action = $this->Penjualan->update('sn_stock', $update, 'ID_SNSTOCK', $id_snstock);
|
|
$qtyRealAfter = $this->Penjualan->getQtyReal_DaftarOrder($id_do);
|
|
if ($datDo[0]['QTY_DO']==$qtyRealAfter) {
|
|
$this->output_json(['value' => 2, 'id' => $id, 'nama_snj' => $nama_snj]);
|
|
$this->session->set_flashdata('quota_full', 'warning');
|
|
} else if ($action) {
|
|
$this->output_json(['value' => 1, 'id' => $id, 'nama_snj' => $nama_snj]);
|
|
} else {
|
|
$this->output_json(['value' => 0]);
|
|
}
|
|
}
|
|
} else {
|
|
$this->output_json(['value' => 0]);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public function hapusorder_GA3() { //[30]
|
|
$id = $this->input->post('id_snj');
|
|
|
|
$datSnj = $this->Penjualan->getData_SnJual_byID($id);
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_byID($datSnj[0]['DO_ID']);
|
|
$qty_do = $datDo[0]['QTY_DO'];
|
|
$qtyReal = $this->Penjualan->getQtyReal_DaftarOrder($datSnj[0]['DO_ID']);
|
|
$datSnStock = $this->Penjualan->getData_SnStock_byNAMA_AllStatus($datSnj[0]['NAMA_SNJ']);
|
|
|
|
$update = [
|
|
'STATUS_SNSTOCK' => NULL
|
|
];
|
|
$action = $this->Penjualan->update('sn_stock', $update, 'ID_SNSTOCK', $datSnStock[0]['ID_SNSTOCK']);
|
|
$action = $this->Penjualan->delete('sn_jual', $id, 'ID_SNJ');
|
|
|
|
if ($qtyReal==$qty_do){
|
|
$this->output_json(['value' => 2, 'message' => 'Berhasil', 'dt' => $action]);
|
|
$this->session->set_flashdata('quota_free', 'warning');
|
|
} else {
|
|
if ($action) {
|
|
$this->output_json(['value' => 1, 'message' => 'Berhasil', 'dt' => $action]);
|
|
} else {
|
|
$this->output_json(['value' => 0, 'message' => "gagal", 'dt' => $action]);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function dataOrder_Gudang_A3_IO_0($id) { //[31]
|
|
$level = $this->session->userdata('level');
|
|
$penjualan = $this->Penjualan->getData_TransaksiStock_byID($id);
|
|
$max = $this->Penjualan->getQtyReal_TransaksiStock0($id);
|
|
$datSnStock = $this->Penjualan->getData_SnStock_byBARANG($penjualan[0]['BARANG_ID'], $level);
|
|
|
|
$data = [
|
|
'sidebar' => "menu penjualan",
|
|
'navChild' => "penjualan step2",
|
|
'penjualan' => $penjualan,
|
|
'snstock' => $datSnStock,
|
|
'count_snstock' => count($datSnStock),
|
|
'id_io' => $id,
|
|
'qty' => $penjualan[0]['QTY_IO'],
|
|
'kode_barang' => $penjualan[0]['KODE_BARANG'],
|
|
'max' => $max,
|
|
];
|
|
|
|
$this->load->view('proses/PenjualanOrder_Gudang_A3_IO_0', $data);
|
|
}
|
|
|
|
public function viewSn_Penjualan_IO_0_Aktif() { //[32]
|
|
$id = $this->input->post('id');
|
|
$data = $this->Penjualan->getData_SnIo_byIO_0($id);
|
|
$this->output_json(['value' => 1, 'total' => sizeof($data), 'data' => $data]);
|
|
}
|
|
|
|
public function viewSn_Penjualan_IO_0_Limit() { //[33]
|
|
$id = $this->input->post('id');
|
|
$data = $this->Penjualan->getData_SnIo_byIO_0($id);
|
|
$this->output_json(['value' => 1, 'jumlah_data' => sizeof($data)]);
|
|
}
|
|
|
|
public function simpanorder_IO_0_GA3() { //[34]
|
|
$id = $this->input->post('id_snio');
|
|
$id_io = $this->input->post('id_io');
|
|
$nama_snio = $this->input->post('nama_snio');
|
|
$nama_snio = strtoupper($nama_snio);
|
|
|
|
//Check Konsistensi Data
|
|
$datIo = $this->Penjualan->getData_TransaksiStock_byID($id_io);
|
|
if ($datIo==FALSE) {
|
|
$this->output_json(['value' => 0]);
|
|
} else {
|
|
$value = 1;
|
|
}
|
|
|
|
if ($value==1) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_SnIo_byNAMA_AllStatus($nama_snio);
|
|
if ($datSnStock==FALSE) {
|
|
$value = 3;
|
|
} else {
|
|
$value = 1;
|
|
}
|
|
|
|
if ($value==3) {
|
|
$this->output_json(['value' => $value]);
|
|
} else if ($value==1) {
|
|
$id_snstock = $datSnStock[0]['ID_SNSTOCK'];
|
|
$datSnIo = $this->Penjualan->getData_SnIo_SnStock_byNAMA_0($nama_snio);
|
|
if ($datSnIo==TRUE) {
|
|
$value = 4;
|
|
} else {
|
|
$value = 1;
|
|
}
|
|
|
|
if ($value==4) {
|
|
$this->output_json(['value' => 4]);
|
|
} else if ($value==1) {
|
|
$barang_idIo = $datIo[0]['BARANG_ID'];
|
|
$barang_idSn = $datSnStock[0]['BARANG_ID'];
|
|
if ($barang_idIo!=$barang_idSn) {
|
|
$this->output_json(['value' => 5]);
|
|
} else {
|
|
$status_snstock = $datSnStock[0]['STATUS_SNSTOCK'];
|
|
if ($status_snstock==NULL) {
|
|
$qtyRealBefore = $this->Penjualan->getQtyReal_TransaksiStock0($id_io);
|
|
if ($qtyRealBefore>=$datIo[0]['QTY_IO']) {
|
|
$this->output_json(['value' => 0]);
|
|
} else {
|
|
$input = [
|
|
'NAMA_SNIO' => $nama_snio,
|
|
'IO_ID' => $id_io,
|
|
'JENIS_SNIO' => '0'
|
|
];
|
|
$action = $this->Penjualan->create('sn_io', $input);
|
|
$update = [
|
|
'STATUS_SNSTOCK' => '0'
|
|
];
|
|
$action = $this->Penjualan->update('sn_stock', $update, 'ID_SNSTOCK', $id_snstock);
|
|
$qtyRealAfter = $this->Penjualan->getQtyReal_TransaksiStock0($id_io);
|
|
if ($datIo[0]['QTY_IO']==$qtyRealAfter) {
|
|
$this->output_json(['value' => 2, 'id' => $id, 'nama_snio' => $nama_snio]);
|
|
$this->session->set_flashdata('quota_full', 'warning');
|
|
} else if ($action) {
|
|
$this->output_json(['value' => 1, 'id' => $id, 'nama_snio' => $nama_snio]);
|
|
} else {
|
|
$this->output_json(['value' => 0, 'id' => $id, 'nama_snio' => $nama_snio]);
|
|
}
|
|
}
|
|
} else {
|
|
$this->output_json(['value' => 0]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function hapusorder_IO_0_GA3() { //[35]
|
|
$id = $this->input->post('id_snio');
|
|
|
|
$datSnIO = $this->Penjualan->getData_SnIo_byID($id);
|
|
$nama_snio = $datSnIO[0]['NAMA_SNIO'];
|
|
$qtyReal = $this->Penjualan->getQtyReal_TransaksiStock0($datSnIO[0]['IO_ID']);
|
|
$datIo = $this->Penjualan->getData_TransaksiStock_byID($datSnIO[0]['IO_ID']);
|
|
$qty_io = $datIo[0]['QTY_IO'];
|
|
$datSnStock = $this->Penjualan->getData_SnStock_byNAMA_AllStatus($nama_snio);
|
|
|
|
$update = [
|
|
'STATUS_SNSTOCK' => NULL
|
|
];
|
|
$action = $this->Penjualan->update('sn_stock', $update, 'ID_SNSTOCK', $datSnStock[0]['ID_SNSTOCK']);
|
|
$action = $this->Penjualan->delete('sn_io', $id, 'ID_SNIO');
|
|
|
|
if ($qtyReal==$qty_io){
|
|
$this->output_json(['value' => 2, 'message' => 'Berhasil', 'dt' => $action]);
|
|
$this->session->set_flashdata('quota_free', 'warning');
|
|
} else {
|
|
if ($action) {
|
|
$this->output_json(['value' => 1, 'message' => 'Berhasil', 'dt' => $action]);
|
|
} else {
|
|
$this->output_json(['value' => 0, 'message' => "gagal", 'dt' => $action]);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function dataOrder_Gudang_A3_IO_1($id) { //[36]
|
|
$level = $this->session->userdata('level');
|
|
$penjualan = $this->Penjualan->getData_TransaksiStock_byID($id);
|
|
$max = $this->Penjualan->getQtyReal_TransaksiStock1($id);
|
|
$datSnStock = $this->Penjualan->getData_SnStock_byBARANG($penjualan[0]['BARANG_ID'], $level);
|
|
|
|
$data = [
|
|
'sidebar' => "menu penjualan",
|
|
'navChild' => "penjualan step2",
|
|
'penjualan' => $penjualan,
|
|
'snstock' => $datSnStock,
|
|
'count_snstock' => count($datSnStock),
|
|
'id_io' => $id,
|
|
'qty' => $penjualan[0]['QTY_IO'],
|
|
'kode_barang' => $penjualan[0]['KODE_BARANG'],
|
|
'max' => $max,
|
|
];
|
|
|
|
$this->load->view('proses/PenjualanOrder_Gudang_A3_IO_1', $data);
|
|
}
|
|
|
|
public function viewSn_Penjualan_IO_1_Aktif() { //[37]
|
|
$id = $this->input->post('id');
|
|
$data = $this->Penjualan->getData_SnIo_byIO_1($id);
|
|
$this->output_json(['value' => 1, 'total' => sizeof($data), 'data' => $data]);
|
|
}
|
|
|
|
public function viewSn_Penjualan_IO_1_Limit() { //[38]
|
|
$id = $this->input->post('id');
|
|
$data = $this->Penjualan->getData_SnIo_byIO_1($id);
|
|
$this->output_json(['value' => 1, 'jumlah_data' => sizeof($data)]);
|
|
}
|
|
|
|
public function simpanorder_IO_1_GA3() { //[39]
|
|
$id = $this->input->post('id_snio');
|
|
$id_io = $this->input->post('id_io');
|
|
$nama_snio = $this->input->post('nama_snio');
|
|
$nama_snio = strtoupper($nama_snio);
|
|
|
|
//Check Konsistensi Data
|
|
$datIo = $this->Penjualan->getData_TransaksiStock_byID($id_io);
|
|
if ($datIo==FALSE) {
|
|
$this->output_json(['value' => 0]);
|
|
} else {
|
|
$value = 1;
|
|
}
|
|
|
|
if ($value==1) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_SnIo_byNAMA_AllStatus($nama_snio);
|
|
if ($datSnStock==TRUE) {
|
|
$value = 3;
|
|
} else {
|
|
$value = 1;
|
|
}
|
|
|
|
if ($value==3) {
|
|
$this->output_json(['value' => $value]);
|
|
} else if ($value==1) {
|
|
$qtyRealBefore = $this->Penjualan->getQtyReal_TransaksiStock1($id_io);
|
|
if ($qtyRealBefore>=$datIo[0]['QTY_IO']) {
|
|
$this->output_json(['value' => 0]);
|
|
} else {
|
|
$input = [
|
|
'NAMA_SNIO' => $nama_snio,
|
|
'JENIS_SNIO' => '1',
|
|
'IO_ID' => $id_io
|
|
];
|
|
$action = $this->Penjualan->create('sn_io', $input);
|
|
$input = [
|
|
'NAMA_SNSTOCK' => $nama_snio,
|
|
'BARANG_ID' => $datIo[0]['BARANG_ID'],
|
|
'GUDANG_SNSTOCK' => '1',
|
|
];
|
|
$action = $this->Penjualan->create('sn_stock', $input);
|
|
$qtyRealAfter = $this->Penjualan->getQtyReal_TransaksiStock1($id_io);
|
|
if ($datIo[0]['QTY_IO']==$qtyRealAfter) {
|
|
$this->output_json(['value' => 2, 'id' => $id, 'nama_snio' => $nama_snio]);
|
|
$this->session->set_flashdata('quota_full', 'warning');
|
|
} else if ($action) {
|
|
$this->output_json(['value' => 1, 'id' => $id, 'nama_snio' => $nama_snio]);
|
|
} else {
|
|
$this->output_json(['value' => 0, 'id' => $id, 'nama_snio' => $nama_snio]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function hapusorder_IO_1_GA3() { //[40]
|
|
$id = $this->input->post('id_snio');
|
|
|
|
$datSnIo = $this->Penjualan->getData_SnIo_byID($id);
|
|
$nama_snio = $datSnIo[0]['NAMA_SNIO'];
|
|
$qtyReal = $this->Penjualan->getQtyReal_TransaksiStock1($datSnIo[0]['IO_ID']);
|
|
$datIo = $this->Penjualan->getData_TransaksiStock_byID($datSnIo[0]['IO_ID']);
|
|
$qty_io = $datIo[0]['QTY_IO'];
|
|
$datSnStock = $this->Penjualan->getData_SnStock_byNAMA_AllStatus($nama_snio);
|
|
|
|
$action = $this->Penjualan->delete('sn_io', $id, 'ID_SNIO');
|
|
$action = $this->Penjualan->delete('sn_stock', $datSnStock[0]['ID_SNSTOCK'], 'ID_SNSTOCK');
|
|
|
|
if ($qtyReal==$qty_io){
|
|
$this->output_json(['value' => 2, 'message' => 'Berhasil', 'dt' => $action]);
|
|
$this->session->set_flashdata('quota_free', 'warning');
|
|
} else {
|
|
if ($action) {
|
|
$this->output_json(['value' => 1, 'message' => 'Berhasil', 'dt' => $action]);
|
|
} else {
|
|
$this->output_json(['value' => 0, 'message' => "gagal", 'dt' => $action]);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function dataOrder_Gudang_A2_Buka($id) { //[41]
|
|
$penjualan = $this->Penjualan->getData_DaftarOrder_bySO($id);
|
|
$datSo = $this->Penjualan->getData_SalesOrder_byID($id);
|
|
|
|
//Set SN jika diisi
|
|
$no = 0;
|
|
foreach ($penjualan as $key) {
|
|
$datSnJual = $this->Penjualan->getData_SnJual_byDO($key['ID_DO']);
|
|
$penjualan[$no++] += ['SN' => $datSnJual];
|
|
}
|
|
|
|
$data = [
|
|
'sidebar' => "menu penjualan",
|
|
'navChild' => "penjualan step2",
|
|
'penjualan' => $penjualan,
|
|
'kode_so' => $datSo[0]['KODE_SO'],
|
|
'ket_so_g' => $datSo[0]['KET_SO_G'],
|
|
'ket_so_k' => $datSo[0]['KET_SO_K'],
|
|
'ket_so_t' => $datSo[0]['KET_SO_T'],
|
|
'ket_so_p' => $datSo[0]['KET_SO_P'],
|
|
'ket_so_a' => $datSo[0]['KET_SO_A'],
|
|
'nama_sales' => $datSo[0]['NAMA_PANGGILAN_KARYAWAN'],
|
|
'nama_pelanggan'=> $datSo[0]['NAMA_PELANGGAN'],
|
|
'nama_kota' => $datSo[0]['NAMA_KOTA'],
|
|
'id_so' => $id
|
|
];
|
|
|
|
$this->load->view('proses/PenjualanOrder_Gudang_A2_Buka', $data);
|
|
}
|
|
|
|
public function bukaorder_GA2() { //[42]
|
|
$method = $this->input->post('method');
|
|
$id_so = $this->input->post('id_so');
|
|
|
|
//Check Konsistensi Data
|
|
$datSo = $this->Penjualan->getData_SalesOrder_4($id_so);
|
|
if ($datSo==FALSE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
}
|
|
|
|
$update = [
|
|
'STATUS_SO' => '0',
|
|
'KET_SO_A' => NULL
|
|
];
|
|
$action = $this->Penjualan->update('sales_order', $update, 'ID_SO', $id_so);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('data_lock', 'dibuka');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dibuka');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
}
|
|
|
|
}
|
|
|
|
public function dataOrder_Gudang_A2_Parsial($id) { //[43]
|
|
$penjualan = $this->Penjualan->getData_DaftarOrder_bySO_forParsial($id);
|
|
$datSjp = $this->Penjualan->getData_DaftarSjParsial_bySO_CDNull($id);
|
|
$datCd = $this->Penjualan->getData_CetakDokumen_forParsial($id);
|
|
$level = $this->session->userdata('level');
|
|
$barangParsialNonJasa = $this->Penjualan->getBarang_forParsialNonJasa($id, $level);
|
|
$barangParsialJasaBiaya = $this->Penjualan->getData_Barang_forParsialJasaBiaya($id);
|
|
$datKaryawan = $this->Penjualan->getData_Karyawan_Qc();
|
|
$potong_part = $this->Penjualan->getData_HargaPart_byID();
|
|
$barangKeluar = $this->Penjualan->getBarang_TypeAll_jenisKeluar($level);
|
|
$barangMasuk = $this->Penjualan->getBarang_TypeAll_jenisMasuk();
|
|
$datIoMasuk = $this->Penjualan->getData_TransaksiStock_bySO_Null_Jenis1($id);
|
|
$datIoKeluar = $this->Penjualan->getData_TransaksiStock_bySO_Null_Jenis0($id);
|
|
$datSo = $this->Penjualan->getData_SalesOrder_byID($id);
|
|
|
|
//Set Nilai Real SN yang terisi
|
|
$no = 0;
|
|
foreach ($datSjp as $key) {
|
|
$qtyReal = $this->Penjualan->getQtyReal_DaftarSjParsial($key['ID_SJP']);
|
|
$datSjp[$no++] += ['REAL' => $qtyReal];
|
|
}
|
|
|
|
$no = 0;
|
|
foreach ($datIoMasuk as $key) {
|
|
$qtyReal = $this->Penjualan->getQtyReal_TransaksiStock1($key['ID_IO']);
|
|
$datIoMasuk[$no++] += ['REAL' => $qtyReal];
|
|
}
|
|
|
|
$no = 0;
|
|
foreach ($datIoKeluar as $key) {
|
|
$qtyReal = $this->Penjualan->getQtyReal_TransaksiStock0($key['ID_IO']);
|
|
$datIoKeluar[$no++] += ['REAL' => $qtyReal];
|
|
}
|
|
|
|
$data = [
|
|
'sidebar' => "menu penjualan",
|
|
'navChild' => "penjualan step2",
|
|
'penjualan' => $penjualan,
|
|
'sjp' => $datSjp,
|
|
'cd' => $datCd,
|
|
'kode_so' => $datSo[0]['KODE_SO'],
|
|
'ket_so_g' => $datSo[0]['KET_SO_G'],
|
|
'ket_so_k' => $datSo[0]['KET_SO_K'],
|
|
'ket_so_t' => $datSo[0]['KET_SO_T'],
|
|
'ket_so_p' => $datSo[0]['KET_SO_P'],
|
|
'nama_pelanggan' => $datSo[0]['NAMA_PELANGGAN'],
|
|
'id_so' => $id,
|
|
'masuk' => $datIoMasuk,
|
|
'keluar' => $datIoKeluar,
|
|
'barang_masuk' => $barangMasuk,
|
|
'barang_keluar' => $barangKeluar,
|
|
'barang_parsial' => $barangParsialNonJasa,
|
|
'jasa_parsial' => $barangParsialJasaBiaya,
|
|
'qc' => $datKaryawan,
|
|
'potong_part' => $potong_part
|
|
];
|
|
|
|
$this->load->view('proses/PenjualanOrder_Gudang_A2_Parsial', $data);
|
|
}
|
|
|
|
public function parsialorder_out_GA2() { //[44]
|
|
$method = $this->input->post('method');
|
|
$id_so = $this->input->post('id_so');
|
|
|
|
//Check Konsistensi Data
|
|
$datSo = $this->Penjualan->getData_SalesOrder_8($id_so);
|
|
if ($datSo==FALSE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
}
|
|
|
|
//Check apakah sudah terisi Data Parsial
|
|
$datSjp = $this->Penjualan->getData_DaftarSjParsial_bySO_allStatus($id_so);
|
|
if ($datSjp==TRUE) {
|
|
$this->session->set_flashdata('data_used_parsial', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah sudah terisi Keluar Masuk Barang
|
|
$datIo = $this->Penjualan->getData_TransaksiStock_bySO_AllStatus($id_so);
|
|
if ($datIo==TRUE) {
|
|
$this->session->set_flashdata('data_used_io', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah ada SJ yang tercetak
|
|
$datCd = $this->Penjualan->getData_CetakDokumen_forParsial($id_so);
|
|
if ($datCd==TRUE) {
|
|
$this->session->set_flashdata('data_used_cd', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$update = [
|
|
'STATUS_SO' => '0'
|
|
];
|
|
$action = $this->Penjualan->update('sales_order', $update, 'ID_SO', $id_so);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('data_lock', 'keluar Mode Parsial');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'keluar Mode Parsial');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
}
|
|
|
|
}
|
|
|
|
public function simpanparsial_GA2() { //[45]
|
|
$method = $this->input->post('method');
|
|
$id_so = $this->input->post('id_so');
|
|
$id_barang = $this->input->post('id_barang');
|
|
$qty_sjp = $this->input->post('qty_sjp');
|
|
$ket_sjp = $this->input->post('ket_sjp');
|
|
$level = $this->session->userdata('level');
|
|
|
|
//Check Konsistensi Data
|
|
$datSo = $this->Penjualan->getData_SalesOrder_8($id_so);
|
|
if ($datSo==FALSE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
}
|
|
|
|
//Check apakah Kuantiti diisi Kurang dari sama dengan 0
|
|
if ($qty_sjp<=0) {
|
|
$this->session->set_flashdata('not_zero_negative', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah barang yang dipilih punya Stok
|
|
$datBarang = $this->Penjualan->getData_Barang_byID($id_barang);
|
|
if ($datBarang[0]['TYPE_JENIS']!="2") {
|
|
$datKuantiti = $this->Penjualan->getData_Kuantiti_byID($id_barang);
|
|
if ($level == 0) {
|
|
if ($datKuantiti[0]['PCM_KUANTITI']<$qty_sjp) {
|
|
$this->session->set_flashdata('over_qty', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
} else if ($level == 1) {
|
|
if ($datKuantiti[0]['ITP_KUANTITI']<$qty_sjp) {
|
|
$this->session->set_flashdata('over_qty', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
|
|
//Check apakah ada Kode Barang yang sama
|
|
$datSjp = $this->Penjualan->getData_DaftarSjParsial_bySO_byBARANG_CDNull($id_so, $id_barang);
|
|
if ($datSjp==TRUE) {
|
|
$this->session->set_flashdata('twin_item', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah Kuantiti tersisa melebihi dari Kuantiti yang diinput
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_bySO_byBARANG($id_so, $id_barang);
|
|
$datSumSjp = $this->Penjualan->getSum_DaftarSjParsial_byBARANG_bySO($id_so, $id_barang);
|
|
if (($datSumSjp[0]['SJP']+$qty_sjp)>$datDo[0]['QTY_DO']) {
|
|
$this->session->set_flashdata('over_qty_so', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$ket_sjp = preg_replace('/\R+/', " " , $ket_sjp);
|
|
$input = [
|
|
'SO_ID' => $id_so,
|
|
'DO_ID' => $datDo[0]['ID_DO'],
|
|
'BARANG_ID' => $id_barang,
|
|
'NAMA_SJP' => $datBarang[0]['NAMA_BARANG'],
|
|
'QTY_SJP' => $qty_sjp,
|
|
'KET_SJP' => $ket_sjp
|
|
];
|
|
$action = $this->Penjualan->create('daftar_sjparsial', $input);
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function hapusparsial_GA2() { //[46]
|
|
$method = $this->input->post('method');
|
|
$id_sjp = $this->input->post('id');
|
|
$id_so = $this->input->post('id_so');
|
|
|
|
//Check Konsistensi Data
|
|
$datSo = $this->Penjualan->getData_SalesOrder_8($id_so);
|
|
if ($datSo==FALSE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
}
|
|
|
|
//Check apakah ada Isi SN Parsial
|
|
$datSjp = $this->Penjualan->getData_SnSj_bySJP($id_sjp);
|
|
if ($datSjp==TRUE) {
|
|
$this->session->set_flashdata('data_used_snparsial', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$action = $this->Penjualan->delete('daftar_sjparsial', $id_sjp, 'ID_SJP');
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function cetaksjparsial_GA2() { //[47]
|
|
$id_so = $this->input->post('id_so');
|
|
$level = $this->session->userdata('level');
|
|
$tgl = date('Y-m-d');
|
|
|
|
//Check Konsistensi Data
|
|
$datSo = $this->Penjualan->getData_SalesOrder_8($id_so);
|
|
if ($datSo==FALSE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
}
|
|
|
|
//Check apakah SN sudah terisi dan Apakah Kuantitinya ada
|
|
$datSjp = $this->Penjualan->getData_DaftarSjParsial_bySO_CDNull($id_so);
|
|
foreach ($datSjp as $key) {
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$qtyReal = $this->Penjualan->getQtyReal_DaftarSjParsial($key['ID_SJP']);
|
|
if ($qtyReal<$key['QTY_SJP']) {
|
|
$this->session->set_flashdata('sn_check', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
if ($key['TYPE_JENIS']!="2") {
|
|
$datKuantiti = $this->Penjualan->getData_Kuantiti_byID($key['BID']);
|
|
if ($level == 0) {
|
|
if ($datKuantiti[0]['PCM_KUANTITI']<$key['QTY_SJP']) {
|
|
$this->session->set_flashdata('over_qty', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
} else if ($level == 1) {
|
|
if ($datKuantiti[0]['ITP_KUANTITI']<$key['QTY_SJP']) {
|
|
$this->session->set_flashdata('over_qty', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$datPenjualan = $this->Penjualan->getData_Penjualan_bySO($id_so);
|
|
if ($datPenjualan==FALSE) {
|
|
$kode_penjualan = $this->kodePenjualan();
|
|
$sj_penjualan = $this->kodeSJPenjualan($id_so);
|
|
$inv_penjualan = $this->kodeINVPenjualan($id_so);
|
|
$input = [
|
|
'SO_ID' => $id_so,
|
|
'KODE_PENJUALAN' => $kode_penjualan,
|
|
'SJ_PENJUALAN' => $sj_penjualan,
|
|
'INV_PENJUALAN' => $inv_penjualan,
|
|
'STATUS_PENJUALAN' => '2'
|
|
];
|
|
$action = $this->Penjualan->create('penjualan', $input);
|
|
$id_penjualan = $this->Penjualan->getID_PenjualanMax();
|
|
$id_penjualan = $id_penjualan[0]['ID_PENJUALAN'];
|
|
$kode_bukti = "$sj_penjualan.01";
|
|
} else {
|
|
$id_penjualan = $datPenjualan[0]['ID_PENJUALAN'];
|
|
$sj_penjualan = $datPenjualan[0]['SJ_PENJUALAN'];
|
|
$datCetak = $this->Penjualan->getData_CetakDokumen_forParsial($id_so);
|
|
$index = count($datCetak);
|
|
$index = $index+1;
|
|
$kode_bukti = "$sj_penjualan.0$index";
|
|
}
|
|
|
|
$input = [
|
|
'SJ_INV' => '0',
|
|
'KODE_BUKTI' => $kode_bukti,
|
|
'PENJUALAN_ID' => $id_penjualan,
|
|
'TGL_CD' => $tgl
|
|
];
|
|
$action = $this->Penjualan->create('cetak_dokumen', $input);
|
|
$id_cd = $this->Penjualan->getID_CetakDokumen();
|
|
$id_cd = $id_cd[0]['ID_CD'];
|
|
|
|
$datSjp = $this->Penjualan->getData_DaftarSjParsial_bySO_CDNull($id_so);
|
|
foreach ($datSjp as $key) {
|
|
$update = [
|
|
'CD_ID' => $id_cd
|
|
];
|
|
$action = $this->Penjualan->update('daftar_sjparsial', $update, 'ID_SJP', $key['ID_SJP']);
|
|
if ($key['TYPE_JENIS']!="2") {
|
|
$datKuantiti = $this->Penjualan->getData_Kuantiti_byID($key['BID']);
|
|
if ($level == 0) {
|
|
$pcm_kuantiti = $datKuantiti[0]['PCM_KUANTITI'];
|
|
$proses_kuantiti = $datKuantiti[0]['PROSES_KUANTITI'];
|
|
$pcm = $pcm_kuantiti-$key['QTY_SJP'];
|
|
$proses = $proses_kuantiti+$key['QTY_SJP'];
|
|
$update = [
|
|
'PCM_KUANTITI' => $pcm,
|
|
'PROSES_KUANTITI' => $proses
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $key['BID']);
|
|
} else if ($level == 1) {
|
|
$itp_kuantiti = $datKuantiti[0]['ITP_KUANTITI'];
|
|
$proses_kuantiti = $datKuantiti[0]['PROSES_KUANTITI'];
|
|
$itp = $itp_kuantiti-$key['QTY_SJP'];
|
|
$proses = $proses_kuantiti+$key['QTY_SJP'];
|
|
$update = [
|
|
'ITP_KUANTITI' => $itp,
|
|
'PROSES_KUANTITI' => $proses
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $key['BID']);
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('print_ready', 'dicetak');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dicetak');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function hapuscetak_GA2() { //[48]
|
|
$id_cd = $this->input->post('id');
|
|
$id_so = $this->input->post('id_so');
|
|
$level = $this->session->userdata('level');
|
|
$tgl = date('Y-m-d');
|
|
|
|
//Check Konsistensi Data
|
|
$datSo = $this->Penjualan->getData_SalesOrder_8($id_so);
|
|
if ($datSo==FALSE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
}
|
|
|
|
//Check apakah ada SJ yang tercetak
|
|
$datCd = $this->Penjualan->getData_CetakDokumen_forParsial($id_so);
|
|
$countCd = count($datCd);
|
|
if ($countCd>=2) {
|
|
if ($datCd[$countCd-1]['ID_CD']!=$id_cd) {
|
|
$this->session->set_flashdata('print_delete_error', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
//Check apakah ada data di dalam SJ Parsial
|
|
$datSjpBySO = $this->Penjualan->getData_DaftarSjParsial_bySO_CDNull($id_so);
|
|
if ($datSjpBySO==TRUE) {
|
|
$this->session->set_flashdata('data_cd_null', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$datSjpByCD = $this->Penjualan->getData_DaftarSjParsial_byCD($datCd[$countCd-1]['ID_CD']);
|
|
foreach ($datSjpByCD as $key) {
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$datSnSj = $this->Penjualan->getData_SnSj_bySJP($key['ID_SJP']);
|
|
foreach ($datSnSj as $dat) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_SnSj_byNAMA_AllStatus($dat['NAMA_SNSJ']);
|
|
if ($datSnStock[0]['STATUS_SNSTOCK']=="0") {
|
|
$update = [
|
|
'STATUS_SNSTOCK' => NULL
|
|
];
|
|
$action = $this->Penjualan->update('sn_stock', $update, 'ID_SNSTOCK', $datSnStock[0]['ID_SNSTOCK']);
|
|
}
|
|
}
|
|
$action = $this->Penjualan->delete('sn_sjparsial', $key['ID_SJP'], 'SJP_ID');
|
|
}
|
|
if ($key['TYPE_JENIS']!="2") {
|
|
$datKuantiti = $this->Penjualan->getData_Kuantiti_byID($key['BARANG_ID']);
|
|
if ($level == 0) {
|
|
$pcm_kuantiti = $datKuantiti[0]['PCM_KUANTITI'];
|
|
$proses_kuantiti = $datKuantiti[0]['PROSES_KUANTITI'];
|
|
$pcm = $pcm_kuantiti+$key['QTY_SJP'];
|
|
$proses = $proses_kuantiti-$key['QTY_SJP'];
|
|
$update = [
|
|
'PCM_KUANTITI' => $pcm,
|
|
'PROSES_KUANTITI' => $proses
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
} else if ($level == 1) {
|
|
$itp_kuantiti = $datKuantiti[0]['ITP_KUANTITI'];
|
|
$proses_kuantiti = $datKuantiti[0]['PROSES_KUANTITI'];
|
|
$itp = $itp_kuantiti+$key['QTY_SJP'];
|
|
$proses = $proses_kuantiti-$key['QTY_SJP'];
|
|
$update = [
|
|
'ITP_KUANTITI' => $itp,
|
|
'PROSES_KUANTITI' => $proses
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
}
|
|
}
|
|
$action = $this->Penjualan->delete('daftar_sjparsial', $key['ID_SJP'], 'ID_SJP');
|
|
}
|
|
|
|
if ($countCd==1) {
|
|
$action = $this->Penjualan->delete('penjualan', $id_so, 'SO_ID');
|
|
}
|
|
|
|
$action = $this->Penjualan->delete('cetak_dokumen', $id_cd, 'ID_CD');
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'dibatalkan');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dibatalkan');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function dataOrder_Gudang_A3_Parsial($id) { //[49]
|
|
$level = $this->session->userdata('level');
|
|
$penjualan = $this->Penjualan->getData_DaftarSjParsial_byID($id);
|
|
$max = $this->Penjualan->getQtyReal_DaftarSjParsial($id);
|
|
$datSnStock = $this->Penjualan->getData_SnStock_byBARANG($penjualan[0]['BARANG_ID'], $level);
|
|
|
|
$data = [
|
|
'sidebar' => "menu penjualan",
|
|
'navChild' => "penjualan step2",
|
|
'penjualan' => $penjualan,
|
|
'snstock' => $datSnStock,
|
|
'count_snstock' => count($datSnStock),
|
|
'id_sjp' => $id,
|
|
'qty' => $penjualan[0]['QTY_SJP'],
|
|
'kode_barang' => $penjualan[0]['KODE_BARANG'],
|
|
'max' => $max,
|
|
];
|
|
$this->load->view('proses/PenjualanOrder_Gudang_A3_Parsial', $data);
|
|
}
|
|
|
|
public function viewSn_Penjualan_Parsial_Aktif() { //[50]
|
|
$id = $this->input->post('id');
|
|
$data = $this->Penjualan->getData_SnSj_bySJP($id);
|
|
$this->output_json(['value' => 1, 'total' => sizeof($data), 'data' => $data]);
|
|
}
|
|
|
|
public function viewSn_Penjualan_Parsial_Limit() { //[51]
|
|
$id = $this->input->post('id');
|
|
$data = $this->Penjualan->getData_SnSj_bySJP($id);
|
|
$this->output_json(['value' => 1, 'jumlah_data' => sizeof($data)]);
|
|
}
|
|
|
|
public function simpanparsial_GA3() { //[52]
|
|
$id = $this->input->post('id_snsj');
|
|
$id_sjp = $this->input->post('id_sjp');
|
|
$nama_snsj = $this->input->post('nama_snsj');
|
|
$nama_snsj = strtoupper($nama_snsj);
|
|
|
|
$datSjp = $this->Penjualan->getData_DaftarSjParsial_byID($id_sjp);
|
|
if ($datSjp==FALSE) {
|
|
$this->output_json(['value' => 0]);
|
|
} else {
|
|
$value = 1;
|
|
}
|
|
|
|
if ($value==1) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_SnSj_byNAMA_AllStatus($nama_snsj);
|
|
if ($datSnStock==FALSE) {
|
|
$value = 3;
|
|
} else {
|
|
$value = 1;
|
|
}
|
|
|
|
if ($value==3) {
|
|
$this->output_json(['value' => $value]);
|
|
} else if ($value==1) {
|
|
$id_snstock = $datSnStock[0]['ID_SNSTOCK'];
|
|
$datSnSj = $this->Penjualan->getData_SnSj_SnStock_byNAMA_0($nama_snsj);
|
|
if ($datSnSj==TRUE) {
|
|
$value = 4;
|
|
} else {
|
|
$value = 1;
|
|
}
|
|
|
|
if ($value==4) {
|
|
$this->output_json(['value' => 4]);
|
|
} else if ($value==1) {
|
|
$status_snstock = $datSnStock[0]['STATUS_SNSTOCK'];
|
|
if ($status_snstock==NULL) {
|
|
$qtyRealBefore = $this->Penjualan->getQtyReal_DaftarSjParsial($id_sjp);
|
|
if ($qtyRealBefore>=$datSjp[0]['QTY_SJP']) {
|
|
$this->output_json(['value' => 0]);
|
|
} else {
|
|
$input = [
|
|
'NAMA_SNSJ' => $nama_snsj,
|
|
'SJP_ID' => $id_sjp
|
|
];
|
|
$action = $this->Penjualan->create('sn_sjparsial', $input);
|
|
$update = [
|
|
'STATUS_SNSTOCK' => '0'
|
|
];
|
|
$action = $this->Penjualan->update('sn_stock', $update, 'ID_SNSTOCK', $id_snstock);
|
|
$qtyRealAfter = $this->Penjualan->getQtyReal_DaftarSjParsial($id_sjp);
|
|
if ($datSjp[0]['QTY_SJP']==$qtyRealAfter) {
|
|
$this->output_json(['value' => 2, 'id' => $id, 'nama_snsj' => $nama_snsj]);
|
|
$this->session->set_flashdata('quota_full', 'warning');
|
|
} else if ($action) {
|
|
$this->output_json(['value' => 1, 'id' => $id, 'nama_snsj' => $nama_snsj]);
|
|
} else {
|
|
$this->output_json(['value' => 0, 'id' => $id, 'nama_snsj' => $nama_snsj]);
|
|
}
|
|
}
|
|
} else {
|
|
$this->output_json(['value' => 0]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public function hapusparsial_GA3() { //[53]
|
|
$id = $this->input->post('id_snsj');
|
|
|
|
//Check Konsistensi Data
|
|
$datSnSj = $this->Penjualan->getData_SnSj_byID($id);
|
|
$nama_snsj = $datSnSj[0]['NAMA_SNSJ'];
|
|
$datSjp = $this->Penjualan->getData_DaftarSjParsial_byID($datSnSj[0]['SJP_ID']);
|
|
$qty_sjp = $datSjp[0]['QTY_SJP'];
|
|
$qtyReal = $this->Penjualan->getQtyReal_DaftarSjParsial($datSnSj[0]['SJP_ID']);
|
|
$datSnStock = $this->Penjualan->getData_SnStock_byNAMA_AllStatus($nama_snsj);
|
|
|
|
$update = [
|
|
'STATUS_SNSTOCK' => NULL
|
|
];
|
|
$action = $this->Penjualan->update('sn_stock', $update, 'ID_SNSTOCK', $datSnStock[0]['ID_SNSTOCK']);
|
|
$action = $this->Penjualan->delete('sn_sjparsial', $id, 'ID_SNSJ');
|
|
|
|
if ($qtyReal==$qty_sjp){
|
|
$this->output_json(['value' => 2, 'message' => 'Berhasil', 'dt' => $action]);
|
|
$this->session->set_flashdata('quota_free', 'warning');
|
|
} else {
|
|
if ($action) {
|
|
$this->output_json(['value' => 1, 'message' => 'Berhasil', 'dt' => $action]);
|
|
} else {
|
|
$this->output_json(['value' => 0, 'message' => "gagal", 'dt' => $action]);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function kunciparsial_GA2() { //[54]
|
|
$method = $this->input->post('method');
|
|
$id_so = $this->input->post('id_so');
|
|
$karyawanqc = $this->input->post('karyawanqc');
|
|
$level = $this->session->userdata('level');
|
|
$tgl = date('Y-m-d');
|
|
|
|
//Check Konsistensi Data
|
|
$datSo = $this->Penjualan->getData_SalesOrder_8($id_so);
|
|
if ($datSo==FALSE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
}
|
|
|
|
//Ada data yang belum selesai
|
|
$datSjpNull = $this->Penjualan->getData_DaftarSjParsial_bySO_CDNull($id_so);
|
|
if ($datSjpNull==TRUE) {
|
|
$this->session->set_flashdata('data_cd_null', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah Jumlah Parsial sudah sama dengan kebutuhan SO
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_bySO($id_so);
|
|
foreach ($datDo as $key) {
|
|
$sumSjp = $this->Penjualan->getSum_DaftarSjParsial_byBARANG_bySO($id_so, $key['BARANG_ID']);
|
|
if ($sumSjp[0]['SJP']!=$key['QTY_DO']) {
|
|
$this->session->set_flashdata('qty_sjp_error', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
//Check apakah SN sudah terisi semua, dan Kuantiti Proses sudah sesuai
|
|
$datSjpNotNull = $this->Penjualan->getData_DaftarSjParsial_bySO_allStatus($id_so);
|
|
foreach ($datSjpNotNull as $key) {
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$qtyReal = $this->Penjualan->getQtyReal_DaftarSjParsial($key['ID_SJP']);
|
|
if ($qtyReal<$key['QTY_SJP']) {
|
|
$this->session->set_flashdata('sn_check', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
$datSnSj = $this->Penjualan->getData_SnSj_bySJP($key['ID_SJP']);
|
|
foreach ($datSnSj as $dat) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_SnSj_byNAMA_AllStatus($dat['NAMA_SNSJ']);
|
|
if ($datSnStock[0]['STATUS_SNSTOCK']!="0") {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
if ($key['TYPE_JENIS']!="2") {
|
|
$datKuantiti = $this->Penjualan->getData_Kuantiti_byID($key['BARANG_ID']);
|
|
if ($datKuantiti[0]['PROSES_KUANTITI']<$key['QTY_SJP']) {
|
|
$this->session->set_flashdata('over_qty', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
|
|
//Check apakah Data Proses Keluar Barang sudah benar.
|
|
$datIo_0 = $this->Penjualan->getData_TransaksiStock_bySO_Null_Jenis0($id_so);
|
|
foreach ($datIo_0 as $key) {
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$datSnIo = $this->Penjualan->getData_SnIo_byIO_0($key['ID_IO']);
|
|
foreach ($datSnIo as $dat) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_byNAMA_AllStatus($dat['NAMA_SNIO']);
|
|
if ($datSnStock[0]['STATUS_SNSTOCK']!="0") {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
if ($key['TYPE_JENIS']!="2") {
|
|
$datKuantiti = $this->Penjualan->getData_Kuantiti_byID($key['BARANG_ID']);
|
|
if ($datKuantiti[0]['PROSES_KUANTITI']<$key['QTY_IO']) {
|
|
$this->session->set_flashdata('over_qty', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
|
|
//Check apakah Data Proses Masuk Barang sudah benar.
|
|
$datIo_1 = $this->Penjualan->getData_TransaksiStock_bySO_Null_Jenis1($id_so);
|
|
foreach ($datIo_1 as $key) {
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$datSnIo = $this->Penjualan->getData_SnIo_byIO_1($key['ID_IO']);
|
|
foreach ($datSnIo as $dat) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_byNAMA_AllStatus($dat['NAMA_SNIO']);
|
|
if ($datSnStock[0]['STATUS_SNSTOCK']!=NULL) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$datPenjualan = $this->Penjualan->getData_Penjualan_bySO($id_so);
|
|
foreach ($datIo_0 as $key) {
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$datSnIo = $this->Penjualan->getData_SnIo_byIO_0($key['ID_IO']);
|
|
foreach ($datSnIo as $dat) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_byNAMA_AllStatus($dat['NAMA_SNIO']);
|
|
$input = [
|
|
'TGL_HSN' => $tgl,
|
|
'KODE_BUKTI' => $datPenjualan[0]['KODE_PENJUALAN'],
|
|
'SJ_HSN' => $datPenjualan[0]['SJ_PENJUALAN'],
|
|
'INV_HSN' => $datPenjualan[0]['INV_PENJUALAN'],
|
|
'PELANGGAN_ID' => $datSo[0]['PELANGGAN_ID'],
|
|
'SNSTOCK_ID' => $datSnStock[0]['ID_SNSTOCK']
|
|
];
|
|
$action = $this->Penjualan->create('histori_sn', $input);
|
|
$update = [
|
|
'STATUS_SNSTOCK' => '1'
|
|
];
|
|
$action = $this->Penjualan->update('sn_stock', $update, 'ID_SNSTOCK', $datSnStock['ID_SNSTOCK']);
|
|
}
|
|
}
|
|
|
|
$datKuantiti = $this->Penjualan->getData_Kuantiti_byID($key['BARANG_ID']);
|
|
$proses_kuantiti = $datKuantiti[0]['PROSES_KUANTITI'];
|
|
$global_kuantiti = $datKuantiti[0]['GLOBAL_KUANTITI'];
|
|
$proses = $proses_kuantiti-$key['QTY_IO'];
|
|
$global = $global_kuantiti-$key['QTY_IO'];
|
|
$input = [
|
|
'TGL_HQ' => $tgl,
|
|
'KODE_BUKTI' => $datPenjualan[0]['KODE_PENJUALAN'],
|
|
'SJ_HQ' => $datPenjualan[0]['SJ_PENJUALAN'],
|
|
'INV_HQ' => $datPenjualan[0]['INV_PENJUALAN'],
|
|
'BARANG_ID' => $key['BARANG_ID'],
|
|
'KELUAR_HQ' => $key['QTY_IO'],
|
|
'MASUK_HQ' => '0'
|
|
];
|
|
$action = $this->Penjualan->create('histori_kuantiti', $input);
|
|
$update = [
|
|
'PROSES_KUANTITI' => $proses,
|
|
'GLOBAL_KUANTITI' => $global
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
$update = [
|
|
'STATUS_IO' => "1"
|
|
];
|
|
$action = $this->Penjualan->update('transaksi_stock', $update, 'ID_IO', $key['ID_IO']);
|
|
}
|
|
|
|
$tempo_penjualan = $this->Penjualan->addTempoDay($tgl,$datSo[0]['TOP_PELANGGAN']);
|
|
$ket_inv = $datPenjualan[0]['INV_PENJUALAN'];
|
|
$ket_penjualan = "No Nota : $ket_inv";
|
|
$update = [
|
|
'SO_ID' => $id_so,
|
|
'KOP_ID' => $datSo[0]['CORP_ID'],
|
|
'TGL_PENJUALAN' => $tgl,
|
|
'TEMPO_PENJUALAN' => $tempo_penjualan,
|
|
'KET_PENJUALAN' => $ket_penjualan,
|
|
'STATUS_PENJUALAN' => '1'
|
|
];
|
|
$action = $this->Penjualan->update('penjualan', $update, 'SO_ID', $id_so);
|
|
|
|
foreach ($datIo_1 as $key) {
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$datSnIo = $this->Penjualan->getData_SnIo_byIO_1($key['ID_IO']);
|
|
foreach ($datSnIo as $dat) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_byNAMA_AllStatus($dat['NAMA_SNIO']);
|
|
$input = [
|
|
'TGL_HSN' => $tgl,
|
|
'KODE_BUKTI' => $datSo[0]['KODE_SO'],
|
|
'SNSTOCK_ID' => $datSnStock[0]['ID_SNSTOCK']
|
|
];
|
|
$action = $this->Penjualan->create('histori_sn', $input);
|
|
}
|
|
}
|
|
|
|
$datKuantiti = $this->Penjualan->getData_Kuantiti_byID($key['BARANG_ID']);
|
|
if ($level == 0) {
|
|
$pcm_kuantiti = $datKuantiti[0]['PCM_KUANTITI'];
|
|
$global_kuantiti = $datKuantiti[0]['GLOBAL_KUANTITI'];
|
|
$pcm = $pcm_kuantiti+$key['QTY_IO'];
|
|
$global = $global_kuantiti+$key['QTY_IO'];
|
|
$update = [
|
|
'PCM_KUANTITI' => $pcm,
|
|
'GLOBAL_KUANTITI' => $global
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
} else if ($level == 1) {
|
|
$itp_kuantiti = $datKuantiti[0]['ITP_KUANTITI'];
|
|
$global_kuantiti = $datKuantiti[0]['GLOBAL_KUANTITI'];
|
|
$itp = $itp_kuantiti+$key['QTY_IO'];
|
|
$global = $global_kuantiti+$key['QTY_IO'];
|
|
$update = [
|
|
'ITP_KUANTITI' => $itp,
|
|
'GLOBAL_KUANTITI' => $global
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
}
|
|
|
|
$nilai_hq = $key['QTY_IO']*$key['HARGA_IO'];
|
|
$input = [
|
|
'TGL_HQ' => $tgl,
|
|
'KODE_BUKTI' => $datPenjualan[0]['KODE_PENJUALAN'],
|
|
'SJ_HQ' => $datPenjualan[0]['SJ_PENJUALAN'],
|
|
'INV_HQ' => $datPenjualan[0]['INV_PENJUALAN'],
|
|
'BARANG_ID' => $key['BARANG_ID'],
|
|
'MASUK_HQ' => $key['QTY_IO'],
|
|
'NILAI_HQ' => $nilai_hq,
|
|
'KELUAR_HQ' => '0'
|
|
];
|
|
$action = $this->Penjualan->create('histori_kuantiti', $input);
|
|
$update = [
|
|
'STATUS_IO' => "1"
|
|
];
|
|
$action = $this->Penjualan->update('transaksi_stock', $update, 'ID_IO', $key['ID_IO']);
|
|
}
|
|
|
|
foreach ($datSjpNotNull as $key) {
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$datCd = $this->Penjualan->getData_CetakDokumen_byID($key['CD_ID']);
|
|
$datSnSj = $this->Penjualan->getData_SnSj_bySJP($key['ID_SJP']);
|
|
foreach ($datSnSj as $dat) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_byNAMA_AllStatus($dat['NAMA_SNSJ']);
|
|
$input = [
|
|
'TGL_HSN' => $tgl,
|
|
'KODE_BUKTI' => $datPenjualan[0]['KODE_PENJUALAN'],
|
|
'SJ_HSN' => $datCd[0]['KODE_BUKTI'],
|
|
'INV_HSN' => $datPenjualan[0]['INV_PENJUALAN'],
|
|
'SNSTOCK_ID' => $datSnStock[0]['ID_SNSTOCK'],
|
|
'PELANGGAN_ID' => $datSo[0]['PELANGGAN_ID'],
|
|
];
|
|
$action = $this->Penjualan->create('histori_sn', $input);
|
|
$update = [
|
|
'STATUS_SNSTOCK' => '1'
|
|
];
|
|
$action = $this->Penjualan->update('sn_stock', $update, 'ID_SNSTOCK', $datSnStock[0]['ID_SNSTOCK']);
|
|
$input = [
|
|
'DO_ID' => $key['DO_ID'],
|
|
'NAMA_SNJ' => $dat['NAMA_SNSJ']
|
|
];
|
|
$action = $this->Penjualan->create('sn_jual', $input);
|
|
}
|
|
}
|
|
|
|
if ($key['TYPE_JENIS']!="2") {
|
|
$datCd = $this->Penjualan->getData_CetakDokumen_byID($key['CD_ID']);
|
|
$datKuantiti = $this->Penjualan->getData_Kuantiti_byID($key['BARANG_ID']);
|
|
$proses_kuantiti = $datKuantiti[0]['PROSES_KUANTITI'];
|
|
$global_kuantiti = $datKuantiti[0]['GLOBAL_KUANTITI'];
|
|
$proses = $proses_kuantiti-$key['QTY_SJP'];
|
|
$global = $global_kuantiti-$key['QTY_SJP'];
|
|
$input = [
|
|
'TGL_HQ' => $tgl,
|
|
'KODE_BUKTI' => $datPenjualan[0]['KODE_PENJUALAN'],
|
|
'SJ_HQ' => $datCd[0]['KODE_BUKTI'],
|
|
'INV_HQ' => $datPenjualan[0]['INV_PENJUALAN'],
|
|
'BARANG_ID' => $key['BARANG_ID'],
|
|
'KELUAR_HQ' => $key['QTY_SJP'],
|
|
'MASUK_HQ' => '0'
|
|
];
|
|
$action = $this->Penjualan->create('histori_kuantiti', $input);
|
|
$update = [
|
|
'PROSES_KUANTITI' => $proses,
|
|
'GLOBAL_KUANTITI' => $global
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
}
|
|
}
|
|
|
|
foreach ($karyawanqc as $key) {
|
|
$input = [
|
|
'SO_ID' => $id_so,
|
|
'KARYAWAN_ID' => $key,
|
|
'TGL_QC' => $tgl
|
|
];
|
|
$action = $this->Penjualan->create('quality_control', $input);
|
|
}
|
|
|
|
$update = [
|
|
'STATUS_SO' => '1',
|
|
'KET_SO_A' => NULL,
|
|
'TGL_SO' => $tgl
|
|
];
|
|
$action = $this->Penjualan->update('sales_order', $update, 'ID_SO', $id_so);
|
|
|
|
foreach ($datDo as $key) {
|
|
if ($datSo[0]['TYPE_PELANGGAN']=="1") {
|
|
$komisi_do = $key['KOMISI_DEALER'];
|
|
} else {
|
|
$komisi_do = $key['KOMISI_USER'];
|
|
}
|
|
$update = [
|
|
'KOMISI_DO' => $komisi_do
|
|
];
|
|
$action = $this->Penjualan->update('daftar_order', $update, 'ID_DO', $key['ID_DO']);
|
|
}
|
|
|
|
$debet_pda = 0;
|
|
foreach ($datDo as $key) {
|
|
$subtotal = $key['QTY_DO']*$key['HARGA_DO'];
|
|
$debet_pda = $debet_pda+$subtotal;
|
|
}
|
|
|
|
$inv_penjualan = $datPenjualan[0]['INV_PENJUALAN'];
|
|
$ket_pda = "No Nota : $inv_penjualan";
|
|
$ppn_pda = $debet_pda*($datSo[0]['PPN_SO']/100);
|
|
$debet_pda = $debet_pda*((100+$datSo[0]['PPN_SO'])/100);
|
|
$debet_pda = round($debet_pda);
|
|
|
|
$input = [
|
|
'TRANSAKSI_PDA' => '0',
|
|
'PENJUALAN_ID' => $datPenjualan[0]['ID_PENJUALAN'],
|
|
'DEBET_PDA' => $debet_pda,
|
|
'KREDIT_PDA' => '0',
|
|
'KODE_BUKTI' => $datPenjualan[0]['KODE_PENJUALAN'],
|
|
'PELANGGAN_ID' => $datSo[0]['PELANGGAN_ID'],
|
|
'TGL_PDA' => $tgl,
|
|
'KET_PDA' => $ket_pda
|
|
];
|
|
$action = $this->Penjualan->create('piutang_dagang', $input);
|
|
|
|
$update = [
|
|
'NILAI_SO' => $debet_pda
|
|
];
|
|
$action = $this->Penjualan->update('sales_order', $update, 'ID_SO', $id_so);
|
|
|
|
$input = [
|
|
'SJ_INV' => '0',
|
|
'TGL_CD' => $tgl,
|
|
'KODE_BUKTI' => $datPenjualan[0]['SJ_PENJUALAN'],
|
|
'PENJUALAN_ID' => $datPenjualan[0]['ID_PENJUALAN']
|
|
];
|
|
$action = $this->Penjualan->create('cetak_dokumen', $input);
|
|
|
|
$input = [
|
|
'SJ_INV' => '1',
|
|
'DP_CD' => '0',
|
|
'TGL_CD' => $tgl,
|
|
'KODE_BUKTI' => $datPenjualan[0]['INV_PENJUALAN'],
|
|
'PENJUALAN_ID' => $datPenjualan[0]['ID_PENJUALAN']
|
|
];
|
|
$action = $this->Penjualan->create('cetak_dokumen', $input);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('data_lock_print', 'dikunci');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dikunci');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
}
|
|
|
|
}
|
|
|
|
public function dataOrder_Gudang_A2_Konsinyasi($id) { //[55]
|
|
$datPenjualan = $this->Penjualan->getData_DaftarOrder_bySO($id);
|
|
$datSo = $this->Penjualan->getData_SalesOrder_byID($id);
|
|
$datPelanggan = $this->Penjualan->getData_Pelanggan_byID($datSo[0]['PELANGGAN_ID']);
|
|
$datPersediaan = $this->Penjualan->getData_DaftarKonsi_byPELANGGAN_groupBARANG_Status0($datSo[0]['PELANGGAN_ID']);
|
|
$datPenarikan = $this->Penjualan->getData_PenarikanLaku_byPELANGGAN($datSo[0]['PELANGGAN_ID']);
|
|
$datSnkAll = $this->Penjualan->getData_SnKonsi_byPELANGGAN_AllNull($datSo[0]['PELANGGAN_ID']);
|
|
$tgl = date('d/m/Y');
|
|
|
|
$no = 0;
|
|
foreach ($datPenjualan as $key) {
|
|
$datSnj = $this->Penjualan->getData_SnJual_byDO_byBARANG($key['ID_DO'], $key['BARANG_ID']);
|
|
$datPenjualan[$no++] += ['SN' => $datSnj];
|
|
}
|
|
|
|
$no = 0;
|
|
foreach ($datPersediaan as $key) {
|
|
$datSnk = $this->Penjualan->getData_SnKonsi_byBARANG_byPELANGGAN_forKonsinyasi($key['BARANG_ID'], $datSo[0]['PELANGGAN_ID']);
|
|
$datPersediaan[$no] += ['SN' => $datSnk];
|
|
|
|
$datDpk = $this->Penjualan->getData_DaftarPenarikanKonsi_byBARANG_byPELANGGAN($key['BARANG_ID'], $datSo[0]['PELANGGAN_ID']);
|
|
$datPersediaan[$no] += ['QTY1' => $datDpk];
|
|
|
|
$datDpl = $this->Penjualan->getData_DaftarPenarikanLaku_byBARANG_byPELANGGAN($key['BARANG_ID'], $datSo[0]['PELANGGAN_ID']);
|
|
$datPersediaan[$no++] += ['QTY2' => $datDpl];
|
|
}
|
|
|
|
if ($datPenarikan==FALSE) {
|
|
$status_pl = NULL;
|
|
} else {
|
|
$status_pl = $datPenarikan[0]['STATUS_PL'];
|
|
}
|
|
|
|
$data = [
|
|
'sidebar' => "menu penjualan",
|
|
'navChild' => "penjualan step2",
|
|
'penjualan' => $datPenjualan,
|
|
'persediaan' => $datPersediaan,
|
|
'kode_so' => $datSo[0]['KODE_SO'],
|
|
'ket_so_g' => $datSo[0]['KET_SO_G'],
|
|
'ket_so_k' => $datSo[0]['KET_SO_K'],
|
|
'ket_so_t' => $datSo[0]['KET_SO_T'],
|
|
'ket_so_p' => $datSo[0]['KET_SO_P'],
|
|
'id_so' => $id,
|
|
'id_pelanggan' => $datSo[0]['PELANGGAN_ID'],
|
|
'tgl' => $tgl,
|
|
'snk' => $datSnkAll,
|
|
'nama_pelanggan' => $datPelanggan[0]['NAMA_PELANGGAN'],
|
|
'nama_kota' => $datPelanggan[0]['NAMA_KOTA'],
|
|
'status_pl' => $status_pl,
|
|
];
|
|
$this->load->view('proses/PenjualanOrder_Gudang_A2_Konsinyasi', $data);
|
|
}
|
|
|
|
public function konsinyasi_out_GA2() { //[56]
|
|
$method = $this->input->post('method');
|
|
$id_so = $this->input->post('id_so');
|
|
|
|
//Check Konsistensi Data
|
|
$datSo = $this->Penjualan->getData_SalesOrder_9($id_so);
|
|
if ($datSo==FALSE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
}
|
|
|
|
//Check apakah SN sudah terisi
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_bySO($id_so);
|
|
foreach ($datDo as $key) {
|
|
$datSnJual = $this->Penjualan->getData_SnJual_byDO($key['ID_DO']);
|
|
if ($datSnJual==TRUE) {
|
|
$this->session->set_flashdata('sn_io', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
//Check apakah sudah ada data Konsinyasi yang laku
|
|
$datPl = $this->Penjualan->getData_PenarikanLaku_byPELANGGAN_bySO_Null($datSo[0]['PELANGGAN_ID'], $id_so);
|
|
$datDpl = $this->Penjualan->getData_DaftarPenarikanLaku_byPL($datPl[0]['ID_PL']);
|
|
if ($datDpl==TRUE) {
|
|
$this->session->set_flashdata('data_used', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$update = [
|
|
'STATUS_SO' => '0'
|
|
];
|
|
$action = $this->Penjualan->update('sales_order', $update, 'ID_SO', $id_so);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('data_lock', 'keluar Proses Konsinyasi');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'keluar Proses Konsinyasi');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
}
|
|
|
|
}
|
|
|
|
public function kodePenarikanLaku() { //[57]
|
|
$kk = $this->Penjualan->getKode_PenarikanLaku(); //[57]
|
|
$tgl = date('y');
|
|
if (is_array($kk) || is_object($kk)) {
|
|
foreach ($kk as $row) {
|
|
if ($row['KODE'] == null) {
|
|
return "PL".$tgl."-0001";
|
|
} else {
|
|
$str = (string) $row['KODE'];
|
|
$tgl_lama = substr($str, 2, -5);
|
|
if ($tgl_lama!=$tgl) {
|
|
return "PL".$tgl."-0001";
|
|
} else {
|
|
$panjang = 4;
|
|
$data = substr($str, 5, $panjang);
|
|
$ko = (int) $data + 1;
|
|
$str = (string) $ko;
|
|
$panjang = 9 - strlen($str);
|
|
$data = "PL".$tgl."-0000";
|
|
$data = substr($data, 0, $panjang) . $str;
|
|
return $data;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function tambahkonsinyasi_GA2() { //[58]
|
|
$method = $this->input->post('method');
|
|
$id_pelanggan = $this->input->post('id_pelanggan');
|
|
$id_so = $this->input->post('id_so');
|
|
$sntarik = $this->input->post('sntarik');
|
|
$id_barang = $this->input->post('id_barang');
|
|
$qty_dpl = $this->input->post('qty_dpl');
|
|
$status_pl = $this->input->post('status_pl');
|
|
|
|
$datPl = $this->Penjualan->getData_PenarikanLaku_byPELANGGAN_orderDESC($id_pelanggan);
|
|
if ($datPl==FALSE) {
|
|
$satpl = NULL;
|
|
} else {
|
|
$satpl = $datPl[0]['STATUS_PL'];
|
|
}
|
|
|
|
//Check Konsistensi Data
|
|
if ($satpl!=$status_pl AND $datPl==TRUE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
}
|
|
|
|
//Check apakah SN sudah sesuai dengan statusnya
|
|
foreach ($sntarik as $key) {
|
|
$datSnKonsi = $this->Penjualan->getData_SnKonsi_byID($key);
|
|
foreach ($datSnKonsi as $dat) {
|
|
if ($dat['STATUS_SNK']!=NULL OR $dat['PK_ID']!=NULL OR $dat['PL_ID']!=NULL) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
|
|
$datPl = $this->Penjualan->getData_PenarikanLaku_byPELANGGAN_Null($id_pelanggan);
|
|
if ($datPl==FALSE) {
|
|
$kode_pl = $this->kodePenarikanLaku();
|
|
$tgl = date('Y-m-d');
|
|
$input = [
|
|
'KODE_PL' => $kode_pl,
|
|
'TGL_PL' => $tgl,
|
|
'PELANGGAN_ID' => $id_pelanggan,
|
|
'SO_ID' => $id_so,
|
|
];
|
|
$action = $this->Penjualan->create('penarikan_laku', $input);
|
|
$id_pl = $this->Penjualan->getID_PLMax();
|
|
$id_pl = $id_pl[0]['ID_PL'];
|
|
} else {
|
|
$id_pl = $datPl[0]['ID_PL'];
|
|
}
|
|
|
|
$no = 0;
|
|
foreach ($sntarik as $key) {
|
|
$datSnk = $this->Penjualan->getData_SnKonsi_byID($key);
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_bySO_byBARANG($id_so, $datSnk[0]['BARANG_ID']);
|
|
if ($datDo==FALSE) {
|
|
$this->session->set_flashdata('sn_konsi_error', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
$input[$no++] = [
|
|
'BARANG_ID' => $datSnk[0]['BARANG_ID'],
|
|
'QTYNEW' => 1
|
|
];
|
|
}
|
|
|
|
foreach ($input as $key) {
|
|
$datDpl = $this->Penjualan->getData_DaftarPenarikanLaku_byPL_byBARANG($id_pl, $key['BARANG_ID']);
|
|
if ($datDpl==TRUE) {
|
|
$this->session->set_flashdata('twin_item_sn', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_bySO($id_so);
|
|
$totalSn = 0;
|
|
foreach ($datDo as $key) {
|
|
foreach ($input as $datkey) {
|
|
if ($datkey['BARANG_ID']==$key['BARANG_ID']) {
|
|
$totalSn = $totalSn+$datkey['QTYNEW'];
|
|
}
|
|
}
|
|
if ($totalSn>$key['QTY_DO']) {
|
|
$this->session->set_flashdata('over_qty_so', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
foreach ($sntarik as $key) {
|
|
$update = [
|
|
'PL_ID' => $id_pl,
|
|
'STATUS_SNK' => '0'
|
|
];
|
|
$action = $this->Penjualan->update('sn_konsi', $update, 'ID_SNK', $key);
|
|
$datSnk = $this->Penjualan->getData_SnKonsi_byID($key);
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_bySO_byBARANG($id_so, $datSnk[0]['BARANG_ID']);
|
|
$input = [
|
|
'DO_ID' => $datDo[0]['ID_DO'],
|
|
'NAMA_SNJ' => $datSnk[0]['NAMA_SNK']
|
|
];
|
|
$action = $this->Penjualan->create('sn_jual', $input);
|
|
}
|
|
|
|
$datDfk = $this->Penjualan->getData_DaftarKonsi_byPELANGGAN_groupBARANG($id_pelanggan);
|
|
foreach ($datDfk as $dat) {
|
|
$qty = '0';
|
|
$datSnk = $this->Penjualan->getData_SnKonsi_byPL_0($id_pl);
|
|
foreach ($datSnk as $keydat) {
|
|
if ($keydat['BARANG_ID']==$dat['BARANG_ID']) {
|
|
$qty = $qty+1;
|
|
}
|
|
}
|
|
if ($qty>0) {
|
|
$input = [
|
|
'PL_ID' => $id_pl,
|
|
'BARANG_ID' => $dat['BARANG_ID'],
|
|
'QTY_DPL' => $qty
|
|
];
|
|
$action = $this->Penjualan->create('daftar_penarikanlaku', $input);
|
|
}
|
|
}
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function hapuskonsinyasi_GA2() { //[59]
|
|
$method = $this->input->post('method');
|
|
$id_do = $this->input->post('id_do');
|
|
$id_pelanggan = $this->input->post('id_pelanggan');
|
|
$id_so = $this->input->post('id_so');
|
|
|
|
//Check Konsistensi Data
|
|
$datPl = $this->Penjualan->getData_PenarikanLaku_byPELANGGAN_bySO_Null($id_pelanggan, $id_so);
|
|
if ($datPl==FALSE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
}
|
|
|
|
$datSnj = $this->Penjualan->getData_SnJual_byDO($id_do);
|
|
foreach ($datSnj as $key) {
|
|
$datSnk = $this->Penjualan->getData_SnKonsi_byPL_byNAMA_0($datPl[0]['ID_PL'],$key['NAMA_SNJ']);
|
|
if ($datSnk==TRUE) {
|
|
$update = [
|
|
'PL_ID' => NULL,
|
|
'STATUS_SNK' => NULL
|
|
];
|
|
$action = $this->Penjualan->update('sn_konsi', $update, 'ID_SNK', $datSnk[0]['ID_SNK']);
|
|
$action = $this->Penjualan->delete('sn_jual', $key['ID_SNJ'], 'ID_SNJ');
|
|
}
|
|
}
|
|
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_byID($id_do);
|
|
$datDpl = $this->Penjualan->getData_DaftarPenarikanLaku_byPL_byBARANG($datPl[0]['ID_PL'],$datDo[0]['BARANG_ID']);
|
|
$action = $this->Penjualan->delete('daftar_penarikanlaku', $datDpl[0]['ID_DPL'], 'ID_DPL');
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function kuncikonsinyasi_GA2() { //[60]
|
|
$method = $this->input->post('method');
|
|
$id_pelanggan = $this->input->post('id_pelanggan');
|
|
$id_so = $this->input->post('id_so');
|
|
$id_gudang = $this->session->userdata('id_karyawan');
|
|
|
|
//Check Konsistensi Data
|
|
$datPl = $this->Penjualan->getData_PenarikanLaku_byPELANGGAN_bySO_Null($id_pelanggan, $id_so);
|
|
if ($datPl==FALSE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
}
|
|
|
|
$datSo = $this->Penjualan->getData_SalesOrder_9($id_so);
|
|
if ($datSo==FALSE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePenjualan/dataOrder_Gudang_A1');
|
|
}
|
|
|
|
//Check apakah Jumlah SN Sesuai, dan Jumlah Kuantiti Konsinyasi Sesuai
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_bySO($id_so);
|
|
foreach ($datDo as $key) {
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$datSnj = $this->Penjualan->getData_SnJual_byDO($key['ID_DO']);
|
|
if (count($datSnj)<$key['QTY_DO']) {
|
|
$this->session->set_flashdata('sn_konsi_qty', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
foreach ($datSnj as $dat) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_SnJual_byNAMA_AllStatus($dat['NAMA_SNJ']);
|
|
if ($datSnStock[0]['STATUS_SNSTOCK']!="11") {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
if ($key['TYPE_JENIS']!="2") {
|
|
$datKuantiti = $this->Penjualan->getData_Kuantiti_byID($key['BARANG_ID']);
|
|
if ($datKuantiti[0]['KONSINYASI_KUANTITI']<$key['QTY_DO']) {
|
|
$this->session->set_flashdata('over_qty', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach ($datDo as $key) {
|
|
if ($key['TYPE_JENIS']=="0") {
|
|
$input = [
|
|
'PL_ID' => $datPl[0]['ID_PL'],
|
|
'BARANG_ID' => $key['BARANG_ID'],
|
|
'QTY_DPL' => $key['QTY_DO']
|
|
];
|
|
$action = $this->Penjualan->create('daftar_penarikanlaku', $input);
|
|
}
|
|
}
|
|
|
|
$update = [
|
|
'STATUS_PL' => '0'
|
|
];
|
|
$action = $this->Penjualan->update('penarikan_laku', $update, 'ID_PL', $datPl[0]['ID_PL']);
|
|
|
|
$kode_penjualan = $this->kodePenjualan();
|
|
$sj_penjualan = $this->kodeSJPenjualan($id_so);
|
|
$inv_penjualan = $this->kodeINVPenjualan($id_so);
|
|
$tempo_penjualan = $this->Penjualan->addTempoDay($tgl,$datSo[0]['TOP_PELANGGAN']);
|
|
|
|
$input = [
|
|
'SO_ID' => $id_so,
|
|
'TGL_PENJUALAN' => $tgl,
|
|
'KODE_PENJUALAN' => $kode_penjualan,
|
|
'SJ_PENJUALAN' => $sj_penjualan,
|
|
'INV_PENJUALAN' => $inv_penjualan,
|
|
'TEMPO_PENJUALAN' => $tempo_penjualan,
|
|
'STATUS_PENJUALAN' => '1'
|
|
];
|
|
$action = $this->Penjualan->create('penjualan', $input);
|
|
|
|
$datPenjualan = $this->Penjualan->getID_PenjualanMax();
|
|
$id_penjualan = $datPenjualan[0]['ID_PENJUALAN'];
|
|
|
|
foreach ($datDo as $key) {
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$datSnj = $this->Penjualan->getData_SnJual_byDO($key['ID_DO']);
|
|
foreach ($datSnj as $dat) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_byNAMA_AllStatus($dat['NAMA_SNJ']);
|
|
$input = [
|
|
'TGL_HSN' => $tgl,
|
|
'KODE_BUKTI' => $kode_penjualan,
|
|
'SJ_HSN' => $sj_penjualan,
|
|
'INV_HSN' => $inv_penjualan,
|
|
'SNSTOCK_ID' => $datSnStock[0]['ID_SNSTOCK'],
|
|
'PELANGGAN_ID' => $key['PELANGGAN_ID'],
|
|
];
|
|
$action = $this->Penjualan->create('histori_sn', $input);
|
|
$update = [
|
|
'STATUS_SNSTOCK' => '1'
|
|
];
|
|
$action = $this->Penjualan->update('sn_stock', $update, 'ID_SNSTOCK', $datSnStock[0]['ID_SNSTOCK']);
|
|
}
|
|
}
|
|
|
|
if ($key['TYPE_JENIS']!="2") {
|
|
$datKuantiti = $this->Penjualan->getData_Kuantiti_byID($key['BARANG_ID']);
|
|
$konsinyasi_kuantiti = $datKuantiti[0]['KONSINYASI_KUANTITI'];
|
|
$global_kuantiti = $datKuantiti[0]['GLOBAL_KUANTITI'];
|
|
$konsinyasi = $konsinyasi_kuantiti-$key['QTY_DO'];
|
|
$global = $global_kuantiti-$key['QTY_DO'];
|
|
$input = [
|
|
'TGL_HQ' => $tgl,
|
|
'KODE_BUKTI' => $kode_penjualan,
|
|
'SJ_HQ' => $sj_penjualan,
|
|
'INV_HQ' => $inv_penjualan,
|
|
'BARANG_ID' => $key['BARANG_ID'],
|
|
'KELUAR_HQ' => $key['QTY_DO'],
|
|
'MASUK_HQ' => '0'
|
|
];
|
|
$action = $this->Penjualan->create('histori_kuantiti', $input);
|
|
$update = [
|
|
'KONSINYASI_KUANTITI' => $proses,
|
|
'GLOBAL_KUANTITI' => $konsinyasi
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
}
|
|
|
|
if ($datSo[0]['TYPE_PELANGGAN']=="1") {
|
|
$komisi_do = $key['KOMISI_DEALER'];
|
|
} else {
|
|
$komisi_do = $key['KOMISI_USER'];
|
|
}
|
|
|
|
$update = [
|
|
'KOMISI_DO' => $komisi_do
|
|
];
|
|
$action = $this->Penjualan->update('daftar_order', $update, 'ID_DO', $key['ID_DO']);
|
|
|
|
}
|
|
|
|
$input = [
|
|
'SO_ID' => $id_so,
|
|
'KARYAWAN_ID' => $id_gudang,
|
|
'TGL_QC' => $tgl
|
|
];
|
|
$action = $this->Penjualan->create('quality_control', $input);
|
|
|
|
$debet_pda = 0;
|
|
foreach ($datDo as $key) {
|
|
$subtotal = $key['QTY_DO']*$key['HARGA_DO'];
|
|
$debet_pda = $debet_pda+$subtotal;
|
|
}
|
|
|
|
$ppn_pda = $debet_pda*($datSo[0]['PPN_SO']/100);
|
|
$debet_pda = $debet_pda*((100+$datSo[0]['PPN_SO'])/100);
|
|
$debet_pda = round($debet_pda);
|
|
|
|
$update = [
|
|
'STATUS_SO' => '1',
|
|
'KET_SO_A' => NULL,
|
|
'TGL_SO' => $tgl,
|
|
'NILAI_SO' => $debet_pda,
|
|
'PL_ID' => $datPl[0]['ID_PL']
|
|
];
|
|
$action = $this->Penjualan->update('sales_order', $update, 'ID_SO', $id_so);
|
|
|
|
$ket_pda = "No Nota : $inv_penjualan";
|
|
$input = [
|
|
'TRANSAKSI_PDA' => '0',
|
|
'PENJUALAN_ID' => $id_penjualan,
|
|
'DEBET_PDA' => $debet_pda,
|
|
'KREDIT_PDA' => '0',
|
|
'KODE_BUKTI' => $kode_penjualan,
|
|
'PELANGGAN_ID' => $datSo[0]['PELANGGAN_ID'],
|
|
'TGL_PDA' => $tgl,
|
|
'KET_PDA' => $ket_pda
|
|
];
|
|
$action = $this->Penjualan->create('piutang_dagang', $input);
|
|
|
|
$update = [
|
|
'KET_PENJUALAN' => $ket_pda,
|
|
'KOP_ID' => $datSo[0]['CORP_ID'],
|
|
];
|
|
$action = $this->Penjualan->update('penjualan', $update, 'ID_PENJUALAN', $id_penjualan);
|
|
|
|
$input = [
|
|
'SJ_INV' => '0',
|
|
'TGL_CD' => $tgl,
|
|
'KODE_BUKTI' => $sj_penjualan,
|
|
'PENJUALAN_ID' => $id_penjualan
|
|
];
|
|
$action = $this->Penjualan->create('cetak_dokumen', $input);
|
|
|
|
$input = [
|
|
'SJ_INV' => '1',
|
|
'DP_CD' => '0',
|
|
'TGL_CD' => $tgl,
|
|
'KODE_BUKTI' => $inv_penjualan,
|
|
'PENJUALAN_ID' => $id_penjualan
|
|
];
|
|
$action = $this->Penjualan->create('cetak_dokumen', $input);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('data_lock_print', 'dikunci');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dikunci');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function dataOrder_Umum_A1() { //[61]
|
|
$penjualan = $this->Penjualan->getData_SalesOrder_0_1_2_3_4_6_7_8();
|
|
$datSo = $this->Penjualan->getData_SalesOrder_1_KirimNull();
|
|
$datKaryawan = $this->Penjualan->getData_Karyawan_Pengiriman();
|
|
$datJp = $this->Penjualan->getData_SalesOrder_forPenjadwalan();
|
|
$tgl = date('Y-m-d');
|
|
$tgl_now = date('d/m/Y');
|
|
$set = 0;
|
|
|
|
$no = 0;
|
|
foreach ($datJp as $key) {
|
|
$datJadwal = $this->Penjualan->getData_JadwalPengiriman_bySO($key['ID_SO']);
|
|
$datJp[$no++] += ['KARYAWAN' => $datJadwal];
|
|
}
|
|
|
|
$data = [
|
|
'sidebar' => "menu penjualan",
|
|
'navChild' => "penjualan step3",
|
|
'penjualan' => $penjualan,
|
|
'so' => $datSo,
|
|
'datJp' => $datJp,
|
|
'set' => $set,
|
|
'jp' => $datKaryawan,
|
|
'tgl' => $tgl,
|
|
'tgl_now' => $tgl_now
|
|
];
|
|
$this->load->view('proses/PenjualanOrder_Umum_A1', $data);
|
|
}
|
|
|
|
public function simpanjadwal_UA1() { //[61]
|
|
$method = $this->input->post('method');
|
|
$id_jp = $this->input->post('id');
|
|
$sojp = $this->input->post('sojp');
|
|
$karyawanjp = $this->input->post('karyawanjp');
|
|
$tgl_kirim = $this->input->post('tgl_kirim');
|
|
$ket_so_a = $this->input->post('ket_so_a');
|
|
$tgl = date('Y-m-d');
|
|
|
|
//if (strtotime($tgl_kirim)<strtotime($tgl)) {
|
|
// $this->session->set_flashdata('date_error', 'error');
|
|
// redirect($_SERVER['HTTP_REFERER']);
|
|
//}
|
|
|
|
$ket_so_a = preg_replace('/\R+/', " " , $ket_so_a);
|
|
foreach ($sojp as $dat) {
|
|
$update = [
|
|
'STATUS_KIRIM' => '0',
|
|
'TGL_KIRIM' => $tgl_kirim,
|
|
'KET_SO_A' => $ket_so_a
|
|
];
|
|
$action = $this->Penjualan->update('sales_order', $update, 'ID_SO', $dat);
|
|
}
|
|
|
|
foreach ($karyawanjp as $key) {
|
|
foreach ($sojp as $dat) {
|
|
$input = [
|
|
'SO_ID' => $dat,
|
|
'KARYAWAN_ID' => $key
|
|
];
|
|
$action = $this->Penjualan->create('jadwal_pengiriman', $input);
|
|
}
|
|
}
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'diproses');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'diproses');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function loginadmin_Penjualan_UA1() { //[62]
|
|
$username = $this->input->post('username');
|
|
$password = $this->input->post('password');
|
|
$datKaryawan = $this->Penjualan->getData_Karyawan_forLogin($username, $password);
|
|
|
|
if ($datKaryawan == TRUE and $datKaryawan[0]['NAMA_JABATAN'] == "ADMIN UMUM") {
|
|
$this->session->set_flashdata('username_pass_success', 'login');
|
|
redirect('ManagePenjualan/dataOrder_Umum_A1_Admin');
|
|
} else if ($datKaryawan == TRUE and $datKaryawan[0]['NAMA_JABATAN'] == "ADMINISTRATOR") {
|
|
$this->session->set_flashdata('username_pass_success', 'login');
|
|
redirect('ManagePenjualan/dataOrder_Umum_A1_Admin');
|
|
} else {
|
|
$this->session->set_flashdata('username_pass_error', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
public function revisijadwal_UA1() { //[63]
|
|
$method = $this->input->post('method');
|
|
$id_so = $this->input->post('id_sorevadm');
|
|
|
|
//Check Konsistensi Data
|
|
$datSo = $this->Penjualan->getData_SalesOrder_1($id_so);
|
|
if ($datSo[0]['STATUS_KIRIM']==NULL) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$action = $this->Penjualan->delete('jadwal_pengiriman', $id_so, 'SO_ID');
|
|
|
|
$update = [
|
|
'STATUS_KIRIM' => NULL,
|
|
'TGL_KIRIM' => NULL,
|
|
'KET_SO_A' => NULL
|
|
];
|
|
$action = $this->Penjualan->update('sales_order', $update, 'ID_SO', $id_so);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'dibatalkan');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dibatalkan');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function dataOrder_Umum_A1_Admin() { //[64]
|
|
$penjualan = $this->Penjualan->getData_SalesOrder_1_KirimNotNull();
|
|
$set = 1;
|
|
|
|
$no = 0;
|
|
foreach ($penjualan as $key) {
|
|
$datJp = $this->Penjualan->getData_JadwalPengiriman_bySO($key['ID_SO']);
|
|
$penjualan[$no++] += ['KARYAWAN' => $datJp];
|
|
}
|
|
|
|
$data = [
|
|
'sidebar' => "menu penjualan",
|
|
'navChild' => "penjualan step3",
|
|
'penjualan' => $penjualan,
|
|
'set' => $set
|
|
];
|
|
$this->load->view('proses/PenjualanOrder_Umum_A1', $data);
|
|
}
|
|
|
|
public function prosesrevisi_UA1() { //[65]
|
|
$method = $this->input->post('method');
|
|
$id_so = $this->input->post('id_sorevsel');
|
|
|
|
//Check Konsistensi Data
|
|
$datSo = $this->Penjualan->getData_SalesOrder_1($id_so);
|
|
if ($datSo==FALSE OR $datSo[0]['STATUS_KIRIM']==NULL) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$action = $this->Penjualan->delete('jadwal_pengiriman', $id_so, 'SO_ID');
|
|
|
|
$update = [
|
|
'STATUS_KIRIM' => NULL,
|
|
'TGL_SELESAI' => NULL,
|
|
'TGL_KIRIM' => NULL,
|
|
'KET_SO_A' => NULL
|
|
];
|
|
$action = $this->Penjualan->update('sales_order', $update, 'ID_SO', $id_so);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'diproses');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'diproses');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function dataOrder_Umum_A1_Pengirim() { //[66]
|
|
$id_karyawan = $this->session->userdata('id_karyawan');
|
|
$jabatan = $this->session->userdata('jabatan');
|
|
$level = $this->session->userdata('level');
|
|
$username = $this->session->userdata('username');
|
|
$set = 2;
|
|
|
|
if ($username=="service") {
|
|
$datPenjualan = $this->Penjualan->getData_SalesOrder_1_KirimNull($id_karyawan);
|
|
} else if ($jabatan=="GUDANG" OR $jabatan=="ADMIN ITP") {
|
|
$datPenjualan = $this->Penjualan->getData_SalesOrder_1_KirimNull_forGudang($level);
|
|
} else {
|
|
$datPenjualan = $this->Penjualan->getData_SalesOrder_1_Kirim0($id_karyawan);
|
|
}
|
|
|
|
$data = [
|
|
'sidebar' => "menu penjualan",
|
|
'navChild' => "penjualan step3",
|
|
'penjualan' => $datPenjualan,
|
|
'set' => $set
|
|
];
|
|
$this->load->view('proses/PenjualanOrder_Umum_A1', $data);
|
|
}
|
|
|
|
public function proseskirim_UA1() { //[67]
|
|
$method = $this->input->post('method');
|
|
$id_so = $this->input->post('id_so');
|
|
$tgl_selesai = $this->input->post('timestamp');
|
|
$id_karyawan = $this->session->userdata('id_karyawan');
|
|
$username = $this->session->userdata('username');
|
|
$jabatan = $this->session->userdata('jabatan');
|
|
$tgl = date('Y-m-d');
|
|
$tgl_now = date('d/m/Y');
|
|
|
|
//Check Konsistensi Data
|
|
$datSo = $this->Penjualan->getData_SalesOrder_1($id_so);
|
|
if ($datSo[0]['TGL_SELESAI']!=NULL) {
|
|
$datKaryawan = $this->Penjualan->getData_Karyawan_byID($datSo[0]['STATUS_KIRIM']);
|
|
$nama = $datKaryawan[0]['NAMA_PANGGILAN_KARYAWAN'];
|
|
$this->session->set_flashdata('latest_pengiriman', "$nama");
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
if ($username=="service") {
|
|
$input = [
|
|
'KARYAWAN_ID' => $id_karyawan,
|
|
'SO_ID' => $id_so
|
|
];
|
|
$action = $this->Penjualan->create('jadwal_pengiriman', $input);
|
|
$update = [
|
|
'TGL_SELESAI' => $tgl_selesai,
|
|
'STATUS_KIRIM' => $id_karyawan,
|
|
'TGL_KIRIM' => $tgl,
|
|
'KET_SO_A' => "Sudah diproses oleh Div. Service Tanggal $tgl_now"
|
|
];
|
|
$action = $this->Penjualan->update('sales_order', $update, 'ID_SO', $id_so);
|
|
} else if (strpos($jabatan,"GUDANG")!==FALSE OR $jabatan=="ADMIN ITP") {
|
|
$input = [
|
|
'KARYAWAN_ID' => $id_karyawan,
|
|
'SO_ID' => $id_so
|
|
];
|
|
$action = $this->Penjualan->create('jadwal_pengiriman', $input);
|
|
$update = [
|
|
'TGL_SELESAI' => $tgl_selesai,
|
|
'STATUS_KIRIM' => $id_karyawan,
|
|
'TGL_KIRIM' => $tgl,
|
|
'KET_SO_A' => "Sudah diproses oleh Div. Gudang Tanggal $tgl_now"
|
|
];
|
|
$action = $this->Penjualan->update('sales_order', $update, 'ID_SO', $id_so);
|
|
} else {
|
|
$update = [
|
|
'TGL_SELESAI' => $tgl_selesai,
|
|
'STATUS_KIRIM' => $id_karyawan
|
|
];
|
|
$action = $this->Penjualan->update('sales_order', $update, 'ID_SO', $id_so);
|
|
}
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'diproses');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'diproses');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
//Controller Transaksi Retur
|
|
public function dataRetur_Gudang_A1() { // [68]
|
|
$datPelanggan = $this->Penjualan->getData_Pelanggan_byID();
|
|
$id_penjualan = NULL;
|
|
$kondisi = $this->input->post('kondisi');
|
|
$id_karyawan = $this->session->userdata('id_karyawan');
|
|
$level = $this->session->userdata('level');
|
|
|
|
if ($kondisi==NULL) {
|
|
$tanggal_awal = date('Y-m-01');
|
|
$tanggal_akhir = date('Y-m-d');
|
|
$id_pelanggan = NULL;
|
|
$title = "Belum Terpilih*";
|
|
} else {
|
|
$id_pelanggan = $this->input->post('id_pelanggan');
|
|
$tanggal_awal = $this->input->post('tanggal_awal');
|
|
$tanggal_akhir = $this->input->post('tanggal_akhir');
|
|
//Isi Judul
|
|
if ($id_pelanggan=="") {
|
|
$title = "Semua Pelanggan";
|
|
} else {
|
|
$dataPelanggan = $this->Penjualan->getData_Pelanggan_byID($id_pelanggan);
|
|
$nama_pelanggan = $dataPelanggan[0]['NAMA_PELANGGAN'];
|
|
$nama_kota = $dataPelanggan[0]['NAMA_KOTA'];
|
|
$title = "$nama_pelanggan ($nama_kota)";
|
|
}
|
|
}
|
|
|
|
$penjualan = $this->Penjualan->getData_Penjualan_1($id_penjualan, $level, $tanggal_awal, $tanggal_akhir, $id_pelanggan);
|
|
|
|
//Set Status Retur
|
|
$no = 0;
|
|
foreach ($penjualan as $key) {
|
|
$datRj = $this->Penjualan->getData_ReturPenjualan_byPENJUALAN_byKARYAWAN_Null($key['ID_PENJUALAN'], $id_karyawan);
|
|
if ($datRj==TRUE) {
|
|
$status = 1;
|
|
} else {
|
|
$status = 0;
|
|
}
|
|
|
|
$datSumPda = $this->Penjualan->getSum_PiutangDagang_byPENJUALAN($key['ID_PENJUALAN']);
|
|
if ($datSumPda[0]['TOTAL']<=0) {
|
|
$lock = 1;
|
|
} else {
|
|
$lock = 0;
|
|
}
|
|
|
|
$penjualan[$no] += ['STATUS' => $status];
|
|
$penjualan[$no++] += ['LOCK' => $lock];
|
|
}
|
|
$data = [
|
|
'sidebar' => "menu penjualan",
|
|
'navChild' => "returjual step1",
|
|
'penjualan' => $penjualan,
|
|
'pelanggan' => $datPelanggan,
|
|
'id_pelanggan' => $id_pelanggan,
|
|
'tanggal_awal' => $tanggal_awal,
|
|
'tanggal_akhir' => $tanggal_akhir,
|
|
'title' => $title,
|
|
|
|
];
|
|
$this->load->view('proses/PenjualanRetur_Gudang_A1', $data);
|
|
}
|
|
|
|
public function dataRetur_Gudang_A2($id) { // [69]
|
|
$id_karyawan = $this->session->userdata('id_karyawan');
|
|
$level = $this->session->userdata('level');
|
|
$tgl = date('Y-m-d');
|
|
$penjualan = $this->Penjualan->getData_DaftarReturJual_byPENJUALAN_byKARYAWAN_byLEVEL_KODENull($id, $id_karyawan, $level);
|
|
$datDo0 = $this->Penjualan->getData_DaftarOrder_byPENJUALAN_JENIS0($id, $level);
|
|
$datDo2 = $this->Penjualan->getData_DaftarOrder_byPENJUALAN_JENIS2($id);
|
|
$datPenjualan = $this->Penjualan->getData_Penjualan_byID($id);
|
|
$datSnJual = $this->Penjualan->getData_SnJual_byPENJUALAN($id);
|
|
|
|
//Set SN Retur Beli ke dalam Data DRB
|
|
$no = 0;
|
|
foreach ($penjualan as $key) {
|
|
$datSnRj = $this->Penjualan->getData_SnReturJual_byDRJ_RJNull($key['ID_DRJ']);
|
|
$penjualan[$no++] += ['SN' => $datSnRj];
|
|
}
|
|
|
|
//Set ID Retur Beli untuk Kunci
|
|
if ($penjualan==NULL) {
|
|
$id_rj = NULL;
|
|
} else {
|
|
$id_rj = $penjualan[0]['RJ_ID'];
|
|
}
|
|
|
|
$data = [
|
|
'sidebar' => "menu penjualan",
|
|
'navChild' => "returbeli step1",
|
|
'penjualan' => $penjualan,
|
|
'id_penjualan' => $id,
|
|
'id_rj' => $id_rj,
|
|
'tgl' => $tgl,
|
|
'snj' => $datSnJual,
|
|
'barang' => $datDo0,
|
|
'jasa' => $datDo2,
|
|
'kode_penjualan' => $datPenjualan[0]['KODE_PENJUALAN'],
|
|
'nama_pelanggan' => $datPenjualan[0]['NAMA_PELANGGAN'],
|
|
'sj_penjualan' => $datPenjualan[0]['SJ_PENJUALAN'],
|
|
'id_pelanggan' => $datPenjualan[0]['PELANGGAN_ID']
|
|
];
|
|
$this->load->view('proses/PenjualanRetur_Gudang_A2', $data);
|
|
}
|
|
|
|
public function simpanretur_GA2() { // [70]
|
|
$method = $this->input->post('method');
|
|
$id_drb = $this->input->post('id');
|
|
$id_penjualan = $this->input->post('id_penjualan');
|
|
$id_barang = $this->input->post('id_barang');
|
|
$qty_drj = $this->input->post('qty_drj');
|
|
$tgl_input = $this->input->post('tgl_input');
|
|
$snretur = $this->input->post('snretur');
|
|
$jenis_drj = $this->input->post('jenis_drj');
|
|
$id_karyawan = $this->session->userdata('id_karyawan');
|
|
$level = $this->session->userdata('level');
|
|
$tgl = date('Y-m-d');
|
|
|
|
//Check apakah Tanggal Melebihi hari Ini
|
|
if (strtotime($tgl_input)>strtotime($tgl)) {
|
|
$this->session->set_flashdata('date_error', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah nilai benar.
|
|
if ($jenis_drj==0 OR $jenis_drj==2) {
|
|
if ($qty_drj<=0) {
|
|
$this->session->set_flashdata('not_zero_negative', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_byPENJUALAN($id_penjualan);
|
|
foreach ($datDo as $key) {
|
|
$sumDrj = $this->Penjualan->getSum_DaftarReturJual_byPENJUALAN_byBARANG($id_penjualan, $id_barang);
|
|
if ($key['BARANG_ID']==$id_barang) {
|
|
$total = $sumDrj[0]['TOTAL_DRJ']+$qty_drj;
|
|
if ($total>$key['QTY_DO']) {
|
|
$this->session->set_flashdata('over_qty', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
} else if ($jenis_drj==1) { //Check apakah SN belum terpakai.
|
|
foreach ($snretur as $key) {
|
|
$datSnJual = $this->Penjualan->getData_SnJual_byID($key);
|
|
if ($datSnJual[0]['STATUS_SNSTOCK']!="1") {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
|
|
$datRj = $this->Penjualan->getData_ReturPenjualan_byPENJUALAN_byADMIN_Null($id_penjualan, $id_karyawan);
|
|
if ($datRj==FALSE) {
|
|
$input = [
|
|
'ADMIN_ID' => $id_karyawan,
|
|
'PENJUALAN_ID' => $id_penjualan,
|
|
'TGL_INPUT' => $tgl_input,
|
|
'TGL_RJ' => $tgl
|
|
];
|
|
$action = $this->Penjualan->create('retur_penjualan', $input);
|
|
|
|
$id_rj = $this->Penjualan->getID_RJMax();
|
|
$id_rj = $id_rj[0]['ID_RJ'];
|
|
} else {
|
|
$id_rj = $datRj[0]['ID_RJ'];
|
|
}
|
|
|
|
if ($jenis_drj==1) {
|
|
foreach ($snretur as $key) {
|
|
$datSnJual = $this->Penjualan->getData_SnJual_byID($key);
|
|
$input = [
|
|
'RJ_ID' => $id_rj,
|
|
'NAMA_SNRJ' => $datSnJual[0]['NAMA_SNSTOCK'],
|
|
'DO_ID' => $datSnJual[0]['DO_ID']
|
|
];
|
|
$action = $this->Penjualan->create('sn_returjual', $input);
|
|
$update = [
|
|
'STATUS_SNSTOCK' => '4'
|
|
];
|
|
$action = $this->Penjualan->update('sn_stock', $update, 'NAMA_SNSTOCK', $datSnJual[0]['NAMA_SNSTOCK']);
|
|
}
|
|
|
|
$datSnRj = $this->Penjualan->getData_SnReturJual_byRJ_groupBARANG($id_rj);
|
|
foreach ($datSnRj as $key) {
|
|
$qty = 0;
|
|
foreach ($snretur as $dat) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_bySNJ_4($dat);
|
|
if ($datSnStock[0]['BARANG_ID']==$key['BARANG_ID']) {
|
|
$qty = $qty+1;
|
|
}
|
|
}
|
|
|
|
$checkDrj = $this->Penjualan->getData_DaftarReturJual_byRJ_byBARANG_byADMIN_Null($id_rj, $key['BARANG_ID'], $id_karyawan);
|
|
if ($checkDrj==TRUE) {
|
|
$qtyDrjNew = $qty + $checkDrj[0]['QTY_DRJ'];
|
|
$update = [
|
|
'QTY_DRJ' => $qtyDrjNew
|
|
];
|
|
$action = $this->Penjualan->update('daftar_returjual', $update, 'ID_DRJ', $checkDrj[0]['ID_DRJ']);
|
|
} else {
|
|
$input = [
|
|
'RJ_ID' => $id_rj,
|
|
'BARANG_ID' => $key['BARANG_ID'],
|
|
'QTY_DRJ' => $qty,
|
|
'JENIS_DRJ' => $jenis_drj,
|
|
];
|
|
$action = $this->Penjualan->create('daftar_returjual', $input);
|
|
}
|
|
}
|
|
|
|
$datDrj = $this->Penjualan->getData_DaftarReturJual_byRJ_groupID($id_rj);
|
|
foreach ($datDrj as $key) {
|
|
$datSnRj = $this->Penjualan->getData_SnReturJual_byRJ_groupID($id_rj);
|
|
foreach ($datSnRj as $dat) {
|
|
if ($dat['BARANG_ID']==$key['BID']) {
|
|
$update = [
|
|
'DRJ_ID' => $key['ID_DRJ']
|
|
];
|
|
$action = $this->Penjualan->update('sn_returjual', $update, 'ID_SNRJ', $dat['ID_SNRJ']);
|
|
}
|
|
}
|
|
}
|
|
|
|
} else if ($jenis_drj==0 OR $jenis_drj==2) {
|
|
$input = [
|
|
'RJ_ID' => $id_rj,
|
|
'BARANG_ID' => $id_barang,
|
|
'QTY_DRJ' => $qty_drj,
|
|
'JENIS_DRJ' => $jenis_drj,
|
|
];
|
|
$action = $this->Penjualan->create('daftar_returjual', $input);
|
|
}
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function hapusretur_GA2() { // [71]
|
|
$id_drj = $this->input->post('id_drj');
|
|
|
|
//Check Konsistensi Data
|
|
$datDrj = $this->Penjualan->getData_DaftarReturJual_byID($id_drj);
|
|
if ($datDrj==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check Konsistensi Data
|
|
if ($datDrj[0]['STATUS_RJ']!=NULL) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePenjualan/dataRetur_Gudang_A1');
|
|
}
|
|
|
|
//Check Apakah SN Retur Beli sudah benar sesuai
|
|
if ($datDrj[0]['JENIS_DRJ']==1) {
|
|
$datSnRj = $this->Penjualan->getData_SnReturJual_byDRJ_RJNull($id_drj);
|
|
if ($datSnRj==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
foreach ($datSnRj as $dat) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_byNAMA_4($dat['NAMA_SNRJ']);
|
|
if ($datSnStock==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
|
|
//Set ID Retur Penjualan yang aktif
|
|
$id_rj = $datDrj[0]['RJ_ID'];
|
|
|
|
if ($datDrj[0]['JENIS_DRJ']==1) {
|
|
foreach ($datSnRj as $key) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_byNAMA_4($key['NAMA_SNRJ']);
|
|
if ($datSnStock==TRUE) {
|
|
$update = [
|
|
'STATUS_SNSTOCK' => '1'
|
|
];
|
|
$action = $this->Penjualan->update('sn_stock', $update, 'ID_SNSTOCK', $datSnStock[0]['ID_SNSTOCK']);
|
|
}
|
|
}
|
|
}
|
|
|
|
$action = $this->Penjualan->delete('sn_returjual', $id_drj ,'DRJ_ID');
|
|
$action = $this->Penjualan->delete('daftar_returjual', $id_drj ,'ID_DRJ');
|
|
|
|
$datDrjAfter = $this->Penjualan->getData_DaftarReturJual_byRJ_Null($id_rj);
|
|
if ($datDrjAfter==FALSE) {
|
|
$action = $this->Penjualan->delete('retur_penjualan', $id_rj, 'ID_RJ');
|
|
}
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
public function kodeReturPenjualan() { // [72]
|
|
$kk = $this->Penjualan->getKode_ReturPenjualan();
|
|
$tgl = date('y/m');
|
|
if (is_array($kk) || is_object($kk)) {
|
|
foreach ($kk as $row) {
|
|
if ($row['KODE'] == null) {
|
|
return "RJ/$tgl/00001";
|
|
} else {
|
|
$str = (string) $row['KODE'];
|
|
$tgl_lama = substr($str, 3, -6);
|
|
if ($tgl_lama!=$tgl) {
|
|
return "RJ/$tgl/00001";
|
|
} else {
|
|
$panjang = 5;
|
|
$data = substr($str, 9, $panjang);
|
|
$ko = (int) $data + 1;
|
|
$str = (string) $ko;
|
|
$panjang = 14 - strlen($str);
|
|
$data = "RJ/$tgl/00000";
|
|
$data = substr($data, 0, $panjang) . $str;
|
|
return $data;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function kunciretur_GA2() { // [73]
|
|
$method = $this->input->post('method');
|
|
$id_rj = $this->input->post('id_rj');
|
|
$ket_rj = $this->input->post('ket_rj');
|
|
$id_karyawan = $this->session->userdata('id_karyawan');
|
|
$level = $this->session->userdata('level');
|
|
$kode_rj = $this->kodeReturPenjualan();
|
|
$tgl = date('Y-m-d');
|
|
|
|
//Check Konsistensi Data
|
|
$datRj = $this->Penjualan->getData_ReturPenjualan_Null($id_rj);
|
|
if ($datRj==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check Konsistensi Data
|
|
$datDrj = $this->Penjualan->getData_DaftarReturJual_byPENJUALAN_byKARYAWAN_byLEVEL_KODENull($datRj[0]['PENJUALAN_ID'], $id_karyawan, $level);
|
|
if ($datDrj==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Set Hilangkan Enter di Keterangan
|
|
$ket_rj = preg_replace('/\R+/', " " , $ket_rj);
|
|
|
|
$update = [
|
|
'STATUS_RJ' => '0',
|
|
'KET_RJ' => $ket_rj,
|
|
'TGL_RJ' => $tgl,
|
|
'KODE_RJ' => $kode_rj,
|
|
];
|
|
$action = $this->Penjualan->update('retur_penjualan', $update, 'ID_RJ', $id_rj);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('data_lock', 'dikunci');
|
|
redirect('ManagePenjualan/dataRetur_Gudang_A1');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dikunci');
|
|
redirect('ManagePenjualan/dataRetur_Gudang_A1');
|
|
}
|
|
|
|
}
|
|
|
|
public function resetretur_GA2() { // [74]
|
|
$method = $this->input->post('method');
|
|
$id_rj = $this->input->post('id_rj');
|
|
$level = $this->session->userdata('level');
|
|
|
|
//Check Konsistensi Data
|
|
$datRj = $this->Penjualan->getData_ReturPenjualan_Null($id_rj);
|
|
if ($datRj==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check Konsistensi Data
|
|
$datDrj = $this->Penjualan->getData_DaftarReturJual_byRJ_Null($id_rj);
|
|
if ($datDrj==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check Konsistensi Data
|
|
$datSnRj = $this->Penjualan->getData_SnReturJual_byRJ_groupID($id_rj);
|
|
foreach ($datSnRj as $key) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_byNAMA_4($key['NAMA_SNRJ']);
|
|
if ($datSnStock==FALSE) {
|
|
$this->session->set_flashdata('failed', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
foreach ($datSnRj as $key) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_byNAMA_4($key['NAMA_SNRJ']);
|
|
$update = [
|
|
'STATUS_SNSTOCK' => '1'
|
|
];
|
|
$action = $this->Penjualan->update('sn_stock', $update, 'ID_SNSTOCK', $datSnStock[0]['ID_SNSTOCK']);
|
|
}
|
|
|
|
$action = $this->Penjualan->delete('sn_returjual', $id_rj, 'RJ_ID');
|
|
$action = $this->Penjualan->delete('daftar_returjual', $id_rj, 'RJ_ID');
|
|
$action = $this->Penjualan->delete('retur_penjualan', $id_rj, 'ID_RJ');
|
|
|
|
$this->session->set_flashdata('flush_data', 'direset');
|
|
redirect('ManagePenjualan/dataRetur_Gudang_A1');
|
|
|
|
}
|
|
|
|
public function dataRetur_Keuangan_A1() { // [75]
|
|
$datPenjualan = $this->Penjualan->getData_ReturPenjualan_0();
|
|
|
|
$data = [
|
|
'sidebar' => "menu penjualan",
|
|
'navChild' => "returjual step2",
|
|
'penjualan' => $datPenjualan,
|
|
];
|
|
$this->load->view('proses/PenjualanRetur_Keuangan_A1', $data);
|
|
}
|
|
|
|
public function dataRetur_Keuangan_A2($id) { // [76]
|
|
$penjualan = $this->Penjualan->getData_DaftarReturJual_byRJ_byBARANG_0($id);
|
|
$datRj = $this->Penjualan->getData_ReturPenjualan_0($id);
|
|
$datPda = $this->Penjualan->getData_PiutangDagang_byPENJUALAN($datRj[0]['PENJUALAN_ID']);
|
|
|
|
//Set Nilai Debet Hutang Dagang
|
|
$kredit_pda = 0;
|
|
foreach ($penjualan as $key) {
|
|
$kredit = $key['HARGA_DRJ']*$key['QTY_DRJ'];
|
|
$kredit_pda = $kredit_pda+$kredit;
|
|
}
|
|
|
|
//Set Nilai Bruto, PPN, Netto
|
|
$bruto = $kredit_pda;
|
|
$ppn_pda = $kredit_pda*($datRj[0]['PPN_SO']/100);
|
|
$kredit_pda = $kredit_pda*(($datRj[0]['PPN_SO']+100)/100);
|
|
$kredit_pda = round($kredit_pda);
|
|
|
|
$data = [
|
|
'sidebar' => "menu penjualan",
|
|
'navChild' => "returjual step2",
|
|
'penjualan' => $penjualan,
|
|
'id_rj' => $id,
|
|
'kredit_pda' => $kredit_pda,
|
|
'bruto' => $bruto,
|
|
'ppn_pda' => $ppn_pda,
|
|
'kode_rj' => $datRj[0]['KODE_RJ'],
|
|
'ppn_so' => $datRj[0]['PPN_SO'],
|
|
'nama_pelanggan' => $datRj[0]['NAMA_PELANGGAN'],
|
|
'debet_pda' => $datPda[0]['DEBET_PDA']
|
|
];
|
|
$this->load->view('proses/PenjualanRetur_Keuangan_A2', $data);
|
|
}
|
|
|
|
public function simpanretur_KA2() { // [77]
|
|
$method = $this->input->post('method');
|
|
$id_drj = $this->input->post('id_drj');
|
|
$harga_drj = $this->input->post('harga_drj');
|
|
|
|
//Check Konsistensi Data
|
|
$datDrj = $this->Penjualan->getData_DaftarReturJual_byID($id_drj);
|
|
if ($datDrj==FALSE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePenjualan/dataRetur_Keuangan_A1');
|
|
}
|
|
|
|
//Set Koma menjadi titik
|
|
$harga_drj = str_replace(',', '.', $harga_drj);
|
|
|
|
//Check Nilai apakah Numeric
|
|
$check_nilai = is_numeric($harga_drj);
|
|
if ($check_nilai==FALSE) {
|
|
$harga_drj = 0;
|
|
}
|
|
|
|
//Check apakah Nilai kurang dari 0
|
|
if ($harga_drj<0) {
|
|
$this->session->set_flashdata('not_zero_negative', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$update = [
|
|
'HARGA_DRJ' => $harga_drj
|
|
];
|
|
$action = $this->Penjualan->update('daftar_returjual', $update, 'ID_DRJ', $id_drj);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function hapusretur_KA2() { // [78]
|
|
$method = $this->input->post('method');
|
|
$id_drj = $this->input->post('id_drj');
|
|
|
|
//Check Konsistensi Data
|
|
$datDrj = $this->Penjualan->getData_DaftarReturJual_byID($id_drj);
|
|
if ($datDrj==FALSE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePenjualan/dataRetur_Keuangan_A1');
|
|
}
|
|
|
|
//Check apakah harganya masih Null
|
|
if ($datDrj[0]['HARGA_DRJ']==NULL) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$update = [
|
|
'HARGA_DRJ' => NULL
|
|
];
|
|
$action = $this->Penjualan->update('daftar_returjual', $update, 'ID_DRJ', $id_drj);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function batalretur_KA2() { // [79]
|
|
$method = $this->input->post('method');
|
|
$id_rj = $this->input->post('id_rj');
|
|
$level = $this->session->userdata('level');
|
|
|
|
//Check Konsistensi Data
|
|
$datRj = $this->Penjualan->getData_ReturPenjualan_0($id_rj);
|
|
if ($datRj==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect('ManagePenjualan/dataRetur_Keuangan_A1');
|
|
}
|
|
|
|
//Check Konsistensi Data
|
|
$datDrj = $this->Penjualan->getData_DaftarReturJual_byRJ_0($id_rj);
|
|
if ($datDrj==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check Konsistensi Data
|
|
$datSnRj = $this->Penjualan->getData_SnReturJual_byRJ_groupID($id_rj);
|
|
foreach ($datSnRj as $key) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_byNAMA_4($key['NAMA_SNRJ']);
|
|
if ($datSnStock==FALSE) {
|
|
$this->session->set_flashdata('failed', 'dibatalkan');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
foreach ($datSnRj as $key) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_byNAMA_4($key['NAMA_SNRJ']);
|
|
$update = [
|
|
'STATUS_SNSTOCK' => '1'
|
|
];
|
|
$action = $this->Penjualan->update('sn_stock', $update, 'ID_SNSTOCK', $datSnStock[0]['ID_SNSTOCK']);
|
|
}
|
|
|
|
$action = $this->Penjualan->delete('sn_returjual', $id_rj, 'RJ_ID');
|
|
$action = $this->Penjualan->delete('daftar_returjual', $id_rj, 'RJ_ID');
|
|
$action = $this->Penjualan->delete('retur_penjualan', $id_rj, 'ID_RJ');
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('data_void', 'dibatalkan');
|
|
redirect('ManagePenjualan/dataRetur_Keuangan_A1');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dibatalkan');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function kodeINVReturPenjualan() { // [80]
|
|
$kk = $this->Penjualan->getKode_INVReturPenjualan();
|
|
$tgl = date('y');
|
|
if (is_array($kk) || is_object($kk)) {
|
|
foreach ($kk as $row) {
|
|
if ($row['KODE'] == null) {
|
|
return "PI".$tgl."000001";
|
|
} else {
|
|
$str = (string) $row['KODE'];
|
|
$tgl_lama = substr($str, 2, -6);
|
|
if ($tgl_lama!=$tgl) {
|
|
return "PI".$tgl."000001";
|
|
} else {
|
|
$panjang = 6;
|
|
$data = substr($str, 4, $panjang);
|
|
$ko = (int) $data + 1;
|
|
$str = (string) $ko;
|
|
$panjang = 10 - strlen($str);
|
|
$data = "PI".$tgl."000000";
|
|
$data = substr($data, 0, $panjang) . $str;
|
|
return $data;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function kunciretur_KA2() { // [81]
|
|
$method = $this->input->post('method');
|
|
$id_rj = $this->input->post('id_rj');
|
|
$kredit_pda = $this->input->post('kredit_pda');
|
|
$level = $this->session->userdata('level');
|
|
$inv_rj = $this->kodeINVReturPenjualan();
|
|
$tgl = date('Y-m-d');
|
|
|
|
//Check Konsistensi Data
|
|
$datRj = $this->Penjualan->getData_ReturPenjualan_0($id_rj);
|
|
if ($datRj==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check Konsistensi Data
|
|
$datDrj = $this->Penjualan->getData_DaftarReturJual_byRJ_0($id_rj);
|
|
foreach ($datDrj as $key) {
|
|
if ($key['HARGA_DRJ']==NULL) {
|
|
$this->session->set_flashdata('price_check', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
$sumPda = $this->Penjualan->getSum_PiutangDagang_byPENJUALAN($datRj[0]['PENJUALAN_ID']);
|
|
$debetPda = $sumPda[0]['DEBET'];
|
|
$kreditPda = $sumPda[0]['KREDIT'];
|
|
$sumDrj = $this->Penjualan->getSum_DaftarReturJual_byRJ_groupDRJ_0($id_rj);
|
|
$totalRetur = round($sumDrj[0]['TOTAL']*(($sumDrj[0]['PPN_SO']+100)/100),0);
|
|
|
|
//Check apakah Nilai Retur ada Perbedaan
|
|
$totalKredit = $totalRetur + $kreditPda;
|
|
if ($debetPda<$totalRetur OR $debetPda<$totalKredit) {
|
|
$this->session->set_flashdata('piutang_error', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
foreach ($datDrj as $key) {
|
|
if ($key['TYPE_JENIS']!="2") {
|
|
$datKuantiti = $this->Penjualan->getData_Kuantiti_byID($key['BARANG_ID']);
|
|
if ($level == 0) {
|
|
$pcm_kuantiti = $datKuantiti[0]['PCM_KUANTITI'];
|
|
$global_kuantiti = $datKuantiti[0]['GLOBAL_KUANTITI'];
|
|
$pcm = $pcm_kuantiti+$key['QTY_DRJ'];
|
|
$global = $global_kuantiti+$key['QTY_DRJ'];
|
|
$update = [
|
|
'PCM_KUANTITI' => $pcm,
|
|
'GLOBAL_KUANTITI' => $global
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
} else if ($level == 1) {
|
|
$itp_kuantiti = $datKuantiti[0]['ITP_KUANTITI'];
|
|
$global_kuantiti = $datKuantiti[0]['GLOBAL_KUANTITI'];
|
|
$itp = $itp_kuantiti+$key['QTY_DRJ'];
|
|
$global = $global_kuantiti+$key['QTY_DRJ'];
|
|
$update = [
|
|
'ITP_KUANTITI' => $itp,
|
|
'GLOBAL_KUANTITI' => $global
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
}
|
|
|
|
$nilai_hq = $key['QTY_DRJ']*$key['HARGA_DRJ'];
|
|
$input = [
|
|
'TGL_HQ' => $tgl,
|
|
'KODE_BUKTI' => $datRj[0]['KODE_RJ'],
|
|
'INV_HQ' => $inv_rj,
|
|
'BARANG_ID' => $key['BARANG_ID'],
|
|
'MASUK_HQ' => $key['QTY_DRJ'],
|
|
'NILAI_HQ' => $nilai_hq,
|
|
'KELUAR_HQ' => '0'
|
|
];
|
|
$action = $this->Penjualan->create('histori_kuantiti', $input);
|
|
}
|
|
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$datSnRj = $this->Penjualan->getData_SnReturJual_byRJ_byBARANG($id_rj,$key['BARANG_ID']);
|
|
foreach ($datSnRj as $dat) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_byNAMA_4($dat['NAMA_SNRJ']);
|
|
$input = [
|
|
'PELANGGAN_ID' => $datRj[0]['PELANGGAN_ID'],
|
|
'SNSTOCK_ID' => $datSnStock[0]['ID_SNSTOCK'],
|
|
'INV_HSN' => $inv_rj,
|
|
'KODE_BUKTI' => $datRj[0]['KODE_RJ'],
|
|
'TGL_HSN' => $tgl
|
|
];
|
|
$action = $this->Penjualan->create('histori_sn', $input);
|
|
$update = [
|
|
'STATUS_SNSTOCK' => NULL
|
|
];
|
|
$action = $this->Penjualan->update('sn_stock', $update, 'ID_SNSTOCK', $datSnStock[0]['ID_SNSTOCK']);
|
|
}
|
|
}
|
|
}
|
|
|
|
$kode_penjualan = $datRj[0]['KODE_PENJUALAN'];
|
|
$ket_pda = "No Nota : $kode_penjualan";
|
|
$input = [
|
|
'PELANGGAN_ID' => $datRj[0]['PELANGGAN_ID'],
|
|
'PENJUALAN_ID' => $datRj[0]['PENJUALAN_ID'],
|
|
'TRANSAKSI_PDA' => '2',
|
|
'KODE_BUKTI' => $datRj[0]['KODE_RJ'],
|
|
'TGL_PDA' => $tgl,
|
|
'DEBET_PDA' => '0',
|
|
'KREDIT_PDA' => $kredit_pda,
|
|
'KET_PDA' => $ket_pda
|
|
];
|
|
$action = $this->Penjualan->create('piutang_dagang', $input);
|
|
|
|
$update = [
|
|
'STATUS_RJ' => '1',
|
|
'INV_RJ' => $inv_rj,
|
|
'TGL_RJ' => $tgl
|
|
];
|
|
$action = $this->Penjualan->update('retur_penjualan', $update, 'ID_RJ', $id_rj);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('data_lock', 'dikunci');
|
|
redirect('ManagePenjualan/dataRetur_Keuangan_A1');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dikunci');
|
|
redirect('ManagePenjualan/dataRetur_Keuangan_A1');
|
|
}
|
|
|
|
}
|
|
|
|
//Controller Transaksi Perubahan Data
|
|
public function dataUbah_Keuangan_A1() { // [82]
|
|
$kondisi = $this->input->post('kondisi');
|
|
$id_penjualan = NULL;
|
|
$level = $this->session->userdata('level');
|
|
$tgl = date('Y-m-d');
|
|
$set = 1;
|
|
|
|
if ($kondisi==null){
|
|
$tanggal_akhir = date('Y-m-d');
|
|
$tanggal_now = date('Y-m-01');
|
|
$tanggal_awal = $this->Penjualan->subTempoMonth($tanggal_now, 2);
|
|
} else {
|
|
$tanggal_awal = $this->input->post('tanggal_awal');
|
|
$tanggal_akhir = $this->input->post('tanggal_akhir');
|
|
$tanggal_now = date('Y-m-01');
|
|
$temporaryAwal = $this->Penjualan->subTempoMonth($tanggal_now, 2);
|
|
if (strtotime($tanggal_awal)<strtotime($temporaryAwal)) {
|
|
$tanggal_awal = $temporaryAwal;
|
|
}
|
|
}
|
|
|
|
$penjualan = $this->Penjualan->getData_Penjualan_forUbah($id_penjualan, $level, $tanggal_awal, $tanggal_akhir);
|
|
$data = [
|
|
'sidebar' => "menu penjualan",
|
|
'navChild' => "penjualan ubah",
|
|
'penjualan' => $penjualan,
|
|
'tgl' => $tgl,
|
|
'tanggal_awal' => $tanggal_awal,
|
|
'tanggal_akhir' => $tanggal_akhir,
|
|
'set' => $set
|
|
];
|
|
$this->load->view('proses/PenjualanUbah_Keuangan_A1', $data);
|
|
}
|
|
|
|
public function loginkoreksi_Penjualan_KA1() { // [83]
|
|
$username = $this->input->post('username');
|
|
$password = $this->input->post('password');
|
|
$datKaryawan = $this->Penjualan->getData_Karyawan_forLogin($username, $password);
|
|
|
|
if ($datKaryawan == TRUE and $datKaryawan[0]['NAMA_JABATAN'] == "ADMIN KEUANGAN") {
|
|
$this->session->set_flashdata('username_pass_success', 'login');
|
|
redirect('ManagePenjualan/dataUbah_Keuangan_A1_Admin');
|
|
} else if ($datKaryawan == TRUE and $datKaryawan[0]['NAMA_JABATAN'] == "ADMIN ITP") {
|
|
$this->session->set_flashdata('username_pass_success', 'login');
|
|
redirect('ManagePenjualan/dataUbah_Keuangan_A1_Admin');
|
|
} else if ($datKaryawan == TRUE and $datKaryawan[0]['NAMA_JABATAN'] == "ADMINISTRATOR") {
|
|
$this->session->set_flashdata('username_pass_success', 'login');
|
|
redirect('ManagePenjualan/dataUbah_Keuangan_A1_Admin');
|
|
} else {
|
|
$this->session->set_flashdata('username_pass_error', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
public function dataUbah_Keuangan_A1_Admin() { // [84]
|
|
$kondisi = $this->input->post('kondisi');
|
|
$id_penjualan = NULL;
|
|
$level = $this->session->userdata('level');
|
|
$tgl = date('Y-m-d');
|
|
$set = 0;
|
|
|
|
if ($kondisi==null){
|
|
$tanggal_akhir = date('Y-m-d');
|
|
$tanggal_now = date('Y-m-01');
|
|
$tanggal_awal = $this->Penjualan->subTempoMonth($tanggal_now, 2);
|
|
} else {
|
|
$tanggal_awal = $this->input->post('tanggal_awal');
|
|
$tanggal_akhir = $this->input->post('tanggal_akhir');
|
|
$tanggal_now = date('Y-m-01');
|
|
$temporaryAwal = $this->Penjualan->subTempoMonth($tanggal_now, 2);
|
|
if (strtotime($tanggal_awal)<strtotime($temporaryAwal)) {
|
|
$tanggal_awal = $temporaryAwal;
|
|
}
|
|
}
|
|
|
|
$penjualan = $this->Penjualan->getData_Penjualan_forUbah($id_penjualan, $level, $tanggal_awal, $tanggal_akhir);
|
|
$data = [
|
|
'sidebar' => "menu penjualan",
|
|
'navChild' => "penjualan ubah",
|
|
'penjualan' => $penjualan,
|
|
'tgl' => $tgl,
|
|
'tanggal_awal' => $tanggal_awal,
|
|
'tanggal_akhir' => $tanggal_akhir,
|
|
'set' => $set
|
|
];
|
|
$this->load->view('proses/PenjualanUbah_Keuangan_A1', $data);
|
|
}
|
|
|
|
public function dataUbah_Keuangan_A2($id) { // [85]
|
|
$level = $this->session->userdata('level');
|
|
$penjualan = $this->Penjualan->getData_Penjualan_forUbah($id, $level);
|
|
$datCetak = $this->Penjualan->getData_CetakDokumen_byPENJUALAN_forNota($id);
|
|
$datPenjualan = $this->Penjualan->getData_Penjualan_byID($id);
|
|
$tgl = date('Y-m-d');
|
|
$set = 1;
|
|
|
|
//Set Tanggal Cetak
|
|
$penjualan[0] += ['TGLCTK' => $datCetak[0]['TGL_CETAK']];
|
|
|
|
//Set Sales Aktif
|
|
if ($level == 0) {
|
|
$datKaryawan = $this->Penjualan->getData_Karyawan_SalesPcm();
|
|
} else if ($level == 1) {
|
|
$datKaryawan = $this->Penjualan->getData_Karyawan_SalesItp();
|
|
}
|
|
|
|
$data = [
|
|
'sidebar' => "menu penjualan",
|
|
'navChild' => "penjualan ubah",
|
|
'penjualan' => $penjualan,
|
|
'karyawan' => $datKaryawan,
|
|
'kode_so' => $datPenjualan[0]['KODE_SO'],
|
|
'inv_penjualan' => $datPenjualan[0]['INV_PENJUALAN'],
|
|
'id_penjualan' => $id,
|
|
'tgl' => $tgl,
|
|
'set' => $set
|
|
];
|
|
$this->load->view('proses/PenjualanUbah_Keuangan_A2', $data);
|
|
}
|
|
|
|
public function dataUbah_Keuangan_A2_Admin($id) { // [86]
|
|
$level = $this->session->userdata('level');
|
|
$penjualan = $this->Penjualan->getData_Penjualan_forUbah($id, $level);
|
|
$datCetak = $this->Penjualan->getData_CetakDokumen_byPENJUALAN_forNota($id);
|
|
$datPenjualan = $this->Penjualan->getData_Penjualan_byID($id);
|
|
$tgl = date('Y-m-d');
|
|
$set = 0;
|
|
|
|
//Set Tanggal Cetak
|
|
$penjualan[0] += ['TGLCTK' => $datCetak[0]['TGL_CETAK']];
|
|
|
|
//Set Sales berdasarkan Cabang
|
|
if ($level == 0) {
|
|
$datKaryawan = $this->Penjualan->getData_Karyawan_SalesPcm();
|
|
} else if ($level == 1) {
|
|
$datKaryawan = $this->Penjualan->getData_Karyawan_SalesItp();
|
|
}
|
|
|
|
$data = [
|
|
'sidebar' => "menu penjualan",
|
|
'navChild' => "penjualan ubah",
|
|
'penjualan' => $penjualan,
|
|
'karyawan' => $datKaryawan,
|
|
'kode_so' => $datPenjualan[0]['KODE_SO'],
|
|
'inv_penjualan' => $datPenjualan[0]['INV_PENJUALAN'],
|
|
'id_penjualan' => $id,
|
|
'tgl' => $tgl,
|
|
'set' => $set
|
|
];
|
|
$this->load->view('proses/PenjualanUbah_Keuangan_A2', $data);
|
|
}
|
|
|
|
public function ubahpenjualan_KA2() { // [87]
|
|
$method = $this->input->post('method');
|
|
$id_penjualan = $this->input->post('id_penjualan');
|
|
$tt_penjualan = $this->input->post('tt_penjualan');
|
|
$fp_penjualan = $this->input->post('fp_penjualan');
|
|
$id_sales = $this->input->post('id_sales');
|
|
$gp_so = $this->input->post('gp_so');
|
|
$fee_so = $this->input->post('fee_so');
|
|
$po_so = $this->input->post('po_so');
|
|
$ket_so_o = $this->input->post('ket_so_o');
|
|
$ket_pda = $this->input->post('ket_pda');
|
|
$set = $this->input->post('set');
|
|
$level = $this->session->userdata('level');
|
|
$tgl_now = date('Y-m-01');
|
|
$tgl = date('Y-m-d');
|
|
|
|
//Check Konsistensi Data
|
|
$datPenjualan = $this->Penjualan->getData_Penjualan_forUbah($id_penjualan, $level);
|
|
if ($datPenjualan==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah Fee sudah diproses atau Belum
|
|
if ($set == 0) {
|
|
if ($datPenjualan[0]['FEE_SO']>0) {
|
|
$datBiayaFee = $this->Penjualan->getData_BiayaFee_byPENJUALAN($id_penjualan);
|
|
if ($datBiayaFee==TRUE) {
|
|
$this->session->set_flashdata('kasbank_processed', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
|
|
//Check apakah tanggal lebih dari hari ini
|
|
if (strtotime($tt_penjualan)>strtotime($tgl)) {
|
|
$this->session->set_flashdata('date_error', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
if ($tt_penjualan=="") {
|
|
$tt_penjualan = NULL;
|
|
}
|
|
|
|
if ($fee_so=="") {
|
|
$fee_so = 0;
|
|
}
|
|
|
|
$checkFee = is_numeric($fee_so);
|
|
if ($checkFee==FALSE) {
|
|
$fee_so = 0;
|
|
}
|
|
|
|
//Check apakah angka Fee kurang dari 0
|
|
if ($fee_so<0) {
|
|
$this->session->set_flashdata('fee_false', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$dataPenjualan = $this->Penjualan->getData_Penjualan_byID($id_penjualan);
|
|
if ($tt_penjualan==NULL) {
|
|
$tempo_penjualan = $dataPenjualan[0]['TEMPO_PENJUALAN'];
|
|
} else {
|
|
$tempo_penjualan = $this->Penjualan->addTempoDay($tt_penjualan, $dataPenjualan[0]['TOP_PELANGGAN']);
|
|
}
|
|
|
|
$ket_so_o = preg_replace('/\R+/', " " , $ket_so_o);
|
|
$ket_pda = preg_replace('/\R+/', " " , $ket_pda);
|
|
$po_so = strtoupper($po_so);
|
|
$fp_penjualan = strtoupper($fp_penjualan);
|
|
|
|
$update = [
|
|
'TT_PENJUALAN' => $tt_penjualan,
|
|
'TEMPO_PENJUALAN' => $tempo_penjualan,
|
|
'FP_PENJUALAN' => $fp_penjualan
|
|
];
|
|
$action = $this->Penjualan->update('penjualan', $update, 'ID_PENJUALAN', $id_penjualan);
|
|
|
|
$update = [
|
|
'KET_PDA' => $ket_pda
|
|
];
|
|
$action = $this->Penjualan->update('piutang_dagang', $update, 'ID_PDA', $datPenjualan[0]['ID_PDA']);
|
|
|
|
if ($set == 1) {
|
|
$update = [
|
|
'PO_SO' => $po_so,
|
|
'KET_SO_O' => $ket_so_o
|
|
];
|
|
$action = $this->Penjualan->update('sales_order', $update, 'ID_SO', $datPenjualan[0]['SO_ID']);
|
|
} else if ($set == 0) {
|
|
$update = [
|
|
'PO_SO' => $po_so,
|
|
'KET_SO_O' => $ket_so_o,
|
|
'FEE_SO' => $fee_so,
|
|
'GP_SO' => $gp_so,
|
|
'SALES_ID' => $id_sales
|
|
];
|
|
$action = $this->Penjualan->update('sales_order', $update, 'ID_SO', $datPenjualan[0]['SO_ID']);
|
|
}
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'diubah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'diubah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function dataUbah_Keuangan_B1() { // [88]
|
|
$penjualan = $this->Penjualan->getData_Penjualan_forKomisiUbah();
|
|
$tgl = date('Y-m-d');
|
|
|
|
$data = [
|
|
'sidebar' => "menu penjualan",
|
|
'navChild' => "penjualan ubah komisi",
|
|
'penjualan' => $penjualan,
|
|
'tgl' => $tgl,
|
|
];
|
|
$this->load->view('proses/PenjualanUbah_Keuangan_B1', $data);
|
|
}
|
|
|
|
public function ubahpenjualan_KB1() { // [89]
|
|
$method = $this->input->post('method');
|
|
$id_do = $this->input->post('id_doed');
|
|
$komisi_do = $this->input->post('komisi_doed');
|
|
|
|
//Set Koma menjadi titik
|
|
$komisi_do = str_replace(',', '.', $komisi_do);
|
|
|
|
//Check apakah nilainya Numeric
|
|
$checkKomisi = is_numeric($komisi_do);
|
|
if ($checkKomisi==FALSE) {
|
|
$komisi_do = 0;
|
|
}
|
|
|
|
$update = [
|
|
'KOMISI_DO' => $komisi_do
|
|
];
|
|
$action = $this->Penjualan->update('daftar_order', $update, 'ID_DO', $id_do);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'diubah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'diubah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
//Controller Transaksi Batal Penjualan
|
|
public function dataBatal_Admin_GKA1() { // [90]
|
|
$id_penjualan = NULL;
|
|
$level = $this->session->userdata('level');
|
|
$penjualan = $this->Penjualan->getData_Penjualan_forBatal($id_penjualan, $level);
|
|
$tgl = date('m');
|
|
$tahun = date('Y');
|
|
|
|
//Set Bulan
|
|
if ($tgl == "01" ) {
|
|
$bulan = "Januari";
|
|
} elseif ($tgl == "02") {
|
|
$bulan = "Februari";
|
|
} elseif ($tgl == "03") {
|
|
$bulan = "Maret";
|
|
} elseif ($tgl == "04") {
|
|
$bulan = "April";
|
|
} elseif ($tgl == "05") {
|
|
$bulan = "Mei";
|
|
} elseif ($tgl == "06") {
|
|
$bulan = "Juni";
|
|
} elseif ($tgl == "07") {
|
|
$bulan = "Juli";
|
|
} elseif ($tgl == "08") {
|
|
$bulan = "Agustus";
|
|
} elseif ($tgl == "09") {
|
|
$bulan = "September";
|
|
} elseif ($tgl == "10") {
|
|
$bulan = "Oktober";
|
|
} elseif ($tgl == "11") {
|
|
$bulan = "November";
|
|
} elseif ($tgl == "12") {
|
|
$bulan = "Desember";
|
|
}
|
|
|
|
$data = [
|
|
'sidebar' => "menu penjualan",
|
|
'navChild' => "penjualan batal",
|
|
'penjualan' => $penjualan,
|
|
'bulan' => $bulan,
|
|
'tahun' => $tahun
|
|
];
|
|
$this->load->view('proses/PenjualanBatal_Admin_GKA1', $data);
|
|
}
|
|
|
|
public function batalpenjualan_GKA1() { // [91]
|
|
$method = $this->input->post('method');
|
|
$id_penjualan = $this->input->post('id_penjualan');
|
|
$ket_batal = $this->input->post('ket_batal');
|
|
$level = $this->session->userdata('level');
|
|
$tgl_now = date('Y-m-01');
|
|
$tgl = date('Y-m-d');
|
|
|
|
//Check Konsistensi Data
|
|
$datPenjualan = $this->Penjualan->getData_Penjualan_forBatal($id_penjualan, $level);
|
|
if ($datPenjualan==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah Fee sudah diproses oleh Keuangan
|
|
if ($datPenjualan[0]['STATUS_FEE']!=NULL) {
|
|
$this->session->set_flashdata('data_used_fee', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah dibatalkan berbeda bulan
|
|
if (strtotime($tgl_now)>strtotime($datPenjualan[0]['TGL_PENJUALAN'])) {
|
|
$this->session->set_flashdata('date_error', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah ada Retur Penjualan
|
|
$datRj = $this->Penjualan->getData_ReturPenjualan_byPENJUALAN($id_penjualan);
|
|
if ($datRj==TRUE) {
|
|
$this->session->set_flashdata('data_used_retur', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah ada proses Keuangan
|
|
$datPda = $this->Penjualan->getData_PiutangDagang_byPENJUALAN($id_penjualan);
|
|
$countPda = count($datPda);
|
|
if (count($datPda)>=2) {
|
|
$this->session->set_flashdata('data_used_kasbank', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah Barang yang keluar mengalami perubahan data
|
|
$datIoKeluar = $this->Penjualan->getData_TransaksiStock_bySO_status1_Jenis0($datPenjualan[0]['SO_ID']);
|
|
foreach ($datIoKeluar as $key) {
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$datSnIo = $this->Penjualan->getData_SnIo_byIO_0($key['ID_IO']);
|
|
foreach ($datSnIo as $dat) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_SnIo_byNAMA_AllStatus($dat['NAMA_SNIO']);
|
|
if ($datSnStock[0]['STATUS_SNSTOCK']!="1") {
|
|
$this->session->set_flashdata('data_used', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//Check apakah Barang yang masuk mengalami perubahan data
|
|
$datIoMasuk = $this->Penjualan->getData_TransaksiStock_bySO_status1_Jenis1($datPenjualan[0]['SO_ID']);
|
|
foreach ($datIoMasuk as $key) {
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$datSnIo = $this->Penjualan->getData_SnIo_byIO_1($key['ID_IO']);
|
|
foreach ($datSnIo as $dat) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_SnIo_byNAMA_AllStatus($dat['NAMA_SNIO']);
|
|
if ($datSnStock[0]['STATUS_SNSTOCK']!=NULL) {
|
|
$this->session->set_flashdata('data_used_io', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//Check apakah Barang Order mengalami perubahan data
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_bySO($datPenjualan[0]['SO_ID']);
|
|
foreach ($datDo as $key) {
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$datSnj = $this->Penjualan->getData_SnJual_byDO($key['ID_DO']);
|
|
foreach ($datSnj as $dat) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_SnJual_byNAMA_AllStatus($dat['NAMA_SNJ']);
|
|
if ($datSnStock[0]['STATUS_SNSTOCK']!="1") {
|
|
$this->session->set_flashdata('data_used', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//Set Hilangkan Enter di Keterangan
|
|
$ket_batal = preg_replace('/\R+/', " " , $ket_batal);
|
|
|
|
$kode_penjualan = $datPenjualan[0]['KODE_PENJUALAN'];
|
|
foreach ($datIoKeluar as $key) {
|
|
$datKuantiti = $this->Penjualan->getData_Kuantiti_byID($key['BARANG_ID']);
|
|
if ($level == 0) {
|
|
$global_kuantiti = $datKuantiti[0]['GLOBAL_KUANTITI'];
|
|
$pcm_kuantiti = $datKuantiti[0]['PCM_KUANTITI'];
|
|
$global = $global_kuantiti+$key['QTY_IO'];
|
|
$pcm = $pcm_kuantiti+$key['QTY_IO'];
|
|
$update = [
|
|
'GLOBAL_KUANTITI' => $global,
|
|
'PCM_KUANTITI' => $pcm
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
} else if ($level == 1) {
|
|
$global_kuantiti = $datKuantiti[0]['GLOBAL_KUANTITI'];
|
|
$itp_kuantiti = $datKuantiti[0]['ITP_KUANTITI'];
|
|
$global = $global_kuantiti+$key['QTY_IO'];
|
|
$itp = $itp_kuantiti+$key['QTY_IO'];
|
|
$update = [
|
|
'GLOBAL_KUANTITI' => $global,
|
|
'ITP_KUANTITI' => $itp
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
}
|
|
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$datSnIo = $this->Penjualan->getData_SnIo_byIO_0($key['ID_IO']);
|
|
foreach ($datSnIo as $dat) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_SnIo_byNAMA_AllStatus($dat['NAMA_SNIO']);
|
|
if ($datSnStock[0]['STATUS_SNSTOCK']=="1") {
|
|
$update = [
|
|
'STATUS_SNSTOCK' => NULL
|
|
];
|
|
$action = $this->Penjualan->update('sn_stock', $update, 'ID_SNSTOCK', $datSnStock[0]['ID_SNSTOCK']);
|
|
}
|
|
}
|
|
$action = $this->Penjualan->delete('sn_io', $key['ID_IO'], 'IO_ID');
|
|
}
|
|
}
|
|
|
|
foreach ($datIoMasuk as $key) {
|
|
$datKuantiti = $this->Penjualan->getData_Kuantiti_byID($key['BARANG_ID']);
|
|
if ($level == 0) {
|
|
$global_kuantiti = $datKuantiti[0]['GLOBAL_KUANTITI'];
|
|
$pcm_kuantiti = $datKuantiti[0]['PCM_KUANTITI'];
|
|
$global = $global_kuantiti-$key['QTY_IO'];
|
|
$pcm = $pcm_kuantiti-$key['QTY_IO'];
|
|
$update = [
|
|
'GLOBAL_KUANTITI' => $global,
|
|
'PCM_KUANTITI' => $pcm
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
} else if ($level == 1) {
|
|
$global_kuantiti = $datKuantiti[0]['GLOBAL_KUANTITI'];
|
|
$itp_kuantiti = $datKuantiti[0]['ITP_KUANTITI'];
|
|
$global = $global_kuantiti-$key['QTY_IO'];
|
|
$itp = $itp_kuantiti-$key['QTY_IO'];
|
|
$update = [
|
|
'GLOBAL_KUANTITI' => $global,
|
|
'ITP_KUANTITI' => $itp
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
}
|
|
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$datSnIo = $this->Penjualan->getData_SnIo_byIO_1($key['ID_IO']);
|
|
foreach ($datSnIo as $dat) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_SnIo_byNAMA_AllStatus($dat['NAMA_SNIO']);
|
|
if ($datSnStock[0]['STATUS_SNSTOCK']==NULL) {
|
|
$action = $this->Penjualan->delete('sn_stock', $datSnStock[0]['ID_SNSTOCK'], 'ID_SNSTOCK');
|
|
}
|
|
}
|
|
$action = $this->Penjualan->delete('sn_io', $key['ID_IO'], 'IO_ID');
|
|
}
|
|
}
|
|
|
|
$datPl = $this->Penjualan->getData_PenarikanLaku_bySO_0($datPenjualan[0]['SO_ID']);
|
|
if ($datPl==TRUE) {
|
|
$setpl = 1;
|
|
} else {
|
|
$setpl = 0;
|
|
}
|
|
|
|
$datCd = $this->Penjualan->getData_CetakDokumen_forParsial($datPenjualan[0]['SO_ID']);
|
|
$countCd = count($datCd);
|
|
if ($countCd>=3) {
|
|
$datSjp = $this->Penjualan->getData_DaftarSjParsial_bySO_allStatus($datPenjualan[0]['SO_ID']);
|
|
foreach ($datSjp as $key) {
|
|
if ($key['TYPE_JENIS']!="2") {
|
|
$datKuantiti = $this->Penjualan->getData_Kuantiti_byID($key['BARANG_ID']);
|
|
if ($level == 0) {
|
|
$global_kuantiti = $datKuantiti[0]['GLOBAL_KUANTITI'];
|
|
$pcm_kuantiti = $datKuantiti[0]['PCM_KUANTITI'];
|
|
$global = $global_kuantiti+$key['QTY_SJP'];
|
|
$pcm = $pcm_kuantiti+$key['QTY_SJP'];
|
|
$update = [
|
|
'GLOBAL_KUANTITI' => $global,
|
|
'PCM_KUANTITI' => $pcm
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
} else if ($level == 1) {
|
|
$global_kuantiti = $datKuantiti[0]['GLOBAL_KUANTITI'];
|
|
$itp_kuantiti = $datKuantiti[0]['ITP_KUANTITI'];
|
|
$global = $global_kuantiti+$key['QTY_SJP'];
|
|
$itp = $itp_kuantiti+$key['QTY_SJP'];
|
|
$update = [
|
|
'GLOBAL_KUANTITI' => $global,
|
|
'ITP_KUANTITI' => $itp
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
}
|
|
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$datSnSj = $this->Penjualan->getData_SnSj_bySJP($key['ID_SJP']);
|
|
foreach ($datSnSj as $dat) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_SnSj_byNAMA_AllStatus($dat['NAMA_SNSJ']);
|
|
if ($datSnStock[0]['STATUS_SNSTOCK']=="1") {
|
|
$update = [
|
|
'STATUS_SNSTOCK' => NULL
|
|
];
|
|
$action = $this->Penjualan->update('sn_stock', $update, 'ID_SNSTOCK', $datSnStock[0]['ID_SNSTOCK']);
|
|
}
|
|
}
|
|
$action = $this->Penjualan->delete('sn_sjparsial', $key['ID_SJP'], 'SJP_ID');
|
|
$action = $this->Penjualan->delete('sn_jual', $key['DO_ID'], 'DO_ID');
|
|
}
|
|
}
|
|
}
|
|
$action = $this->Penjualan->delete('daftar_sjparsial', $datPenjualan[0]['SO_ID'], 'SO_ID');
|
|
} else {
|
|
foreach ($datDo as $key) {
|
|
if ($key['TYPE_JENIS']!="2") {
|
|
if ($setpl==0) {
|
|
$datKuantiti = $this->Penjualan->getData_Kuantiti_byID($key['BARANG_ID']);
|
|
if ($level == 0) {
|
|
$global_kuantiti = $datKuantiti[0]['GLOBAL_KUANTITI'];
|
|
$pcm_kuantiti = $datKuantiti[0]['PCM_KUANTITI'];
|
|
$global = $global_kuantiti+$key['QTY_DO'];
|
|
$pcm = $pcm_kuantiti+$key['QTY_DO'];
|
|
$update = [
|
|
'GLOBAL_KUANTITI' => $global,
|
|
'PCM_KUANTITI' => $pcm
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
} else if ($level == 1) {
|
|
$global_kuantiti = $datKuantiti[0]['GLOBAL_KUANTITI'];
|
|
$itp_kuantiti = $datKuantiti[0]['ITP_KUANTITI'];
|
|
$global = $global_kuantiti+$key['QTY_DO'];
|
|
$itp = $itp_kuantiti+$key['QTY_DO'];
|
|
$update = [
|
|
'GLOBAL_KUANTITI' => $global,
|
|
'ITP_KUANTITI' => $itp
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
}
|
|
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$datSnj = $this->Penjualan->getData_SnJual_byDO($key['ID_DO']);
|
|
foreach ($datSnj as $dat) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_SnJual_byNAMA_AllStatus($dat['NAMA_SNJ']);
|
|
if ($datSnStock[0]['STATUS_SNSTOCK']=="1") {
|
|
$update = [
|
|
'STATUS_SNSTOCK' => NULL
|
|
];
|
|
$action = $this->Penjualan->update('sn_stock', $update, 'ID_SNSTOCK', $datSnStock[0]['ID_SNSTOCK']);
|
|
}
|
|
}
|
|
$action = $this->Penjualan->delete('sn_jual', $key['ID_DO'], 'DO_ID');
|
|
}
|
|
} else if ($setpl==1) {
|
|
$datKuantiti = $this->Penjualan->getData_Kuantiti_byID($key['BARANG_ID']);
|
|
$global_kuantiti = $datKuantiti[0]['GLOBAL_KUANTITI'];
|
|
$konsinyasi_kuantiti = $datKuantiti[0]['KONSINYASI_KUANTITI'];
|
|
$global = $global_kuantiti+$key['QTY_DO'];
|
|
$konsinyasi = $konsinyasi_kuantiti+$key['QTY_DO'];
|
|
$update = [
|
|
'GLOBAL_KUANTITI' => $global,
|
|
'KONSINYASI_KUANTITI' => $konsinyasi
|
|
];
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$datSnj = $this->Penjualan->getData_SnJual_byDO($key['ID_DO']);
|
|
foreach ($datSnj as $dat) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_SnJual_byNAMA_AllStatus($dat['NAMA_SNJ']);
|
|
if ($datSnStock[0]['STATUS_SNSTOCK']=="1") {
|
|
$update = [
|
|
'STATUS_SNSTOCK' => '11'
|
|
];
|
|
$action = $this->Penjualan->update('sn_stock', $update, 'ID_SNSTOCK', $datSnStock[0]['ID_SNSTOCK']);
|
|
$datSnk = $this->Penjualan->getData_SnKonsi_byPL_byNAMA_0($datPl[0]['ID_PL'], $dat['NAMA_SNJ']);
|
|
$update = [
|
|
'STATUS_SNK' => NULL,
|
|
'PL_ID' => NULL
|
|
];
|
|
$action = $this->Penjualan->update('sn_konsi', $update, 'ID_SNK', $datSnk[0]['ID_SNK']);
|
|
}
|
|
}
|
|
$action = $this->Penjualan->delete('sn_jual', $key['ID_DO'], 'DO_ID');
|
|
}
|
|
$datDpl = $this->Penjualan->getData_DaftarPenarikanLaku_byPL_byBARANG($datPl[0]['ID_PL'], $key['BARANG_ID']);
|
|
$action = $this->Penjualan->delete('daftar_penarikanlaku', $datDpl[0]['ID_DPL'], 'ID_DPL');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$datLogNotifikasi = $this->Penjualan->getData_LogNotifikasi_bySO($datPenjualan[0]['SO_ID']);
|
|
foreach ($datLogNotifikasi as $key) {
|
|
$action = $this->Penjualan->delete('log_notifikasi', $key['ID_LOG_NOTIFIKASI'], 'ID_LOG_NOTIFIKASI');
|
|
}
|
|
|
|
$action = $this->Penjualan->delete('histori_kuantiti', $kode_penjualan, 'KODE_BUKTI');
|
|
$action = $this->Penjualan->delete('histori_sn', $kode_penjualan, 'KODE_BUKTI');
|
|
$action = $this->Penjualan->delete('histori_sn', $datPenjualan[0]['KODE_SO'], 'KODE_BUKTI');
|
|
$action = $this->Penjualan->delete('transaksi_stock', $datPenjualan[0]['SO_ID'], 'SO_ID');
|
|
$action = $this->Penjualan->delete('piutang_dagang', $id_penjualan, 'PENJUALAN_ID');
|
|
$action = $this->Penjualan->delete('quality_control', $datPenjualan[0]['SO_ID'], 'SO_ID');
|
|
$action = $this->Penjualan->delete('cetak_dokumen', $datPenjualan[0]['SO_ID'], 'SO_ID');
|
|
$action = $this->Penjualan->delete('cetak_dokumen', $id_penjualan, 'PENJUALAN_ID');
|
|
$action = $this->Penjualan->delete('hasil_hitungpda', $id_penjualan, 'PENJUALAN_ID');
|
|
$action = $this->Penjualan->delete('notifikasi', $datPenjualan[0]['SO_ID'], 'SO_ID');
|
|
$action = $this->Penjualan->delete('jadwal_pengiriman', $datPenjualan[0]['SO_ID'], 'SO_ID');
|
|
|
|
$debet_pda = 0;
|
|
foreach ($datDo as $key) {
|
|
$subtotal = $key['QTY_DO']*$key['HARGA_DO'];
|
|
$debet_pda = $debet_pda+$subtotal;
|
|
}
|
|
|
|
$datSo = $this->Penjualan->getData_SalesOrder_byID($datPenjualan[0]['SO_ID']);
|
|
$debet_pda = $debet_pda*((100+$datSo[0]['PPN_SO'])/100);
|
|
$debet_pda = round($debet_pda);
|
|
|
|
if ($setpl==0) {
|
|
$update = [
|
|
'STATUS_SO' => '5',
|
|
'KET_SO_A' => $ket_batal,
|
|
'NILAI_SO' => $debet_pda,
|
|
'TS_SIAPKIRIM' => NULL,
|
|
'KUNCI_ID' => NULL,
|
|
'TS_TERKUNCI' => NULL,
|
|
'TS_TERKIRIM' => NULL,
|
|
'TGL_KIRIM' => NULL,
|
|
];
|
|
$action = $this->Penjualan->update('sales_order', $update, 'ID_SO', $datPenjualan[0]['SO_ID']);
|
|
} else {
|
|
$update = [
|
|
'STATUS_SO' => '5',
|
|
'KET_SO_A' => $ket_batal,
|
|
'NILAI_SO' => $debet_pda,
|
|
'PL_ID' => NULL,
|
|
'TS_SIAPKIRIM' => NULL,
|
|
'KUNCI_ID' => NULL,
|
|
'TS_TERKUNCI' => NULL,
|
|
'TS_TERKIRIM' => NULL,
|
|
'TGL_KIRIM' => NULL,
|
|
];
|
|
$action = $this->Penjualan->update('sales_order', $update, 'ID_SO', $datPenjualan[0]['SO_ID']);
|
|
$action = $this->Penjualan->delete('penarikan_laku', $datPl[0]['ID_PL'], 'ID_PL');
|
|
}
|
|
|
|
$update = [
|
|
'KET_BATAL' => $ket_batal,
|
|
'STATUS_PENJUALAN' => '0',
|
|
'TGL_BATAL' => $tgl
|
|
];
|
|
$action = $this->Penjualan->update('penjualan', $update, 'ID_PENJUALAN', $id_penjualan);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'dibatalkan');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dibatalkan');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
//Controller Transaksi Revisi
|
|
public function dataRevisi_Sales_SA1() { // [92]
|
|
$id_corp = NULL;
|
|
$id_sales = $this->session->userdata('id_karyawan');
|
|
$jabatan = $this->session->userdata('jabatan');
|
|
$level = $this->session->userdata('level');
|
|
$datPenjualan = $this->Penjualan->getData_SalesOrder_Not1_Not2_Not5_Not8_Not9($id_sales);
|
|
$datCorp = $this->Penjualan->getData_Corp_So($id_corp, $level);
|
|
$datPelanggan = $this->Penjualan->getData_Pelanggan_byID();
|
|
$datSales = $this->Penjualan->getData_Karyawan_byID($id_sales);
|
|
$data = [
|
|
'sidebar' => "menu penjualan",
|
|
'navChild' => "penjualan step1",
|
|
'penjualan' => $datPenjualan,
|
|
'corp' => $datCorp,
|
|
'pelanggan' => $datPelanggan,
|
|
'nama_sales' => $datSales[0]['NAMA_PANGGILAN_KARYAWAN'],
|
|
'jabatan' => $jabatan,
|
|
'id_sales' => $id_sales,
|
|
];
|
|
|
|
$this->load->view('proses/PenjualanRevisi_Sales_SA1', $data);
|
|
}
|
|
|
|
public function ubahso_SA1() { // [93]
|
|
$method = $this->input->post('method');
|
|
$id_so = $this->input->post('id_so');
|
|
$id_corp = $this->input->post('id_corped');
|
|
$id_pelanggan = $this->input->post('id_pelangganed');
|
|
$ppn_so = $this->input->post('ppn_soed');
|
|
$fee_so = $this->input->post('fee_soed');
|
|
$po_so = $this->input->post('po_soed');
|
|
$gp_so = $this->input->post('radio_gp');
|
|
$ongkir_so = $this->input->post('radio_ongkir');
|
|
$ket_so_g = $this->input->post('ket_so_g');
|
|
$ket_so_k = $this->input->post('ket_so_k');
|
|
$ket_so_t = $this->input->post('ket_so_t');
|
|
$ket_so_p = $this->input->post('ket_so_p');
|
|
$reminder_so = $this->input->post('reminder_so');
|
|
$id_sales = $this->session->userdata('id_karyawan');
|
|
|
|
//Check Konsistensi Data
|
|
$datSo = $this->Penjualan->getData_SalesOrder_Not1_Not2_Not5_Not8_Not9($id_sales, $id_so);
|
|
if ($datSo==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Set Koma menjadi titik
|
|
$fee_so = str_replace(',', '.', $fee_so);
|
|
$ppn_so = str_replace(',', '.', $ppn_so);
|
|
|
|
//Check apakah Nilai Fee Numeric
|
|
$check_fee = is_numeric($fee_so);
|
|
if ($check_fee==FALSE) {
|
|
$fee_so = 0;
|
|
}
|
|
|
|
//Check apakah Nilai PPN Numeric
|
|
$check_ppn = is_numeric($ppn_so);
|
|
if ($check_ppn==FALSE) {
|
|
$ppn_so = 0;
|
|
}
|
|
|
|
if ($fee_so=="") {
|
|
$fee_so = 0;
|
|
}
|
|
|
|
if ($ppn_so=="") {
|
|
$ppn_so = 0;
|
|
}
|
|
|
|
//Check apakah nilai PPN atau Fee 0
|
|
if ($ppn_so<0 OR $fee_so<0) {
|
|
$this->session->set_flashdata('not_zero_negative', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah Limit Pelanggan baru masih ada
|
|
if ($datSo[0]['PELANGGAN_ID']!=$id_pelanggan) {
|
|
$datPda = $this->Penjualan->getData_PiutangDagang_byPELANGGAN($id_pelanggan);
|
|
$datPelangganID = $this->Penjualan->getData_Pelanggan_byID($id_pelanggan);
|
|
$limit_pelanggan = $datPelangganID[0]['LIMIT_PELANGGAN'];
|
|
|
|
$totalSo = $this->Penjualan->getData_DaftarOrder_byPELANGGAN_Null_Not1_Not5($id_pelanggan);
|
|
$totalAktif = 0;
|
|
foreach ($totalSo as $key) {
|
|
$order = $key['HARGA_DO']*$key['QTY_DO']*(($key['PPN_SO']+100)/100);
|
|
$totalAktif = $totalAktif+$order;
|
|
}
|
|
|
|
$debetAktif = 0;
|
|
foreach ($datPda as $key) {
|
|
$debet = $key['DEBET_PDA'];
|
|
$debetAktif = $debetAktif+$debet;
|
|
}
|
|
|
|
$kreditAktif = 0;
|
|
foreach ($datPda as $key) {
|
|
$kredit = $key['KREDIT_PDA'];
|
|
$kreditAktif = $kreditAktif+$kredit;
|
|
}
|
|
|
|
$limit = $limit_pelanggan-$debetAktif-$totalAktif+$kreditAktif;
|
|
if ($limit<0) {
|
|
$this->session->set_flashdata('limit_pelbaru_check', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
$ket_so_g = preg_replace('/\R+/', " " , $ket_so_g);
|
|
$ket_so_k = preg_replace('/\R+/', " " , $ket_so_k);
|
|
$ket_so_t = preg_replace('/\R+/', " " , $ket_so_t);
|
|
$ket_so_p = preg_replace('/\R+/', " " , $ket_so_p);
|
|
$po_so = strtoupper($po_so);
|
|
|
|
//Set Sesuai Bulan
|
|
if ($reminder_so=="") {
|
|
$reminder_so = $this->Penjualan->addTempoYear($datSo[0]['TGL_SO'], 1);
|
|
} else if ($reminder_so==12) {
|
|
$reminder_so = $this->Penjualan->addTempoYear($datSo[0]['TGL_SO'], 1);
|
|
} else if ($reminder_so==24) {
|
|
$reminder_so = $this->Penjualan->addTempoYear($datSo[0]['TGL_SO'], 2);
|
|
} else if ($reminder_so==36) {
|
|
$reminder_so = $this->Penjualan->addTempoYear($datSo[0]['TGL_SO'], 3);
|
|
} else {
|
|
$reminder_so = $this->Penjualan->addTempoMonth($datSo[0]['TGL_SO'], $reminder_so);
|
|
}
|
|
|
|
if ($datNotifikasi==TRUE) {
|
|
$update = [
|
|
'TGL_NOTIFIKASI' => $reminder_so
|
|
];
|
|
$action = $this->Penjualan->update('notifikasi', $update, 'ID_NOTIFIKASI', $datNotifikasi[0]['ID_NOTIFIKASI']);
|
|
}
|
|
|
|
$update = [
|
|
'CORP_ID' => $id_corp,
|
|
'PELANGGAN_ID' => $id_pelanggan,
|
|
'PPN_SO' => $ppn_so,
|
|
'FEE_SO' => $fee_so,
|
|
'GP_SO' => $gp_so,
|
|
'ONGKIR_SO' => $ongkir_so,
|
|
'PO_SO' => $po_so,
|
|
'KET_SO_G' => $ket_so_g,
|
|
'KET_SO_K' => $ket_so_k,
|
|
'KET_SO_T' => $ket_so_t,
|
|
'KET_SO_P' => $ket_so_p,
|
|
'REMINDER_SO' => $reminder_so
|
|
];
|
|
$action = $this->Penjualan->update('sales_order', $update, 'ID_SO', $id_so);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'diubah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'diubah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function hapusso_SA1() { // [94]
|
|
$id_so = $this->input->post('id');
|
|
|
|
//Check Konsistensi Data
|
|
$datSo = $this->Penjualan->getData_SalesOrder_6_7($id_so);
|
|
if ($datSo==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah DO masih ada isinya
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_bySO($id_so);
|
|
if ($datDo==TRUE) {
|
|
$this->session->set_flashdata('data_used_do', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah IO masih ada isinya
|
|
$datIo = $this->Penjualan->getData_TransaksiStock_bySO_AllStatus($id_so);
|
|
if ($datIo==TRUE) {
|
|
$this->session->set_flashdata('data_used_io', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah ada Slip Manual yang menggunakan SO ini
|
|
$datSm = $this->Penjualan->getData_SlipManual_bySO($id_so);
|
|
if ($datSm==TRUE) {
|
|
$this->session->set_flashdata('data_used_sm', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$action = $this->Penjualan->delete('sales_order', $id_so, 'ID_SO');
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function dataRevisi_Sales_SA2($id) { // [95]
|
|
$penjualan = $this->Penjualan->getData_DaftarOrder_bySO($id);
|
|
$jabatan = $this->session->userdata('jabatan');
|
|
$level = $this->session->userdata('level');
|
|
$barang = $this->Penjualan->getBarang_TypeAll_NonJasa($level);
|
|
$jasa = $this->Penjualan->getBarang_TypeAll_NonQty();
|
|
$datSo = $this->Penjualan->getData_SalesOrder_byID($id);
|
|
|
|
//Set Nilai Bruto, PPN, Netto
|
|
$datPda = $this->Penjualan->getData_PiutangDagang_byPELANGGAN($datSo[0]['PELANGGAN_ID']);
|
|
$datPelanggan = $this->Penjualan->getData_Pelanggan_byID($datSo[0]['PELANGGAN_ID']);
|
|
$limit_pelanggan = $datPelanggan[0]['LIMIT_PELANGGAN'];
|
|
|
|
$totalSo = $this->Penjualan->getData_DaftarOrder_byPELANGGAN_Null_Not1_Not5($datSo[0]['PELANGGAN_ID']);
|
|
$totalAktif = 0;
|
|
foreach ($totalSo as $key) {
|
|
$order = $key['HARGA_DO']*$key['QTY_DO']*(($key['PPN_SO']+100)/100);
|
|
$totalAktif = $totalAktif+$order;
|
|
}
|
|
|
|
$debetAktif = 0;
|
|
foreach ($datPda as $key) {
|
|
$debet = $key['DEBET_PDA'];
|
|
$debetAktif = $debetAktif+$debet;
|
|
}
|
|
|
|
$kreditAktif = 0;
|
|
foreach ($datPda as $key) {
|
|
$kredit = $key['KREDIT_PDA'];
|
|
$kreditAktif = $kreditAktif+$kredit;
|
|
}
|
|
|
|
//Set Nilai Limit
|
|
$totalAktif = round($totalAktif);
|
|
$limit = $limit_pelanggan-$debetAktif-$totalAktif+$kreditAktif;
|
|
|
|
//Set Nilai Piutang Dagang
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_bySO($id);
|
|
$nominal_pda = 0;
|
|
foreach ($datDo as $key) {
|
|
$piutang = $key['HARGA_DO']*$key['QTY_DO'];
|
|
$nominal_pda = $nominal_pda+$piutang;
|
|
}
|
|
|
|
//Set Nilai Bruto, PPN, dan Netto
|
|
$bruto = $nominal_pda;
|
|
$ppn_pda = $nominal_pda*($datSo[0]['PPN_SO']/100);
|
|
$nominal_pda = $nominal_pda*(($datSo[0]['PPN_SO']+100)/100);
|
|
$nominal_pda = round($nominal_pda);
|
|
|
|
$no = 0;
|
|
foreach ($penjualan as $key) {
|
|
$datSnJual = $this->Penjualan->getQtyReal_SnJual_byDO($key['ID_DO']);
|
|
$penjualan[$no++] += ['REAL' => $datSnJual];
|
|
}
|
|
|
|
$data = [
|
|
'sidebar' => "menu penjualan",
|
|
'navChild' => "penjualan step1",
|
|
'penjualan' => $penjualan,
|
|
'id_so' => $id,
|
|
'level' => $level,
|
|
'limit' => $limit,
|
|
'barang' => $barang,
|
|
'jasa' => $jasa,
|
|
'nominal_pda' => $nominal_pda,
|
|
'bruto' => $bruto,
|
|
'ppn_pda' => $ppn_pda,
|
|
'jabatan' => $jabatan,
|
|
'kode_so' => $datSo[0]['KODE_SO'],
|
|
'status_so' => $datSo[0]['STATUS_SO'],
|
|
'fee_so' => $datSo[0]['FEE_SO'],
|
|
'nama_pelanggan' => $datPelanggan[0]['NAMA_PELANGGAN'],
|
|
'nama_kota' => $datPelanggan[0]['NAMA_KOTA'],
|
|
];
|
|
$this->load->view('proses/PenjualanRevisi_Sales_SA2', $data);
|
|
}
|
|
|
|
public function simpanso_SA2() { //[96]
|
|
$method = $this->input->post('method');
|
|
$id_so = $this->input->post('id_so');
|
|
$id = $this->input->post('id_do');
|
|
$id_barang = $this->input->post('id_barang');
|
|
$qty_do = $this->input->post('qty_do');
|
|
$harga_do = $this->input->post('harga_do');
|
|
$limit = $this->input->post('limit');
|
|
|
|
//Check Konsistensi Data
|
|
$datSo = $this->Penjualan->getData_SalesOrder_byID($id_so);
|
|
if ($datSo[0]['STATUS_SO']==1 OR $datSo[0]['STATUS_SO']==5 OR $datSo[0]['STATUS_SO']==8 OR $datSo[0]['STATUS_SO']==9) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePenjualan/dataRevisi_Sales_SA1');
|
|
}
|
|
|
|
//Check apakah Kuantiti Kurang dari atau sama dengan 0
|
|
if ($qty_do<=0) {
|
|
$this->session->set_flashdata('not_zero_negative', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Set Koma menjadi titik
|
|
$harga_do = str_replace(',', '.', $harga_do);
|
|
|
|
//Check apakah nilai bersifat Numeric
|
|
$check_nilai = is_numeric($harga_do);
|
|
if ($check_nilai==FALSE) {
|
|
$harga_do = 0;
|
|
}
|
|
|
|
//Check apakah Total SO ditambah barang baru melebihi limit
|
|
$totalSo = ($qty_do*$harga_do)*(($datSo[0]['PPN_SO']+100)/100);
|
|
if ($limit<$totalSo) {
|
|
$this->session->set_flashdata('limit_check', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah ada Kode Barang yang sama
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_bySO_byBARANG($id_so, $id_barang);
|
|
if ($datDo==TRUE) {
|
|
$this->session->set_flashdata('twin_item', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$datBarang = $this->Penjualan->getData_Barang_byID($id_barang);
|
|
$input = [
|
|
'SO_ID' => $id_so,
|
|
'BARANG_ID' => $id_barang,
|
|
'QTY_DO' => $qty_do,
|
|
'HARGA_DO' => $harga_do,
|
|
'NAMA_DO' => $datBarang[0]['NAMA_BARANG']
|
|
];
|
|
$action = $this->Penjualan->create('daftar_order', $input);
|
|
|
|
$update = [
|
|
'STATUS_SO' => '6'
|
|
];
|
|
$action = $this->Penjualan->update('sales_order', $update, 'ID_SO', $id_so);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function hapusso_SA2() { //[97]
|
|
$method = $this->input->post('method');
|
|
$id_do = $this->input->post('id');
|
|
$id_so = $this->input->post('id_so');
|
|
$id_sales = $this->session->userdata('id_karyawan');
|
|
|
|
//Check Konsistensi Data
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_byID($id_do);
|
|
if ($datDo==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check Konsistensi Data
|
|
$datSo = $this->Penjualan->getData_SalesOrder_Not1_Not2_Not5_Not8_Not9($id_sales, $id_so);
|
|
if ($datSo==FALSE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePenjualan/dataRevisi_Sales_SA1');
|
|
}
|
|
|
|
foreach ($datDo as $key) {
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$datSnj = $this->Penjualan->getData_SnJual_byDO($key['ID_DO']);
|
|
foreach ($datSnj as $dat) {
|
|
$datSnStock = $this->Penjualan->getData_SnStock_SnJual_byNAMA_AllStatus($dat['NAMA_SNJ']);
|
|
if ($datSnStock[0]['STATUS_SNSTOCK']=="0") {
|
|
$update = [
|
|
'STATUS_SNSTOCK' => NULL
|
|
];
|
|
$action = $this->Penjualan->update('sn_stock', $update, 'ID_SNSTOCK', $datSnStock[0]['ID_SNSTOCK']);
|
|
}
|
|
}
|
|
}
|
|
$action = $this->Penjualan->delete('sn_jual', $key['ID_DO'], 'DO_ID');
|
|
}
|
|
|
|
$action = $this->Penjualan->delete('daftar_order', $id_do ,'ID_DO');
|
|
|
|
$update = [
|
|
'STATUS_SO' => '6'
|
|
];
|
|
$action = $this->Penjualan->update('sales_order', $update, 'ID_SO', $id_so);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function ubahso_SA2() { //[98]
|
|
$method = $this->input->post('method');
|
|
$id_do = $this->input->post('id_do');
|
|
$id_so = $this->input->post('id_so');
|
|
$limit = $this->input->post('limit');
|
|
$qty_do = $this->input->post('qty_doed');
|
|
$harga_do = $this->input->post('harga_doed');
|
|
$id_sales = $this->session->userdata('id_karyawan');
|
|
$level = $this->session->userdata('level');
|
|
|
|
//Check Konsistensi Data
|
|
$datSo = $this->Penjualan->getData_SalesOrder_Not1_Not2_Not5_Not8_Not9($id_sales, $id_so);
|
|
if ($datSo==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah Kuantiti Kurang dari sama dengan 0
|
|
if ($qty_do<=0) {
|
|
$this->session->set_flashdata('not_zero_negative', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah Jumlah Kuantiti baru lebih besar dari data yang diinput Gudang
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_byID($id_do);
|
|
if ($datDo[0]['TYPE_JENIS']=="1") {
|
|
$qtyReal = $this->Penjualan->getQtyReal_DaftarOrder($id_do);
|
|
if ($qty_do<=$qtyReal) {
|
|
$this->session->set_flashdata('sn_error_real', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
$datKuantiti = $this->Penjualan->getData_Kuantiti_byID($datDo[0]['BARANG_ID']);
|
|
//if ($level == 0) {
|
|
// if (($qty_do-$datDo[0]['QTY_DO'])>$datKuantiti[0]['PCM_KUANTITI']) {
|
|
// $this->session->set_flashdata('over_qty_baru', 'error');
|
|
// redirect($_SERVER['HTTP_REFERER']);
|
|
// }
|
|
//} else if ($level == 1) {
|
|
// if (($qty_do-$datDo[0]['QTY_DO'])>$datKuantiti[0]['ITP_KUANTITI']) {
|
|
// $this->session->set_flashdata('over_qty_baru', 'error');
|
|
// redirect($_SERVER['HTTP_REFERER']);
|
|
// }
|
|
//}
|
|
|
|
//Set Koma menjadi titik
|
|
$harga_do = str_replace(',', '.', $harga_do);
|
|
|
|
//Check apakah nilai bersifat Numeric
|
|
$check_nilai = is_numeric($harga_do);
|
|
if ($check_nilai==FALSE) {
|
|
$harga_do = 0;
|
|
}
|
|
|
|
//Check apakah Nilai yang baru melebihi Limit Pelanggan
|
|
$totalDoBefore = ($datDo[0]['QTY_DO']*$datDo[0]['HARGA_DO']) * (($datDo[0]['PPN_SO']+100)/100);
|
|
$totalDoBefore = round($totalDoBefore);
|
|
$totalDoAfter = ($qty_do*$harga_do) * (($datDo[0]['PPN_SO']+100)/100) ;
|
|
$totalDoAfter = round($totalDoAfter);
|
|
$sisaLimit = $limit - $totalDoBefore + $totalDoAfter;
|
|
if ($sisaLimit<0) {
|
|
$this->session->set_flashdata('limit_check', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$update = [
|
|
'QTY_DO' => $qty_do,
|
|
'HARGA_DO' => $harga_do
|
|
];
|
|
$action = $this->Penjualan->update('daftar_order', $update, 'ID_DO', $id_do);
|
|
|
|
$update = [
|
|
'STATUS_SO' => '6'
|
|
];
|
|
$action = $this->Penjualan->update('sales_order', $update, 'ID_SO', $id_so);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'diubah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'diubah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function kunciso_SA2() { //[99]
|
|
$method = $this->input->post('method');
|
|
$id_so = $this->input->post('id_so');
|
|
$limit = $this->input->post('limit');
|
|
$ket_so_o = $this->input->post('ket_so_o');
|
|
$ket_so_a = $this->input->post('ket_so_a');
|
|
$tgl = date('Y-m-d');
|
|
$tgl_now = date('d/m/Y H:i:s');
|
|
|
|
//Check Konsistensi Data
|
|
$datSo = $this->Penjualan->getData_SalesOrder_6($id_so);
|
|
if ($datSo==FALSE) {
|
|
$this->session->set_flashdata('not_change', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah melebihi Limit Kelompok
|
|
$datPelanggan = $this->Penjualan->getData_Pelanggan_byID($datSo[0]['PELANGGAN_ID']);
|
|
if ($datPelanggan[0]['KELOMPOK_ID']!="0") {
|
|
$datKelompok = $this->Penjualan->getData_Pelanggan_byKELOMPOK($datPelanggan[0]['KELOMPOK_ID']);
|
|
foreach ($datKelompok as $key) {
|
|
$datPda = $this->Penjualan->getData_PiutangDagang_byPELANGGAN($key['ID_PELANGGAN']);
|
|
$datPelanggan = $this->Penjualan->getData_Pelanggan_byID($key['ID_PELANGGAN']);
|
|
$datDo = $this->Penjualan->getData_DaftarOrder_bySO($id_so);
|
|
$limit_pelanggan = $datPelanggan[0]['LIMIT_PELANGGAN'];
|
|
$nama_kelompok = $key['NAMA_KELOMPOK'];
|
|
|
|
$totalSo = $this->Penjualan->getData_DaftarOrder_byPELANGGAN_Null_Not1_Not5($key['ID_PELANGGAN']);
|
|
$totalAktif = 0;
|
|
foreach ($totalSo as $key) {
|
|
$order = ($key['HARGA_DO']*$key['QTY_DO'])*(($key['PPN_SO']+100)/100);
|
|
$totalAktif = $totalAktif+$order;
|
|
}
|
|
|
|
$debetAktif = 0;
|
|
foreach ($datPda as $key) {
|
|
$debet = $key['DEBET_PDA'];
|
|
$debetAktif = $debetAktif+$debet;
|
|
}
|
|
|
|
$kreditAktif = 0;
|
|
foreach ($datPda as $key) {
|
|
$kredit = $key['KREDIT_PDA'];
|
|
$kreditAktif = $kreditAktif+$kredit;
|
|
}
|
|
|
|
$nilai_doAktif = 0;
|
|
foreach ($datDo as $key) {
|
|
$total_do = $key['HARGA_DO']*$key['QTY_DO'];
|
|
$nilai_doAktif = $nilai_doAktif+$total_do;
|
|
}
|
|
|
|
$totalAktif = round($totalAktif);
|
|
$nilai_doAktif = round($nilai_doAktif);
|
|
$limit_akhir = $limit_pelanggan-$debetAktif-$totalAktif-$nilai_doAktif+$kreditAktif;
|
|
if ($limit_akhir<0) {
|
|
$this->session->set_flashdata('limit_group_check', "$nama_kelompok");
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
|
|
//Check apakah melebihi limit Pelanggan
|
|
if ($limit<0) {
|
|
$this->session->set_flashdata('limit_check', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$ket_so_o = preg_replace('/\R+/', " " , $ket_so_o);
|
|
$ket_so_a = preg_replace('/\R+/', " " , $ket_so_a);
|
|
$update = [
|
|
'KET_SO_O' => $ket_so_o,
|
|
'KET_SO_A' => $ket_so_a,
|
|
'TGL_SO' => $tgl,
|
|
'TGL_CREATE' => $tgl_now,
|
|
'STATUS_SO' => '7'
|
|
];
|
|
$action = $this->Penjualan->update('sales_order', $update, 'ID_SO', $id_so);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('data_lock', 'dikunci');
|
|
redirect('ManagePenjualan/dataRevisi_Sales_SA1');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dikunci');
|
|
redirect('ManagePenjualan/dataRevisi_Sales_SA1');
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|