|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Database\Seeder; |
|
4
|
|
|
|
|
5
|
|
|
class OpenPayrollDemoSeeder extends Seeder |
|
6
|
|
|
{ |
|
7
|
|
|
public $faker; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Run the database seeds. |
|
11
|
|
|
*/ |
|
12
|
|
|
public function run() |
|
13
|
|
|
{ |
|
14
|
|
|
$this->faker = \Faker\Factory::create(); |
|
15
|
|
|
$this->seedEmployees(); |
|
16
|
|
|
$this->seedPayroll(); |
|
17
|
|
|
$this->calculatePayroll(); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
private function seedEmployees() |
|
21
|
|
|
{ |
|
22
|
|
|
$this->command->info('Seeding employees...'); |
|
23
|
|
|
factory(\App\Models\OpenPayroll\Employee::class, 3)->create()->each(function($user) { |
|
24
|
|
|
$user->addresses()->create([ |
|
25
|
|
|
'primary' => $this->faker->address, |
|
26
|
|
|
'postcode' => $this->faker->postcode, |
|
27
|
|
|
'city' => $this->faker->city, |
|
28
|
|
|
'state' => $this->faker->state, |
|
29
|
|
|
'country_id' => $this->faker->randomElement(range(1, 100)), |
|
30
|
|
|
'is_default' => true, |
|
31
|
|
|
]); |
|
32
|
|
|
|
|
33
|
|
|
$user->phones()->create([ |
|
34
|
|
|
'phone_type_id' => $this->faker->randomElement([1, 2]), |
|
35
|
|
|
'phone_number' => $this->faker->phoneNumber, |
|
36
|
|
|
'is_default' => true, |
|
37
|
|
|
]); |
|
38
|
|
|
|
|
39
|
|
|
$user->banks()->create([ |
|
40
|
|
|
'bank_id' => $this->faker->randomElement(range(1, 50)), |
|
41
|
|
|
'account_no' => $this->faker->bankAccountNumber, |
|
42
|
|
|
]); |
|
43
|
|
|
|
|
44
|
|
|
$user->position()->create([ |
|
45
|
|
|
'name' => $this->faker->jobTitle, |
|
46
|
|
|
]); |
|
47
|
|
|
|
|
48
|
|
|
$user->salary()->create([ |
|
49
|
|
|
'amount' => $this->faker->randomElement(range(10000, 20000)) * 100, |
|
50
|
|
|
]); |
|
51
|
|
|
}); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
private function seedPayroll() |
|
55
|
|
|
{ |
|
56
|
|
|
$this->command->info('Seeding payroll...'); |
|
57
|
|
|
$admin = \App\Models\OpenPayroll\Admin::create([ |
|
58
|
|
|
'name' => 'OpenPayroll Admin', |
|
59
|
|
|
'email' => '[email protected]', |
|
60
|
|
|
'password' => bcrypt('password'), |
|
61
|
|
|
]); |
|
62
|
|
|
|
|
63
|
|
|
for ($month = 1; $month <= 12; ++$month) { |
|
64
|
|
|
$admin->payrolls()->create([ |
|
65
|
|
|
'month' => now()->addMonths($month)->format('n'), |
|
66
|
|
|
'year' => now()->addMonths($month)->format('Y'), |
|
67
|
|
|
'date' => now()->addMonths($month)->format('Y-m-d'), |
|
68
|
|
|
]); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
private function calculatePayroll() |
|
73
|
|
|
{ |
|
74
|
|
|
$payrolls = \App\Models\OpenPayroll\Payroll::all(); |
|
75
|
|
|
|
|
76
|
|
|
\App\Models\OpenPayroll\Employee::has('salary')->with('salary')->get()->each(function($employee) use ($payrolls) { |
|
77
|
|
|
$payrolls->each(function($payroll) use ($employee) { |
|
78
|
|
|
$payslip = \App\Models\OpenPayroll\Payslip::create([ |
|
79
|
|
|
'user_id' => $employee->id, |
|
80
|
|
|
'payroll_id' => $payroll->id, |
|
81
|
|
|
'basic_salary' => optional($employee->salary)->amount ?? 0, |
|
82
|
|
|
'gross_salary' => optional($employee->salary)->amount ?? 0, |
|
83
|
|
|
'net_salary' => optional($employee->salary)->amount ?? 0, |
|
84
|
|
|
]); |
|
85
|
|
|
|
|
86
|
|
|
// earnings |
|
87
|
|
|
\App\Models\OpenPayroll\Earning::create([ |
|
88
|
|
|
'user_id' => $employee->id, |
|
89
|
|
|
'payroll_id' => $payroll->id, |
|
90
|
|
|
'payslip_id' => $payslip->id, |
|
91
|
|
|
'earning_type_id' => 1, |
|
92
|
|
|
'name' => 'Basic Salary', |
|
93
|
|
|
'description' => 'Basic Salary', |
|
94
|
|
|
'amount' => optional($employee->salary)->amount ?? 0, |
|
95
|
|
|
]); |
|
96
|
|
|
|
|
97
|
|
|
// deduction |
|
98
|
|
|
// @todo |
|
99
|
|
|
}); |
|
100
|
|
|
}); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|