Skip to content

Commit

Permalink
Merge pull request #3494 from ColoredCow/feature/export-excel
Browse files Browse the repository at this point in the history
Feature/export excel
  • Loading branch information
GauravGusain98 authored Mar 20, 2024
2 parents c856a67 + c9044b5 commit 4201750
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 24 deletions.
73 changes: 60 additions & 13 deletions Modules/HR/Exports/EmployeePayrollExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,60 @@

class EmployeePayrollExport implements FromArray, WithHeadings, ShouldAutoSize, WithTitle, WithStyles
{
// protected $employees;
protected $employees;

public function __construct()
public function __construct($employees)
{
// $this->employees = $employees;
$this->employees = $employees;
}

public function array(): array
{
return [['hello']];
$data = [];
foreach ($this->employees as $employee) {
$employeePayrollData = [
$employee->user()->withTrashed()->first()->name,
$employee->cc_employee_id,
optional($employee->hrJobDesignation)->designation,
optional($employee->getCurrentSalary())->monthly_gross_salary,
optional($employee->getCurrentSalary())->basic_salary,
optional($employee->getCurrentSalary())->hra,
optional($employee->getCurrentSalary())->transport_allowance,
optional($employee->getCurrentSalary())->other_allowance,
optional($employee->getCurrentSalary())->food_allowance,
optional($employee->getCurrentSalary())->total_salary,
30,
30,
optional($employee->getCurrentSalary())->employee_esi,
optional($employee->getCurrentSalary())->employee_epf,
null,
null,
optional($employee->getCurrentSalary())->food_allowance,
optional($employee->getCurrentSalary())->total_deduction,
null,
optional($employee->getCurrentSalary())->net_pay,
optional($employee->getCurrentSalary())->employer_esi,
optional($employee->getCurrentSalary())->employer_epf,
optional($employee->getCurrentSalary())->administration_charges,
optional($employee->getCurrentSalary())->edli_charges,
optional($employee->getCurrentSalary())->ctc,
optional($employee->getCurrentSalary())->ctc_annual,
optional($employee->getCurrentSalary())->health_insurance,
optional($employee->getCurrentSalary())->ctc_aggregated,
];

array_push($data, $employeePayrollData);
}

return $data;
}

public function headings(): array
{
return [
['Coloredcow Consulting Private Limited'],
[Carbon::now()->format('F Y'), "Paid", Carbon::today()->toDateString()],
['Employee Name', 'Employee ID', 'Designation', 'GROSS', 'Basic Salary', 'HRA', 'Transport allowance', 'Other Allowance', 'Food Allowance', 'Total Salary', 'Total No of Days', 'Paid Days', 'Employee ESI 0.75%', 'Employee EPF 12 %', 'TDS', 'Advance Recovery', 'Food Deduction', 'Total Deduction', 'Advance Salary', ' Net Pay', ' Employer ESI 3.25%', ' EPF EMPLOYER SHARE 12%', ' Administration charges FIXED 0.5%( BASIC SALARY)', ' EDLI Charges FIXED 0.5%(MAXIMUM SALARY LIMIT 15000)', ' CTC', ' CTC Annual', 'Health Insurance', 'CTC Agreed'],
];
}

public function exportData()
{
$data = [
'hello',
[Carbon::now()->format('F Y'), 'Paid', Carbon::today()->toDateString()],
['Employee Name', 'Employee ID', 'Designation', 'GROSS', 'Basic Salary', 'HRA', 'Transport allowance', 'Other Allowance', 'Food Allowance', 'Total Salary', 'Total No of Days', 'Paid Days', 'Employee ESI 0.75%', 'Employee EPF 12 %', 'TDS', 'Advance Recovery', 'Food Deduction', 'Total Deduction', 'Advance Salary', ' Net Pay', ' Employer ESI 3.25%', ' EPF EMPLOYER SHARE 12%', ' Administration charges FIXED 0.5%( BASIC SALARY)', ' EDLI Charges FIXED 0.5%(MAXIMUM SALARY LIMIT 15000)', ' CTC', ' CTC Annual', 'Health Insurance', 'CTC Aggreed'],
];
}

Expand All @@ -54,5 +83,23 @@ public function styles(Worksheet $sheet)
$sheet->setCellValue('M2', 'Deduction');
$sheet->mergeCells('U2:X2');
$sheet->setCellValue('U2', ' Employer Contribution');

return [
1 => [
'font' => [
'bold' => true,
],
],
2 => [
'font' => [
'bold' => true,
],
],
3 => [
'font' => [
'bold' => true,
],
],
];
}
}
12 changes: 7 additions & 5 deletions Modules/HR/Http/Controllers/EmployeeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Maatwebsite\Excel\Facades\Excel;
use Modules\HR\Entities\Assessment;
use Modules\HR\Entities\Employee;
use Modules\HR\Entities\HrJobDesignation;
use Modules\HR\Entities\HrJobDomain;
use Modules\HR\Entities\IndividualAssessment;
use Modules\HR\Entities\Job;
use Modules\Project\Entities\ProjectTeamMember;
use Maatwebsite\Excel\Facades\Excel;
use Modules\HR\Exports\EmployeePayrollExport;
use Modules\Project\Entities\ProjectTeamMember;

