public function testIsReferred() { //Insert into referral table $referral = new Referral(); $referral->status = Referral::REFERRED_IN; $referral->facility_id = 1; $referral->person = "Gentrix"; $referral->contacts = "Saville Row : London"; $referral->user_id = 1; $specimen = Specimen::find(1); $referral->save(); $specimen->referral_id = $referral->id; $specimen->save(); $this->assertEquals($specimen->isReferred(), true); }
/** * save referral code * * @param model of user, referral_code * @return boolean */ public function giveReferralCode($user, $referral) { //save voucher referral $newvoucher = new Referral(); $newvoucher->fill(['user_id' => $user->id, 'code' => $referral, 'type' => 'referral', 'value' => 0, 'started_at' => null, 'expired_at' => null]); if (!$newvoucher->save()) { $this->errors = $newvoucher->getError(); return false; } else { //save quota referral $quota = StoreSetting::type('first_quota')->Ondate('now')->first(); if (!$quota) { $this->errors = 'Tidak dapat melakukan registrasi saat ini.'; return false; } else { $newquota = new QuotaLog(); $newquota->fill(['voucher_id' => $newvoucher['id'], 'amount' => $quota->value, 'notes' => 'Hadiah registrasi']); if (!$newquota->save()) { $this->errors = $newquota->getError(); return false; } } } return true; }
/** * Refer action * * @return View */ public function referAction() { //Validate $rules = array('referral-status' => 'required', 'facility_id' => 'required|non_zero_key', 'person', 'contacts'); $validator = Validator::make(Input::all(), $rules); $specimenId = Input::get('specimen_id'); if ($validator->fails()) { return view('test.refer', array($specimenId))->withInput()->withErrors($validator); } //Insert into referral table $referral = new Referral(); $referral->status = Input::get('referral-status'); $referral->facility_id = Input::get('facility_id'); $referral->person = Input::get('person'); $referral->contacts = Input::get('contacts'); $referral->user_id = Auth::user()->id; //Update specimen referral status $specimen = Specimen::find($specimenId); DB::transaction(function () use($referral, $specimen) { $referral->save(); $specimen->referral_id = $referral->id; $specimen->save(); }); //Start test Input::merge(array('id' => $specimen->test->id)); //Add the testID to the Input $this->start(); //Return view $url = session('SOURCE_URL'); return redirect()->to($url)->with('message', trans('messages.specimen-successful-refer'))->with('activeTest', array($specimen->test->id)); }