import React from 'react';
import {
Menu,
MenuDivider,
MenuItem,
Intent,
Tag,
Position,
Button,
Popover,
} from '@blueprintjs/core';
import intl from 'react-intl-universal';
import moment from 'moment';
import { FormattedMessage as T, Can } from 'components';
import { isNumber } from 'lodash';
import { Icon, Money, If } from 'components';
import { isBlank, safeCallback } from 'utils';
import {
InventoryAdjustmentAction,
AbilitySubject,
} from '../../common/abilityOption';
/**
* Publish accessor
*/
export const PublishAccessor = (r) => {
return r.is_published ? (
) : (
);
};
/**
* Type column accessor.
*/
export const TypeAccessor = (row) => {
return row.formatted_type ? (
{row.formatted_type}
) : (
''
);
};
/**
* Item type accessor.
*/
export const ItemCodeAccessor = (row) =>
row.type ? (
{intl.get(row.type)}
) : (
''
);
/**
* Quantity on hand cell.
*/
export const QuantityOnHandCell = ({ cell: { value } }) => {
return isNumber(value) ? (
{value}
) : null;
};
/**
* Cost price cell.
*/
export const CostPriceCell = ({ cell: { value } }) => {
return !isBlank(value) ? : null;
};
/**
* Sell price cell.
*/
export const SellPriceCell = ({ cell: { value } }) => {
return !isBlank(value) ? : null;
};
/**
* Item type accessor.
*/
export const ItemTypeAccessor = (row) => {
return row.type ? (
{intl.get(row.type)}
) : null;
};
export const ActionsMenu = ({
row: { original },
payload: { onDelete, onPublish, onViewDetails },
}) => {
return (
);
};
export const ActionsCell = (props) => {
return (
}
position={Position.RIGHT_BOTTOM}
>
} />
);
};
/**
* Retrieve inventory adjustments columns.
*/
export const useInventoryAdjustmentsColumns = () => {
return React.useMemo(
() => [
{
id: 'date',
Header: intl.get('date'),
accessor: (r) => moment(r.date).format('YYYY MMM DD'),
width: 115,
className: 'date',
clickable: true,
},
{
id: 'type',
Header: intl.get('type'),
accessor: TypeAccessor,
className: 'type',
width: 100,
clickable: true,
},
{
id: 'reason',
Header: intl.get('reason'),
accessor: 'reason',
className: 'reason',
width: 115,
clickable: true,
},
{
id: 'reference_no',
Header: intl.get('reference_no'),
accessor: 'reference_no',
className: 'reference_no',
width: 100,
clickable: true,
},
{
id: 'published_at',
Header: intl.get('status'),
accessor: PublishAccessor,
width: 95,
className: 'publish',
clickable: true,
},
{
id: 'created_at',
Header: intl.get('created_at'),
accessor: (r) => moment(r.created_at).format('YYYY MMM DD'),
width: 125,
className: 'created_at',
clickable: true,
},
],
[],
);
};