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.

119 lines
3.2 KiB
PHP

<?php
session_start();
if($_SESSION['validUser'] !== TRUE)
{
header("location: ./index.php");
exit();
}
if ($_REQUEST['operation'] == 'simpan' && $_REQUEST['nofaktur'] != "")
{
update_m_pembelian();
update_barang();
}
function update_m_pembelian()
{
$nofaktur = $_REQUEST['nofaktur'];
$nofakturedit = $_REQUEST['nofakturedit'];
$tglnota = decTgl($_REQUEST['tglnota']);
$tglrf = $_REQUEST['tglrf'];
$tglmasuk = decTgl($_REQUEST['tglmasuk']);
$status = $_REQUEST['status'];
$tgljthtempo = decTgl($_REQUEST['tgljthtempo']);
$kdsupp = $_REQUEST['kodesupplier'];
$nik = $_REQUEST['nik'];
$keterangan = $_REQUEST['keterangan'];
$hrgsatuan = $_REQUEST['hargabeli'];
$stok = $_REQUEST['jmlt'];
$rpbeli = hitung_total_hp($hrgsatuan, $stok);
$ketr = $keterangan . "(revisi barang oleh ".$_SESSION["useracc"]." => ". $tglrf .")";
$array_data = array();
require_once("../db_login.inc.php");
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
$stmt = $mysqli->prepare("UPDATE m_pembelian SET no_faktur=?, tgl_nota=?, tgl_masuk=?, tgl_jatuh_tempo=?, kd_supplier=?, status=?, nik=?, keterangan=? WHERE no_faktur = ?");
$stmt->bind_param("sssssssss", $nofakturedit, $tglnota, $tglmasuk, $tgljthtempo, $kdsupp, $status, $nik, $ketr, $nofaktur);
$stmt->execute();
if($stmt->affected_rows > 0) {
$stmt2 = $mysqli->prepare("UPDATE d_pembelian SET no_faktur=? WHERE no_faktur = ?");
$stmt2->bind_param("ss", $nofakturedit, $nofaktur);
$stmt2->execute();
update_barang();
$array_data[0] = 1;
} else {
$array_data[0] = 0;
}
$stmt->close();
$mysqli->close();
echo json_encode($array_data);
}
function update_barang()
{
$barang = array();
$kdsupp = $_REQUEST['kodesupplier'];
$nofaktur = $_REQUEST['nofaktur'];
require_once("../db_login.inc.php");
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
$stmt3 = $mysqli->query("SELECT DISTINCT kode_barang FROM d_pembelian WHERE no_faktur = '$nofaktur'");
$jumBarang = $stmt3->num_rows;
if($jumBarang > 0){
$idx = 0;
while($db = $stmt3->fetch_array(MYSQLI_ASSOC))
{
$barang[$idx] = array('kode_barang' => $db['kode_barang']);
$idx++;
}
$stmt3->close();
}
// update kdsupp
for($i=0; $i<$jumBarang; $i++)
{
$stmt = $mysqli->prepare("UPDATE barang SET kode_supplier = ? WHERE kode_barang = ?");
$stmt->bind_param("ss",$kdsupp, $barang[$i]['kode_barang']);
$stmt->execute();
$stmt->close();
}
$mysqli->close();
}
function hitung_total_hp($data, $stok)
{
$total = 0;
for ($i = 0; $i < count($data); $i++)
{
$total += $data[$i] * $stok[$i];
}
return $total;
}
function decode_hp($hp)
{
$dt = "";
for($i = 0; $i < strlen($hp); $i++)
{
$chr = substr($hp, $i, 1);
switch($chr)
{
case "B" : $dt .= "1";break;
case "R" : $dt .= "2";break;
case "A" : $dt .= "3";break;
case "W" : $dt .= "4";break;
case "N" : $dt .= "5";break;
case "F" : $dt .= "6";break;
case "O" : $dt .= "7";break;
case "X" : $dt .= "8";break;
case "E" : $dt .= "9";break;
case "S" : $dt .= "0";break;
}
}
return (int) $dt;
}
function decTgl($tgl){// ke format yyyy-mm-dd
$d = substr($tgl,0,2);
$m = substr($tgl,3,2);
$y = substr($tgl,6,4);
return $y."-".$m."-".$d;
}