public function fire()
 {
     $this->info(date('Y-m-d') . ' ChargeRenewalInvoices...');
     $ninjaAccount = $this->accountRepo->getNinjaAccount();
     $invoices = Invoice::whereAccountId($ninjaAccount->id)->whereDueDate(date('Y-m-d'))->where('balance', '>', 0)->with('client')->orderBy('id')->get();
     $this->info(count($invoices) . ' invoices found');
     foreach ($invoices as $invoice) {
         // check if account has switched to free since the invoice was created
         $account = Account::find($invoice->client->public_id);
         if (!$account) {
             continue;
         }
         $company = $account->company;
         if (!$company->plan || $company->plan == PLAN_FREE) {
             continue;
         }
         try {
             $this->info("Charging invoice {$invoice->invoice_number}");
             $this->paymentService->autoBillInvoice($invoice);
         } catch (Exception $exception) {
             $this->info('Error: ' . $exception->getMessage());
         }
     }
     $this->info('Done');
 }
Пример #2
0
 public function validateCredentials(UserContract $user, array $credentials)
 {
     $profile = $user instanceof Account ? $user : Account::find($user->getAuthIdentifier());
     if ($profile && $profile->id == $user->getAuthIdentifier()) {
         return static::PAMAuthenticate($profile->username, $credentials['password']);
     }
     return false;
 }
Пример #3
0
 public function demo()
 {
     $demoAccountId = Utils::getDemoAccountId();
     if (!$demoAccountId) {
         return Redirect::to('/');
     }
     $account = Account::find($demoAccountId);
     $user = $account->users()->first();
     Auth::login($user, true);
     return Redirect::to('invoices/create');
 }
Пример #4
0
 /**
 For each account create an item. If previous balance sheet exists and has value - set it as default, otherwise - set to zero
 */
 public function initAmounts()
 {
     $accounts = Account::find()->orderBy('order_code')->all();
     $prevBalance = $this->getPreviouBalance();
     for ($i = 0; $i < count($accounts); $i++) {
         $amount = new BalanceAmount();
         $amount->account_id = $accounts[$i]->id;
         $amount->balance_sheet_id = $this->id;
         $amount->amount = $prevBalance ? $prevBalance->balanceAmounts[$i]->amount : 0;
         $amount->save();
     }
 }
Пример #5
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Account::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(['account_id' => $this->account_id, 'person_id' => $this->person_id, 'remain_time' => $this->remain_time]);
     return $dataProvider;
 }
Пример #6
0
 public function beforeValidate()
 {
     if (parent::beforeValidate()) {
         // ...custom code here...
         if ($this->order_num == null) {
             $this->order_num = Account::find()->where(['balance_item_id' => $this->balance_item_id])->max('order_num') + 1;
         }
         $this->order_code = $this->balanceItem->order_code . "." . $this->order_num;
         return true;
     } else {
         return false;
     }
 }
Пример #7
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Account::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, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'account_number', $this->account_number])->andFilterWhere(['like', 'account_name', $this->account_name])->andFilterWhere(['like', 'saving_type', $this->saving_type])->andFilterWhere(['like', 'bank_name', $this->bank_name])->andFilterWhere(['like', 'brance', $this->brance]);
     return $dataProvider;
 }
Пример #8
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Account::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(['account_id' => $this->account_id, 'date_added' => $this->date_added, 'date_updated' => $this->date_updated]);
     $query->andFilterWhere(['like', 'first_name', $this->first_name])->andFilterWhere(['like', 'last_name', $this->last_name])->andFilterWhere(['like', 'email_address', $this->email_address])->andFilterWhere(['like', 'added_ip', $this->added_ip])->andFilterWhere(['like', 'updated_ip', $this->updated_ip])->andFilterWhere(['like', 'password', $this->password]);
     return $dataProvider;
 }
 /**
  * POST /api/favouriteTransactions
  * @param Request $request
  * @return Response
  */
 public function store(Request $request)
 {
     $favourite = new FavouriteTransaction($request->only(['name', 'type', 'description', 'merchant', 'total']));
     $favourite->user()->associate(Auth::user());
     $favourite->account()->associate(Account::find($request->get('account_id')));
     $favourite->fromAccount()->associate(Account::find($request->get('from_account_id')));
     $favourite->toAccount()->associate(Account::find($request->get('to_account_id')));
     $favourite->save();
     foreach ($request->get('budget_ids') as $id) {
         $favourite->budgets()->attach($id);
     }
     $favourite = $this->transform($this->createItem($favourite, new FavouriteTransactionTransformer()))['data'];
     return response($favourite, Response::HTTP_CREATED);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Account::find();
     // add conditions that should always apply here
     $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;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'card_number', $this->card_number]);
     return $dataProvider;
 }
