bayar spp done

pull/1/head
Aji Kamaludin 5 years ago
parent b00f58bb46
commit df6f9c7034
No known key found for this signature in database
GPG Key ID: 23E2BDC458317AF8

@ -25,14 +25,16 @@ class TabunganController extends Controller
//api manabung
public function menabung(Request $request, Siswa $siswa)
{
$jumlah_bersih = preg_replace("/[,.]/", "", $request->jumlah);
DB::beginTransaction();
$tabungan = Tabungan::where('siswa_id', $siswa->id)->orderBy('created_at','desc')->first();
if($tabungan != null){
$menabung = Tabungan::make($request->input());
$menabung = Tabungan::make($request->except('jumlah'));
$menabung->jumlah = $jumlah_bersih;
if($request->tipe == 'in'){
$menabung->saldo = $request->jumlah + $tabungan->saldo;
$menabung->saldo = $jumlah_bersih + $tabungan->saldo;
}else if($request->tipe == 'out'){
$menabung->saldo = $tabungan->saldo - $request->jumlah;
$menabung->saldo = $tabungan->saldo - $jumlah_bersih;
}
if($menabung->saldo >=0 ){
$menabung->save();
@ -41,13 +43,14 @@ class TabunganController extends Controller
$pesan = 'Transaksi gagal';
}
}else{
$menabung = Tabungan::make($request->input());
$menabung->saldo = $request->jumlah;
$menabung = Tabungan::make($request->except('jumlah'));
$menabung->jumlah = $jumlah_bersih;
$menabung->saldo = $jumlah_bersih;
$menabung->save();
$pesan = 'Berhasil melakukan transaksi';
}
//tambahkan tabungan ke transaksi
//tambahkan tabungan ke keuangan
$keuangan = Keuangan::orderBy('created_at','desc')->first();
if($keuangan != null){
if($menabung->tipe == 'in'){

@ -0,0 +1,124 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Transaksi;
use App\Models\Siswa;
use App\Models\Tagihan;
use Illuminate\Support\Facades\DB;
use App\Models\Keuangan;
use App\Models\Tabungan;
class TransaksiController extends Controller
{
public function index()
{
$siswa = Siswa::where('is_yatim','0')->orderBy('created_at','desc')->get();
$transaksi = Transaksi::orderBy('created_at','desc')->paginate(10);
return view('transaksi.index', [
'siswa' => $siswa,
'transaksi' => $transaksi,
]);
}
//pay tagihan
public function store(Request $request,Siswa $siswa)
{
DB::beginTransaction();
//mulai transaksi, membersihkan request->jumlah dari titik dan koma
$jumlah = preg_replace("/[,.]/", "", $request->jumlah);
$jumlah = $jumlah - $request->diskon;
//membuat transaksi baru
$transaksi = Transaksi::make([
'siswa_id' => $siswa->id,
'tagihan_id' => $request->tagihan_id,
'diskon' => $request->diskon,
'is_lunas' => 1,
'keterangan' => ($request->via == 'tabungan' ? 'dibayarkan melalui tabungan' : 'dibayarkan secara tunai, ').
', '.$request->keterangan,
]);
//menyimpan transaksi
if($transaksi->save()){
//tambahkan transaksi ke keuangan
$keuangan = Keuangan::orderBy('created_at','desc')->first();
if($keuangan != null){
$total_kas = $keuangan->total_kas + $jumlah;
}else{
$total_kas = $jumlah;
}
$keuangan = Keuangan::create([
'transaksi_id' => $transaksi->id,
'tipe' => 'in',
'jumlah' => $jumlah,
'total_kas' => $total_kas,
'keterangan' => 'Pembayaran SPP oleh '.$transaksi->siswa->nama.' pada tanggal '.$transaksi->created_at.' dengan catatan : dibayarkan dengan '.$request->via.
', '.$request->keterangan
]);
}
// jika pembayaran dilakukan melalui tabungan
if($request->via == 'tabungan'){
$tabungan = Tabungan::where('siswa_id', $siswa->id)->orderBy('created_at','desc')->first();
$menabung = Tabungan::create([
'siswa_id' => $siswa->id,
'tipe' => 'out',
'jumlah' => $jumlah,
'saldo' => $tabungan->saldo - $jumlah,
'keperluan' => 'penarikan dilakukan untuk pembayaran spp melalui tabungan',
]);
//tambahkan tabungan ke keuangan
$keuangan = Keuangan::orderBy('created_at','desc')->first();
if($keuangan != null){
$jumlah = $keuangan->total_kas + $menabung->jumlah;
}else{
$jumlah = $menabung->jumlah;
}
$keuangan = Keuangan::create([
'tabungan_id' => $menabung->id,
'tipe' => $menabung->tipe,
'jumlah' => $menabung->jumlah,
'total_kas' => $jumlah,
'keterangan' => 'Transaksi tabungan oleh '. $menabung->siswa->nama."(".$menabung->siswa->kelas->nama.")".
'melakukan pembayaran spp sebesar '. $menabung->jumlah
.' pada '.$menabung->created_at.' dengan total tabungan '.$menabung->saldo
]);
}
if($keuangan){
DB::commit();
return response()->json(['msg' => 'transaksi berhasil dilakukan']);
}else{
DB::rollBack();
return redirect()->route('spp.index')->with([
'type' => 'danger',
'msg' => 'terjadi kesalahan'
]);
}
}
//get list tagihan of siswa
public function tagihan(Siswa $siswa)
{
//wajib semua
$tagihan_wajib = Tagihan::where('wajib_semua','1')->get()->toArray();
//kelas only
$tagihan_kelas = Tagihan::where('kelas_id', $siswa->kelas->id)->get()->toArray();
//student only
$tagihan_siswa = [];
$tagihan_rolesiswa = $siswa->role;
foreach($tagihan_rolesiswa as $tag_siswa){
$tagihan_siswa[] = $tag_siswa->tagihan->toArray();
}
$tagihan = array_merge($tagihan_wajib, $tagihan_kelas, $tagihan_siswa);
return response()->json($tagihan);
}
}

@ -21,16 +21,8 @@
<div class="col-6 col-sm-3 col-lg-3">
<div class="card">
<div class="card-body p-3 text-center">
<div class="h1 m-0">IDR {{ format_idr($total_uang_tabungan) }}</div>
<div class="text-muted mb-4">Total Uang Tabungan</div>
</div>
</div>
</div>
<div class="col-6 col-sm-3 col-lg-3">
<div class="card">
<div class="card-body p-3 text-center">
<div class="h1 m-0">IDR {{ format_idr($total_uang_spp) }}</div>
<div class="text-muted mb-4">Total Uang SPP</div>
<div class="h1 m-0">IDR {{ format_idr($total_uang_masuk) }}</div>
<div class="text-muted mb-4">Total Uang Masuk</div>
</div>
</div>
</div>
@ -45,18 +37,16 @@
<div class="col-6 col-sm-3 col-lg-3">
<div class="card">
<div class="card-body p-3 text-center">
<div class="h1 m-0">IDR {{ format_idr($total_uang_masuk) }}</div>
<div class="text-muted mb-4">Total Uang Masuk</div>
<div class="h1 m-0">IDR {{ format_idr($total_uang_spp) }}</div>
<div class="text-muted mb-4">Total Uang SPP</div>
</div>
</div>
</div>
<div class="col-12">
<div class="col-6 col-sm-3 col-lg-3">
<div class="card">
<div class="card-header">
<h3 class="card-title">Dashboard</h3>
</div>
<div class="card-body">
<h5>Dashboard</h5>
<div class="card-body p-3 text-center">
<div class="h1 m-0">IDR {{ format_idr($total_uang_tabungan) }}</div>
<div class="text-muted mb-4">Total Uang Tabungan</div>
</div>
</div>
</div>

@ -51,7 +51,7 @@
</div>
<div class="form-group" style="display:none" id="form-jumlah">
<label class="form-label">Jumlah</label>
<input type="number" name="jumlah" id="jumlah" class="form-control" min='100'>
<input type="number" name="jumlah" id="jumlah" class="form-control" min='100' required>
</div>
<div class="form-group" style="display:none" id="form-keterangan">
<label class="form-label">Keterangan</label>

@ -9,7 +9,7 @@
</a>
</li>
<li class="nav-item">
<a href="#!" class="nav-link {{ set_active(['transaksispp.*'], 'active') }}">
<a href="{{ route('spp.index') }}" class="nav-link {{ set_active(['spp.*'], 'active') }}">
<i class="fe fe-repeat"></i> Transaksi SPP
</a>
</li>

@ -58,7 +58,7 @@
@foreach ($siswa as $index => $item)
<tr>
<td><span class="text-muted">{{ $index+1 }}</span></td>
<td> {{ $item->kelas->nama }} </td>
<td> {{ $item->kelas->nama }}{{ isset($item->kelas->periode) ? "(".$item->kelas->periode->nama.")" : ''}}</td>
<td>
<a href="" class="link-unmuted">
{{ $item->nama }}

@ -61,7 +61,7 @@
</div>
<div class="form-group" style="display:none" id="form-jumlah">
<label class="form-label">Jumlah</label>
<input type="number" name="jumlah" id="jumlah" class="form-control" min='100'>
<input type="number" name="jumlah" id="jumlah" class="form-control" min='100' placeholder="masukan jumlah tanpa tanda titik atau koma">
</div>
<div class="form-group" style="display:none" id="form-keterangan">
<label class="form-label">Keterangan</label>

@ -0,0 +1,321 @@
@extends('layouts.app')
@section('page-name','Pembayaran SPP')
@section('content')
<div class="page-header">
<h1 class="page-title">
@yield('page-name')
</h1>
</div>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h3 class="card-title">Transaksi</h3>
</div>
@if(session()->has('msg'))
<div class="card-alert alert alert-{{ session()->get('type') }}" id="message" style="border-radius: 0px !important">
@if(session()->get('type') == 'success')
<i class="fe fe-check mr-2" aria-hidden="true"></i>
@else
<i class="fe fe-alert-triangle mr-2" aria-hidden="true"></i>
@endif
{{ session()->get('msg') }}
</div>
@endif
<div class="card-body">
{{-- <form action="{{ route('keuangan.store') }}" method="post"> --}}
@if($errors->any())
<div class="alert alert-danger">
@foreach($errors->all() as $error)
{{ $error }}<br>
@endforeach
</div>
@endif
<div class="row">
<div class="col-12">
@csrf
<div class="form-group">
<label class="form-label">Siswa</label>
<select id="siswa" class="form-control" name="siswa_id">
<option value="#">[-- Pilih Siswa --]</option>
@foreach($siswa as $item)
<option value="{{ $item->id }}"> {{ $item->nama.' - '.$item->kelas->nama.' - ' }} </option>
@endforeach
</select><br>
Saldo: IDR. <span id="saldo">0</span>
</div>
<div class="form-group" style="display: none" id="form-tagihan">
<label class="form-label" >Tagihan</label>
<select id="tagihan" class="form-control" name="tagihan_id">
</select>
</div>
<div class="form-group" style="display: none" id="form-tagihan-2">
<label class="form-label">Total Tagihan</label>
IDR. <span id="harga">0</span>
<label class="custom-switch">
<input type="checkbox" class="custom-switch-input" id="ada-diskon">
<span class="custom-switch-indicator"></span>
<span class="custom-switch-description">Ada diskon? </span>
</label>
</div>
<div class="form-group" style="display: none" id="form-diskon">
<label class="form-label">Diskon (IDR)</label>
<input type="text" name="diskon" id="diskon" class="form-control" placeholder="masukan angka dalam satuan mata uang, tanpa titik atau koma">
</div>
<div class="form-group" style="display: none" id="form-total">
<label class="form-label">Total Pembayaran</label>
<input type="text" name="pembayaran" class="form-control" id="total" readonly>
</div>
<div class="form-group" style="display: none" id="form-pembayaran">
<label class="form-label">Pembayaran</label>
<div class="selectgroup w-100">
<label class="selectgroup-item">
<input type="radio" name="via" value="tunai" class="selectgroup-input" checked="">
<span class="selectgroup-button">Tunai</span>
</label>
<label class="selectgroup-item" style="display: none" id="opsi-tabungan">
<input type="radio" name="via" value="tabungan" class="selectgroup-input">
<span class="selectgroup-button">Potong Tabungan</span>
</label>
</div>
</div>
<div class="form-group" style="display: none" id="form-keterangan">
<label class="form-label">Keterangan</label>
<textarea name="keterangan" id="keterangan" rows="3" class="form-control"></textarea>
</div>
</div>
</div>
<div class="d-flex">
<button class="btn btn-primary ml-auto" style="display: none" id="btn-simpan">Simpan</button>
</div>
{{-- </form> --}}
</div>
</div>
</div>
<div class="col-12">
<div class="card">
<div class="card-header">
<h3 class="card-title">Histori Transaksi</h3>
<div class="card-options">
<a href="{{ route('keuangan.export') }}" class="btn btn-primary btn-sm ml-2" download="true">Export</a>
</div>
</div>
<div class="table-responsive">
<table class="table card-table table-hover table-vcenter text-wrap">
<thead>
<tr>
<th class="w-1">No.</th>
<th>Tanggal</th>
<th>Siswa</th>
<th>Jumlah</th>
<th>Diskon</th>
<th>Total</th>
<th>Keterangan</th>
</tr>
</thead>
<tbody>
@foreach ($transaksi as $index => $item)
<tr>
<td><span class="text-muted">{{ $index+1 }}</span></td>
<td>{{ $item->created_at->format('d-m-Y') }}</td>
<td>{{ $item->siswa->nama.'('.$item->siswa->kelas->nama.')' }}</td>
<td>IDR. {{ format_idr($item->tagihan->jumlah) }}</td>
<td>IDR. {{ format_idr($item->diskon) }}</td>
<td>IDR. {{ format_idr($item->tagihan->jumlah - $item->diskon) }}</td>
<td style="max-width:150px;">{{ $item->keterangan }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="card-footer">
<div class="d-flex">
<div class="ml-auto mb-0">
{{ $transaksi->links() }}
</div>
</div>
</div>
</div>
</div>
</div>
@endsection
@section('css')
<link href="{{ asset('assets/plugins/select2/select2.min.css') }}" rel="stylesheet" />
<style>
.select2-container--default .select2-selection--multiple .select2-selection__choice {
color: black;
}
.select2{
width: 100% !important;
}
</style>
@endsection
@section('js')
<script>
require(['jquery','select2','sweetalert'], function ($, select2, sweetalert) {
$(document).ready(function () {
//format IDR
function formatNumber(num) {
return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1.')
}
$('#siswa').select2({
placeholder: "Pilih Siswa",
});
$('#tagihan').select2({});
var siswa_id; //siswa_id
var tagihan_id; //tagihan_id
var saldo; //saldo dari siswa
var harga; //harga dari tagihan
var diskon = 0; //diskon
var via = 'tunai'; //pembayaran via
// memilih siswa
$('#siswa').on('change',function(){
if(this.value == '#'){
$('#saldo').text('0')
$('#form-tagihan').hide()
$('#form-tagihan-2').hide()
$('#form-total').hide()
$('#form-pembayaran').hide()
$('#opsi-tabungan').hide()
$('#form-keterangan').hide()
$('#btn-simpan').hide()
return;
}else{
siswa_id = this.value
}
//get saldo
$.ajax({url: "{{ route('api.getsaldo') }}/" + this.value, success: function(result){
$('#saldo').text(result.sal)
saldo = result.saldo
$('#form-tagihan').show()
$('#form-tagihan-2').show()
$('#form-total').show()
$('#form-pembayaran').show()
if(saldo > 0){
$('#opsi-tabungan').show()
}
$('#form-keterangan').show()
$('#btn-simpan').show()
}, beforeSend: function(){
$('#saldo').text('tunggu, sedang mengambil saldo.....')
$('#form-tagihan').hide()
$('#form-tagihan-2').hide()
$('#form-total').hide()
$('#form-pembayaran').hide()
$('#opsi-tabungan').hide()
$('#form-keterangan').hide()
$('#btn-simpan').hide()
}});
//get tagihan
$.ajax({url: "{{ route('api.gettagihan') }}/" + this.value, success: function(result){
if(result.length == 0){
alert('tidak ada item tagihan yang tersedia')
}
$("#tagihan").empty()
for(i=0;i < result.length ;i++){
$("#tagihan").append('<option value="'+ result[i].id +'" data-harga="'+ result[i].jumlah +'">'+ result[i].nama +'</option>');
}
//set harga dari data pertama
tagihan_id = result[0].id
harga = result[0].jumlah
if(harga <= saldo){
$('#opsi-tabungan').show()
}else{
$('#opsi-tabungan').hide()
}
//menampilkan harga
$('#harga').text(formatNumber(harga));
$('#total').val(formatNumber(harga - diskon));
},});
})
$('#tagihan').on('change', function(){
tagihan_id = this.value
//set harga dari opsi yang dipilih
harga = $('option:selected', this).attr('data-harga');
if(harga <= saldo){
$('#opsi-tabungan').show()
}else{
$('#opsi-tabungan').hide()
}
//jika diganti diskon kembali ke nol
diskon = 0
$('#diskon').val('');
//menampilkan harga
$('#harga').text(formatNumber(harga));
$('#total').val(formatNumber(harga - diskon));
})
$('#ada-diskon').on('change', function(){
$('#form-diskon').toggle();
})
$('#diskon').keyup(function(){
if(this.value <= 0){
this.value = ''
diskon = 0
}else{
diskon = this.value
}
if((harga - diskon) < 0){
diskon = 0
alert('diskon invalid, silahkan tulis ulang')
$('#diskon').val('')
}
$('#total').val(formatNumber(harga - diskon));
if((harga - diskon) <= saldo){
$('#opsi-tabungan').show()
}else{
$('#opsi-tabungan').hide()
}
})
//pembayaran via
$('.selectgroup-input').change(function(){
via = this.value
})
$('#btn-simpan').on('click', function(){
console.log(harga)
if((harga - diskon) == NaN){
alert('diskon invalid')
}else{
$('#btn-simpan').addClass("btn-loading")
$.ajax({
type: "POST",
url: "{{ route('api.tagihan') }}/"+siswa_id,
data: {
tagihan_id : tagihan_id,
siswa_id : siswa_id,
jumlah : harga,
diskon : diskon,
keterangan : keterangan.value,
via : via
},
success: function(data){
console.log(data);
swal({title: data.msg})
setTimeout(function(){
window.location.reload()
}, 2000)
},
error: function(data){
console.log('Error......')
console.log(data)
}
});
}
})
});
});
</script>
@endsection

@ -18,4 +18,6 @@ Route::middleware('auth:api')->get('/user', function (Request $request) {
});
Route::get('saldo/{siswa?}','SiswaController@getSaldo')->name('api.getsaldo');
Route::post('menabung/{siswa?}', 'TabunganController@menabung')->name('api.menabung');
Route::post('menabung/{siswa?}', 'TabunganController@menabung')->name('api.menabung');
Route::get('tagihan/{siswa?}','TransaksiController@tagihan')->name('api.gettagihan');
Route::post('transaksi-spp/{siswa?}','TransaksiController@store')->name('api.tagihan');

@ -71,6 +71,9 @@ Route::middleware(['auth:web'])->group(function(){
Route::get('keuangan', 'KeuanganController@index')->name('keuangan.index');
Route::post('keuangan', 'KeuanganController@store')->name('keuangan.store');
Route::get('export-keuangan', 'KeuanganController@export')->name('keuangan.export');
//Pembayaran SPP
Route::get('transaksi-spp','TransaksiController@index')->name('spp.index');
});

Loading…
Cancel
Save