<div class="row"> <?php echo $form->label($model, 'id'); ?> <?php echo $form->textField($model, 'id'); ?> </div> <div class="row"> <?php echo $form->label($model, 'beneficiary_id'); ?> <?php echo $form->dropDownList($model, 'beneficiary_id', GxHtml::listDataEx(Beneficiary::model()->findAllAttributes(null, true)), array('prompt' => Yii::t('app', 'All'))); ?> </div> <div class="row"> <?php echo $form->label($model, 'attribute_id'); ?> <?php echo $form->dropDownList($model, 'attribute_id', GxHtml::listDataEx(Attribute::model()->findAllAttributes(null, true)), array('prompt' => Yii::t('app', 'All'))); ?> </div> <div class="row"> <?php echo $form->label($model, 'value');
<?php $this->breadcrumbs = array(Beneficiary::label(2), Yii::t('app', 'Index')); $this->menu = array(array('label' => Yii::t('app', 'Create') . ' ' . Beneficiary::label(), 'url' => array('create')), array('label' => Yii::t('app', 'Manage') . ' ' . Beneficiary::label(2), 'url' => array('admin'))); ?> <h1><?php echo GxHtml::encode(Beneficiary::label(2)); ?> </h1> <?php $this->widget('zii.widgets.CListView', array('dataProvider' => $dataProvider, 'itemView' => '_view'));
public function doOldImport() { DB::delete('DELETE FROM `cache`'); // delete old data: foreach (Auth::user()->accounts()->get() as $acc) { $acc->delete(); } foreach (Auth::user()->budgets()->get() as $b) { $b->delete(); } foreach (Auth::user()->categories()->get() as $b) { $b->delete(); } foreach (Auth::user()->beneficiaries()->get() as $b) { $b->delete(); } foreach (Icon::get() as $icon) { $icon->delete(); } $data = file_get_contents('http://commondatastorage.googleapis.com/nder/import.json'); $json = json_decode($data); $map = array(); $map['accounts'] = array(); $map['icons'] = array(); // all accounts: foreach ($json->accounts as $account) { $newAccount = new Account(); $newAccount->name = Crypt::encrypt($account->name); $newAccount->balance = floatval($account->balance); $newAccount->fireflyuser_id = Auth::user()->id; $newAccount->date = $account->date; $newAccount->save(); $map['accounts'][$account->id] = $newAccount->id; } // all icons: foreach ($json->icons as $icon) { $newIcon = new Icon(); $newIcon->file = $icon->file; $newIcon->save(); $map['icons'][intval($icon->id)] = $newIcon->id; } // all beneficiaries: foreach ($json->beneficiaries as $ben) { $nb = new Beneficiary(); $nb->fireflyuser_id = Auth::user()->id; $nb->name = Crypt::encrypt($ben->name); $nb->save(); $map['beneficiaries'][$ben->id] = $nb->id; } // all budgets foreach ($json->budgets as $bd) { $nbg = new Budget(); $nbg->fireflyuser_id = Auth::user()->id; $nbg->name = Crypt::encrypt($bd->name); $nbg->date = $bd->date; $nbg->amount = floatval($bd->amount); $nbg->save(); $map['budgets'][$bd->id] = $nbg->id; } // all categories: foreach ($json->categories as $c) { $nc = new Category(); $nc->fireflyuser_id = Auth::user()->id; $nc->icon_id = intval($map['icons'][intval($c->icon_id)]); $nc->name = Crypt::encrypt($c->name); $nc->showtrend = intval($c->showtrend); $nc->save(); $map['categories'][$c->id] = $nc->id; } foreach ($json->targets as $t) { $nt = new Target(); $nt->fireflyuser_id = Auth::user()->id; $nt->account_id = $map['accounts'][$t->account_id]; $nt->description = Crypt::encrypt($t->description); $nt->amount = floatval($t->amount); $nt->duedate = $t->duedate; $nt->startdate = $t->startdate; $nt->save(); $map['targets'][$t->id] = $nt->id; } foreach ($json->transactions as $t) { $nt = new Transaction(); $nt->fireflyuser_id = Auth::user()->id; $nt->account_id = $map['accounts'][$t->account_id]; $nt->budget_id = is_null($t->budget_id) ? NULL : intval($map['budgets'][$t->budget_id]); $nt->category_id = is_null($t->category_id) ? NULL : $map['categories'][$t->category_id]; $nt->beneficiary_id = is_null($t->beneficiary_id) ? NULL : $map['beneficiaries'][$t->beneficiary_id]; $nt->description = Crypt::encrypt($t->description); $nt->amount = floatval($t->amount); $nt->date = $t->date; $nt->onetime = intval($t->onetime); $nt->save(); $map['transactions'][$t->id] = $nt->id; } foreach ($json->transfers as $t) { $nt = new Transfer(); $nt->fireflyuser_id = Auth::user()->id; $nt->account_from = $map['accounts'][$t->account_from]; $nt->account_to = $map['accounts'][$t->account_to]; $nt->category_id = is_null($t->category_id) ? NULL : $map['categories'][$t->category_id]; $nt->budget_id = is_null($t->budget_id) ? NULL : intval($map['budgets'][$t->budget_id]); $nt->target_id = is_null($t->target_id) ? NULL : intval($map['targets'][$t->target_id]); $nt->description = Crypt::encrypt($t->description); $nt->amount = floatval($t->amount); $nt->date = $t->date; $nt->save(); $map['targets'][$t->id] = $nt->id; } // //var_dump($data); // create everything from this file. // we map the old id's to the new one to save problems. return 'Old data successfully imported.'; }
<?php $this->breadcrumbs = array($model->label(2) => array('index'), Yii::t('app', 'Manage')); $this->menu = array(array('label' => Yii::t('app', 'List') . ' ' . $model->label(2), 'url' => array('index')), array('label' => Yii::t('app', 'Create') . ' ' . $model->label(), 'url' => array('create'))); Yii::app()->clientScript->registerScript('search', "\n\$('.search-button').click(function(){\n\t\$('.search-form').toggle();\n\treturn false;\n});\n\$('.search-form form').submit(function(){\n\t\$.fn.yiiGridView.update('beneficiary-attribute-grid', {\n\t\tdata: \$(this).serialize()\n\t});\n\treturn false;\n});\n"); ?> <h1><?php echo Yii::t('app', 'Manage') . ' ' . GxHtml::encode($model->label(2)); ?> </h1> <p> You may optionally enter a comparison operator (<, <=, >, >=, <> or =) at the beginning of each of your search values to specify how the comparison should be done. </p> <?php echo GxHtml::link(Yii::t('app', 'Advanced Search'), '#', array('class' => 'search-button')); ?> <div class="search-form"> <?php $this->renderPartial('_search', array('model' => $model)); ?> </div><!-- search-form --> <?php $this->widget('zii.widgets.grid.CGridView', array('id' => 'beneficiary-attribute-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array('id', array('name' => 'beneficiary_id', 'value' => 'GxHtml::valueEx($data->beneficiary)', 'filter' => GxHtml::listDataEx(Beneficiary::model()->findAllAttributes(null, true))), array('name' => 'attribute_id', 'value' => 'GxHtml::valueEx($data->attribute)', 'filter' => GxHtml::listDataEx(Attribute::model()->findAllAttributes(null, true))), 'value', 'create_date', 'deleted_at', array('class' => 'CButtonColumn'))));
public function actionImport() { $model = new Beneficiary('search'); $model->unsetAttributes(); $result = new BeneficiaryImportResult(); $count_inserted = 0; $count_updated = 0; if (isset($_FILES) && !empty($_FILES)) { move_uploaded_file($_FILES['UploadFileName']['tmp_name'], Yii::app()->params['IMPORT_PATH'] . $_FILES['UploadFileName']['name']); Yii::import('application.extensions.phpexcel.Classes.PHPExcel', true); $objReader = new PHPExcel_Reader_Excel5(); $objPHPExcel = $objReader->load(Yii::app()->params['IMPORT_PATH'] . $_FILES['UploadFileName']['name']); $objWorksheet = $objPHPExcel->getActiveSheet(); $highestRow = $objWorksheet->getHighestRow(); // e.g. 10 $highestColumn = $objWorksheet->getHighestColumn(); // e.g 'F' $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); // e.g. 5 $criteria = new CDbCriteria(); $criteria->addCondition('name="Active"'); // created Status for vouchers $status = BeneficiaryStatus::model()->find($criteria); $inserted_arr = []; $updated_arr = []; for ($row = 2; $row <= $highestRow; ++$row) { $criteria = new CDbCriteria(); $criteria->addCondition('registration_code="' . $objWorksheet->getCellByColumnAndRow(0, $row)->getValue() . '"'); // created Status for vouchers $beneficiary = Beneficiary::model()->find($criteria); $insert = 0; if (!$beneficiary) { $beneficiary = new Beneficiary(); $insert = 1; $count_inserted++; //$result->set_count_inserted($result->get_count_inserted()++); } else { $count_updated++; } //$result->set_count_updated($result->get_count_updated()++); $communitycriteria = new CDbCriteria(); $communitycriteria->addCondition('en_name="' . $objWorksheet->getCellByColumnAndRow(6, $row)->getValue() . '"'); $community = Community::model()->find($communitycriteria); $beneficiary->registration_code = $objWorksheet->getCellByColumnAndRow(0, $row)->getValue(); $beneficiary->ar_name = $objWorksheet->getCellByColumnAndRow(1, $row)->getValue() ? $objWorksheet->getCellByColumnAndRow(1, $row)->getValue() : $beneficiary->ar_name; $beneficiary->en_name = $objWorksheet->getCellByColumnAndRow(2, $row)->getValue() ? $objWorksheet->getCellByColumnAndRow(2, $row)->getValue() : $beneficiary->en_name; $beneficiary->family_member = $objWorksheet->getCellByColumnAndRow(3, $row)->getValue() ? $objWorksheet->getCellByColumnAndRow(3, $row)->getValue() : $beneficiary->family_member; $beneficiary->main_income_source = $objWorksheet->getCellByColumnAndRow(4, $row)->getValue() ? $objWorksheet->getCellByColumnAndRow(4, $row)->getValue() : $beneficiary->main_income_source; $beneficiary->combine_household = $objWorksheet->getCellByColumnAndRow(5, $row)->getValue() ? $objWorksheet->getCellByColumnAndRow(5, $row)->getValue() : $beneficiary->combine_household; $beneficiary->phone_number = $objWorksheet->getCellByColumnAndRow(7, $row)->getValue() ? $objWorksheet->getCellByColumnAndRow(7, $row)->getValue() : $beneficiary->phone_number; $beneficiary->neighborhood_id = $objWorksheet->getCellByColumnAndRow(6, $row)->getValue() ? $community->id : $beneficiary->neighborhood_id; $beneficiary->status_id = $status->id; $beneficiary->save(); if ($insert) { array_push($inserted_arr, $beneficiary->registration_code); } else { array_push($updated_arr, $beneficiary->registration_code); } } } else { $result->set_error('No File Selected'); } $result->set_count_inserted($count_inserted); $result->set_count_updated($count_updated); $result->set_record_inserted($inserted_arr); $result->set_record_updated($updated_arr); return $this->sendAjaxResponse($result); }
</p> <?php echo $form->errorSummary($model); ?> <div class="row"> <?php echo $form->labelEx($model, 'name'); ?> <?php echo $form->textField($model, 'name', array('maxlength' => 50)); ?> <?php echo $form->error($model, 'name'); ?> </div><!-- row --> <label><?php echo GxHtml::encode($model->getRelationLabel('beneficiaries')); ?> </label> <?php echo $form->checkBoxList($model, 'beneficiaries', GxHtml::encodeEx(GxHtml::listDataEx(Beneficiary::model()->findAllAttributes(null, true)), false, true)); ?> <?php echo GxHtml::submitButton(Yii::t('app', 'Save')); $this->endWidget(); ?> </div><!-- form -->
function may($u, $lvl) { global $USER; if ($u === $USER && $USER->ID !== NOBODY) { return true; } else { $pr = parent::may($u, $lvl); if (is_bool($pr) || $USER->ID == NOBODY) { return $pr; } else { if ($lvl & READ) { return true; } else { return $pr; } } } }
public function doEditTransaction($id) { $transaction = Auth::user()->transactions()->find($id); if ($transaction) { // set some basic values: $transaction->amount = floatval(Input::get('amount')); $transaction->date = Input::get('date'); $transaction->onetime = Input::get('onetime') == 'on' ? 1 : 0; $transaction->description = Input::get('description'); if (Input::get('type') == 'min') { $transaction->amount = $transaction->amount * -1; } if (!is_null(Input::get('account'))) { $account = Auth::user()->accounts()->find(Input::get('account')); if (!is_null($account)) { $transaction->account_id = $account->id; } } // budget if (intval(Input::get('budget')) > 0) { $budget = Auth::user()->budgets()->find(intval(Input::get('budget'))); if (!is_null($budget)) { $transaction->budget_id = $budget->id; } } // category if (strlen(Input::get('category')) != 0) { $categories = Auth::user()->categories()->get(); //->where('name','=',Input::get('category'))->first(); $category = null; foreach ($categories as $cat) { if (Crypt::decrypt($cat->name) == Input::get('category')) { $category = $cat; break; } } unset($cat, $categories); if (is_null($category)) { $category = new Category(); $category->fireflyuser_id = Auth::user()->id; $category->name = Input::get('category'); $category->showtrend = 0; $category->icon_id = Icon::first()->id; // FIXME moet niet hardcoded $validator = Validator::make($category->toArray(), Category::$rules); if ($validator->passes()) { $category->name = Crypt::encrypt($category->name); $category->save(); $transaction->category_id = $category->id; } } else { $transaction->category_id = $category->id; } } else { $transaction->category_id = null; } // beneficiary if (strlen(Input::get('beneficiary')) != 0) { $beneficiaries = Auth::user()->beneficiaries()->get(); //->where('name','=',Input::get('beneficiary'))->first(); $beneficiary = null; foreach ($beneficiaries as $ben) { if (Crypt::decrypt($ben->name) == Input::get('beneficiary')) { $beneficiary = $ben; break; } } unset($ben, $categories); if (is_null($beneficiary)) { $beneficiary = new Beneficiary(); $beneficiary->fireflyuser_id = Auth::user()->id; $beneficiary->name = Input::get('beneficiary'); $validator = Validator::make($beneficiary->toArray(), Beneficiary::$rules); if ($validator->passes()) { $beneficiary->name = Crypt::encrypt($beneficiary->name); $beneficiary->save(); $transaction->beneficiary_id = $beneficiary->id; } } else { $transaction->beneficiary_id = $beneficiary->id; } } else { $transaction->beneficiary_id = null; } $validator = Validator::make($transaction->toArray(), Transaction::$rules); $transaction->description = Crypt::encrypt($transaction->description); if ($validator->fails()) { return Redirect::to('/home/transaction/edit/' . $transaction->id)->withErrors($validator)->withInput(); } else { // work the tags $tags = explode(',', Input::get('tags')); $sync = array(); foreach ($tags as $tag) { $dbTag = Tag::findOrCreate($tag); $sync[] = $dbTag->id; } $transaction->tags()->sync($sync); $transaction->save(); return Redirect::to('/home/transactions'); } } else { return App::abort(404); } }
<span class="required">*</span> <?php echo Yii::t('app', 'are required'); ?> . </p> <?php echo $form->errorSummary($model); ?> <div class="row"> <?php echo $form->labelEx($model, 'beneficiary_id'); ?> <?php echo $form->dropDownList($model, 'beneficiary_id', GxHtml::listDataEx(Beneficiary::model()->findAllAttributes(null, true))); ?> <?php echo $form->error($model, 'beneficiary_id'); ?> </div><!-- row --> <div class="row"> <?php echo $form->labelEx($model, 'attribute_id'); ?> <?php echo $form->dropDownList($model, 'attribute_id', GxHtml::listDataEx(Attribute::model()->findAllAttributes(null, true))); ?> <?php echo $form->error($model, 'attribute_id'); ?>
/** * Give members right to see the group by default * (non-PHPdoc) * @see lib/MenuItem#may($u, $lvl) */ function may($u, $lvl) { $pr = parent::may($u, $lvl); if (is_bool($pr)) { return $pr; } elseif ($lvl & READ) { return $this->isMember($u); } else { return $pr; } }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = Beneficiary::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionsync() { $this->layout = false; $return = []; $error = 0; $lang = 'en'; $error_count = 0; $sync_count = 0; $in_array = array('en', 'ar', 'tr'); $history_intry = new VoucherHistory(); $history_intry->action = VoucherAction::model()->find("name = 'SYNC'")->id; if (isset($_POST) && !empty($_POST)) { // IMPORT MOBILE DATA $post = ""; //foreach ($_POST as $key => $value) { // $post .= $key . " => " . $value . "/"; //} $history_intry->parameters = $post; if (isset($_POST['lang']) && !empty($_POST['lang']) && in_array($_POST['lang'], $in_array)) { $lang = filter_input(INPUT_GET, "lang", FILTER_SANITIZE_STRING); } if (!isset($_POST['redeemed_voucher']) || empty($_POST['redeemed_voucher'])) { $this->respond('ERR_INVALID_REEQUEST', [], $lang, $history_intry); } if (!isset($_POST['imei']) || empty($_POST['imei'])) { $this->respond('ERR_INVALID_REEQUEST', [], $lang, $history_intry); } $voucher_codes = $_POST['redeemed_voucher']; $redeem_redeemed_status = VoucherStatus::model()->find("name = :name", array(":name" => "REDEEMED")); foreach ($voucher_codes as $voucher_code) { $voucher = Voucher::model()->find("code = :code", array(":code" => $voucher_code)); if (!$voucher) { $error_count += 1; $error .= $voucher_code . ", "; } else { $voucher->status_id = $redeem_redeemed_status->id; $voucher->sync_date = new CDbExpression('NOW()'); $voucher->update(); $voucher->save(); $sync_count += 1; } } if ($error_count > 0) { $err_arr = []; $err_arr['count'] = $error_count; $err_arr['vouchers'] = $error; $this->respond("NOT_ALL_SYNCED", $err_arr, $lang, $history_intry); } else { $this->respond(NULL, $sync_count, $lang, $history_intry); } } elseif (isset($_GET) && !empty($_GET)) { // SEND NEW DATA $get = ""; foreach ($_GET as $key => $value) { $get .= $key . " => " . $value . "/"; } $history_intry->parameters = $get; if (!isset($_GET['imei']) || empty($_GET['imei'])) { $this->respond('ERR_INVALID_REEQUEST', [], $lang, $history_intry); } if (isset($_GET['lang']) && !empty($_GET['lang']) && in_array($_GET['lang'], $in_array)) { $lang = filter_input(INPUT_GET, "lang", FILTER_SANITIZE_STRING); } $imei = $_GET['imei']; $phone = Phone::model()->find("imei = :imei", array(":imei" => $imei)); if (!$phone) { $this->respond('ERR_INVALID_REEQUEST', [], $lang, $history_intry); } $vendor_mobiles = VendorMobile::model()->findAll("phone_id = :phone_id", array(":phone_id" => $phone->id)); $export_list = []; $update_list = []; foreach ($vendor_mobiles as $vendor_mobile) { $voucher_status = VoucherStatus::model()->find("name = :name", array(":name" => "PENDING")); $vouchers = Voucher::model()->findAll("status_id = :status_id and vendor_id = :vendor_id", array(":status_id" => $voucher_status->id, ":vendor_id" => $vendor_mobile->vendor_id)); //print_r($vouchers); foreach ($vouchers as $voucher) { $obj = new stdClass(); if ($voucher->distributionVoucher->subdistribution->distribution->id == $vendor_mobile->distribution_id) { foreach ($voucher as $key => $value) { $obj->{$key} = $value; } $beneficiary = Beneficiary::model()->findByPk($voucher->ben_id); if ($beneficiary->registration_code) { $obj->registration_code = $beneficiary->registration_code; } $subdistribution = $voucher->distributionVoucher->subdistribution; $obj->start_date = $subdistribution->start_date; $obj->expiration_date = $subdistribution->end_date; $obj->status_name = $voucher->status->name; array_push($export_list, $obj); array_push($update_list, $voucher); } } } $this->respond(NULL, $export_list, $lang, $history_intry, false); foreach ($update_list as $item) { $in_mobile_status = VoucherStatus::model()->find("name = 'IN_MOBILE'"); $item->status_id = $in_mobile_status->id; $item->update(); $item->save(); } Yii::app()->end(); } else { $this->respond('ERR_INVALID_REEQUEST', [], $lang, NULL); } }