https://developers.google.com/chart/interactive/docs/gallery/piechart
Reff: https://getbootstrap.com/docs/4.0/components/buttons/
https://getbootstrap.com/docs/4.0/components/dropdowns/
style='width: 50px;'
<button type="button" class="btn btn-primary">Primary</button>
<button type="button" class="btn btn-secondary">Secondary</button>
<button type="button" class="btn btn-success">Success</button>
<button type="button" class="btn btn-danger">Danger</button>
<button type="button" class="btn btn-warning">Warning</button>
<button type="button" class="btn btn-info">Info</button>
<button type="button" class="btn btn-light">Light</button>
<button type="button" class="btn btn-dark">Dark</button>
<button type="button" class="btn btn-link">Link</button>
{{ asset('images/'.$data->foto) }}
{{ route('peserta.create') }}
{{ route('peserta.edit', $data->id_peserta) }}
{{ route('peserta.destroy', $data->id_peserta) }}
@if (Auth::check() &&
(Auth::user()->level == 'admin') || (Auth::user()->level == 'Admin'))
@if($sessi->status == 'Aktif')
checked
@endif
sejajar model, buat helpers.php
pada composer.json:
,"files": [
"app/helpers.php"
]
ketik di cli path:composer dump-autoload
pada app.php
return [
'name' => env('APP_NAME', 'Laravel'),
'periode' => env('APP_TA', 'Februari 2022'),
'init' => env('APP_CAMP', 'Tumbuh Kembang Anak Superkidz'),
'web' => env('APP_SITE', 'tka-superkidz.co.id'),
...];
{{ config('app.init') }}
<?php
$listuser = User::where('level', 'LIKE', "pasien")->get();
//https://drive.google.com/file/d/1oWBXdZTB4PdBMt8FX-3vWMJyj_L_yA5t/view?usp=sharing
//use Illuminate\Support\Facades\DB
//$id_ns = DB::select("select `id_ns` from `sessi` where `id_matkul` = '$id_matkul' and `sessi`='$sessi'");
//$results = DB::table('sessi')->where('id_matkul', '$id_matkul')->get();
$ardata = Sessi::where('id_matkul', $id_matkul)->where('sessi', $sessi)->first();
if($ardata)
$id_ns=$ardata->id_ns;
echo $id_ns;
public function dindex(){
$id_dsn=Auth :: user()->id;
$batas = 100;
$sessi = Sessi::where('id', $id_dsn)->orderBy('id_ns', 'asc')->paginate($batas);
$no = $batas * ($sessi->currentPage() - 1);
$sessi0 = Sessi::select('id_matkul')->where('id', $id_dsn)->distinct()->get();
return view('admin.sessi.dindex', compact('sessi0','sessi', 'no'));
}
if (Auth::check() && (Auth::user()->level == 'Dosen') ){
return redirect('/dsessi')->with('pesan', 'Data Pertemuan/Sessi '.$ke.' berhasil disimpan');
}
else{
return redirect('/sessi')->with('pesan', 'Data Pertemuan/Sessi '.$ke.' berhasil disimpan');
}
$result = User::where('columnName', 'LIKE', "%$value%")->get();
$sessi->id = Auth :: user()->id;
Auth::user()->level
Auth::user()->name
//https://laravel.com/docs/8.x/queries
//aliases:
'App' => Illuminate\Support\Facades\App::class,
'DB' => Illuminate\Support\Facades\DB::class,
'View' => Illuminate\Support\Facades\View::class,
'Request' => Illuminate\Support\Facades\Request::class,
'Route' => Illuminate\Support\Facades\Route::class,
'Session' => Illuminate\Support\Facades\Session::class,
'Image' => Intervention\Image\Facades\Image::class,
//$ardata = Sessi::where('id_matkul', $id_matkul)->where('sessi', $sessi)->first();
//if($ardata)
//$id_ns0=$ardata->id_ns;
//$sql="SELECT `id_ns` FROM `sessi` where `id_matkul`='$id_matkul' and `sessi`='$sessi'";
//$ardata= DB::select($sql);
//$mdata= json_decode( json_encode($ardata), true);
//var_dump($mdata);
$ardata = DB::table('sessi')->where([
['id_matkul', '=', $id_matkul],
['sessi', '=', $sessi],
])->get();//pluck('id_ns');//->first();//->get();
$id_ns0=1;
foreach ($ardata as $message) {
$id_ns0= $message->id_ns;
}
$jumlah = Soal::where('id_ns', $id_ns0)->count();
$users = DB::table('users')->count();
$price = DB::table('orders')->max('price');
$users = DB::table('users')
->where('votes', '>', 100)
->orWhere('name', 'John')
->get();
$users = DB::table('users')
->where('votes', '>', 100)
->orWhere(function($query) {
$query->where('name', 'Abigail')
->where('votes', '>', 50);
})
->get();
select * from users where votes > 100 or (name = 'Abigail' and votes > 50)
$users = DB::table('users')->where([
['status', '=', '1'],
['subscribed', '<>', '1'],
])->get();
$users = DB::table('users')->where('votes', 100)->get();
$users = DB::table('users')
->where('votes', '>=', 100)
->get();
$users = DB::table('users')
->where('votes', '<>', 100)
->get();
$users = DB::table('users')
->where('name', 'like', 'T%')
->get();
$users = DB::table('users')
->where('votes', '=', 100)
->where('age', '>', 35)
->get();
$users = DB::table('users')
->orderBy('name', 'desc')
->orderBy('email', 'asc')
->get();
DB::table('usersa')->truncate();
$deleted = DB::table('usersa')->delete();
$deleted = DB::table('usersa')->where('votes', '>', 100)->delete();
//$matkul = Matkul::all();
//return view('welcome', compact('matkul'));
//return view('home');
//---------------
//$users = DB::table('users')->distinct()->get();
//$kat="ekonomi";
//$matkul= DB::select("select * from `matkul`,`soal` where `matkul`.`id_matkul`= `soal`.`id_matkul` and `matkul`.`nama_matkul` like '$kat'");
//return view('lat', ['matkul' => $matkul]);
public function edit($id){
$hasil = Hasil::find($id);
$listuser = User::all();
$listsessi = Sessi::all();
return view('admin.hasil.edit', compact('hasil','listuser', 'listsessi'));
}
//Model Soal
public function sessis(){
return $this->belongsTo('App\Sessi', 'id_ns', 'id_ns');
}
//SoalController
public function index(){
$batas = 4;
$soal = Soal::orderBy('id_soal', 'desc')->paginate($batas);
$no = $batas * ($soal->currentPage() - 1);
return view('admin.soal.index', compact('soal', 'no'));
}
?>
<a href="{{ route('peserta.create') }}"></i> Tambah</a>
@foreach ($soal as $data)
<?php
$soal=$data->soal;
$deskripsi=$data->deskripsi;
$jawaban=$data->jawaban;
$keterangan=$data->keterangan;
//===========
$sessiPelajaran=$data->sessis->sessi;
use App\Matkul;
$id_matkul=$data->sessis->id_matkul;
$list = Matkul::find($id_matkul);
$nama_matkul= $list->nama_matkul;
?>
<tr>
<td>{{ ++$no }}</td>
<td><img src="{{ asset('images/'.$data->foto) }}" alt="{{ asset('images/'.$data->foto) }}" style="width: 100px">
</td>
<td>{{ $nama_matkul }}</td>
<td>{{ $data->id_mhs }}</td>
</tr>
<form action="{{ route('peserta.destroy', $data->id_peserta) }}" method="post">@csrf
<a href="{{ route('peserta.edit', $data->id_peserta) }}">Edit</a>
<button class="btn btn-danger" onClick="return confirm('Yakin mau dihapus?')">
<i class="fa fa-times"></i> Hapus</button>
</form>
@endforeach
Matkul model
<?php
public function photos(){
return $this->hasMany('App\Soal', 'id_matkul', 'id_matkul');
}
public function getMatkul(){
return $this->belongsTo('App\Sessi', 'id_matkul', 'id_matkul');
}
?>
HomeController
<?php
use App\Matkul;
public function index(){
$matkul = Matkul::all();
return view('home', compact('matkul'));
//return view('home');
}
?>
View home.php
@foreach ($matkul as $data)
<div class="col-md-4">
<a href="{{ route('soal.foto', $data->link_matkul) }}">
<img src="{{ asset('images/'.$data->gambar) }}" style="width:200px; height:150px">
<p>
<h5>{{ $data->nama_matkul }}</h5></a>
({{ $data->photos->count() }} Foto)
</p>
</div>
@endforeach
##############################################################################
In config/database.php
Change 'strict' => true To 'strict' => false and clear the cache
agar sql group by support
<?php
use Illuminate\Support\Facades\DB;
$users = DB::select('select * from soal');
foreach ($users as $user) {
echo $user->soal."<br>";
}
//Model::select()->where()->distinct()->get()
//Model::select()->where()->groupBy()->get() //etc....
//DB::insert('insert into users (id, name) values (?, ?)', [1, 'Marc']);
//$affected = DB::update('update users set votes = 100 where name = ?',['LP@M']);
//$deleted = DB::delete('delete from users');
//$results = DB::select('select * from users where id = :id', ['id' => 1])
//DB::statement('drop table users');
//$user = DB::table('users')->where('name', 'John')->first();
//return $user->email;
//$email = DB::table('users')->where('name', 'John')->value('email');
//$user = DB::table('users')->find(3);
//SINGLE COLUMN
//$titles = DB::table('users')->pluck('title');
//foreach ($titles as $title) {
// echo $title;
//}
//$titles = DB::table('users')->pluck('title', 'name');
//foreach ($titles as $name => $title) {
// echo $title;
//}
//CARA LAIN:
//DB::table('users')->orderBy('id')->chunk(100, function ($users) {
// foreach ($users as $user) {
//
//}});
//$users = DB::table('users')->count();
//$price = DB::table('orders')->max('price');
/*
if (DB::table('orders')->where('finalized', 1)->exists()) {
// ...
}
if (DB::table('orders')->where('finalized', 1)->doesntExist()) {
// ...
}
*/
/*
$users = DB::table('users')
->select('name', 'email as user_email')
->get();
$users = DB::table('users')->distinct()->get();
$users = DB::table('users')
->select(DB::raw('count(*) as user_count, status'))
->where('status', '<>', 1)
->groupBy('status')
->get();
$users = DB::table('users')
->join('contacts', 'users.id', '=', 'contacts.user_id')
->join('orders', 'users.id', '=', 'orders.user_id')
->select('users.*', 'contacts.phone', 'orders.price')
->get();
$users = DB::table('users')
->leftJoin('posts', 'users.id', '=', 'posts.user_id')
->get();
$users = DB::table('users')
->rightJoin('posts', 'users.id', '=', 'posts.user_id')
->get();
$sizes = DB::table('sizes')
->crossJoin('colors')
->get();
DB::table('users')
->join('contacts', function ($join) {
$join->on('users.id', '=', 'contacts.user_id')->orOn(...);
})
->get();
$latestPosts = DB::table('posts')
->select('user_id', DB::raw('MAX(created_at) as last_post_created_at'))
->where('is_published', true)
->groupBy('user_id');
$users = DB::table('users')
->joinSub($latestPosts, 'latest_posts', function ($join) {
$join->on('users.id', '=', 'latest_posts.user_id');
})->get();
$first = DB::table('users')
->whereNull('first_name');
$users = DB::table('users')
->whereNull('last_name')
->union($first)
->get();
$users = DB::table('users')
->where('votes', '=', 100)
->where('age', '>', 35)
->get();
$users = DB::table('users')
->where('votes', '>=', 100)
->get();
$users = DB::table('users')
->where('votes', '<>', 100)
->get();
$users = DB::table('users')
->where('name', 'like', 'T%')
->get();
$users = DB::table('users')->where([
['status', '=', '1'],
['subscribed', '<>', '1'],
])->get();
$users = DB::table('users')
->where('votes', '>', 100)
->orWhere('name', 'John')
->get();
$users = DB::table('users')
->where('votes', '>', 100)
->orWhere(function($query) {
$query->where('name', 'Abigail')
->where('votes', '>', 50);
})
->get();
=select * from users where votes > 100 or (name = 'Abigail' and votes > 50)
$users = DB::table('users')
->whereBetween('votes', [1, 100])
->get();
$users = DB::table('users')
->whereNotBetween('votes', [1, 100])
->get();
$users = DB::table('users')
->whereIn('id', [1, 2, 3])
->get();
$users = DB::table('users')
->whereNotIn('id', [1, 2, 3])
->get();
$users = DB::table('users')
->whereNull('updated_at')
->get();
$users = DB::table('users')
->whereNotNull('updated_at')
->get();
$users = DB::table('users')
->whereDate('created_at', '2016-12-31')
->get();
$users = DB::table('users')
->whereMonth('created_at', '12')
->get();
$users = DB::table('users')
->whereDay('created_at', '31')
->get();
$users = DB::table('users')
->whereYear('created_at', '2016')
->get();
$users = DB::table('users')
->whereTime('created_at', '=', '11:20:45')
->get();
//EQUALS
$users = DB::table('users')
->whereColumn('first_name', 'last_name')
->get();
$users = DB::table('users')
->whereColumn('updated_at', '>', 'created_at')
->get();
$users = DB::table('users')
->whereColumn([
['first_name', '=', 'last_name'],
['updated_at', '>', 'created_at'],
])->get();
$users = DB::table('users')
->where('name', '=', 'John')
->where(function ($query) {
$query->where('votes', '>', 100)
->orWhere('title', '=', 'Admin');
})
->get();
//select * from users where name = 'John' and (votes > 100 or title = 'Admin')
$users = DB::table('users')
->orderBy('name', 'desc')
->orderBy('email', 'asc')
->get();
$user = DB::table('users')
->latest()
->first();
$users = DB::table('users')
->groupBy('account_id')
->having('account_id', '>', 100)
->get();
$report = DB::table('orders')
->selectRaw('count(id) as number_of_orders, customer_id')
->groupBy('customer_id')
->havingBetween('number_of_orders', [5, 15])
->get();
$users = DB::table('users')
->groupBy('first_name', 'status')
->having('account_id', '>', 100)
->get();
$users = DB::table('users')
->offset(10)
->limit(5)
->get();
DB::table('users')->insert([
'email' => 'kayla@example.com',
'votes' => 0
]);
DB::table('users')->insert([
['email' => 'picard@example.com', 'votes' => 0],
['email' => 'janeway@example.com', 'votes' => 0],
]);
DB::table('users')->insertOrIgnore([
['id' => 1, 'email' => 'sisko@example.com'],
['id' => 2, 'email' => 'archer@example.com'],
]);
//AI
$id = DB::table('users')->insertGetId(
['email' => 'john@example.com', 'votes' => 0]
);
$affected = DB::table('users')
->where('id', 1)
->update(['votes' => 1]);
DB::table('users')
->updateOrInsert(
['email' => 'john@example.com', 'name' => 'John'],
['votes' => '2']
);
DB::table('users')->increment('votes');
DB::table('users')->increment('votes', 5);
DB::table('users')->decrement('votes');
DB::table('users')->decrement('votes', 5);
DB::table('users')->delete();
DB::table('users')->where('votes', '>', 100)->delete();
//https://laravel.com/docs/8.x/queries
*/
?>
<?php
//$username=Session::get('key');
//https://laravel.com/docs/8.x/queries#aggregates
//https://blog.quickadminpanel.com/5-ways-to-use-raw-database-queries-in-laravel
/*
Selamat Datang {{ Auth::user()->level }} : {{ Auth::user()->name }}
@if (session('status'))
<div class="alert alert-succes s" role="alert">
{{ session('status') }}
</div>
@endif
@extends('layouts.app')
@section('content')
*/
function getOngkir($kode){
$rp=20000;
if($kode=="Luar Jabodetabek"){$rp=30000;}
return $rp;
}
function getKategori($kode){
$hasil=\App\Kategori::find($kode)->value('nama_kategori');//BEST
return $hasil;
}
function getNominalJual($kode){
$results = DB::table('penjualan')->select('id_pelanggan','total','wilayah')->where('id_penjualan','=', $kode)->first();
$pelanggan=getPelanggan2($results->id_pelanggan);
$total=RP($results->total);
$wilayah=$results->wilayah;
return "$pelanggan $wilayah ->".$total;
}
function getListJual($kode){
$sql= "SELECT `jdetail`.`id_barang`,`jdetail`.`jumlah`,`jdetail`.`subtotal`,`penjualan`.`ongkir` FROM `penjualan`,`jdetail` WHERE `penjualan`.`id_penjualan`=`jdetail`.`id_penjualan` and `penjualan`.`id_penjualan`= '$kode'";
$results = DB::select($sql);
$gab="";
$total=0;
$ongkir=0;
foreach($results as $i){
$id_barang= $i->id_barang;
$jumlah= $i->jumlah;
$ongkir= $i->ongkir;
$subtotal= $i->subtotal;
$nb=getNamaBarang($id_barang);
$gab.="$nb ($jumlah),";
$total+=$subtotal;
}
$gab.="Total:".RP($total).",Ongkir:".RP($ongkir);
return $gab;
}
function getTotal($kode){
$sql= "SELECT `jdetail`.`subtotal` FROM `penjualan`,`jdetail` WHERE `penjualan`.`id_penjualan`=`jdetail`.`id_penjualan` and `penjualan`.`id_penjualan`= '$kode'";
$results = DB::select($sql);
$total=0;
foreach($results as $i){
$subtotal= $i->subtotal;
$total+=$subtotal;
}
return $total;
}
function getListMasuk($kode){
$sql= "SELECT `mdetail`.`id_barang`,`mdetail`.`jumlah`,`mdetail`.`subtotal` FROM `pemasukan`,`mdetail` WHERE `pemasukan`.`id_pemasukan`=`mdetail`.`id_pemasukan` and `pemasukan`.`id_pemasukan`= '$kode'";
$results = DB::select($sql);
$gab="";
$total=0;
foreach($results as $i){
$id_barang= $i->id_barang;
$jumlah= $i->jumlah;
$subtotal= $i->subtotal;
$nb=getNamaBarang($id_barang);
$gab.="$nb ($jumlah),";
$total+=$subtotal;
}
$gab.="Total:".RP($total);
return $gab;
}
function getPelanggan($kode){
//$hasil=\App\Pelanggan::find($kode)->value('nama_pelanggan');//BEST
$results = DB::select('select `nama_pelanggan` from `pelanggan` where `id_pelanggan` = ?', [$kode]);
$hasil=$results[0]->nama_pelanggan;
return $hasil;
}
function getPelanggan2($kode){
$results = DB::select('select `nama_pelanggan` from `pelanggan` where `id_pelanggan` = ?', [$kode]);
$hasil=$results[0]->nama_pelanggan;
return $hasil;
}
function getNamaBarang($kode){
// $pesan = Pesan::orderBy('id_pesan', 'desc')->get();
//$mdetail = Mdetail::all()->where('id_pemasukan',$id); //One to Many
//ModelName::find(id)->value('column_name');
$hasil=\App\Barang::find($kode)->value('nama_barang');//BEST
//$results = DB::select('select `nama_barang`,`stok` from `barang` where `id_barang` = ?', [$kode]);
//$hasil=$results[0]->nama_barang;
//$sql= "SELECT `nama_barang` FROM `barang` WHERE `id_barang`= '".$kode."'";
//$results = DB::select($sql);
//$hasil=$results[0]->nama_barang;
//$results = DB::table('barang')->select('nama_barang','stok')->where('id_barang', '=', $kode)->orderBy('id_barang','asc')->get();//ARRAY
//$hasil=$results[0]->nama_barang;
//foreach($results as $i){echo $i->user_id;}
//$results = DB::table('barang')->select('nama_barang')->where('id_barang','=', $kode)->first();
//$hasil=$results->nama_barang;
//$results = DB::table('barang')->select('nama_barang')->where('id_barang', $kode)->first();//first=return no array
//$hasil=$results->nama_barang;
//$hasil=DB::table('barang')->where('id_barang', $kode)->value('nama_barang');//L5
//$hasil=DB::table('barang')->where('id_barang', $kode)->pluck('nama_barang');//L4
//$hasil = DB::table('barang')->where('id_barang', $kode)->select('nama_barang')->pluck('nama_barang')->first();
//$hasil=DB::table('barang')->where('id_barang', $kode)->orderBy('id_barang', 'desc')->value('nama_barang');
//$hasil =\App\Barang::where('id_barang', $kode)->first()->nama_barang;
//$hasil = \App\Barang::where('id_barang',$kode)->value('nama_barang');
return $hasil;
}
//exe
//DB::statement('UPDATE users SET role_id = 1 WHERE role_id IS NULL AND YEAR(created_at) > 2020');
//DB::statement('DROP TABLE users');
//DB::statement('ALTER TABLE projects AUTO_INCREMENT=123');
//LIBRARY SQL //RAW
//\App\User::whereIn('mobile',['971700000', '965000000'])->select('id')->pluck('id')->all();
/*
$users = DB::table('users')
->selectRaw('count(*) as user_count, status')
->where('status', '<>', 1)
->groupBy('status')
->get();
$products = DB::table('products')
->leftjoin('category','category.product_id','=','products.id')
->selectRaw('COUNT(*) as nbr', 'products.*')
->groupBy('products.id')
->get();
$salaries = DB::table('salaries')
->selectRaw('companies.name as company_name, avg(salary) as avg_salary, count(*) as people_count')
->join('companies', 'salaries.company_id', '=', 'companies.id')
->groupBy('companies.id')
->orderByDesc('avg_salary')
->get();
$results = User::selectRaw('YEAR(birth_date) as year, COUNT(id) as amount')
->groupByRaw('YEAR(birth_date)')
->havingRaw('YEAR(birth_date) > 2000')
->orderByRaw('YEAR(birth_date)')
->get();
$products = Product::select('id', 'name')
->selectRaw('price - discount_price AS discount')
->get();
$users = DB::table('users')
->select('name', 'surname')
->selectRaw("(CASE WHEN (gender = 1) THEN 'M' ELSE 'F' END) as gender_text")
->get();
*/
/*
https://laravel.com/docs/8.x/requests
use Illuminate\Http\Request;
public function store(Request $request){
$name = $request->input('name');
$uri = $request->path();
$url = $request->url();
$urlWithQueryString = $request->fullUrl();
$request->fullUrlWithQuery(['type' => 'phone']);
$method = $request->method();
if ($request->isMethod('post')) {}
$value = $request->header('X-Header-Name');
$value = $request->header('X-Header-Name', 'default');
if ($request->hasHeader('X-Header-Name')) {}
$token = $request->bearerToken();
$ipAddress = $request->ip();
$contentTypes = $request->getAcceptableContentTypes();
if ($request->accepts(['text/html', 'application/json'])) {}
$preferred = $request->prefers(['text/html', 'application/json']);
if ($request->expectsJson()) {}
$input = $request->all();
$input = $request->collect();
$request->collect('users')->each(function ($user) {});
$name = $request->input('name');
$name = $request->input('name', 'Sally');
$name = $request->input('products.0.name');
$names = $request->input('products.*.name');
$input = $request->input();
$name = $request->query('name');
$name = $request->query('name', 'Helen');
$query = $request->query();
$name = $request->input('user.name');
$archived = $request->boolean('archived');
$name = $request->name;
$input = $request->only(['username', 'password']);
$input = $request->only('username', 'password');
$input = $request->except(['credit_card']);
$input = $request->except('credit_card');
if ($request->has('name')) {}
if ($request->has(['name', 'email'])) {}
$request->whenHas('name', function ($input) {});
if ($request->hasAny(['name', 'email'])) {}
if ($request->filled('name')) {}
$request->whenFilled('name', function ($input) {});
if ($request->missing('name')) {}
$request->flash();
$request->flashOnly(['username', 'email']);
$request->flashExcept('password');
return redirect('form')->withInput();
return redirect()->route('user.create')->withInput();
return redirect('form')->withInput(
$request->except('password')
);
$username = $request->old('username');
<input type="text" name="username" value="{{ old('username') }}">
$value = $request->cookie('name');
$file = $request->file('photo');
$file = $request->photo;
if ($request->hasFile('photo')) {}
if ($request->file('photo')->isValid()) {}
$path = $request->photo->path();
$extension = $request->photo->extension();
$path = $request->photo->store('images');
$path = $request->photo->store('images', 's3');
$path = $request->photo->storeAs('images', 'filename.jpg');
$path = $request->photo->storeAs('images', 'filename.jpg', 's3');
https://laravel.com/docs/8.x/requests
}//public
*/
function RP($angka){
$hasil = number_format($angka,0, ',' , '.');
return $hasil.";";
}
function terbilang($i){
$huruf = array("", "Satu", "Dua", "Tiga", "Empat", "Lima", "Enam", "Tujuh", "Delapan", "Sembilan", "Sepuluh", "Sebelas");
if ($i < 12) return " " . $huruf[$i];
elseif ($i < 20) return terbilang($i - 10) . " Belas";
elseif ($i < 100) return terbilang($i / 10) . " Puluh" . terbilang($i % 10);
elseif ($i < 200) return " Seratus" . terbilang($i - 100);
elseif ($i < 1000) return terbilang($i / 100) . " Ratus" . terbilang($i % 100);
elseif ($i < 2000) return " Seribu" . terbilang($i - 1000);
elseif ($i < 1000000) return terbilang($i / 1000) . " Ribu" . terbilang($i % 1000);
elseif ($i < 1000000000) return terbilang($i / 1000000) . " Juta" . terbilang($i % 1000000);
}
?>
<?php function RP2($rupiah){return number_format($rupiah,"2",",",".");}?>
<?php
function WKT($sekarang){
if($sekarang=="0000-00-00"){$sekarang=date("Y-m-d");}
$tanggal = substr($sekarang,8,2)+0;
$bulan = substr($sekarang,5,2);
$tahun = substr($sekarang,0,4);
$judul_bln=array(1=> "Januari", "Februari", "Maret", "April", "Mei","Juni", "Juli", "Agustus", "September","Oktober", "November", "Desember");
$wk=$tanggal." ".$judul_bln[(int)$bulan]." ".$tahun;
return $wk;
}
?>
<?php
function WKTP($sekarang){
$tanggal = substr($sekarang,8,2)+0;
$bulan = substr($sekarang,5,2);
$tahun = substr($sekarang,2,2);
$judul_bln=array(1=> "Jan", "Feb", "Mar", "Apr", "Mei","Jun", "Jul", "Agu", "Sep","Okt", "Nov", "Des");
$wk=$tanggal." ".$judul_bln[(int)$bulan]."'".$tahun;
return $wk;
}
?>
<?php
function BAL($tanggal){
$arr=explode(" ",$tanggal);
if($arr[1]=="Januari"||$arr[1]=="January"){$bul="01";}
else if($arr[1]=="Februari"||$arr[1]=="February"){$bul="02";}
else if($arr[1]=="Maret"||$arr[1]=="March"){$bul="03";}
else if($arr[1]=="April"){$bul="04";}
else if($arr[1]=="Mei"||$arr[1]=="May"){$bul="05";}
else if($arr[1]=="Juni"||$arr[1]=="June"){$bul="06";}
else if($arr[1]=="Juli"||$arr[1]=="July"){$bul="07";}
else if($arr[1]=="Agustus"||$arr[1]=="August"){$bul="08";}
else if($arr[1]=="September"){$bul="09";}
else if($arr[1]=="Oktober"||$arr[1]=="October"){$bul="10";}
else if($arr[1]=="November"){$bul="11";}
else if($arr[1]=="Nopember"){$bul="11";}
else if($arr[1]=="Desember"||$arr[1]=="December"){$bul="12";}
return "$arr[2]-$bul-$arr[0]";
}
?>
<?php
function BALP($tanggal){
$arr=split(" ",$tanggal);
if($arr[1]=="Jan"){$bul="01";}
else if($arr[1]=="Feb"){$bul="02";}
else if($arr[1]=="Mar"){$bul="03";}
else if($arr[1]=="Apr"){$bul="04";}
else if($arr[1]=="Mei"){$bul="05";}
else if($arr[1]=="Jun"){$bul="06";}
else if($arr[1]=="Jul"){$bul="07";}
else if($arr[1]=="Agu"){$bul="08";}
else if($arr[1]=="Sep"){$bul="09";}
else if($arr[1]=="Okt"){$bul="10";}
else if($arr[1]=="Nov"){$bul="11";}
else if($arr[1]=="Nop"){$bul="11";}
else if($arr[1]=="Des"){$bul="12";}
return "$arr[2]-$bul-$arr[0]";
}
?>
Penjualan Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Session;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use App\Penjualan;
use App\Pelanggan;
use DB;
use Auth;
use File;
class PenjualanController extends Controller
{
public function __construct(){
$this->middleware('auth');
}
public function index(){
$no = 0;
$penjualan = Penjualan::orderBy('id_penjualan', 'desc')->get();
return view('admin.penjualan.index', compact('penjualan', 'no'));
}
public function _index(){
$id_pelanggan=Auth::user()->rkey ;
$no = 0;
// $penjualan = Penjualan::orderBy('id_penjualan', 'desc')->get();
$penjualan = DB::select("select * from `pelanggan`,`penjualan` where `penjualan`.`id_pelanggan`='$id_pelanggan' and `penjualan`.`id_pelanggan`=`pelanggan`.`id_pelanggan` order by `penjualan`.`id_penjualan` desc");
return view('admin.penjualan._index', compact('penjualan', 'no'));
}
public function create(){
if(Auth::user()->level=="Pelanggan"){
return view('admin.penjualan._create');
}
else{
$pelanggan = Pelanggan::all();
return view('admin.penjualan.create', compact('pelanggan'));
}
}
public function store(Request $request){
$this->validate($request,[
'id_pelanggan'=>'required'
]);
$penjualan = New Penjualan;
$wilayah=$request->wilayah;
$penjualan->tanggal = date("Y-m-d");//$request->tanggal;
$penjualan->jam = date("H:i:s");//$request->jam;
$penjualan->id_pelanggan = $request->id_pelanggan;
$penjualan->alamat_pengiriman = $request->alamat_pengiriman;
$penjualan->tagihan =0;// $request->tagihan;
$ongkir=getOngkir($wilayah);
$penjualan->ongkir =$ongkir;// $request->ongkir;
$penjualan->total = $ongkir;//$request->total;
$penjualan->status = $request->status;
$penjualan->keterangan = $request->keterangan;
$penjualan->wilayah = $wilayah;
$penjualan->save();
return redirect('/penjualan')->with('pesan', 'Data Penjualan berhasil disimpan');
}
public function _storeOrder(Request $request){
if(session()->has('IDORDER')){
$id_penjualan= Session::get('IDORDER');
$jdetail = New Jdetail;
$id_barang=$request->id_barang;
$jumlah = $request->jumlah;
$barang = Barang::find($id_barang);
$harga=$barang->harga;
$nama_barang=$barang->nama_barang;
$jdetail->id_penjualan = $id_penjualan;
$jdetail->id_barang = $id_barang;
$jdetail->jumlah =$jumlah;
$jdetail->harga = $harga;
$jdetail->subtotal =$jumlah * $harga;
$jdetail->catatan = $request->catatan;
$jdetail->save();
$barang->stok = $barang->stok-$jumlah;
$barang->update();
$penjualan = Penjualan::find($id_penjualan);
$total=getTotal($id_penjualan);
$penjualan->tagihan =$total;
$penjualan->total =$penjualan->ongkir+$total;
$penjualan->update();
return redirect('/jdetail/'.$id_penjualan)->with('pesan', "Data $nama_barang berhasil disimpan");
}
else{
$penjualan = New Penjualan;
$wilayah=$request->wilayah;
$penjualan->tanggal = date("Y-m-d");//$request->tanggal;
$penjualan->jam = date("H:i:s");//$request->jam;
$penjualan->id_pelanggan = $id_pelanggan=Auth::user()->rkey ;
$penjualan->alamat_pengiriman = $request->alamat_pengiriman;
$penjualan->tagihan =0;
$ongkir=getOngkir($wilayah);
$penjualan->ongkir =$ongkir;// $request->ongkir;
$penjualan->total = $ongkir;//$request->total;
$penjualan->status = "Order";
$penjualan->keterangan = "-";
$penjualan->wilayah = $wilayah;
$penjualan->save();
$ARR = Penjualan::all()->last();
$value=$ARR->id_penjualan;
session(['IDORDER' => $value]);
$id_penjualan=$value;
//return redirect('/_penjualan')->with('pesan', 'Data Penjualan berhasil disimpan');
$jdetail = New Jdetail;
$id_barang=$request->id_barang;
$jumlah = $request->jumlah;
$barang = Barang::find($id_barang);
$harga=$barang->harga;
$nama_barang=$barang->nama_barang;
$jdetail->id_penjualan = $id_penjualan;
$jdetail->id_barang = $id_barang;
$jdetail->jumlah =$jumlah;
$jdetail->harga = $harga;
$jdetail->subtotal =$jumlah * $harga;
$jdetail->catatan = $request->catatan;
$jdetail->save();
$barang->stok = $barang->stok-$jumlah;
$barang->update();
$penjualan = Penjualan::find($id_penjualan);
$total=getTotal($id_penjualan);
$penjualan->tagihan =$total;
$penjualan->total =$penjualan->ongkir+$total;
$penjualan->update();
return redirect('/jdetail/'.$id_penjualan)->with('pesan', "Data $nama_barang berhasil disimpan");
}//else
}
public function _store(Request $request){
$penjualan = New Penjualan;
$wilayah=$request->wilayah;
$penjualan->tanggal = date("Y-m-d");//$request->tanggal;
$penjualan->jam = date("H:i:s");//$request->jam;
$penjualan->id_pelanggan = $id_pelanggan=Auth::user()->rkey ;
$penjualan->alamat_pengiriman = $request->alamat_pengiriman;
$penjualan->tagihan =0;
$ongkir=getOngkir($wilayah);
$penjualan->ongkir =$ongkir;// $request->ongkir;
$penjualan->total = $ongkir;//$request->total;
$penjualan->status = "Order";
$penjualan->keterangan = "-";
$penjualan->wilayah = $wilayah;
$penjualan->save();
return redirect('/_penjualan')->with('pesan', 'Data Penjualan berhasil disimpan');
}
public function edit($id_penjualan){
$DaftarPelanggan = Pelanggan::all();
$penjualan = Penjualan::find($id_penjualan);
return view('admin.penjualan.edit', compact('penjualan','DaftarPelanggan'));
}
public function _edit($id_penjualan){
$DaftarPelanggan = Pelanggan::all();
$penjualan = Penjualan::find($id_penjualan);
return view('admin.penjualan._edit', compact('penjualan','DaftarPelanggan'));
}
public function update(Request $request, $id){
$penjualan = Penjualan::find($id);
$penjualan->id_pelanggan = $request->id_pelanggan;
$penjualan->alamat_pengiriman = $request->alamat_pengiriman;
$wilayah=$request->wilayah;
$ongkir=getOngkir($wilayah);
$penjualan->ongkir =$ongkir;
$penjualan->total = $penjualan->tagihan+$ongkir;
$penjualan->wilayah = $wilayah;
$penjualan->status = $request->status;
$penjualan->keterangan = $request->keterangan;
$penjualan->update();
return redirect('/penjualan')->with('pesan','Data Penjualan berhasil di update');
}
public function _update(Request $request, $id){
$penjualan = Penjualan::find($id);
$penjualan->alamat_pengiriman = $request->alamat_pengiriman;
$wilayah=$request->wilayah;
$ongkir=getOngkir($wilayah);
$penjualan->ongkir =$ongkir;
$penjualan->total = $penjualan->tagihan+$ongkir;
$penjualan->wilayah = $wilayah;
$penjualan->keterangan = $request->keterangan;
$penjualan->update();
return redirect('/_penjualan')->with('pesan','Data Penjualan berhasil di update');
}
public function destroy($id){
$penjualan = Penjualan::find($id);
$penjualan->delete();
$ada=0;
$jdetail = \App\Jdetail::all()->where('id_penjualan',$id);
foreach($jdetail as $i){
$pk= $i->idj;
$Detail = \App\Jdetail::find($pk);
$id_barang= $i->id_barang;
$jumlahYgLama= $i->jumlah;
$barang = \App\Barang::find($id_barang);
$barang->stok = $barang->stok+$jumlahYgLama;
$barang->update();
$ada++;
$Detail->delete();
}
return redirect('/penjualan')->with('pesan', "Data Penjualan berikut $ada Transaksi Detailnya Berhasil di Hapus");
}
}
=================================
Jdetail Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Session;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use App\Jdetail;
use App\Penjualan;
use App\Barang;
use File;
use DB ;
use Auth;
class JdetailController extends Controller
{
public function __construct(){
$this->middleware('auth');//auth
}
//ModelName::findOrFail($id, ['firstName', 'lastName']);
//ModelName::find($id, ['name', 'surname']);
//Table::select ('name', 'surname')->where ('id', 1)->get ().
//Eloquent: Get specific columns (not all the row). Pluck returns an array.
//Model::where('id', 1)->pluck('name', 'surname');
// If you only want to get the result value:
//Model::where('id', 1)->value('name');
/*
Model::where('id', 1)
->pluck('name', 'surname')
->all();
*/
//ModelName::all('column1', 'column2', 'column3');
//ModelName::find($id, ['name', 'surname']);
public function index($id){
//$jdetail = Jdetail::all();
//$qry = 'SELECT * FROM `jdetail`,`barang` WHERE `jdetail`.`id_barang`=`barang`.`id_barang` and `jdetail`.`id_penjualan` = "'.$id.'"';
//$jdetail = DB::select($qry);
//Table('table')->select('name','surname')->where('id',1)->get();
//YourModelName::all('id', 'name')->where('id',1)->first()->column_name;
//$jdetail = Jdetail::all()->where('id_penjualan',$id);//->column_name;//find($id)->id_penjualan;
//$subtotal= Jdetail::all()->where('id_penjualan',$id)->sum('subtotal');//max,min,sum,avg,count
//return view('admin.jdetail.index', compact('jdetail','subtotal', 'no','penjualan'));
$no = 0;
$total=0;
$penjualan = Penjualan::find($id);
$jdetail = Jdetail::all()->where('id_penjualan',$id);
return view('admin.jdetail.index', compact('jdetail','total', 'no','penjualan'));
}
public function _storeOrder(Request $request){
if(session()->has('IDORDER')){
$id_penjualan= Session::get('IDORDER');
$jdetail = New Jdetail;
$id_barang=$request->id_barang;
$jumlah = $request->jumlah;
$barang = Barang::find($id_barang);
$harga=$barang->harga;
$nama_barang=$barang->nama_barang;
$jdetail->id_penjualan = $id_penjualan;
$jdetail->id_barang = $id_barang;
$jdetail->jumlah =$jumlah;
$jdetail->harga = $harga;
$jdetail->subtotal =$jumlah * $harga;
$jdetail->catatan = $request->catatan;
$jdetail->save();
$barang->stok = $barang->stok-$jumlah;
$barang->update();
$penjualan = Penjualan::find($id_penjualan);
$total=getTotal($id_penjualan);
$penjualan->tagihan =$total;
$penjualan->total =$penjualan->ongkir+$total;
$penjualan->update();
return redirect('/jdetail/'.$id_penjualan)->with('pesan', "Data $nama_barang berhasil disimpan");
}
else{
$penjualan = New Penjualan;
$wilayah="Jabodetabek";
$penjualan->tanggal = date("Y-m-d");//$request->tanggal;
$penjualan->jam = date("H:i:s");//$request->jam;
$penjualan->id_pelanggan = $id_pelanggan=Auth::user()->rkey ;
$penjualan->alamat_pengiriman = "";
$penjualan->tagihan =0;
$ongkir=getOngkir($wilayah);
$penjualan->ongkir =$ongkir;// $request->ongkir;
$penjualan->total = $ongkir;//$request->total;
$penjualan->status = "Order";
$penjualan->keterangan = "-";
$penjualan->wilayah = $wilayah;
$penjualan->save();
$ARR = Penjualan::all()->last();
$value=$ARR->id_penjualan;
session(['IDORDER' => $value]);
$id_penjualan=$value;
//return redirect('/_penjualan')->with('pesan', 'Data Penjualan berhasil disimpan');
$jdetail = New Jdetail;
$id_barang=$request->id_barang;
$jumlah = $request->jumlah;
$barang = Barang::find($id_barang);
$harga=$barang->harga;
$nama_barang=$barang->nama_barang;
$jdetail->id_penjualan = $id_penjualan;
$jdetail->id_barang = $id_barang;
$jdetail->jumlah =$jumlah;
$jdetail->harga = $harga;
$jdetail->subtotal =$jumlah * $harga;
$jdetail->catatan = $request->catatan;
$jdetail->save();
$barang->stok = $barang->stok-$jumlah;
$barang->update();
$penjualan = Penjualan::find($id_penjualan);
$total=getTotal($id_penjualan);
$penjualan->tagihan =$total;
$penjualan->total =$penjualan->ongkir+$total;
$penjualan->update();
return redirect('/jdetail/'.$id_penjualan)->with('pesan', "Data $nama_barang berhasil disimpan");
}//else
}
public function create($id){
$barang = Barang::all();
$penjualan = Penjualan::find($id);
return view('admin.jdetail.create', compact('penjualan','barang'));
}
public function store(Request $request){
$jdetail = New Jdetail;
$id_penjualan=$request->id_penjualan;
$id_penjualan=$id_penjualan;
$id_barang=$request->id_barang;
$jumlah = $request->jumlah; //Input::get('jumlah', false);
$barang = Barang::find($id_barang);
$harga=$barang->harga;
$nama_barang=$barang->nama_barang;
$jdetail->id_penjualan = $id_penjualan;
$jdetail->id_barang = $id_barang;
$jdetail->jumlah =$jumlah;
$jdetail->harga = $harga;
$jdetail->subtotal =$jumlah * $harga;
$jdetail->catatan = $request->catatan;
$jdetail->save();
$barang->stok = $barang->stok-$jumlah;
$barang->update();
$penjualan = Penjualan::find($id_penjualan);
$total=getTotal($id_penjualan);
$penjualan->tagihan =$total;
$penjualan->total =$penjualan->ongkir+$total;
$penjualan->update();
return redirect('/jdetail/'.$id_penjualan)->with('pesan', "Data $nama_barang berhasil disimpan");
}
public function edit($id,$kode){
$penjualan = Penjualan::find($id);
$jdetail = Jdetail::find($kode);
$barang = Barang::all();
return view('admin.jdetail.edit', compact('jdetail','penjualan','barang'));
}
public function update(Request $request,$id,$kode){//Request $request,
$id_penjualan=$id;
$id_barang=$request->id_barang;
$jumlah = $request->jumlah;//3 8
$barang = Barang::find($id_barang);
$harga=$barang->harga;
$nama_barang=$barang->nama_barang;
$jdetail = Jdetail::find($kode);
$jumlahYgLama =$jdetail->jumlah;//8 3
$selisih=$jumlahYgLama-$jumlah;//8-3=5
$barang->stok = $barang->stok+$selisih;
$barang->update();
$jdetail->id_penjualan = $id_penjualan;
$jdetail->id_barang = $id_barang;
$jdetail->jumlah = $jumlah;
$jdetail->harga = $harga;
$jdetail->subtotal =$jumlah * $harga;
$jdetail->catatan = $request->catatan;
$jdetail->update();
$penjualan = Penjualan::find($id_penjualan);
$total=getTotal($id_penjualan);
$penjualan->tagihan =$total;
$penjualan->total =$penjualan->ongkir+$total;
$penjualan->update();
return redirect('/jdetail/'.$id_penjualan)->with('pesan',"Data $nama_barang Penjualan berhasil di update");
}
public function destroy($id,$kode){
$jdetail = Jdetail::find($kode);//findOrFail
$id_barang=$jdetail->id_barang;
$jumlahYgLama =$jdetail->jumlah;
$jdetail->delete();
$barang = Barang::find($id_barang);
$barang->stok = $barang->stok+$jumlahYgLama;
$barang->update();
return redirect('/jdetail/'.$id)->with('pesan', 'Data Transaksi Berhasil di Hapus');
}
}
?>