fix: edit payment transaction

This commit is contained in:
Ahmed Bouhuolia
2025-10-29 12:54:12 +02:00
parent 98401b5a01
commit fc89cfb14a
13 changed files with 57 additions and 77 deletions

View File

@@ -28,7 +28,12 @@ export class GetBankRulesTransformer extends Transformer {
* @returns {string} * @returns {string}
*/ */
protected assignCategoryFormatted(bankRule: any) { 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) @Inject(BillPayment.name)
private readonly billPaymentModel: TenantModelProxy<typeof BillPayment>, private readonly billPaymentModel: TenantModelProxy<typeof BillPayment>,
) {} ) { }
/** /**
* Retrieve bill payment with associated metadata. * Retrieve bill payment with associated metadata.
@@ -46,7 +46,8 @@ export class BillPaymentsPages {
paymentAmount: entry.paymentAmount, paymentAmount: entry.paymentAmount,
})); }));
const resPayableBills = await Bill.query() const resPayableBills = await this.billModel()
.query()
.modify('opened') .modify('opened')
.modify('dueBills') .modify('dueBills')
.where('vendor_id', billPayment.vendorId) .where('vendor_id', billPayment.vendorId)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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