add module tagihan

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

@ -13,4 +13,10 @@ if(!function_exists('set_active')){
} }
} }
} }
}
if (! function_exists('format_idr')) {
function format_idr($val){
return number_format($val , 0, ',', '.');
}
} }

@ -9,7 +9,6 @@ use Illuminate\Support\Facades\Input;
use Maatwebsite\Excel\Facades\Excel; use Maatwebsite\Excel\Facades\Excel;
use App\Exports\SiswaExport; use App\Exports\SiswaExport;
use App\Imports\SiswaImport; use App\Imports\SiswaImport;
use Complex\Exception;
class SiswaController extends Controller class SiswaController extends Controller
{ {
@ -89,7 +88,7 @@ class SiswaController extends Controller
*/ */
public function show(Siswa $siswa) public function show(Siswa $siswa)
{ {
// //TODO: detail siswa with tagihan, lunas, is yatim is free all
} }
/** /**
@ -157,6 +156,7 @@ class SiswaController extends Controller
*/ */
public function destroy(Siswa $siswa) public function destroy(Siswa $siswa)
{ {
//TODO: delete them all ,
return redirect()->route('siswa.index')->with([ return redirect()->route('siswa.index')->with([
'type' => 'danger', 'type' => 'danger',
'msg' => 'Err.., Belum dibikin cuy , cocokin sama tagihan dll dulu' 'msg' => 'Err.., Belum dibikin cuy , cocokin sama tagihan dll dulu'

@ -3,6 +3,11 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\Tagihan;
use App\Models\Kelas;
use App\Models\Siswa;
use App\Models\Role;
use Illuminate\Support\Facades\Redirect;
class TagihanController extends Controller class TagihanController extends Controller
{ {
@ -13,7 +18,8 @@ class TagihanController extends Controller
*/ */
public function index() public function index()
{ {
// $tagihan = Tagihan::orderBy('created_at','desc')->paginate(10);
return view('tagihan.index', ['tagihan' => $tagihan]);
} }
/** /**
@ -23,7 +29,12 @@ class TagihanController extends Controller
*/ */
public function create() public function create()
{ {
// $kelas = Kelas::all();
$siswa = Siswa::where('is_yatim','!=','1')->get();
return view('tagihan.form',[
'kelas' => $kelas,
'siswa' => $siswa
]);
} }
/** /**
@ -34,7 +45,42 @@ class TagihanController extends Controller
*/ */
public function store(Request $request) public function store(Request $request)
{ {
// $request->validate([
'nama' => 'required|max:255',
'jumlah' => 'required|numeric',
'peserta' => 'required|numeric'
]);
$tagihan = Tagihan::make($request->except('kelas_id'));
switch($request->peserta){
case 1: // semua
$tagihan->wajib_semua = 1;
break;
case 2: // hanya kelas
$tagihan->kelas_id = $request->kelas_id;
break;
case 3: // siswa , make role
$tagihan->save();
foreach($request->siswa_id as $siswa_id){
$tagihan->siswa()->save(Siswa::find($siswa_id));
}
break;
default:
return Redirect::back()->withErrors(['Peserta Wajib diisi']);
}
if($tagihan->save()){
return redirect()->route('tagihan.index')->with([
'type' => 'success',
'msg' => 'Item Tagihan ditambahkan'
]);
}else{
return redirect()->route('tagihan.index')->with([
'type' => 'danger',
'msg' => 'Err.., Terjadi Kesalahan'
]);
}
} }
/** /**
@ -54,9 +100,15 @@ class TagihanController extends Controller
* @param int $id * @param int $id
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function edit($id) public function edit(Tagihan $tagihan)
{ {
// $kelas = Kelas::all();
$siswa = Siswa::where('is_yatim','!=','1')->get();
return view('tagihan.form',[
'kelas' => $kelas,
'siswa' => $siswa,
'tagihan' => $tagihan
]);
} }
/** /**
@ -66,9 +118,48 @@ class TagihanController extends Controller
* @param int $id * @param int $id
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function update(Request $request, $id) public function update(Request $request, Tagihan $tagihan)
{ {
// $request->validate([
'nama' => 'required|max:255',
'jumlah' => 'required|numeric',
'peserta' => 'required|numeric'
]);
$tagihan->fill($request->except('kelas_id'));
//remove all related
$tagihan->siswa()->detach();
$tagihan->kelas_id = null;
$tagihan->wajib_semua = null;
switch($request->peserta){
case 1: // semua
$tagihan->wajib_semua = 1;
break;
case 2: // hanya kelas
$tagihan->kelas_id = $request->kelas_id;
break;
case 3: // siswa , make role
foreach($request->siswa_id as $siswa_id){
$tagihan->siswa()->save(Siswa::find($siswa_id));
}
break;
default:
return Redirect::back()->withErrors(['Peserta Wajib diisi']);
}
if($tagihan->save()){
return redirect()->route('tagihan.index')->with([
'type' => 'success',
'msg' => 'Item Tagihan diubah'
]);
}else{
return redirect()->route('tagihan.index')->with([
'type' => 'danger',
'msg' => 'Err.., Terjadi Kesalahan'
]);
}
} }
/** /**
@ -79,6 +170,6 @@ class TagihanController extends Controller
*/ */
public function destroy($id) public function destroy($id)
{ {
// //TODO: work on this if transaksi and keuangan done
} }
} }

@ -0,0 +1,85 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class UserController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$users = App\User::orderBy('created_at','desc')->paginate(5);
return view('users.index', ['users' => $users]);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}

@ -15,7 +15,7 @@ class Tagihan extends Model
'nama', 'nama',
'jumlah', 'jumlah',
'wajib_semua', 'wajib_semua',
'hanya_kelas' 'kelas_id'
]; ];
public function transaksi(){ public function transaksi(){
@ -29,4 +29,12 @@ class Tagihan extends Model
public function siswa(){ public function siswa(){
return $this->belongsToMany('App\Models\Siswa','role'); return $this->belongsToMany('App\Models\Siswa','role');
} }
public function kelas(){
return $this->hasOne('App\Models\Kelas','id','kelas_id');
}
public function getJumlahIdrAttribute(){
return "IDR. ".format_idr($this->jumlah);
}
} }

@ -20,7 +20,8 @@ paths: {
'vector-map-world': 'assets/js/vendors/jquery-jvectormap-world-mill', 'vector-map-world': 'assets/js/vendors/jquery-jvectormap-world-mill',
'circle-progress': 'assets/js/vendors/circle-progress.min', 'circle-progress': 'assets/js/vendors/circle-progress.min',
'datepicker': 'assets/js/vendors/datepicker', 'datepicker': 'assets/js/vendors/datepicker',
'sweetalert' : 'assets/js/vendors/sweetalert.min' 'sweetalert' : 'assets/js/vendors/sweetalert.min',
'select2' : 'assets/js/vendors/select2.min'
} }
}); });
window.tabler = { window.tabler = {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

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

@ -52,7 +52,7 @@
<div class="dropdown"> <div class="dropdown">
<a href="#" class="nav-link pr-0 leading-none" data-toggle="dropdown"> <a href="#" class="nav-link pr-0 leading-none" data-toggle="dropdown">
<span class="avatar" <span class="avatar"
style="background-image: url(favicon.ico)"></span> style="background-image: url({{ asset("favicon.ico")}})"></span>
<span class="ml-2 d-none d-lg-block"> <span class="ml-2 d-none d-lg-block">
<span class="text-default">{{ Auth::user()->name }}</span> <span class="text-default">{{ Auth::user()->name }}</span>
<small class="text-muted d-block mt-1">{{ Auth::user()->role }}</small> <small class="text-muted d-block mt-1">{{ Auth::user()->role }}</small>

@ -24,7 +24,7 @@
</a> </a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a href="#!" class="nav-link"> <a href="{{ route('tagihan.index') }}" class="nav-link {{ set_active(['tagihan.*'], 'active') }}">
<i class="fe fe-box"></i> Tagihan <i class="fe fe-box"></i> Tagihan
</a> </a>
</li> </li>
@ -50,7 +50,7 @@
</li> </li>
@if(Auth::user()->role == 'Admin') @if(Auth::user()->role == 'Admin')
<li class="nav-item"> <li class="nav-item">
<a href="#!" class="nav-link"> <a href="{{ route('user.index') }}" class="nav-link {{ set_active(['user.*'], 'active') }}">
<i class="fe fe-box"></i> Pengguna <i class="fe fe-box"></i> Pengguna
</a> </a>
</li> </li>

@ -25,7 +25,7 @@
<label class="form-label">Kelas</label> <label class="form-label">Kelas</label>
<select id="select-beast" class="form-control custom-select" name="kelas_id"> <select id="select-beast" class="form-control custom-select" name="kelas_id">
@foreach($kelas as $item) @foreach($kelas as $item)
<option value="{{ $item->id }}" {{ isset($siswa) ? ($item->id == $siswa->kelas_id ? 'selected' : '') : '' }}>{{ $item->nama }}</option> <option value="{{ $item->id }}" {{ isset($siswa) ? ($item->id == $siswa->kelas_id ? 'selected' : '') : '' }}>{{ $item->nama }} - {{ isset($item->periode) ? $item->periode->nama : '' }}</option>
@endforeach @endforeach
</select> </select>
</div> </div>

@ -0,0 +1,132 @@
@extends('layouts.app')
@section('site-name','Sistem Informasi SPP')
@section('page-name', (isset($tagihan) ? 'Ubah Tagihan' : 'Tagihan Baru'))
@section('content')
<div class="row">
<div class="col-8">
<form action="{{ (isset($tagihan) ? route('tagihan.update', $tagihan->id) : route('tagihan.create')) }}" method="post" class="card">
<div class="card-header">
<h3 class="card-title">@yield('page-name')</h3>
</div>
<div class="card-body">
@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">Nama</label>
<input type="text" class="form-control" name="nama" placeholder="Nama" value="{{ isset($tagihan) ? $tagihan->nama : old('nama') }}" required>
</div>
<div class="form-group">
<label class="form-label">Jumlah</label>
<input type="number" class="form-control" name="jumlah" value="{{ isset($tagihan) ? $tagihan->jumlah : old('jumlah') }}" required>
</div>
<div class="form-group">
<div class="form-label">Peserta</div>
<div class="custom-switches-stacked">
<label class="custom-switch">
<input type="radio" name="peserta" value="1" class="custom-switch-input" {{ isset($tagihan) ? ($tagihan->wajib_semua == 1 ? 'checked' : '') : 'checked' }}>
<span class="custom-switch-indicator"></span>
<span class="custom-switch-description">Wajib Semua Siswa</span>
</label>
<label class="custom-switch">
<input type="radio" name="peserta" value="2" class="custom-switch-input" {{ isset($tagihan) ? (($tagihan->kelas_id != null) ? 'checked' : '') : '' }}>
<span class="custom-switch-indicator"></span>
<span class="custom-switch-description">Hanya Kelas</span>
</label>
<label class="custom-switch">
<input type="radio" name="peserta" value="3" class="custom-switch-input" {{ isset($tagihan) ? (($tagihan->kelas_id == null && $tagihan->wajib_semua == null) ? 'checked' : '') : '' }}>
<span class="custom-switch-indicator"></span>
<span class="custom-switch-description">Hanya Siswa</span>
</label>
</div>
</div>
<div class="form-group" style="display: {{ isset($tagihan) ? (($tagihan->kelas_id != null) ? 'block' : 'none') : 'none' }}" id="form-kelas">
<label class="form-label">Kelas</label>
<select class="form-control" name="kelas_id" id="hanya-kelas">
@foreach($kelas as $item)
<option value="{{ $item->id }}" {{ isset($tagihan) ? (($tagihan->kelas_id == $item->id) ? 'selected' : '') : '' }}>
{{ $item->nama }} - {{ isset($item->periode) ? $item->periode->nama : '' }}
</option>
@endforeach
</select>
</div>
<div class="form-group" style="display: {{ isset($tagihan) ? (($tagihan->kelas_id == null && $tagihan->wajib_semua == null) ? 'block' : 'none') : 'none' }}" id="form-siswa">
<label class="form-label">Siswa</label>
<select class="form-control" name="siswa_id[]" id="hanya-siswa" multiple>
@foreach($siswa as $item)
<option value="{{ $item->id }}" {{ isset($tagihan) ? (($tagihan->wajib_semua == null && $tagihan->kelas_id == null) ? (in_array($item->id, $tagihan->siswa->pluck('id')->toArray()) ? 'selected' : '') : '') : '' }}>
{{ $item->nama }} - {{ $item->kelas->nama }} {{ isset($item->kelas->periode) ? "(". $item->kelas->periode->nama .")" : ''}}
</option>
@endforeach
</select>
</div>
</div>
</div>
</div>
<div class="card-footer text-right">
<div class="d-flex">
<a href="{{ url()->previous() }}" class="btn btn-link">Batal</a>
<button type="submit" class="btn btn-primary ml-auto">Simpan</button>
</div>
</div>
</form>
</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', 'selectize','select2'], function ($, selectize) {
$(document).ready(function () {
$('#select-beast').selectize({});
});
$('#hanya-kelas').select2({
placeholder: "Pilih Kelas",
});
$('#hanya-siswa').select2({
placeholder: "Pilih Siswa",
});
$('.custom-switch-input').change(function(){
if(this.value == 2){
$('#form-kelas').show()
$('#form-siswa').hide()
$('#hanya-kelas').prop('required', true)
$('#hanya-siswa').prop('required', false)
}else if(this.value == 3){
$('#form-kelas').hide()
$('#form-siswa').show()
$('#hanya-kelas').prop('required', false)
$('#hanya-siswa').prop('required', true)
}else{
$('#form-kelas').hide()
$('#form-siswa').hide()
$('#hanya-kelas').prop('required', false)
$('#hanya-siswa').prop('required', false)
}
})
});
</script>
@endsection

