Merge pull request #835 from bigcapitalhq/fix-edit-payment-transaction

fix: edit payment transaction
This commit is contained in:
Ahmed Bouhuolia
2025-10-29 12:57:24 +02:00
committed by GitHub
13 changed files with 57 additions and 77 deletions

View File

@@ -28,7 +28,12 @@ export class GetBankRulesTransformer extends Transformer {
* @returns {string}
*/
protected assignCategoryFormatted(bankRule: any) {
return getCashflowTransactionFormattedType(bankRule.assignCategory);
const translationKey = getCashflowTransactionFormattedType(
bankRule.assignCategory,
);
return translationKey
? this.context.i18n.t(translationKey)
: bankRule.assignCategory;
}
/**

View File

@@ -19,7 +19,7 @@ export class BillPaymentsPages {
@Inject(BillPayment.name)
private readonly billPaymentModel: TenantModelProxy<typeof BillPayment>,
) {}
) { }
/**
* Retrieve bill payment with associated metadata.
@@ -46,7 +46,8 @@ export class BillPaymentsPages {
paymentAmount: entry.paymentAmount,
}));
const resPayableBills = await Bill.query()
const resPayableBills = await this.billModel()
.query()
.modify('opened')
.modify('dueBills')
.where('vendor_id', billPayment.vendorId)

View File

@@ -18,7 +18,7 @@ export class PaymentsReceivedPagesService {
@Inject(PaymentReceived.name)
private readonly paymentReceived: TenantModelProxy<typeof PaymentReceived>,
) {}
) { }
/**
* Retrive page invoices entries from the given sale invoices models.
@@ -58,11 +58,10 @@ export class PaymentsReceivedPagesService {
/**
* Retrieve the payment receive details of the given id.
* @param {number} tenantId - Tenant id.
* @param {Integer} paymentReceiveId - Payment receive id.
* @param {number} paymentReceiveId - Payment receive id.
*/
public async getPaymentReceiveEditPage(paymentReceiveId: number): Promise<{
paymentReceive: Omit<PaymentReceived, 'entries'>;
data: Omit<PaymentReceived, 'entries'>;
entries: IPaymentReceivePageEntry[];
}> {
// Retrieve payment receive.
@@ -100,7 +99,7 @@ export class PaymentsReceivedPagesService {
const entries = [...paymentEntries, ...restReceivableEntries];
return {
paymentReceive: omit(paymentReceive, ['entries']),
data: omit(paymentReceive, ['entries']),
entries,
};
}

View File

@@ -102,13 +102,13 @@ export const StatusAccessor = (row) => {
return (
<Choose>
<Choose.When condition={!!row.is_published}>
<Tag minimal={true} round={true}>
<Tag round>
<T id={'published'} />
</Tag>
</Choose.When>
<Choose.Otherwise>
<Tag minimal={true} intent={Intent.WARNING} round={true}>
<Tag intent={Intent.WARNING} round>
<T id={'draft'} />
</Tag>
</Choose.Otherwise>

View File

@@ -42,7 +42,7 @@ export const handleDeleteErrors = (errors) => {
export const AccountCodeAccessor = (row) =>
!isBlank(row.code) ? (
<Tag minimal={true} round={true} intent={Intent.NONE}>
<Tag minimal round intent={Intent.NONE}>
{row.code}
</Tag>
) : null;

View File

@@ -15,7 +15,7 @@ const applyToTypeAccessor = (rule) => {
};
const conditionsAccessor = (rule) => (
<span style={{ fontSize: 12, color: '#5F6B7C' }}>
<span style={{ fontSize: 12 }}>
{rule.conditions_formatted}
</span>
);

View File

@@ -101,11 +101,11 @@ export function ActionsCell(props) {
*/
export function PublishAccessor(row) {
return row.is_published ? (
<Tag round={true} minimal={true}>
<Tag round>
<T id={'published'} />
</Tag>
) : (
<Tag round={true} minimal={true} intent={Intent.WARNING}>
<Tag round minimal intent={Intent.WARNING}>
<T id={'draft'} />
</Tag>
);

View File

@@ -72,7 +72,7 @@ export const SellPriceCell = ({ cell: { value } }) => {
export const ItemTypeAccessor = (row) => {
return row.type_formatted ? (
<Tag minimal={true} round={true} intent={Intent.NONE}>
<Tag round intent={Intent.NONE}>
{row.type_formatted}
</Tag>
) : null;

View File

@@ -46,12 +46,14 @@ function PaymentMadeFormProvider({ query, paymentMadeId, ...props }) {
// Handle fetch specific payment made details.
const {
data: { paymentMade: paymentMadeEditPage, entries: paymentEntriesEditPage },
data: paymentMadeEditData,
isFetching: isPaymentFetching,
isLoading: isPaymentLoading,
} = usePaymentMadeEditPage(paymentMadeId, {
enabled: !!paymentMadeId,
});
const paymentMadeEditPage = paymentMadeEditData?.bill_payment;
const paymentEntriesEditPage = paymentMadeEditData?.entries;
// Fetches the branches list.
const {

View File

@@ -22,27 +22,27 @@ import { safeCallback } from '@/utils';
export const statusAccessor = (row) => (
<Choose>
<Choose.When condition={row.is_approved}>
<Tag minimal={true} intent={Intent.SUCCESS} round={true}>
<Tag intent={Intent.SUCCESS} round>
<T id={'approved'} />
</Tag>
</Choose.When>
<Choose.When condition={row.is_rejected}>
<Tag minimal={true} intent={Intent.DANGER} round={true}>
<Tag intent={Intent.DANGER} round>
<T id={'rejected'} />
</Tag>
</Choose.When>
<Choose.When condition={row.is_expired}>
<Tag minimal={true} intent={Intent.WARNING} round={true}>
<Tag intent={Intent.WARNING} round>
<T id={'estimate.status.expired'} />
</Tag>
</Choose.When>
<Choose.When condition={row.is_delivered}>
<Tag minimal={true} intent={Intent.SUCCESS} round={true}>
<Tag intent={Intent.SUCCESS} round>
<T id={'delivered'} />
</Tag>
</Choose.When>
<Choose.Otherwise>
<Tag minimal={true} round={true}>
<Tag round>
<T id={'draft'} />
</Tag>
</Choose.Otherwise>

View File

@@ -42,15 +42,15 @@ function PaymentReceiveFormProvider({ query, paymentReceiveId, ...props }) {
// Fetches payment recevie details.
const {
data: {
paymentReceive: paymentReceiveEditPage,
entries: paymentEntriesEditPage,
},
data: paymentReceivedEditData,
isLoading: isPaymentLoading,
isFetching: isPaymentFetching,
} = usePaymentReceiveEditPage(paymentReceiveId, {
enabled: !!paymentReceiveId,
});
const paymentReceiveEditPage = paymentReceivedEditData?.data;
const paymentEntriesEditPage = paymentReceivedEditData?.entries
// Handle fetch accounts data.
const { data: accounts, isLoading: isAccountsLoading } = useAccounts();

View File

@@ -1,5 +1,5 @@
// @ts-nocheck
import { useMutation, useQueryClient } from 'react-query';
import { useMutation, useQuery, useQueryClient } from 'react-query';
import { useRequestQuery } from '../useQueryRequest';
import { transformPagination } from '@/utils';
import useApiRequest from '../useRequest';
@@ -66,16 +66,13 @@ export function useCreatePaymentMade(props) {
const client = useQueryClient();
const apiRequest = useApiRequest();
return useMutation(
(values) => apiRequest.post('bill-payments', values),
{
onSuccess: (res, values) => {
// Common invalidation queries.
commonInvalidateQueries(client);
},
...props,
return useMutation((values) => apiRequest.post('bill-payments', values), {
onSuccess: (res, values) => {
// Common invalidation queries.
commonInvalidateQueries(client);
},
);
...props,
});
}
/**
@@ -107,42 +104,28 @@ export function useDeletePaymentMade(props) {
const client = useQueryClient();
const apiRequest = useApiRequest();
return useMutation(
(id) => apiRequest.delete(`bill-payments/${id}`),
{
onSuccess: (res, id) => {
// Common invalidation queries.
commonInvalidateQueries(client);
return useMutation((id) => apiRequest.delete(`bill-payments/${id}`), {
onSuccess: (res, id) => {
// Common invalidation queries.
commonInvalidateQueries(client);
// Invalidate specific payment made.
client.invalidateQueries([t.PAYMENT_MADE, id]);
},
...props,
// Invalidate specific payment made.
client.invalidateQueries([t.PAYMENT_MADE, id]);
},
);
...props,
});
}
/**
* Retrieve specific payment made.
*/
export function usePaymentMadeEditPage(id, props) {
return useRequestQuery(
[t.PAYMENT_MADE_EDIT_PAGE, id],
{
method: 'get',
url: `bill-payments/${id}/edit-page`,
},
{
select: (res) => ({
paymentMade: res.data.bill_payment,
entries: res.data.entries,
}),
defaultData: {
paymentMade: {},
entries: [],
},
...props,
},
export function usePaymentMadeEditPage(
id: number,
props: UseQueryOptions<any, Error>,
) {
const apiRequest = useApiRequest();
return useQuery([t.PAYMENT_MADE_EDIT_PAGE, id], () =>
apiRequest.get(`bill-payments/${id}/edit-page`).then((res) => res.data),
);
}

View File

@@ -171,20 +171,10 @@ export function usePaymentReceive(id, props) {
* @param {number} id - Payment receive id.
*/
export function usePaymentReceiveEditPage(id, props) {
return useRequestQuery(
const apiRequest = useApiRequest();
return useQuery(
[t.PAYMENT_RECEIVE_EDIT_PAGE, id],
{ method: 'get', url: `payments-received/${id}/edit-page` },
{
select: (res) => ({
paymentReceive: res.data,
entries: res.data.entries,
}),
defaultData: {
paymentReceive: {},
entries: [],
},
...props,
},
() => apiRequest.get(`payments-received/${id}/edit-page`).then(res => res.data),
);
}