Пример #11
0
 public function actionIndex()
 {
     $account = new \app\models\Account();
     if (!empty($_POST)) {
         $account = \app\models\Account::find()->where('username = :username AND password = :password', [':username' => $_POST['Account']['username'], ':password' => $_POST['Account']['password']])->one();
         if (!empty($account)) {
             $session = new \yii\web\Session();
             $session->open();
             $session['account_id'] = $account->id;
             $session['account_name'] = $account->name;
             return $this->redirect(['home']);
         } else {
             $account = new \app\models\Account();
             $account->username = $_POST['Account']['username'];
             $account->password = $_POST['Account']['password'];
         }
     }
     return $this->render('//Backend/Index', ['account' => $account]);
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $force = $this->option('force');
     $account = $this->argument('account');
     $accounts = null;
     if ($account) {
         $accounts = Account::find($account)->get();
     } else {
         $accounts = Account::all();
     }
     $latestInvoice = $this->invoice->latest()->first();
     $invoiceYear = Carbon::parse($latestInvoice->created_at)->year;
     if (Carbon::now()->year > $invoiceYear || $force) {
         $accounts->transform(function ($a) {
             /** @var Account $a */
             $a->invoice_number_counter = 1;
             $a->update();
         });
         $this->info('The counter has been resetted successfully for ' . $accounts->count() . ' account(s).');
     }
 }
Пример #13
0
 public function actionLog()
 {
     $user = new Account();
     $model = new LogForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if (isset($_POST['login'])) {
             $user = Account::find()->where(['nickname' => $model->username])->one();
             if ($user && $model->username == $user->nickname && $model->password == $user->password) {
                 if ($user->admin === 0) {
                     //Yii::$app->runAction('site/user', $user->userID);
                     return $this->redirect(array('site/user', 'id' => $user->userID));
                 } else {
                     if ($user->admin === 1) {
                         return $this->redirect(array('site/admin', 'id' => $user->userID));
                         //Yii::$app->runAction('site/admin', $user->userID);
                     }
                 }
             } else {
                 return $this->render('fail');
             }
         }
     }
     return $this->render('login', ['model' => $model]);
 }
Пример #14
0
use app\models\Account;
use app\models\Customer;
use yii\helpers\ArrayHelper;
/* @var $this yii\web\View */
/* @var $model app\models\Collection */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="collection-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'account_id')->dropDownList(ArrayHelper::map(Account::find()->all(), 'id', 'name'), ['prompt' => Yii::t('app', 'Select Account')]);
?>

    <div class="form-group field-collection-time">
        <label class="control-label" for="collection-time"><?php 
echo Yii::t('app', 'Time');
?>
 </label>
        <?php 
echo DatePicker::widget(['id' => 'collection-time', 'name' => 'Collection[time]', 'value' => $model->time ? $model->time : date('Y-m-d', strtotime('today')), 'options' => ['placeholder' => Yii::t('app', 'Select Time')], 'pluginOptions' => ['format' => 'yyyy-m-dd', 'todayHighLight' => true]]);
?>
    </div>

    <?php 
echo $form->field($model, 'money')->textInput(['maxlength' => true]);
?>
Пример #15
0
 private function createPayment($invitation, $ref, $payerId = null)
 {
     $invoice = $invitation->invoice;
     $accountGateway = $invoice->client->account->getGatewayByType(Session::get('payment_type'));
     if ($invoice->account->account_key == NINJA_ACCOUNT_KEY) {
         $account = Account::find($invoice->client->public_id);
         if ($account->pro_plan_paid && $account->pro_plan_paid != '0000-00-00') {
             $date = DateTime::createFromFormat('Y-m-d', $account->pro_plan_paid);
             $account->pro_plan_paid = $date->modify('+1 year')->format('Y-m-d');
         } else {
             $account->pro_plan_paid = date_create()->format('Y-m-d');
         }
         $account->save();
     }
     $payment = Payment::createNew($invitation);
     $payment->invitation_id = $invitation->id;
     $payment->account_gateway_id = $accountGateway->id;
     $payment->invoice_id = $invoice->id;
     $payment->amount = $invoice->getRequestedAmount();
     $payment->client_id = $invoice->client_id;
     $payment->contact_id = $invitation->contact_id;
     $payment->transaction_reference = $ref;
     $payment->payment_date = date_create()->format('Y-m-d');
     if ($payerId) {
         $payment->payer_id = $payerId;
     }
     $payment->save();
     Event::fire(new InvoicePaid($payment));
     return $payment;
 }