@ -0,0 +1,114 @@
@extends('layouts.app')
@section('site-name','Sistem Informasi SPP')
@section('page-name','Tagihan')
@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">@yield('page-name')</h3>
<a href="{{ route('tagihan.create') }}" class="btn btn-outline-primary btn-sm ml-5">Tambah Tagihan</a>
</div>
@if(session()->has('msg'))
<div class="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="table-responsive">
<table class="table card-table table-hover table-vcenter text-nowrap">
<thead>
<tr>
<th class="w-1">No.</th>
<th>Nama</th>
<th>Jumlah</th>
<th>Peserta</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach ($tagihan as $index => $item)
<tr>
<td><span class="text-muted">{{ $index+1 }}</span></td>
<td>
{{ $item->nama }}
</td>
<td>
{{ $item->jumlah_idr }}
</td>
<td>
@if($item->wajib_semua != null)
<p>Wajib Semua</p>
@elseif($item->kelas_id != null)
<p>{{ $item->kelas->nama }} {{ isset($item->kelas->periode) ? ' - '.$item->kelas->periode->nama : '' }}</p>
@elseif($item->wajib_semua == null && $item->kelas_id == null)
@foreach ($item->role as $role)
{{ $role->siswa->nama }}{{ " (".$role->siswa->kelas->nama.")" }},
@endforeach
@endif
</td>
<td class="text-center">
<a class="icon" href="{{ route('tagihan.edit', $item->id) }}" title="edit item">
<i class="fe fe-edit"></i>
</a>
<a class="icon btn-delete" href="#!" data-id="{{ $item->id }}" title="delete item">
<i class="fe fe-trash"></i>
</a>
<form action="{{ route('tagihan.destroy', $item->id) }}" method="POST" id="form-{{ $item->id }}">
@csrf
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="card-footer">
<div class="d-flex">
<div class="ml-auto mb-0">
{{ $tagihan->links() }}
</div>
</div>
</div>
</div>
</div>
</div>
@endsection
@section('js')
<script>
require(['jquery', 'sweetalert'], function ($, sweetalert) {
$(document).ready(function () {
$(document).on('click','.btn-delete', function(){
formid = $(this).attr('data-id');
swal({
title: 'Anda yakin ingin menghapus?',
text: 'tagihan yang dihapus tidak dapat dikembalikan',
dangerMode: true,
buttons: {
cancel: true,
confirm: true,
},
}).then((result) => {
if (result) {
$('#form-' + formid).submit();
}
})
})
});
});
</script>
@endsection

