Example #1
0
 public function proses_distribusi($value = '')
 {
     $basmalah = $this->config->item('astro');
     $user = $this->session->userdata('astrosession');
     $userlog = date('Y-m-d H:i:s');
     $param = $this->input->post();
     $reference = $this->input->post('reference');
     $where = array('reference_no' => $reference);
     $keterangan = 'Distribusi Bahan Khusus dengan referensi no ' . $reference;
     $data = $this->mp->find('atombizz_distribution_items', $where);
     $nominal_retur_out = 0;
     foreach ($data->result_array() as $das) {
         $konv_unit = unit_converter($das['quantity'], $das['unit']);
         $data_konv = json_decode($konv_unit);
         $qty = $data_konv->qty;
         $unit = $data_konv->satuan;
         $arr_stok[] = array('date' => date('Y-m-d'), 'status' => 'distribusi', 'reference' => $reference, 'in' => $qty, 'out' => 0, 'description' => $keterangan, 'userlog' => $userlog, 'operator' => $user[0]->uname, 'rak_code' => 'G-001', 'product_code' => $das['product_code'], 'dept' => $basmalah['bas_code_dept']);
     }
     // print_r($arr_stok);exit;
     $save_stok = $this->mp->write_batch('atombizz_warehouses_stok', $arr_stok);
     if ($save_stok == TRUE) {
         $save_beli = $this->mp->replace('atombizz_distribution', array('status' => 'distributed'), array('reference_no' => $reference));
         if ($save_beli == TRUE) {
             // $where = array('reference'=>$reference);
             // $delete = $this->mp->delete('atombizz_distribution_tmp',$where);
             // if($delete>0){
             echo "1|" . succ_msg("Berhasil, menambahkan data retur keluar.");
             // }
         } else {
             echo "0|" . err_msg("Gagal, menambahkan data distribusi.");
         }
     } else {
         echo "0|" . err_msg("Gagal, mengurangi data stok bahan.");
     }
 }
Example #2
0
 public function proses_retur_out()
 {
     $basmalah = $this->config->item('astro');
     $userlog = date('Y-m-d H:i:s');
     $param = $this->input->post();
     $reference = $this->input->post('reference');
     $where = array('reference' => $reference);
     $keterangan = 'Retur Keluar dengan referensi no ' . $reference;
     $data = $this->mp->find('view_tmp_retur_out', $where);
     $nominal_retur_out = 0;
     foreach ($data->result_array() as $das) {
         $arr_detail[] = array('reference' => $reference, 'product_id' => $das['product_id'], 'product_code' => $das['product_code'], 'product_name' => $das['product_name'], 'quantity' => $das['quantity'], 'hpp' => $das['hpp'], 'description' => $das['description'], 'brand_code' => $das['brand_code'], 'unit' => $das['unit']);
         $nominal_retur_out += $das['sub_total'];
         $qty = $das['quantity'];
         $unit = $das['unit'];
         //brand konversi stok
         if ($das['brand_code'] != '') {
             $query = $this->mp->find('atombizz_brand_converter', array('product_code' => $das['product_code'], 'code' => $das['brand_code']));
             $konv_brand = $query->row();
             $qty = $das['quantity'] * $konv_brand->qty_convertion;
             $unit = $konv_brand->satuan_convertion;
         }
         //konversi satuan terkecil
         $konv_unit = unit_converter($qty, $unit);
         $data_konv = json_decode($konv_unit);
         $qty = $data_konv->qty;
         $unit = $data_konv->satuan;
         $arr_stok[] = array('date' => $param['date'], 'status' => 'retur out', 'reference' => $reference, 'in' => 0, 'out' => $qty, 'description' => $keterangan, 'userlog' => $userlog, 'operator' => $param['operator'], 'rak_code' => $das['gudang_code'], 'product_code' => $das['product_code'], 'dept' => $basmalah['bas_code_dept']);
     }
     // print_r($arr_stok);exit;
     $arr_retur_out = array('reference' => $reference, 'supplier_code' => $param['supplier_code'], 'supplier_name' => $param['supplier_name'], 'date' => $param['date'], 'operator' => $param['operator'], 'total' => $param['total_akhir'], 'urut' => $param['urut'], 'dept' => $basmalah['bas_code_dept'], 'userlog' => $userlog);
     $save_items = $this->mp->write_batch('atombizz_retur_out_detail', $arr_detail);
     if ($save_items == TRUE) {
         $save_stok = $this->mp->write_batch('atombizz_warehouses_stok', $arr_stok);
         if ($save_stok == TRUE) {
             $save_beli = $this->mp->write('atombizz_retur_out', $arr_retur_out);
             // echo $this->db->last_query();exit;
             if ($save_beli == TRUE) {
                 $where = array('reference' => $reference);
                 $delete = $this->mp->delete('atombizz_retur_out_tmp', $where);
                 if ($delete > 0) {
                     $kode = 'FRO';
                     $data = array('kode' => $kode, 'no_referensi' => $reference, 'tanggal' => $param['date'], 'keterangan' => $keterangan, 'dept' => $basmalah['bas_code_dept'], 'person' => $param['supplier_code'], 'valid' => 'yes');
                     //retur
                     $data['debit'] = 0;
                     $data['kredit'] = $param['total_akhir'];
                     $data['no_akun'] = '330000';
                     $kas_acc = $this->mp->write('atombizz_accounting_buku_besar', $data);
                     //hutang
                     $data['kredit'] = 0;
                     $data['debit'] = $param['total_akhir'];
                     $data['no_akun'] = '510000';
                     $data['faktur'] = $reference;
                     $data['kode'] = 'HTG';
                     $save_acc = $this->mp->write('atombizz_accounting_buku_besar', $data);
                     if ($save_acc == TRUE) {
                         echo "1|" . succ_msg("Berhasil, menambahkan data retur keluar.");
                     } else {
                         echo "0|" . err_msg("Gagal, menambahkan data accounting persediaan.");
                     }
                 }
             } else {
                 echo "0|" . err_msg("Gagal, menambahkan data retur keluar.");
             }
         } else {
             echo "0|" . err_msg("Gagal, mengurangi data stok bahan.");
         }
     } else {
         echo "0|" . err_msg("Gagal, menambahkan data retur keluar detail.");
     }
 }
