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 $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;$iquery("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 */