public function syncContacts() { // Title $title = 'Moneybird Contact Sync'; $mContacts = $this->getContacts(); foreach ($mContacts as $mContact) { $contact = Company::whereHas('meta', function ($query) use($mContact) { $query->where('type', 'moneybird')->where('subtype', 'contact')->where('key', 'id')->where('value', $mContact->id); })->first(); if (!$contact) { $contact = new Company(); } $contact->fill(['bedrijfsnaam' => $mContact->companyName, 'voornaam' => $mContact->firstname, 'achternaam' => $mContact->lastname, 'ter_attentie_van' => $mContact->contactName, 'adres_1' => $mContact->address1, 'adres_2' => $mContact->address2, 'postcode' => $mContact->zipcode, 'plaats' => $mContact->city, 'land' => $mContact->country, 'email' => $mContact->email, 'telefoon' => $mContact->phone, 'btw_nummer' => $mContact->taxNumber, 'kvk_nummer' => $mContact->chamberOfCommerce, 'rekening_nummer' => $mContact->sepaIban]); $contact->save(); $customerId = CompanyMeta::firstOrNew(['company_id' => $contact->id, 'type' => 'moneybird', 'subtype' => 'contact', 'key' => 'customerid']); $customerId->value = $mContact->customerId; $customerId->save(); $id = CompanyMeta::firstOrNew(['company_id' => $contact->id, 'type' => 'moneybird', 'subtype' => 'contact', 'key' => 'id']); $id->value = $mContact->id; $id->save(); $contact->meta()->saveMany([$customerId, $id]); } Session::flash('success', 'Contacts succesfully synced'); return View::make('admin/integrations/moneybird/index', compact('title', 'body')); }
/** * [postRenewalSubscriptionData] * @return [json] [DT compatible object] */ public function postNieuwsbrievenSubscriptionData() { $posted_values = $_POST['data']['subscriptions']; $posted_p = var_export($_POST, true); error_log($posted_p); //error_log($posted_ndx); $curr_company = Company::find((int) $posted_values["company_id"]); $subscription = Subscription::find((int) $posted_values["id"]); $curr_aws_account = $posted_values["aws_auth"]; if ($curr_company && $subscription) { $aws_auth = CompanyMeta::firstOrNew(['company_id' => $curr_company->id, 'type' => 'aws', 'subtype' => 'auth', 'key' => 'account']); $aws_auth->value = $curr_aws_account; $aws_auth->save(); // load relations $load_curr_company = $subscription->company; $load_curr_service = $subscription->service; $load_curr_category = $subscription->service->category; $load_curr_status = $subscription->status; $load_curr_period = $subscription->period; $curr_company = $subscription->company !== NULL ? (object) ['id' => $subscription->company_id, 'bedrijfsnaam' => utf8_encode($subscription->company->bedrijfsnaam)] : (object) null; $curr_service = $subscription->service !== NULL ? (object) ['id' => $subscription->service_id, 'category_id' => $subscription->category_id, 'name' => utf8_encode($subscription->service->name)] : (object) null; $curr_category = $subscription->service->category !== NULL ? (object) ['id' => $subscription->service->category_id, 'name' => utf8_encode($subscription->service->category->name)] : (object) null; $curr_status = $subscription->status !== NULL ? (object) ['id' => $subscription->status_id, 'description' => utf8_encode($subscription->status->description)] : (object) null; $curr_period = $subscription->period !== NULL ? (object) ['id' => $subscription->invoice_periods_id, 'description' => utf8_encode($subscription->period->description)] : (object) null; $data = (object) ['DT_RowId' => 'row_' . $subscription->id, 'subscriptions' => $subscription, 'companies' => $curr_company, 'service_categories' => $curr_category, 'services' => $curr_service, 'statuses' => $curr_status, 'invoice_periods' => $curr_period]; $ret = ['row' => $data, 'companies' => $this->getAllCompanies(), 'services' => $this->getAllServices(), 'service_categories' => $this->getAllServiceCategories(), 'statuses' => $this->getAllStatuses(), 'invoice_periods' => $this->getAllInvoicePeriods()]; return Response::json($ret); } return Response::json((object) null); }