/var/www/vhosts/nabawater/backend/controllers
Edit: /var/www/vhosts/nabawater/backend/controllers/ReportController.php (42232B)
data)) {
foreach ($responseData->data as $dataKey => $dataValue) {
$resultData[] = [
'id' => $dataValue->_id,
'key' => $dataValue->_id,
'name' => $dataValue->name,
'status' => $dataValue->status,
'email' => $dataValue->email,
'phone_number' => $dataValue->phone_number,
'country' => $dataValue->country,
'city' => $dataValue->city,
'address' => $dataValue->address,
'is_approved' => $dataValue->is_approved,
'vendor_key' => (isset($dataValue->vendor_key)) ? $dataValue->vendor_key : '',
];
}
}
$responseData = ArrayHelper::map($resultData,'id', 'name');
if(Yii::$app->request->isAjax){
$data = [];
$get = Yii::$app->getRequest()->get();
$table_col = [
// 0 => 'bill_id',
0 => 'deliveryboy_id',
1 => 'OIL.item_name',
2 => 'OI.quantity',
3 => 'order_number',
4 => 'branch_name',
];
$get['sSearch'] = $_GET['search']['value'];
$draw = $_GET['draw'];
$columnIndex = $_GET['order'][0]['column']; // Column index
$columnName = $_GET['columns'][$columnIndex]['data']; // Column name
$columnSortOrder = $_GET['order'][0]['dir']; // asc or desc
$modelData = OrderItem::find()->alias('OI')
->select([
'O.deliveryboy_id',
'OIL.item_name',
'sum(OI.quantity) as quantity',
'O.order_number',
'BL.branch_name'
])
->leftJoin(['O' => Order::tableName()], 'OI.order_id = O.order_id')
->leftJoin(['OIL' => OrderItemLang::tableName()], 'OI.order_item_id = OIL.order_item_id and OIL.language_code = :lang',['lang' => \Yii::$app->language])
->leftJoin(['BL' => BranchLang::tableName()], 'BL.branch_id = O.branch_id and BL.language_code = :lang',['lang' => \Yii::$app->language])
->where(['OR',
['like', 'O.deliveryboy_id', $get['sSearch']],
['like', 'OIL.item_name', $get['sSearch']],
['like', 'quantity', $get['sSearch']],
['like', 'order_number', $get['sSearch']],
['like', 'branch_name', $get['sSearch']],
])->andWhere(['O.order_status' => Order::ORDER_STATUS_DELIVERED])
->groupBy(['O.deliveryboy_id','OI.item_id']);
if($from != null){
$modelData = $modelData->andwhere(['>=','DATE(O.order_date_time)', Date('Y-m-d', strtotime($from))]);
}
if($to != null){
$modelData = $modelData->andwhere(['<=', 'DATE(O.order_date_time)', Date('Y-m-d', strtotime($to))]);
}
if(isset($table_col[$columnIndex])) {
$modelData = $modelData->orderBy([$table_col[$columnIndex] => $columnSortOrder == 'asc' ? SORT_ASC : SORT_DESC ]);
}
$modelResult = clone $modelData;
$modelData = $modelData->limit($_GET['length'])->offset($_GET['start'])->asArray()->all();
foreach ($modelData as $key => $value) {
$data[] = [
"driver_name" => isset($responseData[$value['deliveryboy_id']]) ? $responseData[$value['deliveryboy_id']] : '' ,
"item_name" => $value['item_name'],
"qty" => $value['quantity'],
"order_number" => $value['order_number'],
"branch_name" => $value['branch_name'],
];
}
$response = [
"draw" => $draw,
"iTotalRecords" => $modelResult->count(),
"iTotalDisplayRecords" => $modelResult->count(),
"aaData" => $data
];
return $this->asJson($response);
die('-');
}
return $this->render('index');
}
/**
*
* @return string
*
* @Title("All Wallet Report")
*/
public function actionAllWallet($from = null, $to = null)
{
if(Yii::$app->request->isAjax){
$data = [];
$get = Yii::$app->getRequest()->get();
$table_col = [
// 0 => 'bill_id',
0 => 'first_name',
1 => 'last_name',
2 => 'email',
3 => 'mobile_number',
4 => 'wallet_point',
];
$get['sSearch'] = $_GET['search']['value'];
$draw = $_GET['draw'];
$columnIndex = $_GET['order'][0]['column']; // Column index
$columnName = $_GET['columns'][$columnIndex]['data']; // Column name
$columnSortOrder = $_GET['order'][0]['dir']; // asc or desc
$modelData = User::find()
->where(['OR',
['like', 'first_name', $get['sSearch']],
['like', 'last_name', $get['sSearch']],
['like', 'email', $get['sSearch']],
['like', 'mobile_number', $get['sSearch']],
['like', 'wallet_point', $get['sSearch']],
])->andWhere(['<>', 'status', User::DELETE]);
if($from != null){
$modelData = $modelData->andwhere(['>=','DATE(created_at)', Date('Y-m-d', strtotime($from))]);
}
if($to != null){
$modelData = $modelData->andwhere(['<=', 'DATE(created_at)', Date('Y-m-d', strtotime($to))]);
}
if(isset($table_col[$columnIndex])) {
$modelData = $modelData->orderBy([$table_col[$columnIndex] => $columnSortOrder == 'asc' ? SORT_ASC : SORT_DESC ]);
}
$modelResult = clone $modelData;
$modelData = $modelData->limit($_GET['length'])->offset($_GET['start'])->asArray()->all();
foreach ($modelData as $key => $value) {
$data[] = [
"first_name" => $value['first_name'],
"last_name" => $value['last_name'],
"email" => $value['email'],
"mobile_number" => $value['mobile_number'],
"wallet_point" => $value['wallet_point'],
];
}
$response = [
"draw" => $draw,
"iTotalRecords" => $modelResult->count(),
"iTotalDisplayRecords" => $modelResult->count(),
"aaData" => $data
];
return $this->asJson($response);
die('-');
}
return $this->render('index');
}
/**
*
* @return string
*
* @Title("All Wallet Report")
*/
public function actionTopUp($from = null, $to = null)
{
if(Yii::$app->request->isAjax){
$data = [];
$get = Yii::$app->getRequest()->get();
$table_col = [
// 0 => 'bill_id',
0 => 'first_name',
1 => 'last_name',
2 => 'email',
3 => 'mobile_number',
4 => 'amount',
5 => 'updated_at',
];
$get['sSearch'] = $_GET['search']['value'];
$draw = $_GET['draw'];
$columnIndex = $_GET['order'][0]['column']; // Column index
$columnName = $_GET['columns'][$columnIndex]['data']; // Column name
$columnSortOrder = $_GET['order'][0]['dir']; // asc or desc
$modelData = WalletTransaction::find()
->alias('WT')
->select([
'U.*',
'WT.amount',
'WT.updated_at'
])
->leftJoin(['U' => User::tableName()], 'U.user_key = WT.user_key')
->where(['OR',
['like', 'U.first_name', $get['sSearch']],
['like', 'U.last_name', $get['sSearch']],
['like', 'U.email', $get['sSearch']],
['like', 'U.mobile_number', $get['sSearch']],
['like', 'amount', $get['sSearch']],
['like', 'WT.updated_at', $get['sSearch']],
])->andWhere(['<>', 'status', User::DELETE])
->andWhere(['=', 'transaction_type', WalletTransaction::TRANS_TYPE_RECHARGE])
->andWhere(['=', 'transaction_status', WalletTransaction::TRANSACTION_SUCCESS]);
if($from != null){
$modelData = $modelData->andwhere(['>=','DATE(WT.updated_at)', Date('Y-m-d', strtotime($from))]);
}
if($to != null){
$modelData = $modelData->andwhere(['<=', 'DATE(WT.updated_at)', Date('Y-m-d', strtotime($to))]);
}
if(isset($table_col[$columnIndex])) {
$modelData = $modelData->orderBy([$table_col[$columnIndex] => $columnSortOrder == 'asc' ? SORT_ASC : SORT_DESC ]);
}
$modelResult = clone $modelData;
$modelData = $modelData->limit($_GET['length'])->offset($_GET['start'])->asArray()->all();
foreach ($modelData as $key => $value) {
$data[] = [
"first_name" => $value['first_name'],
"last_name" => $value['last_name'],
"email" => $value['email'],
"mobile_number" => $value['mobile_number'],
"amount" => $value['amount'],
"updated_at" => $value['updated_at'],
];
}
$response = [
"draw" => $draw,
"iTotalRecords" => $modelResult->count(),
"iTotalDisplayRecords" => $modelResult->count(),
"aaData" => $data
];
return $this->asJson($response);
die('-');
}
return $this->render('index');
}
/**
*
* @return string
*
* @Title("All Wallet Report")
*/
public function actionUserSpent($from = null, $to = null)
{
if(Yii::$app->request->isAjax){
$data = [];
$get = Yii::$app->getRequest()->get();
$table_col = [
// 0 => 'bill_id',
0 => 'first_name',
1 => 'last_name',
2 => 'mobile_number',
3 => 'cod_amount',
4 => 'online_amount',
5 => 'wallet_amount',
];
$get['sSearch'] = $_GET['search']['value'];
$draw = $_GET['draw'];
$columnIndex = $_GET['order'][0]['column']; // Column index
$columnName = $_GET['columns'][$columnIndex]['data']; // Column name
$columnSortOrder = $_GET['order'][0]['dir']; // asc or desc
$modelData = User::find()
->alias('U')
->select([
'U.*',
'SUM(IF(O.payment_option = 1,O.order_total,0)) AS cod_amount',
'SUM(IF(O.payment_option = 2,O.order_total,0)) AS online_amount',
'SUM(IF(O.payment_option = 3,O.order_total,0)) AS wallet_amount',
//'sum(Oc.order_total) as cod_amount',
//'sum(Oo.order_total) as online_amount',
//'sum(Ow.order_total) as wallet_amount',
])
->leftJoin(['O' => Order::tableName()], 'U.user_id = O.user_id')
// ->andFilterWhere(['OR',
// ['like', 'U.first_name', $get['sSearch']],
// ['like', 'U.last_name', $get['sSearch']],
// ['like', 'U.mobile_number', $get['sSearch']],
// //['like', "wallet_amount", $get['sSearch']],
// ])
->HAVING(['OR',
['like', 'cod_amount', $get['sSearch']],
['like', 'online_amount', $get['sSearch']],
['like', 'wallet_amount', $get['sSearch']],
['like', 'U.first_name', $get['sSearch']],
['like', 'U.last_name', $get['sSearch']],
['like', 'U.mobile_number', $get['sSearch']],
])
->andWhere(['<>', 'status', User::DELETE])
->andFilterWhere([
'or',
[
'and',
['=', 'O.payment_status', Order::PAYMENT_STATUS_SUCCESS],
['<>', 'O.payment_option', Order::PAYMENT_OPTION_COD]
],
[
'and',
['=','O.payment_option' ,Order::PAYMENT_OPTION_COD]
],
[
'and',
['=','O.payment_option' ,Order::PAYMENT_OPTION_WALLET]
]
])
->andWhere(['<>', 'O.order_status', Order::ORDER_STATUS_IS_DELETE])
->groupBy(['U.user_id']);
// print_r($modelData->createCommand()->getRawSql()); die;
if($from != null){
$modelData = $modelData->andwhere(['>=','DATE(U.created_at)', Date('Y-m-d', strtotime($from))]);
}
if($to != null){
$modelData = $modelData->andwhere(['<=', 'DATE(U.created_at)', Date('Y-m-d', strtotime($to))]);
}
if(isset($table_col[$columnIndex])) {
$modelData = $modelData->orderBy([$table_col[$columnIndex] => $columnSortOrder == 'asc' ? SORT_ASC : SORT_DESC ]);
}
$modelResult = clone $modelData;
$modelData = $modelData->limit($_GET['length'])->offset($_GET['start'])->asArray()->all();
foreach ($modelData as $key => $value) {
$data[] = [
"first_name" => $value['first_name'],
"last_name" => $value['last_name'],
"mobile_number" => $value['mobile_number'],
"cod_amount" => $value['cod_amount'],
"online_amount" => $value['online_amount'],
"wallet_amount" => $value['wallet_amount'],
];
}
$response = [
"draw" => $draw,
"iTotalRecords" => $modelResult->count(),
"iTotalDisplayRecords" => $modelResult->count(),
"aaData" => $data
];
return $this->asJson($response);
die('-');
}
return $this->render('index');
}
/**
*
* @return string
*
* @Title("Order Daily Report")
*/
public function actionDailyOrder($from = null, $to = null)
{
$responseData = Com::getJsonData('GET', Configuration::get(Configuration::DELIVERY_BOY_ACCESS_URL) . "driver/company?company_id=" . Configuration::get(Configuration::COMPANY_KEY), [], 0);
$resultData = [];
if (isset($responseData->data)) {
foreach ($responseData->data as $dataKey => $dataValue) {
$resultData[] = [
'id' => $dataValue->_id,
'key' => $dataValue->_id,
'name' => $dataValue->name,
'status' => $dataValue->status,
'email' => $dataValue->email,
'phone_number' => $dataValue->phone_number,
'country' => $dataValue->country,
'city' => $dataValue->city,
'address' => $dataValue->address,
'is_approved' => $dataValue->is_approved,
'vendor_key' => (isset($dataValue->vendor_key)) ? $dataValue->vendor_key : '',
];
}
}
$responseData = ArrayHelper::map($resultData,'id', 'name');
if(Yii::$app->request->isAjax){
$data = [];
$get = Yii::$app->getRequest()->get();
$table_col = [
// 0 => 'bill_id',
0 => 'deliveryboy_id',
1 => 'customer_first_name',
2 => 'customer_last_name',
3 => 'order_number',
4 => 'quantity',
5 => 'order_type',
6 => 'order_status',
];
$get['sSearch'] = $_GET['search']['value'];
$draw = $_GET['draw'];
$columnIndex = $_GET['order'][0]['column']; // Column index
$columnName = $_GET['columns'][$columnIndex]['data']; // Column name
$columnSortOrder = $_GET['order'][0]['dir']; // asc or desc
$modelData = Order::find()
->alias('O')
->select([
'O.deliveryboy_id',
'O.customer_first_name',
'O.customer_last_name',
'O.order_number',
'sum(OI.quantity) as quantity',
'O.order_type',
'O.order_status',
])
->leftJoin(['OI' => OrderItem::tableName()], 'OI.order_id = O.order_id')
->where(['OR',
['like', 'deliveryboy_id', $get['sSearch']],
['like', 'customer_first_name', $get['sSearch']],
['like', 'customer_last_name', $get['sSearch']],
['like', 'order_number', $get['sSearch']],
//['like', 'mobile_number', $get['sSearch']],
['like', 'order_type', $get['sSearch']],
['like', 'order_status', $get['sSearch']],
])->andFilterWhere([
'or',
[
'and',
['=', 'O.payment_status', Order::PAYMENT_STATUS_SUCCESS],
['<>', 'O.payment_option', Order::PAYMENT_OPTION_COD]
],
[
'and',
['=','O.payment_option' ,Order::PAYMENT_OPTION_COD]
],
[
'and',
['=','O.payment_option' ,Order::PAYMENT_OPTION_WALLET]
]
])
->andWhere(['<>', 'O.order_status', Order::ORDER_STATUS_IS_DELETE])
->groupBy(['O.order_id']);
if($from != null){
$modelData = $modelData->andwhere(['>=','DATE(O.order_date_time)', Date('Y-m-d', strtotime($from))]);
}
if($to != null){
$modelData = $modelData->andwhere(['<=', 'DATE(O.order_date_time)', Date('Y-m-d', strtotime($to))]);
}
if(isset($table_col[$columnIndex])) {
$modelData = $modelData->orderBy([$table_col[$columnIndex] => $columnSortOrder == 'asc' ? SORT_ASC : SORT_DESC ]);
}
$modelResult = clone $modelData;
$modelData = $modelData->limit($_GET['length'])->offset($_GET['start'])->asArray()->all();
foreach ($modelData as $key => $value) {
$data[] = [
"deliveryboy_id" => isset($responseData[$value['deliveryboy_id']]) ? $responseData[$value['deliveryboy_id']] : '' ,
"customer_first_name" => $value['customer_first_name'],
"customer_last_name" => $value['customer_last_name'],
"order_number" => $value['order_number'],
"quantity" => $value['quantity'],
"order_type" => Order::getOrderTypeLabel($value['order_type']),
"order_status" => Order::getOrderStatusLabel($value['order_status']),
];
}
$response = [
"draw" => $draw,
"iTotalRecords" => $modelResult->count(),
"iTotalDisplayRecords" => $modelResult->count(),
"aaData" => $data
];
return $this->asJson($response);
die('-');
}
return $this->render('index');
}
/**
*
* @return string
*
* @Title("Activity Report")
*/
public function actionActivity($from = null, $to = null)
{
if(Yii::$app->request->isAjax){
$data = [];
$get = Yii::$app->getRequest()->get();
$table_col = [
// 0 => 'bill_id',
0 => 'username',
1 => 'log',
2 => 'client_ip',
3 => 'client_agent',
4 => 'client_platform',
5 => 'created_at',
];
$get['sSearch'] = $_GET['search']['value'];
$draw = $_GET['draw'];
$columnIndex = $_GET['order'][0]['column']; // Column index
$columnName = $_GET['columns'][$columnIndex]['data']; // Column name
$columnSortOrder = $_GET['order'][0]['dir']; // asc or desc
$modelData = ActivityLog::find()->where(['OR',
['like', 'username', $get['sSearch']],
['like', 'log', $get['sSearch']],
['like', 'client_ip', $get['sSearch']],
['like', 'client_agent', $get['sSearch']],
['like', 'client_platform', $get['sSearch']],
['like', 'created_at', $get['sSearch']],
]);
if($from != null){
$modelData = $modelData->andwhere(['>=','DATE(created_at)', Date('Y-m-d', strtotime($from))]);
}
if($to != null){
$modelData = $modelData->andwhere(['<=', 'DATE(created_at)', Date('Y-m-d', strtotime($to))]);
}
if(isset($table_col[$columnIndex])) {
$modelData = $modelData->orderBy([$table_col[$columnIndex] => $columnSortOrder == 'asc' ? SORT_ASC : SORT_DESC ]);
}
$modelResult = clone $modelData;
$modelData = $modelData->limit($_GET['length'])->offset($_GET['start'])->orderBy(['activity_log_id' => SORT_DESC])->asArray()->all();
foreach ($modelData as $key => $value) {
$data[] = [
"username" => $value['username'],
"log" => $value['log'],
"client_ip" => $value['client_ip'],
"client_agent" => $value['client_agent'],
"client_platform" => $value['client_platform'],
"created_at" => $value['created_at'],
];
}
$response = [
"draw" => $draw,
"iTotalRecords" => $modelResult->count(),
"iTotalDisplayRecords" => $modelResult->count(),
"aaData" => $data
];
return $this->asJson($response);
die('-');
}
return $this->render('index');
}
/**
*
* @return string
*
* @Title("Customer Report")
*/
public function actionCustomerReport($from = null, $to = null)
{
if(Yii::$app->request->isAjax){
$data = [];
$get = Yii::$app->getRequest()->get();
$table_col = [
// 0 => 'bill_id',
0 => 'first_name',
1 => 'last_name',
2 => 'email',
3 => 'mobile_number',
4 => 'status',
5 => 'wallet_point',
];
$get['sSearch'] = $_GET['search']['value'];
$draw = $_GET['draw'];
$columnIndex = $_GET['order'][0]['column']; // Column index
$columnName = $_GET['columns'][$columnIndex]['data']; // Column name
$columnSortOrder = $_GET['order'][0]['dir']; // asc or desc
$modelData = User::find()->select(['*', 'IF(status =1,"Active","In-Active") as status_value'])
->where(['OR',
['like', 'first_name', $get['sSearch']],
['like', 'last_name', $get['sSearch']],
['like', 'email', $get['sSearch']],
['like', 'mobile_number', $get['sSearch']],
// ['like', 'status', $get['sSearch']],
['like', 'wallet_point', $get['sSearch']],
])->HAVING(['OR',
['like', 'status_value', $get['sSearch']],
]);
if($from != null){
$modelData = $modelData->andwhere(['>=','DATE(created_at)', Date('Y-m-d', strtotime($from))]);
}
if($to != null){
$modelData = $modelData->andwhere(['<=', 'DATE(created_at)', Date('Y-m-d', strtotime($to))]);
}
//print_r($get['sSearch']); die;
if(isset($table_col[$columnIndex])) {
$modelData = $modelData->orderBy([$table_col[$columnIndex] => $columnSortOrder == 'asc' ? SORT_ASC : SORT_DESC ]);
}
$modelResult = clone $modelData;
$modelData = $modelData->limit($_GET['length'])->offset($_GET['start'])->asArray()->all();
foreach ($modelData as $key => $value) {
$data[] = [
"first_name" => $value['first_name'],
"last_name" => $value['last_name'],
"email" => $value['email'],
"mobile_number" => $value['mobile_number'],
"status" => $value['status_value'],
"wallet_point" => $value['wallet_point'],
];
}
$response = [
"draw" => $draw,
"iTotalRecords" => $modelResult->count(),
"iTotalDisplayRecords" => $modelResult->count(),
"aaData" => $data
];
return $this->asJson($response);
die('-');
}
return $this->render('index');
}
/**
*
* @return string
*
* @Title("Customer Report")
*/
public function actionCustomerSalesReport($from = null, $to = null)
{
if(Yii::$app->request->isAjax){
$data = [];
$get = Yii::$app->getRequest()->get();
$table_col = [
// 0 => 'bill_id',
0 => 'first_name',
1 => 'last_name',
2 => 'email',
3 => 'mobile_number',
4 => 'order_total',
5 => 'total_subscription_price',
6 => 'order_date_time',
];
$get['sSearch'] = $_GET['search']['value'];
$draw = $_GET['draw'];
$columnIndex = $_GET['order'][0]['column']; // Column index
$columnName = $_GET['columns'][$columnIndex]['data']; // Column name
$columnSortOrder = $_GET['order'][0]['dir']; // asc or desc
$modelData = Order::find()
->alias('O')
->select(['U.*', 'Sum(O.order_total) as order_total','Sum(O.total_subscription_price) as total_subscription_price', 'Date(O.order_date_time) as order_date_time'])
->leftJoin(['U' => User::tableName()], 'U.user_id = O.user_id')
->where(['OR',
['like', 'first_name', $get['sSearch']],
['like', 'last_name', $get['sSearch']],
['like', 'email', $get['sSearch']],
['like', 'mobile_number', $get['sSearch']],
])->HAVING(['OR',
['like', 'order_total', $get['sSearch']],
['like', 'total_subscription_price', $get['sSearch']],
['like', 'order_date_time', $get['sSearch']],
])
->andFilterWhere([
'or',
[
'and',
['=', 'O.payment_status', Order::PAYMENT_STATUS_SUCCESS],
['<>', 'O.payment_option', Order::PAYMENT_OPTION_COD]
],
[
'and',
['=','O.payment_option' ,Order::PAYMENT_OPTION_COD]
],
[
'and',
['=','O.payment_option' ,Order::PAYMENT_OPTION_WALLET]
]
])
->andWhere(['NOT IN', 'O.order_status', [Order::ORDER_STATUS_IS_DELETE,Order::ORDER_STATUS_IS_CUSTOMER_CANCELED,Order::ORDER_STATUS_REJECTED]])
->groupBy(['Date(O.order_date_time)','O.user_id']);
if($from != null){
$modelData = $modelData->andwhere(['>=','DATE(O.order_date_time)', Date('Y-m-d', strtotime($from))]);
}
if($to != null){
$modelData = $modelData->andwhere(['<=', 'DATE(O.order_date_time)', Date('Y-m-d', strtotime($to))]);
}
if(isset($table_col[$columnIndex])) {
$modelData = $modelData->orderBy([$table_col[$columnIndex] => $columnSortOrder == 'asc' ? SORT_ASC : SORT_DESC ]);
}
$modelResult = clone $modelData;
$modelData = $modelData->limit($_GET['length'])->offset($_GET['start'])->asArray()->all();
foreach ($modelData as $key => $value) {
$data[] = [
"first_name" => $value['first_name'],
"last_name" => $value['last_name'],
"email" => $value['email'],
"mobile_number" => $value['mobile_number'],
"order_total" => $value['order_total'],
"total_subscription_price" => $value['total_subscription_price'],
"order_date_time" => $value['order_date_time'],
];
}
$response = [
"draw" => $draw,
"iTotalRecords" => $modelResult->count(),
"iTotalDisplayRecords" => $modelResult->count(),
"aaData" => $data
];
return $this->asJson($response);
die('-');
}
return $this->render('index');
}
public function actionSuccessOrder()
{
$searchModel = new OrderSearch();
return $this->render('order-sucess', [
'searchModel' => $searchModel,
'dataProvider' => $searchModel->Sucesssearch(Yii::$app->request->queryParams),
]);
}
public function actionOrdersReportExport()
{
$thead = [];
$tbody = [];
$theading = [
'Order Id',
'Customer name',
'Customer phone',
'Branch name',
'Order State',
'Amount',
'VAT',
'Delivery Fee',
'Commission',
'Payment Status',
'Creation Date',
'Creation Time',
];
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$searchModel = new OrderSearch();
$model = $searchModel->SucessRepo(Yii::$app->request->queryParams)->query->asArray()->all();
$index = 1;
foreach ($theading as $key => $value) {
$sheet->setCellValueByColumnAndRow($index, 1,$theading[$key]);
$index++;
}
// $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
$sheet->setTitle("1Successfull Orders");
$positionValue = 2;
foreach ($model as $key => $value) {
$sheet->setCellValue("A$positionValue", $value['order_number'])
->setCellValue("B$positionValue", $value['customer_name'])
->setCellValue("C$positionValue", $value['customer_mobile_number'])
->setCellValue("D$positionValue", $value['branch_name'])
->setCellValue("E$positionValue", Order::getOrderStatusLabel($value['order_status']))
->setCellValue("F$positionValue", $value['order_total'])
->setCellValue("G$positionValue", $value['vat'])
->setCellValue("H$positionValue", $value['delivery_fee'])
->setCellValue("I$positionValue", $value['admin_profit'])
->setCellValue("J$positionValue", Order::getPaymentOptionLabel($value['payment_option']))
->setCellValue("K$positionValue", date('d-m-Y', strtotime($value['order_date_time'])))
->setCellValue("L$positionValue", $value['order_date_time']);
++$positionValue;
}
$sheet = $spreadsheet->createSheet(1);
$sheet = $spreadsheet->setActiveSheetIndex(1);
$sheet->setTitle("2FailerRejected Orders ");
$thead = [];
$tbody = [];
$theading = [
'Order Id',
'Customer name',
'Customer phone',
'Branch name',
'Order State',
'Amount',
'VAT',
'Delivery Fee',
'Commission',
'Payment Status',
'Creation Date',
'Creation Time',
];
$index = 1;
foreach ($theading as $key => $value) {
$sheet->setCellValueByColumnAndRow($index, 1,$theading[$key]);
$index++;
}
$searchModel = new OrderSearch();
$model = $searchModel->Failure(Yii::$app->request->queryParams)->query->asArray()->all();
// $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
$positionValue = 2;
foreach ($model as $key => $value) {
$sheet->setCellValue("A$positionValue", $value['order_number'])
->setCellValue("B$positionValue", $value['customer_name'])
->setCellValue("C$positionValue", $value['customer_mobile_number'])
->setCellValue("D$positionValue", $value['branch_name'])
->setCellValue("E$positionValue", Order::getOrderStatusLabel($value['order_status']))
->setCellValue("F$positionValue", $value['order_total'])
->setCellValue("G$positionValue", $value['vat'])
->setCellValue("H$positionValue", $value['delivery_fee'])
->setCellValue("I$positionValue", $value['admin_profit'])
->setCellValue("J$positionValue", Order::getPaymentOptionLabel($value['payment_option']))
->setCellValue("K$positionValue", date('d-m-Y', strtotime($value['order_date_time'])))
->setCellValue("L$positionValue", $value['order_date_time']);
++$positionValue;
}
$sheet = $spreadsheet->createSheet(2);
$sheet = $spreadsheet->setActiveSheetIndex(2);
$sheet->setTitle("3Restaurant Delivery");
$thead = [];
$tbody = [];
$theading = [
'Order Id',
'Branch name',
'Order State',
'Amount',
'VAT',
'Delivery Fee',
'Commission',
'Payment Status',
'Creation Date',
'Creation Time',
];
$searchModel = new OrderSearch();
$model = $searchModel->SucessRepo(Yii::$app->request->queryParams)->query->asArray()->all();
$index = 1;
foreach ($theading as $key => $value) {
$sheet->setCellValueByColumnAndRow($index, 1,$theading[$key]);
$index++;
}
// $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
$positionValue = 2;
foreach ($model as $key => $value) {
$sheet->setCellValue("A$positionValue", $value['order_number'])
->setCellValue("B$positionValue", $value['branch_name'])
->setCellValue("C$positionValue", Order::getOrderStatusLabel($value['order_status']))
->setCellValue("D$positionValue", $value['order_total'])
->setCellValue("E$positionValue", $value['vat'])
->setCellValue("F$positionValue", $value['delivery_fee'])
->setCellValue("G$positionValue", $value['admin_profit'])
->setCellValue("H$positionValue", Order::getPaymentOptionLabel($value['payment_option']))
->setCellValue("I$positionValue", date('d-m-Y', strtotime($value['order_date_time'])))
->setCellValue("J$positionValue", $value['order_date_time']);
++$positionValue;
}
$writer = new Xlsx($spreadsheet);
$filename = 'Report_'.date('d-m-Y');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'. $filename .'.xlsx"');
header('Cache-Control: max-age=0');
$writer->save('php://output'); // download file
exit;
}
public function actionOrdersReportFinall()
{
$searchModel = new OrderSearch();
return $this->render('order-sucess-report', [
'searchModel' => $searchModel,
'dataProvider' => $searchModel->Sucess(Yii::$app->request->queryParams),
]);
}
public function actionOrdersReportFinallExport()
{
$thead = [];
$tbody = [];
$theading = [
'Order Id',
'Order Creation date',
'Delivery Boy',
'Customer Name',
'Branch Name',
'Customer City',
'Customer Street',
'Address',
'Order State',
'Order Total',
'Delivery Fee',
'discount',
'Grand Total',
'commission',
'Payment Status',
'wallet Rewarded point for the order transaction'
];
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$searchModel = new OrderSearch();
$model = $searchModel->Sucess(Yii::$app->request->queryParams)->query->asArray()->all();
$index = 1;
foreach ($theading as $key => $value) {
$sheet->setCellValueByColumnAndRow($index, 1,$theading[$key]);
$index++;
}
// $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
$sheet->setTitle("Reports");
$positionValue = 2;
foreach ($model as $key => $value) {
$orderModel = ArrayHelper::toArray(Order::findOne($value['order_id']));
// $total = (double)$value['order_total'] + (double)$value['coupon_offer_value'];
//print_r($)
if(!isset($orderModel['customer_address']['city'])) {
//print_r($orderModel['customer_address']['city']); die;
}
$sheet->setCellValue("A$positionValue", $value['order_number'])
->setCellValue("B$positionValue", $value['order_date_time'])
->setCellValue("C$positionValue", '')
->setCellValue("D$positionValue", $value['customer_name'])
->setCellValue("E$positionValue", $value['branch_name'])
->setCellValue("F$positionValue", isset($orderModel['customer_address']['city']) ? $orderModel['customer_address']['city'] : '')
->setCellValue("G$positionValue", isset($orderModel['customer_address']['street_name']) ? $orderModel['customer_address']['street_name'] : '')
->setCellValue("H$positionValue", isset($orderModel['customer_address']['flat_no']) ? $orderModel['customer_address']['flat_no'] : '')
->setCellValue("I$positionValue", Order::getOrderStatusLabel($value['order_status']))
->setCellValue("J$positionValue", $value['order_total'])
->setCellValue("K$positionValue", $value['delivery_fee'])
->setCellValue("L$positionValue", $value['coupon_offer_value'])
->setCellValue("M$positionValue", $value['overall_Total'])
->setCellValue("N$positionValue", $value['admin_profit'])
->setCellValue("O$positionValue", Order::getPaymentOptionLabel($value['payment_option']))
->setCellValue("P$positionValue", $value['promotion_amount']);
++$positionValue;
}
$writer = new Xlsx($spreadsheet);
$filename = 'Wallet_Point_Report_'.date('d-m-Y');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'. $filename .'.xlsx"');
header('Cache-Control: max-age=0');
$writer->save('php://output'); // download file
exit;
}
}