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/SaleExport.php |
<?php namespace App\Exports; use App\Models\Product; 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 SaleExport implements FromQuery,WithHeadings,WithMapping { private $date; /** * @return \Illuminate\Support\Collection */ public function collection() { // return Sale::all(); } private $no = 0; private $search; private $start_date; private $end_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.part number'), __('message.product category'), __('message.name'), __('message.sales price'), __('message.usd price'), __('message.khr price'), __('message.thb price'), __('message.cost'), __('message.selling rate'), __('message.selling cost'), __('message.qty'), __('message.discount'), __('message.weight'), __('message.gold weight'), __('message.wages'), __('message.original wages'), __('message.selling purity'), __('message.purity upgrade to'), __('message.diamond size'), __('message.description'), __('message.supplier rate'), __('message.buy back'), // __('message.image'), __('message.user'), __('message.sale date'), ]; } 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('part_number' , 'like' , '%' . $search . '%')->orderBy('id' , 'desc'); return $sales; } $sales = Sale::whereBetween('created_at', [$start_date . " 00:00:00", $end_date . " 23:59:59"])->orderBy('id' , 'desc'); return $sales; } public function map($sale): array { $this->no++; if($sale->fixed_price || $sale->productCategory->fixed_price){ $this->fixed_price = __('message.yes'); $wages_in_weight = $sale->wages_in_weight; $original_wages_in_weight = $sale->original_wages_in_weight; }else{ $this->fixed_price = __('message.no'); $wages_in_weight = $sale->wages; $original_wages_in_weight = $sale->original_wages; } return [ $this->no, $sale->part_number, $sale->productCategory->name??'', $sale->name??'', number_format($sale->sales_price , 2), number_format($sale->usd_amount , 2), number_format($sale->khr_amount , 2), number_format($sale->thb_amount , 2), number_format($sale->cost() , 2), number_format($sale->selling_rate , 4), number_format($sale->selling_cost , 2), $sale->qty??0, number_format($sale->discount , 2), // $sale->weight, $sale->product->weight, // $sale->goldWeight(), $sale->product->goldWeight(), // number_format($sale->wages_in_weight , 2), $wages_in_weight, // number_format($sale->original_wages_in_weight , 2), $original_wages_in_weight, $sale->purity_upgrade_to??'', $sale->selling_purity??'', htmlspecialchars(trim(strip_tags($sale->diamond_size))), htmlspecialchars(trim(strip_tags($sale->description))), $sale->supplier_rate, $sale->already_buy_back==1?__('message.yes'):__('message.no'), // $sale->image, $sale->user->name??'', $sale->created_at->format('d/m/y H:i'), ]; } }