Пример #16
0
 /**
  * @return string
  */
 public function getWebhookUrl()
 {
     $account = $this->account ? $this->account : Account::find($this->account_id);
     return \URL::to(env('WEBHOOK_PREFIX', '') . 'payment_hook/' . $account->account_key . '/' . $this->gateway_id . env('WEBHOOK_SUFFIX', ''));
 }
Пример #17
0
echo DatePicker::widget(['model' => $model, 'attribute' => 'end_date', 'type' => DatePicker::TYPE_COMPONENT_PREPEND, 'options' => ['placeholder' => ''], 'pluginOptions' => ['autoclose' => true, 'todayHighlight' => true, 'format' => 'yyyy-mm-dd']]);
?>
        </div>
    </div><p>

    <?php 
echo $form->field($model, 'type_id')->dropDownList(['1' => Yii::t('app', 'Revenue'), '2' => Yii::t('app', 'Expense')], ['prompt' => Yii::t('app', 'All')]);
//->dropDownList(ArrayHelper::map(Type::find()->all(), 'id_type', 'desc_type'),['prompt'=>Yii::t('app', 'All')])
?>

    <?php 
echo $form->field($model, 'category_id')->dropDownList(ArrayHelper::map(Category::find()->where(['user_id' => Yii::$app->user->identity->id])->orderBy("desc_category ASC")->all(), 'id_category', 'desc_category'), ['prompt' => Yii::t('app', 'All')]);
?>

    <?php 
echo $form->field($model, 'account_id')->dropDownList(ArrayHelper::map(\app\models\Account::find()->where(['user_id' => Yii::$app->user->identity->id])->orderBy("description ASC")->all(), 'id', 'description'), ['prompt' => Yii::t('app', 'All')]);
?>

    <?php 
echo $form->field($model, 'value');
?>

    <?php 
echo $form->field($model, 'description');
?>

    <?php 
