Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6175 prescription price columns #6356

Merged
merged 7 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const createDraftLine = ({
numberOfPacks: 0,
packSize: 0,
sellPricePerPack: 0,
costPricePerPack: 0,
note: '',
type: InvoiceLineNodeType.Service,
isCreated: !seed,
Expand Down

Large diffs are not rendered by default.

51 changes: 24 additions & 27 deletions client/packages/invoices/src/Prescriptions/DetailView/columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,64 +262,61 @@ export const usePrescriptionColumn = ({
],

{
label: 'label.unit-price',
key: 'sellPricePerUnit',
label: 'label.cost-price',
key: 'costPrice',
align: ColumnAlign.Right,
Cell: CurrencyCell,
accessor: ({ rowData }) => {
if ('lines' in rowData) {
// Multiple lines, so we need to calculate the average price per unit

let totalSellPrice = 0;
let totalUnits = 0;

let totalCostPrice = 0;
for (const line of rowData.lines) {
totalSellPrice += line.sellPricePerPack * line.numberOfPacks;
totalUnits += line.numberOfPacks * line.packSize;
totalCostPrice += line.costPricePerPack * line.numberOfPacks;
}

return totalSellPrice / totalUnits;
return totalCostPrice;
} else {
return (rowData.sellPricePerPack ?? 0) / rowData.packSize;
return (rowData.costPricePerPack ?? 0) * rowData.numberOfPacks;
}
},
getSortValue: rowData => {
if ('lines' in rowData) {
return Object.values(rowData.lines).reduce(
(sum, batch) =>
sum + (batch.sellPricePerPack ?? 0) / batch.packSize,
sum + (batch.costPricePerPack ?? 0) * batch.numberOfPacks,
0
);
} else {
return (rowData.sellPricePerPack ?? 0) / rowData.packSize;
return (rowData.costPricePerPack ?? 0) * rowData.numberOfPacks;
}
},
},

{
label: 'label.line-total',
zachariah-at-msupply marked this conversation as resolved.
Show resolved Hide resolved
key: 'lineTotal',
label: 'label.sell-price',
key: 'sellPrice',
align: ColumnAlign.Right,
Cell: CurrencyCell,
accessor: ({ rowData }) => {
if ('lines' in rowData) {
return Object.values(rowData.lines).reduce(
(sum, batch) => sum + batch.sellPricePerPack * batch.numberOfPacks,
0
);
// Multiple lines, so we need to calculate the average price per unit
zachariah-at-msupply marked this conversation as resolved.
Show resolved Hide resolved
let totalSellPrice = 0;
for (const line of rowData.lines) {
totalSellPrice += line.sellPricePerPack * line.numberOfPacks;
}
return totalSellPrice;
} else {
const x = rowData.sellPricePerPack * rowData.numberOfPacks;
return x;
return (rowData.sellPricePerPack ?? 0) * rowData.numberOfPacks;
}
},
getSortValue: row => {
if ('lines' in row) {
return Object.values(row.lines).reduce(
(sum, batch) => sum + batch.sellPricePerPack * batch.numberOfPacks,
getSortValue: rowData => {
if ('lines' in rowData) {
return Object.values(rowData.lines).reduce(
(sum, batch) =>
sum + (batch.sellPricePerPack ?? 0) * batch.numberOfPacks,
0
);
} else {
const x = row.sellPricePerPack * row.numberOfPacks;
return x;
return (rowData.sellPricePerPack ?? 0) * rowData.numberOfPacks;
}
},
},
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const testLine = ({
id,
expiryDate,
sellPricePerPack: 0,
costPricePerPack: 0,
totalBeforeTax: 0,
totalAfterTax: 0,
item: {
Expand All @@ -64,6 +65,7 @@ const testLine = ({
totalNumberOfPacks,
availableNumberOfPacks,
onHold,
costPricePerPack: 0,
sellPricePerPack: 0,
itemId,
packSize,
Expand Down
7 changes: 5 additions & 2 deletions client/packages/invoices/src/StockOut/operations.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import * as Types from '@openmsupply-client/common';
import { GraphQLClient, RequestOptions } from 'graphql-request';
import gql from 'graphql-tag';
type GraphQLClientRequestHeaders = RequestOptions['requestHeaders'];
export type PartialStockLineFragment = { __typename: 'StockLineNode', id: string, itemId: string, availableNumberOfPacks: number, totalNumberOfPacks: number, onHold: boolean, sellPricePerPack: number, packSize: number, expiryDate?: string | null, item: { __typename: 'ItemNode', name: string, code: string }, location?: { __typename: 'LocationNode', id: string, name: string, code: string, onHold: boolean } | null };
export type PartialStockLineFragment = { __typename: 'StockLineNode', id: string, itemId: string, availableNumberOfPacks: number, totalNumberOfPacks: number, onHold: boolean, costPricePerPack: number, sellPricePerPack: number, packSize: number, expiryDate?: string | null, item: { __typename: 'ItemNode', name: string, code: string }, location?: { __typename: 'LocationNode', id: string, name: string, code: string, onHold: boolean } | null };

export type StockOutLineFragment = { __typename: 'InvoiceLineNode', id: string, type: Types.InvoiceLineNodeType, batch?: string | null, expiryDate?: string | null, numberOfPacks: number, packSize: number, invoiceId: string, sellPricePerPack: number, note?: string | null, totalBeforeTax: number, totalAfterTax: number, taxPercentage?: number | null, itemName: string, item: { __typename: 'ItemNode', id: string, name: string, code: string, unitName?: string | null }, location?: { __typename: 'LocationNode', id: string, name: string, code: string, onHold: boolean } | null, stockLine?: { __typename: 'StockLineNode', id: string, itemId: string, batch?: string | null, availableNumberOfPacks: number, totalNumberOfPacks: number, onHold: boolean, sellPricePerPack: number, packSize: number, expiryDate?: string | null, item: { __typename: 'ItemNode', name: string, code: string } } | null };
export type StockOutLineFragment = { __typename: 'InvoiceLineNode', id: string, type: Types.InvoiceLineNodeType, batch?: string | null, expiryDate?: string | null, numberOfPacks: number, packSize: number, invoiceId: string, costPricePerPack: number, sellPricePerPack: number, note?: string | null, totalBeforeTax: number, totalAfterTax: number, taxPercentage?: number | null, itemName: string, item: { __typename: 'ItemNode', id: string, name: string, code: string, unitName?: string | null }, location?: { __typename: 'LocationNode', id: string, name: string, code: string, onHold: boolean } | null, stockLine?: { __typename: 'StockLineNode', id: string, itemId: string, batch?: string | null, availableNumberOfPacks: number, totalNumberOfPacks: number, onHold: boolean, sellPricePerPack: number, costPricePerPack: number, packSize: number, expiryDate?: string | null, item: { __typename: 'ItemNode', name: string, code: string } } | null };

export type DummyQueryVariables = Types.Exact<{ [key: string]: never; }>;

Expand All @@ -19,6 +19,7 @@ export const PartialStockLineFragmentDoc = gql`
availableNumberOfPacks
totalNumberOfPacks
onHold
costPricePerPack
sellPricePerPack
packSize
expiryDate
Expand All @@ -45,6 +46,7 @@ export const StockOutLineFragmentDoc = gql`
numberOfPacks
packSize
invoiceId
costPricePerPack
sellPricePerPack
note
totalBeforeTax
Expand Down Expand Up @@ -75,6 +77,7 @@ export const StockOutLineFragmentDoc = gql`
totalNumberOfPacks
onHold
sellPricePerPack
costPricePerPack
packSize
expiryDate
item {
Expand Down
3 changes: 3 additions & 0 deletions client/packages/invoices/src/StockOut/operations.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ fragment PartialStockLine on StockLineNode {
availableNumberOfPacks
totalNumberOfPacks
onHold
costPricePerPack
sellPricePerPack
packSize
expiryDate
Expand All @@ -30,6 +31,7 @@ fragment StockOutLine on InvoiceLineNode {
numberOfPacks
packSize
invoiceId
costPricePerPack
sellPricePerPack
note
totalBeforeTax
Expand Down Expand Up @@ -63,6 +65,7 @@ fragment StockOutLine on InvoiceLineNode {
totalNumberOfPacks
onHold
sellPricePerPack
costPricePerPack
packSize
expiryDate
item {
Expand Down
2 changes: 2 additions & 0 deletions client/packages/invoices/src/StockOut/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const createTestLine = ({
totalAfterTax: 0,
totalBeforeTax: 0,
sellPricePerPack: 0,
costPricePerPack: 0,
itemName: '',
item: {
id: itemId,
Expand All @@ -60,6 +61,7 @@ const createTestLine = ({
availableNumberOfPacks,
onHold,
sellPricePerPack: 0,
costPricePerPack: 0,
itemId,
packSize,
item: {
Expand Down
2 changes: 2 additions & 0 deletions client/packages/invoices/src/StockOut/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const createStockOutPlaceholderRow = (
id,
packSize: 1,
sellPricePerPack: 0,
costPricePerPack: 0,
numberOfPacks: 0,
isCreated: true,
isUpdated: false,
Expand Down Expand Up @@ -71,6 +72,7 @@ export const createDraftStockOutLineFromStockLine = ({
location: stockLine?.location,
expiryDate: stockLine?.expiryDate,
sellPricePerPack,
costPricePerPack: 0,
packSize: stockLine?.packSize ?? 0,
id: FnUtils.generateUUID(),
invoiceId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -858,57 +858,57 @@ export const UpdateIndicatorValueDocument = gql`
}
`;

export type SdkFunctionWrapper = <T>(action: (requestHeaders?: Record<string, string>) => Promise<T>, operationName: string, operationType?: string, variables?: any) => Promise<T>;
export type SdkFunctionWrapper = <T>(action: (requestHeaders?:Record<string, string>) => Promise<T>, operationName: string, operationType?: string, variables?: any) => Promise<T>;


const defaultWrapper: SdkFunctionWrapper = (action, _operationName, _operationType, _variables) => action();

export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) {
return {
requestByNumber(variables: RequestByNumberQueryVariables, requestHeaders?: GraphQLClientRequestHeaders): Promise<RequestByNumberQuery> {
return withWrapper((wrappedRequestHeaders) => client.request<RequestByNumberQuery>(RequestByNumberDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), 'requestByNumber', 'query', variables);
return withWrapper((wrappedRequestHeaders) => client.request<RequestByNumberQuery>(RequestByNumberDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'requestByNumber', 'query', variables);
},
requisitionLineChart(variables: RequisitionLineChartQueryVariables, requestHeaders?: GraphQLClientRequestHeaders): Promise<RequisitionLineChartQuery> {
return withWrapper((wrappedRequestHeaders) => client.request<RequisitionLineChartQuery>(RequisitionLineChartDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), 'requisitionLineChart', 'query', variables);
return withWrapper((wrappedRequestHeaders) => client.request<RequisitionLineChartQuery>(RequisitionLineChartDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'requisitionLineChart', 'query', variables);
},
requests(variables: RequestsQueryVariables, requestHeaders?: GraphQLClientRequestHeaders): Promise<RequestsQuery> {
return withWrapper((wrappedRequestHeaders) => client.request<RequestsQuery>(RequestsDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), 'requests', 'query', variables);
return withWrapper((wrappedRequestHeaders) => client.request<RequestsQuery>(RequestsDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'requests', 'query', variables);
},
insertRequestLine(variables: InsertRequestLineMutationVariables, requestHeaders?: GraphQLClientRequestHeaders): Promise<InsertRequestLineMutation> {
return withWrapper((wrappedRequestHeaders) => client.request<InsertRequestLineMutation>(InsertRequestLineDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), 'insertRequestLine', 'mutation', variables);
return withWrapper((wrappedRequestHeaders) => client.request<InsertRequestLineMutation>(InsertRequestLineDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'insertRequestLine', 'mutation', variables);
},
updateRequestLine(variables: UpdateRequestLineMutationVariables, requestHeaders?: GraphQLClientRequestHeaders): Promise<UpdateRequestLineMutation> {
return withWrapper((wrappedRequestHeaders) => client.request<UpdateRequestLineMutation>(UpdateRequestLineDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), 'updateRequestLine', 'mutation', variables);
return withWrapper((wrappedRequestHeaders) => client.request<UpdateRequestLineMutation>(UpdateRequestLineDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'updateRequestLine', 'mutation', variables);
},
addFromMasterList(variables: AddFromMasterListMutationVariables, requestHeaders?: GraphQLClientRequestHeaders): Promise<AddFromMasterListMutation> {
return withWrapper((wrappedRequestHeaders) => client.request<AddFromMasterListMutation>(AddFromMasterListDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), 'addFromMasterList', 'mutation', variables);
return withWrapper((wrappedRequestHeaders) => client.request<AddFromMasterListMutation>(AddFromMasterListDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'addFromMasterList', 'mutation', variables);
},
deleteRequestLines(variables: DeleteRequestLinesMutationVariables, requestHeaders?: GraphQLClientRequestHeaders): Promise<DeleteRequestLinesMutation> {
return withWrapper((wrappedRequestHeaders) => client.request<DeleteRequestLinesMutation>(DeleteRequestLinesDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), 'deleteRequestLines', 'mutation', variables);
return withWrapper((wrappedRequestHeaders) => client.request<DeleteRequestLinesMutation>(DeleteRequestLinesDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'deleteRequestLines', 'mutation', variables);
},
useSuggestedQuantity(variables: UseSuggestedQuantityMutationVariables, requestHeaders?: GraphQLClientRequestHeaders): Promise<UseSuggestedQuantityMutation> {
return withWrapper((wrappedRequestHeaders) => client.request<UseSuggestedQuantityMutation>(UseSuggestedQuantityDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), 'useSuggestedQuantity', 'mutation', variables);
return withWrapper((wrappedRequestHeaders) => client.request<UseSuggestedQuantityMutation>(UseSuggestedQuantityDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'useSuggestedQuantity', 'mutation', variables);
},
insertRequest(variables: InsertRequestMutationVariables, requestHeaders?: GraphQLClientRequestHeaders): Promise<InsertRequestMutation> {
return withWrapper((wrappedRequestHeaders) => client.request<InsertRequestMutation>(InsertRequestDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), 'insertRequest', 'mutation', variables);
return withWrapper((wrappedRequestHeaders) => client.request<InsertRequestMutation>(InsertRequestDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'insertRequest', 'mutation', variables);
},
insertProgramRequest(variables: InsertProgramRequestMutationVariables, requestHeaders?: GraphQLClientRequestHeaders): Promise<InsertProgramRequestMutation> {
return withWrapper((wrappedRequestHeaders) => client.request<InsertProgramRequestMutation>(InsertProgramRequestDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), 'insertProgramRequest', 'mutation', variables);
return withWrapper((wrappedRequestHeaders) => client.request<InsertProgramRequestMutation>(InsertProgramRequestDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'insertProgramRequest', 'mutation', variables);
},
updateRequest(variables: UpdateRequestMutationVariables, requestHeaders?: GraphQLClientRequestHeaders): Promise<UpdateRequestMutation> {
return withWrapper((wrappedRequestHeaders) => client.request<UpdateRequestMutation>(UpdateRequestDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), 'updateRequest', 'mutation', variables);
return withWrapper((wrappedRequestHeaders) => client.request<UpdateRequestMutation>(UpdateRequestDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'updateRequest', 'mutation', variables);
},
deleteRequest(variables: DeleteRequestMutationVariables, requestHeaders?: GraphQLClientRequestHeaders): Promise<DeleteRequestMutation> {
return withWrapper((wrappedRequestHeaders) => client.request<DeleteRequestMutation>(DeleteRequestDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), 'deleteRequest', 'mutation', variables);
return withWrapper((wrappedRequestHeaders) => client.request<DeleteRequestMutation>(DeleteRequestDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'deleteRequest', 'mutation', variables);
},
supplierProgramSettings(variables: SupplierProgramSettingsQueryVariables, requestHeaders?: GraphQLClientRequestHeaders): Promise<SupplierProgramSettingsQuery> {
return withWrapper((wrappedRequestHeaders) => client.request<SupplierProgramSettingsQuery>(SupplierProgramSettingsDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), 'supplierProgramSettings', 'query', variables);
return withWrapper((wrappedRequestHeaders) => client.request<SupplierProgramSettingsQuery>(SupplierProgramSettingsDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'supplierProgramSettings', 'query', variables);
},
programIndicators(variables: ProgramIndicatorsQueryVariables, requestHeaders?: GraphQLClientRequestHeaders): Promise<ProgramIndicatorsQuery> {
return withWrapper((wrappedRequestHeaders) => client.request<ProgramIndicatorsQuery>(ProgramIndicatorsDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), 'programIndicators', 'query', variables);
return withWrapper((wrappedRequestHeaders) => client.request<ProgramIndicatorsQuery>(ProgramIndicatorsDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'programIndicators', 'query', variables);
},
updateIndicatorValue(variables: UpdateIndicatorValueMutationVariables, requestHeaders?: GraphQLClientRequestHeaders): Promise<UpdateIndicatorValueMutation> {
return withWrapper((wrappedRequestHeaders) => client.request<UpdateIndicatorValueMutation>(UpdateIndicatorValueDocument, variables, { ...requestHeaders, ...wrappedRequestHeaders }), 'updateIndicatorValue', 'mutation', variables);
return withWrapper((wrappedRequestHeaders) => client.request<UpdateIndicatorValueMutation>(UpdateIndicatorValueDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'updateIndicatorValue', 'mutation', variables);
}
};
}
Expand Down
Loading
Loading