SHARE
TWEET

Untitled

fadlyshafa Jan 19th, 2020 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use Illuminate\Http\Request;
  6.  
  7. use App\Models\Customer;
  8. use App\Models\Paket;
  9. use App\Models\Status_pesanan;
  10. use App\Models\Status_pembayaran;
  11. use App\Models\T_pesanan;
  12.  
  13. class T_pesanan_controller extends Controller
  14. {
  15.     public function index(){
  16.         $title = 'Transaksi Pesanan';
  17.         $data = T_pesanan::orderBy('created_at','desc')->get();
  18.  
  19.         return view('t_pesanan.index',compact('title','data'));
  20.     }
  21.  
  22.     public function naikkan_status($id){
  23.         try {
  24.             $transaksi = T_pesanan::find($id);
  25.             $id_status = $transaksi->status_pesanan;
  26.             $urutan_status = $transaksi->status_pesanans->urutan;
  27.  
  28.             $urutan_baru = $urutan_status + 1;
  29.             $status_baru = Status_pesanan::where('urutan',$urutan_baru)->first();
  30.  
  31.             T_pesanan::where('id',$id)->update([
  32.                 'status_pesanan'=>$status_baru->id
  33.             ]);
  34.  
  35.             \Session::flash('sukses','Status berhasil dinaikkan');
  36.  
  37.         } catch (\Exception $e) {
  38.             \Session::flash('gagal',$e->getMessage());
  39.         }
  40.  
  41.         return redirect()->back();
  42.     }
  43.  
  44.     public function add(){
  45.         $title = 'Tambah Pesanan';
  46.         $customer = Customer::orderBy('nama','asc')->get();
  47.         $paket = Paket::orderBy('nama','asc')->get();
  48.         $status_pesanan = Status_pesanan::orderBy('urutan','asc')->get();
  49.         $status_pembayaran = Status_pembayaran::orderBy('nama','asc')->get();
  50.  
  51.         return view('t_pesanan.add',compact('title','customer','paket','status_pesanan','status_pembayaran'));
  52.     }
  53.  
  54.     public function store(Request $request){
  55.         $this->validate($request,[
  56.             'customer'=>'required',
  57.             'paket'=>'required',
  58.             'berat'=>'required',
  59.             'status_pesanan'=>'required',
  60.             'status_pembayaran'=>'required'
  61.         ]);
  62.  
  63.         $data['id'] = \Uuid::generate(4);
  64.         $data['customer'] = $request->customer;
  65.         $data['paket'] = $request->paket;
  66.         $data['berat'] = $request->berat;
  67.         $data['status_pembayaran'] = $request->status_pembayaran;
  68.         $data['status_pesanan'] = $request->status_pesanan;
  69.         $data['created_at'] = date('Y-m-d H:i:s');
  70.         $data['updated_at'] = date('Y-m-d H:i:s');
  71.  
  72.         $harga = Paket::find($request->paket);
  73.         $harga_paket = $harga->harga;
  74.         $berat = $request->berat;
  75.  
  76.         $grand_total = $harga_paket * $berat;
  77.  
  78.         $data['grand_total'] = $grand_total;
  79.  
  80.         T_pesanan::insert($data);
  81.  
  82.         \Session::flash('sukses','Transaksi berhasil ditambah');
  83.  
  84.         return redirect('transaksi-pesanan/add');
  85.     }
  86.  
  87.     public function edit($id){
  88.         $dt = T_pesanan::find($id);
  89.         $title = "Edit Transaksi";
  90.         $customer = Customer::orderBy('nama','asc')->get();
  91.         $paket = Paket::orderBy('nama','asc')->get();
  92.         $status_pesanan = Status_pesanan::orderBy('urutan','asc')->get();
  93.         $status_pembayaran = Status_pembayaran::orderBy('nama','asc')->get();
  94.  
  95.         return view('t_pesanan.edit',compact('title','customer','paket','status_pesanan','status_pembayaran','dt'));
  96.     }
  97.  
  98.     public function update(Request $request, $id){
  99.         $this->validate($request,[
  100.             'customer'=>'required',
  101.             'paket'=>'required',
  102.             'berat'=>'required',
  103.             'status_pesanan'=>'required',
  104.             'status_pembayaran'=>'required'
  105.         ]);
  106.  
  107.         // $data['id'] = \Uuid::generate(4);
  108.         $data['customer'] = $request->customer;
  109.         $data['paket'] = $request->paket;
  110.         $data['berat'] = $request->berat;
  111.         $data['status_pembayaran'] = $request->status_pembayaran;
  112.         $data['status_pesanan'] = $request->status_pesanan;
  113.         // $data['created_at'] = date('Y-m-d H:i:s');
  114.         $data['updated_at'] = date('Y-m-d H:i:s');
  115.  
  116.         $harga = Paket::find($request->paket);
  117.         $harga_paket = $harga->harga;
  118.         $berat = $request->berat;
  119.  
  120.         $grand_total = $harga_paket * $berat;
  121.  
  122.         $data['grand_total'] = $grand_total;
  123.  
  124.         T_pesanan::where('id',$id)->update($data);
  125.  
  126.         \Session::flash('sukses','Transaksi berhasil diupdate');
  127.  
  128.         return redirect('transaksi-pesanan');
  129.     }
  130.  
  131.     public function delete($id){
  132.         T_pesanan::where('id',$id)->delete();
  133.  
  134.         \Session::flash('sukses','Data berhasil dihapus');
  135.         return redirect('transaksi-pesanan');
  136.     }
  137. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top