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/ProductExport.php |
<?php namespace App\Exports; use App\Models\Product; use App\Models\ProductCategory; use GuzzleHttp\Psr7\Query; use http\Env\Request; use Illuminate\Support\Facades\Auth; use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\FromQuery; use Maatwebsite\Excel\Concerns\WithDrawings; use Maatwebsite\Excel\Concerns\WithHeadings; use Maatwebsite\Excel\Concerns\WithMapping; use PhpOffice\PhpSpreadsheet\Worksheet\Drawing; use PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing; class ProductExport implements FromQuery,WithHeadings,WithMapping { private $no = 0; private $q; private $for_sale; private $category; private $paginate; private $fixed_price; private $price; private $wages_in_weight; public function __construct($q , $for_sale , $category , $paginate) { $this->q = $q; $this->for_sale = $for_sale; $this->category = $category; $this->paginate = $paginate??25; } /** * @return \Illuminate\Support\Collection */ public function headings(): array { return [ 'no', __('message.part number'), __('message.supplier rate'), __('message.gia number'), __('message.supplier'), __('message.product category'), __('message.name'), __('message.qty'), __('message.cost'), __('message.sales price'), __('message.fixed price'), __('message.diamond size'), __('message.weight'), __('message.gold weight'), __('message.active'), __('message.description'), __('message.wages'), __('message.original wages'), __('message.selling purity'), // __('message.image'), __('message.user'), __('message.created at'), ]; } public function query() { $products = Product::query(); if($this->q){ $q = $this->q; $products = $products->where(function($query) use ($q){ $query->where('part_number', 'like', '%'.$q.'%'); }); } if($this->for_sale>=0 && $this->for_sale!=null){ $products = $products->where('for_sale',$this->for_sale); } if($this->category){ $products = $products->where('product_category_id',$this->category); } $products = $products->orderBy('id', 'desc'); return $products; } // public function drawings() // { // $drawing = new Drawing(); // $drawing->setPath(public_path($product->image)); //// $drawing->setHeight(20); // $drawing->setWidth(100); // $drawing->setCoordinates('M2'); // $drawings [] = ($drawing); // return $drawings; // } public function map($product): array { if($product->fixed_price || $product->productCategory->fixed_price){ $this->fixed_price = __('message.yes'); $wages_in_weight = $product->wages_in_weight; $original_wages_in_weight = $product->original_wages_in_weight; $this->price = number_format($product->price , 2); }else{ $this->fixed_price = __('message.no'); $wages_in_weight = $product->selling_wagesInWeight(); $original_wages_in_weight = $product->cost_wagesInWeight(); $this->price = number_format($product->sellingPrice() , 2); } // $drawingss = new Drawing(); $this->no++; return [ $this->no, $product->part_number, $product->supplier_rate??0, $product->gia_number??'', $product->supplier->name??'', $product->productCategory->name??'', $product->name??'', $product->qty??0, number_format($product->sellingCost() , 2), $this->price, $this->fixed_price, htmlspecialchars(trim(strip_tags($product->diamond_size))), $product->weight, $product->goldWeight(), $product->is_active ? 'active' : 'inactive', htmlspecialchars(trim(strip_tags($product->description))), $wages_in_weight??0, $original_wages_in_weight??0, $product->selling_purity??'', // $drawingss, // $product->image, $product->user->name??'', $product->created_at->format('d/m/y H:i'), ]; } }