if(empty($id_member)){
			$id_member= '1';

			if($potongan > 0){
				$this->session->set_flashdata('pss','<div class="alert alert-info alert-dismissible">
								  <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
								  <strong> Gagal, Tidak Boleh ada Potongan!</strong>
								</div> ');
				 redirect('cetak/form_kosong/');
			}else{

				if($kembali < 0){
					$this->session->set_flashdata('pss','<div class="alert alert-info alert-dismissible">
								  <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
								  <strong> Gagal, Nominal Bayar Salah !</strong>
								</div> ');
					 	redirect('cetak/form_kosong/');
					}else{

						$sql = "SELECT * FROM tb_jual_kasir  where id_admin='$id_admin' and id_kantor='$id_kantor' ";
						$cari = $this->db->query($sql)->result();
						foreach ($cari as $data) {
				        	//input data barmasuk
							$data1=array(

								'id'=>null,

								'id_barang'			=>  $data->id_barang, 
								'id_kantor'			=>  $data->id_kantor,
								'harga_beli'		=>  $data->harga_beli,
								'harga_jual'		=>  $data->harga_jual,
								'jumlah'			=>  $data->jumlah,
								'harga_total'		=>  $data->harga_total,

								'date'				=>  $data->date,
								

								'id_transaksi'=>  $newkode
							);

							$this->db->insert('tb_jual_detail',$data1);


				        //input data history
							$data2=array(

								'id_barang'			=>  $data->id_barang, 
								'id_kantor'			=>  $data->id_kantor,
								'jumlah'			=>  $data->jumlah,
								'id_admin'			=>  $data->id_admin,
								'date'				=>  $data->date,
								'keterangan'=>  'terjual',
								
								'id_transaksi'=>  $newkode, 

							);

							$this->db->insert('tb_history_barang_in_out',$data2);


							$id_barang = $data->id_barang;
							$jum_keluar = $data->jumlah;

							$this->db->where('id_barang',$id_barang);
							$this->db->where('id_kantor',$id_kantor);
							$query1	 = $this->db->get('tb_stok');
							$row1 	 = $query1->row();
							$cek_stok	 = $row1->stok_aplikasi;
							$new_stok =   $cek_stok - $jum_keluar ;
							

			 			//update stok gudang
							$datax=array(

								'stok_aplikasi'=> $new_stok

							);
							$this->db->where('id_barang',$id_barang);
							$this->db->where('id_kantor',$id_kantor);
							$this->db->update('tb_stok',$datax);

						}
					// simpan pembayaran
						$data4=array(
							
							'id_transaksi'=>  $newkode, 
							'id_member'=>  $id_member, 
							'id_kantor'=>  $this->input->post('id_kantor'), 
							'sub_total'=>  $this->input->post('sub_total'), 
							'potongan'=>  $this->input->post('potongan'),
							
							'point'=>  $this->input->post('point'), 
							
							'total'=>  $this->input->post('total'), 
							'bayar'=>  $this->input->post('bayar'), 
							'kembali'=>  $this->input->post('kembali'), 
							'id_admin'=>  $this->input->post('id_admin'), 
							
							
							'metode_bayar'=>  $this->input->post('metode_bayar') ,
							'ket_metode'=>  $this->input->post('ket_metode') 
							
						);
						$this->db->insert('tb_transaksi',$data4); 

					//update point member
						$new_point = $cek_point - $potongan;
						$dataxx=array(

							'point'=> $new_point

						);
						$this->db->where('id_member',$id_member);
						$this->db->update('tb_member',$dataxx);
						

					//hapus barjual kasir
						$hapus = "DELETE FROM tb_jual_kasir where id_admin='$id_admin' and id_kantor='$id_kantor'    ";
						$data = $this->db->query($hapus);
						


						redirect('cetak/form_cetak/'.$newkode);	

					}
			}


		}else{
			//cek Point
			$id_member= $this->input->post('id_member');
			$this->db->where('id_member',$id_member);
			$query = $this->db->get('tb_member');
			$row = $query->row();
			$cek_point= $row->point;

			if($potongan > $point){
				$this->session->set_flashdata('pss','<div class="alert alert-info alert-dismissible">
								  <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
								  <strong> Gagal, Potongan Melebihi Point Member!</strong>
								</div> ');
				 redirect('cetak/form_kosong/');
			}else{
				if($kembali < 0){
					$this->session->set_flashdata('pss','<div class="alert alert-info alert-dismissible">
								  <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
								  <strong> Gagal, Nominal Bayar Salah !</strong>
								</div> ');
				 	redirect('cetak/form_kosong/');
				}else{

					$sql = "SELECT * FROM tb_jual_kasir  where id_admin='$id_admin' and id_kantor='$id_kantor' ";
					$cari = $this->db->query($sql)->result();
					foreach ($cari as $data) {
				        	//input data barmasuk
						$data1=array(

							'id'=>null,

							'id_barang'			=>  $data->id_barang, 
							'id_kantor'			=>  $data->id_kantor,
							'harga_beli'		=>  $data->harga_beli,
							'harga_jual'		=>  $data->harga_jual,
							'jumlah'			=>  $data->jumlah,
							'harga_total'		=>  $data->harga_total,

							'date'				=>  $data->date,
							 

							'id_transaksi'=>  $newkode
						);

						$this->db->insert('tb_jual_detail',$data1);


				        //input data history
						$data2=array(

							'id_barang'			=>  $data->id_barang, 
							'id_kantor'			=>  $data->id_kantor,
							'jumlah'			=>  $data->jumlah,
							'id_admin'			=>  $data->id_admin,
							'date'				=>  $data->date,
							'keterangan'=>  'terjual',
							 
							'id_transaksi'=>  $newkode, 

						);

						$this->db->insert('tb_history_barang_in_out',$data2);


						$id_barang = $data->id_barang;
						$jum_keluar = $data->jumlah;

						$this->db->where('id_barang',$id_barang);
						$this->db->where('id_kantor',$id_kantor);
						$query1	 = $this->db->get('tb_stok');
						$row1 	 = $query1->row();
						$cek_stok	 = $row1->stok_aplikasi;
			 			$new_stok =   $cek_stok - $jum_keluar ;
					 

			 			//update stok gudang
						$datax=array(

							'stok_aplikasi'=> $new_stok

						);
						$this->db->where('id_barang',$id_barang);
						$this->db->where('id_kantor',$id_kantor);
						$this->db->update('tb_stok',$datax);

					}
					// simpan pembayaran
					$data4=array(
							 
							'id_transaksi'=>  $newkode, 
							'id_member'=>  $id_member, 
							'id_kantor'=>  $this->input->post('id_kantor'), 
							'sub_total'=>  $this->input->post('sub_total'), 
							'potongan'=>  $this->input->post('potongan'),
							
							'point'=>  $this->input->post('point'), 
						
							'total'=>  $this->input->post('total'), 
							'bayar'=>  $this->input->post('bayar'), 
							'kembali'=>  $this->input->post('kembali'), 
							'id_admin'=>  $this->input->post('id_admin'), 
							 
							 
							'metode_bayar'=>  $this->input->post('metode_bayar') ,
							'ket_metode'=>  $this->input->post('ket_metode') 
							 
							);
						$this->db->insert('tb_transaksi',$data4); 

					//update point member
						$new_point = $cek_point - $potongan;
							$dataxx=array(

								'point'=> $new_point

							);
						$this->db->where('id_member',$id_member);
						$this->db->update('tb_member',$dataxx);
						

					//hapus barjual kasir
		        	$hapus = "DELETE FROM tb_jual_kasir where id_admin='$id_admin' and id_kantor='$id_kantor'    ";
		       		$data = $this->db->query($hapus);
					


					redirect('cetak/form_cetak/'.$newkode);
    	 
				}

			 
		}
	 