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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | 3x 3x 1x 2x 2x 1x 3x 3x 1x 2x 1x 3x 3x 1x 2x 2x 1x 6x 6x 1x 5x 2x 2x 1x 3x 2x 2x 1x 3x 3x 1x 2x 2x 1x 3x 3x 1x 2x 1x 3x 3x 1x 2x 2x 1x 2x 2x 1x 3x 3x 1x 2x 2x 1x 4x 4x 1x 3x 1x 3x 3x 1x 2x 2x 1x 2x 2x 2x 1x | import APIError from '../helpers/error'; import { t } from '../helpers/i18n'; import BranchInformation from '../source/branches/information'; import CarrierInformation from '../source/carriers/information'; import CustomerInformation from '../source/customers/information'; import DepositInformation from '../source/deposits/information'; import OrderTypeConfigInformation from '../source/orderTypeConfig/information'; import SupplierInformation from '../source/suppliers/information'; import OrderTypeInformation from '../source/typeOrders/information'; import StockGroupInformation from '../source/stockGroup/information'; async function validBranchCode(req) { const { branchCode } = req.body; if (!branchCode) { throw new APIError('', t('BEE1171' /* Código deve ser informado ! */)); } const branch = await BranchInformation.getBranch({ code: branchCode }); if (!branch) { throw new APIError('', t('BEE2028' /* Filial não localizada */)); } } function validMovementType(req) { const { movementType } = req.body; if (!movementType) { throw new APIError( '', t('BEE4095' /* O tipo de movimentação deve ser informado. */) ); } else if (movementType !== 1 && movementType !== 2) { throw new APIError( '', t('BEE4096' /* O tipo de movimentação informado é inválido! */) ); } } async function validDepositCode(req) { const { depositCode } = req.body; if (!depositCode) { throw new APIError( '', t('BEE193' /* Informe o depósito (obrigatório) ! */) ); } const deposit = await DepositInformation.getDeposit({ code: depositCode }); if (!deposit) { throw new APIError('', t('BEE4097' /* Depósito não encontrado! */)); } } async function validCustomerSupplierCode(req) { const { customerSupplierCode, movementType } = req.body; if (!customerSupplierCode) { throw new APIError( '', t('BEE4098' /* Cliente/Fornecedor deve ser informado! */) ); } // Entrada (Fornecedor) if (movementType === 1) { const supplier = await SupplierInformation.getSupplier({ code: customerSupplierCode, }); if (!supplier && customerSupplierCode !== '*') { throw new APIError( '', t( 'BEE1250', { 0: customerSupplierCode, } /* Fornecedor %{0} não localizado */ ) ); } // Saída (Cliente) } else if (movementType === 2) { const customer = await CustomerInformation.getCustomer({ code: customerSupplierCode, }); if (!customer && customerSupplierCode !== '*') { throw new APIError( '', t( 'BEE1190', { 0: customerSupplierCode } /* Cliente %{0} não localizado */ ) ); } } } async function validCarrierCode(req) { const carrierCode = req.body.carrierCode || req.query.carrierCode; if (!carrierCode) { throw new APIError( '', t('BEE1317' /* Código da transportadora deve ser informado */) ); } const carrier = await CarrierInformation.getCarrier({ code: carrierCode, }); if (!carrier && carrierCode !== '*') throw new APIError( '', t('BEE1179', { 0: carrierCode } /* Transportadora %{0} inválida ! */) ); } function validDeliveryType(req) { const { deliveryType } = req.body; if (!deliveryType && deliveryType !== 0) { throw new APIError( '', t('BEE1340' /* Tipo de entrega deve ser informado */) ); } if (deliveryType !== 0 && deliveryType !== 1 && deliveryType !== 2) { throw new APIError( '', t('BEE1341', { 0: deliveryType } /* Tipo de entrega %{0} inválido */) ); } } function validStockGroupCode(req) { const { stockGroupCode } = req.body; if (!stockGroupCode) { throw new APIError( '', t('BEE4100' /* O grupo de estoque deve ser informado! */) ); } const stockGroup = StockGroupInformation.getStockGroup({ code: stockGroupCode, }); if (!stockGroup) { throw new APIError( '', t( 'BEE4033', { 0: stockGroupCode } /* Grupo de estoque %{0} não encontrado */ ) ); } } function validCfop(req) { const { cfop } = req.body; if (!cfop) { throw new APIError( '', t('BEE4101' /* A operação fiscal deve ser informada! */) ); } } async function validOrderType(req) { const { orderTypeCode, branchCode } = req.body; if (!orderTypeCode) { throw new APIError( '', t('BEE4102' /* O tipo de documento deve ser informado! */) ); } const orderType = await OrderTypeInformation.getTypeOrder({ branchCode, type: orderTypeCode, }); if (!orderType) { throw new APIError( '', t('BEE4103' /* Tipo de documento não encontrado! */) ); } } function validStatus(req) { const { status } = req.body; if (!status && status !== 0) { throw new APIError('', t('BEE1198' /* Status deve ser informado! */)); } if (status !== 0 && status !== 1) { throw new APIError('', t('BEE4104' /* Status informado inválido. */)); } } async function validConfigId(req) { const { configId } = req.body; if (!configId) { throw new APIError('', t('BEE4105' /* A regra deve ser informada! */)); } const config = await OrderTypeConfigInformation.getOrderTypeConfig({ id: configId, }); if (!config) { throw new APIError('', t('BEE4106' /* Regra não encontrada. */)); } } async function validConfigExist(req) { const { movementType, branchCode, depositCode, customerSupplierCode, carrierCode, deliveryType, stockGroupCode, cfop, } = req.body; const config = await OrderTypeConfigInformation.getOrderTypeConfig({ movementType, branchCode, depositCode, customerSupplierCode, carrierCode, deliveryType, stockGroupCode, cfop, }); if (config) { throw new APIError('', t('BEE4107' /* Regra já cadastrada! */)); } } export default { validBranchCode, validMovementType, validDepositCode, validConfigExist, validStatus, validConfigId, validDeliveryType, validOrderType, validCustomerSupplierCode, validCarrierCode, validStockGroupCode, validCfop, }; |