public function karyawan()
 {
     $karyawans = Karyawan::where('active', 1)->get();
     $data = [];
     foreach ($karyawans as $karyawan) {
         array_push($data, ['karyawan_id' => $karyawan->id, 'nama_karyawan' => $karyawan->nama]);
     }
     $display['karyawan'] = $data;
     return $display;
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $validator = Validator::make($request->all(), ['karyawan_id' => 'required', 'username' => 'required|unique:users,username', 'password' => 'required|confirmed', 'roles' => 'required'], ['karyawan_id.required' => "Karyawan tidak boleh kosong.", 'username.required' => "Username tidak boleh kosong.", 'username.unique' => "Username sudah dipakai.", 'password.required' => "Password tidak boleh kosong.", 'password.confirmed' => "Password konfirmasi tidak sama.", 'roles.required' => "Role tidak boleh kosong."]);
     if ($validator->fails()) {
         return redirect()->back()->withErrors($validator)->withInput();
     }
     $user = User::create(['username' => $request->get('username'), 'password' => Hash::make($request->get('password')), 'api_token' => Uuid::generate()]);
     if ($user) {
         $roles = $request->get('roles') != "" ? $request->get('roles') : [];
         $user->assignRole($roles);
         Karyawan::find($request->get('karyawan_id'))->update(['user_id' => $user->id]);
         return redirect('/user')->with('succcess', 'Sukses simpan user.');
     }
     return redirect()->back()->withErrors(['failed' => 'Gagal simpan user.']);
 }
예제 #3
0
 public function export()
 {
     $karyawan = new Karyawan();
     //$karyawan->count() handle if count 0
     $karyawans = Karyawan::get($karyawan->getFillable())->toArray();
     return ExcelHelper::export($karyawans);
 }
예제 #4
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(Karyawan $karyawan)
 {
     $karyawan->delete();
     return redirect('karyawan/');
 }
 protected function _karyawanPertahun(Request $request)
 {
     $tahun = $request->get('tahun') ? $request->get('tahun') : date('Y');
     $karyawans = \App\Karyawan::join('orders', 'karyawans.id', '=', 'orders.karyawan_id')->join('order_details', 'orders.id', '=', 'order_details.order_id')->leftJoin('order_detail_returns', 'order_details.id', '=', 'order_detail_returns.order_detail_id')->where(DB::raw('SUBSTRING(orders.tanggal, 1, 4)'), $tahun)->where('state', 'Closed')->where('karyawans.active', 1)->select(['karyawans.id', 'karyawans.nama', DB::raw('SUM( order_details.`harga_jual` * ( order_details.`qty` - ifnull(order_detail_returns.qty, 0) ) )total_penjualan')])->groupBy('karyawans.id')->get();
     return ['tanggal' => Carbon::createFromFormat('Y', $tahun), 'karyawans' => $karyawans];
 }
예제 #6
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $data = Sales::find($id);
     $karyawan = Karyawan::find($data['id_karyawan']);
     return view('sales.show', compact('data', 'karyawan'));
 }
 protected function _reportPertahun(Request $request)
 {
     $id = $request->get('karyawan_id');
     $tahun = $request->get('tahun') ? $request->get('tahun') : date('Y');
     $karyawan = Karyawan::find($id);
     if (!$karyawan) {
         abort(404);
     }
     $start = Carbon::createFromFormat('Y', $tahun)->startOfYear();
     $end = Carbon::createFromFormat('Y', $tahun)->endOfYear();
     $months = [];
     while ($start->lte($end)) {
         $months[] = $start->copy();
         $start->addMonth();
     }
     $reports = \App\Order::join('order_details', 'orders.id', '=', 'order_details.order_id')->leftJoin('order_detail_returns', 'order_details.id', '=', 'order_detail_returns.order_detail_id')->where('orders.state', 'Closed')->where('orders..karyawan_id', $id)->where(DB::raw('SUBSTRING(orders.tanggal, 1, 4)'), $tahun)->select(['orders.tanggal', DB::raw('SUBSTRING(orders.tanggal, 1, 7) as bulan'), DB::raw('SUM(order_details.harga_jual * (order_details.qty - ifnull(order_detail_returns.qty, 0)))total_penjualan')])->groupBy(DB::raw('SUBSTRING(orders.tanggal, 1, 7)'))->get();
     return ['tanggal' => Carbon::createFromFormat('Y', $tahun), 'karyawan' => $karyawan, 'months' => $months, 'reports' => $reports];
 }