@ -42,6 +42,22 @@ Route::middleware(['auth:web'])->group(function(){
Route::get('kelas/{kelas}/ubah', 'KelasController@edit')->name('kelas.edit'); Route::get('kelas/{kelas}/ubah', 'KelasController@edit')->name('kelas.edit');
Route::post('kelas/{kelas}/ubah','KelasController@update')->name('kelas.update'); Route::post('kelas/{kelas}/ubah','KelasController@update')->name('kelas.update');
Route::post('kelas/{kelas}/hapus', 'KelasController@destroy')->name('kelas.destroy'); Route::post('kelas/{kelas}/hapus', 'KelasController@destroy')->name('kelas.destroy');
//Tagihan
Route::get('tagihan','TagihanController@index')->name('tagihan.index');
Route::get('tambah-tagihan','TagihanController@create')->name('tagihan.create');
Route::post('tambah-tagihan', 'TagihanController@store')->name('tagihan.store');
Route::get('tagihan/{tagihan}/ubah', 'TagihanController@edit')->name('tagihan.edit');
Route::post('tagihan/{tagihan}/ubah','TagihanController@update')->name('tagihan.update');
Route::post('tagihan/{tagihan}/hapus', 'TagihanController@destroy')->name('tagihan.destroy');
//Users
Route::get('user','UserController@index')->name('user.index');
Route::get('tambah-user','UserController@create')->name('user.create');
Route::post('tambah-user', 'UserController@store')->name('user.store');
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');
}); });

Loading…
Cancel
Save