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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | 2x 2x 2x 1x 1x 2x 1x 1x 2x 2x 44x 44x 44x 44x 2x 22x 2x 4x 2x 2x 2x 22x 2x 4x 2x 2x 2x 44x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 26x 26x 26x 12x 12x 2x | import moment from 'moment-timezone'; import outboundOrderProductsDao from '../../database/dao/outboundOrderProduct'; import I18n from '../../helpers/i18n'; import { models } from '../../../config/database'; import { mountWhereBasedFilter } from '../../helpers/reports/sequelize'; import { filter } from 'bluebird'; // Funcao criada para popular o array headers e rows enviados por parametro export default async function generateData(columns, filters, headers = [], rows = [], opts = {}) { const productsFilter = {}; Eif (filters) { if (filters.productCode) { productsFilter['productCode'] = filters.productCode; delete filters.productCode; } if (filters.login) { productsFilter['login'] = filters.login; delete filters.login; } } const whereProducts = mountWhereBasedFilter(productsFilter); const whereOrders = mountWhereBasedFilter(filters); let headersValue = columns.map(it => it.value); // Filtrar todos os que vem com 'order.' let resultsOrder = headersValue.filter(option => option.startsWith('outboundOrder.')) // Filtrar todos os que vem com 'products.' let resultsProducts = headersValue.filter(option => option.startsWith('products.')) const orderColumns = headersValue.filter(option => option.startsWith('outboundOrder.')); // Funções para cortar e separar os labels do 'outboundOrder e products.' resultsOrder.forEach((element, index) => { resultsOrder[index] = element.split('.') }); resultsProducts.forEach((element, index) => { resultsProducts[index] = element.split('.') }) const orderValues = []; const productsValues = []; // Laço para popular os arrays com os labels obtidos após o split. for (let i = 0; i < resultsOrder.length; i++) { orderValues.push(resultsOrder[i][1]) } for (let i = 0; i < resultsProducts.length; i++) { productsValues.push(resultsProducts[i][1]) } const dados = await outboundOrderProductsDao.findOutboundOrderProducts(whereProducts, { attributes: productsValues, raw: true, include: [{ required: true, model: models.OutboundOrder, attributes: orderValues, as: 'outboundOrder', where: whereOrders, include: [{ required: false, model: models.User, as: 'pickStartUserObj', attributes: ['login'], }, { required: false, model: models.User, as: 'checkStartUserObj', attributes: ['login'], }, { required: false, model: models.User, as: 'checkEndUserObj', attributes: ['login'], }, { required: false, model: models.User, as: 'pickEndUserObj', attributes: ['login'], }], }, { required: false, model: models.User, as: 'userCreated', attributes: ['login'], }, { required: false, model: models.User, as: 'userUpdated', attributes: ['login'], }, { required: false, model: models.User, as: 'pickedUserObj', attributes: ['login'], }, { required: false, model: models.User, as: 'checkedUserObj', attributes: ['login'], },], ...opts }) const ordersProductsConcat = orderColumns.concat(productsValues) columns.forEach(it => { headers.push(it.label); }); dados.forEach(it => { it.createdUser = it["userCreated.login"] it.updatedUser = it["userUpdated.login"] it.pickedUser = it["pickedUserObj.login"] it.checkedUser = it["checkedUserObj.login"] // it da tabela de Order it['outboundOrder.pickStartUser'] = it["outboundOrder.pickStartUserObj.login"] it['outboundOrder.checkStartUser'] = it["outboundOrder.checkStartUserObj.login"] it['outboundOrder.checkEndUser'] = it["outboundOrder.checkEndUserObj.login"] it['outboundOrder.pickEndUser'] = it["outboundOrder.pickEndUserObj.login"] const row = []; for (let index = 0; index < ordersProductsConcat.length; index++) { const column = ordersProductsConcat[index] row.push(it[column]); // Traduz o tempo do banco para um formato mais bacana para o usuário (moment.js) if (column === 'pickedAt' || column === 'checkedAt' || column === 'createdAt' || column === 'updatedAt' || column === 'outboundOrder.deliveryDate' || column === 'outboundOrder.orderDate' || column === 'outboundOrder.pickStartAt' || column === 'outboundOrder.pickEndAt' || column === 'outboundOrder.checkStartAt' || column === 'outboundOrder.checkEndAt') { Eif (row[index] != null) { row[index] = moment(row[index]).format('l LTS') } } } rows.push(row); }) } |