/var/www/vhosts/nabawater/backend/controllers
NameSizeModeActions
ActivityLogController.php16500644editdlrm
AddressTypeController.php64660644editdlrm
AdminOrderReportController.php35920644editdlrm
AdminUserController.php125230644editdlrm
AdsController.php97430644editdlrm
AreaController.php70190644editdlrm
BannerController.php71000644editdlrm
BranchController.php339890644editdlrm
BranchReviewController.php22090644editdlrm
CashBackPromotionsController.php120510644editdlrm
CategoryController.php87950644editdlrm
CityController.php55180644editdlrm
CmsController.php60260644editdlrm
ConfigurationController.php105640644editdlrm
CountryController.php52340644editdlrm
CouponController.php152450644editdlrm
CuisineController.php82070644editdlrm
DashboardController.php58050644editdlrm
DeliveryAreaController.php75060644editdlrm
DeliveryboyController.php76620644editdlrm
DeliveryChargeSettingsController.php45560644editdlrm
DriverOrderController.php35850644editdlrm
EnquiryController.php25410644editdlrm
FaqController.php65710644editdlrm
IngredientController.php69540644editdlrm
ItemController.php341500644editdlrm
ItemImportController.php38480644editdlrm
ItemIngredientGroupController.php111050644editdlrm
ItemMappingController.php121600644editdlrm
ItemTypeController.php74450644editdlrm
LanguageController.php38470644editdlrm
LoginController.php16840644editdlrm
LoyalityPointController.php66550644editdlrm
MallProductController.php63980644editdlrm
MetaTagController.php50390644editdlrm
MobileTranslationController.php44510644editdlrm
NewsLetterController.php52070664editdlrm
NewsletterController.php52070644editdlrm
NewsletterSubscriberController.php17470644editdlrm
NotificationController.php83820644editdlrm
OrderController.php937130644editdlrm
OrderMallProductController.php76610644editdlrm
OrderParcelController.php27520644editdlrm
OrderReportController.php39040644editdlrm
ParcelItemTypeController.php43570644editdlrm
PromotionController.php67100644editdlrm
PushNotificationController.php29900644editdlrm
RatingController.php6230644editdlrm
RefundRequestController.php29640644editdlrm
reject-index.php429310644editdlrm
RejectedOrderReportController.php5660644editdlrm
ReportController.php422320644editdlrm
RoleController.php52300644editdlrm
SiteController.php3570644editdlrm
StockController.php20670644editdlrm
TaxController.php45680644editdlrm
TodaySpecialController.php74730644editdlrm
TopOrderItemReportController.php38660644editdlrm
TopupController.php46190644editdlrm
UnitController.php71150644editdlrm
UserController.php135660644editdlrm
UserLevelController.php37870644editdlrm
VendorBankController.php28800644editdlrm
VendorController.php244910644editdlrm
VendorOrderReportController.php51460644editdlrm
VendorPaymentController.php60940644editdlrm
VendorTypeController.php84280644editdlrm
WalletController.php17910644editdlrm
WalletTranscationController.php22820644editdlrm
WebpushNotificationController.php25630644editdlrm
Edit: /var/www/vhosts/nabawater/backend/controllers/BranchController.php (33989B)
render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $searchModel->search(Yii::$app->request->queryParams) ] ); } /** * * @return string * * @Title("Create") */ public function actionCreate() { $model = new Branch(); $model->setScenario($model::SCENARIO_CREATE); $modelLang = new BranchLang(); $modelImage = new BranchImage(); $modelBranchDeliveryArea = new BranchDeliveryArea(); $modelDeliveryArea = new DeliveryArea(); $post = Yii::$app->getRequest()->post(); $modelVendor = new Vendor(); $modelBranchLang = new BranchLang(); $modelUploadForm = new BranchUploadForm(); $appLanguages = Language::getAppLanguages(); // print_r($post); // // exit; if(AdminUser::isVendor() || AdminUser::isBranch()) { $model->vendor_id = yii::$app->user->getId(); $model->approve_status = 1; } if ($model->load($post) && $modelLang->load($post) && $model->validate() ) { $modelBranchDeliveryArea->load($post); $password = $model->password; $model->setPassword(trim($model->password)); $model->user_name = isset($post['Branch']['user_name']) ? $post['Branch']['user_name'] : ''; $model->save(); $uploadHelper = UploadHelper::getInstance(); $branch_image_multi_path = Yii::$app->request->post('BranchImage'); if(!empty($branch_image_multi_path)){ foreach($branch_image_multi_path as $index=> $hall_image_multi_path1){ foreach($hall_image_multi_path1 as $index=> $branch_image_multi_path){ $path = $uploadHelper->getAbsPath($branch_image_multi_path); $uploadHelper->setPath($uploadHelper::BRANCH); $distPath = $uploadHelper->join([$uploadHelper->getPath(), basename($path)]); $uploadHelper->move($path, $distPath); $imagePath[] = $uploadHelper->getRealPath($distPath); } } } if (!empty($imagePath)) { foreach($imagePath as $image){ $modelimage = new BranchImage(); $modelimage->branch_id = $model->getPrimaryKey(); $modelimage->branch_image_path = $image; $modelimage->save(false); } } foreach($appLanguages as $langCode => $langName) { $modelTranslation = new BranchLang(); $modelTranslation->loadTranslationAttribute($post, $langCode); if (!empty($imagePath)){ foreach($imagePath as $image){ $modelTranslation->branch_image_path = '/'. $image ; } $modelTranslation->branch_address_line1 = $post['BranchLang']['branch_address_line1']; $modelTranslation->branch_address_line2 = $post['BranchLang']['branch_address_line2']; $modelTranslation->area = $post['BranchLang']['area']; $modelTranslation->city = $post['BranchLang']['city']; $modelTranslation->country = $post['BranchLang']['country']; $modelTranslation->branch_id = $model->getPrimaryKey(); $modelTranslation->save(); } else { $modelTranslation->branch_address_line1 = $post['BranchLang']['branch_address_line1']; $modelTranslation->branch_address_line2 = $post['BranchLang']['branch_address_line2']; $modelTranslation->area = $post['BranchLang']['area']; $modelTranslation->city = $post['BranchLang']['city']; $modelTranslation->country = $post['BranchLang']['country']; $modelTranslation->branch_id = $model->getPrimaryKey(); $modelTranslation->save(); } } $adminUserData = Yii::$app->getUser()->getIdentity(); $adminUserName = $adminUserData->attributes['user_name']; $branchName = $post['BranchLang']['branch_name']['en']; ActivityLog::log($adminUserName.' '. 'created New Branch named '.' '. $branchName); BranchDeliveryArea::deleteAll(['branch_id' => $model->getPrimaryKey()]); foreach ((array)$modelBranchDeliveryArea->delivery_area_id as $deliveryArea => $deliveryAreaId) { $modelbrnDeliveryArea = new BranchDeliveryArea(); $modelbrnDeliveryArea->branch_id = $model->getPrimaryKey(); $modelbrnDeliveryArea->delivery_area_id = $deliveryAreaId; if (!($modelbrnDeliveryArea->save())) { $data = $modelbrnDeliveryArea->attributes; $modelbrnDeliveryArea->setAttributes($data); return $this->render('create', [ 'model' => $model, 'modelLang' => $modelLang, 'modelVendor' => $modelVendor, 'modelBranchDeliveryArea' => $modelBranchDeliveryArea, 'modelDeliveryArea' => $modelDeliveryArea ]); } } $modelBranchDeliveryArea->save(); Com::successFlash(Yii::t('backend','Created Successfully')); return $this->redirect(['index']); } return $this->render('create', [ 'model' => $model, 'modelLang' => $modelLang, 'modelImage' => $modelImage, 'modelVendor' => $modelVendor, 'modelBranchLang' => $modelBranchLang, 'modelUploadForm' => $modelUploadForm, 'modelBranchDeliveryArea' => $modelBranchDeliveryArea, 'modelDeliveryArea' => $modelDeliveryArea, 'appLanguages' => $appLanguages ]); } /** * * @param type $id * @return type * * @Title("Update") */ public function actionUpdate($id) { $model = $this->findModel($id); $model->setScenario($model::SCENARIO_UPDATE); $modelImage = new BranchImage(); $modelLang = new BranchLang(); $modelVendor = new Vendor(); $modelBranchDeliveryAreaData = BranchDeliveryArea::find()->select(['GROUP_CONCAT(delivery_area_id) AS delivery_area_id'])->Where(['branch_id' => $model->getPrimaryKey()])->asArray()->one(); $modelBranchDeliveryArea = new BranchDeliveryArea(); $modelDeliveryArea = new DeliveryArea(); $modelUploadForm = new BranchUploadForm(); $modelUploadForm->setScenario($modelUploadForm::SCENARIO_UPDATE); $modelmultiimage = BranchImage::find()->where(['branch_id' => $model->getPrimaryKey()])->all(); $post = Yii::$app->getRequest()->post(); $appLanguages = Language::getAppLanguages(); BranchLang::updateTranslationAttribute($modelLang, $model->getPrimaryKey()); $modelBranchLang = BranchLang::findOne(['branch_id' => $model->getPrimaryKey()]); if($post){ $model->load($post); $model->payment_option = explode(",", $model->payment_option); } if ($model->validate() && $modelLang->load($post)) { $modelBranchDeliveryArea->load($post); if(AdminUser::isVendor()) { $model->vendor_id = yii::$app->user->getId(); } $model->user_name = isset($post['Branch']['user_name']) ? $post['Branch']['user_name'] : ''; $model->save(); $fileHelper = FileUploadHelper::getInstance()->convertFileArray(); $uploadHelper = UploadHelper::getInstance(); $branch_image_multi_path = Yii::$app->request->post('BranchImage'); if(!empty($branch_image_multi_path)) { foreach($branch_image_multi_path as $index=> $hall_image_multi_path1){ foreach($hall_image_multi_path1 as $index=> $branch_image_multi_path){ $path = $uploadHelper->getAbsPath($branch_image_multi_path); $uploadHelper->setPath($uploadHelper::BRANCH); $distPath = $uploadHelper->join([$uploadHelper->getPath(), basename($path)]); $uploadHelper->move($path, $distPath); $imagePath[] = $uploadHelper->getRealPath($distPath); } } } if (!empty($imagePath)) { foreach($imagePath as $image){ $modelimage = new BranchImage(); $modelimage->branch_id = $model->getPrimaryKey(); $modelimage->branch_image_path = $image; $modelimage->save(false); } } foreach ($appLanguages as $langCode => $langName) { $modelTranslation = BranchLang::findOne([ 'branch_id' => $model->getPrimaryKey(), 'language_code' => $langCode ]); if ($modelTranslation === null) { $modelTranslation = new BranchLang(); $modelTranslation->branch_id = $model->getPrimaryKey(); } $uploadedFile = $fileHelper->getFileInstance($modelUploadForm, 'branch_image_path', $langCode); if (!empty($imagePath)) { if (!empty($imagePath)) { foreach($imagePath as $image){ $modelTranslation->branch_image_path = '/'. $image ; } } $modelTranslation->branch_address_line1 = $post['BranchLang']['branch_address_line1']; $modelTranslation->branch_address_line2 = $post['BranchLang']['branch_address_line2']; $modelTranslation->area = $post['BranchLang']['area']; $modelTranslation->city = $post['BranchLang']['city']; $modelTranslation->country = $post['BranchLang']['country']; $modelTranslation->save(); } else { $modelTranslation->loadTranslationAttribute($post, $langCode); $modelTranslation->branch_id = $model->getPrimaryKey(); $modelTranslation->branch_address_line1 = $post['BranchLang']['branch_address_line1']; $modelTranslation->branch_address_line2 = $post['BranchLang']['branch_address_line2']; $modelTranslation->area = $post['BranchLang']['area']; $modelTranslation->city = $post['BranchLang']['city']; $modelTranslation->country = $post['BranchLang']['country']; $modelTranslation->save(); } } $adminUserData = Yii::$app->getUser()->getIdentity(); $adminUserName = $adminUserData->attributes['user_name']; $branchName = $post['BranchLang']['branch_name']['en']; ActivityLog::log($adminUserName.' '. 'updated Branch named '.' '. $branchName); BranchDeliveryArea::deleteAll(['branch_id' => $model->getPrimaryKey()]); foreach ((array)$modelBranchDeliveryArea->delivery_area_id as $deliveryArea => $deliveryAreaId) { $modelbrnDeliveryArea = new BranchDeliveryArea(); $modelbrnDeliveryArea->branch_id = $model->getPrimaryKey(); $modelbrnDeliveryArea->delivery_area_id = $deliveryAreaId; if (!($modelbrnDeliveryArea->save())) { $data = $modelbrnDeliveryArea->attributes; $modelbrnDeliveryArea->setAttributes($data); return $this->render('create', [ 'model' => $model, 'modelLang' => $modelLang, 'modelVendor' => $modelVendor, 'modelBranchDeliveryArea' => $modelBranchDeliveryArea, 'modelDeliveryArea' => $modelDeliveryArea, 'modelBranchDeliveryAreaData' => $modelBranchDeliveryAreaData, 'appLanguages' => $appLanguages ]); } } $modelBranchDeliveryArea->save(); Com::successFlash(Yii::t('backend','Updated Successfully')); return $this->redirect(['index']); } return $this->render('update', [ 'model' => $model, 'modelLang' => $modelLang, 'modelImage' => $modelImage, 'modelVendor' => $modelVendor, 'modelUploadForm' => $modelUploadForm, 'modelBranchDeliveryArea' => $modelBranchDeliveryArea, 'modelBranchLang' => $modelBranchLang, 'modelmultiimage' => $modelmultiimage, 'modelDeliveryArea' => $modelDeliveryArea, 'modelBranchDeliveryAreaData' => $modelBranchDeliveryAreaData, 'appLanguages' => $appLanguages ]); } /** * * @param type $id * @return string * * @Title("Delete") */ public function actionDelete($id) { $model = $this->findModel($id); if ($model === null) { Com::failureFlash('Unable to find the Branch'); return $this->redirect(['index']); } $model->branch_status = Branch::DELETE; $model->save(); $adminUserData = Yii::$app->getUser()->getIdentity(); $adminUserName = $adminUserData->attributes['user_name']; $branchName = BranchLang::find()->where(['branch_id' => $model->branch_id,'language_code' => Yii::$app->language])->one(); ActivityLog::log($adminUserName.' '. 'deleted branch '.' '. $branchName->branch_name); // $model = $this->findModel($id)->delete(); Com::successFlash(Yii::t('backend','Deleted Successfully')); return $this->redirect(['index']); } public function actionImage() { $modelItemImageUpload = new BranchImage(); $uploadedFile = UploadedFile::getInstance($modelItemImageUpload, 'branch_image_path'); if ($uploadedFile) { $modelItemImageUpload->branch_image_path = $uploadedFile; $uploadHelper = UploadHelper::getInstance(); $uploadHelper->setPath($uploadHelper->join([$uploadHelper::BRANCH])); $uploadHelper->setUploadedFile($uploadedFile); $path = $uploadHelper->getPath(true); if (!$uploadedFile->saveAs($path)) { throw new HttpException(400, $uploadedFile->error); } return $uploadHelper->getRealPath($path); } } public function actionImagedel() { $post = Yii::$app->getRequest()->post(); $result = ['status' => STATUS_FAIL, 'msg' => '']; $id = $post['id']; $x = Yii::$app->db->createCommand("DELETE FROM branch_image WHERE branch_image_id = '$id'")->execute(); Com::successFlash('Deleted Successfully'); if ($x) { $result['status'] = STATUS_SUCCESS; $result['msg'] = 'Deleted Successfully'; } skip: return $this->asJson($result); } /** * * @param type $id * @return $model * @throws NotFoundHttpException */ protected function findModel($id) { $filter = ['branch_key' => $id]; if(AdminUser::isVendor()){ $filter['vendor_id'] = yii::$app->user->getId(); } if (($model = Branch::findOne( $filter)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } } /** * * @return string * * @Title("Upload") */ public function actionUpload() { $modelItemImageUpload = new BranchImage(); $uploadedFile = UploadedFile::getInstance($modelItemImageUpload, 'branch_image_path'); if ($uploadedFile) { $modelItemImageUpload->branch_image_path = $uploadedFile; $uploadHelper = UploadHelper::getInstance(); $uploadHelper->setPath($uploadHelper->join([$uploadHelper::ITEM])); $uploadHelper->setUploadedFile($uploadedFile); $path = $uploadHelper->getPath(true); if (!$uploadedFile->saveAs($path)) { throw new HttpException(400, $uploadedFile->error); } return $uploadHelper->getRealPath($path); } //return throw new \yii\web\HttpException(400,$msg); /*$modelUploadForm = new BranchImage(); $file = UploadedFile::getInstance($modelUploadForm, 'branch_image_path'); $msg = Yii::t('backend', 'Unknown method'); if(!$file){ $msg = Yii::t('backend', 'Upload a file'); goto skip; } $modelUploadForm->branch_image_path = $file; if (!$modelUploadForm->validate()) { $msg= $modelUploadForm->getFirstError('branch_image_path'); goto skip; } $uploadHelper = UploadHelper::getInstance(); $join = $uploadHelper->join([$uploadHelper::TEMP,$uploadHelper::ITEM]); $uploadHelper->setpath($join); $uploadHelper->setUploadedFile($file); $path = $uploadHelper->getPath(true); $realpath = $uploadHelper->getRealPath($path); $file->saveAs($path); */ /* $result = ['original_path' => DIRECTORY_SEPARATOR .$realpath]; $result['thumb'] = DIRECTORY_SEPARATOR . $uploadHelper ->generateThumb($uploadHelper->getAbsPath($result['original_path'])); $result['large_path'] = DIRECTORY_SEPARATOR . $uploadHelper ->resize( $uploadHelper->getAbsPath($result['original_path']), ProductImage::LARGE_IMAGE_WIDTH );*/ return $this->asJson($result); skip: throw new \yii\web\HttpException(400,$msg); } /** * @return Json * @throws \yii\base\InvalidParamException * * @Title("Branch Status") */ public function actionChangeStatus() { $params = ['key', 'status']; $post = Yii::$app->getRequest()->post(); $result = ['status' => STATUS_FAIL, 'msg' => '']; foreach ($params as $param) { if (!array_key_exists($param, $post)) { $result['msg'] = 'Required param missing'; goto skip; } } $model = Branch::findOne(['branch_key' => $post['key']]); if ($model === null) { $result['msg'] = 'Unable to find the Branch'; goto skip; } $model->branch_status = $post['status']; $model->save(false); $result['msg'] = Yii::t('backend','Branch deactivated successfully'); if ((int)$model->branch_status === $model::ACTIVE) { $result['msg'] = Yii::t('backend','Branch activated successfully'); } $result['status'] = STATUS_SUCCESS; skip: return $this->asJson($result); } /** * * @return Json * @throws \yii\base\InvalidParamException * * @Title("Branch Availability Status") */ public function actionGetStatus() { $params = ['id', 'key']; $post = Yii::$app->getRequest()->post(); $result = ['status' => STATUS_FAIL, 'msg' => '']; foreach ($params as $param) { if (!array_key_exists($param, $post)) { $result['msg'] = 'Required param missing'; goto skip; } } $model = Branch::findOne(['branch_key' => $post['key']]); if ($model === null) { $result['msg'] = 'Unable to find the Branch'; goto skip; } else { $model->branch_availability_status = $post['id']; } $modelVendor = Vendor::findOne(['vendor_id' => $model->vendor_id]); if((int)$post['id'] === 1) { $status = 0; } else if((int)$post['id'] === 2) { $status = 1; } else if((int)$post['id'] === 4 ) { $status = 2; } $modelVendor->vendor_shop_status = $status; $modelVendor->save(false); $model->save(false); $result['msg'] = 'Availability Status Changed Successfully'; $result['status'] = STATUS_SUCCESS; skip: return $this->asJson($result); } /** * * @param type $id * @return string * * @Title("Time Slot") */ public function actionTimeSlot($id = '') { $timeSlotArray = [ 1 => 'SUNDAY', 2 => 'MONDAY', 3 => 'TUESDAY', 4 => 'WEDNESDAY', 5 => 'THURSDAY', 6 => 'FRIDAY', 7 => 'SATURDAY', ]; $brnTimeSlotData = []; $brnTimeSlotArray = BranchTimeslot::find() ->alias('BT') ->innerJoin(['B' => Branch::tableName()], 'B.branch_id = BT.branch_id') ->where(['B.branch_key' => $id]) ->asArray() ->all(); foreach ($brnTimeSlotArray as $key => $value) { $brnTimeSlotData[$value['timeslot_type']][$value['day_id']][] = [ 'id' => $value['branch_timeslot_key'], 'start' => ($value['timeslot_start_time'] != null) ? date('H:i', strtotime($value['timeslot_start_time'])) : null, 'end' => ($value['timeslot_end_time'] != null) ? date('H:i', strtotime($value['timeslot_end_time'])) : null, 'status' => $value['branch_timeslot_status'], ]; } $modelBranch = Branch::find()->select('V.order_type') ->alias('B') ->leftjoin(['V' => Vendor::tableName()], 'B.vendor_id = V.vendor_id') ->where(['B.branch_key' => $id]) ->one(); return $this->render('_timeslot', [ 'timeSlotArray' => $timeSlotArray, 'brnTimeSlotData' => $brnTimeSlotData, 'modelBranch' => $modelBranch ]); } /** * * @return Json * @throws \yii\base\InvalidParamException * * @Title("Time Slot Update") */ public function actionTimeSlotUpdate() { $params = ['id', 'type', 'day', 'timetype', 'value']; $post = Yii::$app->getRequest()->post(); $result = ['status' => STATUS_FAIL, 'msg' => '', 'checkbox_status' => 2, 'key' => '']; foreach ($params as $param) { if ( !array_key_exists($param, $post) ) { $result['msg'] = Yii::t('backend', 'Required param missing'); goto skip; } } $modelBranch = Branch::findOne(['branch_key' => $post['id']]); if ($modelBranch === null) { $result['msg'] = Yii::t('backend', 'Invalid branch'); goto skip; } if (empty($post['key'])) { $model = new BranchTimeslot(); $model->branch_id = $modelBranch->getPrimaryKey(); $model->timeslot_type = $post['day']; $model->day_id = $post['type']; $result['checkbox_status'] = 1; } else { $model = BranchTimeslot::findOne(['branch_timeslot_key' => $post['key']]); } if ($post['timetype'] == 1) { $model->timeslot_start_time = $post['value'].":00"; } else if ($post['timetype'] == 2) { $model->timeslot_end_time = $post['value'].":00"; } else { if ($post['value'] == 'true') { $model->branch_timeslot_status = BranchTimeslot::ACTIVE; } else { $model->branch_timeslot_status = BranchTimeslot::INACTIVE; } } $model->save(false); $result['key'] = $model->branch_timeslot_key; $result['msg'] = Yii::t('backend', 'Timeslot updated successfully'); $result['status'] = STATUS_SUCCESS; skip: return $this->asJson($result); } /** * * @return Json * @throws \yii\base\InvalidParamException * * @Title("Time Slot Delete") */ public function actionTimeSlotDelete() { $params = ['id']; $post = Yii::$app->getRequest()->post(); $result = ['status' => STATUS_FAIL, 'msg' => '']; foreach ($params as $param) { if ( !array_key_exists($param, $post) ) { $result['msg'] = Yii::t('backend', 'Required param missing'); goto skip; } } BranchTimeslot::deleteAll(['branch_timeslot_key' => $post['id']]); $result['msg'] = Yii::t('backend', 'Timeslot deleted successfully'); $result['status'] = STATUS_SUCCESS; skip: return $this->asJson($result); } /** * * @return Json * @throws \yii\base\InvalidParamException * * @Title("Save Reason") */ public function actionSaveReason() { $params = ['text', 'key']; $post = Yii::$app->getRequest()->post(); $result = ['status' => STATUS_FAIL, 'msg' => '']; foreach ($params as $param) { if ( !array_key_exists($param, $post) ) { $result['msg'] = Yii::t('backend', 'Required param missing'); goto skip; } } $model = Branch::findOne(['branch_key' => $post['key']]); if ($model === null) { $result['msg'] = 'Unable to find the Branch'; goto skip; } else { $model->busy_reason = $post['text']; $model->branch_availability_status = $post['status']; } $modelVendor = Vendor::findOne(['vendor_id' => $model->vendor_id]); if((int)$post['status'] === 1) { $status = 0; } else if((int)$post['status'] === 2) { $status = 1; } else if((int)$post['status'] === 4 ) { $status = 2; } $modelVendor->vendor_shop_status = $status; $modelVendor->save(false); $model->save(false); $result['msg'] = 'Reason Saved Successfully'; $result['status'] = STATUS_SUCCESS; skip: return $this->asJson($result); } /** * @return string */ public function actionGetBranch() { $post = Yii::$app->request->post(); $vendor_id = $post['id']; $result = ['branch_options' => '', 'category_options' => '']; $branches = Branch::find() ->alias('B') ->select([ 'BL.branch_name', 'BL.branch_id' ]) ->leftJoin(['BL' => BranchLang::tableName()], 'BL.branch_id = B.branch_id') ->where([ 'B.vendor_id' => $vendor_id, 'B.branch_status' => Branch::ACTIVE, 'BL.language_code' => Yii::$app->language ]) ->all(); $option = Html::tag('option', 'Please Select', ['value' => '']); foreach ($branches as $branch) { $option .= Html::tag('option', $branch->branch_name, ['value' => $branch->branch_id]); } $result['branch_options'] = $option; $categoryOption = Html::tag('option', 'Please Select', ['value' => '']); $vendorCategory = VendorCategory::find() ->select('GROUP_CONCAT(category_id) as category_id') ->where(['vendor_id' => $vendor_id]) ->asArray() ->all(); $categoryIds = explode(',', $vendorCategory[0]['category_id']); foreach ($categoryIds as $key => $value) { $categoryData = Category::find() ->alias('C') ->select([ 'CL.category_name', 'CL.category_id' ]) ->innerJoin(['CL' => CategoryLang::tableName()], 'CL.category_id = C.category_id') ->where(['CL.category_id' => $value]) ->one(); if ($categoryData !== null) { $categoryOption .= Html::tag('option', $categoryData->category_name, ['value' => $categoryData->category_id]); } else { continue; } } $result['category_options'] = $categoryOption; return $this->asJson($result); } /** * @throws \Throwable * @throws \yii\base\ExitException * * @Title("Export New") */ public function actionExport() { $searchModel = new BranchSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $model = $dataProvider->query->all(); $thead = []; $tbody = []; $theading = [ 'Branch Id', 'Branch Name', 'Vendor ID', 'Vendor Name', 'Branch Contact Number', 'Branch Email', ]; $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet); $index = 1; foreach ($theading as $key => $value) { $sheet->setCellValueByColumnAndRow($index, 1,$theading[$key]); $index++; } $fileName = 'Branch-Report'.'-'.date('Y-m-d').'.xslx'; $positionValue = 2; foreach ($model as $key => $value) { $sheet->setCellValue("A$positionValue", $value['branch_id']) ->setCellValue("B$positionValue", $value['branch_name']) ->setCellValue("C$positionValue", $value['vendor_id']) ->setCellValue("D$positionValue", $value['vendor_name']) ->setCellValue("E$positionValue", $value['contact_number']) ->setCellValue("F$positionValue", $value['contact_email']); ++$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; } public function actionQrCode() { $post = Yii::$app->request->post(); $qr = QrHelper::getInstance()->setFileName($post['key']) ->setQrCode($post['key'])->generate(); $uploadHelper = UploadHelper::getInstance(); return $uploadHelper->get($qr); } /** * @return string * @param type $id * * @Title("Change password") */ public function actionChangePassword() { $post = Yii::$app->getRequest()->post(); $result = ['status' => STATUS_FAIL, 'msg' => '', 'checkbox_status' => 2, 'key' => '']; $model = $this->findModel($post['Branch']['branch_key']); if ($model === null) { Com::failureFlash('Unable to find the Vendor'); return $this->redirect(['index']); } $model->setScenario($model::SCENARIO_CHANGE_PASSWORD); $model->load($post); $model->setPassword(trim($model->password)); $model->save(false); $result['msg'] = Yii::t('backend', 'Password changed successfully'); $result['status'] = STATUS_SUCCESS; skip: return $this->asJson($result); } }