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/GrnReportsExport.php |
<?php namespace App\Exports; use App\Models\QtyHistory; use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\FromQuery; use Maatwebsite\Excel\Concerns\WithHeadings; use Maatwebsite\Excel\Concerns\WithMapping; class GrnReportsExport implements FromQuery , WithHeadings , WithMapping { /** * @return \Illuminate\Support\Collection */ private $no = 0; private $q; private $grn; public function __construct($q , $grn) { $this->q = $q; $this->grn = $grn; } /** * @return \Illuminate\Support\Collection */ public function headings(): array { return [ 'no', __('message.grn'), __('message.part number'), __('message.product category'), __('message.name'), __('message.sales price'), __('message.qty'), __('message.cost'), __('message.wages'), __('message.original wages'), __('message.weight'), __('message.gold weight'), __('message.diamond size'), __('message.note'), __('message.user'), __('message.updated at'), ]; } public function query() { $query = QTYHistory::join('products', 'qty_histories.product_id', '=', 'products.id') ->where('qty_histories.grn', $this->grn); if ($this->q) { $query->where('products.part_number', $this->q); } return $query->with(['product.productCategory', 'user']) ->orderBy('qty_histories.id', 'desc'); } public function map($productQtyHistories): array { $this->no++; // Eager-loaded relationships $product = $productQtyHistories->product; $productCategory = $product->productCategory ?? null; $user = $productQtyHistories->user ?? null; return [ $this->no, $productQtyHistories->grn, $product->part_number ?? '', $productCategory ? $productCategory->name : '', $product->name ?? '', number_format($product->sellingPrice() ?? 0, 2), $productQtyHistories->qty ?? 0, number_format($product->sellingCost() ?? 0, 2), number_format($product->wages ?? 0, 2), number_format($product->original_wages ?? 0, 2), $product->weight ?? 0, $product->goldWeight() ?? 0, htmlspecialchars(trim(strip_tags($product->diamond_size))) ?? '', $productQtyHistories->note ?? '', $user ? $user->name : '', $productQtyHistories->created_at ? $productQtyHistories->created_at->format('d/m/y H:i') : '', ]; } }