Compare commits
2 commits
c9e948b8dd
...
92aa1cb2bb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
92aa1cb2bb | ||
|
|
cc49e676ca |
8 changed files with 7487 additions and 28 deletions
|
|
@ -11,7 +11,7 @@
|
|||
"buildType": "apk"
|
||||
},
|
||||
"env": {
|
||||
"EXPO_PUBLIC_API_URL": "https://toptran.olymp.com.br"
|
||||
"EXPO_PUBLIC_API_URL": "https://toptran.olymp.com.br/api"
|
||||
}
|
||||
},
|
||||
"preview": {
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
"buildType": "apk"
|
||||
},
|
||||
"env": {
|
||||
"EXPO_PUBLIC_API_URL": "https://toptran.olymp.com.br"
|
||||
"EXPO_PUBLIC_API_URL": "https://toptran.olymp.com.br/api"
|
||||
}
|
||||
},
|
||||
"production": {
|
||||
|
|
@ -29,7 +29,7 @@
|
|||
"buildType": "app-bundle"
|
||||
},
|
||||
"env": {
|
||||
"EXPO_PUBLIC_API_URL": "https://toptran.olymp.com.br"
|
||||
"EXPO_PUBLIC_API_URL": "https://toptran.olymp.com.br/api"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -2,4 +2,17 @@ const { getDefaultConfig } = require('expo/metro-config');
|
|||
|
||||
const config = getDefaultConfig(__dirname);
|
||||
|
||||
config.resolver.assetExts.push('wasm');
|
||||
|
||||
config.server = {
|
||||
...config.server,
|
||||
enhanceMiddleware: (middleware) => {
|
||||
return (req, res, next) => {
|
||||
res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');
|
||||
res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp');
|
||||
return middleware(req, res, next);
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = config;
|
||||
|
|
|
|||
7372
toptran-app/package-lock.json
generated
7372
toptran-app/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -38,6 +38,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "~19.2.10",
|
||||
"expo-module-scripts": "^55.0.2",
|
||||
"react-test-renderer": "19.1.0",
|
||||
"typescript": "~5.9.2"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -346,7 +346,7 @@ const styles = StyleSheet.create({
|
|||
borderColor: COLORS.borderLight,
|
||||
},
|
||||
statValue: {
|
||||
fontSize: 20,
|
||||
fontSize: 18,
|
||||
fontWeight: "800",
|
||||
color: COLORS.text,
|
||||
marginBottom: 2,
|
||||
|
|
|
|||
|
|
@ -31,7 +31,10 @@ function getMonthOptions() {
|
|||
return Array.from({ length: 12 }, (_, i) => {
|
||||
const d = new Date(now.getFullYear(), now.getMonth() - i, 1);
|
||||
const value = `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}`;
|
||||
const label = d.toLocaleDateString("pt-BR", { month: "long", year: "numeric" });
|
||||
const label = d.toLocaleDateString("pt-BR", {
|
||||
month: "long",
|
||||
year: "numeric",
|
||||
});
|
||||
return { value, label: label.charAt(0).toUpperCase() + label.slice(1) };
|
||||
});
|
||||
}
|
||||
|
|
@ -60,7 +63,12 @@ type CompanyReport = { name: string; rides: number; km: number; total: number };
|
|||
function buildCompanyReports(rides: RideDB[]): CompanyReport[] {
|
||||
const map = new Map<string, CompanyReport>();
|
||||
for (const r of rides) {
|
||||
const prev = map.get(r.company) ?? { name: r.company, rides: 0, km: 0, total: 0 };
|
||||
const prev = map.get(r.company) ?? {
|
||||
name: r.company,
|
||||
rides: 0,
|
||||
km: 0,
|
||||
total: 0,
|
||||
};
|
||||
map.set(r.company, {
|
||||
...prev,
|
||||
rides: prev.rides + 1,
|
||||
|
|
@ -109,8 +117,10 @@ function buildPdfHtml(
|
|||
)
|
||||
.join("");
|
||||
|
||||
const generated = new Date().toLocaleDateString("pt-BR") +
|
||||
" às " + new Date().toLocaleTimeString("pt-BR");
|
||||
const generated =
|
||||
new Date().toLocaleDateString("pt-BR") +
|
||||
" às " +
|
||||
new Date().toLocaleTimeString("pt-BR");
|
||||
|
||||
return `<!DOCTYPE html>
|
||||
<html><head>
|
||||
|
|
@ -145,9 +155,11 @@ function buildPdfHtml(
|
|||
</head>
|
||||
<body>
|
||||
<div class="header">
|
||||
${logoSrc
|
||||
? `<img class="logo" src="${logoSrc}" alt="TopTran"/>`
|
||||
: `<span class="logo-text">TopTran</span>`}
|
||||
${
|
||||
logoSrc
|
||||
? `<img class="logo" src="${logoSrc}" alt="TopTran"/>`
|
||||
: `<span class="logo-text">TopTran</span>`
|
||||
}
|
||||
<div class="header-info">
|
||||
<h2>Relatório de Corridas</h2>
|
||||
<p>${monthLabel}</p>
|
||||
|
|
@ -219,11 +231,16 @@ export default function RelatorioPage() {
|
|||
const companies = buildCompanyReports(rides);
|
||||
const totalKm = rides.reduce((s, r) => s + r.km, 0);
|
||||
const totalEarnings = rides.reduce((s, r) => s + r.total, 0);
|
||||
const monthLabel = MONTH_OPTIONS.find((o) => o.value === selectedMonth)?.label ?? selectedMonth;
|
||||
const monthLabel =
|
||||
MONTH_OPTIONS.find((o) => o.value === selectedMonth)?.label ??
|
||||
selectedMonth;
|
||||
|
||||
const handleExport = async () => {
|
||||
if (rides.length === 0) {
|
||||
Alert.alert("Sem dados", "Não há corridas registradas em " + monthLabel + ".");
|
||||
Alert.alert(
|
||||
"Sem dados",
|
||||
"Não há corridas registradas em " + monthLabel + ".",
|
||||
);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
|
@ -253,13 +270,20 @@ export default function RelatorioPage() {
|
|||
return (
|
||||
<SafeAreaView style={styles.container}>
|
||||
<View style={styles.header}>
|
||||
<TouchableOpacity onPress={() => router.back()} style={styles.backButton} activeOpacity={0.7}>
|
||||
<TouchableOpacity
|
||||
onPress={() => router.back()}
|
||||
style={styles.backButton}
|
||||
activeOpacity={0.7}
|
||||
>
|
||||
<Text style={styles.backIcon}>←</Text>
|
||||
<Text style={styles.backLabel}>Voltar</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
|
||||
<ScrollView contentContainerStyle={styles.scroll} showsVerticalScrollIndicator={false}>
|
||||
<ScrollView
|
||||
contentContainerStyle={styles.scroll}
|
||||
showsVerticalScrollIndicator={false}
|
||||
>
|
||||
<View style={styles.titleSection}>
|
||||
<Text style={styles.title}>Relatório</Text>
|
||||
<Text style={styles.subtitle}>Análise de ganhos por período</Text>
|
||||
|
|
@ -268,7 +292,11 @@ export default function RelatorioPage() {
|
|||
{/* Filtro de mês */}
|
||||
<View style={styles.filterCard}>
|
||||
<Text style={styles.cardLabel}>Período</Text>
|
||||
<Select value={selectedMonth} onValueChange={setSelectedMonth} items={MONTH_OPTIONS} />
|
||||
<Select
|
||||
value={selectedMonth}
|
||||
onValueChange={setSelectedMonth}
|
||||
items={MONTH_OPTIONS}
|
||||
/>
|
||||
</View>
|
||||
|
||||
{/* Cards de resumo */}
|
||||
|
|
@ -294,7 +322,9 @@ export default function RelatorioPage() {
|
|||
|
||||
{companies.length === 0 ? (
|
||||
<View style={styles.emptyCard}>
|
||||
<Text style={styles.emptyText}>Nenhuma corrida em {monthLabel}.</Text>
|
||||
<Text style={styles.emptyText}>
|
||||
Nenhuma corrida em {monthLabel}.
|
||||
</Text>
|
||||
</View>
|
||||
) : (
|
||||
<>
|
||||
|
|
@ -308,7 +338,9 @@ export default function RelatorioPage() {
|
|||
</View>
|
||||
<View style={styles.companyStats}>
|
||||
<Text style={styles.companyKm}>{c.km.toFixed(1)} km</Text>
|
||||
<Text style={styles.companyTotal}>R$ {c.total.toFixed(2)}</Text>
|
||||
<Text style={styles.companyTotal}>
|
||||
R$ {c.total.toFixed(2)}
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
))}
|
||||
|
|
@ -319,7 +351,9 @@ export default function RelatorioPage() {
|
|||
</View>
|
||||
<View style={styles.companyStats}>
|
||||
<Text style={styles.companyKm}>{totalKm.toFixed(1)} km</Text>
|
||||
<Text style={styles.totalAmount}>R$ {totalEarnings.toFixed(2)}</Text>
|
||||
<Text style={styles.totalAmount}>
|
||||
R$ {totalEarnings.toFixed(2)}
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
</>
|
||||
|
|
@ -327,7 +361,10 @@ export default function RelatorioPage() {
|
|||
|
||||
{/* Botão exportar */}
|
||||
<TouchableOpacity
|
||||
style={[styles.exportButton, exporting && styles.exportButtonDisabled]}
|
||||
style={[
|
||||
styles.exportButton,
|
||||
exporting && styles.exportButtonDisabled,
|
||||
]}
|
||||
onPress={handleExport}
|
||||
disabled={exporting}
|
||||
activeOpacity={0.85}
|
||||
|
|
@ -364,7 +401,12 @@ const styles = StyleSheet.create({
|
|||
scroll: { padding: SPACING.lg, paddingBottom: 48 },
|
||||
|
||||
titleSection: { marginTop: SPACING.md, marginBottom: SPACING.xl },
|
||||
title: { fontSize: 28, fontWeight: "800", color: COLORS.text, marginBottom: 4 },
|
||||
title: {
|
||||
fontSize: 28,
|
||||
fontWeight: "800",
|
||||
color: COLORS.text,
|
||||
marginBottom: 4,
|
||||
},
|
||||
subtitle: { fontSize: 14, color: COLORS.textTertiary },
|
||||
|
||||
filterCard: {
|
||||
|
|
@ -384,7 +426,11 @@ const styles = StyleSheet.create({
|
|||
marginBottom: SPACING.sm,
|
||||
},
|
||||
|
||||
summaryRow: { flexDirection: "row", gap: SPACING.sm, marginBottom: SPACING.xl },
|
||||
summaryRow: {
|
||||
flexDirection: "row",
|
||||
gap: SPACING.sm,
|
||||
marginBottom: SPACING.xl,
|
||||
},
|
||||
summaryCard: {
|
||||
flex: 1,
|
||||
backgroundColor: COLORS.surface,
|
||||
|
|
@ -395,7 +441,12 @@ const styles = StyleSheet.create({
|
|||
alignItems: "center",
|
||||
},
|
||||
summaryCardAccent: { borderColor: COLORS.success },
|
||||
summaryValue: { fontSize: 20, fontWeight: "800", color: COLORS.text, marginBottom: 2 },
|
||||
summaryValue: {
|
||||
fontSize: 18,
|
||||
fontWeight: "800",
|
||||
color: COLORS.text,
|
||||
marginBottom: 2,
|
||||
},
|
||||
summaryValueAccent: { color: COLORS.success },
|
||||
summaryLabel: {
|
||||
fontSize: 10,
|
||||
|
|
@ -449,7 +500,11 @@ const styles = StyleSheet.create({
|
|||
borderRadius: BORDER_RADIUS.sm,
|
||||
overflow: "hidden",
|
||||
},
|
||||
companyStats: { flexDirection: "row", justifyContent: "space-between", alignItems: "center" },
|
||||
companyStats: {
|
||||
flexDirection: "row",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
},
|
||||
companyKm: { fontSize: 13, color: COLORS.textSecondary },
|
||||
companyTotal: { fontSize: 18, fontWeight: "800", color: COLORS.text },
|
||||
|
||||
|
|
@ -473,5 +528,9 @@ const styles = StyleSheet.create({
|
|||
alignItems: "center",
|
||||
},
|
||||
exportButtonDisabled: { backgroundColor: COLORS.borderLight },
|
||||
exportButtonText: { fontSize: 15, fontWeight: "700", color: COLORS.background },
|
||||
exportButtonText: {
|
||||
fontSize: 15,
|
||||
fontWeight: "700",
|
||||
color: COLORS.background,
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import * as SQLite from "expo-sqlite";
|
||||
|
||||
const db = SQLite.openDatabaseSync("toptran.db");
|
||||
const dbPromise = SQLite.openDatabaseAsync("toptran.db");
|
||||
|
||||
export type UserDB = {
|
||||
id: string;
|
||||
|
|
@ -32,6 +32,7 @@ export type CompanyDB = {
|
|||
|
||||
export const initDB = async () => {
|
||||
try {
|
||||
const db = await dbPromise;
|
||||
await db.execAsync(
|
||||
`CREATE TABLE IF NOT EXISTS users (
|
||||
id TEXT PRIMARY KEY,
|
||||
|
|
@ -79,6 +80,7 @@ export const initDB = async () => {
|
|||
// SETTINGS (key-value store)
|
||||
export const getSetting = async (key: string): Promise<string | null> => {
|
||||
try {
|
||||
const db = await dbPromise;
|
||||
const row = await db.getFirstAsync<{ value: string }>(
|
||||
`SELECT value FROM settings WHERE key = ?`,
|
||||
[key],
|
||||
|
|
@ -92,6 +94,7 @@ export const getSetting = async (key: string): Promise<string | null> => {
|
|||
|
||||
export const setSetting = async (key: string, value: string): Promise<void> => {
|
||||
try {
|
||||
const db = await dbPromise;
|
||||
await db.runAsync(
|
||||
`INSERT OR REPLACE INTO settings (key, value) VALUES (?, ?)`,
|
||||
[key, value],
|
||||
|
|
@ -104,6 +107,7 @@ export const setSetting = async (key: string, value: string): Promise<void> => {
|
|||
|
||||
export const deleteSetting = async (key: string): Promise<void> => {
|
||||
try {
|
||||
const db = await dbPromise;
|
||||
await db.runAsync(`DELETE FROM settings WHERE key = ?`, [key]);
|
||||
} catch (error) {
|
||||
console.error("Error deleting setting:", error);
|
||||
|
|
@ -116,6 +120,7 @@ export const salvarUsuario = async (
|
|||
usuario: Omit<UserDB, "createdAt">,
|
||||
): Promise<string> => {
|
||||
try {
|
||||
const db = await dbPromise;
|
||||
const existing = await db.getFirstAsync<{ id: string }>(
|
||||
`SELECT id FROM users WHERE email = ?`,
|
||||
[usuario.email],
|
||||
|
|
@ -156,6 +161,7 @@ export const obterUsuario = async (
|
|||
usuarioId: string,
|
||||
): Promise<UserDB | null> => {
|
||||
try {
|
||||
const db = await dbPromise;
|
||||
const result = await db.getFirstAsync<UserDB>(
|
||||
`SELECT * FROM users WHERE id = ?`,
|
||||
[usuarioId],
|
||||
|
|
@ -170,6 +176,7 @@ export const obterUsuario = async (
|
|||
// RIDES
|
||||
export const salvarCorrida = async (corrida: Omit<RideDB, "createdAt">) => {
|
||||
try {
|
||||
const db = await dbPromise;
|
||||
const result = await db.runAsync(
|
||||
`INSERT INTO rides (id, user_id, company, km, cost_per_km, total, ride_date, synced)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
|
|
@ -195,6 +202,7 @@ export const obterCorridas = async (
|
|||
usuarioId: string,
|
||||
): Promise<RideDB[]> => {
|
||||
try {
|
||||
const db = await dbPromise;
|
||||
const result = await db.getAllAsync<RideDB>(
|
||||
`SELECT * FROM rides WHERE user_id = ? ORDER BY createdAt DESC`,
|
||||
[usuarioId],
|
||||
|
|
@ -210,6 +218,7 @@ export const obterCorridasNaoSincronizadas = async (
|
|||
usuarioId: string,
|
||||
): Promise<RideDB[]> => {
|
||||
try {
|
||||
const db = await dbPromise;
|
||||
const result = await db.getAllAsync<RideDB>(
|
||||
`SELECT * FROM rides WHERE user_id = ? AND synced = 0`,
|
||||
[usuarioId],
|
||||
|
|
@ -223,6 +232,7 @@ export const obterCorridasNaoSincronizadas = async (
|
|||
|
||||
export const marcarCorridaComoSincronizada = async (corridaId: string) => {
|
||||
try {
|
||||
const db = await dbPromise;
|
||||
await db.runAsync(`UPDATE rides SET synced = 1 WHERE id = ?`, [corridaId]);
|
||||
} catch (error) {
|
||||
console.error("Error marking ride as synced:", error);
|
||||
|
|
@ -232,6 +242,7 @@ export const marcarCorridaComoSincronizada = async (corridaId: string) => {
|
|||
|
||||
export const deletarCorrida = async (corridaId: string) => {
|
||||
try {
|
||||
const db = await dbPromise;
|
||||
await db.runAsync(`DELETE FROM rides WHERE id = ?`, [corridaId]);
|
||||
} catch (error) {
|
||||
console.error("Error deleting ride:", error);
|
||||
|
|
@ -241,6 +252,7 @@ export const deletarCorrida = async (corridaId: string) => {
|
|||
|
||||
export const limparBancoDados = async () => {
|
||||
try {
|
||||
const db = await dbPromise;
|
||||
await db.execAsync(`DELETE FROM rides; DELETE FROM users;`);
|
||||
console.log("Database cleared");
|
||||
} catch (error) {
|
||||
|
|
@ -252,6 +264,7 @@ export const limparBancoDados = async () => {
|
|||
// COMPANIES
|
||||
export const obterEmpresas = async (): Promise<CompanyDB[]> => {
|
||||
try {
|
||||
const db = await dbPromise;
|
||||
return (
|
||||
(await db.getAllAsync<CompanyDB>(
|
||||
`SELECT * FROM companies ORDER BY name ASC`,
|
||||
|
|
@ -267,6 +280,7 @@ export const salvarEmpresa = async (
|
|||
empresa: Omit<CompanyDB, "createdAt">,
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const db = await dbPromise;
|
||||
await db.runAsync(
|
||||
`INSERT INTO companies (id, name, cost_per_km, notes) VALUES (?, ?, ?, ?)`,
|
||||
[empresa.id, empresa.name, empresa.cost_per_km, empresa.notes],
|
||||
|
|
@ -281,6 +295,7 @@ export const upsertEmpresaLocal = async (
|
|||
empresa: Omit<CompanyDB, "createdAt">,
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const db = await dbPromise;
|
||||
await db.runAsync(
|
||||
`INSERT OR REPLACE INTO companies (id, name, cost_per_km, notes) VALUES (?, ?, ?, ?)`,
|
||||
[empresa.id, empresa.name, empresa.cost_per_km, empresa.notes],
|
||||
|
|
@ -295,6 +310,7 @@ export const upsertCorridaLocal = async (
|
|||
corrida: Omit<RideDB, "createdAt">,
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const db = await dbPromise;
|
||||
await db.runAsync(
|
||||
`INSERT OR REPLACE INTO rides (id, user_id, company, km, cost_per_km, total, ride_date, synced)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, 1)`,
|
||||
|
|
@ -310,6 +326,7 @@ export const atualizarEmpresa = async (
|
|||
empresa: Omit<CompanyDB, "createdAt">,
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const db = await dbPromise;
|
||||
await db.runAsync(
|
||||
`UPDATE companies SET name = ?, cost_per_km = ?, notes = ? WHERE id = ?`,
|
||||
[empresa.name, empresa.cost_per_km, empresa.notes, empresa.id],
|
||||
|
|
@ -322,6 +339,7 @@ export const atualizarEmpresa = async (
|
|||
|
||||
export const deletarEmpresa = async (id: string): Promise<void> => {
|
||||
try {
|
||||
const db = await dbPromise;
|
||||
await db.runAsync(`DELETE FROM companies WHERE id = ?`, [id]);
|
||||
} catch (error) {
|
||||
console.error("Error deleting company:", error);
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Add table
Reference in a new issue