449 lines
13 KiB
PHP
449 lines
13 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 ManagePenjualanSO extends CI_Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('ModelPenjualan', 'Penjualan');
|
|
$this->load->model('ModelBarang', 'Barang');
|
|
$this->load->model('ModelCorp', 'Corp');
|
|
$this->load->model('ModelKaryawan', 'Karyawan');
|
|
$this->load->model('ModelNeraca', 'Neraca');
|
|
$this->load->model('ModelPelanggan', 'Pelanggan');
|
|
$this->load->library(['datatables', 'form_validation']);
|
|
$this->form_validation->set_error_delimiters('', '');
|
|
}
|
|
public function output_json($data, $encode = true)
|
|
{
|
|
if ($encode) $data = json_encode($data);
|
|
$this->output->set_content_type('application/json')->set_output($data);
|
|
}
|
|
|
|
public function index() {
|
|
$datPenjualan = $this->Penjualan->getDataPenjualan();
|
|
$datCorp = $this->Corp->getData_Corp();
|
|
$datSales = $this->Karyawan->getDataSales();
|
|
$datPelanggan = $this->Pelanggan->getData_Pelanggan();
|
|
$tgl = date('m/d/Y');
|
|
|
|
$data = [
|
|
'sidebar' => "menu penjualan",
|
|
'navChild' => "",
|
|
'penjualan' => $datPenjualan,
|
|
'corp' => $datCorp,
|
|
'sales' => $datSales,
|
|
'pelanggan' => $datPelanggan,
|
|
'tgl' => $tgl
|
|
];
|
|
|
|
$this->load->view('proses/PenjualanSO', $data);
|
|
}
|
|
|
|
public function kodePenjualan() {
|
|
$kk = $this->Penjualan->getKodePenjualan();
|
|
if (is_array($kk) || is_object($kk)) {
|
|
foreach ($kk as $row) {
|
|
if ($row['KODE'] == null) {
|
|
return "PJ/000001";
|
|
} else {
|
|
$str = (string) $row['KODE'];
|
|
$panjang = 6;
|
|
$data = substr($str, 3, $panjang);
|
|
|
|
$ko = (int) $data + 1;
|
|
$str = (string) $ko;
|
|
|
|
$panjang = 9 - strlen($str);
|
|
$data = "PJ/000000";
|
|
$data = substr($data, 0, $panjang) . $str;
|
|
return $data;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function save() {
|
|
$method = $this->input->post('method');
|
|
$id_penjualan = $this->input->post('id');
|
|
$id_sales = $this->input->post('id_sales');
|
|
$id_corp = $this->input->post('id_corp');
|
|
$id_pelanggan = $this->input->post('id_pelanggan');
|
|
$po_penjualan = $this->input->post('po_penjualan');
|
|
$tgl_penjualan = $this->input->post('tgl_penjualan');
|
|
$tempo_penjualan = $this->input->post('tempo_penjualan');
|
|
$radio_ppn = $this->input->post('radio_ppn');
|
|
$radio_gp = $this->input->post('radio_gp');
|
|
$kode_penjualan = $this->kodePenjualan();
|
|
|
|
$po_penjualan = strtoupper($po_penjualan);
|
|
$tgl = date('Y-m-d H:i:s');
|
|
|
|
if ($tempo_penjualan=="") {
|
|
$tempo_penjualan = '0';
|
|
$tempo_penjualan = $this->Penjualan->addTempo($tgl,$tempo_penjualan);
|
|
} else {
|
|
$tempo_penjualan = $this->Penjualan->addTempo($tgl,$tempo_penjualan);
|
|
}
|
|
|
|
$input = [
|
|
'SALES_ID' => $id_sales,
|
|
'CORP_ID' => $id_corp,
|
|
'PELANGGAN_ID' => $id_pelanggan,
|
|
'PO_PENJUALAN' => $po_penjualan,
|
|
'KODE_PENJUALAN' => $kode_penjualan,
|
|
'TGL_PENJUALAN' => $tgl_penjualan,
|
|
'TEMPO_PENJUALAN' => $tempo_penjualan,
|
|
'PPN_PENJUALAN' => $radio_ppn,
|
|
'GP_PENJUALAN' => $radio_gp
|
|
];
|
|
|
|
$action = $this->Penjualan->create('penjualan', $input);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('flash', 'ditambah');
|
|
redirect('ManagePenjualanSO');
|
|
} else {
|
|
$this->session->set_flashdata('flashgagal', 'ditambah');
|
|
redirect('ManagePenjualanSO');
|
|
}
|
|
|
|
}
|
|
|
|
public function edit() {
|
|
$method = $this->input->post('method');
|
|
$id_penjualan = $this->input->post('id_penjualan');
|
|
$id_sales = $this->input->post('id_salesed');
|
|
$id_corp = $this->input->post('id_corped');
|
|
$id_pelanggan = $this->input->post('id_pelangganed');
|
|
$po_penjualan = $this->input->post('po_penjualaned');
|
|
$tgl_penjualan = $this->input->post('tgl_penjualaned');
|
|
$tempo_penjualan = $this->input->post('tempo_penjualaned');
|
|
$radio_ppn = $this->input->post('radio_ppn');
|
|
$radio_gp = $this->input->post('radio_gp');
|
|
|
|
$po_penjualan = strtoupper($po_penjualan);
|
|
|
|
$update = [
|
|
'SALES_ID' => $id_sales,
|
|
'CORP_ID' => $id_corp,
|
|
'PELANGGAN_ID' => $id_pelanggan,
|
|
'PO_PENJUALAN' => $po_penjualan,
|
|
'TGL_PENJUALAN' => $tgl_penjualan,
|
|
'TEMPO_PENJUALAN' => $tempo_penjualan,
|
|
'PPN_PENJUALAN' => $radio_ppn,
|
|
'GP_PENJUALAN' => $radio_gp
|
|
];
|
|
|
|
$action = $this->Penjualan->update('penjualan', $update,'ID_PENJUALAN',$id_penjualan);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('flash', 'diubah');
|
|
redirect('ManagePenjualanSO');
|
|
} else {
|
|
$this->session->set_flashdata('flashgagal', 'diubah');
|
|
redirect('ManagePenjualanSO');
|
|
}
|
|
|
|
}
|
|
|
|
public function hapus() {
|
|
$id = $this->input->post('id');
|
|
$action = $this->Penjualan->delete('penjualan',$id,'ID_PENJUALAN');
|
|
$this->session->set_flashdata('flash', 'dihapus');
|
|
redirect('ManagePenjualanSO');
|
|
}
|
|
|
|
public function tambahPesanan($id) {
|
|
$pesanan = $this->Penjualan->getPenjualanPesanan($id);
|
|
$title = $this->Penjualan->getTitlePesanan($id);
|
|
$barang = $this->Barang->getBarangPenjualan();
|
|
$cabutan = $this->Barang->getBarangCabutan();
|
|
|
|
$id_pelanggan = $title[0]['PELANGGAN_ID'];
|
|
$limit = $this->Penjualan->getSisaLimit($id_pelanggan);
|
|
|
|
$limitAktif = '0';
|
|
foreach ($limit as $key) {
|
|
$piutang = $key['NOMINAL_PDA'];
|
|
$limitAktif = $limitAktif+$piutang;
|
|
}
|
|
|
|
$cicilanAktif = '0';
|
|
foreach ($limit as $key) {
|
|
$cicilan = $this->Penjualan->getCicilanPiutang($key['ID_PDA']);
|
|
$nominal_dpda = '0';
|
|
foreach ($cicilan as $key) {
|
|
$nominal_dpda = $nominal_dpda+$key['NOMINAL_DPDA'];
|
|
}
|
|
$cicilanAktif = $cicilanAktif+$nominal_dpda;
|
|
}
|
|
|
|
$pelanggan = $this->Penjualan->getDataPelanggan($id_pelanggan);
|
|
$limit_pelanggan = $pelanggan[0]['LIMIT_PELANGGAN'];
|
|
$limit = $limit_pelanggan-$limitAktif+$cicilanAktif;
|
|
|
|
$nominal_pda='0';
|
|
foreach ($pesanan as $key) {
|
|
$piutang = $key['HARGA_DJ']*$key['QTY_DJ'];
|
|
$nominal_pda = $nominal_pda+$piutang;
|
|
}
|
|
|
|
$data = [
|
|
'sidebar' => "menu penjualan",
|
|
'navChild' => "",
|
|
'pesanan' => $pesanan,
|
|
'id_penjualan' => $id,
|
|
'limit' => $limit,
|
|
'nominal_pda' => $nominal_pda,
|
|
'title' => $title[0]['KODE_PENJUALAN'],
|
|
'barang' => $barang,
|
|
'cabutan' => $cabutan,
|
|
];
|
|
|
|
$this->load->view('proses/PenjualanPesanan', $data);
|
|
}
|
|
|
|
public function savepesanan() {
|
|
$method = $this->input->post('method');
|
|
$id_penjualan = $this->input->post('id_penjualan');
|
|
$id = $this->input->post('id_dj');
|
|
$id_barang = $this->input->post('id_barang');
|
|
$qty_dj = $this->input->post('qty_dj');
|
|
$jenis_dj = $this->input->post('jenis_dj');
|
|
$ket_dj = $this->input->post('ket_dj');
|
|
|
|
$kuantiti = $this->Penjualan->getKuantitiBarang($id_barang);
|
|
$id_kuantiti = $kuantiti[0]['ID_KUANTITI'];
|
|
$pcm_kuantiti = $kuantiti[0]['PCM_KUANTITI'];
|
|
$proses_kuantiti = $kuantiti[0]['PROSES_KUANTITI'];
|
|
|
|
if ($qty_dj>$pcm_kuantiti) {
|
|
$this->session->set_flashdata('flashkuantiti', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
if ($qty_dj==0 OR $qty_dj=="") {
|
|
$this->session->set_flashdata('flashzero', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$temp = $proses_kuantiti+$qty_dj;
|
|
$pcm = $pcm_kuantiti-$qty_dj;
|
|
|
|
$input = [
|
|
'PENJUALAN_ID' => $id_penjualan,
|
|
'BARANG_ID' => $id_barang,
|
|
'QTY_DJ' => $qty_dj,
|
|
'JENIS_DJ' => $jenis_dj,
|
|
'KET_DJ' => $ket_dj
|
|
];
|
|
|
|
$action = $this->Penjualan->create('daftar_jual', $input);
|
|
|
|
$update = [
|
|
'PROSES_KUANTITI' => $temp,
|
|
'PCM_KUANTITI' => $pcm
|
|
];
|
|
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $id_kuantiti);
|
|
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('flash', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('flashgagal', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function hargapesanan() {
|
|
$method = $this->input->post('method');
|
|
$id_dj = $this->input->post('id_dj');
|
|
$id_penjualan = $this->input->post('id_penjualan');
|
|
$harga_dj = $this->input->post('harga_dj');
|
|
$limit = $this->input->post('limit');
|
|
$nominal_pda = $this->input->post('nominal_pda');
|
|
|
|
$dj = $this->Penjualan->getDataDaftarJual($id_dj);
|
|
$qty_dj = $dj[0]['QTY_DJ'];
|
|
$total = $qty_dj*$harga_dj;
|
|
$totalAkhir = $total+$nominal_pda;
|
|
|
|
if ($limit<$totalAkhir) {
|
|
$this->session->set_flashdata('flashlimit', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$update = [
|
|
'HARGA_DJ' => $harga_dj
|
|
];
|
|
|
|
$action = $this->Penjualan->update('daftar_jual', $update, 'ID_DJ', $id_dj);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('flashharga', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('flashhargagagal', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function resetharga() {
|
|
$method = $this->input->post('method');
|
|
$id_dj = $this->input->post('id');
|
|
|
|
$update = [
|
|
'HARGA_DJ' => NULL
|
|
];
|
|
|
|
$action = $this->Penjualan->update('daftar_jual', $update, 'ID_DJ', $id_dj);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('flashharga', 'direset');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('flashhargagagal', 'direset');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function hapuspesanan() {
|
|
$method = $this->input->post('method');
|
|
$id_dj = $this->input->post('id');
|
|
|
|
$daftar_jual = $this->Penjualan->getDataDaftarJual($id_dj);
|
|
$id_barang = $daftar_jual[0]['BARANG_ID'];
|
|
$qty_dj = $daftar_jual[0]['QTY_DJ'];
|
|
|
|
$kuantiti = $this->Penjualan->getKuantitiBarang($id_barang);
|
|
$id_kuantiti = $kuantiti[0]['ID_KUANTITI'];
|
|
$pcm_kuantiti = $kuantiti[0]['PCM_KUANTITI'];
|
|
$proses_kuantiti = $kuantiti[0]['PROSES_KUANTITI'];
|
|
|
|
$temp = $proses_kuantiti-$qty_dj;
|
|
$pcm = $pcm_kuantiti+$qty_dj;
|
|
|
|
$update = [
|
|
'PROSES_KUANTITI' => $temp,
|
|
'PCM_KUANTITI' => $pcm
|
|
];
|
|
|
|
$action = $this->Penjualan->update('kuantiti', $update, 'ID_KUANTITI', $id_kuantiti);
|
|
|
|
$action = $this->Penjualan->delete('daftar_jual', $id_dj ,'ID_DJ');
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('flash', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('flashgagal', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function kodePiutangDagang() {
|
|
$kk = $this->Penjualan->getKodePDA();
|
|
if (is_array($kk) || is_object($kk)) {
|
|
foreach ($kk as $row) {
|
|
if ($row['KODE'] == null) {
|
|
return "PDA/000001";
|
|
} else {
|
|
$str = (string) $row['KODE'];
|
|
$panjang = 6;
|
|
$data = substr($str, 4, $panjang);
|
|
|
|
$ko = (int) $data + 1;
|
|
$str = (string) $ko;
|
|
|
|
$panjang = 10 - strlen($str);
|
|
$data = "PDA/000000";
|
|
$data = substr($data, 0, $panjang) . $str;
|
|
return $data;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function konfirmasi() {
|
|
$method = $this->input->post('method');
|
|
$id_penjualan = $this->input->post('id_penjualan');
|
|
$tgl = date('m/d/Y');
|
|
|
|
$harga = $this->Penjualan->getPenjualanPesanan($id_penjualan);
|
|
$tempo_penjualan = $harga[0]['TEMPO_PENJUALAN'];
|
|
|
|
foreach ($harga as $key) {
|
|
if ($key['HARGA_DJ']==NULL) {
|
|
$this->session->set_flashdata('flashharga', 'diproses');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
$nominal_pda='0';
|
|
foreach ($harga as $key) {
|
|
$piutang = $key['HARGA_DJ']*$key['QTY_DJ'];
|
|
$nominal_pda = $nominal_pda+$piutang;
|
|
}
|
|
|
|
$kode_pda = $this->kodePiutangDagang();
|
|
|
|
$input = [
|
|
'KODE_PDA' => $kode_pda,
|
|
'PENJUALAN_ID' => $id_penjualan,
|
|
'NOMINAL_PDA' => $nominal_pda,
|
|
'TGL_PDA' => $tgl,
|
|
'TEMPO_PDA' => $tempo_penjualan
|
|
];
|
|
$action = $this->Penjualan->create('piutang_dagang', $input);
|
|
|
|
$id_setdata = $this->Neraca->getSetdata_ID();
|
|
$id_setdata = $id_setdata[0]['SETDATA_ID'];
|
|
|
|
$neraca = $this->Neraca->getDataNilaiNeraca($id_setdata,3);
|
|
$id_neraca = $neraca[0]['ID_NERACA'];
|
|
$nilai_neraca = $neraca[0]['NILAI_NERACA'];
|
|
$nilai = $nilai_neraca+$nominal_pda;
|
|
$update = [
|
|
'NILAI_NERACA' => $nilai
|
|
];
|
|
$action = $this->Neraca->update('neraca', $update, 'ID_NERACA', $id_neraca);
|
|
|
|
$neraca = $this->Neraca->getDataNilaiNeraca($id_setdata,23);
|
|
$id_neraca = $neraca[0]['ID_NERACA'];
|
|
$nilai_neraca = $neraca[0]['NILAI_NERACA'];
|
|
$nilai = $nilai_neraca+$nominal_pda;
|
|
$update = [
|
|
'NILAI_NERACA' => $nilai
|
|
];
|
|
$action = $this->Neraca->update('neraca', $update, 'ID_NERACA', $id_neraca);
|
|
|
|
$update = [
|
|
'STATUS_PENJUALAN' => '0'
|
|
];
|
|
$action = $this->Penjualan->update('penjualan', $update, 'ID_PENJUALAN', $id_penjualan);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('flash', 'diproses');
|
|
redirect('ManagePenjualanSO');
|
|
} else {
|
|
$this->session->set_flashdata('flashgagal', 'diproses');
|
|
redirect('ManagePenjualanSO');
|
|
}
|
|
|
|
}
|
|
|
|
}
|