Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions app/Enums/InvoiceStatusEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,41 @@
namespace App\Enums;

use Filament\Support\Contracts\HasColor;
use Filament\Support\Contracts\HasDescription;
use Filament\Support\Contracts\HasIcon;
use Filament\Support\Contracts\HasLabel;
use Illuminate\Support\Str;

enum InvoiceStatusEnum: string implements HasLabel, HasColor, HasIcon
enum InvoiceStatusEnum: string implements HasLabel, HasColor, HasIcon, HasDescription
{
case DRAFT = 'draft';
case SENT = 'sent';
case UNPAID = 'unpaid';
case PARTIALLY_PAID = 'partially_paid';
case PAID = 'paid';
case CANCELED = 'canceled';

public function getLabel(): string
{
return ucwords(__($this->value));
return __(
Str::ucfirst(
Str::replace('_', ' ', $this->value)
)
);
}

public function getDescription(): ?string
{
return $this->getLabel();
}

public function getColor(): string
{
return match ($this) {
self::DRAFT => 'gray',
self::SENT => 'info',
self::UNPAID => 'warning',
self::PARTIALLY_PAID => 'warning',
self::PAID => 'success',
self::CANCELED => 'danger',
};
Expand All @@ -33,8 +48,10 @@ public function getIcon(): ?string
return match ($this) {
self::DRAFT => 'heroicon-o-document-duplicate',
self::SENT => 'heroicon-o-document',
self::UNPAID => 'heroicon-o-x-circle',
self::PARTIALLY_PAID => 'heroicon-o-clipboard-document-check',
self::PAID => 'heroicon-o-check',
self::CANCELED => 'heroicon-o-x-circle',
self::CANCELED => 'heroicon-o-exclamation-circle',
};
}

Expand Down
6 changes: 3 additions & 3 deletions app/Filament/App/Resources/InvoiceResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
use Filament\Support\Enums\FontWeight;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Support\Str;
use Symfony\Component\HttpFoundation\StreamedResponse;

class InvoiceResource extends Resource
Expand Down Expand Up @@ -89,6 +88,7 @@ public static function form(Form $form): Form
->required()
->columnSpan(2),
Forms\Components\TextInput::make('discount')
->translateLabel()
->numeric()
->live()
->afterStateUpdated(fn(Forms\Set $set, Forms\Get $get) => self::calcItemTotal($get, $set)),
Expand Down Expand Up @@ -350,6 +350,6 @@ public static function generatePdf(Invoice $invoice): StreamedResponse
return response()->streamDownload(function () use ($invoice) {
$pdf = (new InvoiceService())->generatePdf($invoice);
echo $pdf->stream();
}, 'invoice_' . $invoice->number . '.pdf');
}, Str::snake($invoice->client->name).'_invoice_' . $invoice->number . '.pdf');
}
}
99 changes: 50 additions & 49 deletions app/Filament/App/Resources/TaskResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ public static function form(Form $form): Form
'project',
'name',
fn(Builder $query, Forms\Get $get) =>
$query->byClient($get('client'))
->where('active', true)
->orderBy('name')
$query->byClient($get('client'))
->where('active', true)
->orderBy('name')

)
->searchable()
Expand All @@ -150,10 +150,10 @@ public static function form(Form $form): Form
'parent',
'title',
fn(Builder $query, Forms\Get $get) =>
$query
->byProject($get('project'))
->opened()
->orderBy('title')
$query
->byProject($get('project'))
->opened()
->orderBy('title')
)
->searchable(),
]),
Expand Down Expand Up @@ -237,27 +237,27 @@ public static function form(Form $form): Form
'default' => 2,
'md' => 5
])->schema([
// Forms\Components\Select::make('date_setting')
// ->translateLabel()
// ->options([
// 'all-dates-today' => __('All dates today'),
// 'all-dates-tomorrow' => __('All dates tomorrow'),
// 'due-planned-today' => __('Due and planned dates today'),
// 'due-planned-tomorrow' => __('Due and planned dates tomorrow'),
// ])
// ->live()
// ->afterStateUpdated(function ($state, $get, $set) {
// $today = Carbon::today(PejotaHelper::getUserTimeZone())->toDayDateTimeString();
// match ($state) {
// 'all-dates-today' => function () use ($set, $today) {
// $set('due_date', $today);
// $set('planned_start', $today);
// $set('planned_end', $today);
// $set('actual_start', $today);
// $set('actual_end', $today);
// },
// };
// }),
// Forms\Components\Select::make('date_setting')
// ->translateLabel()
// ->options([
// 'all-dates-today' => __('All dates today'),
// 'all-dates-tomorrow' => __('All dates tomorrow'),
// 'due-planned-today' => __('Due and planned dates today'),
// 'due-planned-tomorrow' => __('Due and planned dates tomorrow'),
// ])
// ->live()
// ->afterStateUpdated(function ($state, $get, $set) {
// $today = Carbon::today(PejotaHelper::getUserTimeZone())->toDayDateTimeString();
// match ($state) {
// 'all-dates-today' => function () use ($set, $today) {
// $set('due_date', $today);
// $set('planned_start', $today);
// $set('planned_end', $today);
// $set('actual_start', $today);
// $set('actual_end', $today);
// },
// };
// }),
Forms\Components\DatePicker::make('due_date')
->columnSpan([
'default' => 2,
Expand Down Expand Up @@ -455,10 +455,10 @@ public static function table(Table $table): Table
->tooltip(__('Start a new session for this task'))
->icon('heroicon-o-play')
->color(Color::Amber)
// ->form(WorkSessionResource::getFormSchema())
// ->fillForm(function(Task $task) {
// return CreateWorkSession::getFillFormArray($task);
// }),
// ->form(WorkSessionResource::getFormSchema())
// ->fillForm(function(Task $task) {
// return CreateWorkSession::getFillFormArray($task);
// }),
->url(fn($record) => CreateWorkSession::getUrl([
'task' => $record->id,
])),
Expand Down Expand Up @@ -595,21 +595,21 @@ public static function infolist(Infolist $infolist): Infolist
return new HtmlString($state);
})
->prefixAction(fn($component) => Action::make('checkCompleted')
->icon(
self::getStateCompleted(
$component
) ? 'heroicon-o-check' : 'heroicon-o-stop'
)
->color(
self::getStateCompleted($component) ? Color::Green : Color::Gray
)
->action(function (Model $record, $component) {
$index = explode('.', $component->getStatePath())[1];
$checklist = $record->checklist;
$checklist[$index]['completed'] = !$record->checklist[$index]['completed'];
$record->checklist = $checklist;
$record->save();
})
->icon(
self::getStateCompleted(
$component
) ? 'heroicon-o-check' : 'heroicon-o-stop'
)
->color(
self::getStateCompleted($component) ? Color::Green : Color::Gray
)
->action(function (Model $record, $component) {
$index = explode('.', $component->getStatePath())[1];
$checklist = $record->checklist;
$checklist[$index]['completed'] = !$record->checklist[$index]['completed'];
$record->checklist = $checklist;
$record->save();
})
),
]),
]),
Expand Down Expand Up @@ -821,8 +821,9 @@ public static function infolist(Infolist $infolist): Infolist
->color(Color::hex('#ACA'))
->button()
->tooltip(__('Change status'))
->action(function (Model $record, array $data): void {
->action(function (Model $record, array $data, $livewire): void {
$record->update($data);
$livewire->handleTaskClose($data, $record->id);
})
->form([
Forms\Components\Select::make('status_id')
Expand Down Expand Up @@ -995,7 +996,7 @@ protected static function getPostponeActions($field): array

public static function getTableColumns(): array
{
// dd(PejotaHelper::getUserTaskListDefaultColumns());
// dd(PejotaHelper::getUserTaskListDefaultColumns());
$isMobile = PejotaHelper::isMobile();

return [
Expand Down
48 changes: 44 additions & 4 deletions app/Filament/App/Resources/TaskResource/Pages/ViewTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,55 @@
namespace App\Filament\App\Resources\TaskResource\Pages;

use App\Filament\App\Resources\TaskResource;
use App\Models\Status;
use App\Models\WorkSession;
use Filament\Facades\Filament;
use Filament\Notifications\Actions\Action;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\ViewRecord;
use Illuminate\Contracts\Support\Htmlable;
use Livewire\Attributes\On;

class ViewTask extends ViewRecord
{
class ViewTask extends ViewRecord {
protected static string $resource = TaskResource::class;

public function getTitle(): string|Htmlable
{
public function getTitle(): string|Htmlable {
return $this->record->title;
}

public function handleTaskClose($data, $taskId)
{
$status = Status::findOrFail($data["status_id"]);
$userId = Filament::auth()->id();

if ($status->phase == "closed") {
$runningWorkSession = WorkSession::where(['is_running' => 1, "task_id" => $taskId])
->where('user_id', $userId)
->first();

if ($runningWorkSession) {
return (Notification::make()
->title('Saved successfully')
->success()
->body('An active work session is in progress. Would you like to close it?')
->duration(10000)
->actions([
Action::make('Close session')
->button()
->dispatch('handle-work-session-close', [$runningWorkSession->id])
->close(),
Action::make('Keep session open')
->color('gray')
->close(),
])
->send());
}
}
}

#[On("handle-work-session-close")]
public function handleWorkSessionClose(int $workSessionId) {
WorkSession::find($workSessionId)
?->update(['is_running' => 0]);
}
}
2 changes: 2 additions & 0 deletions lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
"Overall Numbers": "Números Generales",
"Paid": "Pagado",
"Parent": "Padre",
"Partially paid": "Parcialmente pagado",
"Payment date": "Fecha de pago",
"Payment method": "Método de pago",
"Payment extra-info": "Información adicional de pago",
Expand Down Expand Up @@ -187,6 +188,7 @@
"Type": "Tipo",
"Unit": "Unidad",
"Units": "Unidades",
"Unpaid": "No pagado",
"Updated at": "Actualizado en",
"Urgent": "Urgente",
"Value": "Valor",
Expand Down
2 changes: 2 additions & 0 deletions lang/pt_BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
"Overall Numbers": "Números Gerais",
"Paid": "Pago",
"Parent": "Pai",
"Partially paid": "Parcialmente pago",
"Payment date": "Data de pagamento",
"Payment method": "Método de pagamento",
"Payment extra-info": "Informações adicionais de pagamento",
Expand Down Expand Up @@ -187,6 +188,7 @@
"Type": "Tipo",
"Unit": "Unidade",
"Units": "Unidades",
"Unpaid": "Não pago",
"Updated at": "Atualizado em",
"Urgent": "Urgente",
"Value": "Valor",
Expand Down
2 changes: 1 addition & 1 deletion resources/views/invoice/pdf.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
<h4>@lang('Extra Information:')</h4>
<div class="panel panel-default">
<div class="panel-body">
{{ $invoice->extra_info }}
{!! nl2br($invoice->extra_info) !!}
</div>
</div>
@endif
Expand Down