From df1adc34a2c5723dcc73524d1b0c63ed912d59d8 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Tue, 30 Aug 2022 14:11:34 -0700 Subject: [PATCH] IO-2033 Mark payment as exported. --- bodyshop_translations.babel | 21 ++++ .../accounting-payments-table.component.jsx | 18 +++- ...yment-mark-selected-exported.component.jsx | 96 +++++++++++++++++++ client/src/translations/en_us/common.json | 1 + client/src/translations/es/common.json | 1 + client/src/translations/fr/common.json | 1 + 6 files changed, 133 insertions(+), 5 deletions(-) create mode 100644 client/src/components/payment-mark-selected-exported/payment-mark-selected-exported.component.jsx diff --git a/bodyshop_translations.babel b/bodyshop_translations.babel index 65c608655..776e3e524 100644 --- a/bodyshop_translations.babel +++ b/bodyshop_translations.babel @@ -35220,6 +35220,27 @@ + + markexported + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + payment false diff --git a/client/src/components/accounting-payments-table/accounting-payments-table.component.jsx b/client/src/components/accounting-payments-table/accounting-payments-table.component.jsx index 05e5277dd..61b1bb5f9 100644 --- a/client/src/components/accounting-payments-table/accounting-payments-table.component.jsx +++ b/client/src/components/accounting-payments-table/accounting-payments-table.component.jsx @@ -1,19 +1,20 @@ import { Card, Input, Space, Table } from "antd"; import React, { useState } from "react"; import { useTranslation } from "react-i18next"; +import { connect } from "react-redux"; import { Link } from "react-router-dom"; +import { createStructuredSelector } from "reselect"; import { logImEXEvent } from "../../firebase/firebase.utils"; +import { selectBodyshop } from "../../redux/user/user.selectors"; import CurrencyFormatter from "../../utils/CurrencyFormatter"; import { DateFormatter, DateTimeFormatter } from "../../utils/DateFormatter"; import { alphaSort, dateSort } from "../../utils/sorters"; +import ExportLogsCountDisplay from "../export-logs-count-display/export-logs-count-display.component"; +import OwnerNameDisplay from "../owner-name-display/owner-name-display.component"; import PaymentExportButton from "../payment-export-button/payment-export-button.component"; +import PaymentMarkSelectedExported from "../payment-mark-selected-exported/payment-mark-selected-exported.component"; import PaymentsExportAllButton from "../payments-export-all-button/payments-export-all-button.component"; import QboAuthorizeComponent from "../qbo-authorize/qbo-authorize.component"; -import { connect } from "react-redux"; -import { createStructuredSelector } from "reselect"; -import { selectBodyshop } from "../../redux/user/user.selectors"; -import OwnerNameDisplay from "../owner-name-display/owner-name-display.component"; -import ExportLogsCountDisplay from "../export-logs-count-display/export-logs-count-display.component"; const mapStateToProps = createStructuredSelector({ bodyshop: selectBodyshop, @@ -184,6 +185,13 @@ export function AccountingPayablesTableComponent({ + ({ + //setUserLanguage: language => dispatch(setUserLanguage(language)) +}); + +export default connect( + mapStateToProps, + mapDispatchToProps +)(PaymentMarkSelectedExported); + +export function PaymentMarkSelectedExported({ + bodyshop, + currentUser, + paymentIds, + disabled, + loadingCallback, + completedCallback, + refetch, +}) { + const { t } = useTranslation(); + const [loading, setLoading] = useState(false); + const [insertExportLog] = useMutation(INSERT_EXPORT_LOG); + const [updatePayments] = useMutation(gql` + mutation UPDATE_PAYMENTS($paymentIds: [uuid!]!, $exportedat: timestamptz!) { + update_payments( + where: { id: { _in: $paymentIds } } + _set: { exportedat: $exportedat } + ) { + returning { + id + exportedat + } + } + } + `); + + const handleUpdate = async () => { + setLoading(true); + loadingCallback(true); + const result = await updatePayments({ + variables: { paymentIds: paymentIds, exportedat: new Date() }, + update(cache) {}, + }); + + await insertExportLog({ + variables: { + logs: paymentIds.map((id) => { + return { + bodyshopid: bodyshop.id, + paymentid: id, + successful: true, + message: JSON.stringify([t("general.labels.markedexported")]), + useremail: currentUser.email, + }; + }), + }, + }); + + if (!result.errors) { + notification["success"]({ + message: t("payments.successes.markexported"), + }); + } else { + notification["error"]({ + message: t("bills.errors.saving", { + error: JSON.stringify(result.errors), + }), + }); + } + loadingCallback(false); + completedCallback && completedCallback([]); + setLoading(false); + refetch && refetch(); + }; + + return ( + + ); +} diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index a83e17ba6..81da5a4d8 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -2085,6 +2085,7 @@ }, "successes": { "exported": "Payment(s) exported successfully.", + "markexported": "Payment(s) marked exported.", "payment": "Payment created successfully. ", "stripe": "Credit card transaction charged successfully." } diff --git a/client/src/translations/es/common.json b/client/src/translations/es/common.json index 1044b521c..713cacc30 100644 --- a/client/src/translations/es/common.json +++ b/client/src/translations/es/common.json @@ -2085,6 +2085,7 @@ }, "successes": { "exported": "", + "markexported": "", "payment": "", "stripe": "" } diff --git a/client/src/translations/fr/common.json b/client/src/translations/fr/common.json index 57f9cdb9b..566c5e541 100644 --- a/client/src/translations/fr/common.json +++ b/client/src/translations/fr/common.json @@ -2085,6 +2085,7 @@ }, "successes": { "exported": "", + "markexported": "", "payment": "", "stripe": "" }