forked from b00tc4mp/isdi-parttime-202403
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create api logic deleteDelivery, routes; spec test getAllInvoices; fi…
…x registerCustomer; install reactpdf, implement delete to app, implement reactpdf to deliveryInfo, update styles; b00tc4mp#156
- Loading branch information
Showing
22 changed files
with
927 additions
and
69 deletions.
There are no files selected for viewing
522 changes: 508 additions & 14 deletions
522
staff/jose-canto/project/FactuClient/package-lock.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
staff/jose-canto/project/FactuClient/src/components/Confirm/index.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@tailwind components; | ||
|
||
@layer components { | ||
.Confirm { | ||
@apply absolute mx-auto w-auto flex-1 flex-col items-center rounded-lg bg-[#e4e4e4] p-4 shadow-custom-shadow; | ||
} | ||
|
||
.Confirm h2 { | ||
@apply text-center text-2xl font-bold; | ||
} | ||
|
||
.Confirm p { | ||
@apply mt-4 text-center; | ||
} | ||
|
||
.Confirm-Buttons { | ||
@apply flex w-auto gap-10; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
staff/jose-canto/project/FactuClient/src/components/Confirm/index.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Button from "../core/Button" | ||
import Title from "../Title" | ||
|
||
import "./index.css" | ||
|
||
export default function Confirm({ setShowConfirmDelete, handleDeleteDeliveryNote }) { | ||
return ( | ||
<> | ||
<div className="Confirm"> | ||
<Title level={2}>¿Seguro que quieres eliminar?</Title> | ||
<div className="Confirm-Buttons"> | ||
<Button className="ConfirmButton" onClick={handleDeleteDeliveryNote}> | ||
Aceptar | ||
</Button> | ||
<Button className="CancelButton" onClick={() => setShowConfirmDelete(!setShowConfirmDelete)}> | ||
Cancelar | ||
</Button> | ||
</div> | ||
</div> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
staff/jose-canto/project/FactuClient/src/components/view/DeliveryNotePDF.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
import { Page, Text, View, Document, StyleSheet, Image } from "@react-pdf/renderer" | ||
|
||
const styles = StyleSheet.create({ | ||
page: { | ||
padding: 10, | ||
backgroundColor: "aliceblue" | ||
}, | ||
section: { | ||
margin: 5, | ||
padding: 5, | ||
flexGrow: 1 | ||
}, | ||
headerRow: { | ||
flexDirection: "row", | ||
justifyContent: "space-between", | ||
alignItems: "center", | ||
marginBottom: 15 | ||
}, | ||
header: { | ||
fontSize: 16, | ||
textAlign: "center" | ||
}, | ||
date: { | ||
fontSize: 12, | ||
textAlign: "center" | ||
}, | ||
borderedSection: { | ||
border: "1px solid black", | ||
padding: 10, | ||
marginBottom: 10, | ||
flex: 1, | ||
textAlign: "center" | ||
}, | ||
companyInfo: { | ||
backgroundColor: "#e0f7fa" | ||
}, | ||
customerInfo: { | ||
backgroundColor: "#f1f8e9" | ||
}, | ||
infoRow: { | ||
flexDirection: "row", | ||
justifyContent: "space-between", | ||
marginBottom: 5, | ||
fontSize: 12 | ||
}, | ||
workInfoHeader: { | ||
flexDirection: "row", | ||
justifyContent: "space-between", | ||
marginBottom: 5, | ||
fontWeight: "bold", | ||
fontSize: 14, | ||
backgroundColor: "#d5cabd", | ||
padding: 5 | ||
}, | ||
workInfo: { | ||
flexDirection: "row", | ||
justifyContent: "space-between", | ||
marginBottom: 5, | ||
fontSize: 12 | ||
}, | ||
concept: { | ||
flex: 3, | ||
textAlign: "left" | ||
}, | ||
quantity: { | ||
flex: 1, | ||
textAlign: "right" | ||
}, | ||
price: { | ||
flex: 1, | ||
textAlign: "right" | ||
}, | ||
totalAmount: { | ||
flex: 1, | ||
textAlign: "right" | ||
}, | ||
total: { | ||
marginTop: 20, | ||
fontSize: 16, | ||
textAlign: "right" | ||
}, | ||
logo: { | ||
width: 50, | ||
height: 50, | ||
marginBottom: 15 | ||
} | ||
}) | ||
|
||
const DeliveryNotePDF = ({ deliveryNote, total }) => { | ||
const formattedDate = new Date(deliveryNote.date).toLocaleDateString() | ||
|
||
return ( | ||
<Document> | ||
<Page size="A5" orientation="landscape" style={styles.page}> | ||
<View style={styles.section}> | ||
<Image style={styles.logo} src={deliveryNote.company.companyLogo} /> | ||
|
||
<View style={styles.headerRow}> | ||
<Text style={styles.header}>Albarán nº: {deliveryNote.number}</Text> | ||
<Text style={styles.date}>Fecha: {formattedDate}</Text> | ||
</View> | ||
|
||
<View style={styles.infoRow}> | ||
<Text style={[styles.borderedSection, styles.companyInfo]}> | ||
{deliveryNote.company.companyName} | ||
{"\n"} | ||
{deliveryNote.company.address} | ||
{"\n"} | ||
{deliveryNote.company.taxId} | ||
{"\n"} | ||
{deliveryNote.company.email} | ||
</Text> | ||
<View style={[styles.borderedSection, styles.customerInfo]}> | ||
<Text style={{ fontWeight: "bold", textDecoration: "underline", marginBottom: 5 }}>Cliente:</Text> | ||
<Text> | ||
{deliveryNote.customer.companyName} | ||
{"\n"} | ||
{deliveryNote.customer.address} | ||
{"\n"} | ||
{deliveryNote.customer.taxId} | ||
{"\n"} | ||
{deliveryNote.customer.email} | ||
</Text> | ||
</View> | ||
</View> | ||
|
||
<View style={styles.workInfoHeader}> | ||
<Text style={styles.concept}>Concepto</Text> | ||
<Text style={styles.quantity}>Cantidad</Text> | ||
<Text style={styles.price}>Precio</Text> | ||
<Text style={styles.totalAmount}>Total</Text> | ||
</View> | ||
{deliveryNote.works.map((work) => ( | ||
<View key={work._id} style={styles.workInfo}> | ||
<Text style={styles.concept}>{work.concept}</Text> | ||
<Text style={styles.quantity}>{work.quantity.toFixed(2)}</Text> | ||
<Text style={styles.price}>{work.price.toFixed(2)}</Text> | ||
<Text style={styles.totalAmount}>{(work.quantity * work.price).toFixed(2)}</Text> | ||
</View> | ||
))} | ||
|
||
<Text style={styles.total}>TOTAL: {total.toFixed(2)} €</Text> | ||
</View> | ||
</Page> | ||
</Document> | ||
) | ||
} | ||
|
||
export default DeliveryNotePDF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
} | ||
|
||
.DeliveryLink { | ||
@apply flex items-start; | ||
@apply flex items-center; | ||
} | ||
|
||
.DeliveryNote { | ||
|
27 changes: 27 additions & 0 deletions
27
staff/jose-canto/project/FactuClient/src/logic/deleteDeliveryNote.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import errors, { SystemError } from "com/errors.js" | ||
import validate from "com/validate.js" | ||
|
||
const deleteDeliveryNote = (deliveryNoteId) => { | ||
validate.id(deliveryNoteId, "deliveryNoteId") | ||
|
||
return fetch(`${import.meta.env.VITE_API_URL}/delivery-notes/${deliveryNoteId}`, { | ||
method: "DELETE", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"Authorization": `Bearer ${sessionStorage.token}` | ||
} | ||
}) | ||
.catch(() => { throw new SystemError("connection error") }) | ||
.then(response => { | ||
if (response.status === 204) return | ||
|
||
return response.json() | ||
.catch(() => { throw new SystemError("connection error") }) | ||
.then(body => { | ||
const { error, message } = body | ||
const constructor = errors[error] | ||
throw new constructor(message) | ||
}) | ||
}) | ||
} | ||
export default deleteDeliveryNote |
Oops, something went wrong.