diff --git a/config/default-values.ts b/config/default-values.ts index cfd496a..c62a013 100644 --- a/config/default-values.ts +++ b/config/default-values.ts @@ -11,7 +11,7 @@ const defaultValues: CalculationValues = { VATInLeaseObjectPrice: 0, leaseObjectPriceWthtVAT: 0, engineHours: 0, - supplierCurrency: 'RUB', + supplierCurrency: null, supplierDiscountRub: 0, supplierDiscountPerc: 0, leasingPeriod: 13, diff --git a/pages/__generated__/GetTransactionCurrencies.ts b/pages/__generated__/GetTransactionCurrencies.ts new file mode 100644 index 0000000..2b868af --- /dev/null +++ b/pages/__generated__/GetTransactionCurrencies.ts @@ -0,0 +1,22 @@ +/* tslint:disable */ +/* eslint-disable */ +// @generated +// This file was automatically generated and should not be edited. + +// ==================================================== +// GraphQL query operation: GetTransactionCurrencies +// ==================================================== + +export interface GetTransactionCurrencies_transactioncurrencies { + __typename: "transactioncurrency"; + label: string | null; + currencysymbol: string | null; + value: any | null; +} + +export interface GetTransactionCurrencies { + /** + * Валюта. statecode по умолчанию 0 + */ + transactioncurrencies: (GetTransactionCurrencies_transactioncurrencies | null)[] | null; +} diff --git a/pages/index.jsx b/pages/index.jsx index a6b7f29..7175736 100644 --- a/pages/index.jsx +++ b/pages/index.jsx @@ -44,13 +44,14 @@ function Home({ graphQLData }) { /** * set owner data to store */ - const { ownerData } = graphQLData; + const { ownerData, transactioncurrencies } = graphQLData; const { $calculation } = store; $calculation.$options.setOptions({ selectLead: ownerData?.leads || [], selectOpportunity: ownerData.opportunities || [], + selectSupplierCurrency: transactioncurrencies || [], }); return ( @@ -78,6 +79,16 @@ const QUERY_GET_OWNER_DATA = gql` } `; +const QUERY_GET_TRANSACTION_CURRENCIES = gql` + query GetTransactionCurrencies { + transactioncurrencies { + label: currencyname + currencysymbol + value: transactioncurrencyid + } + } +`; + export const getServerSideProps = async (ctx) => { const user = await fetchUser({ headers: ctx?.req?.headers?.cookie @@ -96,10 +107,16 @@ export const getServerSideProps = async (ctx) => { }, }); + // prettier-ignore + const { data: { transactioncurrencies }, } = await apolloClient.query({ + query: QUERY_GET_TRANSACTION_CURRENCIES, + }); + return { props: { graphQLData: { ownerData, + transactioncurrencies, }, initialApolloState: apolloClient.cache.extract(), }, diff --git a/stores/calculation/options/index.ts b/stores/calculation/options/index.ts index 34206f5..a249faa 100644 --- a/stores/calculation/options/index.ts +++ b/stores/calculation/options/index.ts @@ -53,7 +53,7 @@ export default class OptionsStore { * Проверяем, что значение есть в новом списке, иначе сбрасываем значение */ const value = this.root.$calculation.$values.getElementValue(elementName); - if (options.length === 0 || options.some((x) => x.value === value)) { + if (!options?.length || options.some((x) => x.value === value)) { this.root.$calculation.$values.resetElementValue(elementName); }