Example #3
0
 public function proses_pembelian()
 {
     $param = $this->input->post();
     $this->load->library('form_validation');
     if ($param['cara'] == 'credit') {
         $this->form_validation->set_rules('jatuh_tempo', 'Jatuh Tempo', 'trim|required|xss_clean');
     } else {
         $this->form_validation->set_rules('jatuh_tempo', 'Jatuh Tempo', 'trim|xss_clean');
     }
     if ($this->form_validation->run() == FALSE) {
         //tidak memenuhi validasi
         echo "0|" . warn_msg(validation_errors());
     } else {
         $basmalah = $this->config->item('astro');
         $userlog = date('Y-m-d H:i:s');
         $reference = $param['reference_no'];
         $where = array('reference_no' => $reference);
         $keterangan = 'Pembelian dengan referensi no ' . $reference;
         $data = $this->mp->find('atombizz_tmp_detail_purchases', $where);
         foreach ($data->result_array() as $das) {
             $total = $das['sub_total'] - $das['sub_total'] * $param['disc_reg_1'] / 100;
             $arr_detail[] = array('reference_no' => $reference, 'product_id' => $das['product_id'], 'product_code' => $das['product_code'], 'product_name' => $das['product_name'], 'quantity' => $das['quantity'], 'unit_price' => $das['unit_price'], 'gross_total' => $total, 'disc_reg' => $param['disc_reg_1'], 'unit' => $das['unit'], 'brand_code' => $das['brand_code']);
             $qty = $das['quantity'];
             $unit = $das['unit'];
             //brand konversi stok
             if ($das['brand_code'] != '') {
                 $query = $this->mp->find('atombizz_brand_converter', array('product_code' => $das['product_code'], 'code' => $das['brand_code']));
                 $konv_brand = $query->row();
                 $qty = $das['quantity'] * $konv_brand->qty_convertion;
                 $unit = $konv_brand->satuan_convertion;
             }
             //konversi satuan terkecil
             $konv_unit = unit_converter($qty, $unit);
             $data_konv = json_decode($konv_unit);
             $qty = $data_konv->qty;
             $unit = $data_konv->satuan;
             $hpp = $das['sub_total'] / $qty;
             $arr_stok[] = array('date' => $param['date'], 'status' => 'pembelian', 'reference' => $reference, 'in' => $qty, 'out' => 0, 'description' => $keterangan, 'userlog' => $userlog, 'operator' => $param['operator'], 'rak_code' => $das['warehouse_id'], 'product_code' => $das['product_code'], 'dept' => $basmalah['bas_code_dept']);
             $arr_hpp[] = array('code' => $das['product_code'], 'cost' => $hpp);
         }
         // print_r($arr_hpp);exit;
         if ($param['cara'] == 'cash') {
             $arr_kas = array('kode' => 'PB', 'no_referensi' => $reference, 'tanggal' => $param['date'], 'keterangan' => $keterangan, 'person' => $param['supplier_code'], 'dept' => $basmalah['bas_code_dept'], 'valid' => 'yes');
             //kas
             $arr_kas['debit'] = 0;
             $arr_kas['kredit'] = $param['total'];
             $arr_kas['no_akun'] = '110000';
             $kas_acc = $this->mp->write('atombizz_accounting_buku_besar', $arr_kas);
             //potongan
             $arr_kas['debit'] = 0;
             $arr_kas['kredit'] = $param['nom_reg_1'];
             $arr_kas['no_akun'] = '340000';
             $potongan_acc = $this->mp->write('atombizz_accounting_buku_besar', $arr_kas);
             //pembelian
             $arr_kas['debit'] = $param['subtotal'];
             $arr_kas['kredit'] = 0;
             $arr_kas['no_akun'] = '130000';
             $save_acc = $this->mp->write('atombizz_accounting_buku_besar', $arr_kas);
         } else {
             if ($param['cara'] == 'credit') {
                 $htg = array('code' => $reference, 'jatuh_tempo' => $param['jatuh_tempo'], 'status' => 0);
                 $save_htg = $this->mp->write('atombizz_hutang', $htg);
                 if ($save_htg == TRUE) {
                     $arr_htg = array('kode' => 'PB', 'no_referensi' => $reference, 'tanggal' => $param['date'], 'keterangan' => $keterangan, 'person' => $param['supplier_code'], 'dept' => $basmalah['bas_code_dept'], 'valid' => 'yes');
                     //kas
                     $arr_htg['debit'] = 0;
                     $arr_htg['kredit'] = $param['dp'];
                     $arr_htg['no_akun'] = '110000';
                     $kas_acc = $this->mp->write('atombizz_accounting_buku_besar', $arr_htg);
                     //potongan
                     $arr_htg['debit'] = 0;
                     $arr_htg['kredit'] = $param['nom_reg_1'];
                     $arr_htg['no_akun'] = '340000';
                     $potongan_acc = $this->mp->write('atombizz_accounting_buku_besar', $arr_htg);
                     //pembelian
                     $arr_htg['debit'] = $param['subtotal'];
                     $arr_htg['kredit'] = 0;
                     $arr_htg['no_akun'] = '130000';
                     $pembelian_acc = $this->mp->write('atombizz_accounting_buku_besar', $arr_htg);
                     //hutang
                     $arr_htg['debit'] = 0;
                     $arr_htg['kredit'] = $param['total'] - $param['dp'];
                     $arr_htg['no_akun'] = '510000';
                     $arr_htg['faktur'] = $reference;
                     $arr_htg['kode'] = 'HTG';
                     $save_acc = $this->mp->write('atombizz_accounting_buku_besar', $arr_htg);
                 } else {
                     echo "0|" . err_msg("Error, hubungi teknisi.");
                 }
             }
         }
         if ($save_acc) {
             $save_items = $this->mp->write_batch('atombizz_purchase_items', $arr_detail);
             if ($save_items == TRUE) {
                 $save_stok = $this->mp->write_batch('atombizz_warehouses_stok', $arr_stok);
                 if ($save_stok == TRUE) {
                     $save_hpp = $this->mp->replace_batch('atombizz_product', $arr_hpp, 'code');
                     // echo $this->db->last_query();exit;
                     if ($save_hpp == TRUE) {
                         unset($param['jatuh_tempo']);
                         unset($param['cara']);
                         unset($param['dp']);
                         $param['dept'] = $basmalah['bas_code_dept'];
                         $save_beli = $this->mp->write('atombizz_purchases', $param);
                         if ($save_beli == TRUE) {
                             $where = array('reference_no' => $reference);
                             $delete = $this->mp->delete('atombizz_tmp_detail_purchases', $where);
                             if ($delete > 0) {
                                 $where = array('code' => $param['supplier_code']);
                                 $sql_ins['last_active'] = $param['date'];
                                 $sql_ins['last_num'] = $this->mp->get_last_num($param['supplier_code']);
                                 $insert = $this->mp->replace('atombizz_suppliers', $sql_ins, $where);
                                 if ($insert == TRUE) {
                                     echo "1|" . succ_msg("Berhasil, menambahkan data pembelian.");
                                 } else {
                                     echo "0|" . err_msg("Error, hubungi teknisi.");
                                 }
                             } else {
                                 echo "0|" . err_msg("Error, hubungi teknisi.");
                             }
                         } else {
                             echo "0|" . err_msg("Error, hubungi teknisi.");
                         }
                     } else {
                         echo "0|" . err_msg("Error, hubungi teknisi. -hpp");
                     }
                 } else {
                     echo "0|" . err_msg("Error, hubungi teknisi.");
                 }
             } else {
                 echo "0|" . err_msg("Error, hubungi teknisi.");
             }
         } else {
             echo "0|" . err_msg("Error, hubungi teknisi.");
         }
     }
 }