Skip to content

Instantly share code, notes, and snippets.

@jongravois
Created July 27, 2020 09:19
Show Gist options
  • Save jongravois/c0da7a0709d6de3e3d84547394067952 to your computer and use it in GitHub Desktop.
Save jongravois/c0da7a0709d6de3e3d84547394067952 to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Livewire\Invoices;
use App\Models\Invoice;
use Carbon\Carbon;
use Kdion4891\LaravelLivewireTables\Column;
use Kdion4891\LaravelLivewireTables\TableComponent;
class InvoicesTable extends TableComponent
{
public $checkbox = true;
public $checkbox_side = 'left';
public $sort_attribute = 'invoice_date';
public $sort_direction = 'desc';
public $per_page = 100;
public $table_class = 'w-full uam-ultra-condensed-table';
public $thead_class = 'uam';
public $start;
public $end;
public $sales;
// protected $casts = [
// 'start' => 'date',
// 'end' => 'date'
// ];
public function mount($start=null, $end=null, $sales=null)
{
$this->setTableProperties();
$this->start = $start;
$this->end = $end;
//$this->sales = $sales ? $sales : null;
}
public function query()
{
if($this->sales) {
$invoices = Invoice::whereBetween('invoice_date', [$this->start, $this->end])->whereSalespersonCode($this->sales);
} else {
$invoices = Invoice::whereBetween('invoice_date', [$this->start, $this->end]);
} // end if
return $invoices;
}
public function columns()
{
return [
Column::make('ID', 'invc_number')->searchable()->sortable(),
Column::make('Invoiced', 'invoice_date')->searchable()->sortable(),
Column::make('Posted', 'post_date')->searchable()->sortable(),
Column::make('Type', 'route_code')->searchable()->sortable(),
Column::make('Lot', 'consignment_code')->searchable()->sortable(),
Column::make('Percent', 'consignment_percentage')->searchable()->sortable()
->view('livewire.invoices.percent'),
Column::make('SO#', 'so_number')->searchable()->sortable(),
Column::make('Seller', 'salesperson_code')->searchable()->sortable(),
Column::make('Description')->searchable()->sortable(),
Column::make('PN#', 'pn')->searchable()->sortable(),
Column::make('MSN', 'serial_number')->searchable()->sortable(),
Column::make('QTY', 'qty_invoiced')->sortable(),
Column::make('Price', 'unit_price')->sortable()
->view('livewire.invoices.price'),
Column::make('Cost', 'unit_cost')->sortable()
->view('livewire.invoices.cost'),
Column::make('Gross', 'gross')->sortable()
->view('livewire.invoices.gross'),
Column::make('Net', 'net')->sortable()
->view('livewire.invoices.net'),
Column::make('Profit', 'profit')->sortable()
->view('livewire.invoices.profit'),
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment