示例#1
0
 /**
  * Save payment in database
  *
  * @param $user_id
  * @param $amount
  * @return integer id
  */
 public function saveCharge($user_id, $amount)
 {
     $payment = new Payments();
     $payment->user_id = $user_id;
     $payment->amount = $amount;
     $payment->method = 'STRIPE';
     $payment->save();
     return $payment->id;
 }
示例#2
0
 public static function addPayments($input, $id)
 {
     $data = new Payments();
     $data->idexpense = $id;
     $data->name = $input['name'];
     $data->date = time();
     $data->type = $input['type'];
     $data->price = $input['price'];
     $data->save();
 }
示例#3
0
 public function actionFormSubmission($id = null)
 {
     $data = Yii::$app->request->post();
     if (isset($data['type'])) {
         Payments::addPayments($data, $id);
     }
     $searchModel = new Payments();
     $expenses = Expenses::getByid(['id' => $id]);
     $departments = Departments::getByid(['id' => $expenses[0]['iddepartment']]);
     $params = ['idexpense' => $id];
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams, $params);
     $breadcrumbs[] = ['label' => $departments[0]['name'], 'url' => ['/department/' . $departments[0]['id']]];
     $breadcrumbs[] = $expenses[0]['name'];
     return $this->render('expenses', ['dataProvider' => $dataProvider, 'breadcrumbs' => $breadcrumbs, 'id' => $id, 'data' => $data, 'searchModel' => $searchModel]);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Payments::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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;
     }
     $query->andFilterWhere(['id' => $this->id, 'customer_id' => $this->customer_id, 'timestamp' => $this->timestamp]);
     $query->andFilterWhere(['like', 'mpesa_id', $this->mpesa_id])->andFilterWhere(['like', 'original', $this->original])->andFilterWhere(['like', 'destination', $this->destination])->andFilterWhere(['like', 'test', $this->test])->andFilterWhere(['like', 'mpesa_code', $this->mpesa_code])->andFilterWhere(['like', 'mpesa_acc', $this->mpesa_acc])->andFilterWhere(['like', 'mpesa_msidn', $this->mpesa_msidn])->andFilterWhere(['like', 'mpesa_amount', $this->mpesa_amount])->andFilterWhere(['like', 'mpesa_sender', $this->mpesa_sender]);
     return $dataProvider;
 }
 /**
  * Updates an existing Suspense model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->status == 'yes') {
         try {
             //FIND CUSTOMER RECORDS
             $customer = Clients::findOne(['clientAcc' => $model->mpesa_acc]);
             //HOW MUCH MONEY CLIENTS SHOULD PAY A MONTH
             $billing = Bills::findOne(['id' => 1]);
             //IF NO CLIENT FOUND, SUBMIT THIS TO SUSPENSE ACCOUNT
             if (count($customer) >= 1) {
                 // IF A CLIENT IS FOUND, THEN DO THE FOLLOWING AND SAVE
                 $payment = new Payments();
                 $payment->mpesa_id = $model->mpesa_id;
                 $payment->original = $model->original;
                 $payment->destination = $model->destination;
                 $payment->customer_id = $model->customer_id;
                 $payment->test = $model->test;
                 $payment->mpesa_code = $model->mpesa_code;
                 $payment->mpesa_acc = $model->mpesa_acc;
                 $payment->mpesa_msidn = $model->mpesa_msidn;
                 $payment->mpesa_amount = $model->mpesa_amount;
                 $payment->mpesa_sender = $model->mpesa_sender;
                 $payment->timestamp = $model->timestamp;
                 $payment->save();
                 echo "<pre>";
                 //print_r($payment);
                 echo "</pre>";
                 //IS THE CLIENT ACTIVE OR INACTIVE? BASED ON THE PROFILE
                 $customer_radgroup = Radusergroup::findOne(['username' => $customer->username]);
                 //print_r($customer_radgroup);
                 //COLLECT ALL RADGROUPS
                 $radgroups = Radgroupcheck::find()->all();
                 if ($payment->mpesa_amount >= $billing->monthly_charge) {
                     //IF USER WAS DISCONNECTED, AND HAS PAID MORE THAN THE BILLING AMOUNT, SAY: 3000, THEN ACTIVATE THAT USER
                     if (count($customer_radgroup) >= 1) {
                         if ($customer_radgroup->groupname == "daloRADIUS-Disabled-Users") {
                             try {
                                 //Yii::$app->db->createCommand()->delete('radusergroup', ['username' => $customer->username])->execute();
                                 if ($customer_radgroup->delete()) {
                                     echo "Deleted";
                                 }
                             } catch (Exception $e) {
                             }
                         }
                     }
                     if ($customer->arrears < 0 && $customer->balances >= $billing->monthly_charge) {
                         $customer->arrears += $payment->mpesa_amount;
                         if ($customer->arrears > 0) {
                             $customer->balances += $customer->arrears;
                         }
                     } elseif ($customer->arrears < 0 && $customer->balances < $billing->monthly_charge) {
                         $difference = $billing->monthly_charge - $customer->balances;
                         $topup = $billing->monthly_charge - $customer->balances;
                         //$customer->balances = 2500;
                         //$billing->monthly_charge = 3000;
                         //$difference = 1000;
                         //$payment->mpesa_amount = 2000
                         if ($payment->mpesa_amount > $topup) {
                             $remainder = $payment->mpesa_amount - $topup;
                             $customer->balances += $billing->monthly_charge;
                             $customer->arrears += $remainder;
                             if ($customer->arrears > 0) {
                                 $customer->balances += $customer->arrears;
                             }
                         } else {
                             $customer->balances += $payment->mpesa_amount;
                         }
                     } else {
                         $customer->balances += $payment->mpesa_amount;
                     }
                 } else {
                     if ($customer->balances >= $billing->monthly_charge && $customer->arrears < 0) {
                         //$customer->balances = 2000;
                         //$billing->monthly_charge = 3000;
                         //$difference = 1000;
                         //$payment->mpesa_amount = 2000
                         $customer->arrears += $payment->mpesa_amount;
                         if ($customer->arrears > 0) {
                             $customer->balances += $customer->arrears;
                         }
                     } elseif ($customer->balances <= $billing->monthly_charge && $customer->arrears < 0) {
                         if ($payment->mpesa_amount + $customer->balances > $billing->monthly_charge) {
                             $topup = $billing->monthly_charge - $customer->balances;
                             $customer->balances += $topup;
                             //
                             $excess = $payment->mpesa_amount - $topup;
                             $customer->arrears += $excess;
                         } else {
                             $customer->balances += $payment->mpesa_amount;
                         }
                     }
                     if ($customer->balances >= $billing->monthly_charge && count($customer_radgroup) >= 1) {
                         if ($customer_radgroup->groupname == "daloRADIUS-Disabled-Users") {
                             try {
                                 //Yii::$app->db->createCommand()->delete('radusergroup', ['username' => $customer->username])->execute();
                                 if ($customer_radgroup->delete()) {
                                     echo "Deleted";
                                 }
                             } catch (Exception $e) {
                             }
                         }
                     }
                 }
                 try {
                     $customer->balances = (string) $customer->balances;
                     $customer->arrears = (string) $customer->arrears;
                     $customer->save();
                 } catch (Exception $e) {
                 }
             }
             //return $this->render('collection', ["status"=>"Records saved"] );
         } catch (Exception $e) {
             //return $this->render('collection', ["status"=>"Client Account details not found!"] );
         }
         if ($model->save()) {
             //return $this->redirect(['view', 'id' => $model->id]);
             return $this->render('update', ['model' => $model, 'result' => $payment]);
         }
     } elseif ($model->load(Yii::$app->request->post()) && $model->save() && $model->status == 'no') {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }
示例#6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPayments()
 {
     return $this->hasMany(Payments::className(), ['PI_ID' => 'PI_ID']);
 }
示例#7
0
 public function doCapture()
 {
     $result = 'payment not found';
     $payment = Payments::find($this->request->id);
     if ($payment) {
         $result = Paypal::doCapture($payment->auth_id, $payment->auth_amount, 'USD', true);
     }
     return compact('result');
 }
示例#8
0
 public function index()
 {
     $payments = Payments::all();
     return compact('payments');
 }
示例#9
0
 /**
  * Get the validator rules by path
  *
  * @param string $id
  * @return array
  */
 public function rules($id = '')
 {
     switch (Request::method()) {
         case 'GET':
         case 'DELETE':
             return [];
         case 'POST':
             return $rules = ['name' => 'required|unique:payments', 'status' => 'required|boolean'];
         case 'PUT':
         case 'PATCH':
             $payment = Payments::find($id);
             return $rules = ['name' => 'required|unique:payments,id,' . $payment->id, 'status' => 'required|boolean'];
         default:
             break;
     }
 }
 /**
  * Finds the Payments model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Payments the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Payments::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }