public function actionAdmin() { $model = new Plan('search'); $model->unsetAttributes(); if (isset($_GET['Plan'])) { $model->setAttributes($_GET['Plan']); } $this->render('admin', array('model' => $model)); }
public function getShortestPath(Plan $plan) { $mutation = $this->selection->getMutations(); $places = $plan->getPlaces(); $from = array_shift($places); $roadmap = new Roadmap($places); $roadmap->addPlace($from); $roadmaps = $this->sortRoadmaps($this->explodeRoadmaps([$roadmap])); return $roadmaps[0]; }
public function testPayload() { $price = new Price(); $plan = new Plan(); foreach ($this->payload as $testCase) { echo "Testing case: " . json_encode($testCase) . "\n"; $price->setPricePerMinute($testCase["price"]["ppm"]); $plan->setMinutes($testCase["plan"]["min"]); $plan->setFareAdditionalMin($testCase["plan"]["fare"]); $this->assertEquals($plan->calculateCallCost($price, $testCase["duration"]), $testCase["result"]); } }
/** * Lists all models. */ public function actionIndex() { $model = new PurchasedPlan(); $form = new PurchasePlanForm(); if (isset($_POST['PurchasedPlan'])) { $form->attributes = $_POST['PurchasedPlan']; if ($form->validate()) { if ($_POST['PurchasedPlan']['realPayment'] == 0) { //$form->purchasePlan($this->getPlanType()); $this->redirect(array('index')); } else { $wl = WhiteLabel::model()->findByPk(Yii::app()->user->getWhiteLabelId()); if ($wl == null) { throw new Exception("Account doesn't exist"); } $plan = Plan::model()->findByAttributes(array('plan_id' => $form->plan_id, 'wlabel_id' => Yii::app()->user->getWhiteLabelId(), 'type' => $this->getPlanType())); if ($plan == null) { throw new Exception("Plan doesn't exist"); } if ($wl->payment_type == PaymentType::TYPE_PAYPAL) { $this->processPayPalPayment($wl, $plan); } else { if ($wl->payment_type == PaymentType::TYPE_AUTHORIZENET) { $this->processAuthnetPayment($wl, $plan); } } exit; } } } if (isset($_GET['PurchasedPlan'])) { $model->attributes = $_GET['PurchasedPlan']; } $this->render('index', array('model' => $model, 'planType' => $this->getPlanType())); }
/** * * 改进:使用延迟绑定,将这个函数写在父类里面 *返回某个用户所发布的所有计划列表 * @return CActiveDataProvider $dataProvider 返回CActiveDataProvider对象 * 使用attach的好处是随时绑定,不一定在初始化的时候绑定 */ public function getDataProvider(CFormModel &$condition) { $this->attachBehaviors(array('NearScopeBehavior' => array('class' => 'ext.behavior.NearScopeBehavior', 'latitude' => $condition->latitude, 'longitude' => $condition->longitude))); $dataProvider = new CActiveDataProvider(Plan::model()->unexpired()->near()->with('user'), array('pagination' => array('pageSize' => 20))); $dataProvider->setCriteria($this->addCondition($condition)); return $dataProvider; }
public static function ProrataDiscount($account_id, $month_sub, $plan_data, $new_plan_cost, $rem_day, $num_of_days, $prorata_bal) { $plan_det = Plan::where('account_id', '=', $account_id)->get()->first(); $old_plan_code = $plan_det->plan_code; $old_plan_amount = PlanCostDetail::where('plan_code', '=', $old_plan_code)->get()->first()->plan_cost; $old_plan_cost = round($old_plan_amount + $old_plan_amount * 0.14); $prorata_dis = $old_plan_cost - $prorata_bal; if ($month_sub == 'Monthly') { if ($plan_data != 0) { $prorata_cost = $new_plan_cost; $prorata_dis = $prorata_dis; $plan_amount = $new_plan_cost - $prorata_dis; return array("plan_amount" => $plan_amount, "prorata_dis" => $prorata_dis, "prorata_cost" => $prorata_cost); } else { $plan_amount = round($rem_day * ($new_plan_cost / $num_of_days)) - $prorata_dis; //var_dump($plan_cost_tax); die; $prorata_cost = $plan_amount; $prorata_dis = $new_plan_cost - $prorata_cost; return array("plan_amount" => $plan_amount, "prorata_dis" => $prorata_dis, "prorata_cost" => $prorata_cost); } } else { $plan_amount = $new_plan_cost; $prorata_cost = $new_plan_cost; $prorata_dis = 0; return array("plan_amount" => $plan_amount, "prorata_dis" => $prorata_dis, "prorata_cost" => $prorata_cost); } }
/** * Search Licenses */ static function search($q = NULL, $param = NULL, $product_code = NULL) { $_tbl_licenses = License::getTableName(); $_tbl_licensesUses = LicensesUses::getTableName(); $_tbl_transactions = Transaction::getTableName(); $_tbl_purchases = Purchase::getTableName(); $_tbl_products = Product::getTableName(); $_tbl_plans = Plan::getTableName(); $_tbl_buyers = Buyer::getTableName(); $fields = array("{$_tbl_licenses}.*", DB::raw("COUNT({$_tbl_licensesUses}.id) AS totalUsed"), "{$_tbl_buyers}.first_name", "{$_tbl_buyers}.last_name", "{$_tbl_buyers}.email", "{$_tbl_products}.code", "{$_tbl_plans}.code AS plan_code", "{$_tbl_products}.api_key"); $licenses = DB::table($_tbl_licenses)->leftJoin($_tbl_licensesUses, "{$_tbl_licensesUses}.license_id", '=', "{$_tbl_licenses}.id")->join($_tbl_transactions, "{$_tbl_transactions}.id", '=', "{$_tbl_licenses}.transaction_id")->join($_tbl_plans, "{$_tbl_transactions}.plan_id", '=', "{$_tbl_plans}.id")->join($_tbl_purchases, "{$_tbl_purchases}.id", '=', "{$_tbl_transactions}.purchase_id")->join($_tbl_products, "{$_tbl_products}.id", '=', "{$_tbl_purchases}.product_id")->join($_tbl_buyers, "{$_tbl_buyers}.id", '=', "{$_tbl_purchases}.buyer_id")->select($fields)->groupBy("{$_tbl_licenses}.id"); $q = $q ? $q : Input::get('q'); $param = $param ? $param : Input::get('param'); if ($q) { if ($param == "key") { $licenses = $licenses->where("license_key", '=', $q); } if ($param == "email") { $licenses = $licenses->where("email", '=', $q); } if ($product_code) { $licenses = $licenses->where($_tbl_licenses . ".license_key", 'LIKE', strtoupper($product_code) . '-%'); } } return $licenses->orderBy($_tbl_licenses . '.created_at', 'DESC')->paginate(25); }
/** * Generate license */ public function postGenerateLicense() { $rules = array('transaction_id' => 'required'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::to('admin/utilities/generate-license')->withErrors($validator)->withInput(); } else { $transaction_id = Input::get('transaction_id'); if ($transaction = Transaction::where('id', '=', $transaction_id)->first()) { if ($license = License::where('transaction_id', '=', $transaction_id)->first()) { Session::flash('alert_error', '<strong>Ooops!</strong> License for given transaction already exists.'); return Redirect::to('admin/licenses?q=' . $license->license_key . '¶m=key'); } $plan = Plan::where('id', '=', $transaction->plan_id)->first(); if ($plan->has_license) { $product = Product::where('id', '=', $plan->product_id)->first(); $license_key = License::generate($product->code); // Save license $license = new License(); $license->license_key = $license_key; $license->transaction_id = $transaction_id; $license->allowed_usage = $plan->license_allowed_usage; $license->save(); Session::flash('alert_message', '<strong>Well done!</strong> You successfully have generated license key.'); return Redirect::to('admin/licenses?q=' . $license_key . '¶m=key'); } else { Session::flash('alert_error', '<strong>Ooops!</strong> This plan does not allow to generate a license key.'); return Redirect::to('admin/utilities/generate-license'); } } else { Session::flash('alert_error', '<strong>Ooops!</strong> Transaction was not found.'); return Redirect::to('admin/utilities/generate-license'); } } }
/** * * 查看plan的详细。在里面就包括了评论等具体的内容,注意,评论则需要分页。 * 因为plan本身已经返回,所以只返回评论的内容。 */ public function actionDetail($planId) { $plan = Plan::model()->findByPk('planId', 'planId=:planId', array(':planId' => $planId)); $dataProvider = $plan->getComments(); $this->page($dataProvider); $data = array('data' => $dataProvider); $this->render('detail', $data); }
public function plan() { $plans = Plan::where('account_id', '=', $this->account_id)->get(); if (count($plans) != 0) { return $plans->first(); } return null; }
function testTraerPlanesCompletosSinAnios() { $planIdSinAnios = 5; $params = array('recursive' => 3, 'conditions' => array('Plan.id' => $planIdSinAnios)); $ps = $this->Plan->__findCompleto($buscaroSoloContar = 'buscar', $params); $this->assertEqual(count($ps), 1); $this->assertTrue(empty($ps[0]['Anio'])); }
public function purchasePlan($planType, $advertiserId = '') { $transaction = Yii::app()->db->beginTransaction(); try { // load plan and its plan limits if ($planType == PlanType::ADVERTISER_PLAN) { $plan = Plan::model()->findByAttributes(array('plan_id' => $this->plan_id, 'wlabel_id' => Yii::app()->user->getWhiteLabelId(), 'type' => $planType)); } else { $plan = Plan::model()->findByAttributes(array('plan_id' => $this->plan_id, 'type' => $planType)); } if ($plan == null) { throw new Exception("Plan doesn't exist"); } $planLimits = PlanLimit::model()->findAllByAttributes(array('plan_id' => $plan->plan_id)); if ($planLimits == null) { // throw new Exception("Plan Limits don't exist"); } // create new purchased_plans record $purchasedPlan = new PurchasedPlan(); $purchasedPlan->plan_id = $plan->plan_id; if ($planType == PlanType::ADVERTISER_PLAN) { $purchasedPlan->wlabel_id = $plan->wlabel_id; } else { $purchasedPlan->wlabel_id = $this->wlabel_id; } $purchasedPlan->type = $plan->type; if ($planType == PlanType::ADVERTISER_PLAN) { if (Yii::app()->user->isAdvertiser()) { $purchasedPlan->advertiser_id = Yii::app()->user->getAdvertiserId(); } else { $purchasedPlan->advertiser_id = $advertiserId; } } else { } $purchasedPlan->method = 0; $purchasedPlan->price = $plan->price; $purchasedPlan->date_created = date("Y-m-d h:i:s"); if (!$purchasedPlan->validate()) { throw new Exception("Plan purchase cannot be saved: " . $this->putErrorsToString($purchasedPlan->getErrors())); } $purchasedPlan->save(); // create new purchased_plans payments record $purchasedPlanPayment = new PurchasedPlanPayment(); $purchasedPlanPayment->pplan_id = $purchasedPlan->pplan_id; $purchasedPlanPayment->date_paid = $purchasedPlan->date_created; $purchasedPlanPayment->date_expire = Date('y-m-d', strtotime("+{$plan->duration} day")); $purchasedPlanPayment->transaction_id = 'TEST_PAYMENT'; if (!$purchasedPlanPayment->validate()) { throw new Exception("Plan payment cannot be saved: " . $this->putErrorsToString($purchasedPlanPayment->getErrors())); } $purchasedPlanPayment->save(); } catch (Exception $e) { $transaction->rollBack(); throw new CHttpException(400, 'DB Exception: ' . $e->getMessage()); } $transaction->commit(); return false; }
public function actionIndex() { $this->layout = 'login'; $wlabelId = isset($_REQUEST['wid']) ? $_REQUEST['wid'] : ''; if ($wlabelId == '') { throw new CHttpException(404, 'Bad parameter wid'); } $planId = isset($_REQUEST['pid']) ? $_REQUEST['pid'] : ''; if ($planId == '') { throw new CHttpException(404, 'Bad parameter pid'); } $advertiserId = isset($_REQUEST['aid']) ? $_REQUEST['aid'] : ''; if ($advertiserId == '') { throw new CHttpException(404, 'Bad parameter aid'); } $returnUrl = isset($_REQUEST['return']) ? $_REQUEST['return'] : ''; if ($returnUrl == '') { throw new CHttpException(404, 'Bad parameter return'); } $wl = WhiteLabel::model()->findByPk(Yii::app()->user->getWhiteLabelId()); if ($wl == null) { throw new Exception("Account doesn't exist"); } $plan = Plan::model()->findByAttributes(array('plan_id' => $planId, 'wlabel_id' => $wlabelId)); if ($plan == null) { throw new CHttpException(404, 'Cannot find plan!'); } $advertiser = Advertiser::model()->findByAttributes(array('advertiser_id' => $planId, 'wlabel_id' => $advertiserId)); if ($plan == null) { throw new CHttpException(404, 'Cannot find advertiser!'); } $form = new AuthorizenetPaymentForm(); if (isset($_POST['AuthorizenetPaymentForm'])) { $form->attributes = $_POST['AuthorizenetPaymentForm']; $form->advertiser_id = $advertiserId; $form->wlabel_id = $wlabelId; $form->plan_id = $plan->plan_id; $form->refId = $plan->plan_id; $form->name = "Plan Subscription"; $form->unit = "days"; $form->totalOccurrences = 999; $form->trialOccurrences = 0; $form->trialAmount = 0; $form->startDate = date('Y-m-d'); $form->length = $plan->duration; $form->amount = $plan->price; if ($form->validate()) { if ($form->sendCreateSubscription($wl, $plan)) { $this->redirect($returnUrl); } } } if (isset($_GET['AuthorizenetPaymentForm'])) { $form->attributes = $_GET['AuthorizenetPaymentForm']; } $this->render('form_authnet_payment', array('model' => $form)); }
/** * Verify that a plan with a given ID exists, or create a new one if it does * not. */ protected static function retrieveOrCreatePlan($id) { self::authorizeFromEnv(); try { $plan = Plan::retrieve($id); } catch (Error\InvalidRequest $exception) { $plan = Plan::create(array('id' => $id, 'amount' => 0, 'currency' => 'usd', 'interval' => 'month', 'name' => 'Gold Test Plan')); } }
public function get_delete($id = NULL) { $plan = Plan::find($id); if (empty($plan)) { return View::make('msg.error')->with('error', 'Plan doesn\'t exist.'); } $plan->delete(); return Redirect::to('/admin/plan/overview'); }
public function actionIndex() { $plan = Plan::model(); $searchForm = $this->initParams('SearchForm', 'new'); $dataProvider = $plan->getDataProvider($searchForm); $this->page($dataProvider, true); $data = array('search' => $searchForm, 'dataProvider' => $dataProvider); $this->render('index', $data); }
public static function generate($input) { $res = []; $plan = Plan::findOrFail($input['plan_id']); $voucher['expires_on'] = self::_makeExpiry($input['validity'], $input['validity_unit']); $voucher['created_at'] = time(); $voucher['plan_name'] = $plan->name; $voucher['plan_type'] = $plan->plan_type; $voucher['sim_sessions'] = $plan->sim_sessions; $voucher['interim_updates'] = $plan->interim_updates; $voucher['price'] = $plan->price; $voucher['validity'] = $plan->validity; $voucher['validity_unit'] = $plan->validity_unit; $voucher['policy_type'] = $plan->policy_type; if ($plan->plan_type == 1) { //if limited $limit = $plan->limit->toArray(); if ($plan->limit->aq_access == 1) { // $limit['aq_access'] = 1; $aq_policy = Policy::findOrFail($plan->limit->aq_policy); $limit['aq_policy'] = mikrotikRateLimit($aq_policy->toArray()); } $voucher_limit = VoucherLimit::create($limit); $voucher['limit_id'] = $voucher_limit->id; } if ($plan->policy_type == 'Policy') { $policy = new VoucherPolicy(['bw_policy' => mikrotikRateLimit($plan->policy->toArray())]); $policy->save(); } elseif ($plan->policy_type == 'PolicySchema') { $days = ['mo' => 'monday', 'tu' => 'tuesday', 'we' => 'wednesday', 'th' => 'thursday', 'fr' => 'friday', 'sa' => 'saturday', 'su' => 'sunday']; foreach ($days as $d => $day) { $tpl = $plan->policy->{$day}->toArray(); $type = ['bw_policy', 'pr_policy', 'sec_policy']; foreach ($type as $t) { if (!is_null($tpl[$t])) { $policy = Policy::find($tpl[$t])->toArray(); $tpl[$t] = mikrotikRateLimit($policy); } } $template = VoucherPolicySchemaTemplate::create($tpl); $schema[$d] = $template->id; } $policy = VoucherPolicySchema::create($schema); } $voucher['policy_id'] = $policy->id; for ($i = 0; $i < $input['count']; $i++) { $voucher['pin'] = self::generatePin(); $voucher['expires_on'] = self::_makeExpiry($input['validity'], $input['validity_unit']); $v = new Voucher($voucher); if (!$v->save()) { return FALSE; } $res[] = $v->pin; } return $res; }
public static function billUpdate($id, $account_id, $for_month, $other_charges_new, $plan_code, $plan_start_date) { $bill = Bill::where('account_id', '=', $account_id)->where('for_month', $for_month)->get()->first(); // var_dump($bill,$for_month,$account_id);die; if (count($bill) != 0) { $plan = Plan::where('account_id', '=', $account_id)->get()->first(); $plan_cost_det = PlanCostDetail::where('plan_code', '=', $plan_code)->get()->first(); $planChange = PlanChangeDet::where('account_id', $account_id)->where('status', 'payment pending')->first(); if (count($planChange) != 0) { $planChange->plan_code = $plan_code; $planChange->plan_name = $plan_cost_det->plan_desc; $planChange->plan_change_date = $plan_start_date; $planChange->request_id = "44444"; $planChange->save(); } else { $planchange = new PlanChangeDet(); $planchange->account_id = $account_id; $planchange->plan_code = $plan_code; $planchange->plan_name = $plan_cost_det->plan_desc; $planchange->plan_change_date = $plan_start_date; $planchange->request_id = "44444"; $planchange->remarks = $bill->bill_no; $planchange->status = "payment pending"; $planchange->save(); } $account_id = $account_id; $for_month = $for_month; $other_charges_exit = OtherCharges::where('account_id', '=', $account_id)->where('for_month', $for_month)->where('id', '!=', $id)->sum('amount'); $other_charges_update = OtherCharges::where('id', $id)->first(); if (count($other_charges_update) != 0) { $sub_total = $bill->sub_total; $service_tax = $bill->service_tax; $total_charges = $sub_total + $service_tax; $amount_before_due_date = intval($bill->amount_before_due_date + $other_charges_update->amount); $amount_after_due_date = intval($bill->amount_before_due_date + $other_charges_update->amount); $other_charges_update->is_considered = 1; $other_charges_update->remarks = "planchange bill no " . $bill->bill_no; $other_charges_update->save(); $other_charges = $other_charges_update->amount; $amount_paid = $bill->amount_paid; } if ($amount_paid == 0) { $status = "not_paid"; } else { if ($amount_before_due_date > $amount_paid) { $status = "partially_paid"; } else { if ($amount_before_due_date <= $amount_paid) { $status = "paid"; } } } DB::table('bill_det')->where('bill_no', '=', $bill->bill_no)->update(array('other_charges' => $other_charges + $other_charges_exit, 'amount_before_due_date' => $amount_before_due_date, 'amount_after_due_date' => $amount_after_due_date, 'amount_paid' => $amount_paid, 'status' => $status)); return DB::table('bill_det')->where('bill_no', '=', $bill->bill_no)->first(); } }
public function testSave() { self::authorizeFromEnv(); $planID = 'gold-' . self::generateRandomString(20); $p = Plan::create(array('amount' => 2000, 'interval' => 'month', 'currency' => 'usd', 'name' => 'Plan', 'id' => $planID)); $p->name = 'A new plan name'; $p->save(); $this->assertSame($p->name, 'A new plan name'); $stripePlan = Plan::retrieve($planID); $this->assertSame($p->name, $stripePlan->name); }
public static function AssignPlan($user_id, $plan_id, $price = NULL) { DB::transaction(function () use($user_id, $plan_id, $price) { $oldPlan = APActivePlan::where('user_id', $user_id)->first(); if (!is_null($oldPlan)) { self::updatePlanHistory($oldPlan); } else { $oldPlan = new ApActivePlan(); } $plan = Plan::findOrFail($plan_id); $newPlan = ['user_id' => $user_id, 'plan_name' => $plan->name, 'plan_type' => $plan->plan_type, 'policy_type' => $plan->policy_type, 'sim_sessions' => $plan->sim_sessions, 'interim_updates' => $plan->interim_updates, 'aq_invocked' => 0, 'price' => $plan->price, 'time_balance' => NULL, 'data_balance' => NULL, 'assigned_on' => date("Y-m-d H:i:s"), 'validity' => $plan->validity, 'validity_unit' => $plan->validity_unit]; if ($price != NULL) { $newPlan['price'] = $price; } if ($plan->plan_type == LIMITED) { $limit = $plan->limit; if ($limit->limit_type == TIME_LIMIT || $limit->limit_type == BOTH_LIMITS) { $newPlan['time_balance'] = $limit->time_limit * constant($limit->time_unit); } if ($limit->limit_type == DATA_LIMIT || $limit->limit_type == BOTH_LIMITS) { $newPlan['data_balance'] = $limit->data_limit * constant($limit->data_unit); } if ($limit->aq_access == ALLOWED) { $aq_policy = Policy::findOrFail($limit->aq_policy); $limit->aq_policy = mikrotikRateLimit($aq_policy->toArray()); } $planLimit = APLimit::create($limit->toArray()); $newPlan['limit_id'] = $planLimit->id; } if ($plan->policy_type == 'Policy') { $policy = APPolicy::create(['bw_policy' => mikrotikRateLimit($plan->policy->toArray())]); } elseif ($plan->policy_type == 'PolicySchema') { $days = ['mo' => 'monday', 'tu' => 'tuesday', 'we' => 'wednesday', 'th' => 'thursday', 'fr' => 'friday', 'sa' => 'saturday', 'su' => 'sunday']; foreach ($days as $d) { $tpl = $plan->policy->{$day}->toArray(); $types = ['bw_policy', 'pr_policy', 'sec_policy']; foreach ($types as $t) { if (!is_null($tpl[$t])) { $policy = Policy::find($tpl[$t])->toArray(); $tpl[$t] = mikrotikRateLimit($policy); } } $template = APPolicySchemaTemplate::create($tpl); $schema[$d] = $template->id; } $policy = APPolicySchema::create($schema); } $newPlan['policy_id'] = $policy->id; $oldPlan->fill($newPlan); $oldPlan->save(); return TRUE; }); }
public function actionIndex() { $tempForm = $this->initParams('TempForm', 'new'); $data = array('tempForm' => $tempForm); if ($tempForm->validate()) { $plan = Plan::model(); $dataProvider = $plan->getDataProvider($tempForm); $this->page($dataProvider); $data = array_merge($data, array('dataProvider' => $dataProvider)); } else { $this->error->capture($tempForm); } $this->render('index', $data); }
public static function VeryPayment() { if ($user = Sentry::getUser()) { $dt = Carbon::now(); $payment = Payment::where('user_id', $user->id)->first(); $plan = Plan::find($payment->plan_id); $create = Carbon::parse($payment->created_at); if ($create->addDays($plan->time) > $dt) { return true; } else { return false; } } }
public function run() { Plan::updateOrCreate(['name' => 'Free'], array('name' => 'Free', 'interval' => 'permanent', 'interval_count' => 0, 'amount' => 0, 'braintree_plan_id' => null, 'description' => '<ul class="list-group"> <li class="list-group-item">We host the software</li> <li class="list-group-item">Access all free widgets</li> <li class="list-group-item">Community support</li> </ul> <p><small>Just create an account, and use the free functionalities without any install.</small></p>')); Plan::updateOrCreate(['name' => 'Premium'], array('name' => 'Premium', 'interval' => 'month', 'interval_count' => 12, 'amount' => 9, 'braintree_plan_id' => $_ENV['BRAINTREE_PREMIUM_PLAN_ID'], 'description' => '<ul class="list-group"> <li class="list-group-item">We host the software</li> <li class="list-group-item">Access all premium widgets</li> <li class="list-group-item">Email support</li> </ul> <p><small>Use the dashboard without any restrictions.</small></p>')); /* Send message to console */ error_log('PlanSeeder | All Plans updated'); }
public function actionIndex() { $plan = Plan::Model(); $plan->setScenario('detail'); $data = array('model' => Plan::model()); if (isset($_POST['Plan'])) { $plan->attributes = $_POST['Plan']; } if ($plan->validate()) { $dataProvider = new CActiveDataProvider(PlanComment::model()->with('user'), array('criteria' => array('condition' => 'planId=' . $plan->planId, 'order' => 'commentId DESC'), 'pagination' => array('pageSize' => 10))); $data = array_merge($data, array('dataProvider' => $dataProvider)); $this->page($dataProvider); } else { $this->error->capture($plan); } $this->render('index', $data); }
public function editarProyecto() { $idProyecto = Input::get('p'); //Obtiene el id del proyecto a trabajar. $ciclo = Proyecto::select('ciclo')->where('id', $idProyecto)->get(); $semestres = []; if (sizeof($ciclo) > 0) { if ($ciclo[0]->ciclo == "Enero-Julio") { $semestres = [2, 4, 6, 8]; } else { $semestres = [1, 3, 5, 7, 9]; } return View::make('proyectos.plantilla')->with('planes', Plan::all())->with('semestres', $semestres)->with('id', $idProyecto)->with('plantillas', Plantilla::select('plantillas.*', 'p.nombre as plan', 's.semestre')->join('subjects as s', 's.id', '=', 'plantillas.id_subject')->join('plans as p', 'p.id', '=', 's.id_plan')->where('id_proyecto', $idProyecto)->groupBy('s.semestre')->groupBy('plantillas.grupo')->get()); } else { return Redirect::to('proyectos'); } }
public function run() { // Create a new instance of Faker $faker = Faker\Factory::create(); // Create a plan $plan = Plan::create(['user_id' => 2]); // Attach an instructor //$plan->instructors()->attach(1); // Create some goals $goals = [new Goal(['plan_id' => 1, 'title' => ucwords(implode(' ', $faker->words(mt_rand(4, 10)))), 'summary' => $faker->text(mt_rand(25, 200)), 'created_at' => $faker->dateTimeBetween('-1 years'), 'updated_at' => $faker->dateTimeBetween('-1 years')]), new Goal(['plan_id' => 1, 'title' => ucwords(implode(' ', $faker->words(mt_rand(4, 10)))), 'summary' => $faker->text(mt_rand(25, 200)), 'created_at' => $faker->dateTimeBetween('-1 years'), 'updated_at' => $faker->dateTimeBetween('-1 years')]), new Goal(['plan_id' => 1, 'title' => ucwords(implode(' ', $faker->words(mt_rand(4, 10)))), 'summary' => $faker->text(mt_rand(25, 200)), 'created_at' => $faker->dateTimeBetween('-1 years'), 'updated_at' => $faker->dateTimeBetween('-1 years')]), new Goal(['plan_id' => 1, 'title' => ucwords(implode(' ', $faker->words(mt_rand(4, 10)))), 'summary' => $faker->text(mt_rand(25, 200)), 'created_at' => $faker->dateTimeBetween('-1 years'), 'updated_at' => $faker->dateTimeBetween('-1 years')])]; // Attach the goals to the plan $plan->goals()->saveMany($goals); // Create some comments for ($i = 0; $i < 15; $i++) { $date = $faker->dateTimeBetween('-1 years'); Comment::create(['goal_id' => mt_rand(1, 4), 'user_id' => mt_rand(1, 2), 'content' => $faker->text(mt_rand(10, 300)), 'created_at' => $date, 'updated_at' => $date]); } }
/** * postSubscribe * -------------------------------------------------- * @param (integer) ($planID) The requested Plan ID * @return Subscribes the user to the selected plan. * -------------------------------------------------- */ public function postSubscribe($planID) { /* Get the Plan */ $plan = Plan::find($planID); /* Wrong plan */ if ($plan === null) { return Redirect::route('payment.plans')->with(['error' => 'Something went wrong with your request, please try again.']); } /* Get the current subscription of the user */ $subscription = Auth::user()->subscription; /* Check if the plan has been modified. Redirect if not */ if ($subscription->plan->id == $plan->id) { return Redirect::route('payment.plans')->with(['success' => 'You have already been subscribed to the requested plan.']); } /* Check if the new plan has Braintree plan_id. Redirect to unsubscribe if not */ if ($plan->braintree_plan_id == null) { return Redirect::route('payment.unsubscribe'); } /* Check if the old plan has Braintree plan_id. Cancel the subscription if it has */ if ($subscription->braintree_subscription_id != null) { /* Cancel subscription */ $result = $subscription->cancelSubscription(); /* Check errors */ if ($result['errors'] == TRUE) { /* Return with errors */ return Redirect::route('payment.subscribe', $planID)->with('error', $result['messages']); } } /* Check for payment_method_nonce in input */ if (!Input::has('payment_method_nonce')) { return Redirect::route('payment.subscribe', $plan->id)->with('error', "Something went wrong with your request, please try again."); } /* Commit subscription */ $result = $subscription->createSubscription(Input::get('payment_method_nonce'), $plan); /* Check errors */ if ($result['errors'] == FALSE) { /* Return with success */ return Redirect::route('payment.subscribe', $planID)->with('success', 'Your subscription was successfull.'); } else { /* Return with errors */ return Redirect::route('payment.subscribe', $planID)->with('error', $result['messages']); } }
/** * cancelSubscription * -------------------------------------------------- * @return Cancels the subscription for the user * -------------------------------------------------- */ public function cancelSubscription() { /* Initialize variables */ $result = ['errors' => FALSE, 'messages' => '']; /* Get customer and update Braintree payment fields */ $result = $this->cancelBraintreeSubscription(); if ($result['errors'] == FALSE) { /* Get the free plan */ $freePlan = Plan::where('name', 'Free')->first(); /* Update the DB */ $this->plan()->associate($freePlan); $this->braintree_subscription_id = null; $this->current_period_start = Carbon::now(); $this->current_period_end = Carbon::now(); $this->save(); } /* Return the updated result */ return $result; }
public function purchasePlan($subscriptionId, $advertiserId = '') { $transaction = Yii::app()->db->beginTransaction(); try { // load plan and its plan limits $plan = Plan::model()->findByAttributes(array('plan_id' => $this->plan_id, 'wlabel_id' => $this->wlabel_id)); if ($plan == null) { throw new Exception("Plan doesn't exist"); } // create new purchased_plans record $purchasedPlan = new PurchasedPlan(); $purchasedPlan->plan_id = $plan->plan_id; $purchasedPlan->wlabel_id = $plan->wlabel_id; $purchasedPlan->type = $plan->type; $purchasedPlan->duration = $plan->duration; $purchasedPlan->method = PaymentType::TYPE_AUTHORIZENET; $purchasedPlan->subscription_id = $subscriptionId; $purchasedPlan->advertiser_id = $this->advertiser_id; $purchasedPlan->method = 0; $purchasedPlan->price = $plan->price; $purchasedPlan->date_created = date("Y-m-d h:i:s"); if (!$purchasedPlan->validate()) { throw new Exception("Plan purchase cannot be saved: " . $this->putErrorsToString($purchasedPlan->getErrors())); } $purchasedPlan->save(); // create new purchased_plans payments record $purchasedPlanPayment = new PurchasedPlanPayment(); $purchasedPlanPayment->pplan_id = $purchasedPlan->pplan_id; $purchasedPlanPayment->date_paid = $purchasedPlan->date_created; $purchasedPlanPayment->date_expire = Date('Y-m-d', strtotime("+{$plan->duration} day")); $purchasedPlanPayment->transaction_id = 'AUTHNET_INIT_PAYMENT'; if (!$purchasedPlanPayment->validate()) { throw new Exception("Plan payment cannot be saved: " . $this->putErrorsToString($purchasedPlanPayment->getErrors())); } $purchasedPlanPayment->save(); } catch (Exception $e) { $transaction->rollBack(); throw new CHttpException(400, 'DB Exception: ' . $e->getMessage()); } $transaction->commit(); return true; }
public function actionAddPlanPicture() { if (isset($_FILES) && count($_FILES) > 0 && ControleurRights::canAddPlans()) { $plan = new Plan(); $plan = Plan::getEntity($_POST['id_plan']); // Delete old picture if ($plan->getMedia_id() != null) { $old_media = Media::getEntity($plan->getMedia_id()); $old_media->deleteEntity(); } // Upload new picture $media_list = ControleurMedia::actionUploadNewMedia($_FILES, $_POST['id_plan'], $plan->getName()); // Save picture to plan $media = $media_list[0]; $media->setIs_main_media(true); $media->updateEntity(); $plan->setMedia_id($media->getId()); $plan->updateEntity(); } }