Skip to content

Commit

Permalink
ajustes
Browse files Browse the repository at this point in the history
  • Loading branch information
Brunobento1990 committed Dec 25, 2024
1 parent aab5d8c commit 7666f1c
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 49 deletions.
12 changes: 11 additions & 1 deletion src/@open-adm/api/use-api-parcela.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export function useApiParcela() {
url: 'parcela/pagar'
})

const apiEstorno = useNewApi({
method: 'PUT',
url: 'parcela/estornar?parcelaId='
})

async function obterParcela(id: string): Promise<IParcela | undefined> {
return await apiGet.fecth({
urlParams: `?id=${id}`
Expand All @@ -23,8 +28,13 @@ export function useApiParcela() {
return await apiPagar.fecth({ body: pagarParcela, message: 'Parcela paga com sucesso!' })
}

async function estornarParcela(id: string): Promise<any> {
return await apiEstorno.fecth({ urlParams: id, message: 'Estorno efetuado com sucesso!' })
}

return {
obterParcela,
pagarParcela
pagarParcela,
estornarParcela
}
}
37 changes: 19 additions & 18 deletions src/@open-adm/components/form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,26 @@ export function Form(props: propsForm) {
}
}}>
{props.children}
<Box display='flex' justifyContent='space-between' sx={{ marginTop: 10 }}>
{props.urlVoltar &&
<Button
onClick={() => navigate(props.urlVoltar ?? '/home')}
>
Voltar
</Button>
}
{props.action !== 'view' &&
<Button
disabled={props.loading}
variant="contained"
type="submit"
onClick={props.submit}
>
{props.loading ? <>Aguarde ... <LoadingApp size={20} /></> : props.titleButton ?? 'Salvar'}
</Button>
}
</Box>
</form>
<Box display='flex' justifyContent='space-between' sx={{ marginTop: 10 }}>
{props.urlVoltar &&
<Button
onClick={() => navigate(props.urlVoltar ?? '/home')}
>
Voltar
</Button>
}
{props.action !== 'view' &&
<Button
disabled={props.loading}
variant="contained"
onClick={props.submit}
>
{props.loading ? <>Aguarde ... <LoadingApp size={20} /></> : props.titleButton ?? 'Salvar'}
</Button>
}
</Box>
</Card>
)
}
10 changes: 5 additions & 5 deletions src/@open-adm/pages/financeiro/fatura/baixar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export function BaixarParcela() {
setLoading(true)
const response = await pagarParcela({
id: form.values.id,
valor: cleanFormatMoney(form.values.valor) ?? 0,
dataDePagamento,
valor: cleanFormatMoney(form.values.valorAPagarAReceber) ?? 0,
dataDePagamento: dataDePagamento?.length && dataDePagamento.length > 0 ? dataDePagamento : undefined,
desconto: cleanFormatMoney(form.values.desconto),
meioDePagamento: form.values.meioDePagamento,
observacao: form.values.observacao
Expand Down Expand Up @@ -88,10 +88,10 @@ export function BaixarParcela() {
<FormItemRow sm={6} xs={12}>
<InputCustom
fullWidth
id="valor"
id="valorAPagarAReceber"
label="Valor"
name="valor"
value={form.values.valor}
name="valorAPagarAReceber"
value={form.values.valorAPagarAReceber}
mask={MaskType.MONEY}
onChange={form.onChange}
onBlur={form.onBlur}
Expand Down
2 changes: 1 addition & 1 deletion src/@open-adm/pages/financeiro/fatura/form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export function CreateFatura(props: propsCreateFatura) {
fullWidth
id="total"
onBlur={gerarParcelas}
label={"Quantidade de parcelas"}
label={"Total"}
onChange={form.onChange}
name={"total"}
value={form.values.total}
Expand Down
32 changes: 31 additions & 1 deletion src/@open-adm/pages/financeiro/fatura/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { TableIndex } from "src/@open-adm/components/table-paginacao";
import { useNavigateApp } from "src/@open-adm/hooks/use-navigate-app";
import { IconButton, Tooltip } from "@mui/material";
import IconifyIcon from "src/@core/components/icon";
import { useApiParcela } from "src/@open-adm/api/use-api-parcela";
import { IParcela } from "src/@open-adm/types/fatura";
import { useModal } from "src/@open-adm/components/modal/modal";

export const statusFatura: StatusObj = {
0: { title: 'Pendente', color: 'warning' },
Expand All @@ -22,6 +25,19 @@ interface propsFaturaPaginacao {

export function FaturaPaginacao(props: propsFaturaPaginacao) {
const { navigate } = useNavigateApp();
const { estornarParcela } = useApiParcela();
const { show, close } = useModal()

async function estornar(parcela: IParcela) {
show({
message: `Confirma o estorno da parcela: ${parcela.numeroDaParcela}?`,
confirmed: async () => {
await estornarParcela(parcela.id)
close()
}
})
}

return (
<TableIndex
minWidth={2500}
Expand Down Expand Up @@ -93,7 +109,7 @@ export function FaturaPaginacao(props: propsFaturaPaginacao) {
sortable: true,
},
{
width: 150,
width: 100,
field: 'baixa',
headerName: 'Baixar',
renderCell: (params: any) => {
Expand All @@ -106,6 +122,20 @@ export function FaturaPaginacao(props: propsFaturaPaginacao) {
)
}
},
{
width: 140,
field: 'estornar',
headerName: 'Estornar',
renderCell: (params: IParcela) => {
return (
<IconButton onClick={async () => await estornar(params)}>
<IconifyIcon
icon='mage:reload-reverse'
/>
</IconButton>
)
}
},
]}
url="parcela/paginacao"
urlView={props.urlView}
Expand Down
55 changes: 44 additions & 11 deletions src/@open-adm/pages/financeiro/transacao-financeira/extrato.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@ import { initialValues, schema } from "./config";
import { FormRow } from "src/@open-adm/components/form/row";
import { FormItemRow } from "src/@open-adm/components/form/item-row";
import { InputDate } from "src/@open-adm/components/input/input-date";
import { convertDateForJson, formatDateComHoras } from "src/@open-adm/utils/convert-date";
import { formatDateComHoras } from "src/@open-adm/utils/convert-date";
import { useApiTransacao } from "src/@open-adm/api/use-api-transacao";
import { useState } from "react";
import { TablePaginacao } from "src/@open-adm/components/table-paginacao/table";
import { formatMoney } from "src/@open-adm/utils/format-money";
import { BoxApp } from "src/@open-adm/components/box";
import { DropDownMultiple } from "src/@open-adm/components/drop-down-scroll/dorp-down-multiple";
import { DropDownScroll } from "src/@open-adm/components/drop-down-scroll";
import { StatusApp } from "src/@open-adm/components/chip";
import { StatusObj } from "../../pedidos/config";
import { statusFatura } from "../fatura";
import IconifyIcon from "src/@core/components/icon";
import { listaIcones } from "src/configs/listaIcones";

export const tipoTransacaoFinanceira: StatusObj = {
0: { title: 'Entrada', color: 'success' },
1: { title: 'Saída', color: 'error' },
}

export function Extrato() {
const [loading, setLoading] = useState(false)
Expand All @@ -33,8 +41,6 @@ export function Extrato() {
setLoading(false)
}

console.log('values', form.values)

return (
<Form
loading={loading}
Expand Down Expand Up @@ -89,6 +95,39 @@ export function Extrato() {
stickyHeader
minWidth={2000}
columns={[
{
width: 20,
field: 'tipo_1',
headerName: '',
renderCell: (row: ITransacaoFinanceira) => {
return (
<IconifyIcon icon={row.tipoTransacaoFinanceira === 0 ?
listaIcones.contasAReceber
: listaIcones.contasAPagar}
color={row.tipoTransacaoFinanceira === 0 ? 'green' : 'red'}
/>
)
}
},
{
width: 50,
field: 'tipo',
headerName: 'Tipo',
renderCell: (row: ITransacaoFinanceira) => {
const status = tipoTransacaoFinanceira[row.tipoTransacaoFinanceira]
return (
<StatusApp cor={status.color} titulo={status.title} />
)
}
},
{
width: 50,
field: 'ehEstorno',
headerName: 'Estorno',
renderCell: (row: ITransacaoFinanceira) => {
return row.ehEstorno ? 'Sim' : 'Não'
}
},
{
width: 100,
field: 'usuario',
Expand Down Expand Up @@ -125,12 +164,6 @@ export function Extrato() {
headerName: 'Desconto da parcela',
renderCell: (row: ITransacaoFinanceira) => formatMoney(row.parcela?.desconto) ?? ''
},
{
width: 50,
field: 'tipo',
headerName: 'Tipo',
renderCell: (row: ITransacaoFinanceira) => row.tipoTransacaoFinanceira === 0 ? 'Entrada' : 'Saída'
},
{
width: 100,
field: 'pedido',
Expand Down
12 changes: 6 additions & 6 deletions src/@open-adm/pages/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,23 @@ export function HomePage() {
<>
<BoxApp padding="1rem">
<Grid container spacing={5} padding={2}>
{home?.totalAReceber &&
{home?.totalAReceber && home?.totalAReceber > 0 ?
<Grid item xs={12} sm={6}>
<FaturasTotalizador total={home.totalAReceber} />
</Grid>
</Grid> : <></>
}
{home?.pedidosEmAberto &&
{home?.pedidosEmAberto && home?.pedidosEmAberto > 0 ?
<Grid item xs={12} sm={6}>
<PedidosEmEbrtoGrafico total={home.pedidosEmAberto} />
</Grid>
</Grid> : <></>
}
</Grid>
</BoxApp>
<Grid container spacing={5} padding={2}>
{home?.faturas && home.faturas?.length &&
{home?.faturas && home.faturas?.length ?
<Grid item xs={12} sm={6}>
<Faturas faturas={home?.faturas ?? []} />
</Grid>
</Grid> : <></>
}
<Grid item xs={12} sm={6}>
<Movimentos movimentos={home?.movimentos ?? []} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ export function RelatorioPorPeriodo() {
<SelectCustom
id='usuarios'
getOptionLabel={option => option.nome || ''}
onInputChange={(event, newInputValue) => formik.setValues({
onInputChange={(_, newInputValue) => formik.setValues({
...formik.values,
usuarioId: usuarios.find((x) => x.nome === newInputValue).id
usuarioId: usuarios.find((x) => x.nome === newInputValue)?.id
})}
options={usuarios}
renderInput={params =>
Expand Down
3 changes: 2 additions & 1 deletion src/@open-adm/types/transacao-financeira.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export interface ITransacaoFinanceira {
valor: number,
tipoTransacaoFinanceira: TipoTransacaoFinanceira,
meioDePagamento: number,
observacao: string
observacao: string,
ehEstorno?: boolean;
}

export type TipoTransacaoFinanceira = 0 | 1;
Expand Down
7 changes: 4 additions & 3 deletions src/@open-adm/views/home/faturas.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AreaChart, Area, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer } from 'recharts';
import { BoxApp } from 'src/@open-adm/components/box';
import { TextApp } from 'src/@open-adm/components/text';
import { formatMoney } from 'src/@open-adm/utils/format-money';

interface propsFaturasDashBoard {
faturas: any[];
Expand All @@ -12,7 +13,7 @@ const FaturasDashBoard = (props: propsFaturasDashBoard) => {
<ResponsiveContainer width="100%" height="100%">
<>
<BoxApp width='100%' display='flex' alignItems='center' justifyContent='center'>
<TextApp texto={`Faturas recebidas no últimos ${props.faturas.length} meses`} />
<TextApp texto={`Faturas recebidas nos ultimos ${props.faturas.length} meses`} />
</BoxApp>
<AreaChart
width={500}
Expand All @@ -27,8 +28,8 @@ const FaturasDashBoard = (props: propsFaturasDashBoard) => {
>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="mes" />
<YAxis />
<Tooltip />
<YAxis dataKey={"count"} />
<Tooltip formatter={(value) => formatMoney(value as any)} label={'Valor'} />
<Area type="monotone" dataKey="count" stroke="#8884d8" fill="#8884d8" fillOpacity={0.3} />
</AreaChart>
</>
Expand Down
4 changes: 4 additions & 0 deletions src/configs/listaIcones.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const listaIcones = {
contasAPagar: 'streamline:money-graph-arrow-decrease-down-stats-graph-descend-right-arrow',
contasAReceber: 'streamline:money-graph-arrow-increase-ascend-growth-up-arrow-stats-graph-right-grow'
}

0 comments on commit 7666f1c

Please sign in to comment.