public function actionPayment()
 {
     $headers = Yii::$app->request->getHeaders();
     if ($headers->has('X-TERMINAL')) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         $model = new PaymentForm();
         if ($model->hasError()) {
             return $model->getError();
         }
         $transaction = Transaction::create();
         $connector = new CateringConnector();
         $response = $connector->pay($transaction);
         if (in_array($response['status'], ['error', 'redirect'])) {
             return $response;
         }
         $transaction->is_fulfilled = true;
         $transaction->save();
         return ['status' => 'success'];
     }
     Yii::$app->getSession()->set('payer.account_type', Yii::$app->request->get('account_type'));
     $bills = Bill::find()->where(['enabled' => true])->select('denomination')->asArray()->all();
     $denominations = [];
     foreach ($bills as $bill) {
         $denominations[] = $bill['denomination'];
     }
     Yii::$app->get('xmlrpc')->enableBillTypes();
     return $this->render('payment', ['denominations' => implode(', ', $denominations)]);
 }
Пример #2
0
 public function enableBillTypes()
 {
     $bills = Bill::find()->select('bill_type')->where(['enabled' => true])->asArray()->all();
     $data = [];
     foreach ($bills as $bill) {
         $data[] = (int) $bill['bill_type'];
     }
     $this->sendCommand('enable_bill_types', [$data]);
 }
Пример #3
0
 public function actionIndex()
 {
     $post = Yii::$app->request->post();
     if ($post && array_key_exists('bills', $post)) {
         Bill::updateAll(['enabled' => false]);
         $updatedBills = $post['bills'];
         foreach ($updatedBills as $billType => $status) {
             /** @var Bill $bill */
             $bill = Bill::findOne(['bill_type' => $billType]);
             $bill->enabled = $status === 'on';
             $bill->save();
         }
         Yii::$app->session->setFlash('bills_updated');
     }
     $bills = Bill::find()->all();
     return $this->render('index', ['bills' => $bills]);
 }
Пример #4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function searchWithPerson($params)
 {
     $query = Bill::find();
     $query->innerJoinWith('price');
     $query->joinWith('billPersonals');
     $query->orderBy(BillPersonal::tableName() . '.updated_at DESC');
     if (isset($params['id'])) {
         $query->where([BillPersonal::tableName() . '.personal_id' => $params['id']]);
         $query->orWhere([BillPersonal::tableName() . '.personal_id' => null]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => new Sort(['attributes' => [self::tableName() . '.id', 'price_total' => ['asc' => ['price.total' => SORT_ASC], 'desc' => ['price.total' => SORT_DESC]], 'discount', 'bp_paid' => ['asc' => [BillPersonal::tableName() . '.paid' => SORT_ASC], 'desc' => [BillPersonal::tableName() . '.paid' => SORT_DESC]], 'bp_description' => ['asc' => [BillPersonal::tableName() . '.description' => SORT_ASC], 'desc' => [BillPersonal::tableName() . '.description' => SORT_DESC]], 'bp_amount' => ['asc' => [BillPersonal::tableName() . '.amount' => SORT_ASC], 'desc' => [BillPersonal::tableName() . '.amount' => SORT_DESC]], self::tableName() . '.created_at', self::tableName() . '.updated_at'], 'defaultOrder' => [self::tableName() . '.updated_at' => SORT_DESC]])]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     if ($this->bp_paid == 0) {
         $this->bp_paid = null;
     }
     $query->andFilterWhere([self::tableName() . '.id' => $this->id, 'price_id' => $this->price_id, 'discount' => $this->discount, self::tableName() . '.created_at' => $this->created_at, self::tableName() . '.updated_at' => $this->updated_at, BillPersonal::tableName() . '.paid' => $this->bp_paid]);
     $query->andFilterWhere(['like', 'price.total', $this->price_total]);
     $query->andFilterWhere(['like', BillPersonal::tableName() . '.amount', $this->bp_amount]);
     $query->andFilterWhere(['like', BillPersonal::tableName() . '.description', $this->bp_description]);
     return $dataProvider;
 }