/** * Get the owner for this property. */ public function owner() { $foreignKey = 'strIDNumber'; $localKey = 'strIdentity'; $instance = new Owner(); $instance->setConnection($this->getConnectionName()); return new HasOne($instance->newQuery(), $this, $foreignKey, $localKey); // return $this->hasOne('App\Owner','strIDNumber' ,'strIdentity' ); }
/** * Run the database seeds. * * @return void */ public function run() { $owner_id = \App\Owner::where('last_name', '=', 'Murphy')->pluck('id'); DB::table('tasks')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'owner_id' => $owner_id, 'title' => 'Mow the lawn', 'user_id' => 1, 'detail' => 'Cut the grass in the front and side yard. Weedwack the walkway.', 'status' => 'Not started']); $owner_id = \App\Owner::where('last_name', '=', 'Harvard')->pluck('id'); DB::table('tasks')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'owner_id' => $owner_id, 'title' => 'Paint shed', 'user_id' => 1, 'detail' => 'Paint the shed in the backyard', 'status' => 'Completed']); $owner_id = \App\Owner::where('last_name', '=', 'Harvard')->pluck('id'); DB::table('tasks')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'owner_id' => $owner_id, 'user_id' => 1, 'title' => 'Complete final project', 'detail' => 'Complete P4 for Dynamic Web Applications.', 'status' => 'In progress']); }
public function index(Request $request) { // set database $database = Auth::user()->getDatabase(); //change database for notes $owner = new Owner(); $owner->changeConnection($database); //change database for Street $property = new Property(); $property->changeConnection($database); // get inputs $Input = $request->input('input'); $Select = $request->input('selected'); //dd( $streetInput,$streetSelect); // check if input or select // if input ignore select if (strlen($Input) > 0) { // search $search = $Input; $properties = Property::on($database)->where('strOwners', 'LIKE', "%{$search}%")->orderby('strOwners', 'ASC')->get(); } else { $owner = Property::on($database)->where('id', $Select)->first(); $search = $owner->strOwners; $properties = Property::on($database)->where('strOwners', $search)->orderby('strOwners', 'ASC')->get(); } Session::put('search', $Input); Session::put('controllerroute', '/owners'); // view properties // return with error if no result if ($properties->count()) { return view('owners', compact('properties', 'search')); } else { Session::flash('flash_message', '' . "No properties matching search criteria."); Session::flash('flash_type', 'alert-danger'); return Redirect::back(); } }
public function newMultiUnit($updatesA, $unit, $database) { $echo = "Entering newMultiUnit ........................................ "; File::append($this->logfilename, $echo . "\r\n"); //dd($updatesA, $unit); // check if multiple units // get sqM for specific unit $a = explode(" & ", $updatesA['strComplexNo']); $sqM = explode(" & ", $updatesA['strSqMeters']); $found = in_array($unit, $a); if ($found) { $place = array_search($unit, $a); $updatesA['strSqMeters'] = $sqM[$place]; } $now = \Carbon\Carbon::now('Africa/Johannesburg')->toDateTimeString(); $updatesA['id'] = null; $updatesA['strKey'] = $updatesA['strKey']; $updatesA['numStreetNo'] = $updatesA['strStreetNo']; $updatesA['numComplexNo'] = $updatesA['strComplexNo']; $updatesA['created_at'] = $now; // dd($updatesA, $a, $found, $place, $a[$place], $sqM[$place]); // delete older ones $delOld = Property::on($database)->where('strKey', $updatesA['strKey'])->where(DB::raw("STR_TO_DATE(dtmRegDate, '%Y-%m-%d')"), '<', Date($updatesA['dtmRegDate']))->delete(); $echo = "..DELETE OLD ............ " . $updatesA['strKey'] . " - " . $delOld; File::append($this->logfilename, $echo . "\r\n"); // insert new property record Property::on($database)->insert($updatesA); // add owner record if not existing // $hascontact = Owner::on($database)->select('id')->where('strIDNumber', '=', $updatesA['strIdentity']); if ($hascontact->count() == 0) { // update details from admin contacts $admin_contacts = "farmbook_admin"; $otf = new \App\Database\OTF(['database' => $admin_contacts]); $db = DB::connection($admin_contacts); $owner_details = Contact::on($admin_contacts)->select('*')->where('strIDNumber', $updatesA['strIdentity'])->first(); // contact details found in admin contacts if (sizeof($owner_details) == 1) { $uid = $owner_details->strIDNumber; // set database back $dbname = $database; $otf = new \App\Database\OTF(['database' => $dbname]); $db = DB::connection($dbname); // update contact details $owner = Owner::on($database)->insert(array('strIDNumber' => $owner_details->strIDNumber, 'NAME' => $owner_details->NAME, 'TITLE' => $owner_details->TITLE, 'INITIALS' => $owner_details->INITIALS, 'strSurname' => $owner_details->strSurname, 'strFirstName' => $owner_details->strFirstName, 'strHomePhoneNo' => $owner_details->strHomePhoneNo, 'strWorkPhoneNo' => $owner_details->strWorkPhoneNo, 'strCellPhoneNo' => $owner_details->strCellPhoneNo, 'EMAIL' => $owner_details->EMAIL, 'created_at' => $now, 'updated_at' => $now)); // update from prop rec } else { $dbname = $database; $otf = new \App\Database\OTF(['database' => $dbname]); $db = DB::connection($dbname); $owner = Owner::on($database)->insert(array('strIDNumber' => $updatesA['strIdentity'], 'NAME' => $updatesA['strOwners'], 'created_at' => $now)); } } else { // dont wipe old details } // add note // $hasnote = Note::on($database)->select('id')->where('strKey', '=', $updatesA['strKey'])->get(); if ($hasnote->count() == 0) { //$note = Note::on($database)->insert(array('strKey' => $updatesA[$x]['strKey'], 'numErf' => $updatesA[$x]['numErf'], 'memNotes' => "\n" . $now . ' ' . $updatesA[$x]['strOwners'] . ' - New Owner.', 'created_at' => $now)); $note = Note::on($database)->insert(array('strKey' => $updatesA['strKey'], 'numErf' => $updatesA['numErf'], 'created_at' => $now)); } else { $note = Note::on($database)->where('strKey', '=', $updatesA['strKey'])->update(array('memNotes' => DB::raw('concat(memNotes, " \\n' . $now . ' ' . $updatesA['strOwners'] . ' - New Owner.")'), 'updated_at' => $now)); } $echo = "Finishing newMultiUnit ........................................ "; File::append($this->logfilename, $echo . "\r\n"); }
public function update(Request $request) { // set database $database = Auth::user()->getDatabase(); //change database $owner = new Owner(); $owner->changeConnection($database); //change database $note = new Note(); $note->changeConnection($database); // get logged in user $user = Auth::user()->name; $now = Carbon\Carbon::now('Africa/Cairo')->toDateTimeString(); // get inputs $strKey = $request->input('strKey'); $strIdentity = $request->input('strIdentity'); $strOwners = $request->input('strOwners'); $homePhone = $request->input('strHomePhoneNo'); $workPhone = $request->input('strWorkPhoneNo'); $cellPhone = $request->input('strCellPhoneNo'); $email = $request->input('EMAIL'); $note = $request->input('note'); $newnote = $request->input('newnote'); $strStreetNo = $request->input('strStreetNo'); $strStreetName = $request->input('strStreetName'); $followup = $request->input('followup'); $date = ""; if (strLen($followup) > 0) { $date = Carbon\Carbon::createFromFormat('Y-m-d', $followup); } try { // update personal details // $owner = Owner::on( $database )->where('strIDNumber', $strIdentity)->update(array('strCellPhoneNo' => $cellPhone, // 'strHomePhoneNo' => $homePhone, // 'strWorkPhoneNo' => $workPhone, // 'EMAIL' => $email, // 'updated_at'=> $now // )); $properties = Property::on($database)->where('strKey', $strKey)->update(array('strStreetNo' => $strStreetNo, 'numStreetNo' => $strStreetNo, 'strStreetName' => $strStreetName)); //dd($properties); //update owner details $owner = Owner::on($database)->where('strIDNumber', $strIdentity)->first(); $owner->strHomePhoneNo = $homePhone; $owner->strCellPhoneNo = $cellPhone; $owner->strWorkPhoneNo = $workPhone; $owner->EMAIL = $email; $owner->save(); // check if there is a new note if (strlen($newnote) > 0) { // if a previous note exists add a carrige return and new note if (strlen($note) > 0) { $updatednote = ltrim(rtrim($note)) . "\n" . $now . " " . $user . " wrote: " . "\n" . $newnote; } else { // add just the new note $updatednote = $now . " " . $user . " wrote: " . "\n" . $newnote; } // update the note $affected = Note::on($database)->where('strKey', $strKey)->update(array('memNotes' => $updatednote, 'followup' => $date, 'updated_at' => $now)); } Note::on($database)->where('strKey', $strKey)->update(array('followup' => $date, 'updated_at' => $now)); } catch (exception $e) { Session::flash('flash_message', 'Error ' . $e->getMessage()); Session::flash('flash_type', 'alert-danger'); return Redirect::back(); } Session::flash('flash_message', 'Updated ' . $strOwners . ' at ' . $now); Session::flash('flash_type', 'alert-success'); return Redirect::back(); }
public static function disassocLog($id) { $device = Device::find($id); $device_log = new DeviceLog(); $device_log->owner_id = $device->owner_id; $device_log->device_id = $id; $device_log->user_id = \Auth::user()->id; $device_log->action = "DISASSOCIATE"; $device_log->save(); $owner_id = $device_log->owner_id; $owner = Owner::find($owner_id); $device->owner_id = 0; $device->save(); return redirect()->back()->with('success_msg', $device->name . ' was DISASSOCIATED to ' . $owner->fullName())->with('message_label', 'alert-success'); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $owner = Owner::findOrFail($id); $owner->delete(); return $id; }
public function openExcel(Request $request) { //return $category_id; $import_excel = Owner::importOwner($request); return $import_excel; }
/** * Show the application welcome screen to the user. * * @return Response */ public function index() { $owners = Owner::all(); return view('home', compact('owners')); }
public static function getOwnerCount() { return count(Owner::all()); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $sites = Site::paginate(); $owners = Owner::all(); return view('admin.sites.index', compact('sites', 'owners')); }
public function globContacts(Request $request) { $start = \Carbon\Carbon::now('Africa/Johannesburg'); echo 'Start : ' . $start . '<br>'; // get all farmbook databases $farmbooks = Farmbook::orderBy('name')->get(); $email = Auth::user()->email; //log $action = 'GLOBAL UPDATE'; $comment = 'Contacts'; $append = \Carbon\Carbon::now('Africa/Johannesburg')->toDateTimeString() . ', ' . trim($email) . ', ' . $action . ',' . $comment; Storage::append('logfile.txt', $append); // loop through databases for ($x = 0; $x < $farmbooks->count(); $x++) { $error = 0; $database = $farmbooks[$x]->database; try { //change database $own = new Owner(); $own->changeConnection($database); // fetch records with missing info for te numbers and email $owners = Owner::on($database)->select('*')->where('strHomePhoneNo', '')->orWhere('strWorkPhoneNo', '')->orWhere('strCellPhoneNo', '')->orWhere('EMAIL', '')->get(); $noinfoowners = Owner::on($database)->select('*')->where('strHomePhoneNo', '')->Where('strWorkPhoneNo', '')->Where('strCellPhoneNo', '')->Where('EMAIL', '')->get(); $allowners = Owner::on($database)->select('*')->get(); //dd($owners); } catch (Exception $ex) { // echo "<br> ------------------------------------------------------------------" . "<br>"; // echo $x . ". " . $farmbooks[$x]->database . " <br>"; // echo " ** PROBLEM ** " . $ex->getMessage() . "<br>"; // echo " ------------------------------------------------------------------" . "<br>"; $error = 1; //dd(); } //dd($prop); if ($error == 0) { // check it has the farmbook2 ext $found = strpos($database, 'farmbook2'); // echo "<br> ------------------------------------------------------------------" . "<br>"; // if ($found == 0) { // echo "** ALERT ** Database has not got correct naming convention - farmbook2" . " <br>"; // } echo "<br> ------------------------------------------------------------------" . "<br>"; echo $x . ". Farmbook : " . $database . "<br><br>"; echo 'Local Owners : ' . $allowners->count() . "<br>"; echo 'Missing some info : ' . $owners->count() . "<br>"; echo 'Missing all info : ' . $noinfoowners->count() . "<br>"; if ($owners->count() > 0) { // echo " ------------------------------------------------------------------" . "<br>"; // $users = $farmbooks[$x]->users; $new = 0; $canupdate = 0; $can = 0; $canupdateRow = 0; $strHomePhoneNo = 0; $strWorkPhoneNo = 0; $strCellPhoneNo = 0; $EMAIL = 0; foreach ($owners as $owner) { //[0] echo " - " . $owner->NAME . " | " . $owner->strHomePhoneNo . " | " . $owner->strWorkPhoneNo . " | " . $owner->strCellPhoneNo . " | " . $owner->EMAIL . " | " . " <br>"; $found = Contact::select('*')->where('strIDNumber', $owner->strIDNumber)->get(); if ($found->count() > 0) { $new++; $can = 0; if ($owner->strHomePhoneNo == "" && $found[0]->strHomePhoneNo != "") { $canupdate++; $can++; $strHomePhoneNo++; $owner->strHomePhoneNo = $found[0]->strHomePhoneNo; } if ($owner->strWorkPhoneNo == "" && $found[0]->strWorkPhoneNo != "") { $canupdate++; $can++; $strWorkPhoneNo++; $owner->strWorkPhoneNo = $found[0]->strWorkPhoneNo; } if ($owner->strCellPhoneNo == "" && $found[0]->strCellPhoneNo != "") { $canupdate++; $can++; $strCellPhoneNo++; $owner->strCellPhoneNo = $found[0]->strCellPhoneNo; } if ($owner->EMAIL == "" && $found[0]->EMAIL != "") { $canupdate++; $can++; $EMAIL++; $owner->EMAIL = $found[0]->EMAIL; } if ($can > 0) { $canupdateRow++; $owner->update(); } } } echo ' Found in admin contacts : ' . $new . '<br><br>'; echo ' Can update fields : ' . $canupdate . '<br>'; echo ' Can update record : ' . $canupdateRow . '<br><br>'; echo 'strHomePhoneNo updates : ' . $strHomePhoneNo . '<br>'; echo 'strWorkPhoneNo updates : ' . $strWorkPhoneNo . '<br>'; echo 'strCellPhoneNo updates : ' . $strCellPhoneNo . '<br>'; echo 'EMAIL updates : ' . $EMAIL . '<br><br>'; //dd("end of first data"); } } } $end = \Carbon\Carbon::now('Africa/Johannesburg'); echo '<br><br>End : ' . $end . '<br><br>'; echo 'Time : ' . $end->diffForHumans($start); dd("The End"); }