echo $form->field($model, 'is_pending')->checkbox();
?>

    <?php 
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     $timeout = ini_get('max_execution_time');
     if ($timeout == 0) {
         $timeout = 600;
     }
     $timeout = max($timeout - 10, $timeout * 0.9);
     $startTime = time();
     if (!Schema::hasTable('companies')) {
         Schema::create('companies', function ($table) {
             $table->increments('id');
             $table->enum('plan', array('pro', 'enterprise', 'white_label'))->nullable();
             $table->enum('plan_term', array('month', 'year'))->nullable();
             $table->date('plan_started')->nullable();
             $table->date('plan_paid')->nullable();
             $table->date('plan_expires')->nullable();
             $table->unsignedInteger('payment_id')->nullable();
             $table->foreign('payment_id')->references('id')->on('payments');
             $table->date('trial_started')->nullable();
             $table->enum('trial_plan', array('pro', 'enterprise'))->nullable();
             $table->enum('pending_plan', array('pro', 'enterprise', 'free'))->nullable();
             $table->enum('pending_term', array('month', 'year'))->nullable();
             $table->timestamps();
             $table->softDeletes();
         });
     }
     if (!Schema::hasColumn('accounts', 'company_id')) {
         Schema::table('accounts', function ($table) {
             $table->unsignedInteger('company_id')->nullable();
         });
         Schema::table('accounts', function ($table) {
             $table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
         });
     }
     $single_account_ids = \DB::table('users')->leftJoin('user_accounts', function ($join) {
         $join->on('user_accounts.user_id1', '=', 'users.id');
         $join->orOn('user_accounts.user_id2', '=', 'users.id');
         $join->orOn('user_accounts.user_id3', '=', 'users.id');
         $join->orOn('user_accounts.user_id4', '=', 'users.id');
         $join->orOn('user_accounts.user_id5', '=', 'users.id');
     })->leftJoin('accounts', 'accounts.id', '=', 'users.account_id')->whereNull('user_accounts.id')->whereNull('accounts.company_id')->where(function ($query) {
         $query->whereNull('users.public_id');
         $query->orWhere('users.public_id', '=', 0);
     })->lists('users.account_id');
     if (count($single_account_ids)) {
         foreach (Account::find($single_account_ids) as $account) {
             $this->upAccounts($account);
             $this->checkTimeout($timeout, $startTime);
         }
     }
     $group_accounts = \DB::select('SELECT u1.account_id as account1, u2.account_id as account2, u3.account_id as account3, u4.account_id as account4, u5.account_id as account5 FROM `user_accounts`
         LEFT JOIN users u1 ON (u1.public_id IS NULL OR u1.public_id = 0) AND user_accounts.user_id1 = u1.id
         LEFT JOIN users u2 ON (u2.public_id IS NULL OR u2.public_id = 0) AND user_accounts.user_id2 = u2.id
         LEFT JOIN users u3 ON (u3.public_id IS NULL OR u3.public_id = 0) AND user_accounts.user_id3 = u3.id
         LEFT JOIN users u4 ON (u4.public_id IS NULL OR u4.public_id = 0) AND user_accounts.user_id4 = u4.id
         LEFT JOIN users u5 ON (u5.public_id IS NULL OR u5.public_id = 0) AND user_accounts.user_id5 = u5.id
         LEFT JOIN accounts a1 ON a1.id = u1.account_id
         LEFT JOIN accounts a2 ON a2.id = u2.account_id
         LEFT JOIN accounts a3 ON a3.id = u3.account_id
         LEFT JOIN accounts a4 ON a4.id = u4.account_id
         LEFT JOIN accounts a5 ON a5.id = u5.account_id
         WHERE (a1.id IS NOT NULL AND a1.company_id IS NULL)
         OR (a2.id IS NOT NULL AND a2.company_id IS NULL)
         OR (a3.id IS NOT NULL AND a3.company_id IS NULL)
         OR (a4.id IS NOT NULL AND a4.company_id IS NULL)
         OR (a5.id IS NOT NULL AND a5.company_id IS NULL)');
     if (count($group_accounts)) {
         foreach ($group_accounts as $group_account) {
             $this->upAccounts(null, Account::find(get_object_vars($group_account)));
             $this->checkTimeout($timeout, $startTime);
         }
     }
     if (Schema::hasColumn('accounts', 'pro_plan_paid')) {
         Schema::table('accounts', function ($table) {
             $table->dropColumn('pro_plan_paid');
             $table->dropColumn('pro_plan_trial');
         });
     }
 }
Пример #19
0
 /**
  * Todo: Do validations
  * POST /api/transactions
  * @param Request $request
  * @return Response
  */
 public function store(Request $request)
 {
     $transaction = new Transaction($request->only(['date', 'description', 'merchant', 'total', 'type', 'reconciled', 'minutes']));
     //Make sure total is negative for expense, negative for transfers from, and positive for income
     if ($transaction->type === 'expense' && $transaction->total > 0) {
         $transaction->total *= -1;
     } else {
         if ($transaction->type === 'income' && $transaction->total < 0) {
             $transaction->total *= -1;
         } else {
             if ($transaction->type === 'transfer' && $request->get('direction') === Transaction::DIRECTION_FROM) {
                 $transaction->total *= -1;
             }
         }
     }
     $transaction->account()->associate(Account::find($request->get('account_id')));
     $transaction->user()->associate(Auth::user());
     $transaction->save();
     if ($transaction->type !== 'transfer') {
         $this->budgetTransactionRepository->attachBudgetsWithDefaultAllocation($transaction, $request->get('budget_ids'));
     }
     //Fire event
     event(new TransactionWasCreated($transaction));
     $transaction = $this->transform($this->createItem($transaction, new TransactionTransformer()))['data'];
     return response($transaction, Response::HTTP_CREATED);
 }
