コード例 #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $userId)
 {
     $query = Contractor::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andWhere(['user_id' => $userId]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'comment', $this->comment]);
     return $dataProvider;
 }
コード例 #2
0
 public function actionIndex()
 {
     $fname = __DIR__ . "/../expense.csv";
     $lines = file($fname);
     $expenses = [];
     $current = null;
     foreach ($lines as $line) {
         $arr = explode(',', $line);
         if (trim($line) == ',,,,,,,,,') {
             continue;
         }
         if ($arr[0]) {
             var_dump($arr[1], $arr[8]);
             $expenses[] = ['date' => $arr[0], 'contractor' => $arr[1], 'contractor_id' => \app\models\contractor\Contractor::getByName($arr[1], 2)->id, 'bonus' => $arr[7], 'account' => $arr[8], 'account_id' => \app\models\account\Account::getByName($arr[8], 2)->id, 'expenses' => [['title' => $arr[2], 'price' => $arr[3], 'count' => $arr[4], 'discount' => $arr[5], 'sum' => $arr[6], 'comment' => trim($arr[9])]]];
         } else {
             $expenses[count($expenses) - 1]['expenses'][] = ['title' => $arr[2], 'price' => $arr[3], 'count' => $arr[4], 'discount' => $arr[5], 'sum' => $arr[6], 'comment' => trim($arr[9])];
         }
     }
     foreach ($expenses as $expense) {
         $transfer = new \app\models\transaction\Transaction();
         $transfer->comment = "";
         preg_match('!^(\\d{1,2})[\\.\\-](\\d{1,2}) (\\d{1,2})-(\\d{2})$!', $expense['date'], $m);
         $transfer->date = date('Y-m-d H:i:s', strtotime("{$m['1']}.{$m['2']}.2015 {$m['3']}:{$m['4']}:00"));
         var_dump($transfer->date);
         $transfer->user_id = 2;
         $transfer->comment = $expense['expenses'][0]['comment'];
         $transfer->type = 'expense';
         $transfer->save(false);
         $exps = [];
         $total = 0;
         foreach ($expense['expenses'] as $e) {
             $exp = new \app\models\transaction\TransactionExpense();
             $exp->name = $e['title'];
             $exp->price = $e['price'];
             $exp->qty = $e['count'];
             $exp->discount = floatval($e['discount']);
             $exp->sum = $exp->price * $exp->qty * (1 - $exp->discount);
             $exp->comment = $e['comment'];
             $exp->contractor_id = $expense['contractor_id'];
             $exp->user_id = 2;
             $total += $exp->sum;
             $exp->transaction_id = $transfer->id;
             $exp->save(false);
         }
         $out = new \app\models\transaction\TransactionOutgoing();
         $out->account_id = $expense['account_id'];
         $out->sum = $total;
         $out->user_id = 2;
         $out->transaction_id = $transfer->id;
         $out->save(false);
         if ($expense['bonus']) {
             var_dump($expense['bonus']);
             $in = new \app\models\transaction\TransactionIncoming();
             $in->account_id = \app\models\account\Account::getByName('Okeycity', 2)->id;
             $in->sum = $expense['bonus'];
             $in->user_id = 3;
             $in->transaction_id = $transfer->id;
             $in->contractor_id = \app\models\contractor\Contractor::getByName('Okeycity', 2)->id;
             $in->save(false);
         }
     }
 }
コード例 #3
0
ファイル: __expense.php プロジェクト: alexshadie/wallet
">
        <?php 
if ($model->type == 'transfer' || $__ITEM->contractor_id && $__ITEM->contractor_id != $model->expenseContractorId) {
    ?>
            <?php 
    echo $form->field($__ITEM, 'contractor_id')->label(false)->dropDownList(ArrayHelper::merge(["" => "Select contractor"], Contractor::dropdown(Yii::$app->user->getId())), ['role' => "expense-contractor"]);
    ?>
        <?php 
} else {
    ?>
            <a href="#" onclick="$(this).remove(); $('div[role=\'contractor-container-expense-<?php 
    echo $__ITEM->id;
    ?>
\'] select').show(); return false;">Specify contractor</a>
            <?php 
    echo $form->field($__ITEM, 'contractor_id')->label(false)->dropDownList(ArrayHelper::merge(["" => "Select contractor"], Contractor::dropdown(Yii::$app->user->getId())), ['role' => "expense-contractor", 'style' => 'display: none;']);
    ?>
        <?php 
}
?>
        </div>
        <?php 
echo $form->field($__ITEM, 'name')->label(false)->textInput();
?>
        <?php 
echo $form->field($__ITEM, 'price')->label(false)->textInput();
?>
        <?php 
echo $form->field($__ITEM, 'qty')->label(false)->textInput();
?>
        <?php 
コード例 #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getContractor()
 {
     return $this->hasOne(Contractor::className(), ['id' => 'contractor_id']);
 }
コード例 #5
0
 /**
  * Finds the Contractor model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Contractor the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Contractor::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #6
0
ファイル: _form_expense.php プロジェクト: alexshadie/wallet
    <?php 
echo $form->field($model, 'date')->textInput();
?>

    <?php 
echo $form->field($model, 'comment')->textarea(['rows' => 6]);
?>

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

    <?php 
echo $form->field($model, 'expenseContractorId')->label(false)->dropDownList(ArrayHelper::merge(["" => "Select contractor"], Contractor::dropdown(Yii::$app->user->getId())), ['name' => '']);
?>
    
    <div>
        <a href="#" class="btn btn-primary" role="add-outgoing">Add outgoing</a>
        <a href="#" class="btn btn-primary" role="add-expense">Add expense</a>
        <a href="#" class="btn btn-primary" role="add-incoming">Add bonus</a>
    </div>

    <div role="transaction-details">
        <div role="transaction-details-outgoing">
            <h3>From</h3>
            <ol>
                <?php 
foreach ($model->transactionOutgoings as $__ITEM) {
    ?>