"UEA", "KGM" => "KGM", "PCE" => "UB" ]; /** * The Order to be exported * * @var \App\Models\Order * */ private $order; /** * Create a new notification instance. * * @param \App\Models\Order $order * @return void */ public function __construct(Order $order) { $this->order = $order; } /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ // phpcs:ignore public function via($notifiable) { return ['mail']; } /** * Get the mail representation of the notification. * * @param mixed $notifiable * @return \Illuminate\Notifications\Messages\MailMessage */ // phpcs:ignore public function toMail($notifiable) { $fileName = sprintf( 'BTQ-%s-%s%s.csv', $this->order->reference, date('Ymd_His'), \microtime(true) ); return (new MailMessage())->subject( sprintf( "%s - %s", config('app.name'), __('An order was placed') ) ) ->line( sprintf( "%s. %s : %s", __("An order was placed"), __("Attachement filename"), $fileName ) ) ->attachData( $this->makeCsv(), $fileName, ['mime' => 'text/csv'] ); } /** * Render Regate CSV for order. * * @return string */ private function makeCsv(): string { /** * Formatted array to make CSV * * @var array $csvlines */ $csvlines = []; foreach ($this->order->lines as $orderline) { array_push( $csvlines, [ $orderline->product->foodProduct->no_art, // 21/01/2022 : suppression du pcb ici $this->order->customer->salarie->matricule, $orderline->product->reference, "commande ferme", $orderline->product->order_unit ?? 'PCE', // UEA,KGM,UB (respectivement selon le champ précédent). $this->mode_commande[$orderline->product->order_unit ?? 'PCE'], // On vide la colonne pcb comme demandé. "", $this->order->timeslot->day->format('d/m/Y'), $orderline->quantity, $this->order->reference, ] ); } // Add header line. array_unshift($csvlines, $this->header); $f = fopen('php://temp', 'w'); foreach ($csvlines as $item) { fputcsv($f, $item, ";", '"', "\\"); } rewind($f); return stream_get_contents($f); } }