diff --git a/app/Console/Commands/Connectors/Notifications/MailCaddieLabCommand.php b/app/Console/Commands/Connectors/Notifications/MailCaddieLabCommand.php new file mode 100644 index 000000000..b43a30310 --- /dev/null +++ b/app/Console/Commands/Connectors/Notifications/MailCaddieLabCommand.php @@ -0,0 +1,18 @@ +info('Sending internal mail to Caddie Lab'); + MailCaddieLabJob::dispatch(AppsRepository::findFirstByKey($this->argument('apps_id'))); + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 867ebff35..b8e80aedb 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -13,8 +13,6 @@ class Kernel extends ConsoleKernel /** * Define the application's command schedule. * - * @param \Illuminate\Console\Scheduling\Schedule $schedule - * * @return void */ protected function schedule(Schedule $schedule) @@ -22,6 +20,9 @@ protected function schedule(Schedule $schedule) $schedule->command(RunHealthChecksCommand::class)->everyMinute(); $schedule->command(DispatchQueueCheckJobsCommand::class)->everyMinute(); $schedule->command(ScheduleCheckHeartbeatCommand::class)->everyMinute(); + /* $schedule->command(MailCaddieLabCommand::class, [getenv('CADDIE_APP_KEY')]) + ->dailyAt('13:00') + ->timezone('America/Santo_Domingo') ; */ } /** diff --git a/composer.lock b/composer.lock index 5110ef914..5eec2d4b5 100644 --- a/composer.lock +++ b/composer.lock @@ -1195,16 +1195,16 @@ }, { "name": "aws/aws-sdk-php", - "version": "3.308.1", + "version": "3.308.4", "source": { "type": "git", "url": "https://github.com/aws/aws-sdk-php.git", - "reference": "bf5f1221d4c5c67d3213150fb91dfb5ce627227b" + "reference": "c88e9df7e076b6e2c652a1c87d2c3af0a9ac30b6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/bf5f1221d4c5c67d3213150fb91dfb5ce627227b", - "reference": "bf5f1221d4c5c67d3213150fb91dfb5ce627227b", + "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/c88e9df7e076b6e2c652a1c87d2c3af0a9ac30b6", + "reference": "c88e9df7e076b6e2c652a1c87d2c3af0a9ac30b6", "shasum": "" }, "require": { @@ -1284,9 +1284,9 @@ "support": { "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80", "issues": "https://github.com/aws/aws-sdk-php/issues", - "source": "https://github.com/aws/aws-sdk-php/tree/3.308.1" + "source": "https://github.com/aws/aws-sdk-php/tree/3.308.4" }, - "time": "2024-05-22T18:05:56+00:00" + "time": "2024-05-28T18:05:38+00:00" }, { "name": "berkayk/onesignal-laravel", @@ -2928,16 +2928,16 @@ }, { "name": "google/protobuf", - "version": "v4.26.1", + "version": "v4.27.0", "source": { "type": "git", "url": "https://github.com/protocolbuffers/protobuf-php.git", - "reference": "5c46b0eb09e7ad3e6efef3c5a85e2a34108c52ae" + "reference": "28cf84ac822e2c8f82edd7c84cc792cacb822faa" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/protocolbuffers/protobuf-php/zipball/5c46b0eb09e7ad3e6efef3c5a85e2a34108c52ae", - "reference": "5c46b0eb09e7ad3e6efef3c5a85e2a34108c52ae", + "url": "https://api.github.com/repos/protocolbuffers/protobuf-php/zipball/28cf84ac822e2c8f82edd7c84cc792cacb822faa", + "reference": "28cf84ac822e2c8f82edd7c84cc792cacb822faa", "shasum": "" }, "require": { @@ -2966,9 +2966,9 @@ "proto" ], "support": { - "source": "https://github.com/protocolbuffers/protobuf-php/tree/v4.26.1" + "source": "https://github.com/protocolbuffers/protobuf-php/tree/v4.27.0" }, - "time": "2024-03-27T19:56:50+00:00" + "time": "2024-05-22T21:40:13+00:00" }, { "name": "graham-campbell/result-type", @@ -5085,16 +5085,16 @@ }, { "name": "league/flysystem-google-cloud-storage", - "version": "3.25.1", + "version": "3.28.0", "source": { "type": "git", "url": "https://github.com/thephpleague/flysystem-google-cloud-storage.git", - "reference": "4b201fb9abc1a8162f227c28855035117a29ae65" + "reference": "072b92961e6d14272de4b857546fe824e689775b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/flysystem-google-cloud-storage/zipball/4b201fb9abc1a8162f227c28855035117a29ae65", - "reference": "4b201fb9abc1a8162f227c28855035117a29ae65", + "url": "https://api.github.com/repos/thephpleague/flysystem-google-cloud-storage/zipball/072b92961e6d14272de4b857546fe824e689775b", + "reference": "072b92961e6d14272de4b857546fe824e689775b", "shasum": "" }, "require": { @@ -5127,19 +5127,9 @@ "google cloud storage" ], "support": { - "source": "https://github.com/thephpleague/flysystem-google-cloud-storage/tree/3.25.1" + "source": "https://github.com/thephpleague/flysystem-google-cloud-storage/tree/3.28.0" }, - "funding": [ - { - "url": "https://ecologi.com/frankdejonge", - "type": "custom" - }, - { - "url": "https://github.com/frankdejonge", - "type": "github" - } - ], - "time": "2024-03-15T19:58:44+00:00" + "time": "2024-05-06T20:05:52+00:00" }, { "name": "league/flysystem-local", diff --git a/database/migrations/Guild/2024_05_28_030618_apps_id_people.php b/database/migrations/Guild/2024_05_28_030618_apps_id_people.php new file mode 100644 index 000000000..b7b455cbc --- /dev/null +++ b/database/migrations/Guild/2024_05_28_030618_apps_id_people.php @@ -0,0 +1,29 @@ +bigInteger('apps_id')->unsigned()->nullable()->after('companies_id'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('peoples', function (Blueprint $table) { + // + $table->dropColumn('apps_id'); + }); + } +}; diff --git a/routes/console.php b/routes/console.php index e05f4c9a1..194ca9336 100644 --- a/routes/console.php +++ b/routes/console.php @@ -2,6 +2,10 @@ use Illuminate\Foundation\Inspiring; use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Schedule; +use Illuminate\Support\Facades\Schema; +use Kanvas\Apps\Repositories\AppsRepository; +use Kanvas\Connectors\Jobs\MailCaddieLabJob; /* |-------------------------------------------------------------------------- diff --git a/src/Domains/Connectors/Notifications/Jobs/MailCaddieLabJob.php b/src/Domains/Connectors/Notifications/Jobs/MailCaddieLabJob.php new file mode 100644 index 000000000..72f7a8d00 --- /dev/null +++ b/src/Domains/Connectors/Notifications/Jobs/MailCaddieLabJob.php @@ -0,0 +1,59 @@ +app); + $this->sendMails($peoples, 'join-caddie'); + + $peoples = PeoplesRepository::getByDaysCreated(28, $this->app); + $this->sendMails($peoples, 'join-caddie'); + } + + public function sendMails(Collection $peoples, string $template) + { + foreach ($peoples as $people) { + $email = $people->emails()->first(); + $url = $this->app->get('billing_url') . '/' . '?email=' . $email->value . '&paid=false'; + $notification = new Blank( + $template, + ['membershipUpgradeUrl' => $url, 'app' => $this->app], + ['mail'], + $people + ); + $notification->setSubject('Join to Caddie Lab'); + echo ' Sending email to ' . $email->value . "\n"; + if (! $people->get('paid_subscription')) { + Notification::route('mail', $email->value)->notify($notification); + } + } + } +} diff --git a/src/Domains/Guild/Customers/Actions/CreatePeopleAction.php b/src/Domains/Guild/Customers/Actions/CreatePeopleAction.php index 67dfea488..4113c4f71 100644 --- a/src/Domains/Guild/Customers/Actions/CreatePeopleAction.php +++ b/src/Domains/Guild/Customers/Actions/CreatePeopleAction.php @@ -28,6 +28,7 @@ public function execute(): People $company = $this->peopleData->branch->company()->firstOrFail(); $attributes = [ + 'apps_id' => $this->peopleData->app->getId(), 'users_id' => $this->peopleData->user->getId(), 'firstname' => $this->peopleData->firstname, 'middlename' => $this->peopleData->middlename, diff --git a/src/Domains/Guild/Customers/Repositories/PeoplesRepository.php b/src/Domains/Guild/Customers/Repositories/PeoplesRepository.php index 427877f66..0ed4f3e61 100644 --- a/src/Domains/Guild/Customers/Repositories/PeoplesRepository.php +++ b/src/Domains/Guild/Customers/Repositories/PeoplesRepository.php @@ -7,8 +7,10 @@ use Baka\Contracts\CompanyInterface; use Baka\Traits\SearchableTrait; use Baka\Users\Contracts\UserInterface; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\ModelNotFoundException; +use Kanvas\Apps\Models\Apps; use Kanvas\Exceptions\ModelNotFoundException as ExceptionsModelNotFoundException; use Kanvas\Guild\Customers\Enums\ContactTypeEnum; use Kanvas\Guild\Customers\Models\Contact; @@ -51,6 +53,13 @@ public static function getByEmail(string $email, CompanyInterface $company): ?Pe ->first(); } + public static function getByDaysCreated(int $days, Apps $app): Collection + { + return People::whereRaw('DATEDIFF(NOW(), created_at) = ?', [$days]) + ->where('apps_id', $app->getId()) + ->get(); + } + public static function findByEmailOrCreate(string $email, UserInterface $user, CompanyInterface $company, ?string $name): People { $people = self::getByEmail($email, $company); diff --git a/src/Kanvas/Users/Repositories/UsersRepository.php b/src/Kanvas/Users/Repositories/UsersRepository.php index 881b8faba..6ab7bc237 100644 --- a/src/Kanvas/Users/Repositories/UsersRepository.php +++ b/src/Kanvas/Users/Repositories/UsersRepository.php @@ -9,6 +9,7 @@ use Baka\Users\Contracts\UserInterface; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\ModelNotFoundException; +use Illuminate\Support\Facades\DB; use Kanvas\Apps\Models\Apps; use Kanvas\Companies\Models\Companies; use Kanvas\Companies\Models\CompaniesBranches; @@ -94,6 +95,17 @@ public static function getUserOfAppById(int $id, ?AppInterface $app = null): Use ->firstOrFail(); } + public static function getUsersByDaysCreated(int $days, ?AppInterface $app = null): Collection + { + $app = $app ?? app(Apps::class); + + return Users::join('users_associated_apps', 'users_associated_apps.users_id', '=', 'users.id') + ->whereRaw('DATEDIFF(CURDATE(), users_associated_apps.created_at) = ?', [$days]) + ->select('users.*') + ->groupBy('users.id') + ->get(); + } + /** * getAll. * @psalm-suppress MixedReturnStatement @@ -104,6 +116,7 @@ public static function getAll(int $companiesId): Collection ->join('users_associated_company', 'users_associated_company.users_id', 'users.id') ->where('users_associated_company.companies_id', $companiesId) ->whereNot('users.id', auth()->user()->id) + ->select('users.*') ->get(); }