Skip to content

Commit

Permalink
Release v0.4.8 (#171)
Browse files Browse the repository at this point in the history
* ⏫ Bump Version

* feat: Make payment methods coordinates configurable  (#169)

* feat: Make payment methods coordinates configurable (Fixes #168)

* Handle NaN

* Make money look like money

* password protection for reset settings (#172)

* Init Reset Setting Protection

* password input in teaching bubble

Co-authored-by: Aashutosh Rathi <[email protected]>

* blur animate overlay behind panel (#173)

* blur animate overlay behind panel

* Don't reset password and products

* Fix hang on reset

Co-authored-by: Aashutosh Rathi <[email protected]>

* feat: Add option to print two copies with & without bg (#175)

* Make GSTIN and Address non mandatory

* Reload on reset

Co-authored-by: Mohit Kumar Yadav <[email protected]>
  • Loading branch information
aashutoshrathi and mohitkyadav authored Sep 6, 2020
1 parent 87dc7e0 commit 0499a45
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 47 deletions.
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.7",
"version": "0.4.8",
"author": "2AM Devs",
"description": "Digitalizes your billing process",
"private": true,
Expand Down
12 changes: 10 additions & 2 deletions src/components/Header/HeaderRightSection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ const HeaderRightSection = ({ refreshCompanyName }) => {
setProductsCount(getProducts().length || 0)
}

const reloadStuff = () => history.push('/')

const lockIt = () => {
updateAuthState({ isAuthenticated: false })
if (window.location.hash !== '#/') history.push('/')
if (window.location.hash !== '#/') reloadStuff()
}

useEffect(() => {
Expand Down Expand Up @@ -116,7 +118,13 @@ const HeaderRightSection = ({ refreshCompanyName }) => {
closeButtonAriaLabel="Close"
headerText="Settings"
>
<Settings refreshCompanyName={refreshCompanyName} />
<Settings
refreshCompanyName={refreshCompanyName}
reloadPage={() => {
dismissSettingsPanel()
reloadStuff()
}}
/>
</Panel>
</div>
)
Expand Down
31 changes: 24 additions & 7 deletions src/components/Invoice/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,36 @@ const Invoice = ({ showPdfPreview }) => {
setInvoiceFooter(defaultInvoiceFooter)
}

const moveAhead = () => {
localStorage.invoiceNumber = invoice['Invoice Number'] + 1
resetForm()
}

const printAndMove = (_, includeBill) => {
fetchPDF(includeBill && PREVIEW).then((pdfBytes) => {
if (pdfBytes?.error) {
setAlertDetails(PdfPathError)
setHideAlert(false)
return
return false
}
return printPDF(pdfBytes)
}).then((oneGone) => {
if (oneGone && getFromStorage('printBoth')) {
fetchPDF(PREVIEW).then((pdfBytes) => {
if (pdfBytes?.error) {
setAlertDetails(PdfPathError)
setHideAlert(false)
return
}
printPDF(pdfBytes).then((fin) => {
if (fin) {
moveAhead()
}
})
})
} else if (oneGone) {
moveAhead()
}
printPDF(pdfBytes).then((res) => {
if (res) {
localStorage.invoiceNumber = invoice['Invoice Number'] + 1
resetForm()
}
})
})
}

Expand Down
71 changes: 61 additions & 10 deletions src/components/Settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { useState, useEffect } from 'react'
import { DefaultButton } from 'office-ui-fabric-react'
import { Spinner, SpinnerSize } from 'office-ui-fabric-react/lib/Spinner'
import { Stack } from 'office-ui-fabric-react/lib/Stack'
import { TeachingBubble } from 'office-ui-fabric-react/lib/TeachingBubble'
import { TextField } from 'office-ui-fabric-react/lib/TextField'
import { Toggle } from 'office-ui-fabric-react/lib/Toggle'

Expand All @@ -20,7 +21,7 @@ const { ipcRenderer } = require('electron')
const stackTokens = { childrenGap: 15 }
const stackStyles = { root: { width: '40rem' } }

const Settings = ({ refreshCompanyName }) => {
const Settings = ({ refreshCompanyName, reloadPage }) => {
const [checkingPath, setCheckingPath] = useState(false)
const [hideDialog, setHideDialog] = useState(true)
const [previewBill, setPreviewBill] = useState(getFromStorage('previewPDFUrl'))
Expand All @@ -33,6 +34,10 @@ const Settings = ({ refreshCompanyName }) => {
const [font, setFont] = useState(getFromStorage('customFont'))
const [gstinPrefix, setGstinPrefix] = useState(getFromStorage('nativeGstinPrefix'))
const [currency, setCurrency] = useState(getFromStorage('currency'))
const [showAuthModal, setShowAuthModal] = useState(false)
const [resetSettingsPasswordError, setResetSettingsPasswordError] = useState('')
const [resetSettingsPassword, setResetSettingsPassword] = useState('')
const [printBoth, setPrintBoth] = useState(getFromStorage('printBoth'))

useEffect(() => {
// eslint-disable-next-line func-names
Expand All @@ -48,6 +53,11 @@ const Settings = ({ refreshCompanyName }) => {
setHindiDate(checked)
}

const onChangePrintBoth = (_, c) => {
localStorage.printBoth = c
setPrintBoth(c)
}

const onMonthShowChange = (_, checked) => {
localStorage.showFullMonth = checked
setShowFullMonth(checked)
Expand Down Expand Up @@ -90,12 +100,17 @@ const Settings = ({ refreshCompanyName }) => {

const resetAndUpdate = () => {
resetSettings()
setPreviewBill(getFromStorage('previewPDFUrl'))
setProductType(getFromStorage('productType'))
setInvoiceNumber(getFromStorage('invoiceNumber'))
setCompanyName(getFromStorage('companyName'))
setHindiDate(getFromStorage('hindiDate'))
setFont(getFromStorage('customFont'))
}

const verifyAndReset = () => {
if (resetSettingsPassword === getFromStorage('password')) {
resetAndUpdate()
setResetSettingsPasswordError(null)
setShowAuthModal(false)
reloadPage()
} else {
setResetSettingsPasswordError('Incorrect Password')
}
}

const onProductTypeChange = (_, newValue) => {
Expand Down Expand Up @@ -136,17 +151,22 @@ const Settings = ({ refreshCompanyName }) => {
horizontal
>
<TextField
label="Next Invoice Number"
label="Next Invoice"
onChange={onInvoiceNoChange}
value={invoiceNumber}
description="You can change next invoice number here"
/>
<TextField
label="Default Currency Symbol"
label="Currency Symbol"
onChange={onCurrencyChange}
value={currency}
description="Currency Symbol will be used in printing"
/>
<Toggle
label="Print Both Types"
checked={printBoth}
onChange={onChangePrintBoth}
/>
</Stack>
<Stack
tokens={stackTokens}
Expand Down Expand Up @@ -219,9 +239,10 @@ const Settings = ({ refreshCompanyName }) => {
/>
<DefaultButton
text="Reset Settings"
id="targetButton"
iconProps={{ iconName: 'FullHistory' }}
primary
onClick={resetAndUpdate}
onClick={() => setShowAuthModal(true)}
styles={{ root: { width: '18rem' } }}
/>
<br />
Expand Down Expand Up @@ -255,6 +276,36 @@ const Settings = ({ refreshCompanyName }) => {
/>
)}
</Stack>
{showAuthModal && (
<TeachingBubble
target="#targetButton"
primaryButtonProps={{
text: 'Reset',
onClick: () => {
verifyAndReset()
},
}}
secondaryButtonProps={{
text: 'Cancel',
onClick: () => {
setResetSettingsPasswordError('')
setShowAuthModal(false)
},
}}
onDismiss={() => {
setResetSettingsPasswordError('')
setShowAuthModal(false)
}}
headline="Authenticate yourself to reset 🔐"
>
<TextField
placeholder="Enter password"
type="password"
onChange={(_, val) => setResetSettingsPassword(val)}
errorMessage={resetSettingsPasswordError}
/>
</TeachingBubble>
)}
</div>
)
}
Expand Down
16 changes: 16 additions & 0 deletions src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,19 @@ code {
display: flex;
flex-direction: row;
}

@keyframes fadeUp {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}

.ms-Overlay {
animation: fadeUp forwards 0.5s;
-webkit-backdrop-filter: blur(0.8rem);
backdrop-filter: blur(0.8rem);
background-color: var(--color-black-op-20);
}
9 changes: 6 additions & 3 deletions src/pages/InvoiceSettings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,24 @@ const InvoiceSettings = () => {
<br />

<Stack
{...token}
key="Footer Stuff"
>
{Object.keys(footerPrintSettings).map((key) => (
<Stack
horizontal
{...token}
key
key={key}
>
{Object.keys(footerPrintSettings[key]).map((subkey) => (
<TextField
label={`${subkey.toUpperCase()} (${titleCase(key)})`}
key={`${key} ${subkey}`}
onChange={(_, val) => handleChange(0, key,
{ ...footerPrintSettings[key], [subkey]: parseInt(val, 10) }, ISET.FOOTER)}
{
...footerPrintSettings[key],
// eslint-disable-next-line no-restricted-globals
[subkey]: isNaN(parseFloat(val)) ? 0 : parseFloat(val),
}, ISET.FOOTER)}
value={footerPrintSettings[key][subkey]}
/>
))}
Expand Down
24 changes: 20 additions & 4 deletions src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ const defaultPrintSettings = [
name: 'GSTIN',
x: 100,
y: 641,
required: true,
required: false,
disabled: false,
type: TEXT,
inputLength: 15,
Expand All @@ -259,7 +259,7 @@ const defaultPrintSettings = [
name: 'Address',
x: 257,
y: 641,
required: true,
required: false,
disabled: false,
type: TEXT,
row: 4,
Expand All @@ -275,9 +275,25 @@ const morePrintSettings = {
}

const footerPrintSettings = {
[PAY_METHOD.CASH]: {
x: 242,
y: 220,
},
[PAY_METHOD.CHEQUE]: {
x: 349,
y: 220,
},
[PAY_METHOD.CHEQUENO]: {
x: 299,
y: 205,
x: 303,
y: 207,
},
[PAY_METHOD.CARD]: {
x: 238,
y: 188,
},
[PAY_METHOD.UPI]: {
x: 324,
y: 188,
},
}

Expand Down
44 changes: 24 additions & 20 deletions src/utils/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const initializeSettings = async () => {
localStorage.products = localStorage.products ?? '[]'
localStorage.password = localStorage.password ?? ''
localStorage.showFullMonth = localStorage.showFullMonth ?? true
localStorage.printBoth = localStorage.printBoth ?? true
localStorage.productType = localStorage.productType ?? 'G, S'
localStorage.customFont = localStorage.customFont ?? CUSTOM_FONT
localStorage.currency = localStorage.currency ?? '₹'
Expand Down Expand Up @@ -340,30 +341,30 @@ const getPdf = async (invoiceDetails, mode = PRINT) => {
}

// Print Distribution
page.drawText(...footerCommonParts(219, PAY_METHOD.CASH, 255))
page.drawText(...footerCommonParts(219, PAY_METHOD.CHEQUE, 356))
page.drawText(...footerCommonParts(190, PAY_METHOD.UPI, 330))
page.drawText(...footerCommonParts(190, PAY_METHOD.CARD, 255))

// Currently things are coded for Cheque number
Object.keys(getInvoiceSettings(ISET.FOOTER)).forEach((item) => {
if (footer[item]) {
page.drawText(`Cheque No.: ${footer[item]}`, {
...getInvoiceSettings(ISET.FOOTER)[item],
...commonFont,
})
page.drawLine({
start: {
const isCN = item === PAY_METHOD.CHEQUENO
page.drawText(
`${isCN ? 'Cheque No.:' : ''} ${footer[item]} ${isCN ? '' : '/-'}`, {
...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,
...commonFont,
},
thickness: 2,
opacity: 0.75,
})
)

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,
},
thickness: 2,
opacity: 0.75,
})
}
}
})

Expand Down Expand Up @@ -423,7 +424,10 @@ const restartApp = () => {
}

const resetSettings = () => {
const { password, products } = localStorage
localStorage.clear()
localStorage.password = password
localStorage.products = products
initializeSettings()
}

Expand Down

0 comments on commit 0499a45

Please sign in to comment.