module keuangan
parent
fa65af44b5
commit
b00f58bb46
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Models\Keuangan;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Maatwebsite\Excel\Concerns\FromView;
|
||||
|
||||
class KeuanganExport implements FromView
|
||||
{
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function collection()
|
||||
{
|
||||
return Keuangan::all();
|
||||
}
|
||||
|
||||
public function view(): View
|
||||
{
|
||||
return view('keuangan.export', [
|
||||
'keuangan' => $this->collection()
|
||||
]);
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Keuangan;
|
||||
use App\Exports\KeuanganExport;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
class KeuanganController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$keuangan = Keuangan::orderBy('created_at','desc')->paginate(10);
|
||||
return view('keuangan.index', [
|
||||
'keuangan' => $keuangan,
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'keperluan' => 'required|in:in,out',
|
||||
'jumlah' => 'required|numeric',
|
||||
'keterangan' => 'nullable',
|
||||
]);
|
||||
|
||||
$keuangan = Keuangan::orderBy('created_at','desc')->first();
|
||||
if($keuangan != null){
|
||||
$simpan = Keuangan::make([
|
||||
'tipe' => $request->keperluan,
|
||||
'jumlah' => $request->jumlah,
|
||||
'keterangan' => $request->keterangan
|
||||
]);
|
||||
if($request->keperluan == 'in'){
|
||||
$simpan->total_kas = $keuangan->total_kas + $request->jumlah;
|
||||
}else if($request->keperluan == 'out'){
|
||||
$simpan->total_kas = $keuangan->total_kas - $request->jumlah;
|
||||
}
|
||||
}else{
|
||||
$simpan = Keuangan::make([
|
||||
'tipe' => $request->keperluan,
|
||||
'jumlah' => $request->jumlah,
|
||||
'keterangan' => $request->keterangan
|
||||
]);
|
||||
$simpan->total_kas = $request->jumlah;
|
||||
}
|
||||
|
||||
if($simpan->save()){
|
||||
return redirect()->route('keuangan.index')->with([
|
||||
'type' => 'success',
|
||||
'msg' => 'Pencatatan Keuangan dibuat'
|
||||
]);
|
||||
}else{
|
||||
return redirect()->route('keuangan.index')->with([
|
||||
'type' => 'danger',
|
||||
'msg' => 'Terjadi Kesalahan'
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function export()
|
||||
{
|
||||
return Excel::download(new KeuanganExport, 'mutasi_keuangan-'.now().'.xlsx');
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th><b>Tanggal</b></th>
|
||||
<th><b>KD</b></th>
|
||||
<th><b>Jumlah</b></th>
|
||||
<th><b>Keterangan</b></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($keuangan as $item)
|
||||
<tr>
|
||||
<td>{{ $item->created_at->format('d-m-Y') }}</td>
|
||||
<td>{{ ($item->tipe == 'in') ? 'Pemasukan' : 'Pengeluaran' }}</td>
|
||||
<td>{{ $item->jumlah }}</td>
|
||||
<td>{{ $item->keterangan }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
@ -0,0 +1,134 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('page-name','Keuangan')
|
||||
|
||||
@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">Keperluan</label>
|
||||
<div class="selectgroup w-100">
|
||||
<label class="selectgroup-item">
|
||||
<input type="radio" name="keperluan" value="in" class="selectgroup-input">
|
||||
<span class="selectgroup-button">Catat Pemasukan</span>
|
||||
</label>
|
||||
<label class="selectgroup-item">
|
||||
<input type="radio" name="keperluan" value="out" class="selectgroup-input">
|
||||
<span class="selectgroup-button">Catat Pengeluaran</span>
|
||||
</label>
|
||||
</div>
|
||||
</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'>
|
||||
</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 id="submit" class="btn btn-primary ml-auto" style="display:none">Simpan</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title">Mutasi Keuangan</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>KD</th>
|
||||
<th>Keterangan</th>
|
||||
<th>Jumlah</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($keuangan as $index => $item)
|
||||
<tr>
|
||||
<td><span class="text-muted">{{ $index+1 }}</span></td>
|
||||
<td>{{ $item->created_at->format('d-m-Y') }}</td>
|
||||
<td>
|
||||
@if($item->tipe == 'in')
|
||||
Uang Masuk
|
||||
@elseif($item->tipe == 'out')
|
||||
Uang Keluar
|
||||
@endif
|
||||
</td>
|
||||
<td style="max-width:150px;">{{ $item->keterangan }}</td>
|
||||
<td>IDR. {{ format_idr($item->jumlah) }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<div class="d-flex">
|
||||
<div class="ml-auto mb-0">
|
||||
{{ $keuangan->links() }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@section('js')
|
||||
<script>
|
||||
require(['jquery'], function ($) {
|
||||
$(document).ready(function () {
|
||||
var keperluan = 'in';
|
||||
//keperluan
|
||||
$('.selectgroup-input').change(function(){
|
||||
keperluan = this.value
|
||||
$('#form-jumlah').show()
|
||||
$('#form-keterangan').show()
|
||||
$('#submit').show()
|
||||
})
|
||||
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endsection
|
Loading…
Reference in New Issue