Skip to content

Commit

Permalink
Thêm in lương bản thân, theo tháng và fix bug khi cập nhập tài nguyên…
Browse files Browse the repository at this point in the history
… cru
  • Loading branch information
1119-DuyNguyen committed Apr 21, 2024
1 parent 3b42232 commit ee21143
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 209 deletions.
32 changes: 23 additions & 9 deletions app/Http/Controllers/Backend/User/EmployeeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Models\Role;
use App\Models\User;
use Barryvdh\DomPDF\Facade\Pdf;
use Filament\Notifications\Notification;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Auth;
Expand Down Expand Up @@ -112,22 +113,35 @@ protected function getFormElements(): array
];
}

public function getMySalary()
public function getMySalaryForm()
{
$user = User::with('contract.checkins')->findOrFail(Auth::user()->id);
$pdf = Pdf::loadView('admin.prints.my-salary', compact('user'));
$month = 1;
return $pdf->stream('my-salary.pdf', compact('month'));
return view('admin.employees.my-salary-form');
}

public function formSelectMySalary()
public function getMySalary(Request $request)
{
$user = User::with('contract.checkins')->findOrFail(Auth::user()->id);
$pdf = Pdf::loadView('admin.prints.my-salary', compact('user'));
$month = 1;
return $pdf->stream('my-salary.pdf', compact('month'));
$day = Carbon::createFromFormat('Y-m', $request->input('month'));
$month = $request->input('month');

$checkin = Checkin::with('contract.user')->whereMonth('date', $day->month)->whereYear(
'date',
$day->year
)
->whereHas('contract', function ($query) {
// $query->where('user_id', '=', Auth::user()->id);
$query->where('user_id', '=', 4);
})
->first();
if (empty($checkin)) {
Notification::make()->title("Không tìm thấy tháng chấm công")->info()->send();
return redirect()->back();
}
$pdf = Pdf::loadView('admin.prints.my-salary', compact('checkin', 'day', 'month'));
return $pdf->stream('luong-cua-toi-' . $month . '.pdf');
}


public function getSalary(Request $request)
{
$day = Carbon::createFromFormat('Y-m', $request->input('month'));
Expand Down
49 changes: 24 additions & 25 deletions app/Http/Controllers/CRUDController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Traits\InputHandlerTrait;
use Exception;
use Filament\Notifications\Notification;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -148,10 +149,12 @@ public function store(Request $request)
$data = $this->handleDataInput($request);

$this->model()::create($data);
// toast()->success('Created Successfully!');
toast()->success('Khởi tạo dữ liệu thành công');
Notification::make()
->title('Khởi tạo dữ liệu thành công')
->success()
->send();

return redirect()->back();
return response()->json();
}

/**
Expand All @@ -167,31 +170,27 @@ public function show($resource_id)
*/
public function update(Request $request, $resource_id)
{
try {
$resource = $this->model()::findOrFail($resource_id);

$data = $this->handleDataInput(
$request,
!empty($this->getImageInput())
? $resource->{$this->getImageInput()}
: null
);
foreach ($this->unsetUpdateEmptyField() as $field) {
if (empty($data[$field])) {
unset($data[$field]);
}
}
$resource->fill($data);
$resource->save();
$resource = $this->model()::findOrFail($resource_id);

toast()->success('Cập nhập dữ liệu thành công!');
} catch (ValidationException $e) {
return response(['status' => 'error', 'message' => $e->getMessage()]);
} catch (Exception $e) {
$data = $this->handleDataInput(
$request,
!empty($this->getImageInput())
? $resource->{$this->getImageInput()}
: null
);
foreach ($this->unsetUpdateEmptyField() as $field) {
if (empty($data[$field])) {
unset($data[$field]);
}
}
$resource->fill($data);
$resource->save();
Notification::make()
->title('Cập nhập thành công')
->success()
->send();


return redirect()->back();
return response()->json();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Requests/Backend/CheckinRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public function rules(): array
return [
'contract_id' => ['required'],
'date' => ['required'],
'over_times' => ['required', 'numeric', 'min:1'],
'auth_day_off' => ['required', 'numeric', 'min:1'],
'user_id' => ['required']
'over_times' => ['required', 'numeric', 'min:0'],
'auth_day_off' => ['required', 'numeric', 'min:0'],
// 'user_id' => ['required']

];
}
Expand Down
3 changes: 3 additions & 0 deletions resources/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@

}

.form-group .control-label, .form-group > label {
font-size: 1rem !important;
}
73 changes: 3 additions & 70 deletions resources/views/admin/layouts/master.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,81 +129,14 @@
<script src="{{asset("backend/assets/js/custom.js")}}"></script>

{{--vendor--}}
@include('setup-js')

@livewireScripts
@filamentScripts
@livewire('notifications')
@vite('resources/js/app.js')
<!-- Dynamic Delete alart -->

<script type="text/javascript">
$(document).ready(function () {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$('body').on('click', '.delete-item', function (event) {
event.preventDefault();
let deleteUrl = $(this).attr('href');
Swal.fire({
title: 'Bạn chắc chắn muốn xoá chứ ?',
text: "Bạn sẽ không thể hoàn lại tác vụ này",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Xoá',
cancelButtonText: 'Huỷ bỏ'
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
type: 'DELETE',
url: deleteUrl,
// headers: {
// 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
// },
success: function (data) {
if (data.status == 'success') {
Swal.fire(
'Xóa thành công!',
"",
// data.message,
'success'
).then(() => {
window.location.reload();
})
} else if (data.status == 'error') {
Swal.fire(
data.message ?? 'Không thể xóa',
// data.message,
'',
'error'
)
}
},
error: function (xhr, status, error) {
console.log(error);
}
})
}
})
})
})
</script>
@include('setup-js')



@stack('scripts')

Expand Down
4 changes: 2 additions & 2 deletions resources/views/admin/layouts/navbar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ class="dropdown-item has-icon">
<i class="fas fa-comments"></i> Ý kiến của tôi
</a>
<div class="dropdown-divider"></div>
<a href="{{ route('admin.employees.my-salary', [\Illuminate\Support\Facades\Auth::user()->id]) }}"
<a href="{{ route('admin.employees.my-salary.form') }}"
class="dropdown-item has-icon">

<i class="fas fa-comments"></i> Lương của tôi
<i class="fas fa-wallet"></i> Lương của tôi
</a>
<div class="dropdown-divider"></div>

Expand Down
Loading

0 comments on commit ee21143

Please sign in to comment.