Файловый менеджер - Редактировать - /home/clickysoft/public_html/travel-guru.clickysoft.net/app/Exports/AllOrderDataExport.php
Назад
<?php namespace App\Exports; use App\Models\LunchOrder; use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\WithHeadings; use Maatwebsite\Excel\Concerns\WithEvents; use Maatwebsite\Excel\Events\AfterSheet; class AllOrderDataExport implements FromCollection, WithHeadings, WithEvents { protected $orders; protected $mergingCells = []; public function __construct($orders) { $this->orders = $orders; } public function headings(): array { return [ "Order Number", "Parent Name", "Parent Email", "Order Type", "Order Status", "Child Name", "Child Grade", "T Shirt Size", "Item", "Price", "Annual Due", "School Directory Quantity Total", "School Directory Price Total", "Annual Graduation Total", "Community Service Total", "Discount", "Final Price" ]; } /** * @return \Illuminate\Support\Collection */ public function collection() { $dataSet = []; $mainCounter = 1; foreach ($this->orders as $order){ $mainCounter++; $rowStart = $mainCounter; $orderNumber = $order->lunchPayment->transaction_id; $parentName = $order->user->full_name; $parentEmail = $order->user->email; $orderType = $order->type; $orderStatus = $order->status; $annualDue = $order->annual_due; $schoolDirectoryQuantityTotal = !empty($order->school_directory_quantity)?$order->school_directory_quantity:"-"; $schoolDirectoryPriceTotal = !empty($order->school_directory_price)?$order->school_directory_price:"-"; $annualGraduationTotal = !empty($order->annual_graduation_contribution)?$order->annual_graduation_contribution:"-"; $communityServiceTotal = !empty($order->community_service)?$order->community_service:"-"; $discount = !empty($order->discount)?$order->discount:"-"; $finalPrice = $order->final_price; foreach ($order->children as $childKey => $child){ if ($childKey > 0){ $mainCounter++; } if ($order->type === LunchOrder::LUNCH_PROGRAM){ foreach ($child->childItems as $itemKey => $item){ if ($itemKey > 0){ $mainCounter++; } $dataSet[] = (object)[ 'order_number' => $orderNumber, 'parent_name' => $parentName, 'parent_email' => $parentEmail, 'order_type' => $orderType, 'order_status' => $orderStatus, 'child_name' => $child->full_name, 'child_grade' => $child->grade->title, 't_type' => $child->t_type, 'item' => $item->item->name, 'price' => $item->price, 'annual_due' => $annualDue, 'school_directory_quantity_total' => $schoolDirectoryQuantityTotal, 'school_directory_price_total' => $schoolDirectoryPriceTotal, 'annual_graduation_total' => $annualGraduationTotal, 'community_service_total' => $communityServiceTotal, 'discount' => $discount, 'final_price' => $finalPrice ]; } }else{ $dataSet[] = (object)[ 'order_number' => $orderNumber, 'parent_name' => $parentName, 'parent_email' => $parentEmail, 'order_type' => $orderType, 'order_status' => $orderStatus, 'child_name' => $child->full_name, 'child_grade' => $child->grade->title, 't_type' => $child->t_type, 'item' => "-", 'price' => "-", 'annual_due' => $annualDue, 'school_directory_quantity_total' => $schoolDirectoryQuantityTotal, 'school_directory_price_total' => $schoolDirectoryPriceTotal, 'annual_graduation_total' => $annualGraduationTotal, 'community_service_total' => $communityServiceTotal, 'discount' => $discount, 'final_price' => $finalPrice ]; } } array_push($this->mergingCells, ['start_from' => $rowStart, 'end' => $mainCounter]); } return collect($dataSet); } public function registerEvents(): array { return [ AfterSheet::class => function (AfterSheet $event) { foreach ($this->mergingCells as $val){ $startPoint = $val['start_from']; $endPoint = $val['end']; $event->sheet->getDelegate()->mergeCells('A'.$startPoint.':A'.$endPoint); $event->sheet->getDelegate()->mergeCells('B'.$startPoint.':B'.$endPoint); $event->sheet->getDelegate()->mergeCells('C'.$startPoint.':C'.$endPoint); $event->sheet->getDelegate()->mergeCells('D'.$startPoint.':D'.$endPoint); $event->sheet->getDelegate()->mergeCells('E'.$startPoint.':E'.$endPoint); $event->sheet->getDelegate()->mergeCells('I'.$startPoint.':I'.$endPoint); $event->sheet->getDelegate()->mergeCells('J'.$startPoint.':J'.$endPoint); $event->sheet->getDelegate()->mergeCells('K'.$startPoint.':K'.$endPoint); $event->sheet->getDelegate()->mergeCells('L'.$startPoint.':L'.$endPoint); $event->sheet->getDelegate()->mergeCells('M'.$startPoint.':M'.$endPoint); $event->sheet->getDelegate()->mergeCells('N'.$startPoint.':N'.$endPoint); $event->sheet->getDelegate()->mergeCells('O'.$startPoint.':O'.$endPoint); } }, ]; } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.29 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка