diff --git a/app/Exports/SiswaExport.php b/app/Exports/SiswaExport.php
index 7963e1f..ccef167 100644
--- a/app/Exports/SiswaExport.php
+++ b/app/Exports/SiswaExport.php
@@ -3,7 +3,6 @@
namespace App\Exports;
use App\Models\Siswa;
-use Maatwebsite\Excel\Concerns\FromCollection;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
diff --git a/app/Exports/TabunganExport.php b/app/Exports/TabunganExport.php
new file mode 100644
index 0000000..70afc84
--- /dev/null
+++ b/app/Exports/TabunganExport.php
@@ -0,0 +1,25 @@
+ $this->collection()
+ ]);
+ }
+}
diff --git a/app/Http/Controllers/SiswaController.php b/app/Http/Controllers/SiswaController.php
index 80df48f..9e798b1 100644
--- a/app/Http/Controllers/SiswaController.php
+++ b/app/Http/Controllers/SiswaController.php
@@ -9,6 +9,7 @@ use Illuminate\Support\Facades\Input;
use Maatwebsite\Excel\Facades\Excel;
use App\Exports\SiswaExport;
use App\Imports\SiswaImport;
+use App\Models\Tabungan;
class SiswaController extends Controller
{
@@ -204,4 +205,24 @@ class SiswaController extends Controller
{
return Excel::download(new SiswaExport, 'siswa-'.now().'.xlsx');
}
+
+ //api saldo
+ public function getSaldo(Siswa $siswa)
+ {
+ if($siswa == null){
+ return response()->json(['msg' => 'siswa tidak ditemukan'], 404);
+ }
+ if($siswa->tabungan->count() == 0){
+ return response()->json(['saldo' => '0', 'sal' => '0']);
+ }
+
+ $input = Tabungan::where('tipe','in')->where('siswa_id',$siswa->id)->sum('jumlah');
+ $output = Tabungan::where('tipe','out')->where('siswa_id',$siswa->id)->sum('jumlah');
+ $verify = Tabungan::where('siswa_id', $siswa->id)->orderBy('created_at','desc')->first()->saldo;
+ if(($input - $output) == $verify){
+ return response()->json(['saldo' => $input - $output, 'sal' => format_idr($input - $output)]);
+ }else{
+ return response()->json(['saldo' => '0', 'sal' => 'invalid '.format_idr($input - $output)]);
+ }
+ }
}
diff --git a/app/Http/Controllers/TabunganController.php b/app/Http/Controllers/TabunganController.php
new file mode 100644
index 0000000..e80ae57
--- /dev/null
+++ b/app/Http/Controllers/TabunganController.php
@@ -0,0 +1,89 @@
+get();
+ $tabungan = Tabungan::orderBy('created_at','desc')->paginate(10);
+ return view('tabungan.index', [
+ 'siswa' => $siswa,
+ 'tabungan' => $tabungan,
+ ]);
+ }
+
+ //api manabung
+ public function menabung(Request $request, Siswa $siswa)
+ {
+ DB::beginTransaction();
+ $tabungan = Tabungan::where('siswa_id', $siswa->id)->orderBy('created_at','desc')->first();
+ if($tabungan != null){
+ $menabung = Tabungan::make($request->input());
+ if($request->tipe == 'in'){
+ $menabung->saldo = $request->jumlah + $tabungan->saldo;
+ }else if($request->tipe == 'out'){
+ $menabung->saldo = $tabungan->saldo - $request->jumlah;
+ }
+ if($menabung->saldo >=0 ){
+ $menabung->save();
+ $pesan = 'Berhasil melakukan transaksi';
+ }else{
+ $pesan = 'Transaksi gagal';
+ }
+ }else{
+ $menabung = Tabungan::make($request->input());
+ $menabung->saldo = $request->jumlah;
+ $menabung->save();
+ $pesan = 'Berhasil melakukan transaksi';
+ }
+
+ //tambahkan tabungan ke transaksi
+ $keuangan = Keuangan::orderBy('created_at','desc')->first();
+ if($keuangan != null){
+ if($menabung->tipe == 'in'){
+ $jumlah = $keuangan->total_kas + $menabung->jumlah;
+ }else if($request->tipe == 'out'){
+ $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.")".
+ ( ($request->tipe == 'in') ? ' menabung' : ' melakukan penarikan tabungan').' sebesar '. $menabung->jumlah
+ .' pada '.$menabung->created_at.' dengan total tabungan '.$menabung->saldo.
+ ( (isset($menabung->keperluan)) ? ' dengan catatan: '.$menabung->keperluan : ''),
+ ]);
+
+ if($keuangan){
+ DB::commit();
+ return response()->json(['msg' => $pesan]);
+ }else{
+ DB::rollBack();
+ return redirect()->route('tabungan.index')->with([
+ 'type' => 'danger',
+ 'msg' => 'terjadi kesalahan'
+ ]);
+ }
+
+ }
+
+ public function export()
+ {
+ return Excel::download(new TabunganExport, 'mutasi_tabungan-'.now().'.xlsx');
+ }
+}
diff --git a/app/Models/Tabungan.php b/app/Models/Tabungan.php
index 6e731c5..5d20585 100644
--- a/app/Models/Tabungan.php
+++ b/app/Models/Tabungan.php
@@ -20,7 +20,7 @@ class Tabungan extends Model
];
public function siswa(){
- return $this->belongsTo('App\Models\Siswa','id','siswa_id');
+ return $this->belongsTo('App\Models\Siswa','siswa_id','id');
}
public function keuangan(){
diff --git a/resources/views/shared/navbar.blade.php b/resources/views/shared/navbar.blade.php
index 2489c30..eecafa3 100644
--- a/resources/views/shared/navbar.blade.php
+++ b/resources/views/shared/navbar.blade.php
@@ -14,8 +14,8 @@
-
- Transaksi Tabungan
+
+ Tabungan
diff --git a/resources/views/tabungan/export.blade.php b/resources/views/tabungan/export.blade.php
new file mode 100644
index 0000000..eeccf47
--- /dev/null
+++ b/resources/views/tabungan/export.blade.php
@@ -0,0 +1,22 @@
+
+
+
+ Tanggal |
+ Siswa |
+ KD |
+ Jumlah |
+ Keterangan |
+
+
+
+ @foreach($tabungan as $item)
+
+ {{ $item->created_at->format('d-m-Y') }} |
+ {{ $item->siswa->nama."(".$item->siswa->kelas->nama.")" }} |
+ {{ ($item->tipe == 'in') ? 'Menabung' : 'Penarikan Uang' }} |
+ {{ $item->jumlah }} |
+ {{ $item->keperluan }} |
+
+ @endforeach
+
+
\ No newline at end of file
diff --git a/resources/views/tabungan/index.blade.php b/resources/views/tabungan/index.blade.php
new file mode 100644
index 0000000..bf4de18
--- /dev/null
+++ b/resources/views/tabungan/index.blade.php
@@ -0,0 +1,263 @@
+@extends('layouts.app')
+
+@section('page-name','Tabungan')
+
+@section('content')
+
+
+
+
+
+ @if(session()->has('msg'))
+
+ @if(session()->get('type') == 'success')
+
+ @else
+
+ @endif
+ {{ session()->get('msg') }}
+
+ @endif
+
+
+
+
+
+
+
+
+
+
+ No. |
+ Tanggal |
+ Nama |
+ KD |
+ Keterangan |
+ Jumlah |
+ |
+
+
+
+ @foreach ($tabungan as $index => $item)
+
+ {{ $index+1 }} |
+ {{ $item->created_at->format('d-m-Y') }} |
+
+ {{ $item->siswa->nama }} -
+ {{ $item->siswa->kelas->nama }} -
+ {{ isset($item->siswa->kelas->periode) ? $item->siswa->kelas->periode->nama : '' }}
+ |
+
+ @if($item->tipe == 'in')
+ Menabung
+ @elseif($item->tipe == 'out')
+ Penarikan
+ @endif
+ |
+ {{ $item->keperluan }} |
+ IDR. {{ format_idr($item->jumlah) }} |
+
+ {{--
+
+ --}}
+
+ |
+
+ @endforeach
+
+
+
+
+
+
+
+@endsection
+@section('css')
+
+
+@endsection
+@section('js')
+
+@endsection
\ No newline at end of file
diff --git a/routes/api.php b/routes/api.php
index c641ca5..acf30c6 100644
--- a/routes/api.php
+++ b/routes/api.php
@@ -16,3 +16,6 @@ use Illuminate\Http\Request;
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
+
+Route::get('saldo/{siswa?}','SiswaController@getSaldo')->name('api.getsaldo');
+Route::post('menabung/{siswa?}', 'TabunganController@menabung')->name('api.menabung');
\ No newline at end of file
diff --git a/routes/web.php b/routes/web.php
index 600473a..2647e60 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -61,6 +61,12 @@ Route::middleware(['auth:web'])->group(function(){
Route::get('user/{user}/ubah', 'UserController@edit')->name('user.edit');
Route::post('user/{user}/ubah','UserController@update')->name('user.update');
Route::post('user/{user}/hapus', 'UserController@destroy')->name('user.destroy');
+
+ //Menabung
+ Route::get('tabungan', 'TabunganController@index')->name('tabungan.index');
+ Route::post('menabung', 'TabunganController@menabung')->name('tabungan.store');
+ Route::get('export-mutasi', 'TabunganController@export')->name('tabungan.export');
+ Route::post('del-tabungan','TabunganController@destroy')->name('tabungan.destroy');
});