Skip to content

Commit

Permalink
🚧 v0.4.10 (#183)
Browse files Browse the repository at this point in the history
* ⬆️ 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 <mohitkyadav@outlook.com>

* 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 <mohitkyadav@outlook.com>

Co-authored-by: Mohit Kumar Yadav <mohitkyadav@outlook.com>
  • Loading branch information
aashutoshrathi and mohitkyadav authored Nov 1, 2020
1 parent 78c380f commit 89143d1
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 30 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "invoicify",
"version": "0.4.9",
"version": "0.4.10",
"author": "2AM Devs",
"description": "Digitalizes your billing process",
"private": true,
Expand Down
2 changes: 2 additions & 0 deletions src/components/ImportProducts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ const ImportProducts = ({ refreshProductItems }) => {
const newLocalProducts = res?.map((item) => ({
name: item[0],
type: item[1],
price: item[2],
id: generateUuid4(),
}))
if (newLocalProducts?.length) {
setNewProducts(newLocalProducts)
toggleHideDialog()
}
// eslint-disable-next-line no-console
}).catch(console.error)
}

Expand Down
14 changes: 11 additions & 3 deletions src/components/Invoice/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
PREVIEW, PRINT, DATE, MASKED, ZERO, ISET, PAY_METHOD, defaultPrintSettings,
} from '../../utils/constants'
import {
getFromStorage, getPdf, getInvoiceSettings, printPDF, currency, groupBy, generateUuid4,
getFromStorage, getPdf, getInvoiceSettings, printPDF, currency,
groupBy, generateUuid4, getProducts,
} from '../../utils/helper'
import Alert from '../Alert'
import HoverTotal from '../HoverTotal'
Expand Down Expand Up @@ -41,6 +42,7 @@ const Invoice = ({ showPdfPreview }) => {

const [invoiceItems, setInvoiceItems] = useState(invoiceState.invoiceItems ?? [])
const [isInvoiceItemFormOpen, setIsInvoiceItemFormOpen] = useState(false)
const [isGrossWeightNetWeight, setIsGrossWeightNetWeight] = useState(false)

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

Expand Down Expand Up @@ -73,6 +75,7 @@ const Invoice = ({ showPdfPreview }) => {
oldPurchase: ZERO,
grandTotal: ZERO,
[PAY_METHOD.CHEQUE]: ZERO,
[PAY_METHOD.CREDIT]: ZERO,
[PAY_METHOD.CARD]: ZERO,
[PAY_METHOD.UPI]: ZERO,
[PAY_METHOD.CASH]: ZERO,
Expand Down Expand Up @@ -160,7 +163,7 @@ const Invoice = ({ showPdfPreview }) => {
updatedInvoiceFooter = { ...invoiceFooter, ...change }
}
const {
oldPurchase, grossTotal, cheque, card, upi, interState,
oldPurchase, grossTotal, cheque, card, upi, interState, credit,
} = updatedInvoiceFooter
const calcSettings = getInvoiceSettings(ISET.CALC)
const cgst = interState
Expand All @@ -178,7 +181,7 @@ const Invoice = ({ showPdfPreview }) => {
igst,
totalAmount,
grandTotal: currency(totalAmount - oldPurchase),
cash: currency(totalAmount - oldPurchase - card - cheque - upi),
cash: currency(totalAmount - oldPurchase - card - cheque - upi - credit),
})
}

