Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reworked average calculator #18

Open
wants to merge 14 commits into
base: staging
Choose a base branch
from
17 changes: 17 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# If you use the docker-based dev environment, keep it commented
#DATABASE_URL=postgresql:/admin:admin@localhost:5432/admin

NEXT_PUBLIC_FRONTEND_URL=http://localhost:3000
NEXT_PUBLIC_GA_TRACKING_ID=REDACTED

LYDIA_API_VENDOR_ID=REDACTED
NEXT_PUBLIC_LYDIA_API_URL=REDACTED
NEXT_PUBLIC_LYDIA_API_VENDOR_TOKEN=REDACTED

SESSION_SECRET_KEY=generate_on_https://randomkeygen.com

[email protected]
SMTP_HOST=smtp.gmail.com
SMTP_PASSWORD=your_password
SMTP_PORT=587
SMTP_USER=your_user
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ lib-cov

.idea
.vercel

dev/.db-migrated
dev/data/db
dev/data/pg4admin
2 changes: 1 addition & 1 deletion app/components/auth/LoginForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState } from 'react'
import { TextField } from 'bde-isima-mui-rff'
import { TextField } from 'mui-rff'
import Typography from '@mui/material/Typography'
import { useMutation, AuthenticationError } from 'blitz'

Expand Down
2 changes: 1 addition & 1 deletion app/components/dashboard/articles/ArticleForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Image } from 'blitz'
import { TextField, Switches } from 'bde-isima-mui-rff'
import { TextField, Switches } from 'mui-rff'
import IconButton from '@mui/material/IconButton'
import InputAdornment from '@mui/material/InputAdornment'

Expand Down
91 changes: 91 additions & 0 deletions app/components/dashboard/articles/ExportArticles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import xlsx from 'xlsx'
import { useQuery } from 'blitz'
import Button from '@mui/material/Button'

import TableChartIcon from '@mui/icons-material/TableChart'
corentin703 marked this conversation as resolved.
Show resolved Hide resolved

import Box from '@mui/material/Box'
import CircularProgress from '@mui/material/CircularProgress'
import getArticlesWithStats from 'app/entities/articles/queries/getArticlesWithStats'

export default function ExportArticles() {
const [{ articles }] = useQuery(getArticlesWithStats, {})

const exportToExcel = () => {
const date = new Date()

const workBook = xlsx.utils.book_new()

workBook.Props = {
Title: 'BDE ISIMA - Utilisateurs',
Subject: 'Liste des utilisateurs',
CreatedDate: date,
}

workBook.SheetNames.push('Articles')

const workSheetData = [
[
'Nom',
'Prix',
'Prix cotisants',
'Visible',
'Ajouté le',
'Total ventes (semaine)',
'Total ventes (mois)',
'Total ventes (année)',
'Total ventes',
],
...articles.map((article) => [
article.name,
article.price,
article.member_price ?? article.price,
article.is_enabled ? 'Oui' : 'Non',
new Date(article.createdAt).toLocaleDateString('fr'),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je vais te faire un utilitaire ici pour format les dates, parce que je pense que c'est mieux de s'adapter à la locale du PC

article.weekCount ?? 0,
article.monthCount ?? 0,
article.yearCount ?? 0,
article.totalCount ?? 0,
]),
]

const workSheet = xlsx.utils.aoa_to_sheet(workSheetData)
workBook.Sheets['Articles'] = workSheet

workSheet['!autofilter'] = { ref: 'A1:I1' }

xlsx.writeFile(
workBook,
`bde_isima_articles-${date.getFullYear()}-${
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pareil ici avec l'utilitaire tu pourras format la date à un format précis

date.getMonth() + 1
}-${date.getDate()}_${date.getHours()}-${date.getMinutes()}.xlsx`
)
}

return (
<Button endIcon={<TableChartIcon />} variant="contained" onClick={exportToExcel}>
Exporter vers Excel
</Button>
)
}

export function ExportArticlesFallback() {
return (
<Box sx={{ m: 1, position: 'relative' }}>
<Button disabled endIcon={<TableChartIcon />} variant={'contained'}>
Exporter vers Excel
</Button>
<CircularProgress
size={25}
sx={{
position: 'absolute',
top: '50%',
left: '50%',
marginTop: '-12px',
marginLeft: '-12px',
}}
/>
</Box>
);
}

