Skip to content

Commit

Permalink
Merge pull request #350 from jesusantguerrero/master
Browse files Browse the repository at this point in the history
Merge master into v1.1.0
  • Loading branch information
jesusantguerrero authored Feb 17, 2024
2 parents f21d7d0 + 20e4d41 commit 47c0748
Show file tree
Hide file tree
Showing 160 changed files with 11,585 additions and 24,230 deletions.
13 changes: 3 additions & 10 deletions .do/deploy.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ spec:
services:
- name: web
git:
branch: staging
branch: master
repo_clone_url: https://github.com/jesusantguerrero/atmosphere.git
build_command: npm run build
run_command: php artisan migrate --force ; php artisan db:seed ; php artisan journal:set-accounts ; heroku-php-apache2 public/
build_command: npm run build:digitalocean; composer install --ignore-platform-reqs
run_command: php artisan migrate:fresh --force --seed ; php artisan storage:link; heroku-php-nginx public/
envs:
- key: APP_NAME
scope: RUN_TIME
Expand Down Expand Up @@ -132,10 +132,3 @@ spec:
value: "YOUR_DO_SPACES_BUCKET"
databases:
- name: loger-db
jobs:
- name: storagelink
kind: POST_DEPLOY
git:
repo_clone_url: https://github.com/jesusantguerrero/atmosphere.git
branch: staging
run_command: php artisan storage:link
2 changes: 1 addition & 1 deletion .github/workflows/laravel.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Laravel App Deployment
name: Loger Demo Deployment

on:
push:
Expand Down
34 changes: 34 additions & 0 deletions Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
frankenphp
order mercure after encode
order php_server before file_server
{$GLOBAL_OPTIONS}
}

# The domain name of your server
dev-loger.neatlancer.com {
root * public/
encode zstd gzip
php_server {
resolve_root_symlink
}

mercure {
# Transport to use (default to Bolt)
transport_url {$MERCURE_TRANSPORT_URL:bolt://mercure.db}
# Publisher JWT key
publisher_jwt {env.MERCURE_PUBLISHER_JWT_KEY}
# Subscriber JWT key
subscriber_jwt {env.MERCURE_SUBSCRIBER_JWT_KEY}
# Permissive configuration for the development environment
cors_origins *
publish_origins *
demo
anonymous
subscriptions
# Extra directives
{$MERCURE_EXTRA_DIRECTIVES}
}

{$CADDY_SERVER_EXTRA_DIRECTIVES}
}
38 changes: 38 additions & 0 deletions Caddyfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
frankenphp
order mercure after encode
order php_server before file_server
{$GLOBAL_OPTIONS}
}

