/var/www/vhosts/nabawater/backend/models
Edit: /var/www/vhosts/nabawater/backend/models/DriverOrderSearch.php (6823B)
alias('AO')
->select(
new \yii\db\Expression("if(count(AO.order_id)>0, count(AO.order_id),0)")
)
->where('O.deliveryboy_id = AO.deliveryboy_id')
->andWhere(['order_status' => Order::ORDER_STATUS_DELIVERYBOY_ASSIGNED]);
$accepted_order_count = Order::find()
->alias('AO')
->select(
new \yii\db\Expression("if(count(AO.order_id)>0, count(AO.order_id),0)")
)
->where('O.deliveryboy_id = AO.deliveryboy_id')
->andWhere(['order_status' => Order::ORDER_STATUS_DELIVERYBOY_ACCEPTED]);
$on_order_count = Order::find()
->alias('AO')
->select(
new \yii\db\Expression("if(count(AO.order_id)>0, count(AO.order_id),0)")
)
->where('O.deliveryboy_id = AO.deliveryboy_id')
->andWhere(['order_status' => Order::ORDER_STATUS_READY_TO_PICKUP]);
$delivered_order_count = Order::find()
->alias('AO')
->select(
new \yii\db\Expression("if(count(AO.order_id)>0, count(AO.order_id),0)")
)
->where('O.deliveryboy_id = AO.deliveryboy_id')
->andWhere(['order_status' => Order::ORDER_STATUS_DELIVERED]);
$query = Order::find()
->alias('O')
->select([
'O.deliveryboy_id',
])
->addSelect(['total_assigned_order' => $assigned_order_count])
->addSelect(['total_accepted_order' => $accepted_order_count])
->addSelect(['total_one_the_way_order' => $on_order_count])
->addSelect(['total_delivered_order' => $delivered_order_count])
->andWhere(['not', ['deliveryboy_id' => null]])
->groupBy(['O.deliveryboy_id']);
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'defaultPageSize' => Com::postPerPage(),
],
'sort' => [
'attributes' => [
],
'defaultOrder' => [
]
]
]);
$this->load($params);
if(!$this->validate()) {
return $dataProvider;
}
$query->andFilterWhere(['like', 'deliveryboy_id', $this->deliveryboy_id]);
return $dataProvider;
}
/**
*
* @param type $params
* @return ActiveDataProvider
*/
public function orderSearch($params)
{
$query = Order::find()
->alias('O')
->select([
'O.*',
'U.username',
'BL.branch_name',
'CONCAT(O.customer_first_name, O.customer_last_name) as customer_name',
])
->leftJoin(['U' => User::tableName()], 'U.user_id = O.user_id')
->leftJoin(['BL' => BranchLang::tableName()], 'BL.branch_id = O.branch_id')
->andWhere(['not', ['deliveryboy_id' => null]]);
// ->groupBy(['O.deliveryboy_id']);
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'defaultPageSize' => Com::postPerPage(),
],
'sort' => [
'attributes' => [
],
'defaultOrder' => [
]
]
]);
$this->load($params);
if(!$this->validate()) {
return $dataProvider;
}
$query->andFilterWhere(['like', 'deliveryboy_id', $this->deliveryboy_id])
->andFilterWhere(['like', 'order_number', $this->order_number])
->andFilterWhere(['like', 'branch_name', $this->branch_name])
->andFilterWhere(['like', 'order_total', $this->order_total])
->andFilterWhere(['like', 'order_status', $this->order_status])
->andFilterWhere(['like', 'order_date_time', $this->order_date_time])
->andFilterWhere(['like', 'payment_status', $this->payment_status]);
return $dataProvider;
}
public function Driver()
{
$responseData = Com::getJsonData('GET', Configuration::get(Configuration::DELIVERY_BOY_ACCESS_URL) . "driver/company?company_id=" . Configuration::get(Configuration::COMPANY_KEY), [], 0);
if ($responseData == null || (isset($responseData) && $responseData->status == 404)) {
Yii::$app->session->setFlash('danger', Yii::t('backend', 'Server is down! Please try again some other time!'));
}
$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 : '',
'fleet_id' => (isset($dataValue->fleet_id)) ? $dataValue->fleet_id : '',
];
}
} else {
$resultData = [];
}
return $resultData;
}
}