mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +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,
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user