for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace CleaniqueCoders\OpenPayroll\Processors;
use CleaniqueCoders\OpenPayroll\Contracts\CalculateContract;
class PayslipProcessor implements CalculateContract
{
public $payslip;
public function __construct($identifier = null)
if (! is_null($identifier)) {
if (is_string($identifier) || is_int($identifier)) {
$this->payslip = config('open-payroll.models.payslip')::query()
->with('earnings', 'deductions', 'payroll', 'employee', 'employee.salary')
->whereId($identifier)
->orWhere('hashslug', $identifier)
->firstOrFail();
}
if (is_object($identifier)) {
$this->payslip($identifier);
public static function make($identifier = null)
return new self($identifier);
public function payslip($payslip)
$this->payslip = $payslip;
return $this;
public function calculate()
if ($this->payslip) {
$employee = $this->payslip->employee;
$salary = $employee->salary;
$payroll = $this->payslip->payroll;
$payroll
$earnings = $this->payslip->earnings;
$deductions = $this->payslip->deductions;
$this->payslip->basic_salary = $salary->amount;
$this->payslip->gross_salary = $gross_salary = ($earnings->sum('amount') + $salary->amount);
$this->payslip->net_salary = $gross_salary - $deductions->sum('amount');
$this->payslip->save();