Skip to content

Commit 89143d1

Browse files
🚧 v0.4.10 (#183)
* ⬆️ bump: v0.4.10 * fix: enable hotkeys on validation (#182) [Fixes #181] * enable hotkeys on validation * allow preview and reset * feat: Add rate option to Product (#189) * feat: Add rate option to Product * fix price Co-authored-by: Mohit K. Yadav <[email protected]> * feat: Add Gross is Net check box (#190) [Fixes #185] * feat: Print Payment Methods as per need (#191) * Add new payment method and print from app itself * Add sameLine bool to handle 4 payment method printing * fix cheq no width and credit bug Co-authored-by: Mohit K. Yadav <[email protected]> Co-authored-by: Mohit Kumar Yadav <[email protected]>
1 parent 78c380f commit 89143d1

File tree

10 files changed

+102
-30
lines changed

10 files changed

+102
-30
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "invoicify",
3-
"version": "0.4.9",
3+
"version": "0.4.10",
44
"author": "2AM Devs",
55
"description": "Digitalizes your billing process",
66
"private": true,

src/components/ImportProducts/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ const ImportProducts = ({ refreshProductItems }) => {
4343
const newLocalProducts = res?.map((item) => ({
4444
name: item[0],
4545
type: item[1],
46+
price: item[2],
4647
id: generateUuid4(),
4748
}))
4849
if (newLocalProducts?.length) {
4950
setNewProducts(newLocalProducts)
5051
toggleHideDialog()
5152
}
53+
// eslint-disable-next-line no-console
5254
}).catch(console.error)
5355
}
5456

src/components/Invoice/index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import {
1313
PREVIEW, PRINT, DATE, MASKED, ZERO, ISET, PAY_METHOD, defaultPrintSettings,
1414
} from '../../utils/constants'
1515
import {
16-
getFromStorage, getPdf, getInvoiceSettings, printPDF, currency, groupBy, generateUuid4,
16+
getFromStorage, getPdf, getInvoiceSettings, printPDF, currency,
17+
groupBy, generateUuid4, getProducts,
1718
} from '../../utils/helper'
1819
import Alert from '../Alert'
1920
import HoverTotal from '../HoverTotal'
@@ -41,6 +42,7 @@ const Invoice = ({ showPdfPreview }) => {
4142

4243
const [invoiceItems, setInvoiceItems] = useState(invoiceState.invoiceItems ?? [])
4344
const [isInvoiceItemFormOpen, setIsInvoiceItemFormOpen] = useState(false)
45+
const [isGrossWeightNetWeight, setIsGrossWeightNetWeight] = useState(false)
4446

4547
const openInvoiceItemsPanel = useConstCallback(() => setIsInvoiceItemFormOpen(true))
4648

@@ -73,6 +75,7 @@ const Invoice = ({ showPdfPreview }) => {
7375
oldPurchase: ZERO,
7476
grandTotal: ZERO,
7577
[PAY_METHOD.CHEQUE]: ZERO,
78+
[PAY_METHOD.CREDIT]: ZERO,
7679
[PAY_METHOD.CARD]: ZERO,
7780
[PAY_METHOD.UPI]: ZERO,
7881
[PAY_METHOD.CASH]: ZERO,
@@ -160,7 +163,7 @@ const Invoice = ({ showPdfPreview }) => {
160163
updatedInvoiceFooter = { ...invoiceFooter, ...change }
161164
}
162165
const {
163-
oldPurchase, grossTotal, cheque, card, upi, interState,
166+
oldPurchase, grossTotal, cheque, card, upi, interState, credit,
164167
} = updatedInvoiceFooter
165168
const calcSettings = getInvoiceSettings(ISET.CALC)
166169
const cgst = interState
@@ -178,7 +181,7 @@ const Invoice = ({ showPdfPreview }) => {
178181
igst,
179182
totalAmount,
180183
grandTotal: currency(totalAmount - oldPurchase),
181-
cash: currency(totalAmount - oldPurchase - card - cheque - upi),
184+
cash: currency(totalAmount - oldPurchase - card - cheque - upi - credit),
182185
})
183186
}
184187

