CasperSecurity

Current Path : /var/www/orientalss.com/app/Http/Livewire/Report/
Upload File :
Current File : /var/www/orientalss.com/app/Http/Livewire/Report/DeductionReportLivewire.php

<?php

namespace App\Http\Livewire\Report;

use App\Models\Organisation;
use App\Models\PayrollItems;
use App\Models\SalaryCalculation;
use Carbon\Carbon;
use Livewire\Component;

class DeductionReportLivewire extends Component
{
    public $search;
    public $perPage = 10;
    public $orderBy = 'id';
    public $orderAsc = '1';
    public $from_date, $to_date;

    public function mount()
    {
        $this->from_date = Carbon::now()->startOfMonth()->format('Y-m-d');
        $this->to_date = Carbon::now()->endOfMonth()->format('Y-m-d');
        $this->orderBy = 'id';
    }

    public function closemodalclick()
    {
        $this->resetValidation();
        $this->datatable = [];

    }
    public function read()
    {
        $query = SalaryCalculation::select('salary_calculations.*', 'employee_registrations.employee_id', 'employee_registrations.name', 'designations.designation_name')
            ->join('employee_registrations', 'salary_calculations.employee_id', '=', 'employee_registrations.id')
            ->join('designations', 'employee_registrations.designation', '=', 'designations.id')
            ->whereBetween('salary_calculations.created_at', [$this->from_date, $this->to_date])
            ->where('salary_calculations.status', '1');

        if ($this->search !== null) {
            $query->where(function ($q) {
                $q->where('employee_registrations.name', 'like', '%' . $this->search . '%')
                    ->orWhere('employee_registrations.employee_id', 'like', '%' . $this->search . '%');
            });
        }

        $salary_calculations = $query->get();
        $totals = [];
        $grandTotalDeductions = 0; // Initialize grand total deductions

        foreach ($salary_calculations as $record) {
            $emp_id = $record->employee_id;
            $amount = $record->amount;
            $payroll_item_name = $record->payroll_item_name;

            // Initialize totals array if not set
            if (!isset($totals[$emp_id])) {
                $totals[$emp_id] = [
                    'employee_id' => $emp_id,
                    'name' => $record->name,
                    'designation_name' => $record->designation_name,
                    'deduction' => [], // Initialize deduction array
                ];
            }

            // Fetch payroll component details
            $pay_component = PayrollItems::where('payroll_item_short_name', $payroll_item_name)->first();

            // Check if the payroll component is a deduction
            if ($pay_component && $pay_component->payroll_item_type === 'DEDUCTION') {
                if (!isset($totals[$emp_id]['deduction'][$pay_component->payroll_item])) {
                    $totals[$emp_id]['deduction'][$pay_component->payroll_item] = 0;
                }
                $totals[$emp_id]['deduction'][$pay_component->payroll_item] += $amount;
            }
        }

        // Calculate total deductions for each employee and grand total
        foreach ($totals as &$data) {
            $data['Total Deductions'] = array_sum($data['deduction']);
            $grandTotalDeductions += $data['Total Deductions'];
        }

        return [
            'employee_totals' => array_values($totals),
            'grand_total_deductions' => $grandTotalDeductions
        ];
    }

    public function render()
    {
        $org = Organisation::latest()->first();
        $result = $this->read();
        $datatable = $result['employee_totals'];
        $grandTotalDeductions = $result['grand_total_deductions'];
        return view('livewire.report.deduction-report-livewire', compact('datatable', 'grandTotalDeductions', 'org'));
    }

}
Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY