HEX
Server: Apache/2.4.46 (Ubuntu)
System: Linux localhost 5.11.0-49-generic #55-Ubuntu SMP Wed Jan 12 17:36:34 UTC 2022 x86_64
User: root (0)
PHP: 7.4.16
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/html/fieldsblaze-heroku/app/Http/Controllers/ContactController copy.php
<?php

namespace App\Http\Controllers;

use App\Models\Contact;

use Illuminate\Http\Request;
use App\Library\UserLib;
use DB;
use pgsqlSalesforce;

class ContactController extends Controller
{
    protected $userLib;
    public function __construct(UserLib $userLib)
	{
		$this->userLib = $userLib;	          
	}

    //testContact
    public function testContact(){
         
        // $Contact=DB::table('contact')->select()->get();
        // echo json_encode($Contact);
     

         $payLoad = '{"lastname":"Manoj","asssign_to__c":null,"languages__c":"English","crmid__c":null,"name":"Rose Gonzalez","alternate_email__c":null,"heroku_id__c":null,"device_name__c":null,"isdeleted":false,"systemmodstamp":"2023-01-31 06:36:53","status__c":null,"is_primary__c":null,"createddate":"2023-04-06 06:36:53","firstname":"Rose","email":"rose@edge.com","wedding_anniversary__c":null,"level__c":"Primary","sfid":"0032w00000yDBOmAAO","id":1,"_hc_lastop":null,"_hc_err":null}';

        // $payLoadArray = json_decode($payLoad,true);

        // DB::connection('pgsqlSalesforce')->table('contact')->insert($payLoadArray);

        // $params = [
        //     '{"Manoj4"},{"Gupta4"}'
        // ];

        // DB::connection('pgsqlSalesforce')->insert("insert into salesforce.contact (firstname, lastname) values ('Manoj2', 'Gupta')");


        DB::connection('pgsqlSalesforce')->table('salesforce.contact')->insert([
   ["firstname' => 'Peter', 'lastname'=>'Chicago']
]);



        //DB::connection('pgsqlSalesforce')->table('contact')->insert((info)'{"lastname":"Manoj","asssign_to__c":null,"languages__c":"English"}');


        //DB::connection('pgsqlSalesforce')->insert("insert into salesforce.contact (firstname, lastname) values ('Manoj2', 'Gupta')");


        // $Contact=DB::connection('pgsqlSalesforce')->table('contact')->select()->get();
        // echo json_encode($Contact);


        // {"lastname":"Gonzalez","asssign_to__c":null,"languages__c":"English","crmid__c":null,"name":"Rose Gonzalez","alternate_email__c":null,"heroku_id__c":null,"device_name__c":null,"isdeleted":false,"systemmodstamp":"2023-01-31 06:36:53","status__c":null,"is_primary__c":null,"createddate":"2023-01-31 06:36:53","firstname":"Rose","email":"rose@edge.com","wedding_anniversary__c":null,"level__c":"Primary","sfid":"0032w00000yDBOmAAO","id":1,"_hc_lastop":null,"_hc_err":null}
    }

    #All Contacts
    public function allContact(){
        if (empty(session('UserId'))) {
            return redirect('/admin/logout');
        }
        $Contact = Contact::select('tbl_contact.*', 'tbl_customer.CustomerName as CustomerName', 'tbl_customer.CustomerCode as CustomerCode', 'tbl_customer.CustomerId as CustomerId', 'tbl_countries.country_name as Country', 'tbl_admin.FirstName as Updated_by', 'tbl_admin.FirstName as Created_by')
        ->leftJoin('tbl_admin', 'tbl_contact.Updated_by', '=', 'tbl_admin.UserId')
        ->leftJoin('tbl_customer', 'tbl_contact.CustomerId', '=', 'tbl_customer.CustomerId')
        ->leftJoin('tbl_countries', 'tbl_contact.Country', '=', 'tbl_countries.id')
        ->where('tbl_contact.IsDeleted', '=', '0')
        ->orderBy('tbl_contact.id', 'desc')
        ->get();
        $ActiveContact = Contact::select('tbl_contact.*', 'tbl_customer.CustomerName as CustomerName', 'tbl_customer.CustomerCode as CustomerCode', 'tbl_customer.CustomerId as CustomerId', 'tbl_countries.country_name as Country', 'tbl_admin.FirstName as Updated_by', 'tbl_admin.FirstName as Created_by')
        ->leftJoin('tbl_admin', 'tbl_contact.Updated_by', '=', 'tbl_admin.UserId')
        ->leftJoin('tbl_customer', 'tbl_contact.CustomerId', '=', 'tbl_customer.CustomerId')
        ->leftJoin('tbl_countries', 'tbl_contact.Country', '=', 'tbl_countries.id')
        ->where('tbl_contact.IsDeleted', '=', '0')
        ->where('tbl_contact.Status', '=', '1')
        ->orderBy('tbl_contact.id', 'desc')
        ->get();
        $InActiveContact = Contact::select('tbl_contact.*', 'tbl_customer.CustomerName as CustomerName', 'tbl_customer.CustomerCode as CustomerCode', 'tbl_customer.CustomerId as CustomerId', 'tbl_countries.country_name as Country', 'tbl_admin.FirstName as Updated_by', 'tbl_admin.FirstName as Created_by')
        ->leftJoin('tbl_admin', 'tbl_contact.Updated_by', '=', 'tbl_admin.UserId')
        ->leftJoin('tbl_customer', 'tbl_contact.CustomerId', '=', 'tbl_customer.CustomerId')
        ->leftJoin('tbl_countries', 'tbl_contact.Country', '=', 'tbl_countries.id')
        ->where('tbl_contact.IsDeleted', '=', '0')
        ->where('tbl_contact.Status', '=', '0')
        ->orderBy('tbl_contact.id', 'desc')
        ->get();
        $TrashContact = Contact::select('tbl_contact.*', 'tbl_customer.CustomerName as CustomerName', 'tbl_customer.CustomerCode as CustomerCode', 'tbl_countries.country_name as Country', 'tbl_admin.FirstName as Updated_by', 'tbl_admin.FirstName as Created_by')
        ->leftJoin('tbl_admin', 'tbl_contact.Updated_by', '=', 'tbl_admin.UserId')
        ->leftJoin('tbl_customer', 'tbl_contact.CustomerId', '=', 'tbl_customer.CustomerId')
        ->leftJoin('tbl_countries', 'tbl_contact.Country', '=', 'tbl_countries.id')
        ->where('tbl_contact.IsDeleted', '=', '1')
        ->orderBy('tbl_contact.id', 'desc')
        ->get();
        return view('admin.all-contact', ['Contact' => $Contact, 'ActiveContact' => $ActiveContact, 'InActiveContact' => $InActiveContact, 'TrashContact' => $TrashContact]);
    }

    #Active Contacts
    public function activeContact(){
        if (empty(session('UserId'))) {
            return redirect('/admin/logout');
        }
        $Contact = Contact::select('tbl_contact.*', 'tbl_customer.CustomerName as CustomerName', 'tbl_customer.CustomerCode as CustomerCode', 'tbl_customer.CustomerId as CustomerId', 'tbl_countries.country_name as Country', 'tbl_admin.FirstName as Updated_by', 'tbl_admin.FirstName as Created_by')
        ->leftJoin('tbl_admin', 'tbl_contact.Updated_by', '=', 'tbl_admin.UserId')
        ->leftJoin('tbl_customer', 'tbl_contact.CustomerId', '=', 'tbl_customer.CustomerId')
        ->leftJoin('tbl_countries', 'tbl_contact.Country', '=', 'tbl_countries.id')
        ->where('tbl_contact.IsDeleted', '=', '0')
        ->orderBy('tbl_contact.id', 'desc')
        ->get();
        $ActiveContact = Contact::select('tbl_contact.*', 'tbl_customer.CustomerName as CustomerName', 'tbl_customer.CustomerCode as CustomerCode', 'tbl_customer.CustomerId as CustomerId', 'tbl_countries.country_name as Country', 'tbl_admin.FirstName as Updated_by', 'tbl_admin.FirstName as Created_by')
        ->leftJoin('tbl_admin', 'tbl_contact.Updated_by', '=', 'tbl_admin.UserId')
        ->leftJoin('tbl_customer', 'tbl_contact.CustomerId', '=', 'tbl_customer.CustomerId')
        ->leftJoin('tbl_countries', 'tbl_contact.Country', '=', 'tbl_countries.id')
        ->where('tbl_contact.IsDeleted', '=', '0')
        ->where('tbl_contact.Status', '=', '1')
        ->orderBy('tbl_contact.id', 'desc')
        ->get();
        $InActiveContact = Contact::select('tbl_contact.*', 'tbl_customer.CustomerName as CustomerName', 'tbl_customer.CustomerCode as CustomerCode', 'tbl_customer.CustomerId as CustomerId', 'tbl_countries.country_name as Country', 'tbl_admin.FirstName as Updated_by', 'tbl_admin.FirstName as Created_by')
        ->leftJoin('tbl_admin', 'tbl_contact.Updated_by', '=', 'tbl_admin.UserId')
        ->leftJoin('tbl_customer', 'tbl_contact.CustomerId', '=', 'tbl_customer.CustomerId')
        ->leftJoin('tbl_countries', 'tbl_contact.Country', '=', 'tbl_countries.id')
        ->where('tbl_contact.IsDeleted', '=', '0')
        ->where('tbl_contact.Status', '=', '0')
        ->orderBy('tbl_contact.id', 'desc')
        ->get();
        $TrashContact = Contact::select('tbl_contact.*', 'tbl_customer.CustomerName as CustomerName', 'tbl_customer.CustomerCode as CustomerCode', 'tbl_countries.country_name as Country', 'tbl_admin.FirstName as Updated_by', 'tbl_admin.FirstName as Created_by')
        ->leftJoin('tbl_admin', 'tbl_contact.Updated_by', '=', 'tbl_admin.UserId')
        ->leftJoin('tbl_customer', 'tbl_contact.CustomerId', '=', 'tbl_customer.CustomerId')
        ->leftJoin('tbl_countries', 'tbl_contact.Country', '=', 'tbl_countries.id')
        ->where('tbl_contact.IsDeleted', '=', '1')
        ->orderBy('tbl_contact.id', 'desc')
        ->get();
        return view('admin.active-contact', ['Contact' => $Contact, 'ActiveContact' => $ActiveContact, 'InActiveContact' => $InActiveContact, 'TrashContact' => $TrashContact]);
    }

    #InActive Contacts
    public function inactiveContact(){
        if (empty(session('UserId'))) {
            return redirect('/admin/logout');
        }
        $Contact = Contact::select('tbl_contact.*', 'tbl_customer.CustomerName as CustomerName', 'tbl_customer.CustomerCode as CustomerCode', 'tbl_customer.CustomerId as CustomerId', 'tbl_countries.country_name as Country', 'tbl_admin.FirstName as Updated_by', 'tbl_admin.FirstName as Created_by')
        ->leftJoin('tbl_admin', 'tbl_contact.Updated_by', '=', 'tbl_admin.UserId')
        ->leftJoin('tbl_customer', 'tbl_contact.CustomerId', '=', 'tbl_customer.CustomerId')
        ->leftJoin('tbl_countries', 'tbl_contact.Country', '=', 'tbl_countries.id')
        ->where('tbl_contact.IsDeleted', '=', '0')
        ->orderBy('tbl_contact.id', 'desc')
        ->get();
        $ActiveContact = Contact::select('tbl_contact.*', 'tbl_customer.CustomerName as CustomerName', 'tbl_customer.CustomerCode as CustomerCode', 'tbl_customer.CustomerId as CustomerId', 'tbl_countries.country_name as Country', 'tbl_admin.FirstName as Updated_by', 'tbl_admin.FirstName as Created_by')
        ->leftJoin('tbl_admin', 'tbl_contact.Updated_by', '=', 'tbl_admin.UserId')
        ->leftJoin('tbl_customer', 'tbl_contact.CustomerId', '=', 'tbl_customer.CustomerId')
        ->leftJoin('tbl_countries', 'tbl_contact.Country', '=', 'tbl_countries.id')
        ->where('tbl_contact.IsDeleted', '=', '0')
        ->where('tbl_contact.Status', '=', '1')
        ->orderBy('tbl_contact.id', 'desc')
        ->get();
        $InActiveContact = Contact::select('tbl_contact.*', 'tbl_customer.CustomerName as CustomerName', 'tbl_customer.CustomerCode as CustomerCode', 'tbl_customer.CustomerId as CustomerId', 'tbl_countries.country_name as Country', 'tbl_admin.FirstName as Updated_by', 'tbl_admin.FirstName as Created_by')
        ->leftJoin('tbl_admin', 'tbl_contact.Updated_by', '=', 'tbl_admin.UserId')
        ->leftJoin('tbl_customer', 'tbl_contact.CustomerId', '=', 'tbl_customer.CustomerId')
        ->leftJoin('tbl_countries', 'tbl_contact.Country', '=', 'tbl_countries.id')
        ->where('tbl_contact.IsDeleted', '=', '0')
        ->where('tbl_contact.Status', '=', '0')
        ->orderBy('tbl_contact.id', 'desc')
        ->get();
        $TrashContact = Contact::select('tbl_contact.*', 'tbl_customer.CustomerName as CustomerName', 'tbl_customer.CustomerCode as CustomerCode', 'tbl_countries.country_name as Country', 'tbl_admin.FirstName as Updated_by', 'tbl_admin.FirstName as Created_by')
        ->leftJoin('tbl_admin', 'tbl_contact.Updated_by', '=', 'tbl_admin.UserId')
        ->leftJoin('tbl_customer', 'tbl_contact.CustomerId', '=', 'tbl_customer.CustomerId')
        ->leftJoin('tbl_countries', 'tbl_contact.Country', '=', 'tbl_countries.id')
        ->where('tbl_contact.IsDeleted', '=', '1')
        ->orderBy('tbl_contact.id', 'desc')
        ->get();
        return view('admin.inactive-contact', ['Contact' => $Contact, 'ActiveContact' => $ActiveContact, 'InActiveContact' => $InActiveContact, 'TrashContact' => $TrashContact]);
    }

    #Trash Contacts
    public function trashContact(){
        if (empty(session('UserId'))) {
            return redirect('/admin/logout');
        }
        $Contact = Contact::select('tbl_contact.*', 'tbl_customer.CustomerName as CustomerName', 'tbl_customer.CustomerCode as CustomerCode', 'tbl_customer.CustomerId as CustomerId', 'tbl_countries.country_name as Country', 'tbl_admin.FirstName as Updated_by', 'tbl_admin.FirstName as Created_by')
        ->leftJoin('tbl_admin', 'tbl_contact.Updated_by', '=', 'tbl_admin.UserId')
        ->leftJoin('tbl_customer', 'tbl_contact.CustomerId', '=', 'tbl_customer.CustomerId')
        ->leftJoin('tbl_countries', 'tbl_contact.Country', '=', 'tbl_countries.id')
        ->where('tbl_contact.IsDeleted', '=', '0')
        ->orderBy('tbl_contact.id', 'desc')
        ->get();
        $ActiveContact = Contact::select('tbl_contact.*', 'tbl_customer.CustomerName as CustomerName', 'tbl_customer.CustomerCode as CustomerCode', 'tbl_customer.CustomerId as CustomerId', 'tbl_countries.country_name as Country', 'tbl_admin.FirstName as Updated_by', 'tbl_admin.FirstName as Created_by')
        ->leftJoin('tbl_admin', 'tbl_contact.Updated_by', '=', 'tbl_admin.UserId')
        ->leftJoin('tbl_customer', 'tbl_contact.CustomerId', '=', 'tbl_customer.CustomerId')
        ->leftJoin('tbl_countries', 'tbl_contact.Country', '=', 'tbl_countries.id')
        ->where('tbl_contact.IsDeleted', '=', '0')
        ->where('tbl_contact.Status', '=', '1')
        ->orderBy('tbl_contact.id', 'desc')
        ->get();
        $InActiveContact = Contact::select('tbl_contact.*', 'tbl_customer.CustomerName as CustomerName', 'tbl_customer.CustomerCode as CustomerCode', 'tbl_customer.CustomerId as CustomerId', 'tbl_countries.country_name as Country', 'tbl_admin.FirstName as Updated_by', 'tbl_admin.FirstName as Created_by')
        ->leftJoin('tbl_admin', 'tbl_contact.Updated_by', '=', 'tbl_admin.UserId')
        ->leftJoin('tbl_customer', 'tbl_contact.CustomerId', '=', 'tbl_customer.CustomerId')
        ->leftJoin('tbl_countries', 'tbl_contact.Country', '=', 'tbl_countries.id')
        ->where('tbl_contact.IsDeleted', '=', '0')
        ->where('tbl_contact.Status', '=', '0')
        ->orderBy('tbl_contact.id', 'desc')
        ->get();
        $TrashContact = Contact::select('tbl_contact.*', 'tbl_customer.CustomerName as CustomerName', 'tbl_customer.CustomerCode as CustomerCode', 'tbl_countries.country_name as Country', 'tbl_admin.FirstName as Updated_by', 'tbl_admin.FirstName as Created_by')
        ->leftJoin('tbl_admin', 'tbl_contact.Updated_by', '=', 'tbl_admin.UserId')
        ->leftJoin('tbl_customer', 'tbl_contact.CustomerId', '=', 'tbl_customer.CustomerId')
        ->leftJoin('tbl_countries', 'tbl_contact.Country', '=', 'tbl_countries.id')
        ->where('tbl_contact.IsDeleted', '=', '1')
        ->orderBy('tbl_contact.id', 'desc')
        ->get();
        return view ('admin.trash-contact', ['Contact' => $Contact, 'ActiveContact' => $ActiveContact, 'InActiveContact' => $InActiveContact, 'TrashContact' => $TrashContact]);
    }

    ### View Record
    public function viewContact($ContactId)
    {
        if (empty(session('UserId'))) {
            return redirect('/admin/logout');
        }
        $ViewContact = Contact::select('tbl_contact.*', 'tbl_customer.CustomerName as CustomerName', 'tbl_customer.CustomerCode as CustomerCode', 'tbl_customer.CustomerId as CustomerId', 'tbl_countries.country_name as Country', 'tbl_admin.FirstName as Updated_by', 'tbl_admin.FirstName as Created_by')->where('ContactId', '=', $ContactId)
        ->leftJoin('tbl_admin', 'tbl_contact.Updated_by', '=', 'tbl_admin.UserId')
        ->leftJoin('tbl_customer', 'tbl_contact.CustomerId', '=', 'tbl_customer.CustomerId')
        ->leftJoin('tbl_countries', 'tbl_contact.Country', '=', 'tbl_countries.id')
        ->get()->first();
        return view('admin.view-contact', ['Contact' => $ViewContact]);
    }


    ### Check Contact Mobile Number
    public function checkContactMobile(Request $request)
    {
        $CreatedDate = date('Y-m-d H:i:s',time());
         
        $data = $request->all(); 

        $contact = Contact::where('Mobile', $data['Mobile'])->get();               
        if ($contact->count() > 0)
        {   //mobile exist
            $contact = $contact->first();   
            $ContactId = $contact->ContactId;  
        
            $response = [
                'Success' => false,
                'ResponseMessage' => "Number already exist in CRM!",
                'ResponseCode' => '201',                
            ];
            return response()->json($response);
        }  
        else{
            $response = [
                'Success' => true,
                'ResponseMessage' => "",
                'ResponseCode' => '200',                
            ];
            return response()->json($response);
        }       
    }

    ### Store New Record
    public function storeContact(Request $request)
    {
        if (empty(session('UserId'))) {
            return redirect('/admin/logout');
        }
        $Contact = new Contact;
        $Contact->ContactId = $this->userLib->useridGenrator();
        $Contact->Title = $request->input('Title');
        $Contact->FirstName = $request->input('firstName');
        $Contact->LastName = $request->input('lastName');
        $Contact->Mobile = $request->input('mobile');
        $Contact->AlternateMobile = $request->input('alternateMobile');
        $Contact->Email = $request->input('email');
        $Contact->AlternateEmail = $request->input('alternateEmail');

        if ($request->input('dateOfBirth')) {
            $BirthDate = str_replace('/', '-', $request->input('dateOfBirth'));
        }
        $Contact->DateOfBirth = date('d-m-Y', strtotime($BirthDate));
        //$Contact->DateOfBirth = $request->input('dateOfBirth');

        if ($request->input('weddingAnniversary')) {
            $WeddingDate = str_replace('/', '-', $request->input('weddingAnniversary'));
        }
        $Contact->WeddingAnniversary = date('d-m-Y', strtotime($WeddingDate));
        //$Contact->WeddingAnniversary = $request->input('weddingAnniversary');

        $Contact->CustomerId = $request->input('customer');
        $Contact->StreetAddress = $request->input('streetAddress');
        $Contact->City = $request->input('city');
        $Contact->Country = $request->input('country');
        $Contact->State = $request->input('state');
        $Contact->PostalCode = $request->input('postalCode');
        $Contact->Description = $request->input('description');
        $Contact->CrmId = '';
        $Contact->Created_by = session('UserId');
        $Contact->Updated_by = session('UserId');
        $Contact->IsDeleted = '0';
        $Contact->DeviceName = 'WEB';

        if ($request->has('IsPrimary')) {
            $Contact->IsPrimary = '1';
        } else {
            $Contact->IsPrimary = '0';
        }

        if ($request->has('Status')) {
            $Contact->Status = '0';
        } else {
            $Contact->Status = '1';
        }

        $Contact->save();
        //return redirect()->back()->with('status_success');
        return response()->json('status_success');
    }

    #### Change Status
    public function statusUpdateContact($id)
    {
        $data = Contact::find($id);
        if ($data->Status == '1') {
            $Status = '0';
        } else {
            $Status = '1';
        }

        $values = array('Status' => $Status);
        Contact::find($id)->update($values);
        return redirect()->back();
    }


    #### Delete Temporary
    public function deleteContact($id)
    {
        $value = array('IsDeleted' => '1', 'Status' => '0');
        Contact::find($id)->update($value);
    }
	#### Delete Selected Contact
    public function deleteSelectedContact(Request $request)
    {
        if (empty(session('UserId'))) {
            return redirect('/admin/logout');
        }

        $id = $request->input('SelectedContact');
        if ($id) {
            foreach ($id as $contact) {
                $checkData = Contact::find($contact);
                if ($checkData->IsDeleted == '0') {
                    $CreatedDate = date(
                        'Y-m-d H:i:s',
                        time()
                    );
                    $data = array();
                    $data['Updated_at'] = $CreatedDate;
                    $data['IsDeleted'] = '1';
    
                    $selected_contact = Contact::where('id', $contact)->update($data);
                    if ($selected_contact) {
                        echo '1';
                    } else {
                        echo '0';
                    }
                } else {
                    $selected_contact = Contact::find($contact);
                    $selected_contact->delete();
                }
            }
        }

        return redirect()->back()->with('status_success');
    }

    #### Empty trash contact folder 
    // public function emptyTrashContact(Request $request)
    // {
    //     if (empty(session('UserId'))) {
    //         return redirect('/admin/logout');
    //     }

    //     $id = $request->input('SelectedContact');
    //     foreach ($id as $contact) {
    //         $checkData = Contact::find($contact);
    //         if ($checkData->IsDeleted == '1') {
                
    //             $selected_contact = Contact::find($contact);
    //             $selected_contact->delete();
    //             if ($selected_contact) {
    //                 echo '1';
    //             } else {
    //                 echo '0';
    //             }
    //         }
    //     }

    //     return redirect()->back()->with('status_success');
    // }

    #### Restore
    public function restoreContact($id)
    {
        $value = array('IsDeleted' => '0');
        Contact::find($id)->update($value);
    }

    #### Delete Permanent
    public function destroyContact($id)
    {
        $destroyData = Contact::find($id);
        $destroyData->delete();
    }

    ### Edit Records
    public function editContact($id)
    {
        $Contact = Contact::find($id);
        return response()->json([
            'status' => 200,
            'Contact' => $Contact,
        ]);
    }

    ### Update Records
    public function updateContact(Request $request)
    {
        if (empty(session('UserId'))) {
            return redirect('/admin/logout');
        }
        //$user_id = Auth::id();
        $contact_id =  $request->input('id');
        $Contact = Contact::find($contact_id);
        $Contact->Title = $request->input('Title');
        $Contact->FirstName = $request->input('firstName');
        $Contact->LastName = $request->input('lastName');
        $Contact->Mobile = $request->input('mobile');
        $Contact->AlternateMobile = $request->input('alternateMobile');
        $Contact->Email = $request->input('email');
        $Contact->AlternateEmail = $request->input('alternateEmail');

        if ($request->input('dateOfBirth')) {
            $BirthDate = str_replace('/', '-', $request->input('dateOfBirth'));
        }
        $Contact->DateOfBirth = date('d-m-Y', strtotime($BirthDate));
        //$Contact->DateOfBirth = $request->input('dateOfBirth');

        if ($request->input('weddingAnniversary')) {
            $WeddingDate = str_replace('/', '-', $request->input('weddingAnniversary'));
        }
        $Contact->WeddingAnniversary = date('d-m-Y', strtotime($WeddingDate));
        //$Contact->WeddingAnniversary = $request->input('weddingAnniversary');
        
        $Contact->CustomerId = $request->input('customer');
        $Contact->StreetAddress = $request->input('streetAddress');
        $Contact->City = $request->input('city');
        $Contact->Country = $request->input('country');
        $Contact->State = $request->input('state');
        $Contact->PostalCode = $request->input('postalCode');
        $Contact->Description = $request->input('description');
        $Contact->CrmId = '';
        $Contact->Updated_by = session('UserId');
        $Contact->DeviceName = '';

        if ($request->has('editIsPrimary')) {
            $Contact->IsPrimary = '1';
        } else {
            $Contact->IsPrimary = '0';
        }

        $Contact->update();
        return redirect()->back()->with('status_success');
    }

    ### Check Primary Records
    public function checkContactPrimary($CustomerId)
    {
        $Contact = Contact::select('tbl_contact.*')
        ->where('CustomerId', '=', $CustomerId)
        ->where('IsPrimary', '=', '1')
        //->where('Status', '=', '1')
       //->where('IsDeleted', '=', '0')
        ->get()->first();
        return response()->json([
            'status' => 200,
            'Contact' => $Contact,
        ]);
    }
}