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.

110 lines
2.8 KiB
PHP

<?php
session_start();
if($_SESSION['validUser'] !== TRUE)
{
header("location: ./index.php");
exit();
}
?>
<?php
include './db_login.inc.php';
include "./func_lib.php";
if(isset($_REQUEST['status']) && $_REQUEST['status'] == 'ok') {
if ($_REQUEST['operation'] == 'ambilKode') {
ambil_kode();
} elseif ($_REQUEST['operation'] == 'simpanbayar') {
simpan_bayar();
}
}
function simpan_bayar() {
if(isset($_POST['grandtot'])) {
$per_awal = $_POST['pawal'];
$per_akhir = $_POST['pakhir'];
$tglbyr = $_POST['tglbyr'];
$kdsupplier = $_POST['kdsupp'];
$idbayar = $_POST['idbayar'];
$jnsbayar = $_POST['jnsbyr'];
$tglcair = decTgl($_POST['tglcair']);
$nogiro = $_POST['nogiro'];
$disc = $_POST['disc'];
$penyesuaian = $_POST['pembulatan'];
$materai = $_POST['materai'];
$grandtotal = $_POST['grandtot'];
$ketbayar = $_POST['ketbayar'];
$array_data = array();
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
$dtInsert = $mysqli->prepare("INSERT INTO bayar(
`periode_awal`,
`periode_akhir`,
`tgl_bayar`,
`jenis_bayar`,
`tgl_cair`,
`no_giro`,
`kd_supplier`,
`diskon`,
`penyesuaian`,
`materai`,
`total_bayar`,
`ket_bayar`
)
VALUES ('$per_awal','$per_akhir','$tglbyr','$jnsbayar','$tglcair','$nogiro',
'$kdsupplier','$disc','$penyesuaian','$materai','$grandtotal','$ketbayar')");
$dtInsert->execute();
$qry_select = $mysqli->query("SELECT MAX(`IDbayar`) id FROM `bayar` WHERE 1");
if($qry_select->num_rows > 0){
while($n = $qry_select->fetch_array(MYSQLI_ASSOC)){
$id = $n['id'];
}
}
validBeli($id);
validRetur($id);
if($dtInsert->affected_rows > 0) {
$array_data[0] = 1;
} else {
$array_data[0] = 0;
}
$dtInsert->close();
$mysqli->close();
}
echo json_encode($array_data);
}
function validBeli($id){
$notabelis = $_POST['notabeli'];
$mysqli_beli = new mysqli(HOST, USER, PASSWORD, DATABASE);
foreach ($notabelis as $fakt => $valnotabelis){
$update_beli = $mysqli_beli->prepare("UPDATE `m_pembelian` SET status_bayar = '1',
IDbayar = '$id'
WHERE no_faktur = '$fakt'");
$update_beli->execute();
}
$mysqli_beli->close();
}
function validRetur($id){
$notareturs = $_POST['notaretur'];
$mysqli_retur = new mysqli(HOST, USER, PASSWORD, DATABASE);
foreach ($notareturs as $nota => $valnotareturs){
$update_retur = $mysqli_retur->prepare("UPDATE `m_retur_beli` SET status_bayar = '1',
IDbayar = '$id'
WHERE no_nota = '$nota'");
$update_retur->execute();
}
$mysqli_retur->close();
}
?>