Skip to content

Commit

Permalink
Merge pull request alexrobaina#259 from alexrobaina/feat/add-expense
Browse files Browse the repository at this point in the history
add expense
  • Loading branch information
alexrobaina authored Jun 13, 2024
2 parents daebf27 + a5898d7 commit 2325a07
Show file tree
Hide file tree
Showing 38 changed files with 1,485 additions and 171 deletions.
24 changes: 24 additions & 0 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
"exotics": "Exotics",
"males": "Males",
"females": "Females",
"quantity": "Quantity",
"areYouSureDeleteProduct": "Are you sure you want to delete this product?",
"expense": "Expense",
"income": "Income",
"items": "Items",
"amount": "Amount",
"dog": "Dog",
"itemName": "Item name",
"itemDescription": "Item description",
Expand All @@ -36,6 +42,24 @@
"category": "Categoría",
"gender": "Gender",
"age": "Age",
"analytics": "Analytics",
"expenses": "Expenses",
"expenseType": {
"INCOME": "Income",
"EXPENSE": "Expense"
},
"expenseCategory": {
"SUPPLIES": "Supplies",
"EQUIPMENT": "Equipment",
"RENT": "Rent",
"UTILITIES": "Utilities",
"INSURANCE": "Insurance",
"VEHICLE": "Vehicle",
"SERVICES": "Services",
"INVENTORY": "Inventory",
"SALARIES": "Salaries",
"OTHERS": "Others"
},
"inventoryType": {
"MEDICINE": "Medicine",
"FOOD": "Food",
Expand Down
27 changes: 27 additions & 0 deletions public/locales/en/expense.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"editExpense": "Edit expense",
"addExpense": "Add expense",
"title": "Title",
"titlePlaceholder": "Enter title",
"totalAmount": "Total amount",
"type": "Type",
"categoryPlaceholder": "Select category",
"addItem": "Add items",
"itemPrice": "Item price",
"itemPricePlaceholder": "Enter item price",
"totalIncome": "Total income",
"totalExpense": "Total expense",
"itemQuantity": "Item quantity",
"inventoryPlaceholder": "Select inventory...",
"expenseNotFound": "Expense not found",
"dontHaveExpense": "You can start adding your incomes and expenses",
"listOfExpenses": "List of expenses and incomes",
"descriptionPlaceholder": "Enter description",
"itemQuantityPlaceholder": "Enter item quantity",
"selectInventory": "Select inventory",
"expensesTitle": "Expense Tracker",
"expensesSubtitle": "Track your expenses and incomes",
"expensesDescription": "Expense Manager helps you track and manage your daily expenses with ease.",
"typePlaceholder": "Select type of expense",
"last": "Last"
}
26 changes: 25 additions & 1 deletion public/locales/es/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@
"exotics": "Exoticos",
"males": "Machos",
"females": "Hembras",
"analytics": "Analiticas",
"items": "Items",
"amount": "Cantidad",
"expenses": "Gastos",
"expenseType": {
"INCOME": "Ingreso",
"EXPENSE": "Gasto"
},
"expenseCategory": {
"SUPPLIES": "Suministros",
"EQUIPMENT": "Equipo",
"RENT": "Renta",
"UTILITIES": "Servicios",
"INSURANCE": "Seguro",
"VEHICLE": "Vehículo",
"INVENTORY": "Inventario",
"SALARIES": "Salarios",
"SERVICES": "Servicios",
"OTHERS": "Otros"
},
"inventoryType": {
"MEDICINE": "Medicina",
"FOOD": "Comida",
Expand All @@ -33,6 +53,10 @@
"TRAVEL_OUTDOOR": "Viajes y Aire Libre",
"TRAINING_BEHAVIOR": "Entrenamiento y Comportamiento"
},
"quantity": "Cantidad",
"areYouSureDeleteProduct": "Estas por eliminar el producto",
"expense": "Gasto",
"income": "Ingreso",
"dog": "Perro",
"cat": "Gato",
"exotic": "Exotico",
Expand Down Expand Up @@ -112,7 +136,7 @@
"veterinarians": "Veterinarios",
"veterinarian": "Veterinaria",
"shelters": "Refugios",
"role": "Role",
"role": "Rol del usuario",
"myPets": "Mis mascotas",
"start": "Start",
"end": "End",
Expand Down
27 changes: 27 additions & 0 deletions public/locales/es/expense.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"editExpense": "Editar gasto",
"addExpense": "Agregar gasto",
"title": "Titulo",
"titlePlaceholder": "Titulo del gasto",
"totalAmount": "Monto total",
"type": "Tipo",
"typePlaceholder": "Tipo de gasto",
"categoryPlaceholder": "Categoria",
"addItem": "Agregar items",
"itemPrice": "Precio",
"itemPricePlaceholder": "Precio del item",
"itemQuantity": "Cantidad",
"listOfExpenses": "Lista de ingresos y gastos",
"expenseNotFound": "Gastos no encontrado",
"dontHaveExpense": "Puedes comenzar a agregar tus ingresos y gastos",
"inventoryPlaceholder": "Seleccionar inventario",
"descriptionPlaceholder": "Descripcion del gasto",
"itemQuantityPlaceholder": "Cantidad del item",
"selectInventory": "Seleccionar inventario",
"expensesTitle": "Gastos",
"totalIncome": "Ingresos totales",
"totalExpense": "Gastos totales",
"expensesSubtitle": "Aqui puedes ver tus gastos",
"expensesDescription": "Puedes ver tus gastos y agregar nuevos",
"last": "Ultimo"
}
22 changes: 22 additions & 0 deletions public/locales/fr/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"birds": "Oiseaux",
"dashboard": "Tableau de bord",
"settings": "Paramètres",
"areYouSureDeleteProduct": "Êtes-vous sûr de vouloir supprimer ce produit?",
"inventory": "Inventaire",
"type": "Type",
"selectType": "Sélectionner Type",
Expand All @@ -18,8 +19,11 @@
"searchByName": "Recherche par nom",
"placeholderTitle": "Ajouter un titre",
"itemName": "Nom de l'élément",
"expense": "Dépense",
"income": "Revenu",
"dogs": "Chiens",
"cats": "Chats",
"quantity": "Quantité",
"inventoryType": {
"MEDICINE": "Médicament",
"FOOD": "Nourriture",
Expand Down Expand Up @@ -80,8 +84,26 @@
"results": "résultats",
"previous": "Précédent",
"name": "Nom",
"expenseType": {
"INCOME": "Revenu",
"EXPENSE": "Dépense"
},
"expenses": "Dépenses",
"expenseCategory": {
"SUPPLIES": "Fournitures",
"EQUIPMENT": "Équipement",
"RENT": "Loyer",
"INVENTORY": "Inventaire",
"SALARIES": "Salaires",
"UTILITIES": "Services publics",
"INSURANCE": "Assurance",
"VEHICLE": "Véhicule",
"SERVICES": "Services",
"OTHERS": "Autres"
},
"next": "Suivant",
"selectImages": "Sélectionner des images",
"items": "Articles",
"selectImagesInfo": "JPG, GIF ou PNG. Maximum 1,5 Mo.",
"petName": "Nom de l'animal",
"breed": "Race",
Expand Down
28 changes: 28 additions & 0 deletions public/locales/fr/expense.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"editExpense": "Modifier les dépenses",
"addExpense": "Ajouter des dépenses",
"title": "Titre",
"addItem": "Ajouter des articles",
"titlePlaceholder": "Titre de la dépense",
"expenseNotFound": "Dépense introuvable",
"totalAmount": "Montant total",
"type": "Type",
"itemPrice": "Prix de l'article",
"itemPricePlaceholder": "Prix de l'article",
"inventoryPlaceholder": "Select Inventory",
"itemQuantity": "Quantité de l'article",
"dontHaveExpense": "Vous pouvez commencer à ajouter vos revenus et dépenses",
"itemQuantityPlaceholder": "Quantité de l'article",
"descriptionPlaceholder": "Description de la dépense",
"expensesTitle": "Dépenses",
"expensesSubtitle": "Ajoutez vos dépenses ici",
"totalIncome": "Revenu total",
"totalExpense": "Dépense totale",
"analytics": "Analytique",
"expensesDescription": "Ajoutez vos dépenses ici",
"listOfExpenses": "Liste des dépenses",
"selectInventory": "Sélectionner l'inventaire",
"typePlaceholder": "Type de dépense",
"categoryPlaceholder": "Catégorie de dépense",
"last": "Dernier"
}
5 changes: 5 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { UserProfilePage } from './pages/UserProfilePage'
import { AppContext, AppContextProps } from './services/AppContext'

