$libraries = $request->librarylists;
$stockArray = [];
$orderlists = CODOrder::whereIn('library_id', $libraries)->get();
foreach($orderlists as $sale)
{
$orderDetail = CODOrderDetails::where('order_id', $sale->id)->get();
$temp = [];
$tempbooks = [];
$temp['payment_mode'] = $sale->payment_type;
$add = json_decode($sale->address, true);
$temp['customer_name'] = $add['customername'];
$temp['customer_phone'] = $add['customerphone'];
foreach($orderDetail as $orderDetails)
{
$tempbooks['bookdiscount_Amount'] = $orderDetails->discount;
$tempbooks['bookfinal_Amount'] = $orderDetails->total;
$tempbooks['Books'] = $orderDetails->getBook->title . '-' . $orderDetails->quantity;
$tempbooks['Hardcopy_Amount'] = $orderDetails->selling_price;
$temp['bookdetails'][] = $tempbooks;
}
$stockArray[] = $temp;
}
return Excel::download(new LibraryOrderExport($stockArray), 'LibraryData.xlsx');
Here I want to export some order details based on a specific library.
I try to avoid duplicate entry's, so the main row only shows the common order details.
Each row have its on order details, so i want to display the all order details inside a Order Details cell.
class LibraryOrderExport implements FromCollection, WithHeadings, ShouldAutoSize
{
/**
* @return \Illuminate\Support\Collection
*/
protected $data;
public function __construct($data)
{
$this->data = $data;
}
public function collection()
{
return collect($this->data);
}
public function headings() : array {
return [
'Payment Mode',
'Customer Name',
'Customer Phone',
'Order Details'
];
}
public function title(): string
{
return $this->title;
}
}