Пример #20
0
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->user_id != Yii::$app->user->id) {
         throw new ErrorException(Yii::t('app', 'Forbidden to change entries of other users'));
     }
     $oldFile = $model->getImageFile();
     $oldattachment = $model->attachment;
     $oldFileName = $model->filename;
     $model->edit_datetime = date("Y-m-d H:i:s");
     if ($model->load(Yii::$app->request->post())) {
         // process uploaded image file instance
         $file = $model->uploadImage();
         // revert back if no valid file instance uploaded
         if ($file === false) {
             $model->attachment = $oldattachment;
             $model->filename = $oldFileName;
         }
         if ($model->save()) {
             // upload only if valid uploaded file instance found
             if ($file !== false && unlink($oldFile)) {
                 // delete old and overwrite
                 $path = $model->getImageFile();
                 $file->saveAs($path);
             }
             Yii::$app->session->setFlash("Entry-success", Yii::t("app", "Entry updated"));
             return $this->redirect(['index']);
         } else {
             // error in saving model
         }
     }
     $accountItems = Account::find()->select(['id', 'description'])->where(['user_id' => Yii::$app->user->id])->asArray()->all();
     $accountItems = ArrayHelper::map($accountItems, 'id', 'description');
     return $this->render('update', ['model' => $model, 'accountItems' => $accountItems]);
 }
Пример #21
0
 public function getMonthStat($user_id)
 {
     $account_query = Account::find()->where(['user_id' => $user_id, 'io_type' => Account::IO_TYPE_EXPENDITURE])->andWhere(['>=', 'date', date("Y-m-01")]);
     $sum = round($account_query->sum('value'), 2);
     $month_days = intval((strtotime(date("Y-m-d")) - strtotime(date("Y-m-01")) + 3600 * 24) / (3600 * 24));
     $average = round($sum / $month_days, 2);
     $plan = Plan::findOne(['user_id' => $user_id]);
     return ['sum' => $sum, 'average' => $average, 'plan' => isset($plan->value) ? intval($plan->value) : 5000];
 }
Пример #22
0
 /**
  * Get the basic info of the account.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function personal_info(Request $request)
 {
     if ($request->has('id')) {
         $id = $request->input('id');
         try {
             $account = Account::find($id);
         } catch (ModelNotFoundException $e) {
             return response()->json(['status' => 403, 'message' => 'account not found', 'data' => null]);
         }
         $name = $account->name;
         $nickName = $account->nickName;
         $address = $account->address;
         $nationality = $account->nationality;
         $city = $account->city;
         $hobby = $account->hobby;
         $birthday = $account->birthday;
         $gender = $account->gender;
         return response()->json(['status' => 0, 'message' => 'ok', 'data' => ['name' => $name, 'nickName' => $nickName, 'gender' => $gender, 'nationality' => $nationality, 'city' => $city, 'address' => $address, 'hobby' => $hobby, 'birthday' => $birthday]]);
     } else {
         return response()->json(['status' => 404, 'message' => 'input error', 'data' => null]);
     }
 }
Пример #23
0
 /**
  * Lists all Account models.
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = new Account();
     $dataProvider = new ActiveDataProvider(['query' => $searchModel->find()->where(['user_id' => Yii::$app->user->id])]);
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
Пример #24
0
<div class="transaction-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'amount')->textInput(['maxlength' => true]);
?>
	
    <?php 
echo $form->field($model, 'description')->textInput(['maxlength' => true]);
?>

    <?php 
$src = \app\models\Account::find()->select('name, id')->orderBy('order_code')->indexBy('id')->column();
echo $form->field($model, 'account_from_id')->dropdownList($src, ['prompt' => '- add -']);
echo $form->field($model, 'account_to_id')->dropdownList($src, ['prompt' => '- remove -']);
?>

    <?php 
echo $form->field($model, 'date')->textInput();
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
Пример #25
0
/* @var $this yii\web\View */
/* @var $model app\models\BalanceAmount */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="balance-amount-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'amount')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'account_id')->dropdownList(\app\models\Account::find()->select('name, id')->indexBy('id')->column());
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
?>

</div>
Пример #26
0
 /**
  * update.
  *
  * @param int   $id
  * @param array $input
  */
 public function update($id, $input)
 {
     $model = $this->model->find($id);
     return $this->savePost($model, $input);
 }
Пример #27
0
 /**
  * Lists all Account models.
  * @return mixed
  */
 public function actionIndex()
 {
     $dataProvider = new ActiveDataProvider(['query' => Account::find()->orderBy('order_code')]);
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }
Пример #28
0
 public function actionIndex()
 {
     $accounts = Account::find()->orderBy('id DESC')->all();
     return $this->render('//Account/Index', ['accounts' => $accounts, 'n' => 1]);
 }