protected function buildFile(array $orders, string $name)
    {
        if (false === $path = tempnam(sys_get_temp_dir(), $name)) {
            throw new RuntimeException("Failed to create temporary file.");
        }

        if (false === $handle = fopen($path, "w")) {
            throw new RuntimeException("Failed to open '$path' for writing.");
        }

        if (!empty($headers = $this->buildHeaders())) {
            fputcsv($handle, $headers, ';', '"');
        }

        $supplierTotal = 0;
        $forwarderTotal = 0;

        // Order rows
        foreach ($orders as $order) {
            if (!empty($row = $this->buildRow($order))) {
                fputcsv($handle, $row, ';', '"');

                $supplierTotal += $row['payment_total'];
                $forwarderTotal += $row['forwarder_total'];
            }
        }

        // Total row
        fputcsv($handle, [
            'id'                 => '',
            'number'             => '',
            'state'              => '',
            'ordered_at'         => '',
            'completed_at'       => '',
            'supplier'           => '',
            'payment_total'      => $supplierTotal,
            'payment_date'       => '',
            'payment_due_date'   => '',
            'carrier'            => '',
            'forwarder_total'    => $forwarderTotal,
            'forwarder_date'     => '',
            'forwarder_due_date' => '',
        ], ';', '"');

        fclose($handle);

        return $path;
    }