IO-1864 Mark bills as exported in bulk.
This commit is contained in:
@@ -14,6 +14,7 @@ import { connect } from "react-redux";
|
|||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||||
import ExportLogsCountDisplay from "../export-logs-count-display/export-logs-count-display.component";
|
import ExportLogsCountDisplay from "../export-logs-count-display/export-logs-count-display.component";
|
||||||
|
import BillMarkSelectedExported from "../payable-mark-selected-exported/payable-mark-selected-exported.component";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop,
|
bodyshop: selectBodyshop,
|
||||||
@@ -28,7 +29,12 @@ export default connect(
|
|||||||
mapDispatchToProps
|
mapDispatchToProps
|
||||||
)(AccountingPayablesTableComponent);
|
)(AccountingPayablesTableComponent);
|
||||||
|
|
||||||
export function AccountingPayablesTableComponent({ bodyshop, loading, bills, refetch }) {
|
export function AccountingPayablesTableComponent({
|
||||||
|
bodyshop,
|
||||||
|
loading,
|
||||||
|
bills,
|
||||||
|
refetch,
|
||||||
|
}) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [selectedBills, setSelectedBills] = useState([]);
|
const [selectedBills, setSelectedBills] = useState([]);
|
||||||
const [transInProgress, setTransInProgress] = useState(false);
|
const [transInProgress, setTransInProgress] = useState(false);
|
||||||
@@ -143,15 +149,13 @@ export function AccountingPayablesTableComponent({ bodyshop, loading, bills, ref
|
|||||||
sorter: (a, b) => a.clm_total - b.clm_total,
|
sorter: (a, b) => a.clm_total - b.clm_total,
|
||||||
|
|
||||||
render: (text, record) => (
|
render: (text, record) => (
|
||||||
<div>
|
<PayableExportButton
|
||||||
<PayableExportButton
|
billId={record.id}
|
||||||
billId={record.id}
|
disabled={transInProgress || !!record.exported}
|
||||||
disabled={transInProgress || !!record.exported}
|
loadingCallback={setTransInProgress}
|
||||||
loadingCallback={setTransInProgress}
|
setSelectedBills={setSelectedBills}
|
||||||
setSelectedBills={setSelectedBills}
|
refetch={refetch}
|
||||||
refetch={refetch}
|
/>
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@@ -177,6 +181,13 @@ export function AccountingPayablesTableComponent({ bodyshop, loading, bills, ref
|
|||||||
<Card
|
<Card
|
||||||
extra={
|
extra={
|
||||||
<Space wrap>
|
<Space wrap>
|
||||||
|
<BillMarkSelectedExported
|
||||||
|
billids={selectedBills}
|
||||||
|
disabled={transInProgress || selectedBills.length === 0}
|
||||||
|
loadingCallback={setTransInProgress}
|
||||||
|
completedCallback={setSelectedBills}
|
||||||
|
refetch={refetch}
|
||||||
|
/>
|
||||||
<PayableExportAll
|
<PayableExportAll
|
||||||
billids={selectedBills}
|
billids={selectedBills}
|
||||||
disabled={transInProgress || selectedBills.length === 0}
|
disabled={transInProgress || selectedBills.length === 0}
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
import { gql, useMutation } from "@apollo/client";
|
||||||
|
import { Button, notification } from "antd";
|
||||||
|
import React, { useState } from "react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { connect } from "react-redux";
|
||||||
|
import { createStructuredSelector } from "reselect";
|
||||||
|
import {
|
||||||
|
selectAuthLevel,
|
||||||
|
selectBodyshop,
|
||||||
|
} from "../../redux/user/user.selectors";
|
||||||
|
|
||||||
|
const mapStateToProps = createStructuredSelector({
|
||||||
|
bodyshop: selectBodyshop,
|
||||||
|
authLevel: selectAuthLevel,
|
||||||
|
});
|
||||||
|
const mapDispatchToProps = (dispatch) => ({
|
||||||
|
//setUserLanguage: language => dispatch(setUserLanguage(language))
|
||||||
|
});
|
||||||
|
|
||||||
|
export default connect(
|
||||||
|
mapStateToProps,
|
||||||
|
mapDispatchToProps
|
||||||
|
)(BillMarkSelectedExported);
|
||||||
|
|
||||||
|
export function BillMarkSelectedExported({
|
||||||
|
billids,
|
||||||
|
disabled,
|
||||||
|
loadingCallback,
|
||||||
|
completedCallback,
|
||||||
|
refetch,
|
||||||
|
}) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
const [updateBill] = useMutation(gql`
|
||||||
|
mutation UPDATE_BILL($billIds: [uuid!]!) {
|
||||||
|
update_bills(where: { id: { _in: $billIds } }, _set: { exported: true }) {
|
||||||
|
returning {
|
||||||
|
id
|
||||||
|
exported
|
||||||
|
exported_at
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
|
||||||
|
const handleUpdate = async () => {
|
||||||
|
setLoading(true);
|
||||||
|
loadingCallback(true);
|
||||||
|
const result = await updateBill({
|
||||||
|
variables: { billIds: billids },
|
||||||
|
update(cache){
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!result.errors) {
|
||||||
|
notification["success"]({
|
||||||
|
message: t("bills.successes.markexported"),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
notification["error"]({
|
||||||
|
message: t("bills.errors.saving", {
|
||||||
|
error: JSON.stringify(result.errors),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
loadingCallback(false);
|
||||||
|
completedCallback && completedCallback([]);
|
||||||
|
setLoading(false);
|
||||||
|
refetch && refetch();
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Button loading={loading} disabled={disabled} onClick={handleUpdate}>
|
||||||
|
{t("bills.labels.markexported")}
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user