-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* CM-508: add payroll files tab * CM-508: fix linter --------- Co-authored-by: Jan <[email protected]>
- Loading branch information
1 parent
988496a
commit f35ebde
Showing
8 changed files
with
252 additions
and
7 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { bindActionCreators } from 'redux'; | ||
|
||
import { IconButton, Tooltip } from '@material-ui/core'; | ||
import DownloadIcon from '@material-ui/icons/CloudDownload'; | ||
|
||
import { | ||
Searcher, | ||
useModulesManager, | ||
useTranslations, | ||
} from '@openimis/fe-core'; | ||
import { | ||
DEFAULT_PAGE_SIZE, MODULE_NAME, | ||
ROWS_PER_PAGE_OPTIONS, PAYROLL_PAYMENT_FILE_STATUS, | ||
} from '../../constants'; | ||
import { fetchPayrollPaymentFiles } from '../../actions'; | ||
import downloadPayroll from '../../utils/export'; | ||
|
||
function PayrollPaymentFilesSearcher({ | ||
fetchingPayrollFiles, | ||
fetchedPayrollFiles, | ||
errorPayrollFiles, | ||
files, | ||
pageInfo, | ||
totalCount, | ||
fetchPayrollPaymentFiles, | ||
payrollUuid, | ||
}) { | ||
const modulesManager = useModulesManager(); | ||
const { formatMessage, formatMessageWithValues } = useTranslations(MODULE_NAME, modulesManager); | ||
|
||
const headers = () => [ | ||
'payrollPaymentFile.fileName', | ||
'payrollPaymentFile.status', | ||
'payrollPaymentFile.download', | ||
]; | ||
|
||
const defaultFilters = () => { | ||
const filters = { | ||
isDeleted: { | ||
value: false, | ||
filter: 'isDeleted: false', | ||
}, | ||
}; | ||
if (payrollUuid) { | ||
filters.payrollId = { | ||
value: payrollUuid, | ||
filter: `payroll_Id: "${payrollUuid}"`, | ||
}; | ||
} | ||
return filters; | ||
}; | ||
|
||
const download = (payrollId, fileName) => { | ||
downloadPayroll(payrollId, fileName, false); | ||
}; | ||
|
||
const fetchFiles = (params) => fetchPayrollPaymentFiles(modulesManager, params); | ||
|
||
const rowIdentifier = (file) => file.fileName; | ||
|
||
const itemFormatters = () => [ | ||
(file) => file.fileName, | ||
(file) => file.status, | ||
(file) => ( | ||
<Tooltip title={formatMessage('tooltip.delete')}> | ||
<IconButton | ||
onClick={() => download(payrollUuid, file.fileName)} | ||
disabled={file.status !== PAYROLL_PAYMENT_FILE_STATUS.SUCCESS} | ||
> | ||
<DownloadIcon /> | ||
</IconButton> | ||
</Tooltip> | ||
), | ||
]; | ||
|
||
return ( | ||
<Searcher | ||
module="payroll" | ||
FilterPane={null} | ||
fetch={fetchFiles} | ||
items={files} | ||
itemsPageInfo={pageInfo} | ||
fetchedItems={fetchedPayrollFiles} | ||
fetchingItems={fetchingPayrollFiles} | ||
errorItems={errorPayrollFiles} | ||
tableTitle={formatMessageWithValues('payrollPaymentFilesSearcher.results', { totalCount })} | ||
headers={headers} | ||
itemFormatters={itemFormatters} | ||
rowsPerPageOptions={ROWS_PER_PAGE_OPTIONS} | ||
defaultPageSize={DEFAULT_PAGE_SIZE} | ||
rowIdentifier={rowIdentifier} | ||
defaultFilters={defaultFilters()} | ||
/> | ||
); | ||
} | ||
const mapStateToProps = (state) => ({ | ||
fetchingPayrollFiles: state.payroll.fetchingPayrollFiles, | ||
fetchedPayrollFiles: state.payroll.fetchedPayrollFiles, | ||
errorPayrollFiles: state.payroll.errorPayrollFiles, | ||
files: state.payroll.payrollFiles, | ||
pageInfo: state.payroll.payrollFilesPageInfo, | ||
totalCount: state.payroll.payrollFilesTotalCount, | ||
}); | ||
|
||
const mapDispatchToProps = (dispatch) => bindActionCreators({ | ||
fetchPayrollPaymentFiles, | ||
}, dispatch); | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(PayrollPaymentFilesSearcher); |
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,53 @@ | ||
import React from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { Tab } from '@material-ui/core'; | ||
import { PublishedComponent, useTranslations } from '@openimis/fe-core'; | ||
import { | ||
MODULE_NAME, PAYROLL_PAYMENT_FILES_TAB_VALUE, | ||
} from '../../constants'; | ||
import PayrollPaymentFilesSearcher from './PayrollPaymentFilesSearcher'; | ||
|
||
function PayrollPaymentFilesTabLabel({ | ||
onChange, tabStyle, isSelected, modulesManager, payrollUuid, isInTask, isPayrollFromFailedInvoices, | ||
}) { | ||
const { formatMessage } = useTranslations(MODULE_NAME, modulesManager); | ||
if (!payrollUuid || isInTask || isPayrollFromFailedInvoices) { | ||
return null; | ||
} | ||
return ( | ||
<Tab | ||
onChange={onChange} | ||
className={tabStyle(PAYROLL_PAYMENT_FILES_TAB_VALUE)} | ||
selected={isSelected(PAYROLL_PAYMENT_FILES_TAB_VALUE)} | ||
value={PAYROLL_PAYMENT_FILES_TAB_VALUE} | ||
label={formatMessage('PayrollPaymentFilesTab.label')} | ||
/> | ||
); | ||
} | ||
|
||
function PayrollPaymentFilesTabPanel({ value, payrollUuid, isInTask }) { | ||
const rights = useSelector((store) => store?.core?.user?.i_user?.rights ?? []); | ||
if (isInTask) return null; | ||
|
||
return ( | ||
<PublishedComponent | ||
pubRef="policyHolder.TabPanel" | ||
module="payroll" | ||
index={PAYROLL_PAYMENT_FILES_TAB_VALUE} | ||
value={value} | ||
> | ||
{ | ||
payrollUuid && ( | ||
<PayrollPaymentFilesSearcher | ||
module="payroll" | ||
payrollUuid={payrollUuid} | ||
rights={rights} | ||
showFilters={false} | ||
/> | ||
) | ||
} | ||
</PublishedComponent> | ||
); | ||
} | ||
|
||
export { PayrollPaymentFilesTabLabel, PayrollPaymentFilesTabPanel }; |
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
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 |
---|---|---|
@@ -1,20 +1,25 @@ | ||
import { baseApiUrl } from '@openimis/fe-core'; | ||
|
||
export default function downloadPayroll(payrollId, payrollName) { | ||
export default function downloadPayroll(payrollId, payrollFileName, blank = true) { | ||
const url = new URL( | ||
`${window.location.origin}${baseApiUrl}/payroll/csv_reconciliation/?payroll_id=${payrollId}`, | ||
`${window.location.origin}${baseApiUrl}/payroll/csv_reconciliation/`, | ||
); | ||
url.searchParams.append('payroll_id', payrollId); | ||
url.searchParams.append('blank', blank); | ||
url.searchParams.append('payroll_file_name', payrollFileName); | ||
|
||
fetch(url) | ||
.then((response) => response.blob()) | ||
.then((blob) => { | ||
const link = document.createElement('a'); | ||
link.href = URL.createObjectURL(blob); | ||
link.download = `reconciliation_${payrollName}.csv`; | ||
link.download = blank ? `reconciliation_${payrollFileName}.csv` : payrollFileName; | ||
document.body.appendChild(link); | ||
link.click(); | ||
document.body.removeChild(link); | ||
}) | ||
.catch((error) => { | ||
// eslint-disable-next-line no-console | ||
console.error('Export failed, reason: ', error); | ||
}); | ||
} |