class EmployeeController extends Controller
{
Expand Down Expand Up @@ -141,8 +141,10 @@ public function updateEmployeeReviewers(Request $request, Employee $employee)

public function downloadPayRoll()
{
$endDate = date('Y-m-d');
$filename = 'PayRoll Report-' . $endDate . '.xlsx';
return Excel::download(new EmployeePayrollExport(), $filename);
$employees = $this->service->getEmployeeListForExport();
$today = date('Y-m-d');
$filename = 'PayRoll Report-' . $today . '.xlsx';

return Excel::download(new EmployeePayrollExport($employees['employees']), $filename);
}
}
2 changes: 1 addition & 1 deletion Modules/Salary/Entities/EmployeeSalary.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function getTotalDeductionAttribute()
return $this->employee_esi + $this->employee_epf + $this->food_allowance;
}

public function gteNetPayAttribute()
public function getNetPayAttribute()
{
return $this->total_salary - $this->total_deduction;
}
Expand Down
13 changes: 13 additions & 0 deletions app/Services/EmployeeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ public function getEmployeeListWithLatestPayroll($filters = [])
];
}

public function getEmployeeListForExport()
{
$employees = Employee::with('user')->whereHas('user', function ($query) {
$query->whereNull('deleted_at');
})
->orderBy('name')
->get();

return [
'employees' => $employees,
];
}

public function defaultFilters()
{
return [
Expand Down
3 changes: 2 additions & 1 deletion resources/views/hr/payroll/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@
$commencementDate = optional($employeeCurrentSalaryObject)->commencement_date;
$diff = now()->diff($commencementDate);
$difference = $diff->format('%m months and %d days');
$diffInDays = now()->diffInDays($commencementDate)
@endphp
{{ optional($commencementDate)->format('Y-m-d') }} {{ $diff->d == 0 ? '(0 days)' : '( ' . $difference . ' )' }}
{{ optional($commencementDate)->format('Y-m-d') }} {{ $diffInDays == 0 ? '(0 days)' : '( ' . $difference . ' )' }}
</td>
</tr>
@endforeach
Expand Down
8 changes: 4 additions & 4 deletions resources/views/hr/payroll/menu.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@
<ul class="nav nav-pills">
<li class="nav-item">
@php
$params = array_merge(['staff_type' => 'Employee'], ['status' => 'current']);
$params = array_merge(['staff_type' => 'Employee']);
@endphp
<a class="nav-item nav-link {{ request()->input('staff_type') === 'Employee' ? 'active' : '' }}" href="{{ route('payroll',$params) }}"><i class="fa fa-users"></i>&nbsp; Employee </a>
</li>
<li class="nav-item">
@php
$params = array_merge(['staff_type' => 'Intern'], ['status' => 'current']);
$params = array_merge(['staff_type' => 'Intern']);
@endphp
<a class="nav-item nav-link {{ request()->input('staff_type') === 'Intern' ? 'active' : '' }}" href="{{ route('payroll', $params) }}"><i class="fa fa-users"></i>&nbsp;Intern</a>
</li>

<li class="nav-item">
@php
$params = array_merge(['staff_type' => 'Contractor'], ['status' => 'current']);
$params = array_merge(['staff_type' => 'Contractor']);
@endphp
<a class="nav-item nav-link {{ request()->input('staff_type') === 'Contractor' ? 'active' : '' }}" href="{{ route('payroll', $params) }}"><i class="fa fa-users"></i>&nbsp;Contractor</a>
</li>

<li class="nav-item">
@php
$params = array_merge(['staff_type' => 'Support Staff'], ['status' => 'current']);
$params = array_merge(['staff_type' => 'Support Staff']);
@endphp
<a class="nav-item nav-link {{ request()->input('staff_type') === 'Support Staff' ? 'active' : '' }}" href="{{ route('payroll', $params) }}"><i class="fa fa-users"></i>&nbsp;Support Staff</a>
</li>
Expand Down

0 comments on commit 4201750

Please sign in to comment.