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.
133 lines
4.4 KiB
PHP
133 lines
4.4 KiB
PHP
<?php
|
|
session_start();
|
|
if($_SESSION['validUser'] !== TRUE)
|
|
{
|
|
header("location: ./index.php");
|
|
exit();
|
|
}
|
|
|
|
if(isset($_POST['tgltransfer']) && isset($_POST['tokoasal']) && isset($_POST['tokotujuan'])
|
|
&& isset($_POST['kode']) && isset($_POST['nomorbarang']) && isset($_POST['jumlah']))
|
|
{
|
|
require_once("../db_login.inc.php");
|
|
$transfer_id = $_POST['idtransfer'];
|
|
$tgl_transfer = substr($_POST['tgltransfer'],6,4)."-".substr($_POST['tgltransfer'],3,2)."-".substr($_POST['tgltransfer'],0,2);
|
|
$faktur_oper = $_POST['fakturoper'];
|
|
$tokoasal = $_POST['tokoasal'];
|
|
$tokotujuan = $_POST['tokotujuan'];
|
|
$kd_supplier = $_POST['kodesupp'];
|
|
$no_faktur = $_POST['nofaktur'];
|
|
$diskon = $_POST['diskon'];
|
|
$kode = $_POST['kode'];
|
|
$kodeasli = $_POST['kodeasli'];
|
|
$jumlah = $_POST['jumlah'];
|
|
$hb_satuan = $_POST['hargabelisatuan'];
|
|
$no_barang = $_POST['nomorbarang'];
|
|
$tot_oper = $_POST['totaloper'];
|
|
$jml_oper = $_POST['jumlahoper'];
|
|
|
|
$hasilmaster = 0;
|
|
$hasild = 0;
|
|
|
|
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
|
|
if(!mysqli_connect_errno())
|
|
{
|
|
// isi table retur
|
|
$stmt = $mysqli->prepare("UPDATE m_transfer SET tgl_transfer = ? , toko_tujuan = ?, diskon = ?, jml_item = ?, total_transfer = ?
|
|
WHERE id_transfer = ?");
|
|
$stmt->bind_param("ssiiii", $tgl_transfer, $tokotujuan, $diskon, $jml_oper, $tot_oper, $transfer_id);
|
|
$stmt->execute();
|
|
if($stmt->affected_rows > 0) $hasilmaster = 1;
|
|
else $hasilmaster = 0;
|
|
$stmt->close();
|
|
|
|
// 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], 'kodeasli' => $kodeasli[$id], 'hb' => $hb_satuan[$id], 'jumlah' => $jumlah[$id], 'kodesupp' => $kd_supplier[$id], 'nofaktur' => $no_faktur[$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 kode_barang_nota
|
|
FROM d_transfer
|
|
WHERE id_transfer = $transfer_id
|
|
AND kode_barang_nota = '$k'
|
|
AND harga_satuan = $h
|
|
AND nomor = '$n'");
|
|
if($dt->num_rows > 0)
|
|
{
|
|
$a = $dt->fetch_array(MYSQLI_NUM);
|
|
$stmt = $mysqli->prepare("UPDATE d_transfer SET jumlah = ? WHERE id_transfer = ? AND kode_barang_nota = ? AND harga_satuan = ? AND nomor = ?");
|
|
$stmt->bind_param("iisis", $aBaru[$x]['jumlah'], $transfer_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_transfer(id_transfer, kode_barang_nota, jumlah, harga_satuan, nomor, kd_supplier, no_nota)
|
|
VALUES (?,?,?,?,?,?,?)");
|
|
$stmt->bind_param("isiisss",$transfer_id, $aBaru[$x]['kode'], $aBaru[$x]['jumlah'], $aBaru[$x]['hb'], $aBaru[$x]['nomor'], $aBaru[$x]['kodesupp'], $aBaru[$x]['nofaktur']);
|
|
$stmt->execute();
|
|
if($stmt->affected_rows > 0)
|
|
{
|
|
$hasild = 1;
|
|
}
|
|
else
|
|
{
|
|
$hasild = 0;
|
|
}
|
|
|
|
$stmt->close();
|
|
}
|
|
}
|
|
// --> end update data table detail
|
|
}
|
|
$mysqli->close();
|
|
// $harray = array('hasilmaster' => $hasilmaster, 'hasild' => $hasild, 'id_transfer' => $transfer_id);
|
|
$harray = array($aBaru);
|
|
echo json_encode($harray);
|
|
}
|
|
|
|
/* end file */
|