Expand Down Expand Up @@ -221,6 +224,9 @@ const Invoice = ({ showPdfPreview }) => {
setInvoiceItems(invoiceItems.map((item, i) => {
if (i === index) {
const newItem = { ...item, ...valueObject }
if (valueObject.product && item.product !== valueObject.product) {
newItem.price = getProducts(newItem.product).price
}
if (valueObject.isOldItem) {
newItem.quantity = 1
newItem.product = null
Expand Down Expand Up @@ -484,6 +490,8 @@ const Invoice = ({ showPdfPreview }) => {
headerText="Invoice item"
>
<InvoiceItems
isGrossWeightNetWeight={isGrossWeightNetWeight}
setIsGrossWeightNetWeight={setIsGrossWeightNetWeight}
invoiceItems={invoiceItems}
currentInvoiceItemIndex={currentInvoiceItemIndex}
currentInvoiceItem={invoiceItems[currentInvoiceItemIndex]}
Expand Down
16 changes: 14 additions & 2 deletions src/components/InvoiceItems/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const columnProps = {

const InvoiceItems = ({
currentInvoiceItem, currentInvoiceItemIndex, removeInvoiceItem, updateInvoiceItem,
dismissInvoiceItemsPanel, addNewInvoiceItem,
dismissInvoiceItemsPanel, addNewInvoiceItem, isGrossWeightNetWeight, setIsGrossWeightNetWeight
}) => {
const [itemsFilterValue, setItemsFilterValue] = useState('')

Expand All @@ -32,6 +32,8 @@ const InvoiceItems = ({
[stateKey]: value,
...((stateKey === 'gWeight' && currentInvoiceItem.isOldItem)
&& { weight: currency(value * currentInvoiceItem.purity * 0.01) }),
...((stateKey === 'gWeight' && !currentInvoiceItem.isOldItem && isGrossWeightNetWeight)
&& { weight: value }),
}
updateInvoiceItem(itemIndex, updateObject)
setItemsFilterValue('')
Expand Down Expand Up @@ -80,6 +82,12 @@ const InvoiceItems = ({
checked={currentInvoiceItem.isOldItem}
onChange={(_, isChecked) => onChangeField(currentInvoiceItemIndex, 'isOldItem', isChecked)}
/>
<Checkbox
className="invoice-items__item__weight-check"
label="Gross W is the same as Net W"
checked={isGrossWeightNetWeight}
onChange={(_, isChecked) => setIsGrossWeightNetWeight(isChecked)}
/>

<Stack
horizontal
Expand All @@ -97,7 +105,11 @@ const InvoiceItems = ({
label="Item name"
options={filterComboBoxOptions(currentInvoiceItem.product)}
selectedKey={currentInvoiceItem.product}
onChange={(_, option) => option && onChangeField(currentInvoiceItemIndex, 'product', option.id)}
onChange={(_, option) => {
if (option) {
onChangeField(currentInvoiceItemIndex, 'product', option.id)
}
}}
onKeyUp={(e) => {
if (!e.key.includes('Arrow')) {
setItemsFilterValue(e.target.value)
Expand Down
4 changes: 4 additions & 0 deletions src/components/InvoiceItems/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
align-items: center;
margin: 1rem 0;

&__weight-check {
margin-left: 1rem;
}

&__field {
width: 20rem;
}
Expand Down
3 changes: 3 additions & 0 deletions src/components/InvoicePageFooter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class InvoicePageFooter extends React.Component {

keyDownHandler = (e) => {
if (e.shiftKey && e.ctrlKey) {
if (this.props.disablePrintButton) return

const { key, repeat } = e
if (repeat) return
if (key.toLowerCase() === 'p' && this.props.printWithBill) this.props.printWithBill()
Expand All @@ -50,6 +52,7 @@ class InvoicePageFooter extends React.Component {
this.props.previewPDF()
break
case 'p':
if (this.props.disablePrintButton) return
this.props.printAndMove()
break
case 'r':
Expand Down
12 changes: 11 additions & 1 deletion src/components/ProductForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,23 @@ const ProductForm = ({
}) => {
const [name, setName] = useState(product?.name ?? '')
const [type, setType] = useState(product?.type ?? '')
const [price, setPrice] = useState(product?.price ?? 0)

const changeName = (_, val) => setName(val)
const changePrice = (_, val) => setPrice(val)

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

const resetForm = () => {
setName('')
setType('')
setPrice('')
}

const saveForm = () => {
const id = product?.id ?? generateUuid4()
setProduct({
name, id, type,
name, id, type, price,
})
if (fetchItems) fetchItems()
if (hideModal) hideModal()
Expand Down Expand Up @@ -63,6 +66,13 @@ const ProductForm = ({
value={name}
onChange={changeName}
/>
<TextField
label="Price"
required
placeholder="Product Price"
value={price}
onChange={changePrice}
/>
<Dropdown
placeholder="Product Type"
required
Expand Down
14 changes: 14 additions & 0 deletions src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const PAY_METHOD = {
CASH: 'cash',
CHEQUE: 'cheque',
CHEQUENO: 'chequeNumber',
CREDIT: 'credit',
UPI: 'upi',
CARD: 'card',
}
Expand Down Expand Up @@ -83,6 +84,19 @@ const productTableColumns = [
key: 'column2',
name: 'Type',
fieldName: 'type',
minWidth: 20,
maxWidth: 20,
isRowHeader: true,
isResizable: true,
isSorted: false,
isSortedDescending: false,
data: 'string',
isPadded: true,
},
{
key: 'column3',
name: 'Price',
fieldName: 'price',
minWidth: 40,
maxWidth: 40,
isRowHeader: true,
Expand Down
63 changes: 41 additions & 22 deletions src/utils/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,29 +351,48 @@ const getPdf = async (invoiceDetails, mode = PRINT) => {
}

// Print Distribution
Object.keys(getInvoiceSettings(ISET.FOOTER)).forEach((item) => {
if (footer[item]) {
const isCN = item === PAY_METHOD.CHEQUENO
page.drawText(
`${isCN ? 'Cheque No.:' : ''} ${footer[item]} ${isCN ? '' : '/-'}`, {
...getInvoiceSettings(ISET.FOOTER)[item],
...commonFont,
},
)

if (isCN) {
page.drawLine({
start: {
...getInvoiceSettings(ISET.FOOTER)[item],
y: getInvoiceSettings(ISET.FOOTER)[item].y - 2.3,
},
end: {
y: getInvoiceSettings(ISET.FOOTER)[item].y - 2.3,
x: getInvoiceSettings(ISET.FOOTER)[item].x + 55,
const startX = 210
const yLimit = 190
let startY = 220
let prevPayLen = 0
let sameLine = false
Object.values(PAY_METHOD).forEach((item) => {
const isCN = item === PAY_METHOD.CHEQUENO
if (isCN && !footer[item]) {
startY -= 15
} else if (footer[item]) {
const textContent = `${isCN ? 'Chq No:' : item.toUpperCase()}: ${+footer[item]} ${isCN ? '' : '/-'}`
const currX = startX + ((isCN || sameLine) ? (prevPayLen + 10) : 0)

if (isCN && !footer[PAY_METHOD.CHEQUE]) {
// eslint-disable-next-line no-console
console.log('No Cheques Please')
} else {
page.drawText(
textContent, {
x: currX,
y: startY,
...commonFont,
},
thickness: 2,
opacity: 0.75,
})
)

if (isCN) {
page.drawLine({
start: {
x: currX,
y: startY - 2.3,
},
end: {
y: startY - 2.3,
x: currX + 90,
},
thickness: 2,
opacity: 0.75,
})
}
sameLine = (startY === yLimit)
startY -= ((item === PAY_METHOD.CHEQUE) || sameLine ? 0 : 15)
prevPayLen = font.widthOfTextAtSize(textContent, fontSize)
}
}
})
Expand Down

0 comments on commit 89143d1

Please sign in to comment.