2 changes: 1 addition & 1 deletion app/components/dashboard/cashing/SearchUser.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Autocomplete } from 'bde-isima-mui-rff'
import { Autocomplete } from 'mui-rff'
import TextField from '@mui/material/TextField'
import { useQuery, useAuthenticatedSession } from 'blitz'
import { useState, Dispatch, SetStateAction } from 'react'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TextField } from 'bde-isima-mui-rff'
import { TextField } from 'mui-rff'

import { Form, FORM_ERROR } from 'app/components/forms/Form'
import EnhancedTextField from 'app/components/forms/EnhancedTextfield'
Expand Down
2 changes: 1 addition & 1 deletion app/components/dashboard/clubs/ClubForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Image } from 'blitz'
import { TextField } from 'bde-isima-mui-rff'
import { TextField } from 'mui-rff'
import Divider from '@mui/material/Divider'
import IconButton from '@mui/material/IconButton'
import InputAdornment from '@mui/material/InputAdornment'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TextField } from 'bde-isima-mui-rff'
import { TextField } from 'mui-rff'
import Tab from '@mui/material/Tab'
import TabList from '@mui/lab/TabList'
import { Field } from 'react-final-form'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useForm } from 'react-final-form'
import { TextField, Select } from 'bde-isima-mui-rff'
import { TextField, Select } from 'mui-rff'
import Divider from '@mui/material/Divider'
import MenuItem from '@mui/material/MenuItem'
import FormGroup from '@mui/material/FormGroup'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TextField } from 'bde-isima-mui-rff'
import { TextField } from 'mui-rff'
import { useForm } from 'react-final-form'
import FormGroup from '@mui/material/FormGroup'
import { FieldArray } from 'react-final-form-arrays'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TextField } from 'bde-isima-mui-rff'
import { TextField } from 'mui-rff'
import { useForm } from 'react-final-form'
import Divider from '@mui/material/Divider'
import FormGroup from '@mui/material/FormGroup'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Select } from 'bde-isima-mui-rff'
import { Select } from 'mui-rff'
import MuiCard from '@mui/material/Card'
import Button from '@mui/material/Button'
import { useForm } from 'react-final-form'
Expand Down
2 changes: 1 addition & 1 deletion app/components/dashboard/elections/CandidatesForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TextField } from 'bde-isima-mui-rff'
import { TextField } from 'mui-rff'
import { useForm } from 'react-final-form'
import Divider from '@mui/material/Divider'
import FormGroup from '@mui/material/FormGroup'
Expand Down
2 changes: 1 addition & 1 deletion app/components/dashboard/partners/PartnerForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Image } from 'blitz'
import { TextField } from 'bde-isima-mui-rff'
import { TextField } from 'mui-rff'
import IconButton from '@mui/material/IconButton'
import InputAdornment from '@mui/material/InputAdornment'

Expand Down
88 changes: 88 additions & 0 deletions app/components/dashboard/promotions/ExportPromotions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import xlsx from 'xlsx'
import { useQuery } from 'blitz'
corentin703 marked this conversation as resolved.
Show resolved Hide resolved
import Button from '@mui/material/Button'

import TableChartIcon from '@mui/icons-material/TableChart'

import Box from '@mui/material/Box'
import { Promotion } from '@prisma/client'
import CircularProgress from '@mui/material/CircularProgress'
import getPromotions from 'app/entities/promotions/queries/getPromotions'

export default function ExportPromotions() {
const [{ promotions }] = useQuery(getPromotions, {
include: {
_count: {
select: {
User: true,
},
},
},
orderBy: {
year: 'asc',
},
})

const exportToExcel = () => {
const date = new Date()

const workBook = xlsx.utils.book_new()

workBook.Props = {
Title: 'BDE ISIMA - Utilisateurs',
Subject: 'Liste des utilisateurs',
CreatedDate: date,
}

workBook.SheetNames.push('Promotions')

const workSheetData = [
['Année', 'ID Groupe Facebook', 'Liste de diffusion', "Nombre d'utilisateurs"],
...promotions.map((promotion: Promotion & { _count: { User: number }}) => [
promotion.year,
promotion.fb_group_id,
promotion.list_email,
promotion._count.User,
]),
]

const workSheet = xlsx.utils.aoa_to_sheet(workSheetData)
workBook.Sheets['Promotions'] = workSheet

workSheet['!autofilter'] = { ref: 'A1:D1' }

xlsx.writeFile(
workBook,
`bde_isima_promotions-${date.getFullYear()}-${
date.getMonth() + 1
}-${date.getDate()}_${date.getHours()}-${date.getMinutes()}.xlsx`
)
}

return (
<Button endIcon={<TableChartIcon />} variant={'contained'} onClick={exportToExcel}>
Exporter vers Excel
</Button>
)
}

