Esempio n. 1
0
 public function getuser()
 {
     if (empty(Input::get('response'))) {
         $id = 0;
     } else {
         $id = Input::get('response');
     }
     // TODO: check contact_type field and redirect to appropriate parish, diocese, person, etc.
     if ($id == 0) {
         return redirect()->action('PersonsController@create');
     } else {
         $contact = \montserrat\Contact::findOrFail($id);
         if ($contact->contact_type == CONTACT_TYPE_INDIVIDUAL) {
             return redirect()->action('PersonsController@show', $id);
         }
         switch ($contact->subcontact_type) {
             case CONTACT_TYPE_PARISH:
                 return redirect()->action('ParishesController@show', $id);
                 break;
             case CONTACT_TYPE_DIOCESE:
                 return redirect()->action('DiocesesController@show', $id);
                 break;
             case CONTACT_TYPE_VENDOR:
                 return redirect()->action('VendorsController@show', $id);
                 break;
             default:
                 return redirect()->action('OrganizationsController@show', $id);
         }
     }
 }
 public function edit_group($id)
 {
     //
     $registration = \montserrat\Registration::with('retreatant', 'retreat', 'room')->findOrFail($id);
     //        $retreat = \montserrat\Retreat::findOrFail($registration->event_id);
     $retreatant = \montserrat\Contact::findOrFail($registration->contact_id);
     $retreats = \montserrat\Retreat::select(\DB::raw('CONCAT(idnumber, "-", title, " (",DATE_FORMAT(start_date,"%m-%d-%Y"),")") as description'), 'id')->where("end_date", ">", \Carbon\Carbon::today())->orderBy('start_date')->pluck('description', 'id');
     //dd($retreats);
     //TODO: we will want to be able to switch between types when going from a group registration to individual room assignment
     if ($retreatant->contact_type == CONTACT_TYPE_INDIVIDUAL) {
         $retreatants = \montserrat\Contact::whereContactType(CONTACT_TYPE_INDIVIDUAL)->orderBy('sort_name')->pluck('sort_name', 'id');
     }
     if ($retreatant->contact_type == CONTACT_TYPE_ORGANIZATION) {
         $retreatants = \montserrat\Contact::whereContactType(CONTACT_TYPE_ORGANIZATION)->whereSubcontactType($retreatant->subcontact_type)->orderBy('sort_name')->pluck('sort_name', 'id');
     }
     $rooms = \montserrat\Room::orderby('name')->pluck('name', 'id');
     $rooms->prepend('Unassigned', 0);
     /* Check to see if the current registration is for a past retreat and if so, add it to the collection */
     // $retreats[0] = 'Unassigned';
     if ($registration->retreat->end < \Carbon\Carbon::now()) {
         $retreats[$registration->event_id] = $registration->retreat->idnumber . '-' . $registration->retreat->title . " (" . date('m-d-Y', strtotime($registration->retreat->start_date)) . ")";
     }
     return view('registrations.edit_group', compact('registration', 'retreats', 'rooms', 'retreatants'));
 }
 public function add($id, $a = NULL, $b = NULL)
 {
     $relationship_type = \montserrat\RelationshipType::findOrFail($id);
     $ignored_subtype = array();
     $ignored_subtype["Child"] = RELATIONSHIP_TYPE_CHILD_PARENT;
     $ignored_subtype["Parent"] = RELATIONSHIP_TYPE_CHILD_PARENT;
     $ignored_subtype["Husband"] = RELATIONSHIP_TYPE_HUSBAND_WIFE;
     $ignored_subtype["Wife"] = RELATIONSHIP_TYPE_HUSBAND_WIFE;
     $ignored_subtype["Sibling"] = RELATIONSHIP_TYPE_SIBLING;
     $ignored_subtype["Parishioner"] = RELATIONSHIP_TYPE_PARISHIONER;
     if (in_array($relationship_type->name_a_b, $ignored_subtype)) {
         $subtype_a_name = NULL;
     } else {
         $subtype_a_name = $relationship_type->name_a_b;
     }
     if (in_array($relationship_type->name_b_a, $ignored_subtype)) {
         $subtype_b_name = NULL;
     } else {
         $subtype_b_name = $relationship_type->name_b_a;
     }
     if (!isset($a) or $a == 0) {
         $contact_a_list = $this->get_contact_type_list($relationship_type->contact_type_a, $subtype_a_name);
     } else {
         $contacta = \montserrat\Contact::findOrFail($a);
         $contact_a_list[$contacta->id] = $contacta->sort_name;
     }
     if (!isset($b) or $b == 0) {
         $contact_b_list = $this->get_contact_type_list($relationship_type->contact_type_b, $subtype_b_name);
     } else {
         $contactb = \montserrat\Contact::findOrFail($b);
         $contact_b_list[$contactb->id] = $contactb->sort_name;
     }
     //dd($contact_b_list);
     return view('relationships.types.add', compact('relationship_type', 'contact_a_list', 'contact_b_list'));
     //
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     //
     $touchpoint = \montserrat\Touchpoint::with('staff', 'person')->findOrFail($id);
     $staff = \montserrat\Contact::with('groups')->whereHas('groups', function ($query) {
         $query->where('group_id', '=', GROUP_ID_STAFF);
     })->orderBy('sort_name')->pluck('sort_name', 'id');
     //consider renaming touchpoint table's person_id field to contact_id
     $contact = \montserrat\Contact::findOrFail($touchpoint->person_id);
     if (isset($contact->subcontact_type)) {
         $persons = \montserrat\Contact::whereSubcontactType($contact->subcontact_type)->orderBy('sort_name')->pluck('sort_name', 'id');
     } else {
         $persons = \montserrat\Contact::whereContactType($contact->contact_type)->orderBy('sort_name')->pluck('sort_name', 'id');
     }
     //$persons = \montserrat\Contact::whereContactType(CONTACT_TYPE_INDIVIDUAL)->orderBy('sort_name')->pluck('sort_name','id');
     // check contact type and if parish get list of parishes if individual get list of persons
     return view('touchpoints.edit', compact('touchpoint', 'staff', 'persons'));
     //
 }
