-
Notifications
You must be signed in to change notification settings - Fork 1.2k
update #6087
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
Merged
Merged
update #6087
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
1444624
update
ColeGN 2b24759
update
ColeGN 782934e
update
ColeGN 48064c3
fresh and clean
ColeGN 73a1433
update
ColeGN 47135a7
update
ColeGN fb9cff5
update
ColeGN 87de95d
update
ColeGN 14c63c5
update
ColeGN 7f3d8df
update
ColeGN bf2b0bd
Merge branch 'master' of github.com:erxes/erxes into pos-change
munkhsaikhan d079e2d
refactor
munkhsaikhan f921388
update
ColeGN b765a39
update
ColeGN fa8ba92
update
ColeGN 6608dac
update
ColeGN 94b67ca
fix: refactor and pos cat prod mapping
munkhsaikhan 39d5771
Merge branch 'master' of github.com:erxes/erxes into pos-change
munkhsaikhan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -34,15 +34,15 @@ const CatProdItem = (props: Props) => { | |
|
|
||
| const onSelectChange = (field: string, value: any) => { | ||
| setState((prevState) => ({ ...prevState, [field]: value })); | ||
| editMapping({ ...state, _id: item._id }); | ||
| editMapping({ _id: item._id, ...state, [field]: value }); | ||
| }; | ||
|
|
||
| const onChangeInput = (e) => { | ||
| const name = e.target.name; | ||
| const value = e.target.value; | ||
|
|
||
| setState((prevState) => ({ ...prevState, [name]: value })); | ||
| editMapping({ ...state, _id: item._id }); | ||
| editMapping({ _id: item._id, ...state, [name]: value }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, in onChangeInput the editMapping call uses the current 'state' immediately after setState, which might be stale. Refactor to use the updated state value or the setState callback result. |
||
| }; | ||
|
|
||
| return ( | ||
|
|
||
This file contains hidden or 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 hidden or 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
236 changes: 236 additions & 0 deletions
236
pos/modules/checkout/components/paymentType/invoiceInfo.tsx
This file contains hidden or 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,236 @@ | ||
| "use client" | ||
|
|
||
| import { useMemo } from "react" | ||
| import { useAtomValue } from "jotai" | ||
| import { addDays } from "date-fns" | ||
|
|
||
| import { | ||
| userNameAtom, | ||
| userBankAddressAtom, | ||
| companyRegisterAtom, | ||
| accountTypeAtom, | ||
| invoiceExpiryDaysAtom | ||
| } from "@/store" | ||
| import { formatNum } from "@/lib/utils" | ||
| import { totalAmountAtom, cartAtom } from "@/store/cart.store" | ||
| import { useInvoicePrintStyles } from "../../hooks/useInvoicePrintStyles" | ||
|
|
||
| const VAT_RATE = 0.1; | ||
| const VAT_MULTIPLIER = 1 + VAT_RATE; | ||
|
|
||
| const InvoiceInfo = () => { | ||
| const userName = useAtomValue(userNameAtom) | ||
| const userBankAddress = useAtomValue(userBankAddressAtom) | ||
| const company = useAtomValue(companyRegisterAtom) | ||
| const accountType = useAtomValue(accountTypeAtom) | ||
| const expiryDays = useAtomValue(invoiceExpiryDaysAtom) | ||
| const total = useAtomValue(totalAmountAtom) | ||
| const cartItems = useAtomValue(cartAtom) | ||
|
|
||
| const { userInfo, table } = useInvoicePrintStyles() | ||
|
|
||
| const transactionDate = useMemo(() => new Date(), []) | ||
| const deadlineDate = useMemo(() => addDays(transactionDate, expiryDays), [transactionDate, expiryDays]) | ||
| const isCompany = accountType === "company" | ||
|
|
||
| const totals = useMemo(() => { | ||
| const totalWithoutVat = cartItems.reduce((sum, item) => { | ||
| const totalItemPrice = item.count * item.unitPrice | ||
| return sum + (totalItemPrice / VAT_MULTIPLIER) | ||
| }, 0) | ||
| const vatAmount = total - totalWithoutVat | ||
|
|
||
| return { | ||
| subtotal: Math.round(totalWithoutVat), | ||
| vat: Math.round(vatAmount), | ||
| total: Math.round(total) | ||
| } | ||
| }, [cartItems, total]) | ||
|
|
||
| return ( | ||
| <div style={userInfo.container}> | ||
| <h2 style={userInfo.heading}>Нэхэмжлэл гаргах мэдээлэл</h2> | ||
|
|
||
| <div style={userInfo.userInfoSection}> | ||
| <div style={userInfo.userInfoItem}> | ||
| <strong>{isCompany ? "Байгууллагын нэр:" : "Овог, нэр:"}</strong> {userName} | ||
| </div> | ||
| {isCompany && company && ( | ||
| <div style={userInfo.userInfoItem}> | ||
| <strong>Бүртгэлийн дугаар:</strong> {company} | ||
| </div> | ||
| )} | ||
| <div style={userInfo.userInfoItem}> | ||
| <strong>Банкны дансны дугаар:</strong> MN{userBankAddress} | ||
| </div> | ||
| </div> | ||
|
|
||
| <div style={userInfo.dateSection}> | ||
| <div style={userInfo.dateGrid}> | ||
| <div> | ||
| <h3 style={userInfo.dateLabel}> | ||
| Гүйлгээний огноо | ||
| </h3> | ||
| <p style={userInfo.dateValue}> | ||
| {transactionDate.toLocaleDateString()} | ||
| </p> | ||
| <p style={userInfo.dateTime}> | ||
| {transactionDate.toLocaleTimeString()} | ||
| </p> | ||
| </div> | ||
| <div> | ||
| <h3 style={userInfo.dateLabel}> | ||
| Төлбөр төлөх хугацаа | ||
| </h3> | ||
| <p style={userInfo.deadlineDate}> | ||
| {deadlineDate.toLocaleDateString()} | ||
| </p> | ||
| <p style={userInfo.deadlineNote}> | ||
| ({expiryDays} хоногийн дотор төлнө үү) | ||
| </p> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div style={userInfo.sectionDivider}> | ||
| <h3 style={userInfo.heading}>Захиалгын мэдээлэл</h3> | ||
|
|
||
| {cartItems.length === 0 ? ( | ||
| <div style={userInfo.emptyCart}> | ||
| Захиалга хоосон байна | ||
| </div> | ||
| ) : ( | ||
| <div style={table.container}> | ||
| <table style={{...table.table, fontSize: '12px'}}> | ||
| <thead> | ||
| <tr style={table.header}> | ||
| <th style={{ | ||
| ...table.headerCellCenter, | ||
| width: '50px', | ||
| padding: '8px 6px' | ||
| }}> | ||
| # | ||
| </th> | ||
| <th style={{...table.headerCell, padding: '8px 6px'}}> | ||
| Бүтээгдэхүүн | ||
| </th> | ||
| <th style={{ | ||
| ...table.headerCellCenter, | ||
| width: '80px', | ||
| padding: '8px 6px' | ||
| }}> | ||
| Тоо ширхэг | ||
| </th> | ||
| <th style={{ | ||
| ...table.headerCellRight, | ||
| width: '100px', | ||
| padding: '8px 6px' | ||
| }}> | ||
| Нэгжийн үнэ | ||
| </th> | ||
| <th style={{ | ||
| ...table.headerCellRight, | ||
| width: '100px', | ||
| padding: '8px 6px' | ||
| }}> | ||
| Нийт үнэ | ||
| </th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| {cartItems.map((item, index) => { | ||
| const totalItemPrice = item.count * item.unitPrice; | ||
|
|
||
| return ( | ||
| <tr key={item._id}> | ||
| <td style={{...table.cellCenter, padding: '6px'}}> | ||
| {index + 1} | ||
| </td> | ||
| <td style={{...table.cell, padding: '6px'}}> | ||
| <div> | ||
| <div style={table.productName}> | ||
| {item.productName} | ||
| </div> | ||
| {item.isTake && ( | ||
| <div style={{...table.takeAwayLabel, fontSize: '10px'}}> | ||
| ✓ Авч явах | ||
| </div> | ||
| )} | ||
| </div> | ||
| </td> | ||
| <td style={{...table.cellCenter, padding: '6px'}}> | ||
| {item.count} | ||
| </td> | ||
| <td style={{...table.cellRight, padding: '6px'}}> | ||
| {formatNum(item.unitPrice)}₮ | ||
| </td> | ||
| <td style={{...table.cellRightBold, padding: '6px'}}> | ||
| {formatNum(totalItemPrice)}₮ | ||
| </td> | ||
| </tr> | ||
| ) | ||
| })} | ||
| <tr style={{borderTop: '2px solid #374151'}}> | ||
| <td style={{...table.cell, padding: '6px', border: 'none'}} colSpan={3}></td> | ||
| <td style={{...table.cellRight, padding: '6px', fontWeight: 'bold'}}> | ||
| НӨАТ-гүй дүн: | ||
| </td> | ||
| <td style={{...table.cellRightBold, padding: '6px'}}> | ||
| {formatNum(totals.subtotal)}₮ | ||
| </td> | ||
| </tr> | ||
|
|
||
| <tr> | ||
| <td style={{...table.cell, padding: '6px', border: 'none'}} colSpan={3}></td> | ||
| <td style={{...table.cellRight, padding: '6px', fontWeight: 'bold'}}> | ||
| НӨАТ (10%): | ||
| </td> | ||
| <td style={{...table.cellRightBold, padding: '6px'}}> | ||
| {formatNum(totals.vat)}₮ | ||
| </td> | ||
| </tr> | ||
|
|
||
| <tr style={{backgroundColor: '#f3f4f6'}}> | ||
| <td style={{...table.cell, padding: '8px', border: 'none'}} colSpan={3}></td> | ||
| <td style={{ | ||
| ...table.cellRight, | ||
| padding: '8px', | ||
| fontWeight: 'bold', | ||
| fontSize: '14px' | ||
| }}> | ||
| Нийт төлбөр: | ||
| </td> | ||
| <td style={{ | ||
| ...table.cellRightBold, | ||
| padding: '8px', | ||
| fontSize: '14px', | ||
| color: '#059669' | ||
| }}> | ||
| {formatNum(totals.total)}₮ | ||
| </td> | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
| </div> | ||
| )} | ||
| </div> | ||
|
|
||
| <div style={userInfo.infoSection}> | ||
| <p> | ||
| <strong>{userName}</strong> {isCompany ? "байгууллагыг" : "нэр дээрх хүнийг"}{" "} | ||
| <strong>MN{userBankAddress}</strong> дугаартай банкны данс руу{" "} | ||
| <strong>{formatNum(total)}₮</strong> төгрөгийн төлбөрийг нэхэмжилж байна. | ||
| </p> | ||
| </div> | ||
|
|
||
| <div style={userInfo.signatureSection}> | ||
| <p style={userInfo.signatureLabel}>Гарын үсэг:</p> | ||
| <div style={userInfo.signatureLine}></div> | ||
| <p style={userInfo.signatureNote}>Нэхэмжлэл гаргасан</p> | ||
| <p>_________________________</p> | ||
| </div> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| export default InvoiceInfo |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The updated spread order in onSelectChange (using { _id: item._id, ...state, [field]: value }) may risk using a stale state value since setState is async. Consider using a functional update to guarantee the latest state.