export function ExportPromotionsFallback() {
return (
<Box sx={{ m: 1, position: 'relative' }}>
<Button disabled endIcon={<TableChartIcon />} variant={'contained'}>
Exporter vers Excel
</Button>
<CircularProgress
size={25}
sx={{
position: 'absolute',
top: '50%',
left: '50%',
marginTop: '-12px',
marginLeft: '-12px',
}}
/>
</Box>
);
}

2 changes: 1 addition & 1 deletion app/components/dashboard/promotions/PromotionForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TextField } from 'bde-isima-mui-rff'
import { TextField } from 'mui-rff'

import { Promotion } from 'db'
import { Form, FORM_ERROR } from 'app/components/forms/Form'
Expand Down
92 changes: 92 additions & 0 deletions app/components/dashboard/users/ExportUsers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import xlsx from 'xlsx'
import { useQuery } from 'blitz'
corentin703 marked this conversation as resolved.
Show resolved Hide resolved
import Box from '@mui/material/Box'
import Button from '@mui/material/Button'
import { Promotion, User } from '@prisma/client'
import TableChartIcon from '@mui/icons-material/TableChart'
import CircularProgress from '@mui/material/CircularProgress'

import getUsers from 'app/entities/users/queries/getUsers'

export default function ExportUsers() {
const [{ users }] = useQuery(getUsers, {
include: {
promotion: {
select: {
year: true,
},
},
},
where: {
is_enabled: true,
},
orderBy: {
card: 'asc',
},
})

const exportToExcel = () => {
const date = new Date()

const workBook = xlsx.utils.book_new()

workBook.Props = {
Title: 'BDE ISIMA - Utilisateurs',
Subject: 'Liste des utilisateurs',
CreatedDate: date,
}

workBook.SheetNames.push('Utilisateurs')

const workSheetData = [
['Numéro carte', 'Prénom', 'Nom', 'Courriel', 'Promotion', 'Solde', 'Cotisant'],
...users.map((user: User & { promotion: Promotion }) => [
user.card,
user.firstname,
user.lastname,
user.email,
user.promotion ? user.promotion.year : 'N/A',
user.balance,
user.is_member ? 'Oui' : 'Non',
]),
]

const workSheet = xlsx.utils.aoa_to_sheet(workSheetData)
workBook.Sheets['Utilisateurs'] = workSheet

workSheet['!autofilter'] = { ref: 'A1:G1' }

xlsx.writeFile(
workBook,
`bde_isima_utilisateurs-${date.getFullYear()}-${
date.getMonth() + 1
}-${date.getDate()}_${date.getHours()}-${date.getMinutes()}.xlsx`
)
}

return (
<Button endIcon={<TableChartIcon />} variant={'contained'} onClick={exportToExcel}>
Exporter vers Excel
</Button>
)
}

export function ExportUserFallback() {
return (
<Box sx={{ m: 1, position: 'relative' }}>
<Button disabled endIcon={<TableChartIcon />} variant={'contained'}>
Exporter vers Excel
</Button>
<CircularProgress
size={25}
sx={{
position: 'absolute',
top: '50%',
left: '50%',
marginTop: '-12px',
marginLeft: '-12px',
}}
/>
</Box>
);
}
2 changes: 1 addition & 1 deletion app/components/dashboard/users/PromotionsForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useQuery } from 'blitz'
import { Select } from 'bde-isima-mui-rff'
import { Select } from 'mui-rff'
import MenuItem from '@mui/material/MenuItem'

import getPromotions from 'app/entities/promotions/queries/getPromotions'
Expand Down
2 changes: 1 addition & 1 deletion app/components/dashboard/users/UserForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useMemo, useState } from 'react'
import AppBar from '@mui/material/AppBar'
import Divider from '@mui/material/Divider'
import TabContext from '@mui/lab/TabContext'
import { TextField, Switches } from 'bde-isima-mui-rff'
import { TextField, Switches } from 'mui-rff'
import IconButton from '@mui/material/IconButton'
import InputAdornment from '@mui/material/InputAdornment'
import CircularProgress from '@mui/material/CircularProgress'
Expand Down
Loading