Fix backend

This commit is contained in:
Rayan Konecny 2026-05-05 01:42:46 -03:00
parent cc49e676ca
commit 92aa1cb2bb
4 changed files with 84 additions and 25 deletions

View file

@ -11,7 +11,7 @@
"buildType": "apk" "buildType": "apk"
}, },
"env": { "env": {
"EXPO_PUBLIC_API_URL": "https://toptran.olymp.com.br" "EXPO_PUBLIC_API_URL": "https://toptran.olymp.com.br/api"
} }
}, },
"preview": { "preview": {
@ -20,7 +20,7 @@
"buildType": "apk" "buildType": "apk"
}, },
"env": { "env": {
"EXPO_PUBLIC_API_URL": "https://toptran.olymp.com.br" "EXPO_PUBLIC_API_URL": "https://toptran.olymp.com.br/api"
} }
}, },
"production": { "production": {
@ -29,7 +29,7 @@
"buildType": "app-bundle" "buildType": "app-bundle"
}, },
"env": { "env": {
"EXPO_PUBLIC_API_URL": "https://toptran.olymp.com.br" "EXPO_PUBLIC_API_URL": "https://toptran.olymp.com.br/api"
} }
} }
}, },

View file

@ -346,7 +346,7 @@ const styles = StyleSheet.create({
borderColor: COLORS.borderLight, borderColor: COLORS.borderLight,
}, },
statValue: { statValue: {
fontSize: 20, fontSize: 18,
fontWeight: "800", fontWeight: "800",
color: COLORS.text, color: COLORS.text,
marginBottom: 2, marginBottom: 2,

View file

@ -31,7 +31,10 @@ function getMonthOptions() {
return Array.from({ length: 12 }, (_, i) => { return Array.from({ length: 12 }, (_, i) => {
const d = new Date(now.getFullYear(), now.getMonth() - i, 1); const d = new Date(now.getFullYear(), now.getMonth() - i, 1);
const value = `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}`; 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) }; 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[] { function buildCompanyReports(rides: RideDB[]): CompanyReport[] {
const map = new Map<string, CompanyReport>(); const map = new Map<string, CompanyReport>();
for (const r of rides) { 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, { map.set(r.company, {
...prev, ...prev,
rides: prev.rides + 1, rides: prev.rides + 1,
@ -109,8 +117,10 @@ function buildPdfHtml(
) )
.join(""); .join("");
const generated = new Date().toLocaleDateString("pt-BR") + const generated =
" às " + new Date().toLocaleTimeString("pt-BR"); new Date().toLocaleDateString("pt-BR") +
" às " +
new Date().toLocaleTimeString("pt-BR");
return `<!DOCTYPE html> return `<!DOCTYPE html>
<html><head> <html><head>
@ -145,9 +155,11 @@ function buildPdfHtml(
</head> </head>
<body> <body>
<div class="header"> <div class="header">
${logoSrc ${
? `<img class="logo" src="${logoSrc}" alt="TopTran"/>` logoSrc
: `<span class="logo-text">TopTran</span>`} ? `<img class="logo" src="${logoSrc}" alt="TopTran"/>`
: `<span class="logo-text">TopTran</span>`
}
<div class="header-info"> <div class="header-info">
<h2>Relatório de Corridas</h2> <h2>Relatório de Corridas</h2>
<p>${monthLabel}</p> <p>${monthLabel}</p>
@ -219,11 +231,16 @@ export default function RelatorioPage() {
const companies = buildCompanyReports(rides); const companies = buildCompanyReports(rides);
const totalKm = rides.reduce((s, r) => s + r.km, 0); const totalKm = rides.reduce((s, r) => s + r.km, 0);
const totalEarnings = rides.reduce((s, r) => s + r.total, 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 () => { const handleExport = async () => {
if (rides.length === 0) { 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; return;
} }
try { try {
@ -253,13 +270,20 @@ export default function RelatorioPage() {
return ( return (
<SafeAreaView style={styles.container}> <SafeAreaView style={styles.container}>
<View style={styles.header}> <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.backIcon}></Text>
<Text style={styles.backLabel}>Voltar</Text> <Text style={styles.backLabel}>Voltar</Text>
</TouchableOpacity> </TouchableOpacity>
</View> </View>
<ScrollView contentContainerStyle={styles.scroll} showsVerticalScrollIndicator={false}> <ScrollView
contentContainerStyle={styles.scroll}
showsVerticalScrollIndicator={false}
>
<View style={styles.titleSection}> <View style={styles.titleSection}>
<Text style={styles.title}>Relatório</Text> <Text style={styles.title}>Relatório</Text>
<Text style={styles.subtitle}>Análise de ganhos por período</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 */} {/* Filtro de mês */}
<View style={styles.filterCard}> <View style={styles.filterCard}>
<Text style={styles.cardLabel}>Período</Text> <Text style={styles.cardLabel}>Período</Text>
<Select value={selectedMonth} onValueChange={setSelectedMonth} items={MONTH_OPTIONS} /> <Select
value={selectedMonth}
onValueChange={setSelectedMonth}
items={MONTH_OPTIONS}
/>
</View> </View>
{/* Cards de resumo */} {/* Cards de resumo */}
@ -294,7 +322,9 @@ export default function RelatorioPage() {
{companies.length === 0 ? ( {companies.length === 0 ? (
<View style={styles.emptyCard}> <View style={styles.emptyCard}>
<Text style={styles.emptyText}>Nenhuma corrida em {monthLabel}.</Text> <Text style={styles.emptyText}>
Nenhuma corrida em {monthLabel}.
</Text>
</View> </View>
) : ( ) : (
<> <>
@ -308,7 +338,9 @@ export default function RelatorioPage() {
</View> </View>
<View style={styles.companyStats}> <View style={styles.companyStats}>
<Text style={styles.companyKm}>{c.km.toFixed(1)} km</Text> <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>
</View> </View>
))} ))}
@ -319,7 +351,9 @@ export default function RelatorioPage() {
</View> </View>
<View style={styles.companyStats}> <View style={styles.companyStats}>
<Text style={styles.companyKm}>{totalKm.toFixed(1)} km</Text> <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>
</View> </View>
</> </>
@ -327,7 +361,10 @@ export default function RelatorioPage() {
{/* Botão exportar */} {/* Botão exportar */}
<TouchableOpacity <TouchableOpacity
style={[styles.exportButton, exporting && styles.exportButtonDisabled]} style={[
styles.exportButton,
exporting && styles.exportButtonDisabled,
]}
onPress={handleExport} onPress={handleExport}
disabled={exporting} disabled={exporting}
activeOpacity={0.85} activeOpacity={0.85}
@ -364,7 +401,12 @@ const styles = StyleSheet.create({
scroll: { padding: SPACING.lg, paddingBottom: 48 }, scroll: { padding: SPACING.lg, paddingBottom: 48 },
titleSection: { marginTop: SPACING.md, marginBottom: SPACING.xl }, 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 }, subtitle: { fontSize: 14, color: COLORS.textTertiary },
filterCard: { filterCard: {
@ -384,7 +426,11 @@ const styles = StyleSheet.create({
marginBottom: SPACING.sm, marginBottom: SPACING.sm,
}, },
summaryRow: { flexDirection: "row", gap: SPACING.sm, marginBottom: SPACING.xl }, summaryRow: {
flexDirection: "row",
gap: SPACING.sm,
marginBottom: SPACING.xl,
},
summaryCard: { summaryCard: {
flex: 1, flex: 1,
backgroundColor: COLORS.surface, backgroundColor: COLORS.surface,
@ -395,7 +441,12 @@ const styles = StyleSheet.create({
alignItems: "center", alignItems: "center",
}, },
summaryCardAccent: { borderColor: COLORS.success }, 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 }, summaryValueAccent: { color: COLORS.success },
summaryLabel: { summaryLabel: {
fontSize: 10, fontSize: 10,
@ -449,7 +500,11 @@ const styles = StyleSheet.create({
borderRadius: BORDER_RADIUS.sm, borderRadius: BORDER_RADIUS.sm,
overflow: "hidden", overflow: "hidden",
}, },
companyStats: { flexDirection: "row", justifyContent: "space-between", alignItems: "center" }, companyStats: {
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
},
companyKm: { fontSize: 13, color: COLORS.textSecondary }, companyKm: { fontSize: 13, color: COLORS.textSecondary },
companyTotal: { fontSize: 18, fontWeight: "800", color: COLORS.text }, companyTotal: { fontSize: 18, fontWeight: "800", color: COLORS.text },
@ -473,5 +528,9 @@ const styles = StyleSheet.create({
alignItems: "center", alignItems: "center",
}, },
exportButtonDisabled: { backgroundColor: COLORS.borderLight }, exportButtonDisabled: { backgroundColor: COLORS.borderLight },
exportButtonText: { fontSize: 15, fontWeight: "700", color: COLORS.background }, exportButtonText: {
fontSize: 15,
fontWeight: "700",
color: COLORS.background,
},
}); });

Binary file not shown.