# The domain name of your server
localhost {
# Set the webroot to the public/ dir
root * public/
# Enable compression (optional)
encode zstd gzip
# Execute PHP files in the current directory and serve assets
php_server {
# Required for the public/storage/ dir
resolve_root_symlink
}

mercure {
# Transport to use (default to Bolt)
transport_url {$MERCURE_TRANSPORT_URL:bolt://mercure.db}
# Publisher JWT key
publisher_jwt {env.MERCURE_PUBLISHER_JWT_KEY}
# Subscriber JWT key
subscriber_jwt {env.MERCURE_SUBSCRIBER_JWT_KEY}
# Permissive configuration for the development environment
cors_origins *
publish_origins *
demo
anonymous
subscriptions
# Extra directives
{$MERCURE_EXTRA_DIRECTIVES}
}

{$CADDY_SERVER_EXTRA_DIRECTIVES}
}
24 changes: 13 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
FROM php:8.1.2-fpm
FROM dunglas/frankenphp

ARG user
ARG uid
ARG TZ

ENV user $user
ENV uid $uid
ENV TZ $TZ
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
Expand All @@ -20,19 +24,17 @@ RUN apt-get clean && rm -rf /var/lib/apt/lists/* && \
docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd && \
#install mailparse
pecl install mailparse && \
echo extension=mailparse.so > /usr/local/etc/php/conf.d/mailparse.ini
echo extension=mailparse.so > /usr/local/etc/php/conf.d/mailparse.ini && \
echo "max_execution_time=900" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer


# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root,crontab -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user && \
chown -R $user:$user /var/www && \
chown -R www-data:www-data /var/www
# RUN useradd -G www-data,root,crontab -u $uid -d /home/$user $user
# RUN mkdir -p /home/$user/.composer && \
# chown -R $user:$user /home/$user && \
# chown -R $user:$user /var/www && \
# chown -R www-data:www-data /var/www

# Set working directory
WORKDIR /var/www

USER $user
# USER $user
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
</strong>
</p>

![example workflow](https://github.com/jesusantguerrero/atmosphere/actions/workflows/laravel.yml/badge.svg)

![example workflow](https://github.com/jesusantguerrero/atmosphere/actions/workflows/laravel.yml/badge.svg?event-push)


![image](https://user-images.githubusercontent.com/17421742/212417292-19f319c5-1cf4-48a8-ba40-1e9b040e820f.png)

Expand Down Expand Up @@ -74,6 +78,13 @@ Loger is organized in "concerns" by the moment it has 4

## Showcase

## Demo
View a live [demo here](https://loger.neatlancer.com), or deploy your instance to DigitalOcean, by clicking the button below.

<a href="https://cloud.digitalocean.com/apps/new?repo=https://github.com/jesusantguerrero/atmosphere/tree/master" target="_blank">
<img src="https://www.deploytodo.com/do-btn-blue.svg" width="240" alt="Deploy to DO">
</a>

### Dashboard
![Dashboard](https://user-images.githubusercontent.com/17421742/212417292-19f319c5-1cf4-48a8-ba40-1e9b040e820f.png)

Expand Down
21 changes: 15 additions & 6 deletions app/Console/Commands/CheckMonthRollover.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace App\Console\Commands;

use App\Domains\Budget\Services\BudgetRolloverService;
use DateTime;
use App\Models\Team;
use Illuminate\Console\Command;

use Illuminate\Support\Facades\DB;
use Illuminate\Console\Command;
use App\Domains\Budget\Services\BudgetRolloverService;

class MonthlyRollover extends Command
class CheckMonthRollover extends Command
{
/**
* The name and signature of the console command.
Expand All @@ -31,7 +31,16 @@ public function handle(BudgetRolloverService $rolloverService)
{

$teams = Team::with('timezone')->without(['settings'])->get();
dd($teams->toArray());

$now = now();
foreach ($teams as $team) {
$timezone = $team["timezone"] ?? null;
if (!$timezone) continue;

$now->setTimezone($timezone['value']);
if ($now->format('H:i') === '00:00' && $now->format('Y-m-d')) {
$previousMonth = $now->subMonth()->startOf('month')->format('Y-m');
$rolloverService->startFrom($team->id, $previousMonth);
}
}
}
}
28 changes: 28 additions & 0 deletions app/Console/Commands/FixLiabilitiesSpent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Console\Commands;

use DateTime;
use App\Models\Team;
use Illuminate\Console\Command;

use App\Domains\Transaction\Services\TransactionService;

class FixLiabilitiesSpent extends Command
{

protected $signature = 'app:fix-liabilities-spent {teamId}';


protected $description = 'change counter account for liability transactions';

public function handle(TransactionService $transactionService)
{

$transactions = $transactionService->getCreditCardSpentTransactions($this->argument('teamId'));
dd($transactions->sum('total'));
foreach ($transactions as $transaction) {
$transactions->id;
}
}
}
14 changes: 7 additions & 7 deletions app/Console/Commands/MakeOccurrenceReminders.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace App\Console\Commands;

use App\Domains\Housing\Contracts\OccurrenceNotifyTypes;
use App\Domains\Housing\Models\Occurrence;
use App\Models\User;
use App\Notifications\OccurrenceAlert;
use Illuminate\Console\Command;
use App\Notifications\OccurrenceAlert;
use App\Domains\Housing\Models\Occurrence;
use App\Domains\Housing\Contracts\OccurrenceNotifyTypes;

class MakeOccurrenceReminders extends Command
{
Expand Down Expand Up @@ -34,14 +34,14 @@ public function handle()
$occurrencesOnLast = Occurrence::getForNotificationType(OccurrenceNotifyTypes::LAST);
$occurrencesOnAvg = Occurrence::getForNotificationType(OccurrenceNotifyTypes::AVG);

$this->sendNotifications($occurrencesOnLast);
$this->sendNotifications($occurrencesOnAvg);
$this->sendNotifications($occurrencesOnLast, OccurrenceNotifyTypes::LAST);
$this->sendNotifications($occurrencesOnAvg, OccurrenceNotifyTypes::AVG);
}

public function sendNotifications($occurrences)
public function sendNotifications($occurrences, $type)
{
foreach ($occurrences as $occurrence) {
User::find($occurrence->user_id)->notify(new OccurrenceAlert($occurrence));
User::find($occurrence->user_id)->notify(new OccurrenceAlert($occurrence, $type));
}
}
}
7 changes: 1 addition & 6 deletions app/Console/Commands/MonthlyRollover.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

namespace App\Console\Commands;

use App\Domains\AppCore\Models\Category;
use App\Domains\Budget\Data\BudgetReservedNames;
use App\Domains\Budget\Services\BudgetRolloverService;
use Illuminate\Console\Command;

use Illuminate\Support\Facades\DB;
use App\Domains\Budget\Services\BudgetRolloverService;

class MonthlyRollover extends Command
{
Expand Down Expand Up @@ -35,6 +31,5 @@ public function handle(BudgetRolloverService $rolloverService)
$month = $this->argument('month');

$rolloverService->rollMonth($teamId, $month."-01");

}
}
34 changes: 13 additions & 21 deletions app/Console/Commands/TeamBudgetRollover.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

namespace App\Console\Commands;

use App\Domains\AppCore\Models\Category;
use App\Domains\Budget\Data\BudgetReservedNames;
use App\Domains\Budget\Services\BudgetRolloverService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use App\Domains\Budget\Services\BudgetRolloverService;

class TeamBudgetRollover extends Command
{
Expand All @@ -15,7 +13,7 @@ class TeamBudgetRollover extends Command
*
* @var string
*/
protected $signature = 'app:team-budget-rollover {teamId}';
protected $signature = 'app:team-budget-rollover {teamId} {date?}';

/**
* The console command description.
Expand All @@ -31,26 +29,20 @@ public function handle(BudgetRolloverService $rolloverService)
{

$teamId = $this->argument('teamId');
$date = $this->argument('date');

$categories = Category::where([
'team_id' => $teamId,
])
->whereNot('name', BudgetReservedNames::READY_TO_ASSIGN->value)
->get();
$monthsWithTransactions = $this->getFirstTransaction($teamId);
$rolloverService->startFrom($teamId, $date ?? $monthsWithTransactions->date);
}

$monthsWithTransactions = DB::table('transaction_lines')
private function getFirstTransaction(int $teamId) {
return DB::table('transaction_lines')
->where([
"team_id" => $teamId
])
->selectRaw("date_format(transaction_lines.date, '%Y-%m') AS date")
->groupBy(DB::raw("date_format(transaction_lines.date, '%Y-%m')"))
->get()
->pluck('date');

$total = count($monthsWithTransactions);
$count = 0;
foreach ($monthsWithTransactions as $month) {
$count++;
$rolloverService->rollMonth($teamId, $month."-01", $categories);
echo "updated month {$month}".PHP_EOL;
echo "{$count} of {$total}".PHP_EOL.PHP_EOL;
}
->orderBy('date')
->first();
}
}
22 changes: 15 additions & 7 deletions app/Console/Commands/TestMessaging.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace App\Console\Commands;

use Exception;
use App\Models\UserDevice;
use App\Services\MessagingService;
use Illuminate\Console\Command;
use App\Events\BudgetCalculated;
use App\Services\MessagingService;

class TestMessaging extends Command
{
Expand All @@ -27,11 +29,17 @@ class TestMessaging extends Command
*/
public function handle()
{
$service = new MessagingService();
$userDevice = UserDevice::find(3);
$service->occurrenceType([
'title' => 'test',
], $userDevice->device_id);
echo $userDevice->device_id;
// $service = new MessagingService();
// $userDevice = UserDevice::find(3);
// $service->occurrenceType([
// 'title' => 'test',
// ], $userDevice->device_id);
// echo $userDevice->device_id;
try {
broadcast( new BudgetCalculated());
} catch (Exception $e) {
dd($e);
}
echo "Done";
}
}
Loading

0 comments on commit 47c0748

Please sign in to comment.