|
@@ -17,6 +17,7 @@
|
|
|
const ORDERBOOK_PAYMENT_STORAGE_PREFIX = 'tooeasy_orderbook_payment_';
|
|
const ORDERBOOK_PAYMENT_STORAGE_PREFIX = 'tooeasy_orderbook_payment_';
|
|
|
const CIDADES_ESTADOS_SRC = 'https://cdn.jsdelivr.net/npm/cidades-estados@1.4.1/cidades-estados.js';
|
|
const CIDADES_ESTADOS_SRC = 'https://cdn.jsdelivr.net/npm/cidades-estados@1.4.1/cidades-estados.js';
|
|
|
const DEFAULT_STATE_OPTIONS = ['AC','AL','AP','AM','BA','CE','DF','ES','GO','MA','MT','MS','MG','PA','PB','PR','PE','PI','RJ','RN','RS','RO','RR','SC','SP','SE','TO'];
|
|
const DEFAULT_STATE_OPTIONS = ['AC','AL','AP','AM','BA','CE','DF','ES','GO','MA','MT','MS','MG','PA','PB','PR','PE','PI','RJ','RN','RS','RO','RR','SC','SP','SE','TO'];
|
|
|
|
|
+ const PACKAGING_SACK_LABEL = 'saca (60 kg)';
|
|
|
|
|
|
|
|
const orders = writable([]);
|
|
const orders = writable([]);
|
|
|
|
|
|
|
@@ -75,6 +76,32 @@
|
|
|
return raw ? JSON.parse(raw) : null;
|
|
return raw ? JSON.parse(raw) : null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ function resolvePackagingValue(source = {}) {
|
|
|
|
|
+ return pickNonEmptyString(source, [
|
|
|
|
|
+ 'packagingName',
|
|
|
|
|
+ 'packaging_name',
|
|
|
|
|
+ 'packagingname',
|
|
|
|
|
+ 'Packagingname',
|
|
|
|
|
+ 'PACKAGINGNAME'
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function normalizePackaging(value = '') {
|
|
|
|
|
+ return value
|
|
|
|
|
+ ?.toString?.()
|
|
|
|
|
+ ?.normalize?.('NFD')
|
|
|
|
|
+ ?.replace?.(/\p{Diacritic}/gu, '')
|
|
|
|
|
+ ?.trim()
|
|
|
|
|
+ ?.toLowerCase?.();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function isSackPackaging(value = '') {
|
|
|
|
|
+ const normalized = normalizePackaging(value);
|
|
|
|
|
+ if (!normalized) return false;
|
|
|
|
|
+ if (normalized === PACKAGING_SACK_LABEL) return true;
|
|
|
|
|
+ return normalized.includes('saca') && normalized.includes('60');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
function pickNonEmptyString(source = {}, keys = []) {
|
|
function pickNonEmptyString(source = {}, keys = []) {
|
|
|
if (!source || typeof source !== 'object') return '';
|
|
if (!source || typeof source !== 'object') return '';
|
|
|
for (const key of keys) {
|
|
for (const key of keys) {
|
|
@@ -316,7 +343,11 @@
|
|
|
function mapOrderResponse(item = {}) {
|
|
function mapOrderResponse(item = {}) {
|
|
|
const totalValue = Number(item?.token_commodities_value ?? item?.valor ?? 0);
|
|
const totalValue = Number(item?.token_commodities_value ?? item?.valor ?? 0);
|
|
|
const quantidade = Number(item?.orderbook_amount ?? item?.token_commodities_amount ?? item?.quantidade ?? 0);
|
|
const quantidade = Number(item?.orderbook_amount ?? item?.token_commodities_amount ?? item?.quantidade ?? 0);
|
|
|
- const valorPorSaca = quantidade ? totalValue / quantidade : totalValue;
|
|
|
|
|
|
|
+ const packagingName = resolvePackagingValue(item) || resolvePackagingValue(item?.raw ?? {});
|
|
|
|
|
+ const adjustedQuantity = isSackPackaging(packagingName) && quantidade
|
|
|
|
|
+ ? quantidade / 60
|
|
|
|
|
+ : quantidade;
|
|
|
|
|
+ const valorPorSaca = adjustedQuantity ? totalValue / adjustedQuantity : totalValue;
|
|
|
const resolvedCity = resolveCityValue(item);
|
|
const resolvedCity = resolveCityValue(item);
|
|
|
const resolvedMeasureUnit = resolveMeasureUnitValue(item);
|
|
const resolvedMeasureUnit = resolveMeasureUnitValue(item);
|
|
|
return {
|
|
return {
|
|
@@ -1072,7 +1103,7 @@
|
|
|
token_external_id: tokenExternalId
|
|
token_external_id: tokenExternalId
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- const res = await fetch(`${apiUrl} `, {
|
|
|
|
|
|
|
+ const res = await fetch(`${apiUrl}/token/orderbook`, {
|
|
|
method: 'POST',
|
|
method: 'POST',
|
|
|
headers: {
|
|
headers: {
|
|
|
'content-type': 'application/json',
|
|
'content-type': 'application/json',
|