<?php
require("../../config/config.default.php");
require("../../config/config.function.php");
require("../../config/functions.crud.php");

$idsiswa = $_POST['idsiswa'];
$setoran = reset_rupiah($_POST['setoran']);

$data = mysqli_query ($koneksi, " select  penarikan,
										  setoran,
										  sum(penarikan) as jumlah_penarikan,
										  sum(setoran) as jumlah_setoran
										  from 
										  tabungan
										  where
										  idsiswa = $idsiswa");
$row = mysqli_fetch_array ($data);
$saldo = $row['jumlah_setoran'] - $row['jumlah_penarikan'] + $setoran;

$query = "insert INTO tabungan SET
								idsiswa = '$idsiswa',
								setoran = '$setoran',
								saldo = '$saldo'
								";

mysqli_query($koneksi, $query)
or die ("Gagal Perintah SQL".mysql_error());

?>

