diff --git a/src/pages/Supplier/Card/SupplierConsumption.vue b/src/pages/Supplier/Card/SupplierConsumption.vue index 5407af1df..85549acb3 100644 --- a/src/pages/Supplier/Card/SupplierConsumption.vue +++ b/src/pages/Supplier/Card/SupplierConsumption.vue @@ -30,7 +30,7 @@ const { notify } = useNotify(); const totalRows = ref({}); const arrayData = useArrayData('SupplierConsumption', { url: 'Suppliers/consumption', - order: ['itemTypeFk', 'item', 'itemSize'], + order: ['itemTypeFk', 'itemName', 'itemSize'], userFilter: { where: { supplierFk: route.params.id } }, }); const headerColumns = computed(() => [ @@ -122,11 +122,13 @@ const dateRanges = computed(() => { }); const reportParams = computed(() => { - return { + console.log('reportParams', dateRanges.value); + const params = { recipientId: Number(route.params.id), - to: dateRange(dateRanges.value.to)[1], - from: dateRange(dateRanges.value.from)[1], + from: dateRange(dateRanges.value.from)[0].toISOString(), + to: dateRange(dateRanges.value.to)[1].toISOString(), }; + return params; }); async function getSupplierConsumptionData() { @@ -183,27 +185,27 @@ const sendCampaignMetricsEmail = ({ address }) => { }; const totalEntryPrice = (rows) => { - let totalPrice = 0; - let totalQuantity = 0; - if (!rows) return totalPrice; - for (const row of rows) { - let total = 0; - let quantity = 0; - - if (row.buys) { - for (const buy of row.buys) { - total = total + buy.total; - quantity = quantity + buy.quantity; + if (!rows) return []; + totalRows.value = rows.reduce( + (acc, row) => { + if (Array.isArray(row.buys)) { + const { total, quantity } = row.buys.reduce( + (buyAcc, buy) => { + buyAcc.total += buy.total || 0; + buyAcc.quantity += buy.quantity || 0; + return buyAcc; + }, + { total: 0, quantity: 0 }, + ); + row.total = total; + row.quantity = quantity; + acc.totalPrice += total; + acc.totalQuantity += quantity; } - } - - row.total = total; - row.quantity = quantity; - totalPrice = totalPrice + total; - totalQuantity = totalQuantity + quantity; - } - totalRows.value = { totalPrice, totalQuantity }; - // expanded.value = rows.map((r) => r.id); + return acc; + }, + { totalPrice: 0, totalQuantity: 0 }, + ); return rows; }; const tableRef = ref(null); @@ -212,64 +214,7 @@ onMounted(async () => { await getSupplierConsumptionData(); }); const lastAction = ref(null); -const isAction = (action) => { - if (lastAction.value === action) { - lastAction.value = null; - return true; - } - lastAction.value = action; - return false; -}; -const isActionExpand = (action) => { - if (action === 'expand_all') { - return isAction('expand_all'); - } - if (action === 'unfold_all') { - return isAction('unfold_all'); - } -}; -const isActionExpandAll = computed(() => { - return isActionExpand('expand_all'); -}); -const isActionUnfoldAll = computed(() => { - return isActionExpand('unfold_all'); -}); -const isActionExpandAllIcon = computed(() => { - return isActionExpandAll.value ? 'unfold_less' : 'expand_more'; -}); -const isActionUnfoldAllIcon = computed(() => { - return isActionUnfoldAll.value ? 'expand_more' : 'unfold_less'; -}); -const isActionExpandAllLabel = computed(() => { - return isActionExpandAll.value ? t('globals.unfold_all') : t('globals.expand_all'); -}); -const isActionUnfoldAllLabel = computed(() => { - return isActionUnfoldAll.value ? t('globals.expand_all') : t('globals.unfold_all'); -}); -const isActionExpandAllDisabled = computed(() => { - return !rows.value.length; -}); -const isActionUnfoldAllDisabled = computed(() => { - return !rows.value.length; -}); -const isActionExpandAllTooltip = computed(() => { - return isActionExpandAll.value ? t('globals.unfold_all') : t('globals.expand_all'); -}); -const isActionUnfoldAllTooltip = computed(() => { - return isActionUnfoldAll.value ? t('globals.expand_all') : t('globals.unfold_all'); -}); -const isActionExpandAllIconClass = computed(() => { - return isActionExpandAll.value ? 'vn:unfold_less' : 'vn:expand_more'; -}); -const isActionUnfoldAllIconClass = computed(() => { - return isActionUnfoldAll.value ? 'vn:expand_more' : 'vn:unfold_less'; -}); -const isActionExpandAllIconClassColor = computed(() => { - return isActionExpandAll.value ? 'primary' : 'grey-4'; -}); -const isActionUnfoldAllIconClassColor = computed(() => { - return isActionUnfoldAll.value ? 'primary' : 'grey-4'; -}); +const expanded = ref([]); const actions = (action) => { if (action === 'expand_all') { expanded.value = rows.value.map((r) => r.id); @@ -278,8 +223,6 @@ const actions = (action) => { } lastAction.value = action; }; -const expanded = ref([]); -// const initialExpanded = rows.filter((r, i) => i % 3 === 0).map((r) => r.index);