You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
3.8 KiB
PHP
125 lines
3.8 KiB
PHP
<?php
|
|
session_start();
|
|
if($_SESSION['validUser'] !== TRUE)
|
|
{
|
|
header("location: ./index.php");
|
|
exit();
|
|
}
|
|
|
|
|
|
if(isset($_POST['nonota']) && isset($_POST['tglretur']) && isset($_POST['totaloper']) && isset($_POST['nik'])
|
|
&& isset($_POST['kode']) && isset($_POST['jumlah']) && isset($_POST['hargabelisatuan']))
|
|
{
|
|
require_once("../db_login.inc.php");
|
|
$no_nota = $_POST['nonota'];
|
|
$tgl_retur = substr($_POST['tglretur'],6,4)."-".substr($_POST['tglretur'],3,2)."-".substr($_POST['tglretur'],0,2);
|
|
$total_retur = $_POST['totaloper'];
|
|
$jumlah_retur = $_POST['jumlahoper'];
|
|
$kdsupp = $_POST['supp'];
|
|
$nik = $_POST['nik'];
|
|
$ket_retur = "-";
|
|
if($_POST['ketretur'] != "")
|
|
$ket_retur = $_POST['ketretur'];
|
|
$kode = $_POST['kode'];
|
|
$jumlah = $_POST['jumlah'];
|
|
$hb_satuan = $_POST['hargabelisatuan'];
|
|
$no_barang = $_POST['nomorbarang'];
|
|
$retur_id = $_POST['idretur'];
|
|
$hasilm = 0;
|
|
$hasild = 0;
|
|
|
|
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
|
|
if(!mysqli_connect_errno())
|
|
{
|
|
// begin update data table master <--
|
|
$stmt = $mysqli->prepare("UPDATE m_retur_beli SET no_nota = ?, total_retur = ?, jml_item = ?, kd_supplier = ?, tgl_retur = ?, keterangan = ? WHERE id_retur = ?");
|
|
$stmt->bind_param("siisssi", $no_nota, $total_retur, $jumlah_retur, $kdsupp, $tgl_retur, $ket_retur, $retur_id);
|
|
$stmt->execute();
|
|
if($stmt->affected_rows > 0)
|
|
$hasilm = 1;
|
|
else $hasilm = 0;
|
|
$stmt->close();
|
|
// --> end update data table master
|
|
|
|
// begin update data table detail <--
|
|
$aDataBaru = array();
|
|
// masukkan semua data baru dalam satu array
|
|
for($id=0; $id<count($kode); $id++)
|
|
$aDataBaru[$id] = array('kode' => $kode[$id], 'nomor' => $no_barang[$id], 'hb' => $hb_satuan[$id], 'jumlah' => $jumlah[$id]);
|
|
|
|
// urutkan datanya
|
|
sort($aDataBaru);
|
|
|
|
// proses penggabungan data yang sama
|
|
$aBaru = array();
|
|
$co = 0;
|
|
$c=0;
|
|
for ($i=0;$i<count($aDataBaru);$i++)
|
|
{
|
|
$aBaru[] = $aDataBaru[$i];
|
|
for($s=1+$i;$s<=count($aDataBaru);$s++)
|
|
{
|
|
if($aBaru[$co]['kode'] == $aDataBaru[$s]['kode'] && $aBaru[$co]['nomor'] == $aDataBaru[$s]['nomor'])
|
|
{
|
|
$c++;
|
|
$aBaru[$co]['jumlah'] += $aDataBaru[$s]['jumlah'];
|
|
}else
|
|
{
|
|
$co++;
|
|
$i+=$c;
|
|
$c=0;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// bandingkan data yang baru dengan data yang ada di db
|
|
for($x=0; $x<count($aBaru); $x++)
|
|
{
|
|
$k = $aBaru[$x]['kode'];
|
|
$h = $aBaru[$x]['hb'];
|
|
$n = $aBaru[$x]['nomor'];
|
|
|
|
$dt = $mysqli->query("SELECT jumlah
|
|
FROM d_retur_beli
|
|
WHERE id_retur = $retur_id
|
|
AND kd_barang = '$k'
|
|
AND harga_satuan = $h
|
|
AND nomor_barang = '$n'");
|
|
if($dt->num_rows > 0)
|
|
{
|
|
$a = $dt->fetch_array(MYSQLI_NUM);
|
|
// kalau jumlahnya tidak sama, update jumlah
|
|
if($aBaru[$x]['jumlah'] != $a[0])
|
|
{
|
|
$stmt = $mysqli->prepare("UPDATE d_retur_beli SET jumlah = ? WHERE id_retur = ? AND kd_barang = ? AND harga_satuan = ? AND nomor_barang = ?");
|
|
$stmt->bind_param("iisis", $aBaru[$x]['jumlah'], $retur_id, $aBaru[$x]['kode'], $aBaru[$x]['hb'], $aBaru[$x]['nomor']);
|
|
$stmt->execute();
|
|
if($stmt->affected_rows > 0) $hasild = 1;
|
|
else $hasild = 0;
|
|
$stmt->close();
|
|
}
|
|
/* tutup hasil query */
|
|
$dt->close();
|
|
}else
|
|
{
|
|
// jika data belum ada, insert data baru.
|
|
$stmt = $mysqli->prepare("INSERT INTO d_retur_beli(id_retur, kd_barang, jumlah, harga_satuan, nomor_barang)
|
|
VALUES (?, ?, ?, ?, ?)");
|
|
$stmt->bind_param("isiis", $retur_id, $aBaru[$x]['kode'], $aBaru[$x]['jumlah'], $aBaru[$x]['hb'], $aBaru[$x]['nomor']);
|
|
$stmt->execute();
|
|
if($stmt->affected_rows > 0) $hasild = 1;
|
|
else $hasild = 0;
|
|
$stmt->close();
|
|
}
|
|
}
|
|
// --> end update data table detail
|
|
}
|
|
/* tutup koneksi */
|
|
$mysqli->close();
|
|
$harray = array('hasilm' => $hasilm, 'hasild' => $hasild, 'id_retur' => $retur_id);
|
|
echo json_encode($harray);
|
|
}
|
|
|
|
/* end file */
|