Esempio n. 5
0
 public function contact_info_report($id)
 {
     $person = \montserrat\Contact::findOrFail($id);
     return view('reports.contact_info', compact('person'));
     //
 }
Esempio n. 6
0
 public function merge($contact_id, $merge_id = NULL)
 {
     $contact = \montserrat\Contact::findOrFail($contact_id);
     $similar = \montserrat\Contact::whereSortName($contact->sort_name)->get();
     $duplicates = $similar->keyBy('id');
     $duplicates->forget($contact->id);
     if (!empty($merge_id)) {
         $merge = \montserrat\Contact::findOrFail($merge_id);
         //dd($merge);
         if (empty($contact->prefix_id) && !empty($merge->prefix_id)) {
             $contact->prefix_id = $merge->prefix_id;
         }
         if (empty($contact->first_name) && !empty($merge->first_name)) {
             $contact->first_name = $merge->first_name;
         }
         if (empty($contact->nick_name) && !empty($merge->nick_name)) {
             $contact->nick_name = $merge->nick_name;
         }
         if (empty($contact->middle_name) && !empty($merge->middle_name)) {
             $contact->middle_name = $merge->middle_name;
         }
         if (empty($contact->last_name) && !empty($merge->last_name)) {
             $contact->last_name = $merge->last_name;
         }
         if (empty($contact->organization_name) && !empty($merge->organization_name)) {
             $contact->organization_name = $merge->organization_name;
         }
         if (empty($contact->suffix_id) && !empty($merge->suffix_id)) {
             $contact->suffix_id = $merge->suffix_id;
         }
         if (empty($contact->gender_id) && !empty($merge->gender_id)) {
             $contact->gender_id = $merge->gender_id;
         }
         if (empty($contact->birth_date) && !empty($merge->birth_date)) {
             $contact->birth_date = $merge->birth_date;
         }
         if (empty($contact->religion_id) && !empty($merge->religion_id)) {
             $contact->religion_id = $merge->religion_id;
         }
         if (empty($contact->occupation_id) && !empty($merge->occupation_id)) {
             $contact->occupation_id = $merge->occupation_id;
         }
         if (empty($contact->ethnicity_id) && !empty($merge->ethnicity_id)) {
             $contact->ethnicity_id = $merge->ethnicity_id;
         }
         $contact->save();
         //addresses
         if (NULL === $contact->address_primary) {
             $contact->address_primary = new \montserrat\Address();
             $contact->address_primary->contact_id = $contact->id;
             $contact->address_primary->is_primary = 1;
         }
         if (empty($contact->address_primary->street_address) && !empty($merge->address_primary->street_address)) {
             $contact->address_primary->street_address = $merge->address_primary->street_address;
         }
         if (empty($contact->address_primary->supplemental_address) && !empty($merge->address_primary->supplemental_address)) {
             $contact->address_primary->supplemental_address = $merge->address_primary->supplemental_address;
         }
         if (empty($contact->address_primary->city) && !empty($merge->address_primary->city)) {
             $contact->address_primary->city = $merge->address_primary->city;
         }
         if (empty($contact->address_primary->state_province_id) && !empty($merge->address_primary->state_province_id)) {
             $contact->address_primary->state_province_id = $merge->address_primary->state_province_id;
         }
         if (empty($contact->address_primary->postal_code) && !empty($merge->address_primary->postal_code)) {
             $contact->address_primary->postal_code = $merge->address_primary->postal_code;
         }
         if (empty($contact->address_primary->country_code) && !empty($merge->address_primary->country_code)) {
             $contact->address_primary->country_code = $merge->address_primary->country_code;
         }
         $contact->address_primary->save();
         //emergency_contact_info
         if (NULL === $contact->emergency_contact) {
             $contact->emergency_contact = new \montserrat\EmergencyContact();
             $contact->emergency_contact->contact_id = $contact->id;
         }
         if (empty($contact->emergency_contact->name) && !empty($merge->emergency_contact->name)) {
             $contact->emergency_contact->name = $merge->emergency_contact->name;
         }
         if (empty($contact->emergency_contact->relationship) && !empty($merge->emergency_contact->relationship)) {
             $contact->emergency_contact->relationship = $merge->emergency_contact->relationship;
         }
         if (empty($contact->emergency_contact->phone) && !empty($merge->emergency_contact->phone)) {
             $contact->emergency_contact->phone = $merge->emergency_contact->phone;
         }
         if (empty($contact->emergency_contact->phone_alternate) && !empty($merge->emergency_contact->phone_alternate)) {
             $contact->emergency_contact->phone_alternate = $merge->emergency_contact->phone_alternate;
         }
         $contact->emergency_contact->save();
         //emails
         foreach ($merge->emails as $email) {
             $contact_email = \montserrat\Email::firstOrNew(['contact_id' => $contact->id, 'location_type_id' => $email->location_type_id]);
             $contact_email->contact_id = $contact->id;
             $contact_email->location_type_id = $email->location_type_id;
             $contact_email->is_primary = $email->is_primary;
             //only create or overwrite if the current email address for the location is empty
             if (empty($contact_email->email)) {
                 $contact_email->email = $email->email;
                 $contact_email->save();
             }
         }
         //phones
         foreach ($merge->phones as $phone) {
             $contact_phone = \montserrat\Phone::firstOrNew(['contact_id' => $contact->id, "location_type_id" => $phone->location_type_id, "phone_type" => $phone->phone_type]);
             $contact_phone->contact_id = $contact->id;
             $contact_phone->location_type_id = $phone->location_type_id;
             $contact_phone->phone_type = $phone->phone_type;
             $contact_phone->is_primary = $phone->is_primary;
             //only create or overwrite if the current email address for the location is empty
             if (empty($contact_phone->phone)) {
                 $contact_phone->phone = $phone->phone;
                 $contact_phone->save();
             }
         }
         //notes - move all from merge to contact
         foreach ($merge->notes as $note) {
             $note->entity_id = $contact_id;
             $note->save();
         }
         //groups - move all from merge to contact
         foreach ($merge->groups as $group) {
             $group_exist = \montserrat\GroupContact::whereContactId($contact_id)->whereGroupId($group->group_id)->first();
             if (!isset($group_exist)) {
                 $group->contact_id = $contact_id;
                 $group->save();
             }
         }
         //relationships
         foreach ($merge->a_relationships as $a_relationship) {
             $a_relationship_exist = \montserrat\Relationship::whereContactIdA($contact_id)->whereContactIdB($a_relationship->contact_id_b)->whereRelationshipTypeId($a_relationship->relationship_type_id)->first();
             if (!isset($a_relationship_exist)) {
                 $a_relationship->contact_id_a = $contact_id;
                 $a_relationship->save();
             }
         }
         foreach ($merge->b_relationships as $b_relationship) {
             $b_relationship_exist = \montserrat\Relationship::whereContactIdB($contact_id)->whereContactIdA($b_relationship->contact_id_a)->whereRelationshipTypeId($b_relationship->relationship_type_id)->first();
             if (!isset($b_relationship_exist)) {
                 $b_relationship->contact_id_b = $contact_id;
                 $b_relationship->save();
             }
         }
         //touchpoints
         foreach ($merge->touchpoints as $touchpoint) {
             $touchpoint->person_id = $contact_id;
             $touchpoint->save();
         }
         //attachments
         foreach ($merge->attachments as $attachment) {
             $path = 'contact/' . $merge_id . '/attachments/' . $attachment->uri;
             $newpath = 'contact/' . $contact_id . '/attachments/' . $attachment->uri;
             Storage::move($path, $newpath);
             $attachment->entity_id = $contact->id;
             $attachment->save();
         }
     }
     return view('persons.merge', compact('contact', 'duplicates'));
 }