/var/www/vhosts/nabawater/backend/controllers
Edit: /var/www/vhosts/nabawater/backend/controllers/AdminOrderReportController.php (3592B)
request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $searchModel->search(Yii::$app->request->queryParams),
'total_order' => $total_order,
'total_earnings' => $total_earnings
]);
}
/**
* @throws \Throwable
* @throws \yii\base\ExitException
*
* @Title("Export New")
*/
public function actionExport()
{
$searchModel = new AdminOrderReportSearch();
$dataProvider = $searchModel->search($_SESSION['admin_data']);
$model = $dataProvider->query->all();
$thead = [];
$tbody = [];
$theading = [
'order_number',
'Order Total',
'Item Total',
'Tax',
'Admin commission',
'Delivery Fee',
'Coupon Discount',
'Total Discount Value',
'Amount to Driver',
'Vendor Profit',
];
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Csv($spreadsheet);
$index = 1;
foreach ($theading as $key => $value) {
$sheet->setCellValueByColumnAndRow($index, 1,$theading[$key]);
$index++;
}
$fileName = 'Admin-Order-Report'.'-'.date('Y-m-d').'.csv';
$positionValue = 2;
foreach ($model as $key => $value) {
$sheet->setCellValue("A$positionValue", $value['order_number'])
->setCellValue("B$positionValue", number_format($value['order_total'],2))
->setCellValue("C$positionValue", number_format($value['item_total'],2))
->setCellValue("D$positionValue", number_format($value['vat'],2))
->setCellValue("E$positionValue", number_format($value['admin_commission'],2))
->setCellValue("F$positionValue", number_format($value['delivery_fee'],2))
->setCellValue("G$positionValue", number_format($value['coupon_offer_value'],2))
->setCellValue("H$positionValue", number_format($value['total_discount_value'],2))
->setCellValue("I$positionValue", number_format($value['delivery_fee'],2))
->setCellValue("J$positionValue", number_format($value['vendor_profit']),2);
++$positionValue;
}
// We'll be outputting an excel file
header('Content-type: text/x-csv');
// It will be called file.xls
header("Content-Disposition: attachment; filename=.$fileName");
$writer->save('php://output');
exit;
}
}