예제 #1
0
 /**
  * Displays a particular model.
  * @param integer $id the ID of the model to be displayed
  */
 public function actionIndex()
 {
     $this->layout = 'clean';
     //$this->layout='main';
     //echo \yii\helpers\Json::encode("ok");
     //Yii::$app->end();
     if (isset($_POST['Company'])) {
         $id = (int) $_POST['Company'];
         //
         //if has access
         //$database= Company::findOne($id);
         Yii::info($id);
         //Yii::$app->user->setState('Database',$database );
         //Yii::$app->user->setState('Company',$id);
         //echo 'ok';
         //Company::select($id);
         Yii::$app->session['company'] = $id;
         //redirect
         return \app\helpers\Response::send(200, $id);
     }
     if ($this->company != 0) {
         Yii::$app->session['company'] = 0;
         //unset(Yii::$app->session['company']);
         return $this->redirect(\yii\helpers\BaseUrl::base() . '/company/index');
         \Yii::$app->end();
     }
     $model = new Company();
     ////$model->unsetAttributes();  // clear any default values
     return $this->render('index', array('model' => $model));
 }
예제 #2
0
 public function actionError()
 {
     //var_dump (Yii::$app->errorHandler->exception);
     //exit;
     $this->layout = 'single';
     if (isset(Yii::$app->errorHandler->error) && ($error = Yii::$app->errorHandler->error)) {
         if (strpos(Yii::$app->request->url, 'api') != true) {
             //if (Yii::$app->request->isAjaxRequest)
             //    return $error['message'];
             //else
             return $this->render('error', ['error' => $error]);
         } else {
             return \app\helpers\Response::send($error->statusCode, $error->getMessage());
         }
     } elseif (isset(Yii::$app->errorHandler->exception) && ($exception = Yii::$app->errorHandler->exception)) {
         if (strpos(Yii::$app->request->url, 'api') != true) {
             //if (Yii::$app->request->isAjaxRequest)
             //    return $exception['message'];
             //else
             return $this->render('error', ['error' => $exception]);
         } else {
             return \app\helpers\Response::send($exception->statusCode, $exception->getMessage());
         }
     } else {
         //if ($error = Yii::$app->errorHandler->error)
         return \app\helpers\Response::send(500, 'Unknown error');
     }
 }
예제 #3
0
 public function actionCalc()
 {
     $model = new Docdetails();
     if (isset($_POST['Docdetails']['line'])) {
         $i = $_POST['Docdetails']['line'];
         $model->attributes = $_POST['Docdetails'][$i];
         if (isset($_POST['CalcPriceWithVat'])) {
             return Response::send(200, $model->CalcPriceWithVat());
         }
         if (isset($_POST['CalcPriceWithOutVat'])) {
             return Response::send(200, $model->CalcPriceWithOutVat());
         }
         return Response::send(200, $model->CalcPrice());
     }
 }
예제 #4
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Item();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         if (Yii::$app->request->post('ajax') !== null) {
             return \app\helpers\Response::send(200, $model);
         }
         //$model->pic->saveAs('/to/localFile');
         return $this->redirect(array('admin', 'id' => $model->id));
     }
     if (Yii::$app->request->post('ajax') !== null) {
         return \app\helpers\Response::send(501, $model->errors);
     }
     $model->sku = $model->maxId() + 1;
     $model->parent_item_id = 0;
     return $this->render('create', array('model' => $model));
 }
예제 #5
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate($type = 0, $parent_account_id = 0)
 {
     $model = new Accounts(['type' => (int) $type, 'parent_account_id' => (int) $parent_account_id]);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         if (Yii::$app->request->post('ajax') !== null) {
             return \app\helpers\Response::send(200, $model);
         }
         //$model->deleteEavAttributes();
         //if (isset($_POST['AccounteavE']) && isset($_POST['AccounteavE'])) {
         //    $model->setEavAttributes(array_combine($_POST['AccounteavE'], $_POST['AccounteavV']));
         //}
         if (!$this->hasCallback()) {
             return $this->redirect(array('accounts/admin/' . $model->type));
         }
     }
     if (Yii::$app->request->post('ajax') !== null) {
         return \app\helpers\Response::send(501, $model->errors);
     }
     //$model->accType = Acctype::findOne((int) $type);
     //$model->type = $type;
     return $this->render('create', array('model' => $model));
 }
예제 #6
0
 public function actionDelete($model, $id)
 {
     if ($this->hasAccess($model . '/delete')) {
         $modelName = $this->translate($model);
         $loadedModel = $modelName::findOne($id);
         // Was a model found? If not, raise an error
         if ($loadedModel === null) {
             Response::send(400, sprintf("Error: Didn't find any model <b>%s</b> with ID <b>%s</b>.", $model, $id));
         }
         // Delete the model
         $num = $loadedModel->delete();
         if ($num > 0) {
             Response::send(200, $num);
         } else {
             Response::send(500, sprintf("Error: Couldn't delete model <b>%s</b> with ID <b>%s</b>.", $model, $id));
         }
     } else {
         Response::send(403, sprintf('Error: Mode <b>delete</b> is not implemented for model <b>%s</b>', $model));
     }
 }
예제 #7
0
 public function actionRefstatus($id)
 {
     $model = $this->findModel((int) $id);
     $model->refstatus = !$model->refstatus;
     if ($model->save(false)) {
         return \app\helpers\Response::send(200, true);
     } else {
         return \app\helpers\Response::send(500, $model->errors);
     }
 }
예제 #8
0
 public function actionGetrate($id)
 {
     \app\helpers\Response::send(200, Currates::GetRate($id));
 }