diff --git a/src/integrations/supabase/types.ts b/src/integrations/supabase/types.ts index df75f3f..98047fb 100644 --- a/src/integrations/supabase/types.ts +++ b/src/integrations/supabase/types.ts @@ -49,7 +49,12 @@ export type Database = { } accounts_payable: { Row: { + ai_suggested_chart_of_account_id: number | null + ai_suggestion_accepted: boolean | null + ai_suggestion_confidence: number | null amount: number + approved_by_name: string | null + approved_by_user_id: string | null bank_account_id: string | null bank_category: string | null bank_integration_id: string | null @@ -58,24 +63,40 @@ export type Database = { created_at: string | null description: string | null document_number: string | null + document_type: string | null due_date: string id: string imported_from_bank: boolean | null - issue_date: string + installments: number | null + is_internal_transfer: boolean | null + issue_date: string | null organization_id: string + origin_module: string | null paid_amount: number | null + partner_id: string | null payment_date: string | null payment_method_id: string | null person_id: string | null reconciled: boolean | null reconciliation_notes: string | null + recurrence: boolean | null + recurrence_interval: string | null + related_closing_id: string | null status: string suggested_chart_of_account_id: number | null + tags: string[] | null + transaction_code: number transaction_type: Database["public"]["Enums"]["transaction_type_enum"] + transfer_group_id: string | null unit_id: string | null } Insert: { + ai_suggested_chart_of_account_id?: number | null + ai_suggestion_accepted?: boolean | null + ai_suggestion_confidence?: number | null amount: number + approved_by_name?: string | null + approved_by_user_id?: string | null bank_account_id?: string | null bank_category?: string | null bank_integration_id?: string | null @@ -84,24 +105,40 @@ export type Database = { created_at?: string | null description?: string | null document_number?: string | null + document_type?: string | null due_date: string id?: string imported_from_bank?: boolean | null - issue_date: string + installments?: number | null + is_internal_transfer?: boolean | null + issue_date?: string | null organization_id: string + origin_module?: string | null paid_amount?: number | null + partner_id?: string | null payment_date?: string | null payment_method_id?: string | null person_id?: string | null reconciled?: boolean | null reconciliation_notes?: string | null + recurrence?: boolean | null + recurrence_interval?: string | null + related_closing_id?: string | null status: string suggested_chart_of_account_id?: number | null + tags?: string[] | null + transaction_code?: number transaction_type?: Database["public"]["Enums"]["transaction_type_enum"] + transfer_group_id?: string | null unit_id?: string | null } Update: { + ai_suggested_chart_of_account_id?: number | null + ai_suggestion_accepted?: boolean | null + ai_suggestion_confidence?: number | null amount?: number + approved_by_name?: string | null + approved_by_user_id?: string | null bank_account_id?: string | null bank_category?: string | null bank_integration_id?: string | null @@ -110,23 +147,41 @@ export type Database = { created_at?: string | null description?: string | null document_number?: string | null + document_type?: string | null due_date?: string id?: string imported_from_bank?: boolean | null - issue_date?: string + installments?: number | null + is_internal_transfer?: boolean | null + issue_date?: string | null organization_id?: string + origin_module?: string | null paid_amount?: number | null + partner_id?: string | null payment_date?: string | null payment_method_id?: string | null person_id?: string | null reconciled?: boolean | null reconciliation_notes?: string | null + recurrence?: boolean | null + recurrence_interval?: string | null + related_closing_id?: string | null status?: string suggested_chart_of_account_id?: number | null + tags?: string[] | null + transaction_code?: number transaction_type?: Database["public"]["Enums"]["transaction_type_enum"] + transfer_group_id?: string | null unit_id?: string | null } Relationships: [ + { + foreignKeyName: "accounts_payable_ai_suggested_chart_of_account_id_fkey" + columns: ["ai_suggested_chart_of_account_id"] + isOneToOne: false + referencedRelation: "chart_of_accounts" + referencedColumns: ["id"] + }, { foreignKeyName: "accounts_payable_bank_account_id_fkey" columns: ["bank_account_id"] @@ -155,6 +210,13 @@ export type Database = { referencedRelation: "organizations" referencedColumns: ["id"] }, + { + foreignKeyName: "accounts_payable_partner_id_fkey" + columns: ["partner_id"] + isOneToOne: false + referencedRelation: "unit_partners" + referencedColumns: ["id"] + }, { foreignKeyName: "accounts_payable_payment_method_id_fkey" columns: ["payment_method_id"] @@ -169,6 +231,13 @@ export type Database = { referencedRelation: "people" referencedColumns: ["id"] }, + { + foreignKeyName: "accounts_payable_related_closing_id_fkey" + columns: ["related_closing_id"] + isOneToOne: false + referencedRelation: "financial_closings" + referencedColumns: ["id"] + }, { foreignKeyName: "accounts_payable_suggested_chart_of_account_id_fkey" columns: ["suggested_chart_of_account_id"] @@ -212,6 +281,298 @@ export type Database = { } Relationships: [] } + ai_chart_rules: { + Row: { + chart_of_account_id: number + created_at: string | null + examples: string | null + id: string + keywords: string + organization_id: string + priority: number | null + updated_at: string | null + } + Insert: { + chart_of_account_id: number + created_at?: string | null + examples?: string | null + id?: string + keywords: string + organization_id: string + priority?: number | null + updated_at?: string | null + } + Update: { + chart_of_account_id?: number + created_at?: string | null + examples?: string | null + id?: string + keywords?: string + organization_id?: string + priority?: number | null + updated_at?: string | null + } + Relationships: [ + { + foreignKeyName: "ai_chart_rules_chart_of_account_id_fkey" + columns: ["chart_of_account_id"] + isOneToOne: false + referencedRelation: "chart_of_accounts" + referencedColumns: ["id"] + }, + { + foreignKeyName: "ai_chart_rules_organization_id_fkey" + columns: ["organization_id"] + isOneToOne: false + referencedRelation: "organizations" + referencedColumns: ["id"] + }, + ] + } + ai_config: { + Row: { + assistant_name: string + created_at: string | null + custom_instructions: string | null + enabled: boolean + id: string + model_name: string + organization_id: string + provider: string + updated_at: string | null + } + Insert: { + assistant_name?: string + created_at?: string | null + custom_instructions?: string | null + enabled?: boolean + id?: string + model_name?: string + organization_id: string + provider?: string + updated_at?: string | null + } + Update: { + assistant_name?: string + created_at?: string | null + custom_instructions?: string | null + enabled?: boolean + id?: string + model_name?: string + organization_id?: string + provider?: string + updated_at?: string | null + } + Relationships: [ + { + foreignKeyName: "ai_config_organization_id_fkey" + columns: ["organization_id"] + isOneToOne: true + referencedRelation: "organizations" + referencedColumns: ["id"] + }, + ] + } + approval_audit_logs: { + Row: { + action: string + actor_ip: string | null + actor_name: string | null + actor_user_agent: string | null + actor_user_id: string | null + batch_id: string + created_at: string | null + id: string + note: string | null + payable_id: string | null + } + Insert: { + action: string + actor_ip?: string | null + actor_name?: string | null + actor_user_agent?: string | null + actor_user_id?: string | null + batch_id: string + created_at?: string | null + id?: string + note?: string | null + payable_id?: string | null + } + Update: { + action?: string + actor_ip?: string | null + actor_name?: string | null + actor_user_agent?: string | null + actor_user_id?: string | null + batch_id?: string + created_at?: string | null + id?: string + note?: string | null + payable_id?: string | null + } + Relationships: [ + { + foreignKeyName: "approval_audit_logs_batch_id_fkey" + columns: ["batch_id"] + isOneToOne: false + referencedRelation: "approval_batches" + referencedColumns: ["id"] + }, + { + foreignKeyName: "approval_audit_logs_payable_id_fkey" + columns: ["payable_id"] + isOneToOne: false + referencedRelation: "accounts_payable" + referencedColumns: ["id"] + }, + ] + } + approval_batches: { + Row: { + access_code: string | null + approval_token_hash: string + assigned_approver_id: string | null + assigned_reviewer_id: string | null + batch_type: string + created_at: string | null + created_by: string + created_by_email: string | null + decided_at: string | null + decided_by: string | null + expires_at: string + id: string + items_count: number + organization_id: string + status: string + total_amount: number + webhook_duration_ms: number | null + webhook_error: string | null + webhook_payload: Json | null + webhook_response_text: string | null + webhook_return_duration_ms: number | null + webhook_return_response_text: string | null + webhook_return_sent_at: string | null + webhook_return_status: string | null + webhook_sent_at: string | null + webhook_status: string | null + } + Insert: { + access_code?: string | null + approval_token_hash: string + assigned_approver_id?: string | null + assigned_reviewer_id?: string | null + batch_type?: string + created_at?: string | null + created_by: string + created_by_email?: string | null + decided_at?: string | null + decided_by?: string | null + expires_at: string + id?: string + items_count?: number + organization_id: string + status: string + total_amount?: number + webhook_duration_ms?: number | null + webhook_error?: string | null + webhook_payload?: Json | null + webhook_response_text?: string | null + webhook_return_duration_ms?: number | null + webhook_return_response_text?: string | null + webhook_return_sent_at?: string | null + webhook_return_status?: string | null + webhook_sent_at?: string | null + webhook_status?: string | null + } + Update: { + access_code?: string | null + approval_token_hash?: string + assigned_approver_id?: string | null + assigned_reviewer_id?: string | null + batch_type?: string + created_at?: string | null + created_by?: string + created_by_email?: string | null + decided_at?: string | null + decided_by?: string | null + expires_at?: string + id?: string + items_count?: number + organization_id?: string + status?: string + total_amount?: number + webhook_duration_ms?: number | null + webhook_error?: string | null + webhook_payload?: Json | null + webhook_response_text?: string | null + webhook_return_duration_ms?: number | null + webhook_return_response_text?: string | null + webhook_return_sent_at?: string | null + webhook_return_status?: string | null + webhook_sent_at?: string | null + webhook_status?: string | null + } + Relationships: [ + { + foreignKeyName: "approval_batches_organization_id_fkey" + columns: ["organization_id"] + isOneToOne: false + referencedRelation: "organizations" + referencedColumns: ["id"] + }, + ] + } + approval_items: { + Row: { + batch_id: string + created_at: string | null + current_status: string + decided_at: string | null + decided_by: string | null + id: string + note: string | null + payable_id: string + rejection_reason: string | null + } + Insert: { + batch_id: string + created_at?: string | null + current_status: string + decided_at?: string | null + decided_by?: string | null + id?: string + note?: string | null + payable_id: string + rejection_reason?: string | null + } + Update: { + batch_id?: string + created_at?: string | null + current_status?: string + decided_at?: string | null + decided_by?: string | null + id?: string + note?: string | null + payable_id?: string + rejection_reason?: string | null + } + Relationships: [ + { + foreignKeyName: "approval_items_batch_id_fkey" + columns: ["batch_id"] + isOneToOne: false + referencedRelation: "approval_batches" + referencedColumns: ["id"] + }, + { + foreignKeyName: "approval_items_payable_id_fkey" + columns: ["payable_id"] + isOneToOne: false + referencedRelation: "accounts_payable" + referencedColumns: ["id"] + }, + ] + } avisos_enviados: { Row: { conta_id: string @@ -595,8 +956,69 @@ export type Database = { } Relationships: [] } + category_management_limits: { + Row: { + category_id: number | null + created_at: string + direction: string | null + enabled: boolean | null + id: string + limit_green: number | null + limit_red: number | null + limit_yellow: number | null + metric: string | null + organization_id: string + unit_id: string | null + updated_at: string + } + Insert: { + category_id?: number | null + created_at?: string + direction?: string | null + enabled?: boolean | null + id?: string + limit_green?: number | null + limit_red?: number | null + limit_yellow?: number | null + metric?: string | null + organization_id: string + unit_id?: string | null + updated_at?: string + } + Update: { + category_id?: number | null + created_at?: string + direction?: string | null + enabled?: boolean | null + id?: string + limit_green?: number | null + limit_red?: number | null + limit_yellow?: number | null + metric?: string | null + organization_id?: string + unit_id?: string | null + updated_at?: string + } + Relationships: [ + { + foreignKeyName: "category_management_limits_category_id_fkey" + columns: ["category_id"] + isOneToOne: false + referencedRelation: "chart_of_account_categories" + referencedColumns: ["id"] + }, + { + foreignKeyName: "category_management_limits_unit_id_fkey" + columns: ["unit_id"] + isOneToOne: false + referencedRelation: "units" + referencedColumns: ["id"] + }, + ] + } chart_of_account_categories: { Row: { + allowed_unit_ids: string[] | null code: number created_at: string | null description: string @@ -607,6 +1029,7 @@ export type Database = { section_id: string | null } Insert: { + allowed_unit_ids?: string[] | null code: number created_at?: string | null description: string @@ -617,6 +1040,7 @@ export type Database = { section_id?: string | null } Update: { + allowed_unit_ids?: string[] | null code?: number created_at?: string | null description?: string @@ -645,28 +1069,40 @@ export type Database = { } chart_of_accounts: { Row: { + allowed_unit_ids: string[] | null category_id: number created_at: string | null description: string id: number + is_internal_transfer: boolean | null + is_obligatory: boolean | null organization_id: string structured_code: string + transfer_direction: string | null } Insert: { + allowed_unit_ids?: string[] | null category_id: number created_at?: string | null description: string id?: number + is_internal_transfer?: boolean | null + is_obligatory?: boolean | null organization_id: string structured_code: string + transfer_direction?: string | null } Update: { + allowed_unit_ids?: string[] | null category_id?: number created_at?: string | null description?: string id?: number + is_internal_transfer?: boolean | null + is_obligatory?: boolean | null organization_id?: string structured_code?: string + transfer_direction?: string | null } Relationships: [ { @@ -1021,6 +1457,164 @@ export type Database = { } Relationships: [] } + critical_bill_months: { + Row: { + alerts_sent: number[] | null + created_at: string | null + critical_bill_id: string + due_date: string + id: string + last_alert_sent_at: string | null + month: number + notes: string | null + organization_id: string + paid_at: string | null + payment_amount: number | null + payment_desc: string | null + payment_details: Json | null + payment_ref: string | null + payment_supplier: string | null + status: string | null + updated_at: string | null + year: number + } + Insert: { + alerts_sent?: number[] | null + created_at?: string | null + critical_bill_id: string + due_date: string + id?: string + last_alert_sent_at?: string | null + month: number + notes?: string | null + organization_id: string + paid_at?: string | null + payment_amount?: number | null + payment_desc?: string | null + payment_details?: Json | null + payment_ref?: string | null + payment_supplier?: string | null + status?: string | null + updated_at?: string | null + year: number + } + Update: { + alerts_sent?: number[] | null + created_at?: string | null + critical_bill_id?: string + due_date?: string + id?: string + last_alert_sent_at?: string | null + month?: number + notes?: string | null + organization_id?: string + paid_at?: string | null + payment_amount?: number | null + payment_desc?: string | null + payment_details?: Json | null + payment_ref?: string | null + payment_supplier?: string | null + status?: string | null + updated_at?: string | null + year?: number + } + Relationships: [ + { + foreignKeyName: "critical_bill_months_critical_bill_id_fkey" + columns: ["critical_bill_id"] + isOneToOne: false + referencedRelation: "critical_bills" + referencedColumns: ["id"] + }, + { + foreignKeyName: "critical_bill_months_organization_id_fkey" + columns: ["organization_id"] + isOneToOne: false + referencedRelation: "organizations" + referencedColumns: ["id"] + }, + ] + } + critical_bills: { + Row: { + alert_days: number[] | null + chart_of_account_id: number + created_at: string | null + criticality: string | null + default_due_day: number | null + enabled: boolean | null + id: string + organization_id: string + responsible_user_id: string | null + responsible_whatsapp: string | null + supplier_id: string | null + unit_id: string | null + updated_at: string | null + validation_type: string | null + } + Insert: { + alert_days?: number[] | null + chart_of_account_id: number + created_at?: string | null + criticality?: string | null + default_due_day?: number | null + enabled?: boolean | null + id?: string + organization_id: string + responsible_user_id?: string | null + responsible_whatsapp?: string | null + supplier_id?: string | null + unit_id?: string | null + updated_at?: string | null + validation_type?: string | null + } + Update: { + alert_days?: number[] | null + chart_of_account_id?: number + created_at?: string | null + criticality?: string | null + default_due_day?: number | null + enabled?: boolean | null + id?: string + organization_id?: string + responsible_user_id?: string | null + responsible_whatsapp?: string | null + supplier_id?: string | null + unit_id?: string | null + updated_at?: string | null + validation_type?: string | null + } + Relationships: [ + { + foreignKeyName: "critical_bills_chart_of_account_id_fkey" + columns: ["chart_of_account_id"] + isOneToOne: false + referencedRelation: "chart_of_accounts" + referencedColumns: ["id"] + }, + { + foreignKeyName: "critical_bills_organization_id_fkey" + columns: ["organization_id"] + isOneToOne: false + referencedRelation: "organizations" + referencedColumns: ["id"] + }, + { + foreignKeyName: "critical_bills_supplier_id_fkey" + columns: ["supplier_id"] + isOneToOne: false + referencedRelation: "people" + referencedColumns: ["id"] + }, + { + foreignKeyName: "critical_bills_unit_id_fkey" + columns: ["unit_id"] + isOneToOne: false + referencedRelation: "units" + referencedColumns: ["id"] + }, + ] + } dados_cliente_dolceamore: { Row: { atendimento_ia: string | null @@ -1198,6 +1792,41 @@ export type Database = { }, ] } + document_types: { + Row: { + created_at: string + description: string | null + id: string + is_active: boolean | null + name: string + organization_id: string + } + Insert: { + created_at?: string + description?: string | null + id?: string + is_active?: boolean | null + name: string + organization_id: string + } + Update: { + created_at?: string + description?: string | null + id?: string + is_active?: boolean | null + name?: string + organization_id?: string + } + Relationships: [ + { + foreignKeyName: "document_types_organization_id_fkey" + columns: ["organization_id"] + isOneToOne: false + referencedRelation: "organizations" + referencedColumns: ["id"] + }, + ] + } documents_dolceamore: { Row: { content: string | null @@ -1275,6 +1904,7 @@ export type Database = { created_at: string | null id: string organization_id: string + secure_share_webhook_url: string | null updated_at: string | null webhook_url: string } @@ -1282,6 +1912,7 @@ export type Database = { created_at?: string | null id?: string organization_id: string + secure_share_webhook_url?: string | null updated_at?: string | null webhook_url: string } @@ -1289,6 +1920,7 @@ export type Database = { created_at?: string | null id?: string organization_id?: string + secure_share_webhook_url?: string | null updated_at?: string | null webhook_url?: string } @@ -1302,6 +1934,233 @@ export type Database = { }, ] } + dre_goal_achievements: { + Row: { + accounts_payable_id: string | null + achieved: boolean | null + actual_profit: number | null + created_at: string + goal_id: string | null + id: string + organization_id: string + payable_created_at: string | null + payable_created_by: string | null + reward_amount: number | null + target_profit: number | null + unit_id: string | null + updated_at: string + year: number + } + Insert: { + accounts_payable_id?: string | null + achieved?: boolean | null + actual_profit?: number | null + created_at?: string + goal_id?: string | null + id?: string + organization_id: string + payable_created_at?: string | null + payable_created_by?: string | null + reward_amount?: number | null + target_profit?: number | null + unit_id?: string | null + updated_at?: string + year: number + } + Update: { + accounts_payable_id?: string | null + achieved?: boolean | null + actual_profit?: number | null + created_at?: string + goal_id?: string | null + id?: string + organization_id?: string + payable_created_at?: string | null + payable_created_by?: string | null + reward_amount?: number | null + target_profit?: number | null + unit_id?: string | null + updated_at?: string + year?: number + } + Relationships: [ + { + foreignKeyName: "dre_goal_achievements_accounts_payable_id_fkey" + columns: ["accounts_payable_id"] + isOneToOne: false + referencedRelation: "accounts_payable" + referencedColumns: ["id"] + }, + { + foreignKeyName: "dre_goal_achievements_goal_id_fkey" + columns: ["goal_id"] + isOneToOne: false + referencedRelation: "dre_profit_goals" + referencedColumns: ["id"] + }, + { + foreignKeyName: "dre_goal_achievements_organization_id_fkey" + columns: ["organization_id"] + isOneToOne: false + referencedRelation: "organizations" + referencedColumns: ["id"] + }, + { + foreignKeyName: "dre_goal_achievements_unit_id_fkey" + columns: ["unit_id"] + isOneToOne: false + referencedRelation: "units" + referencedColumns: ["id"] + }, + ] + } + dre_manual_entries: { + Row: { + amount: number + chart_of_account_id: number + created_at: string | null + id: string + month: number + organization_id: string + unit_id: string + year: number + } + Insert: { + amount?: number + chart_of_account_id: number + created_at?: string | null + id?: string + month: number + organization_id: string + unit_id: string + year: number + } + Update: { + amount?: number + chart_of_account_id?: number + created_at?: string | null + id?: string + month?: number + organization_id?: string + unit_id?: string + year?: number + } + Relationships: [ + { + foreignKeyName: "dre_manual_entries_chart_of_account_id_fkey" + columns: ["chart_of_account_id"] + isOneToOne: false + referencedRelation: "chart_of_accounts" + referencedColumns: ["id"] + }, + { + foreignKeyName: "dre_manual_entries_organization_id_fkey" + columns: ["organization_id"] + isOneToOne: false + referencedRelation: "organizations" + referencedColumns: ["id"] + }, + { + foreignKeyName: "dre_manual_entries_unit_id_fkey" + columns: ["unit_id"] + isOneToOne: false + referencedRelation: "units" + referencedColumns: ["id"] + }, + ] + } + dre_profit_goals: { + Row: { + created_at: string + id: string + level: string + max_value: number | null + min_value: number + organization_id: string + payable_chart_account_id: number | null + payable_default_vendor_id: string | null + payable_due_day: number | null + payable_due_days: number | null + payable_due_rule: string | null + payable_enabled: boolean | null + reward_type: string + reward_value: number + target_type: string | null + unit_id: string | null + updated_at: string + year: number + } + Insert: { + created_at?: string + id?: string + level: string + max_value?: number | null + min_value: number + organization_id: string + payable_chart_account_id?: number | null + payable_default_vendor_id?: string | null + payable_due_day?: number | null + payable_due_days?: number | null + payable_due_rule?: string | null + payable_enabled?: boolean | null + reward_type: string + reward_value: number + target_type?: string | null + unit_id?: string | null + updated_at?: string + year: number + } + Update: { + created_at?: string + id?: string + level?: string + max_value?: number | null + min_value?: number + organization_id?: string + payable_chart_account_id?: number | null + payable_default_vendor_id?: string | null + payable_due_day?: number | null + payable_due_days?: number | null + payable_due_rule?: string | null + payable_enabled?: boolean | null + reward_type?: string + reward_value?: number + target_type?: string | null + unit_id?: string | null + updated_at?: string + year?: number + } + Relationships: [ + { + foreignKeyName: "dre_profit_goals_organization_id_fkey" + columns: ["organization_id"] + isOneToOne: false + referencedRelation: "organizations" + referencedColumns: ["id"] + }, + { + foreignKeyName: "dre_profit_goals_payable_chart_account_id_fkey" + columns: ["payable_chart_account_id"] + isOneToOne: false + referencedRelation: "chart_of_accounts" + referencedColumns: ["id"] + }, + { + foreignKeyName: "dre_profit_goals_payable_default_vendor_id_fkey" + columns: ["payable_default_vendor_id"] + isOneToOne: false + referencedRelation: "people" + referencedColumns: ["id"] + }, + { + foreignKeyName: "dre_profit_goals_unit_id_fkey" + columns: ["unit_id"] + isOneToOne: false + referencedRelation: "units" + referencedColumns: ["id"] + }, + ] + } faixas_dre: { Row: { ativo: boolean | null @@ -1464,6 +2323,101 @@ export type Database = { }, ] } + financial_closing_shares: { + Row: { + access_code: string + closing_id: string + created_at: string | null + created_by: string | null + expires_at: string | null + id: string + organization_id: string + share_token: string + views_count: number | null + } + Insert: { + access_code: string + closing_id: string + created_at?: string | null + created_by?: string | null + expires_at?: string | null + id?: string + organization_id: string + share_token?: string + views_count?: number | null + } + Update: { + access_code?: string + closing_id?: string + created_at?: string | null + created_by?: string | null + expires_at?: string | null + id?: string + organization_id?: string + share_token?: string + views_count?: number | null + } + Relationships: [ + { + foreignKeyName: "financial_closing_shares_closing_id_fkey" + columns: ["closing_id"] + isOneToOne: false + referencedRelation: "financial_closings" + referencedColumns: ["id"] + }, + { + foreignKeyName: "financial_closing_shares_organization_id_fkey" + columns: ["organization_id"] + isOneToOne: false + referencedRelation: "organizations" + referencedColumns: ["id"] + }, + ] + } + financial_closings: { + Row: { + created_at: string | null + id: string + net_profit: number | null + reference_date: string + status: string | null + total_expenses: number | null + total_revenue: number | null + unit_id: string + user_id: string | null + } + Insert: { + created_at?: string | null + id?: string + net_profit?: number | null + reference_date: string + status?: string | null + total_expenses?: number | null + total_revenue?: number | null + unit_id: string + user_id?: string | null + } + Update: { + created_at?: string | null + id?: string + net_profit?: number | null + reference_date?: string + status?: string | null + total_expenses?: number | null + total_revenue?: number | null + unit_id?: string + user_id?: string | null + } + Relationships: [ + { + foreignKeyName: "financial_closings_unit_id_fkey" + columns: ["unit_id"] + isOneToOne: false + referencedRelation: "units" + referencedColumns: ["id"] + }, + ] + } grupos_whatsapp: { Row: { created_at: string | null @@ -1819,31 +2773,100 @@ export type Database = { } Relationships: [] } + notifications: { + Row: { + content: string + created_at: string | null + created_by: string | null + dedupe_key: string | null + entity_id: string | null + entity_type: string | null + id: string + is_read: boolean + link: string | null + organization_id: string + title: string + type: string + unit_id: string | null + user_id: string + } + Insert: { + content: string + created_at?: string | null + created_by?: string | null + dedupe_key?: string | null + entity_id?: string | null + entity_type?: string | null + id?: string + is_read?: boolean + link?: string | null + organization_id: string + title: string + type: string + unit_id?: string | null + user_id: string + } + Update: { + content?: string + created_at?: string | null + created_by?: string | null + dedupe_key?: string | null + entity_id?: string | null + entity_type?: string | null + id?: string + is_read?: boolean + link?: string | null + organization_id?: string + title?: string + type?: string + unit_id?: string | null + user_id?: string + } + Relationships: [ + { + foreignKeyName: "notifications_organization_id_fkey" + columns: ["organization_id"] + isOneToOne: false + referencedRelation: "organizations" + referencedColumns: ["id"] + }, + { + foreignKeyName: "notifications_unit_id_fkey" + columns: ["unit_id"] + isOneToOne: false + referencedRelation: "units" + referencedColumns: ["id"] + }, + ] + } organization_members: { Row: { + can_delete_transactions: boolean | null created_at: string | null id: number is_super_admin: boolean organization_id: string - role: Database["public"]["Enums"]["organization_role"] | null + role: string | null status: Database["public"]["Enums"]["member_status"] user_id: string } Insert: { + can_delete_transactions?: boolean | null created_at?: string | null id?: number is_super_admin?: boolean organization_id: string - role?: Database["public"]["Enums"]["organization_role"] | null + role?: string | null status?: Database["public"]["Enums"]["member_status"] user_id: string } Update: { + can_delete_transactions?: boolean | null created_at?: string | null id?: number is_super_admin?: boolean organization_id?: string - role?: Database["public"]["Enums"]["organization_role"] | null + role?: string | null status?: Database["public"]["Enums"]["member_status"] user_id?: string } @@ -1859,22 +2882,40 @@ export type Database = { } organizations: { Row: { + approval_webhook_url: string | null created_at: string | null id: string + logo_url: string | null name: string owner_id: string + radar_notification_day: number | null + radar_notification_time: string | null + radar_notification_webhook: string | null + webhook_url: string | null } Insert: { + approval_webhook_url?: string | null created_at?: string | null id?: string + logo_url?: string | null name: string owner_id: string + radar_notification_day?: number | null + radar_notification_time?: string | null + radar_notification_webhook?: string | null + webhook_url?: string | null } Update: { + approval_webhook_url?: string | null created_at?: string | null id?: string + logo_url?: string | null name?: string owner_id?: string + radar_notification_day?: number | null + radar_notification_time?: string | null + radar_notification_webhook?: string | null + webhook_url?: string | null } Relationships: [] } @@ -2058,24 +3099,72 @@ export type Database = { } profiles: { Row: { + avatar_url: string | null + can_lead_one_on_one: boolean | null document_number: string | null + email: string | null full_name: string | null id: string + phone: string | null + username: string | null + website: string | null } Insert: { + avatar_url?: string | null + can_lead_one_on_one?: boolean | null document_number?: string | null + email?: string | null full_name?: string | null id: string + phone?: string | null + username?: string | null + website?: string | null } Update: { + avatar_url?: string | null + can_lead_one_on_one?: boolean | null document_number?: string | null + email?: string | null full_name?: string | null id?: string + phone?: string | null + username?: string | null + website?: string | null } Relationships: [] } + role_menu_permissions: { + Row: { + created_at: string | null + id: string + menu_path: string + role_id: string + } + Insert: { + created_at?: string | null + id?: string + menu_path: string + role_id: string + } + Update: { + created_at?: string | null + id?: string + menu_path?: string + role_id?: string + } + Relationships: [ + { + foreignKeyName: "role_menu_permissions_role_id_fkey" + columns: ["role_id"] + isOneToOne: false + referencedRelation: "roles" + referencedColumns: ["id"] + }, + ] + } roles: { Row: { + can_confer_payments: boolean | null created_at: string | null description: string | null id: string @@ -2085,6 +3174,7 @@ export type Database = { updated_at: string | null } Insert: { + can_confer_payments?: boolean | null created_at?: string | null description?: string | null id?: string @@ -2094,6 +3184,7 @@ export type Database = { updated_at?: string | null } Update: { + can_confer_payments?: boolean | null created_at?: string | null description?: string | null id?: string @@ -2215,29 +3306,227 @@ export type Database = { }, ] } + transaction_comments: { + Row: { + batch_id: string | null + batch_item_id: string | null + content: string + created_at: string | null + id: string + organization_id: string + payable_id: string + reply_to_comment_id: string | null + source: string + unit_id: string | null + user_id: string | null + } + Insert: { + batch_id?: string | null + batch_item_id?: string | null + content: string + created_at?: string | null + id?: string + organization_id: string + payable_id: string + reply_to_comment_id?: string | null + source: string + unit_id?: string | null + user_id?: string | null + } + Update: { + batch_id?: string | null + batch_item_id?: string | null + content?: string + created_at?: string | null + id?: string + organization_id?: string + payable_id?: string + reply_to_comment_id?: string | null + source?: string + unit_id?: string | null + user_id?: string | null + } + Relationships: [ + { + foreignKeyName: "transaction_comments_batch_id_fkey" + columns: ["batch_id"] + isOneToOne: false + referencedRelation: "approval_batches" + referencedColumns: ["id"] + }, + { + foreignKeyName: "transaction_comments_batch_item_id_fkey" + columns: ["batch_item_id"] + isOneToOne: false + referencedRelation: "approval_items" + referencedColumns: ["id"] + }, + { + foreignKeyName: "transaction_comments_organization_id_fkey" + columns: ["organization_id"] + isOneToOne: false + referencedRelation: "organizations" + referencedColumns: ["id"] + }, + { + foreignKeyName: "transaction_comments_payable_id_fkey" + columns: ["payable_id"] + isOneToOne: false + referencedRelation: "accounts_payable" + referencedColumns: ["id"] + }, + { + foreignKeyName: "transaction_comments_reply_to_comment_id_fkey" + columns: ["reply_to_comment_id"] + isOneToOne: false + referencedRelation: "transaction_comments" + referencedColumns: ["id"] + }, + { + foreignKeyName: "transaction_comments_unit_id_fkey" + columns: ["unit_id"] + isOneToOne: false + referencedRelation: "units" + referencedColumns: ["id"] + }, + ] + } + unit_partners: { + Row: { + created_at: string | null + email: string | null + id: string + name: string + percentage: number + phone: string | null + unit_id: string + } + Insert: { + created_at?: string | null + email?: string | null + id?: string + name: string + percentage: number + phone?: string | null + unit_id: string + } + Update: { + created_at?: string | null + email?: string | null + id?: string + name?: string + percentage?: number + phone?: string | null + unit_id?: string + } + Relationships: [ + { + foreignKeyName: "unit_partners_unit_id_fkey" + columns: ["unit_id"] + isOneToOne: false + referencedRelation: "units" + referencedColumns: ["id"] + }, + ] + } + unit_rankings: { + Row: { + consumption_pct: number | null + created_at: string | null + expense_goal: number | null + id: string + month: string + occupancy_rate: number | null + sales_goal_pct: number | null + unit_id: string + updated_at: string | null + } + Insert: { + consumption_pct?: number | null + created_at?: string | null + expense_goal?: number | null + id?: string + month: string + occupancy_rate?: number | null + sales_goal_pct?: number | null + unit_id: string + updated_at?: string | null + } + Update: { + consumption_pct?: number | null + created_at?: string | null + expense_goal?: number | null + id?: string + month?: string + occupancy_rate?: number | null + sales_goal_pct?: number | null + unit_id?: string + updated_at?: string | null + } + Relationships: [ + { + foreignKeyName: "unit_rankings_unit_id_fkey" + columns: ["unit_id"] + isOneToOne: false + referencedRelation: "units" + referencedColumns: ["id"] + }, + ] + } units: { Row: { address: string | null created_at: string | null + distribution_webhook_url: string | null + enable_payment_conference: boolean | null id: string + last_radar_notification_sent_at: string | null + leader_id: string | null + leader_whatsapp: string | null name: string organization_id: string + radar_notification_day: number | null + radar_notification_time: string | null + radar_notification_webhook: string | null } Insert: { address?: string | null created_at?: string | null + distribution_webhook_url?: string | null + enable_payment_conference?: boolean | null id?: string + last_radar_notification_sent_at?: string | null + leader_id?: string | null + leader_whatsapp?: string | null name: string organization_id: string + radar_notification_day?: number | null + radar_notification_time?: string | null + radar_notification_webhook?: string | null } Update: { address?: string | null created_at?: string | null + distribution_webhook_url?: string | null + enable_payment_conference?: boolean | null id?: string + last_radar_notification_sent_at?: string | null + leader_id?: string | null + leader_whatsapp?: string | null name?: string organization_id?: string + radar_notification_day?: number | null + radar_notification_time?: string | null + radar_notification_webhook?: string | null } Relationships: [ + { + foreignKeyName: "units_leader_id_fkey" + columns: ["leader_id"] + isOneToOne: false + referencedRelation: "profiles" + referencedColumns: ["id"] + }, { foreignKeyName: "units_organization_id_fkey" columns: ["organization_id"] @@ -2369,7 +3658,7 @@ export type Database = { } Functions: { accept_invitation: { - Args: { invitation_id: string; user_id: string } + Args: { p_invitation_id: string; p_user_id: string } Returns: Json } autenticar_usuario: { @@ -2386,6 +3675,46 @@ export type Database = { }[] } expire_old_invitations: { Args: never; Returns: undefined } + generate_bill_months: { + Args: { bill_id: string; target_year: number } + Returns: undefined + } + get_atlas_accuracy_trend: { + Args: { p_organization_id: string } + Returns: { + accepted_count: number + accuracy_rate: number + month_label: string + total_count: number + }[] + } + get_atlas_mismatches: { + Args: { p_limit?: number; p_organization_id: string } + Returns: { + actual_account_name: string + avg_confidence: number + description: string + occurrence_count: number + suggested_account_name: string + }[] + } + get_atlas_overview_stats: { + Args: { p_organization_id: string } + Returns: { + acceptance_rate: number + accepted_suggestions: number + avg_confidence: number + estimated_time_saved_minutes: number + total_suggestions: number + }[] + } + get_auth_user_organization_id: { Args: never; Returns: string } + get_auth_user_organization_ids: { + Args: never + Returns: { + organization_id: string + }[] + } get_cash_flow_data_with_comparison: { Args: { p_month: number; p_year: number } Returns: { @@ -2403,6 +3732,14 @@ export type Database = { realized_total: number }[] } + get_cash_flow_summary: { + Args: { p_year: number } + Returns: { + chart_of_account_id: number + month: number + total_amount: number + }[] + } get_dre_data_with_comparison: { Args: { p_month: number; p_year: number } Returns: { @@ -2465,6 +3802,69 @@ export type Database = { token: string }[] } + get_my_time_records: { + Args: { p_clerk_id: string; p_end_date: string; p_start_date: string } + Returns: { + created_at: string + id: string + is_valid_location: boolean + latitude: number + longitude: number + photo_url: string + record_timestamp: string + record_type: string + }[] + } + get_my_time_records_with_justifications: { + Args: { p_clerk_id: string; p_end_date: string; p_start_date: string } + Returns: { + address: string + custom_reason: string + deviation_minutes: number + id: string + is_valid_location: boolean + justification_id: string + justification_type: string + latitude: number + longitude: number + photo_url: string + reason_text: string + record_timestamp: string + record_type: string + }[] + } + get_orgs_to_notify_radar: { + Args: never + Returns: { + id: string + name: string + radar_notification_day: number + radar_notification_time: string + radar_notification_webhook: string + }[] + } + get_previous_balance: { + Args: { + p_bank_account_id?: string + p_date: string + p_organization_id: string + p_payment_method_id?: string + p_unit_id?: string + } + Returns: number + } + get_top_growing_expenses: { + Args: { p_ref_date: string; p_unit_id: string } + Returns: { + account_id: number + account_name: string + current_value: number + growth_diff: number + last_year_value: number + prev_value: number + }[] + } + is_admin_of_org: { Args: { org_id: string }; Returns: boolean } match_documents_dolceamore: { Args: { match_count?: number @@ -2478,7 +3878,24 @@ export type Database = { similarity: number }[] } + migrate_chart_of_account: { + Args: { + p_organization_id: string + p_source_account_id: number + p_target_account_id: number + } + Returns: Json + } registrar_usuario: + | { + Args: { + email: string + empresa: string + nome: string + senha: string + } + Returns: string + } | { Args: { email: string @@ -2489,15 +3906,10 @@ export type Database = { } Returns: string } - | { - Args: { - email: string - empresa: string - nome: string - senha: string - } - Returns: string - } + sync_radar_status: { + Args: { target_bill_id?: string; target_org_id?: string } + Returns: undefined + } } Enums: { bank_type: "banco_inter" | "stone" diff --git a/supabase/config.toml b/supabase/config.toml index 08e019c..01c4b92 100644 --- a/supabase/config.toml +++ b/supabase/config.toml @@ -44,3 +44,6 @@ verify_jwt = false [functions.update-register-function-sql] verify_jwt = false + +[functions.avisos-financeiros] +verify_jwt = false diff --git a/supabase/functions/avisos-financeiros/index.ts b/supabase/functions/avisos-financeiros/index.ts index 750db01..2b1b76c 100644 --- a/supabase/functions/avisos-financeiros/index.ts +++ b/supabase/functions/avisos-financeiros/index.ts @@ -91,11 +91,14 @@ serve(async (req) => { console.log(`Dias restantes: ${diasRestantes}`) console.log(`Hora atual: ${horaAtualBrasilia}, Hora aviso: ${conta.hora_aviso}`) + // Normalizar hora_aviso para comparação (pode vir como "09:00:00" do banco) + const horaAvisoNormalizada = conta.hora_aviso ? conta.hora_aviso.substring(0, 5) : '' + // Verificar se deve enviar aviso // Enviar aviso nos dias de antecedência E no dia do vencimento const deveEnviarAviso = ( (diasRestantes <= conta.dias_antecedencia && diasRestantes >= 0) && - horaAtualBrasilia === conta.hora_aviso + horaAtualBrasilia === horaAvisoNormalizada ) console.log(`Deve enviar aviso: ${deveEnviarAviso}`)