@@ -221,6 +224,9 @@ const Invoice = ({ showPdfPreview }) => {
221224
setInvoiceItems(invoiceItems.map((item, i) => {
222225
if (i === index) {
223226
const newItem = { ...item, ...valueObject }
227+
if (valueObject.product && item.product !== valueObject.product) {
228+
newItem.price = getProducts(newItem.product).price
229+
}
224230
if (valueObject.isOldItem) {
225231
newItem.quantity = 1
226232
newItem.product = null
@@ -484,6 +490,8 @@ const Invoice = ({ showPdfPreview }) => {
484490
headerText="Invoice item"
485491
>
486492
<InvoiceItems
493+
isGrossWeightNetWeight={isGrossWeightNetWeight}
494+
setIsGrossWeightNetWeight={setIsGrossWeightNetWeight}
487495
invoiceItems={invoiceItems}
488496
currentInvoiceItemIndex={currentInvoiceItemIndex}
489497
currentInvoiceItem={invoiceItems[currentInvoiceItemIndex]}

src/components/InvoiceItems/index.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const columnProps = {
2121

2222
const InvoiceItems = ({
2323
currentInvoiceItem, currentInvoiceItemIndex, removeInvoiceItem, updateInvoiceItem,
24-
dismissInvoiceItemsPanel, addNewInvoiceItem,
24+
dismissInvoiceItemsPanel, addNewInvoiceItem, isGrossWeightNetWeight, setIsGrossWeightNetWeight
2525
}) => {
2626
const [itemsFilterValue, setItemsFilterValue] = useState('')
2727

@@ -32,6 +32,8 @@ const InvoiceItems = ({
3232
[stateKey]: value,
3333
...((stateKey === 'gWeight' && currentInvoiceItem.isOldItem)
3434
&& { weight: currency(value * currentInvoiceItem.purity * 0.01) }),
35+
...((stateKey === 'gWeight' && !currentInvoiceItem.isOldItem && isGrossWeightNetWeight)
36+
&& { weight: value }),
3537
}
3638
updateInvoiceItem(itemIndex, updateObject)
3739
setItemsFilterValue('')
@@ -80,6 +82,12 @@ const InvoiceItems = ({
8082
checked={currentInvoiceItem.isOldItem}
8183
onChange={(_, isChecked) => onChangeField(currentInvoiceItemIndex, 'isOldItem', isChecked)}
8284
/>
85+
<Checkbox
86+
className="invoice-items__item__weight-check"
87+
label="Gross W is the same as Net W"
88+
checked={isGrossWeightNetWeight}
89+
onChange={(_, isChecked) => setIsGrossWeightNetWeight(isChecked)}
90+
/>
8391

8492
<Stack
8593
horizontal
@@ -97,7 +105,11 @@ const InvoiceItems = ({
97105
label="Item name"
98106
options={filterComboBoxOptions(currentInvoiceItem.product)}
99107
selectedKey={currentInvoiceItem.product}
100-
onChange={(_, option) => option && onChangeField(currentInvoiceItemIndex, 'product', option.id)}
108+
onChange={(_, option) => {
109+
if (option) {
110+
onChangeField(currentInvoiceItemIndex, 'product', option.id)
111+
}
112+
}}
101113
onKeyUp={(e) => {
102114
if (!e.key.includes('Arrow')) {
103115
setItemsFilterValue(e.target.value)

src/components/InvoiceItems/index.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
align-items: center;
1010
margin: 1rem 0;
1111

12+
&__weight-check {
13+
margin-left: 1rem;
14+
}
15+
1216
&__field {
1317
width: 20rem;
1418
}

src/components/InvoicePageFooter/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class InvoicePageFooter extends React.Component {
3434

3535
keyDownHandler = (e) => {
3636
if (e.shiftKey && e.ctrlKey) {
37+
if (this.props.disablePrintButton) return
38+
3739
const { key, repeat } = e
3840
if (repeat) return
3941
if (key.toLowerCase() === 'p' && this.props.printWithBill) this.props.printWithBill()
@@ -50,6 +52,7 @@ class InvoicePageFooter extends React.Component {
5052
this.props.previewPDF()
5153
break
5254
case 'p':
55+
if (this.props.disablePrintButton) return
5356
this.props.printAndMove()
5457
break
5558
case 'r':

src/components/ProductForm/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,23 @@ const ProductForm = ({
1818
}) => {
1919
const [name, setName] = useState(product?.name ?? '')
2020
const [type, setType] = useState(product?.type ?? '')
21+
const [price, setPrice] = useState(product?.price ?? 0)
2122

2223
const changeName = (_, val) => setName(val)
24+
const changePrice = (_, val) => setPrice(val)
2325

2426
const changeType = (_, val) => setType(val.key)
2527

2628
const resetForm = () => {
2729
setName('')
2830
setType('')
31+
setPrice('')
2932
}
3033

3134
const saveForm = () => {
3235
const id = product?.id ?? generateUuid4()
3336
setProduct({
34-
name, id, type,
37+
name, id, type, price,
3538
})
3639
if (fetchItems) fetchItems()
3740
if (hideModal) hideModal()
@@ -63,6 +66,13 @@ const ProductForm = ({
6366
value={name}
6467
onChange={changeName}
6568
/>
69+
<TextField
70+
label="Price"
71+
required
72+
placeholder="Product Price"
73+
value={price}
74+
onChange={changePrice}
75+
/>
6676
<Dropdown
6777
placeholder="Product Type"
6878
required

src/utils/constants.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const PAY_METHOD = {
2323
CASH: 'cash',
2424
CHEQUE: 'cheque',
2525
CHEQUENO: 'chequeNumber',
26+
CREDIT: 'credit',
2627
UPI: 'upi',
2728
CARD: 'card',
2829
}
@@ -83,6 +84,19 @@ const productTableColumns = [
8384
key: 'column2',
8485
name: 'Type',
8586
fieldName: 'type',
87+
minWidth: 20,
88+
maxWidth: 20,
89+
isRowHeader: true,
90+
isResizable: true,
91+
isSorted: false,
92+
isSortedDescending: false,
93+
data: 'string',
94+
isPadded: true,
95+
},
96+
{
97+
key: 'column3',
98+
name: 'Price',
99+
fieldName: 'price',
86100
minWidth: 40,
87101
maxWidth: 40,
88102
isRowHeader: true,

src/utils/helper.js

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -351,29 +351,48 @@ const getPdf = async (invoiceDetails, mode = PRINT) => {
351351
}
352352

353353
// Print Distribution
354-
Object.keys(getInvoiceSettings(ISET.FOOTER)).forEach((item) => {
355-
if (footer[item]) {
356-
const isCN = item === PAY_METHOD.CHEQUENO
357-
page.drawText(
358-
`${isCN ? 'Cheque No.:' : ''} ${footer[item]} ${isCN ? '' : '/-'}`, {
359-
...getInvoiceSettings(ISET.FOOTER)[item],
360-
...commonFont,
361-
},
362-
)
363-
364-
if (isCN) {
365-
page.drawLine({
366-
start: {
367-
...getInvoiceSettings(ISET.FOOTER)[item],
368-
y: getInvoiceSettings(ISET.FOOTER)[item].y - 2.3,
369-
},
370-
end: {
371-
y: getInvoiceSettings(ISET.FOOTER)[item].y - 2.3,
372-
x: getInvoiceSettings(ISET.FOOTER)[item].x + 55,
354+
const startX = 210
355+
const yLimit = 190
356+
let startY = 220
357+
let prevPayLen = 0
358+
let sameLine = false
359+
Object.values(PAY_METHOD).forEach((item) => {
360+
const isCN = item === PAY_METHOD.CHEQUENO
361+
if (isCN && !footer[item]) {
362+
startY -= 15
363+
} else if (footer[item]) {
364+
const textContent = `${isCN ? 'Chq No:' : item.toUpperCase()}: ${+footer[item]} ${isCN ? '' : '/-'}`
365+
const currX = startX + ((isCN || sameLine) ? (prevPayLen + 10) : 0)
366+
367+
if (isCN && !footer[PAY_METHOD.CHEQUE]) {
368+
// eslint-disable-next-line no-console
369+
console.log('No Cheques Please')
370+
} else {
371+
page.drawText(
372+
textContent, {
373+
x: currX,
374+
y: startY,
375+
...commonFont,
373376
},
374-
thickness: 2,
375-
opacity: 0.75,
376-
})
377+
)
378+
379+
if (isCN) {
380+
page.drawLine({
381+
start: {
382+
x: currX,
383+
y: startY - 2.3,
384+
},
385+
end: {
386+
y: startY - 2.3,
387+
x: currX + 90,
388+
},
389+
thickness: 2,
390+
opacity: 0.75,
391+
})
392+
}
393+
sameLine = (startY === yLimit)
394+
startY -= ((item === PAY_METHOD.CHEQUE) || sameLine ? 0 : 15)
395+
prevPayLen = font.widthOfTextAtSize(textContent, fontSize)
377396
}
378397
}
379398
})

0 commit comments

Comments
 (0)