Path : /var/www/html/jewelry-pos/app/Exports/ |
B-Con CMD Config cPanel C-Rdp D-Log Info Jump Mass Ransom Symlink vHost Zone-H |
Current File : /var/www/html/jewelry-pos/app/Exports/TransactionExport.php |
<?php namespace App\Exports; use App\Models\ProductCategoryWeightHistory; use App\Models\Sale; use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\FromQuery; use Maatwebsite\Excel\Concerns\WithHeadings; use Maatwebsite\Excel\Concerns\WithMapping; class TransactionExport implements WithHeadings , WithMapping , FromQuery { /** * @return \Illuminate\Support\Collection */ // public function collection() // { // // } private $no = 0; private $in_out; private $start_date; private $end_date; private $paginate; private $date; private $id; public function __construct($id ,$in_out,$start_date,$end_date,$paginate) { $this->id = $id; $this->in_out = $in_out; $this->start_date = $start_date; $this->end_date = $end_date; $this->paginate = $paginate; } /** * @return \Illuminate\Support\Collection */ public function headings(): array { return [ __('message.no'), __('message.product category'), __('message.weight'), __('message.weight before transaction'), __('message.weight after transaction'), __('message.note'), __('message.user'), __('message.created at'), ]; } public function query() { $paginate = $this->paginate??25; $start_date = $this->start_date ?? date('Y-m-d'); $end_date = $this->end_date ?? date('Y-m-d'); $dates = explode(' - ', $this->date); if ($this->date) { $start_date = $dates[0]; $end_date = $dates[1]; } $in_out = $this->in_out??0; $productCategoryWeightHistorys = ProductCategoryWeightHistory::where('product_category_id' , $this->id)->whereBetween('created_at', [$start_date . " 00:00:00", $end_date . " 23:59:59"])->orderBy('id' , 'desc'); if($this->in_out > 0){ $productCategoryWeightHistory = $productCategoryWeightHistorys->where('weight' , '>' , 0); }else if($this->in_out < 0){ $productCategoryWeightHistory = $productCategoryWeightHistorys->where('weight' , '<' , 0); }else{ $productCategoryWeightHistory = $productCategoryWeightHistorys; } return $productCategoryWeightHistory; } public function map($productCategoryWeightHistory): array { $this->no++; return [ $this->no, $productCategoryWeightHistory->productCategory->name??'', $productCategoryWeightHistory->weight, $productCategoryWeightHistory->weight_before_transaction, $productCategoryWeightHistory->weight_after_transaction, $productCategoryWeightHistory->note, $productCategoryWeightHistory->user->name??'', $productCategoryWeightHistory->created_at->format('d/m/y H:i'), ]; } }