| 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/BuyBackExport.php |
<?php
namespace App\Exports;
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 BuyBackExport implements FromQuery , WithHeadings , WithMapping
{
/**
* @return \Illuminate\Support\Collection
*/
// public function collection()
// {
// //
// }
private $no = 0;
private $search;
private $start_date;
private $end_date;
private $date;
public function __construct($search,$start_date,$end_date)
{
$this->search = $search;
$this->start_date = $start_date;
$this->end_date = $end_date;
}
/**
* @return \Illuminate\Support\Collection
*/
public function headings(): array
{
return [
'no',
__('message.invoice no'),
__('message.product category'),
__('message.name'),
__('message.buy back price'),
__('message.customer'),
__('message.customer phone'),
__('message.user'),
__('message.qty'),
__('message.weight'),
__('message.gold weight'),
__('message.wages'),
__('message.original wages'),
__('message.diamond size'),
__('message.buy back'),
__('message.buy back note'),
__('message.date buy back'),
];
}
public function query()
{
$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];
}
$search = $this->search;
if($search){
$sales = Sale::where('invoice_no' , 'like' , '%' . $search . '%')->where('already_buy_back' , true??1)->orderBy('id' , 'desc');
}else{
$sales = Sale::whereBetween('created_at', [$start_date . " 00:00:00", $end_date . " 23:59:59"])->where('already_buy_back' , true??1)->orderBy('id' , 'desc');
}
return $sales;
}
public function map($sale): array
{
$this->no++;
return [
$this->no,
$sale->invoice_no??'',
$sale->productCategory->name??'',
$sale->name??'',
number_format($sale->buy_back_price , 2),
$sale->member->name??'',
$sale->member->phone??'',
$sale->user->name??'',
$sale->qty??0,
$sale->weight,
$sale->goldWeight(),
number_format($sale->wages ,2),
number_format($sale->original_wages , 2),
htmlspecialchars(trim(strip_tags($sale->diamond_size))),
$sale->already_buy_back==1?__('message.yes'):__('message.no'),
$sale->buy_back_note,
date('d-M-Y H:i' , strtotime($sale->date_buy_back)),
];
}
}