'boolean', 'auto_cancel_unpaid_active' => 'boolean', 'auto_cancel_unpaid_hours' => 'integer', 'auto_cancel_unpaid_send_email' => 'boolean', 'auto_finish_seated_active' => 'boolean', 'auto_finish_seated_minutes' => 'integer', 'auto_mark_no_show_active' => 'boolean', 'auto_mark_no_show_minutes' => 'integer', 'auto_mark_no_show_send_email' => 'boolean', 'auto_mark_no_show_tags' => 'array', 'feedback_request_active' => 'boolean', 'feedback_request_hours' => 'integer', ]; function settingName() { return __eva('Automations'); } public function listItems() { $fields = $this->fields(); return [ [ 'label' => __eva('Pending Payment Reminder'), 'slug' => 'pending_payment_reminder', 'description' => __eva('If customer does not complete reservation payment, send a reminder to finish it'), 'active_field' => 'pending_payment_reminder_active', 'fields' => isset($fields['pending_payment_reminder']) ? $fields['pending_payment_reminder'] : [] ], [ 'label' => __eva('Auto-cancel Unpaid Reservations'), 'slug' => 'auto_cancel_unpaid', 'description' => __eva('Automatically cancel reservations that are not paid after X hours'), 'active_field' => 'auto_cancel_unpaid_active', 'fields' => isset($fields['auto_cancel_unpaid']) ? $fields['auto_cancel_unpaid'] : [] ], [ 'label' => __eva('Auto-finish Seated Reservations'), 'slug' => 'auto_finish_seated', 'description' => __eva('Automatically mark seated reservations as finished after X minutes'), 'active_field' => 'auto_finish_seated_active', 'fields' => isset($fields['auto_finish_seated']) ? $fields['auto_finish_seated'] : [] ], [ 'label' => __eva('Auto-mark No-Show Reservations'), 'slug' => 'auto_mark_no_show', 'description' => __eva('Automatically mark reservations as no-show if customer has not been seated X minutes after reservation time'), 'active_field' => 'auto_mark_no_show_active', 'fields' => isset($fields['auto_mark_no_show']) ? $fields['auto_mark_no_show'] : [] ], [ 'label' => __eva('Feedback Request'), 'slug' => 'feedback_request', 'description' => __eva('Send feedback request email X hours after reservation is finished'), 'active_field' => 'feedback_request_active', 'fields' => isset($fields['feedback_request']) ? $fields['feedback_request'] : [] ], ]; } public function fields() { return [ 'pending_payment_reminder' => $this->fieldsPendingPaymentReminder(), 'auto_cancel_unpaid' => $this->fieldsAutoCancelUnpaid(), 'auto_finish_seated' => $this->fieldsAutoFinishSeated(), 'auto_mark_no_show' => $this->fieldsAutoMarkNoShow(), 'feedback_request' => $this->fieldsFeedbackRequest(), ]; } protected function fieldsPendingPaymentReminder() { return [ [ 'attribute' => 'pending_payment_reminder_active', 'stacked' => true, 'name' => __eva('Active'), 'component' => 'boolean-field', 'type' => 'switch', 'value' => $this->pending_payment_reminder_active, 'helpText' => __eva('Enable/disable pending payment reminders') ], /*[ 'attribute' => 'pending_payment_reminder_hours', 'stacked' => false, 'name' => __eva('Send reminder after (hours)'), 'component' => 'select-field', 'value' => $this->pending_payment_reminder_hours ?? 1, 'min' => 0.5, 'max' => 24, 'step' => 0.5, 'helpText' => __eva('How many hours to wait before sending the reminder'), 'showWhen' => [ 'attribute' => 'pending_payment_reminder_active', 'values' => ['true'] ] ],*/ ]; } protected function fieldsAutoCancelUnpaid() { return [ [ 'attribute' => 'auto_cancel_unpaid_active', 'stacked' => true, 'name' => __eva('Active'), 'component' => 'boolean-field', 'type' => 'switch', 'value' => $this->auto_cancel_unpaid_active, 'helpText' => __eva('Enable/disable auto-cancellation of unpaid reservations') ], [ 'attribute' => 'auto_cancel_unpaid_hours', 'stacked' => false, 'name' => __eva('Cancel after (hours)'), 'component' => 'select-field', 'value' => $this->auto_cancel_unpaid_hours ?? 2, 'options' => [ ['label' => '1h', 'value' => 1], ['label' => '2h', 'value' => 2], ['label' => '3h', 'value' => 3], ['label' => '4h', 'value' => 4], ['label' => '5h', 'value' => 5], ['label' => '6h', 'value' => 6], ], 'helpText' => __eva('How many hours to wait before cancelling unpaid reservations'), 'showWhen' => [ 'attribute' => 'auto_cancel_unpaid_active', 'values' => ['true'] ] ], [ 'attribute' => 'auto_cancel_unpaid_send_email', 'stacked' => false, 'name' => __eva('Send cancelled email'), 'component' => 'boolean-field', 'type' => 'switch', 'value' => $this->auto_cancel_unpaid_send_email ?? true, 'helpText' => __eva('Send cancelled email notification to customer'), 'showWhen' => [ 'attribute' => 'auto_cancel_unpaid_active', 'values' => ['true'] ] ], // NUEVO: Selector de tipo de email [ 'attribute' => 'auto_cancel_unpaid_email_type', 'stacked' => false, 'name' => __eva('Email to send'), 'component' => 'select-field', 'value' => $this->auto_cancel_unpaid_email_type ?? 'default', 'options' => $this->getEmailOptions(), 'helpText' => __eva('Choose which email template to send when cancelling unpaid reservations'), 'showWhen' => [ 'attribute' => 'auto_cancel_unpaid_send_email', 'values' => ['true'] ] ], ]; } protected function fieldsAutoFinishSeated() { return [ [ 'attribute' => 'auto_finish_seated_active', 'stacked' => true, 'name' => __eva('Active'), 'component' => 'boolean-field', 'type' => 'switch', 'value' => $this->auto_finish_seated_active, 'helpText' => __eva('Enable/disable auto-finishing of seated reservations') ], [ 'attribute' => 'auto_finish_seated_minutes', 'stacked' => false, 'name' => __eva('Mark as finished after (minutes)'), 'component' => 'select-field', 'value' => $this->auto_finish_seated_minutes ?? 15, 'options' => [ ['label' => '15 min', 'value' => 15], ['label' => '30 min', 'value' => 30], ['label' => '45 min', 'value' => 45], ['label' => '60 min', 'value' => 60], ], 'helpText' => __eva('How many minutes to wait before marking seated reservations as finished'), 'showWhen' => [ 'attribute' => 'auto_finish_seated_active', 'values' => ['true'] ] ], ]; } protected function fieldsAutoMarkNoShow() { return [ [ 'attribute' => 'auto_mark_no_show_active', 'stacked' => true, 'name' => __eva('Active'), 'component' => 'boolean-field', 'type' => 'switch', 'value' => $this->auto_mark_no_show_active, 'helpText' => __eva('Enable/disable auto-marking reservations as no-show') ], [ 'attribute' => 'auto_mark_no_show_minutes', 'stacked' => false, 'name' => __eva('Mark as no-show after (minutes)'), 'component' => 'select-field', 'value' => $this->auto_mark_no_show_minutes ?? 30, 'options' => [ ['label' => '15 min', 'value' => 15], ['label' => '30 min', 'value' => 30], ['label' => '45 min', 'value' => 45], ['label' => '60 min', 'value' => 60], ], 'helpText' => __eva('How many minutes after reservation time to mark as no-show if not seated'), 'showWhen' => [ 'attribute' => 'auto_mark_no_show_active', 'values' => ['true'] ] ], [ 'attribute' => 'auto_mark_no_show_send_email', 'stacked' => false, 'name' => __eva('Send no-show email'), 'component' => 'boolean-field', 'type' => 'switch', 'value' => $this->auto_mark_no_show_send_email ?? true, 'helpText' => __eva('Send no-show email notification to customer'), 'showWhen' => [ 'attribute' => 'auto_mark_no_show_active', 'values' => ['true'] ] ], [ 'attribute' => 'auto_mark_no_show_tags', 'stacked' => false, 'name' => __eva('Tags for customer'), 'component' => 'select-tags-field', 'url' => '/app/ctags', 'value' => $this->auto_mark_no_show_tags ?? [], 'helpText' => __eva('Add tags to customer when marking as no-show'), 'showWhen' => [ 'attribute' => 'auto_mark_no_show_active', 'values' => ['true'] ], ] ]; } protected function fieldsFeedbackRequest() { return [ [ 'attribute' => 'feedback_request_active', 'stacked' => true, 'name' => __eva('Active'), 'component' => 'boolean-field', 'type' => 'switch', 'value' => $this->feedback_request_active, 'helpText' => __eva('Enable/disable feedback request emails') ], [ 'attribute' => 'feedback_request_hours', // antes eran horas pero lo he cambiado a minutos para que tenga mas margen 'stacked' => false, 'name' => __eva('Send feedback request after (hours)'), 'component' => 'select-field', 'value' => $this->feedback_request_hours ?? 1, 'options' => [ ['label' => '15min', 'value' => 15], ['label' => '30min', 'value' => 30], ['label' => '45min', 'value' => 45], ['label' => '1h', 'value' => 60], ['label' => '2h', 'value' => 120], ['label' => '3h', 'value' => 180], ['label' => '4h', 'value' => 240], ['label' => '5h', 'value' => 300], ['label' => '6h', 'value' => 360], ['label' => '7h', 'value' => 420], ['label' => '8h', 'value' => 480], ], 'helpText' => __eva('How many hours after finishing to send the feedback request'), 'showWhen' => [ 'attribute' => 'feedback_request_active', 'values' => ['true'] ] ], ]; } protected function getEmailOptions() { $options = [ ['label' => __eva('Default Cancelled Email'), 'value' => 'default'] ]; // Obtener los emails personalizados de EmailCustom $customEmails = EmailCustom::where('restaurant_id', $this->restaurant_id) ->get(); foreach ($customEmails as $customEmail) { if ($customEmail->email_active) { $options[] = [ 'label' => $customEmail->name, 'value' => 'custom_' . $customEmail->id ]; } } return $options; } public function defaultValue() { return [ 'pending_payment_reminder_active' => false, //'pending_payment_reminder_hours' => 1, 'auto_cancel_unpaid_active' => false, 'auto_cancel_unpaid_hours' => 2, 'auto_cancel_unpaid_send_email' => false, 'auto_cancel_unpaid_email_type' => 'default', 'auto_finish_seated_active' => false, 'auto_finish_seated_minutes' => 15, 'auto_mark_no_show_active' => false, 'auto_mark_no_show_minutes' => 30, 'auto_mark_no_show_send_email' => true, 'auto_mark_no_show_tags' => [], 'feedback_request_active' => false, 'feedback_request_hours' => 1, ]; } }