Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | import SheetSerialLogInformation from '../../database/dao/inventorySheetSerialLog'; import { models } from '../../../config/database'; import { mountWhereBasedFilter } from '../../helpers/reports/sequelize'; import { t } from '../../helpers/i18n'; // Funcao criada para popular o array headers e rows enviados por parametro export default async function generateData( columns, filters, headers = [], rows = [], opts = {}, appLanguage = 'ptBr' ) { const where = mountWhereBasedFilter(filters); const headersValueLogs = columns .filter((it) => it.table === 'InventorySheetSerialLog') .map((it) => it.value); const headersValueInventory = columns .filter((it) => it.table === 'inventory') .map((it) => it.value); const headersValueSheet = columns .filter((it) => it.table === 'inventorySheet') .map((it) => it.value); const headersValueGroup = columns .filter((it) => it.table === 'serialGroup') .map((it) => it.value); const headersValueSerial = columns .filter((it) => it.table === 'serialLabel') .map(() => 'code'); const headersValueUser = columns .filter((it) => it.table === 'userCreated') .map((it) => it.value); const headersValueProduct = columns .filter((it) => it.table === 'product') .map((it) => (it.value === 'productName' ? 'name' : it.value)); const dados = await SheetSerialLogInformation.findInventorySheetSerialLogs( where, { attributes: headersValueLogs, include: [ { attributes: headersValueInventory, required: true, model: models.Inventory, as: 'inventory', }, { attributes: headersValueSheet, required: true, model: models.InventorySheet, as: 'inventorySheet', include: [ { attributes: headersValueProduct, required: true, model: models.Product, as: 'product', }, ], }, { attributes: headersValueGroup, required: false, model: models.SerialGroup, as: 'serialGroup', }, { attributes: headersValueSerial, required: false, model: models.SerialLabel, as: 'serialLabel', }, { attributes: headersValueUser, required: false, model: models.User, as: 'userCreated', }, ], ...opts, } ); columns.forEach((it) => { headers.push(it.label); }); const typeOptions = { 1: t('BEE3612' /* Divergente */, undefined, appLanguage), 2: t('BEE3613' /* Etiqueta não prevista */, undefined, appLanguage), 3: t('BEE3614' /* Etiqueta não lida */, undefined, appLanguage), }; dados.forEach((it) => { const row = []; for (let index = 0; index < columns.length; index++) { const column = columns[index].value; let value; if (columns[index].table === 'InventorySheetSerialLog') { if (column === 'type') { value = it[column] ? typeOptions[it[column]] : ''; } else { value = it[column]; } } else if (columns[index].table === 'product') { value = it.inventorySheet.product[columns[index].value]; } else if (columns[index].table === 'serialLabel') { value = (it.serialLabel && it.serialLabel.code) || ''; } else { value = it[columns[index].table] ? it[columns[index].table][columns[index].value] : ''; } if (columns[index].type === 'Number' && value !== '') { value = parseFloat(value); } row.push(value); } rows.push(row); }); } |