import './api/axiosInstance'
import { ExpensePage } from './pages/ExpensePage'

interface Props {
appContext: AppContextProps
Expand Down Expand Up @@ -63,6 +64,10 @@ const router = createBrowserRouter([
path: '/inventory',
element: <InventoryPage />,
},
{
path: '/expense',
element: <ExpensePage />,
},
{
path: '/',
element: <DashboardPage />,
Expand Down
108 changes: 108 additions & 0 deletions src/api/expense.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import axios from 'axios'

const API_URL = '/api/v1'

export const createExpense = async (data: {
id: string
totalAmount: number
type: string
category: string
title: string
description: string
items: {
title: string
quantity: number
price: number
inventoryId: string
}[]
}) => {
try {
const response = await axios.post(`${API_URL}/expense`, data, {
headers: {
'Content-Type': 'application/json',
},
})
return response.data
} catch (error) {
console.error(error)
throw new Error('Failed to create expense')
}
}

export const updateExpense = async (data: {
id: string
totalAmount: number
type: string
category: string
title: string
description: string
items: {
title: string
quantity: number
price: number
inventoryId: string
}[]
}) => {
try {
console.log(data)

const response = await axios.put(`${API_URL}/expense/${data.id}`, data, {
headers: {
'Content-Type': 'application/json',
},
})
return response.data
} catch (error) {
console.error(error)
throw new Error('Failed to update expense')
}
}

export const deleteExpense = async (expenseId: string) => {
try {
const response = await axios.delete(`${API_URL}/expense/${expenseId}`)
return response.data
} catch (error) {
console.error(error)
throw new Error('Failed to delete expense')
}
}

export const getExpense = async (expenseId: string) => {
try {
const response = await axios.get(`${API_URL}/expense/${expenseId}`)
return response.data
} catch (error) {
console.error(error)
throw new Error('Failed to fetch expense')
}
}

export const listExpenses = async (filters: {
title?: string
type?: string
category?: string
page?: number
startDate?: string
endDate?: string
amount?: string
date?: string
}) => {
try {
const response = await axios.get(`${API_URL}/expenses`, { params: filters })
return response.data
} catch (error) {
console.error(error)
throw new Error('Failed to fetch expenses')
}
}

export const getAnalytics = async () => {
try {
const response = await axios.get(`${API_URL}/expenses/analytics`)
return response.data
} catch (error) {
console.error(error)
throw new Error('Failed to fetch analytics')
}
}
8 changes: 8 additions & 0 deletions src/assets/icons/iconBuildingStore.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/assets/icons/iconCoin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/assets/icons/iconMoneyBag.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 2325a07

Please sign in to comment.