mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
feat: credit note and vendor credit universal search.
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
import React from 'react';
|
||||
import { MenuItem, Intent } from '@blueprintjs/core';
|
||||
|
||||
import { TextStatus, Icon, Choose, T } from 'components';
|
||||
|
||||
import { RESOURCES_TYPES } from '../../../common/resourcesTypes';
|
||||
import withDrawerActions from '../../Drawer/withDrawerActions';
|
||||
import {
|
||||
AbilitySubject,
|
||||
VendorCreditAction,
|
||||
} from '../../../common/abilityOption';
|
||||
import { DRAWERS } from 'common/drawers';
|
||||
|
||||
/**
|
||||
* Vendor credit universal search item select action.
|
||||
*/
|
||||
function VendorCreditUniversalSearchSelectComponent({
|
||||
// #ownProps
|
||||
resourceType,
|
||||
resourceId,
|
||||
onAction,
|
||||
|
||||
// #withDrawerActions
|
||||
openDrawer,
|
||||
}) {
|
||||
if (resourceType === RESOURCES_TYPES.VENDOR_CREDIT) {
|
||||
openDrawer(DRAWERS.VENDOR_CREDIT_DETAIL_DRAWER, {
|
||||
vendorCreditId: resourceId,
|
||||
});
|
||||
onAction && onAction();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export const VendorCreditUniversalSearchSelect = withDrawerActions(
|
||||
VendorCreditUniversalSearchSelectComponent,
|
||||
);
|
||||
|
||||
/**
|
||||
* Status accessor.
|
||||
*/
|
||||
function VendorCreditUniversalSearchStatus({ receipt }) {
|
||||
return (
|
||||
<Choose>
|
||||
<Choose.When condition={receipt.is_closed}>
|
||||
<TextStatus intent={Intent.SUCCESS}>
|
||||
<T id={'closed'} />
|
||||
</TextStatus>
|
||||
</Choose.When>
|
||||
|
||||
<Choose.When condition={receipt.is_open}>
|
||||
<TextStatus intent={Intent.WARNING}>
|
||||
<T id={'closed'} />
|
||||
</TextStatus>
|
||||
</Choose.When>
|
||||
|
||||
<Choose.Otherwise>
|
||||
<TextStatus intent={Intent.NONE}>
|
||||
<T id={'draft'} />
|
||||
</TextStatus>
|
||||
</Choose.Otherwise>
|
||||
</Choose>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Credit note universal search item.
|
||||
*/
|
||||
export function VendorCreditUniversalSearchItem(
|
||||
item,
|
||||
{ handleClick, modifiers, query },
|
||||
) {
|
||||
return (
|
||||
<MenuItem
|
||||
active={modifiers.active}
|
||||
text={
|
||||
<div>
|
||||
<div>{item.text}</div>
|
||||
<span class="bp3-text-muted">
|
||||
{item.reference.vendor_credit_number}{' '}
|
||||
<Icon icon={'caret-right-16'} iconSize={16} />
|
||||
{item.reference.formatted_vendor_credit_date}
|
||||
</span>
|
||||
</div>
|
||||
}
|
||||
label={
|
||||
<>
|
||||
<div class="amount">${item.reference.amount}</div>
|
||||
<VendorCreditUniversalSearchStatus receipt={item.reference} />
|
||||
</>
|
||||
}
|
||||
onClick={handleClick}
|
||||
className={'universal-search__item--receipt'}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transformes receipt resource item to search item.
|
||||
*/
|
||||
const transformVendorCreditsToSearch = (vendorCredit) => ({
|
||||
id: vendorCredit.id,
|
||||
text: vendorCredit.vendor.display_name,
|
||||
label: vendorCredit.formatted_amount,
|
||||
reference: vendorCredit,
|
||||
});
|
||||
|
||||
/**
|
||||
* Credit note universal search bind configuration.
|
||||
*/
|
||||
export const universalSearchVendorCreditBind = () => ({
|
||||
resourceType: RESOURCES_TYPES.VENDOR_CREDIT,
|
||||
optionItemLabel: 'Vendor credits',
|
||||
selectItemAction: VendorCreditUniversalSearchSelect,
|
||||
itemRenderer: VendorCreditUniversalSearchItem,
|
||||
itemSelect: transformVendorCreditsToSearch,
|
||||
permission: {
|
||||
ability: VendorCreditAction.View,
|
||||
subject: AbilitySubject.VendorCredit,
|
||||
},
|
||||
});
|
||||
119
src/containers/Sales/CreditNotes/CreditNoteUniversalSearch.js
Normal file
119
src/containers/Sales/CreditNotes/CreditNoteUniversalSearch.js
Normal file
@@ -0,0 +1,119 @@
|
||||
import React from 'react';
|
||||
import { MenuItem, Intent } from '@blueprintjs/core';
|
||||
|
||||
import { Icon, Choose, T, TextStatus } from 'components';
|
||||
|
||||
import { RESOURCES_TYPES } from '../../../common/resourcesTypes';
|
||||
import withDrawerActions from '../../Drawer/withDrawerActions';
|
||||
import {
|
||||
AbilitySubject,
|
||||
CreditNoteAction,
|
||||
} from '../../../common/abilityOption';
|
||||
import { DRAWERS } from 'common/drawers';
|
||||
|
||||
/**
|
||||
* Credit note universal search item select action.
|
||||
*/
|
||||
function CreditNoteUniversalSearchSelectComponent({
|
||||
// #ownProps
|
||||
resourceType,
|
||||
resourceId,
|
||||
onAction,
|
||||
|
||||
// #withDrawerActions
|
||||
openDrawer,
|
||||
}) {
|
||||
if (resourceType === RESOURCES_TYPES.CREDIT_NOTE) {
|
||||
openDrawer(DRAWERS.CREDIT_NOTE_DETAIL_DRAWER, { creditNoteId: resourceId });
|
||||
onAction && onAction();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export const CreditNoteUniversalSearchSelect = withDrawerActions(
|
||||
CreditNoteUniversalSearchSelectComponent,
|
||||
);
|
||||
|
||||
/**
|
||||
* Status accessor.
|
||||
*/
|
||||
function CreditNoteUniversalSearchStatus({ receipt }) {
|
||||
return (
|
||||
<Choose>
|
||||
<Choose.When condition={receipt.is_closed}>
|
||||
<TextStatus intent={Intent.SUCCESS}>
|
||||
<T id={'closed'} />
|
||||
</TextStatus>
|
||||
</Choose.When>
|
||||
|
||||
<Choose.When condition={receipt.is_open}>
|
||||
<TextStatus intent={Intent.WARNING}>
|
||||
<T id={'open'} />
|
||||
</TextStatus>
|
||||
</Choose.When>
|
||||
|
||||
<Choose.Otherwise>
|
||||
<TextStatus intent={Intent.NONE}>
|
||||
<T id={'draft'} />
|
||||
</TextStatus>
|
||||
</Choose.Otherwise>
|
||||
</Choose>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Credit note universal search item.
|
||||
*/
|
||||
export function CreditNoteUniversalSearchItem(
|
||||
item,
|
||||
{ handleClick, modifiers, query },
|
||||
) {
|
||||
return (
|
||||
<MenuItem
|
||||
active={modifiers.active}
|
||||
text={
|
||||
<div>
|
||||
<div>{item.text}</div>
|
||||
<span class="bp3-text-muted">
|
||||
{item.reference.credit_note_number}{' '}
|
||||
<Icon icon={'caret-right-16'} iconSize={16} />
|
||||
{item.reference.formatted_credit_note_date}
|
||||
</span>
|
||||
</div>
|
||||
}
|
||||
label={
|
||||
<>
|
||||
<div class="amount">${item.reference.amount}</div>
|
||||
<CreditNoteUniversalSearchStatus receipt={item.reference} />
|
||||
</>
|
||||
}
|
||||
onClick={handleClick}
|
||||
className={'universal-search__item--receipt'}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transformes receipt resource item to search item.
|
||||
*/
|
||||
const transformReceiptsToSearch = (creditNote) => ({
|
||||
id: creditNote.id,
|
||||
text: creditNote.customer.display_name,
|
||||
label: creditNote.formatted_amount,
|
||||
reference: creditNote,
|
||||
});
|
||||
|
||||
/**
|
||||
* Credit note universal search bind configuration.
|
||||
*/
|
||||
export const universalSearchCreditNoteBind = () => ({
|
||||
resourceType: RESOURCES_TYPES.CREDIT_NOTE,
|
||||
optionItemLabel: 'Credit notes',
|
||||
selectItemAction: CreditNoteUniversalSearchSelect,
|
||||
itemRenderer: CreditNoteUniversalSearchItem,
|
||||
itemSelect: transformReceiptsToSearch,
|
||||
permission: {
|
||||
ability: CreditNoteAction.View,
|
||||
subject: AbilitySubject.CreditNote,
|
||||
},
|
||||
});
|
||||
@@ -9,6 +9,8 @@ import { universalSearchCustomerBind } from '../Customers/CustomersUniversalSear
|
||||
import { universalSearchJournalBind } from '../Accounting/ManualJournalUniversalSearch';
|
||||
import { universalSearchAccountBind } from '../Accounts/AccountUniversalSearch';
|
||||
import { universalSearchVendorBind } from '../Vendors/VendorsUniversalSearch';
|
||||
import { universalSearchCreditNoteBind } from '../Sales/CreditNotes/CreditNoteUniversalSearch';
|
||||
import { universalSearchVendorCreditBind } from '../Purchases/CreditNotes/VendorCreditIUniversalSearchBind';
|
||||
|
||||
// Universal search binds.
|
||||
export const universalSearchBinds = [
|
||||
@@ -23,4 +25,6 @@ export const universalSearchBinds = [
|
||||
universalSearchCustomerBind,
|
||||
universalSearchVendorBind,
|
||||
universalSearchJournalBind,
|
||||
universalSearchCreditNoteBind,
|
||||
universalSearchVendorCreditBind,
|
||||
];
|
||||
|
||||
@@ -26,7 +26,7 @@ export function useResourceData(type, query, props) {
|
||||
|
||||
/**
|
||||
* Retrieve the resource url by the given resource type.
|
||||
* @param {string} type
|
||||
* @param {string} type
|
||||
* @returns {string}
|
||||
*/
|
||||
function getResourceUrlFromType(type) {
|
||||
@@ -42,6 +42,8 @@ function getResourceUrlFromType(type) {
|
||||
[RESOURCES_TYPES.VENDOR]: '/vendors',
|
||||
[RESOURCES_TYPES.MANUAL_JOURNAL]: '/manual-journals',
|
||||
[RESOURCES_TYPES.ACCOUNT]: '/accounts',
|
||||
[RESOURCES_TYPES.CREDIT_NOTE]: '/sales/credit_notes',
|
||||
[RESOURCES_TYPES.VENDOR_CREDIT]: '/purchases/vendor-credit',
|
||||
};
|
||||
return config[type] || '';
|
||||
}
|
||||
@@ -81,7 +83,6 @@ const transformVendors = (response) => ({
|
||||
items: response.data.vendors,
|
||||
});
|
||||
|
||||
|
||||
const transformPaymentMades = (response) => ({
|
||||
items: response.data.bill_payments,
|
||||
});
|
||||
@@ -104,7 +105,15 @@ const transformsEstimates = (response) => ({
|
||||
|
||||
const transformAccounts = (response) => ({
|
||||
items: response.data.accounts,
|
||||
})
|
||||
});
|
||||
|
||||
const transformCreditNotes = (response) => ({
|
||||
items: response.data.credit_notes,
|
||||
});
|
||||
|
||||
const transformVendorCredits = (response) => ({
|
||||
items: response.data.vendor_credits,
|
||||
});
|
||||
|
||||
/**
|
||||
* Detarmines the transformer based on the given resource type.
|
||||
@@ -122,7 +131,9 @@ const transformResourceData = (type) => (response) => {
|
||||
[RESOURCES_TYPES.VENDOR]: transformVendors,
|
||||
[RESOURCES_TYPES.BILL]: transformBills,
|
||||
[RESOURCES_TYPES.MANUAL_JOURNAL]: transformManualJournals,
|
||||
[RESOURCES_TYPES.ACCOUNT]: transformAccounts
|
||||
[RESOURCES_TYPES.ACCOUNT]: transformAccounts,
|
||||
[RESOURCES_TYPES.CREDIT_NOTE]: transformCreditNotes,
|
||||
[RESOURCES_TYPES.VENDOR_CREDIT]: transformVendorCredits,
|
||||
};
|
||||
return {
|
||||
...pairs[type](response),
|
||||
|
||||
Reference in New Issue
Block a user