MAIL_BCC_ALL=test+toolboxalpha@cubedesigners.com
MAIL_TEAM_NAME=Fluidbook
+MAILJET_API_KEY=ca110b35f8735c223d69c9987c2ac47d
+MAILJET_API_SECRET=b289d0acb08e0fe56ce98ccf0dd1ed8b
+
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
MAIL_BCC_ALL=test+toolboxdev@cubedesigners.com
MAIL_TEAM_NAME=Fluidbook
+MAILJET_API_KEY=ca110b35f8735c223d69c9987c2ac47d
+MAILJET_API_SECRET=b289d0acb08e0fe56ce98ccf0dd1ed8b
+
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
MAIL_BCC_ALL=test+toolbox@cubedesigners.com
MAIL_TEAM_NAME=Fluidbook
+MAILJET_API_KEY=ca110b35f8735c223d69c9987c2ac47d
+MAILJET_API_SECRET=b289d0acb08e0fe56ce98ccf0dd1ed8b
+
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
--- /dev/null
+<?php
+
+namespace App\Jobs;
+
+use App\Models\Company;
+use App\Models\User;
+use Cubedesigners\UserDatabase\Permissions;
+use DateTimeInterface;
+use Egulias\EmailValidator\EmailValidator;
+use Egulias\EmailValidator\Validation\DNSCheckValidation;
+use Egulias\EmailValidator\Validation\MultipleValidationWithAnd;
+use Egulias\EmailValidator\Validation\RFCValidation;
+use Illuminate\Support\Facades\Cache;
+use Mailjet\Client;
+use Mailjet\Resources;
+
+class MailjetSyncList extends Base
+{
+ const LIST_ID = '10296433';
+
+ /**
+ * @throws \Exception
+ */
+ public function handle()
+ {
+
+
+ $skippedCompanies = [];
+ $companies = [];
+ $contacts = ['addnoforce' => [], 'unsub' => [], 'remove' => []];
+
+ $validator = new EmailValidator();
+ $multipleValidations = new MultipleValidationWithAnd([
+ new RFCValidation(),
+ new DNSCheckValidation()
+ ]);
+
+ foreach (Company::withoutGlobalScopes()->get() as $company) {
+ if (!$company->created_ok) {
+ $skippedCompanies[] = $company->id;
+ continue;
+ }
+ /** @var Company $company */
+ $adminCompany = Permissions::getCompanyByUser($company->admin);
+ // Skip companies not directly managed by Cubedesigners
+ if ($adminCompany != 7) {
+ $skippedCompanies[] = $company->id;
+ continue;
+ }
+ $companies[$company->id] = $company;
+ }
+
+ foreach (User::withoutGlobalScopes()->where('created_ok', '1')->where('enabled', '1')->get() as $user) {
+ if (in_array($user->company, $skippedCompanies) || !isset($companies[$user->company])) {
+ continue;
+ }
+
+ $c = $companies[$user->company];
+ $address = $user->address;
+ if (is_string($address)) {
+ $address = json_decode($address);
+ }
+ if (null === $address) {
+ $country = '';
+ } else {
+ $country = is_array($address) ? $address['country'] : $address->country;
+ }
+
+ $action = 'addnoforce';
+
+ if (str_ends_with($user->email, '@extranet.cubedesigners.com')) {
+ $action = 'remove';
+ }
+
+ if (!Cache::rememberForever('email_valid_' . $user->email, function () use ($user, $validator, $multipleValidations) {
+ return $validator->isValid($user->email, $multipleValidations);
+ })) {
+ continue;
+ }
+
+ if (!$user->marketing) {
+ $action = 'unsub';
+ }
+
+ $contact = [
+ 'Email' => $user->email,
+ 'IsExcludedFromCampaigns' => 'false',
+ 'Name' => trim($user->firstname . ' ' . $user->lastname),
+ 'Properties' => [
+ 'toolbox_id' => $user->id,
+ 'firstname' => trim($user->firstname),
+ 'lastname' => trim($user->lastname),
+ 'company' => trim($c->name),
+ 'fluidbook' => $c->e1_ws_grade > 0 && $c->toolbox_access,
+ 'elearning' => (bool)$c->permissions_elearning,
+ 'locale' => $user->locale,
+ 'country' => $country,
+ 'last_project' => $c->c_last_project_date ? (new \DateTime($c->c_last_project_date))->format(DateTimeInterface::RFC3339) : '',
+ ]
+ ];
+
+ $contacts[$action][] = $contact;
+ }
+
+
+ foreach ($contacts as $action => $list) {
+ $this->addContactsToList($list, $action);
+ }
+ }
+
+ protected function addContactsToList($contacts, $action = 'addnoforce')
+ {
+ if (empty($contacts)) {
+ return;
+ }
+ $mj = static::_api();
+ $body = [
+ 'Action' => $action,
+ 'Contacts' => $contacts
+ ];
+ $response = $mj->post(Resources::$ContactslistManagemanycontacts, ['id' => self::LIST_ID, 'body' => $body]);
+ $jobId = $response->getData()[0]['JobID'];
+
+ while (true) {
+ $check = $mj->get(Resources::$ContactslistManagemanycontacts, ['id' => self::LIST_ID, 'actionid' => (string)$jobId]);
+ $status = ($check->getData()[0]['Status']);
+ if ($status === 'Error') {
+ dd($check->getData()[0]);
+ } else if ($status === 'Completed') {
+ return;
+ }
+ dump($status);
+ sleep(2);
+ }
+ }
+
+ /**
+ * @return Client
+ */
+ protected static function _api($call = true, $version = 'v3')
+ {
+ return new \Mailjet\Client(env('MAILJET_API_KEY'), env('MAILJET_API_SECRET'), $call, ['version' => $version]);
+ }
+}
use App\Models\Company;
use App\Models\FluidbookQuote;
use App\Models\User;
+use Cubedesigners\UserDatabase\Permissions;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
protected $companyYears = [];
protected $unpaidYears = [];
protected $unpaid = [];
+
+ protected $lastProject = [];
protected static $_wstable = 'extranet_clean';
public function handle()
{
$this->processInvoices();
- //$this->processProjects();
$this->processCompanies();
$this->processFluidbookCounts();
Artisan::command('ws:precache', function () {
protected function processInvoices()
{
foreach (DB::table(self::$_wstable . '.factures')->whereIn('status', [1, 2])->get() as $e) {
-
$this->invoices[$e->facture_id] =
['status' => $e->status, 'amount' => $e->total_ht, 'project' => $e->projet, 'year' => date('Y', $e->date_creation), 'paid' => $e->status == 2];
if (!isset($this->invoicesByProject[$e->projet])) {
}
}
-// protected function processProjects()
-// {
-// foreach (DB::table(self::$_wstable . '.taches')->get() as $e) {
-// if (!isset($this->projects[$e->projet])) {
-// $this->projects[$e->projet] = 0;
-// }
-// $this->projects[$e->projet] += $e->budget;
-// }
-//
-// }
protected function processCompanies()
{
}
foreach (DB::table(self::$_wstable . '.projets')->get() as $e) {
+
if (!isset($this->companyOfUser[$e->client])) {
continue;
}
if (!isset($this->invoicesByProject[$e->projet_id])) {
continue;
}
+
+ $company = $this->companyOfUser[$e->client];
+ if (!isset($this->companies[$company])) {
+ $this->companies[$company] = 0;
+ $this->unpaid[$company] = 0;
+ $this->lastProject[$company] = 0;
+ }
+
+ $this->lastProject[$company] = max($this->lastProject[$company], $e->date_creation, $e->date_debut, $e->date_fin);
+
foreach ($this->invoicesByProject[$e->projet_id] as $invoice_id) {
$invoice = $this->invoices[$invoice_id];
- $company = $this->companyOfUser[$e->client];
- if (!isset($this->companies[$company])) {
- $this->companies[$company] = 0;
- $this->unpaid[$company] = 0;
- }
if (!isset($this->companyYears[$company])) {
$this->companyYears[$company] = [];
$this->unpaidYears[$company] = [];
if (null === $c) {
continue;
}
+ $d = new \DateTime();
+ $d->setTimestamp($this->lastProject[$company]);
$c->c_ca = $ca;
+ $c->c_last_project_date = $d;
foreach ($this->companyYears[$company] as $y => $yca) {
$c->{'c_ca_' . $y} = $yca;
}
'URL' => $this->request->url(),
];
}
+
/** @var User $user */
$user = backpack_user();
if ($user) {
];
}
+
return $record;
}
}
"cubist/matomo": "dev-master",
"cubist/pdf": "dev-master",
"cubist/scorm": "dev-master",
+ "egulias/email-validator": "^4.0",
"fluidbook/tools": "dev-master",
"hollodotme/fast-cgi-client": "^3.1.7",
"jolicode/slack-php-api": "^v4.6.0",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "e4b75781593f63e2769630b55d6cfd1f",
+ "content-hash": "a2c4e7e7e43bf89fa3a5c783830cb261",
"packages": [
{
"name": "archtechx/enums",