CasperSecurity
<?php
namespace App\Http\Livewire\Report;
use App\Models\Billing;
use App\Models\Client;
use App\Models\CreateTender;
use App\Models\Organisation;
use Illuminate\Support\Carbon;
use Livewire\Component;
class InvoiceRegisterLivewire extends Component
{
public $search;
public $perPage = 10;
public $orderBy = 'id';
public $orderAsc = 'asc';
public $filter_by;
public $from_date,$to_date,$data;
public function closemodalclick()
{
$this->resetValidation();
$this->datatable = [];
}
public function mount()
{
$this->from_date = Carbon::now()->format('Y-m-d');
$this->to_date = Carbon::now()->format('Y-m-d');
}
public function updatedFilterBy(){
$this->search = null;
}
public function read()
{
$billings = Billing::select('billings.*','create_tenders.tender_name','clients.client_name')
->join('create_tenders','billings.project_id', '=', 'create_tenders.id')
->join('clients','billings.client_id', '=', 'clients.id')
->whereDate('billings.invoice_date','>=',$this->from_date)
->where('billings.status', 1);
if ($this->search != null) {
if ($this->filter_by == 'tender_name') {
//dd($this->search);
$billings->where(function($query) {
$query->where('create_tenders.id', $this->search);
});
} elseif ($this->filter_by == 'client_name') {
$billings->where(function($query) {
$query->where('clients.id',$this->search);
});
}
}
return $billings->paginate($this->perPage);
}
public function render()
{
$org = Organisation::latest()->first();
$datatable = $this->read();
//dd($datatable);
$total_gross_amount = $datatable->sum('gross_amount');
$total_net_amount = $datatable->sum('net_amount');
$tenders = CreateTender::where('status', 1)->get();
$clients = Client::where('status', 1)->get();
return view('livewire.report.invoice-register-livewire',compact('datatable', 'org','total_gross_amount','total_net_amount','tenders','clients'));
}
}