Commit aab55e8570aff9c373c184bd901bd0aa93df1396
1 parent
6eccd5edf7
Exists in
master
and in
1 other branch
inicial
Showing
1 changed file
with
6 additions
and
5 deletions
Show diff stats
src/js/controller.js
| 1 | angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', | 1 | angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
| 2 | [ | 2 | [ |
| 3 | '$scope', | 3 | '$scope', |
| 4 | '$uibModal', | 4 | '$uibModal', |
| 5 | '$location', | 5 | '$location', |
| 6 | '$filter', | 6 | '$filter', |
| 7 | '$timeout', | 7 | '$timeout', |
| 8 | 'crearNotaPedidoService', | 8 | 'crearNotaPedidoService', |
| 9 | 'focaBotoneraLateralService', | 9 | 'focaBotoneraLateralService', |
| 10 | 'focaModalService', | 10 | 'focaModalService', |
| 11 | 'notaPedidoBusinessService', | 11 | 'notaPedidoBusinessService', |
| 12 | '$rootScope', | 12 | '$rootScope', |
| 13 | 'focaSeguimientoService', | 13 | 'focaSeguimientoService', |
| 14 | 'APP', | 14 | 'APP', |
| 15 | 'focaLoginService', | 15 | 'focaLoginService', |
| 16 | '$localStorage', | 16 | '$localStorage', |
| 17 | function( | 17 | function( |
| 18 | $scope, $uibModal, $location, $filter, $timeout, crearNotaPedidoService, | 18 | $scope, $uibModal, $location, $filter, $timeout, crearNotaPedidoService, |
| 19 | focaBotoneraLateralService, focaModalService, notaPedidoBusinessService, | 19 | focaBotoneraLateralService, focaModalService, notaPedidoBusinessService, |
| 20 | $rootScope, focaSeguimientoService, APP, focaLoginService, $localStorage) | 20 | $rootScope, focaSeguimientoService, APP, focaLoginService, $localStorage) |
| 21 | { | 21 | { |
| 22 | config(); | 22 | config(); |
| 23 | 23 | ||
| 24 | function config() { | 24 | function config() { |
| 25 | // PARAMETROS INICIALES PARA FUNCIONAMIENTO DEL PROGRAMA | 25 | // PARAMETROS INICIALES PARA FUNCIONAMIENTO DEL PROGRAMA |
| 26 | $scope.tmpCantidad = Number; | 26 | $scope.tmpCantidad = Number; |
| 27 | $scope.tmpPrecio = Number; | 27 | $scope.tmpPrecio = Number; |
| 28 | $scope.notaPedido = {}; | 28 | $scope.notaPedido = {}; |
| 29 | $scope.isNumber = angular.isNumber; | 29 | $scope.isNumber = angular.isNumber; |
| 30 | $scope.datepickerAbierto = false; | 30 | $scope.datepickerAbierto = false; |
| 31 | $scope.show = false; | 31 | $scope.show = false; |
| 32 | $scope.cargando = true; | 32 | $scope.cargando = true; |
| 33 | $scope.botonera = crearNotaPedidoService.getBotonera(); | 33 | $scope.botonera = crearNotaPedidoService.getBotonera(); |
| 34 | $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); | 34 | $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); |
| 35 | $scope.comprobante = $filter('rellenarDigitos')(0, 8); | 35 | $scope.comprobante = $filter('rellenarDigitos')(0, 8); |
| 36 | $scope.dateOptions = { | 36 | $scope.dateOptions = { |
| 37 | maxDate: new Date(), | 37 | maxDate: new Date(), |
| 38 | minDate: new Date(2010, 0, 1) | 38 | minDate: new Date(2010, 0, 1) |
| 39 | }; | 39 | }; |
| 40 | 40 | ||
| 41 | //SETEO BOTONERA LATERAL | 41 | //SETEO BOTONERA LATERAL |
| 42 | $timeout(function() { | 42 | $timeout(function() { |
| 43 | focaBotoneraLateralService.showSalir(false); | 43 | focaBotoneraLateralService.showSalir(false); |
| 44 | focaBotoneraLateralService.showPausar(true); | 44 | focaBotoneraLateralService.showPausar(true); |
| 45 | focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido); | 45 | focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido); |
| 46 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 46 | focaBotoneraLateralService.addCustomButton('Salir', salir); |
| 47 | }); | 47 | }); |
| 48 | 48 | ||
| 49 | // SETEA BOTONERA DE FACTURADOR TENIENDO EN CUENTA SI ESTA SETEADO EL VENDEDOR | 49 | // SETEA BOTONERA DE FACTURADOR TENIENDO EN CUENTA SI ESTA SETEADO EL VENDEDOR |
| 50 | if (APP === 'distribuidor') { | 50 | if (APP === 'distribuidor') { |
| 51 | $scope.idVendedor = focaLoginService.getLoginData().vendedorCobrador; | 51 | $scope.idVendedor = focaLoginService.getLoginData().vendedorCobrador; |
| 52 | } | 52 | } |
| 53 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' | 53 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' |
| 54 | //Trabajo con el proveedor YPF, por eso uso siempre la primera | 54 | //Trabajo con el proveedor YPF, por eso uso siempre la primera |
| 55 | 55 | ||
| 56 | var promiseMoneda = crearNotaPedidoService.getCotizacionByIdMoneda(1); | 56 | var promiseMoneda = crearNotaPedidoService.getCotizacionByIdMoneda(1); |
| 57 | var promiseProveedor = crearNotaPedidoService.getProveedorById(98); | 57 | var promiseProveedor = crearNotaPedidoService.getProveedorById(98); |
| 58 | 58 | ||
| 59 | //TODO refactor después de demo | 59 | //TODO refactor después de demo |
| 60 | Promise.all([promiseMoneda, promiseProveedor]).then(function(res) { | 60 | Promise.all([promiseMoneda, promiseProveedor]).then(function(res) { |
| 61 | 61 | ||
| 62 | var monedaPorDefecto = res[0].data[0]; | 62 | var monedaPorDefecto = res[0].data[0]; |
| 63 | 63 | ||
| 64 | $scope.notaPedido.cotizacion = Object.assign( | 64 | $scope.notaPedido.cotizacion = Object.assign( |
| 65 | {moneda: monedaPorDefecto}, | 65 | {moneda: monedaPorDefecto}, |
| 66 | monedaPorDefecto.cotizaciones[0] | 66 | monedaPorDefecto.cotizaciones[0] |
| 67 | ); | 67 | ); |
| 68 | $scope.inicial.cotizacion = $scope.notaPedido.cotizacion; | 68 | $scope.inicial.cotizacion = $scope.notaPedido.cotizacion; |
| 69 | 69 | ||
| 70 | var proveedorPorDefecto = res[1].data[0]; | 70 | var proveedorPorDefecto = res[1].data[0]; |
| 71 | 71 | ||
| 72 | $scope.notaPedido.proveedor = proveedorPorDefecto; | 72 | $scope.notaPedido.proveedor = proveedorPorDefecto; |
| 73 | $scope.inicial.proveedor = $scope.notaPedido.proveedor; | 73 | $scope.inicial.proveedor = $scope.notaPedido.proveedor; |
| 74 | 74 | ||
| 75 | $scope.notaPedido.flete = false; | 75 | $scope.notaPedido.flete = false; |
| 76 | $scope.notaPedido.fob = false; | 76 | $scope.notaPedido.fob = false; |
| 77 | $scope.notaPedido.bomba = false; | 77 | $scope.notaPedido.bomba = false; |
| 78 | 78 | ||
| 79 | $scope.inicial.flete = false; | 79 | $scope.inicial.flete = false; |
| 80 | $scope.inicial.fob = false; | 80 | $scope.inicial.fob = false; |
| 81 | $scope.inicial.bomba = false; | 81 | $scope.inicial.bomba = false; |
| 82 | 82 | ||
| 83 | $timeout(function() { getLSNotaPedido();} ); | 83 | $timeout(function() { getLSNotaPedido();} ); |
| 84 | }); | 84 | }); |
| 85 | 85 | ||
| 86 | init(); | 86 | init(); |
| 87 | 87 | ||
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | function init() { | 90 | function init() { |
| 91 | $scope.$broadcast('cleanCabecera'); | 91 | $scope.$broadcast('cleanCabecera'); |
| 92 | 92 | ||
| 93 | $scope.notaPedido = { | 93 | $scope.notaPedido = { |
| 94 | id: 0, | 94 | id: 0, |
| 95 | cliente: {}, | 95 | cliente: {}, |
| 96 | proveedor: {}, | 96 | proveedor: {}, |
| 97 | domicilio: {dom: ''}, | 97 | domicilio: {dom: ''}, |
| 98 | vendedor: {}, | 98 | vendedor: {}, |
| 99 | fechaCarga: new Date(), | 99 | fechaCarga: new Date(), |
| 100 | cotizacion: {}, | 100 | cotizacion: {}, |
| 101 | articulosNotaPedido: [], | 101 | articulosNotaPedido: [], |
| 102 | notaPedidoPlazo: [], | 102 | notaPedidoPlazo: [], |
| 103 | notaPedidoPuntoDescarga: { | 103 | notaPedidoPuntoDescarga: { |
| 104 | puntoDescarga: {} | 104 | puntoDescarga: {} |
| 105 | } | 105 | } |
| 106 | }; | 106 | }; |
| 107 | $scope.idLista = undefined; | 107 | $scope.idLista = undefined; |
| 108 | 108 | ||
| 109 | crearNotaPedidoService.getNumeroNotaPedido().then( | 109 | crearNotaPedidoService.getNumeroNotaPedido().then( |
| 110 | function(res) { | 110 | function(res) { |
| 111 | $scope.puntoVenta = $filter('rellenarDigitos')( | 111 | $scope.puntoVenta = $filter('rellenarDigitos')( |
| 112 | res.data.sucursal, 4 | 112 | res.data.sucursal, 4 |
| 113 | ); | 113 | ); |
| 114 | 114 | ||
| 115 | $scope.comprobante = $filter('rellenarDigitos')( | 115 | $scope.comprobante = $filter('rellenarDigitos')( |
| 116 | res.data.numeroNotaPedido, 8 | 116 | res.data.numeroNotaPedido, 8 |
| 117 | ); | 117 | ); |
| 118 | }, | 118 | }, |
| 119 | function(err) { | 119 | function(err) { |
| 120 | focaModalService.alert('La terminal no esta configurada correctamente'); | 120 | focaModalService.alert('La terminal no esta configurada correctamente'); |
| 121 | console.info(err); | 121 | console.info(err); |
| 122 | } | 122 | } |
| 123 | ); | 123 | ); |
| 124 | 124 | ||
| 125 | if (APP === 'distribuidor') { | 125 | if (APP === 'distribuidor') { |
| 126 | crearNotaPedidoService.getVendedorById($scope.idVendedor).then( | 126 | crearNotaPedidoService.getVendedorById($scope.idVendedor).then( |
| 127 | function(res) { | 127 | function(res) { |
| 128 | var vendedor = res.data; | 128 | var vendedor = res.data; |
| 129 | $scope.$broadcast('addCabecera', { | 129 | $scope.$broadcast('addCabecera', { |
| 130 | label: 'Vendedor:', | 130 | label: 'Vendedor:', |
| 131 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + | 131 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + |
| 132 | vendedor.NOM | 132 | vendedor.NOM |
| 133 | }); | 133 | }); |
| 134 | 134 | ||
| 135 | $scope.notaPedido.vendedor = vendedor; | 135 | $scope.notaPedido.vendedor = vendedor; |
| 136 | $scope.inicial.vendedor = $scope.notaPedido.vendedor; | 136 | $scope.inicial.vendedor = $scope.notaPedido.vendedor; |
| 137 | } | 137 | } |
| 138 | ); | 138 | ); |
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | $scope.inicial = angular.copy($scope.notaPedido); | 141 | $scope.inicial = angular.copy($scope.notaPedido); |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | $scope.$watch('notaPedido', function(newValue) { | 144 | $scope.$watch('notaPedido', function(newValue) { |
| 145 | focaBotoneraLateralService.setPausarData({ | 145 | focaBotoneraLateralService.setPausarData({ |
| 146 | label: 'notaPedido', | 146 | label: 'notaPedido', |
| 147 | val: newValue | 147 | val: newValue |
| 148 | }); | 148 | }); |
| 149 | }, true); | 149 | }, true); |
| 150 | 150 | ||
| 151 | $scope.crearNotaPedido = function() { | 151 | $scope.crearNotaPedido = function() { |
| 152 | if (!$scope.notaPedido.cliente.COD) { | 152 | if (!$scope.notaPedido.cliente.COD) { |
| 153 | focaModalService.alert('Ingrese Cliente'); | 153 | focaModalService.alert('Ingrese Cliente'); |
| 154 | return; | 154 | return; |
| 155 | } else if ($scope.notaPedido.idRemito === -1) { | 155 | } else if ($scope.notaPedido.idRemito === -1) { |
| 156 | focaBotoneraLateralService.alert('No se puede modificar esta nota de pedido'); | 156 | focaBotoneraLateralService.alert('No se puede modificar esta nota de pedido'); |
| 157 | return; | 157 | return; |
| 158 | } else if (!$scope.notaPedido.proveedor.COD) { | 158 | } else if (!$scope.notaPedido.proveedor.COD) { |
| 159 | focaModalService.alert('Ingrese Proveedor'); | 159 | focaModalService.alert('Ingrese Proveedor'); |
| 160 | return; | 160 | return; |
| 161 | } else if (!$scope.notaPedido.cotizacion.ID) { | 161 | } else if (!$scope.notaPedido.cotizacion.ID) { |
| 162 | focaModalService.alert('Ingrese Cotización'); | 162 | focaModalService.alert('Ingrese Cotización'); |
| 163 | return; | 163 | return; |
| 164 | } else if (!$scope.notaPedido.cotizacion.moneda.ID) { | 164 | } else if (!$scope.notaPedido.cotizacion.moneda.ID) { |
| 165 | focaModalService.alert('Ingrese Moneda'); | 165 | focaModalService.alert('Ingrese Moneda'); |
| 166 | return; | 166 | return; |
| 167 | } else if (!$scope.notaPedido.notaPedidoPlazo) { | 167 | } else if (!$scope.notaPedido.notaPedidoPlazo) { |
| 168 | focaModalService.alert('Ingrese Precios y Condiciones'); | 168 | focaModalService.alert('Ingrese Precios y Condiciones'); |
| 169 | return; | 169 | return; |
| 170 | } else if ( | 170 | } else if ( |
| 171 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) | 171 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) |
| 172 | { | 172 | { |
| 173 | focaModalService.alert('Ingrese Flete'); | 173 | focaModalService.alert('Ingrese Flete'); |
| 174 | return; | 174 | return; |
| 175 | } else if (!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto | 175 | } else if (!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto |
| 176 | focaModalService.alert('Ingrese Domicilio'); | 176 | focaModalService.alert('Ingrese Domicilio'); |
| 177 | return; | 177 | return; |
| 178 | } else if ($scope.notaPedido.articulosNotaPedido.length === 0) { | 178 | } else if ($scope.notaPedido.articulosNotaPedido.length === 0) { |
| 179 | focaModalService.alert('Debe cargar al menos un articulo'); | 179 | focaModalService.alert('Debe cargar al menos un articulo'); |
| 180 | return; | 180 | return; |
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | focaBotoneraLateralService.startGuardar(); | 183 | focaBotoneraLateralService.startGuardar(); |
| 184 | $scope.saveLoading = true; | 184 | $scope.saveLoading = true; |
| 185 | var notaPedido = { | 185 | var notaPedido = { |
| 186 | id: $scope.notaPedido.id, | 186 | id: $scope.notaPedido.id, |
| 187 | fechaCarga: new Date($scope.notaPedido.fechaCarga) | 187 | fechaCarga: new Date($scope.notaPedido.fechaCarga) |
| 188 | .toISOString().slice(0, 19).replace('T', ' '), | 188 | .toISOString().slice(0, 19).replace('T', ' '), |
| 189 | idVendedor: $scope.notaPedido.vendedor.id, | 189 | idVendedor: $scope.notaPedido.vendedor.id, |
| 190 | idCliente: $scope.notaPedido.cliente.COD, | 190 | idCliente: $scope.notaPedido.cliente.COD, |
| 191 | nombreCliente: $scope.notaPedido.cliente.NOM, | 191 | nombreCliente: $scope.notaPedido.cliente.NOM, |
| 192 | cuitCliente: $scope.notaPedido.cliente.CUIT, | 192 | cuitCliente: $scope.notaPedido.cliente.CUIT, |
| 193 | idProveedor: $scope.notaPedido.proveedor.COD, | 193 | idProveedor: $scope.notaPedido.proveedor.COD, |
| 194 | idDomicilio: $scope.notaPedido.domicilio.id, | 194 | idDomicilio: $scope.notaPedido.domicilio.id, |
| 195 | idCotizacion: $scope.notaPedido.cotizacion.ID, | 195 | idCotizacion: $scope.notaPedido.cotizacion.ID, |
| 196 | idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, | 196 | idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, |
| 197 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 197 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
| 198 | flete: $scope.notaPedido.flete, | 198 | flete: $scope.notaPedido.flete, |
| 199 | fob: $scope.notaPedido.fob, | 199 | fob: $scope.notaPedido.fob, |
| 200 | bomba: $scope.notaPedido.bomba, | 200 | bomba: $scope.notaPedido.bomba, |
| 201 | kilometros: $scope.notaPedido.kilometros, | 201 | kilometros: $scope.notaPedido.kilometros, |
| 202 | domicilioStamp: $scope.notaPedido.domicilioStamp, | 202 | domicilioStamp: $scope.notaPedido.domicilioStamp, |
| 203 | observaciones: $scope.notaPedido.observaciones, | 203 | observaciones: $scope.notaPedido.observaciones, |
| 204 | estado: 0, | 204 | estado: 0, |
| 205 | total: $scope.getTotal() | 205 | total: $scope.getTotal() |
| 206 | }; | 206 | }; |
| 207 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( | 207 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( |
| 208 | function(data) { | 208 | function(data) { |
| 209 | // Al guardar los datos de la nota de pedido logueamos la | 209 | // Al guardar los datos de la nota de pedido logueamos la |
| 210 | // actividad para su seguimiento. | 210 | // actividad para su seguimiento. |
| 211 | //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? | 211 | //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? |
| 212 | focaSeguimientoService.guardarPosicion( | 212 | focaSeguimientoService.guardarPosicion( |
| 213 | 'Nota de pedido', | 213 | 'Nota de pedido', |
| 214 | data.data.id, | 214 | data.data.id, |
| 215 | '' | 215 | '' |
| 216 | ); | 216 | ); |
| 217 | notaPedidoBusinessService.addArticulos( | 217 | notaPedidoBusinessService.addArticulos( |
| 218 | $scope.notaPedido.articulosNotaPedido, | 218 | $scope.notaPedido.articulosNotaPedido, |
| 219 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); | 219 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); |
| 220 | 220 | ||
| 221 | if ($scope.notaPedido.notaPedidoPuntoDescarga) { | 221 | if ($scope.notaPedido.notaPedidoPuntoDescarga) { |
| 222 | notaPedidoBusinessService.addPuntosDescarga(data.data.id, | 222 | notaPedidoBusinessService.addPuntosDescarga(data.data.id, |
| 223 | $scope.notaPedido.notaPedidoPuntoDescarga); | 223 | $scope.notaPedido.notaPedidoPuntoDescarga); |
| 224 | } | 224 | } |
| 225 | 225 | ||
| 226 | var plazos = $scope.notaPedido.notaPedidoPlazo; | 226 | var plazos = $scope.notaPedido.notaPedidoPlazo; |
| 227 | var plazosACrear = []; | 227 | var plazosACrear = []; |
| 228 | plazos.forEach(function(plazo) { | 228 | plazos.forEach(function(plazo) { |
| 229 | plazosACrear.push({ | 229 | plazosACrear.push({ |
| 230 | idNotaPedido: data.data.id, | 230 | idNotaPedido: data.data.id, |
| 231 | dias: plazo.dias | 231 | dias: plazo.dias |
| 232 | }); | 232 | }); |
| 233 | }); | 233 | }); |
| 234 | 234 | ||
| 235 | if (plazosACrear.length) { | 235 | if (plazosACrear.length) { |
| 236 | crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear); | 236 | crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear); |
| 237 | } | 237 | } |
| 238 | 238 | ||
| 239 | notaPedidoBusinessService.addEstado(data.data.id, | 239 | notaPedidoBusinessService.addEstado(data.data.id, |
| 240 | $scope.notaPedido.vendedor.id); | 240 | $scope.notaPedido.vendedor.id); |
| 241 | 241 | ||
| 242 | focaBotoneraLateralService.endGuardar(true); | 242 | focaBotoneraLateralService.endGuardar(true); |
| 243 | $scope.saveLoading = false; | 243 | $scope.saveLoading = false; |
| 244 | 244 | ||
| 245 | init(); | 245 | init(); |
| 246 | }, function(error) { | 246 | }, function(error) { |
| 247 | focaModalService.alert('Hubo un error al crear la nota de pedido'); | 247 | focaModalService.alert('Hubo un error al crear la nota de pedido'); |
| 248 | focaBotoneraLateralService.endGuardar(); | 248 | focaBotoneraLateralService.endGuardar(); |
| 249 | $scope.saveLoading = false; | 249 | $scope.saveLoading = false; |
| 250 | console.info(error); | 250 | console.info(error); |
| 251 | }); | 251 | }); |
| 252 | }; | 252 | }; |
| 253 | 253 | ||
| 254 | $scope.seleccionarNotaPedido = function() { | 254 | $scope.seleccionarNotaPedido = function() { |
| 255 | var modalInstance = $uibModal.open( | 255 | var modalInstance = $uibModal.open( |
| 256 | { | 256 | { |
| 257 | ariaLabelledBy: 'Busqueda de Nota de Pedido', | 257 | ariaLabelledBy: 'Busqueda de Nota de Pedido', |
| 258 | templateUrl: 'foca-modal-nota-pedido.html', | 258 | templateUrl: 'foca-modal-nota-pedido.html', |
| 259 | controller: 'focaModalNotaPedidoController', | 259 | controller: 'focaModalNotaPedidoController', |
| 260 | size: 'lg', | 260 | size: 'lg', |
| 261 | resolve: { | 261 | resolve: { |
| 262 | usadoPor: function() {return 'notaPedido';}, | 262 | usadoPor: function() {return 'notaPedido';}, |
| 263 | idVendedor: function() { | 263 | idVendedor: function() { |
| 264 | if (APP === 'distribuidor') | 264 | if (APP === 'distribuidor') |
| 265 | return $scope.notaPedido.vendedor.id; | 265 | return $scope.notaPedido.vendedor.id; |
| 266 | else | 266 | else |
| 267 | return null; | 267 | return null; |
| 268 | } | 268 | } |
| 269 | } | 269 | } |
| 270 | } | 270 | } |
| 271 | ); | 271 | ); |
| 272 | modalInstance.result.then(setearNotaPedido); | 272 | modalInstance.result.then(setearNotaPedido); |
| 273 | }; | 273 | }; |
| 274 | 274 | ||
| 275 | $scope.seleccionarProductos = function() { | 275 | $scope.seleccionarProductos = function() { |
| 276 | if ($scope.idLista === undefined) { | 276 | if ($scope.idLista === undefined) { |
| 277 | focaModalService.alert( | 277 | focaModalService.alert( |
| 278 | 'Primero seleccione una lista de precio y condicion'); | 278 | 'Primero seleccione una lista de precio y condicion'); |
| 279 | return; | 279 | return; |
| 280 | } | 280 | } |
| 281 | var modalInstance = $uibModal.open( | 281 | var modalInstance = $uibModal.open( |
| 282 | { | 282 | { |
| 283 | ariaLabelledBy: 'Busqueda de Productos', | 283 | ariaLabelledBy: 'Busqueda de Productos', |
| 284 | templateUrl: 'modal-busqueda-productos.html', | 284 | templateUrl: 'modal-busqueda-productos.html', |
| 285 | controller: 'modalBusquedaProductosCtrl', | 285 | controller: 'modalBusquedaProductosCtrl', |
| 286 | resolve: { | 286 | resolve: { |
| 287 | parametroProducto: { | 287 | parametroProducto: { |
| 288 | idLista: $scope.idLista, | 288 | idLista: $scope.idLista, |
| 289 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 289 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
| 290 | simbolo: $scope.notaPedido.cotizacion.moneda.SIMBOLO | 290 | simbolo: $scope.notaPedido.cotizacion.moneda.SIMBOLO |
| 291 | } | 291 | } |
| 292 | }, | 292 | }, |
| 293 | size: 'lg' | 293 | size: 'lg' |
| 294 | } | 294 | } |
| 295 | ); | 295 | ); |
| 296 | modalInstance.result.then( | 296 | modalInstance.result.then( |
| 297 | function(producto) { | 297 | function(producto) { |
| 298 | var newArt = | 298 | var newArt = |
| 299 | { | 299 | { |
| 300 | id: 0, | 300 | id: 0, |
| 301 | codigo: producto.codigo, | 301 | codigo: producto.codigo, |
| 302 | sector: producto.sector, | 302 | sector: producto.sector, |
| 303 | sectorCodigo: producto.sector + '-' + producto.codigo, | 303 | sectorCodigo: producto.sector + '-' + producto.codigo, |
| 304 | descripcion: producto.descripcion, | 304 | descripcion: producto.descripcion, |
| 305 | item: $scope.notaPedido.articulosNotaPedido.length + 1, | 305 | item: $scope.notaPedido.articulosNotaPedido.length + 1, |
| 306 | nombre: producto.descripcion, | 306 | nombre: producto.descripcion, |
| 307 | precio: parseFloat(producto.precio.toFixed(4)), | 307 | precio: parseFloat(producto.precio.toFixed(4)), |
| 308 | costoUnitario: producto.costo, | 308 | costoUnitario: producto.costo, |
| 309 | editCantidad: false, | 309 | editCantidad: false, |
| 310 | editPrecio: false, | 310 | editPrecio: false, |
| 311 | rubro: producto.CodRub, | 311 | rubro: producto.CodRub, |
| 312 | ivaUnitario: producto.IMPIVA, | 312 | ivaUnitario: producto.IMPIVA, |
| 313 | impuestoInternoUnitario: producto.ImpInt, | 313 | impuestoInternoUnitario: producto.ImpInt, |
| 314 | impuestoInterno1Unitario: producto.ImpInt2, | 314 | impuestoInterno1Unitario: producto.ImpInt2, |
| 315 | impuestoInterno2Unitario: producto.ImpInt3, | 315 | impuestoInterno2Unitario: producto.ImpInt3, |
| 316 | precioLista: producto.precio, | 316 | precioLista: producto.precio, |
| 317 | combustible: 1, | 317 | combustible: 1, |
| 318 | facturado: 0, | 318 | facturado: 0, |
| 319 | idArticulo: producto.id, | 319 | idArticulo: producto.id, |
| 320 | tasaIva: producto.tasaIVA | 320 | tasaIva: producto.tasaIVA |
| 321 | }; | 321 | }; |
| 322 | 322 | ||
| 323 | newArt.exentoUnitario = newArt.ivaUnitario ? 0 : producto.neto; | 323 | newArt.exentoUnitario = newArt.ivaUnitario ? 0 : producto.neto; |
| 324 | newArt.netoUnitario = newArt.ivaUnitario ? producto.neto : 0; | 324 | newArt.netoUnitario = newArt.ivaUnitario ? producto.neto : 0; |
| 325 | 325 | ||
| 326 | $scope.articuloACargar = newArt; | 326 | $scope.articuloACargar = newArt; |
| 327 | $scope.cargando = false; | 327 | $scope.cargando = false; |
| 328 | }, function() { | 328 | }, function() { |
| 329 | // funcion ejecutada cuando se cancela el modal | 329 | // funcion ejecutada cuando se cancela el modal |
| 330 | } | 330 | } |
| 331 | ); | 331 | ); |
| 332 | }; | 332 | }; |
| 333 | 333 | ||
| 334 | $scope.seleccionarPuntosDeDescarga = function() { | 334 | $scope.seleccionarPuntosDeDescarga = function() { |
| 335 | if (!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { | 335 | if (!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { |
| 336 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); | 336 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); |
| 337 | return; | 337 | return; |
| 338 | } else { | 338 | } else { |
| 339 | var modalInstance = $uibModal.open( | 339 | var modalInstance = $uibModal.open( |
| 340 | { | 340 | { |
| 341 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', | 341 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', |
| 342 | templateUrl: 'modal-punto-descarga.html', | 342 | templateUrl: 'modal-punto-descarga.html', |
| 343 | controller: 'focaModalPuntoDescargaController', | 343 | controller: 'focaModalPuntoDescargaController', |
| 344 | size: 'lg', | 344 | size: 'lg', |
| 345 | resolve: { | 345 | resolve: { |
| 346 | filters: { | 346 | filters: { |
| 347 | idDomicilio: $scope.notaPedido.domicilio.id, | 347 | idDomicilio: $scope.notaPedido.domicilio.id, |
| 348 | idCliente: $scope.notaPedido.cliente.COD, | 348 | idCliente: $scope.notaPedido.cliente.COD, |
| 349 | articulos: $scope.notaPedido.articulosNotaPedido, | 349 | articulos: $scope.notaPedido.articulosNotaPedido, |
| 350 | puntoDescarga: $scope.notaPedido.notaPedidoPuntoDescarga, | 350 | puntoDescarga: $scope.notaPedido.notaPedidoPuntoDescarga, |
| 351 | domicilio: $scope.notaPedido.domicilio | 351 | domicilio: $scope.notaPedido.domicilio |
| 352 | } | 352 | } |
| 353 | } | 353 | } |
| 354 | } | 354 | } |
| 355 | ); | 355 | ); |
| 356 | modalInstance.result.then( | 356 | modalInstance.result.then( |
| 357 | function(puntoDescarga) { | 357 | function(puntoDescarga) { |
| 358 | $scope.notaPedido.notaPedidoPuntoDescarga = puntoDescarga; | 358 | $scope.notaPedido.notaPedidoPuntoDescarga = puntoDescarga; |
| 359 | 359 | ||
| 360 | $scope.$broadcast('addCabecera', { | 360 | $scope.$broadcast('addCabecera', { |
| 361 | label: 'Puntos de descarga:', | 361 | label: 'Puntos de descarga:', |
| 362 | valor: getCabeceraPuntoDescarga(puntoDescarga) | 362 | valor: getCabeceraPuntoDescarga(puntoDescarga) |
| 363 | }); | 363 | }); |
| 364 | }, function() { | 364 | }, function() { |
| 365 | $scope.abrirModalDomicilios($scope.cliente); | 365 | $scope.abrirModalDomicilios($scope.cliente); |
| 366 | } | 366 | } |
| 367 | ); | 367 | ); |
| 368 | } | 368 | } |
| 369 | }; | 369 | }; |
| 370 | 370 | ||
| 371 | $scope.seleccionarProveedor = function() { | 371 | $scope.seleccionarProveedor = function() { |
| 372 | $scope.abrirModalProveedores(function() { | 372 | $scope.abrirModalProveedores(function() { |
| 373 | if (validarNotaRemitada()) { | 373 | if (validarNotaRemitada()) { |
| 374 | var modalInstance = $uibModal.open( | 374 | var modalInstance = $uibModal.open( |
| 375 | { | 375 | { |
| 376 | ariaLabelledBy: 'Busqueda de Flete', | 376 | ariaLabelledBy: 'Busqueda de Flete', |
| 377 | templateUrl: 'modal-flete.html', | 377 | templateUrl: 'modal-flete.html', |
| 378 | controller: 'focaModalFleteController', | 378 | controller: 'focaModalFleteController', |
| 379 | size: 'lg', | 379 | size: 'lg', |
| 380 | resolve: { | 380 | resolve: { |
| 381 | parametrosFlete: | 381 | parametrosFlete: |
| 382 | function() { | 382 | function() { |
| 383 | return { | 383 | return { |
| 384 | flete: $scope.notaPedido.fob ? 'FOB' : | 384 | flete: $scope.notaPedido.fob ? 'FOB' : |
| 385 | ( $scope.notaPedido.flete ? '1' : | 385 | ( $scope.notaPedido.flete ? '1' : |
| 386 | ($scope.notaPedido.flete === undefined ? | 386 | ($scope.notaPedido.flete === undefined ? |
| 387 | null : '0')), | 387 | null : '0')), |
| 388 | bomba: $scope.notaPedido.bomba ? '1' : | 388 | bomba: $scope.notaPedido.bomba ? '1' : |
| 389 | ($scope.notaPedido.bomba === undefined ? | 389 | ($scope.notaPedido.bomba === undefined ? |
| 390 | null : '0'), | 390 | null : '0'), |
| 391 | kilometros: $scope.notaPedido.kilometros | 391 | kilometros: $scope.notaPedido.kilometros |
| 392 | }; | 392 | }; |
| 393 | } | 393 | } |
| 394 | } | 394 | } |
| 395 | } | 395 | } |
| 396 | ); | 396 | ); |
| 397 | modalInstance.result.then( | 397 | modalInstance.result.then( |
| 398 | function(datos) { | 398 | function(datos) { |
| 399 | $scope.notaPedido.flete = datos.flete; | 399 | $scope.notaPedido.flete = datos.flete; |
| 400 | $scope.notaPedido.fob = datos.FOB; | 400 | $scope.notaPedido.fob = datos.FOB; |
| 401 | $scope.notaPedido.bomba = datos.bomba; | 401 | $scope.notaPedido.bomba = datos.bomba; |
| 402 | $scope.notaPedido.kilometros = datos.kilometros; | 402 | $scope.notaPedido.kilometros = datos.kilometros; |
| 403 | $scope.$broadcast('addCabecera', { | 403 | $scope.$broadcast('addCabecera', { |
| 404 | label: 'Flete:', | 404 | label: 'Flete:', |
| 405 | valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') | 405 | valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') |
| 406 | }); | 406 | }); |
| 407 | if (datos.flete) { | 407 | if (datos.flete) { |
| 408 | $scope.$broadcast('addCabecera', { | 408 | $scope.$broadcast('addCabecera', { |
| 409 | label: 'Bomba:', | 409 | label: 'Bomba:', |
| 410 | valor: datos.bomba ? 'Si' : 'No' | 410 | valor: datos.bomba ? 'Si' : 'No' |
| 411 | }); | 411 | }); |
| 412 | $scope.$broadcast('addCabecera', { | 412 | $scope.$broadcast('addCabecera', { |
| 413 | label: 'Kilometros:', | 413 | label: 'Kilometros:', |
| 414 | valor: datos.kilometros | 414 | valor: datos.kilometros |
| 415 | }); | 415 | }); |
| 416 | } else { | 416 | } else { |
| 417 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 417 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
| 418 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 418 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
| 419 | $scope.notaPedido.bomba = false; | 419 | $scope.notaPedido.bomba = false; |
| 420 | $scope.notaPedido.kilometros = null; | 420 | $scope.notaPedido.kilometros = null; |
| 421 | } | 421 | } |
| 422 | }, function() { | 422 | }, function() { |
| 423 | $scope.seleccionarTransportista(); | 423 | $scope.seleccionarTransportista(); |
| 424 | } | 424 | } |
| 425 | ); | 425 | ); |
| 426 | } | 426 | } |
| 427 | }); | 427 | }); |
| 428 | }; | 428 | }; |
| 429 | 429 | ||
| 430 | $scope.seleccionarVendedor = function(callback, ocultarVendedor) { | 430 | $scope.seleccionarVendedor = function(callback, ocultarVendedor) { |
| 431 | if (APP === 'distribuidor' || ocultarVendedor) { | 431 | if (APP === 'distribuidor' || ocultarVendedor) { |
| 432 | callback(); | 432 | callback(); |
| 433 | return; | 433 | return; |
| 434 | } | 434 | } |
| 435 | 435 | ||
| 436 | if (validarNotaRemitada()) { | 436 | if (validarNotaRemitada()) { |
| 437 | var parametrosModal = { | 437 | var parametrosModal = { |
| 438 | titulo: 'Búsqueda vendedores', | 438 | titulo: 'Búsqueda vendedores', |
| 439 | query: '/vendedor', | 439 | query: '/vendedor', |
| 440 | columnas: [ | 440 | columnas: [ |
| 441 | { | 441 | { |
| 442 | propiedad: 'NUM', | 442 | propiedad: 'NUM', |
| 443 | nombre: 'Código', | 443 | nombre: 'Código', |
| 444 | filtro: { | 444 | filtro: { |
| 445 | nombre: 'rellenarDigitos', | 445 | nombre: 'rellenarDigitos', |
| 446 | parametro: 3 | 446 | parametro: 3 |
| 447 | } | 447 | } |
| 448 | }, | 448 | }, |
| 449 | { | 449 | { |
| 450 | propiedad: 'NOM', | 450 | propiedad: 'NOM', |
| 451 | nombre: 'Nombre' | 451 | nombre: 'Nombre' |
| 452 | } | 452 | } |
| 453 | ], | 453 | ], |
| 454 | size: 'md' | 454 | size: 'md' |
| 455 | }; | 455 | }; |
| 456 | focaModalService.modal(parametrosModal).then( | 456 | focaModalService.modal(parametrosModal).then( |
| 457 | function(vendedor) { | 457 | function(vendedor) { |
| 458 | $scope.$broadcast('addCabecera', { | 458 | $scope.$broadcast('addCabecera', { |
| 459 | label: 'Vendedor:', | 459 | label: 'Vendedor:', |
| 460 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + | 460 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + |
| 461 | vendedor.NOM | 461 | vendedor.NOM |
| 462 | }); | 462 | }); |
| 463 | $scope.notaPedido.vendedor = vendedor; | 463 | $scope.notaPedido.vendedor = vendedor; |
| 464 | deleteCliente(); | 464 | deleteCliente(); |
| 465 | callback(); | 465 | callback(); |
| 466 | }, function() {} | 466 | }, function() {} |
| 467 | ); | 467 | ); |
| 468 | } | 468 | } |
| 469 | }; | 469 | }; |
| 470 | 470 | ||
| 471 | $scope.seleccionarCliente = function(ocultarVendedor) { | 471 | $scope.seleccionarCliente = function(ocultarVendedor) { |
| 472 | $scope.seleccionarVendedor(function() { | 472 | $scope.seleccionarVendedor(function() { |
| 473 | if (validarNotaRemitada()) { | 473 | if (validarNotaRemitada()) { |
| 474 | var modalInstance = $uibModal.open( | 474 | var modalInstance = $uibModal.open( |
| 475 | { | 475 | { |
| 476 | ariaLabelledBy: 'Busqueda de Cliente', | 476 | ariaLabelledBy: 'Busqueda de Cliente', |
| 477 | templateUrl: 'foca-busqueda-cliente-modal.html', | 477 | templateUrl: 'foca-busqueda-cliente-modal.html', |
| 478 | controller: 'focaBusquedaClienteModalController', | 478 | controller: 'focaBusquedaClienteModalController', |
| 479 | resolve: { | 479 | resolve: { |
| 480 | vendedor: function() { return $scope.notaPedido.vendedor; }, | 480 | vendedor: function() { return $scope.notaPedido.vendedor; }, |
| 481 | cobrador: function() { return null; } | 481 | cobrador: function() { return null; } |
| 482 | }, | 482 | }, |
| 483 | size: 'lg' | 483 | size: 'lg' |
| 484 | } | 484 | } |
| 485 | ); | 485 | ); |
| 486 | modalInstance.result.then( | 486 | modalInstance.result.then( |
| 487 | function(cliente) { | 487 | function(cliente) { |
| 488 | $scope.abrirModalDomicilios(cliente); | 488 | $scope.abrirModalDomicilios(cliente); |
| 489 | $scope.cliente = cliente; | 489 | $scope.cliente = cliente; |
| 490 | }, function() { | 490 | }, function() { |
| 491 | if (APP !== 'distribuidor') $scope.seleccionarCliente(); | 491 | if (APP !== 'distribuidor') $scope.seleccionarCliente(); |
| 492 | } | 492 | } |
| 493 | ); | 493 | ); |
| 494 | } | 494 | } |
| 495 | }, ocultarVendedor); | 495 | }, ocultarVendedor); |
| 496 | }; | 496 | }; |
| 497 | 497 | ||
| 498 | $scope.abrirModalProveedores = function(callback) { | 498 | $scope.abrirModalProveedores = function(callback) { |
| 499 | if (validarNotaRemitada()) { | 499 | if (validarNotaRemitada()) { |
| 500 | var parametrosModal = { | 500 | var parametrosModal = { |
| 501 | titulo: 'Búsqueda de Proveedor', | 501 | titulo: 'Búsqueda de Proveedor', |
| 502 | query: '/proveedor', | 502 | query: '/proveedor', |
| 503 | columnas: [ | 503 | columnas: [ |
| 504 | { | 504 | { |
| 505 | nombre: 'Código', | 505 | nombre: 'Código', |
| 506 | propiedad: 'COD', | 506 | propiedad: 'COD', |
| 507 | filtro: { | 507 | filtro: { |
| 508 | nombre: 'rellenarDigitos', | 508 | nombre: 'rellenarDigitos', |
| 509 | parametro: 5 | 509 | parametro: 5 |
| 510 | } | 510 | } |
| 511 | }, | 511 | }, |
| 512 | { | 512 | { |
| 513 | nombre: 'Nombre', | 513 | nombre: 'Nombre', |
| 514 | propiedad: 'NOM' | 514 | propiedad: 'NOM' |
| 515 | }, | 515 | }, |
| 516 | { | 516 | { |
| 517 | nombre: 'CUIT', | 517 | nombre: 'CUIT', |
| 518 | propiedad: 'CUIT' | 518 | propiedad: 'CUIT' |
| 519 | } | 519 | } |
| 520 | ], | 520 | ], |
| 521 | tipo: 'POST', | 521 | tipo: 'POST', |
| 522 | json: {razonCuitCod: ''} | 522 | json: {razonCuitCod: ''} |
| 523 | }; | 523 | }; |
| 524 | focaModalService.modal(parametrosModal).then( | 524 | focaModalService.modal(parametrosModal).then( |
| 525 | function(proveedor) { | 525 | function(proveedor) { |
| 526 | $scope.notaPedido.proveedor = proveedor; | 526 | $scope.notaPedido.proveedor = proveedor; |
| 527 | $scope.$broadcast('addCabecera', { | 527 | $scope.$broadcast('addCabecera', { |
| 528 | label: 'Proveedor:', | 528 | label: 'Proveedor:', |
| 529 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + | 529 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + |
| 530 | proveedor.NOM | 530 | proveedor.NOM |
| 531 | }); | 531 | }); |
| 532 | callback(); | 532 | callback(); |
| 533 | }, function() { | 533 | }, function() { |
| 534 | 534 | ||
| 535 | } | 535 | } |
| 536 | ); | 536 | ); |
| 537 | } | 537 | } |
| 538 | }; | 538 | }; |
| 539 | 539 | ||
| 540 | $scope.abrirModalDomicilios = function(cliente) { | 540 | $scope.abrirModalDomicilios = function(cliente) { |
| 541 | var modalInstanceDomicilio = $uibModal.open( | 541 | var modalInstanceDomicilio = $uibModal.open( |
| 542 | { | 542 | { |
| 543 | ariaLabelledBy: 'Busqueda de Domicilios', | 543 | ariaLabelledBy: 'Busqueda de Domicilios', |
| 544 | templateUrl: 'modal-domicilio.html', | 544 | templateUrl: 'modal-domicilio.html', |
| 545 | controller: 'focaModalDomicilioController', | 545 | controller: 'focaModalDomicilioController', |
| 546 | resolve: { | 546 | resolve: { |
| 547 | idCliente: function() { return cliente.cod; }, | 547 | idCliente: function() { return cliente.cod; }, |
| 548 | esNuevo: function() { return cliente.esNuevo; } | 548 | esNuevo: function() { return cliente.esNuevo; } |
| 549 | }, | 549 | }, |
| 550 | size: 'lg', | 550 | size: 'lg', |
| 551 | } | 551 | } |
| 552 | ); | 552 | ); |
| 553 | modalInstanceDomicilio.result.then( | 553 | modalInstanceDomicilio.result.then( |
| 554 | function(domicilio) { | 554 | function(domicilio) { |
| 555 | $scope.notaPedido.domicilio = domicilio; | 555 | $scope.notaPedido.domicilio = domicilio; |
| 556 | $scope.notaPedido.cliente = { | 556 | $scope.notaPedido.cliente = { |
| 557 | COD: cliente.cod, | 557 | COD: cliente.cod, |
| 558 | CUIT: cliente.cuit, | 558 | CUIT: cliente.cuit, |
| 559 | NOM: cliente.nom, | 559 | NOM: cliente.nom, |
| 560 | MOD: cliente.mod | 560 | MOD: cliente.mod |
| 561 | }; | 561 | }; |
| 562 | var domicilioStamp = | 562 | var domicilioStamp = |
| 563 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + | 563 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + |
| 564 | domicilio.Localidad + ', ' + domicilio.Provincia; | 564 | domicilio.Localidad + ', ' + domicilio.Provincia; |
| 565 | $scope.notaPedido.domicilioStamp = domicilioStamp; | 565 | $scope.notaPedido.domicilioStamp = domicilioStamp; |
| 566 | 566 | ||
| 567 | $scope.notaPedido.notaPedidoPuntoDescarga = domicilio.puntoDescarga; | 567 | $scope.notaPedido.notaPedidoPuntoDescarga = domicilio.puntoDescarga; |
| 568 | 568 | ||
| 569 | $scope.$broadcast('addCabecera', { | 569 | $scope.$broadcast('addCabecera', { |
| 570 | label: 'Cliente:', | 570 | label: 'Cliente:', |
| 571 | valor: $filter('rellenarDigitos')(cliente.cod, 5) + ' - ' + cliente.nom | 571 | valor: $filter('rellenarDigitos')(cliente.cod, 5) + ' - ' + cliente.nom |
| 572 | }); | 572 | }); |
| 573 | $scope.$broadcast('addCabecera', { | 573 | $scope.$broadcast('addCabecera', { |
| 574 | label: 'Domicilio:', | 574 | label: 'Domicilio:', |
| 575 | valor: domicilioStamp | 575 | valor: domicilioStamp |
| 576 | }); | 576 | }); |
| 577 | if (domicilio.verPuntos) { | 577 | if (domicilio.verPuntos) { |
| 578 | delete $scope.notaPedido.domicilio.verPuntos; | 578 | delete $scope.notaPedido.domicilio.verPuntos; |
| 579 | $scope.seleccionarPuntosDeDescarga(); | 579 | $scope.seleccionarPuntosDeDescarga(); |
| 580 | } else { | 580 | } else { |
| 581 | crearNotaPedidoService | 581 | crearNotaPedidoService |
| 582 | .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) | 582 | .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) |
| 583 | .then(function(res) { | 583 | .then(function(res) { |
| 584 | if (res.data.length) $scope.seleccionarPuntosDeDescarga(); | 584 | if (res.data.length) $scope.seleccionarPuntosDeDescarga(); |
| 585 | }); | 585 | }); |
| 586 | } | 586 | } |
| 587 | }, function() { | 587 | }, function() { |
| 588 | $scope.seleccionarCliente(true); | 588 | $scope.seleccionarCliente(true); |
| 589 | return; | 589 | return; |
| 590 | } | 590 | } |
| 591 | ); | 591 | ); |
| 592 | }; | 592 | }; |
| 593 | 593 | ||
| 594 | $scope.getTotal = function() { | 594 | $scope.getTotal = function() { |
| 595 | var total = 0; | 595 | var total = 0; |
| 596 | if ($scope.notaPedido.articulosNotaPedido) { | 596 | if ($scope.notaPedido.articulosNotaPedido) { |
| 597 | var arrayTempArticulos = $scope.notaPedido.articulosNotaPedido; | 597 | var arrayTempArticulos = $scope.notaPedido.articulosNotaPedido; |
| 598 | for (var i = 0; i < arrayTempArticulos.length; i++) { | 598 | for (var i = 0; i < arrayTempArticulos.length; i++) { |
| 599 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | 599 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; |
| 600 | } | 600 | } |
| 601 | } | 601 | } |
| 602 | return parseFloat(total.toFixed(2)); | 602 | return parseFloat(total.toFixed(2)); |
| 603 | }; | 603 | }; |
| 604 | 604 | ||
| 605 | $scope.getSubTotal = function() { | 605 | $scope.getSubTotal = function() { |
| 606 | if ($scope.articuloACargar) { | 606 | if ($scope.articuloACargar) { |
| 607 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; | 607 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
| 608 | } | 608 | } |
| 609 | }; | 609 | }; |
| 610 | 610 | ||
| 611 | $scope.seleccionarPreciosYCondiciones = function() { | 611 | $scope.seleccionarPreciosYCondiciones = function() { |
| 612 | if (!$scope.notaPedido.cliente.COD) { | 612 | if (!$scope.notaPedido.cliente.COD) { |
| 613 | focaModalService.alert('Primero seleccione un cliente'); | 613 | focaModalService.alert('Primero seleccione un cliente'); |
| 614 | return; | 614 | return; |
| 615 | } | 615 | } |
| 616 | if ($scope.notaPedido.articulosNotaPedido.length !== 0) { | 616 | if ($scope.notaPedido.articulosNotaPedido.length !== 0) { |
| 617 | focaModalService.confirm('Se perderan los productos ingresados').then(function(data) { | 617 | focaModalService.confirm('Se perderan los productos ingresados') |
| 618 | if (data) { | 618 | .then(function(data) { |
| 619 | abrirModal(); | 619 | if (data) { |
| 620 | } | 620 | abrirModal(); |
| 621 | }); | 621 | } |
| 622 | }); | ||
| 622 | } else if (validarNotaRemitada()) { | 623 | } else if (validarNotaRemitada()) { |
| 623 | abrirModal(); | 624 | abrirModal(); |
| 624 | } | 625 | } |
| 625 | function abrirModal() { | 626 | function abrirModal() { |
| 626 | var modalInstance = $uibModal.open( | 627 | var modalInstance = $uibModal.open( |
| 627 | { | 628 | { |
| 628 | ariaLabelledBy: 'Busqueda de Precio Condición', | 629 | ariaLabelledBy: 'Busqueda de Precio Condición', |
| 629 | templateUrl: 'modal-precio-condicion.html', | 630 | templateUrl: 'modal-precio-condicion.html', |
| 630 | controller: 'focaModalPrecioCondicionController', | 631 | controller: 'focaModalPrecioCondicionController', |
| 631 | size: 'lg', | 632 | size: 'lg', |
| 632 | resolve: { | 633 | resolve: { |
| 633 | idListaPrecio: function() { | 634 | idListaPrecio: function() { |
| 634 | return $scope.notaPedido.cliente.MOD || null; | 635 | return $scope.notaPedido.cliente.MOD || null; |
| 635 | } | 636 | } |
| 636 | } | 637 | } |
| 637 | } | 638 | } |
| 638 | ); | 639 | ); |
| 639 | 640 | ||
| 640 | modalInstance.result.then( | 641 | modalInstance.result.then( |
| 641 | function(precioCondicion) { | 642 | function(precioCondicion) { |
| 642 | var cabecera = ''; | 643 | var cabecera = ''; |
| 643 | var plazosConcat = ''; | 644 | var plazosConcat = ''; |
| 644 | if (!Array.isArray(precioCondicion)) { | 645 | if (!Array.isArray(precioCondicion)) { |
| 645 | $scope.notaPedido.notaPedidoPlazo = precioCondicion.plazoPago; | 646 | $scope.notaPedido.notaPedidoPlazo = precioCondicion.plazoPago; |
| 646 | $scope.notaPedido.precioCondicion = precioCondicion; | 647 | $scope.notaPedido.precioCondicion = precioCondicion; |
| 647 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; | 648 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; |
| 648 | $scope.idLista = precioCondicion.idListaPrecio; | 649 | $scope.idLista = precioCondicion.idListaPrecio; |
| 649 | for (var i = 0; i < precioCondicion.plazoPago.length; i++) { | 650 | for (var i = 0; i < precioCondicion.plazoPago.length; i++) { |
| 650 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; | 651 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; |
| 651 | } | 652 | } |
| 652 | cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + | 653 | cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + |
| 653 | ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); | 654 | ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); |
| 654 | } else { //Cuando se ingresan los plazos manualmente | 655 | } else { //Cuando se ingresan los plazos manualmente |
| 655 | $scope.notaPedido.idPrecioCondicion = 0; | 656 | $scope.notaPedido.idPrecioCondicion = 0; |
| 656 | //-1, el modal productos busca todos los productos | 657 | //-1, el modal productos busca todos los productos |
| 657 | $scope.idLista = -1; | 658 | $scope.idLista = -1; |
| 658 | $scope.notaPedido.notaPedidoPlazo = precioCondicion; | 659 | $scope.notaPedido.notaPedidoPlazo = precioCondicion; |
| 659 | for (var j = 0; j < precioCondicion.length; j++) { | 660 | for (var j = 0; j < precioCondicion.length; j++) { |
| 660 | plazosConcat += precioCondicion[j].dias + ' '; | 661 | plazosConcat += precioCondicion[j].dias + ' '; |
| 661 | } | 662 | } |
| 662 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); | 663 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); |
| 663 | } | 664 | } |
| 664 | $scope.notaPedido.articulosNotaPedido = []; | 665 | $scope.notaPedido.articulosNotaPedido = []; |
| 665 | $scope.$broadcast('addCabecera', { | 666 | $scope.$broadcast('addCabecera', { |
| 666 | label: 'Precios y condiciones:', | 667 | label: 'Precios y condiciones:', |
| 667 | valor: cabecera | 668 | valor: cabecera |
| 668 | }); | 669 | }); |
| 669 | }, function() { | 670 | }, function() { |
| 670 | 671 | ||
| 671 | } | 672 | } |
| 672 | ); | 673 | ); |
| 673 | } | 674 | } |
| 674 | }; | 675 | }; |
| 675 | 676 | ||
| 676 | $scope.seleccionarMoneda = function() { | 677 | $scope.seleccionarMoneda = function() { |
| 677 | if (validarNotaRemitada()) { | 678 | if (validarNotaRemitada()) { |
| 678 | var parametrosModal = { | 679 | var parametrosModal = { |
| 679 | titulo: 'Búsqueda de monedas', | 680 | titulo: 'Búsqueda de monedas', |
| 680 | query: '/moneda', | 681 | query: '/moneda', |
| 681 | columnas: [ | 682 | columnas: [ |
| 682 | { | 683 | { |
| 683 | propiedad: 'DETALLE', | 684 | propiedad: 'DETALLE', |
| 684 | nombre: 'Nombre' | 685 | nombre: 'Nombre' |
| 685 | }, | 686 | }, |
| 686 | { | 687 | { |
| 687 | propiedad: 'SIMBOLO', | 688 | propiedad: 'SIMBOLO', |
| 688 | nombre: 'Símbolo' | 689 | nombre: 'Símbolo' |
| 689 | } | 690 | } |
| 690 | ], | 691 | ], |
| 691 | size: 'md' | 692 | size: 'md' |
| 692 | }; | 693 | }; |
| 693 | focaModalService.modal(parametrosModal).then( | 694 | focaModalService.modal(parametrosModal).then( |
| 694 | function(moneda) { | 695 | function(moneda) { |
| 695 | $scope.abrirModalCotizacion(moneda); | 696 | $scope.abrirModalCotizacion(moneda); |
| 696 | }, function() { | 697 | }, function() { |
| 697 | 698 | ||
| 698 | } | 699 | } |
| 699 | ); | 700 | ); |
| 700 | } | 701 | } |
| 701 | }; | 702 | }; |
| 702 | 703 | ||
| 703 | $scope.seleccionarObservaciones = function() { | 704 | $scope.seleccionarObservaciones = function() { |
| 704 | var observacion = { | 705 | var observacion = { |
| 705 | titulo: 'Ingrese Observaciones', | 706 | titulo: 'Ingrese Observaciones', |
| 706 | value: $scope.notaPedido.observaciones, | 707 | value: $scope.notaPedido.observaciones, |
| 707 | maxlength: 155, | 708 | maxlength: 155, |
| 708 | textarea: true | 709 | textarea: true |
| 709 | }; | 710 | }; |
| 710 | 711 | ||
| 711 | focaModalService | 712 | focaModalService |
| 712 | .prompt(observacion) | 713 | .prompt(observacion) |
| 713 | .then(function(observaciones) { | 714 | .then(function(observaciones) { |
| 714 | $scope.notaPedido.observaciones = observaciones; | 715 | $scope.notaPedido.observaciones = observaciones; |
| 715 | }); | 716 | }); |
| 716 | }; | 717 | }; |
| 717 | 718 | ||
| 718 | $scope.abrirModalCotizacion = function(moneda) { | 719 | $scope.abrirModalCotizacion = function(moneda) { |
| 719 | var modalInstance = $uibModal.open( | 720 | var modalInstance = $uibModal.open( |
| 720 | { | 721 | { |
| 721 | ariaLabelledBy: 'Busqueda de Cotización', | 722 | ariaLabelledBy: 'Busqueda de Cotización', |
| 722 | templateUrl: 'modal-cotizacion.html', | 723 | templateUrl: 'modal-cotizacion.html', |
| 723 | controller: 'focaModalCotizacionController', | 724 | controller: 'focaModalCotizacionController', |
| 724 | size: 'lg', | 725 | size: 'lg', |
| 725 | resolve: { | 726 | resolve: { |
| 726 | idMoneda: function() { | 727 | idMoneda: function() { |
| 727 | return moneda.ID; | 728 | return moneda.ID; |
| 728 | } | 729 | } |
| 729 | } | 730 | } |
| 730 | } | 731 | } |
| 731 | ); | 732 | ); |
| 732 | modalInstance.result.then( | 733 | modalInstance.result.then( |
| 733 | function(cotizacion) { | 734 | function(cotizacion) { |
| 734 | var articulosTablaTemp = $scope.notaPedido.articulosNotaPedido || []; | 735 | var articulosTablaTemp = $scope.notaPedido.articulosNotaPedido || []; |
| 735 | for (var i = 0; i < articulosTablaTemp.length; i++) { | 736 | for (var i = 0; i < articulosTablaTemp.length; i++) { |
| 736 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * | 737 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * |
| 737 | $scope.notaPedido.cotizacion.VENDEDOR; | 738 | $scope.notaPedido.cotizacion.VENDEDOR; |
| 738 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / | 739 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / |
| 739 | cotizacion.VENDEDOR; | 740 | cotizacion.VENDEDOR; |
| 740 | } | 741 | } |
| 741 | $scope.notaPedido.articulosNotaPedido = articulosTablaTemp; | 742 | $scope.notaPedido.articulosNotaPedido = articulosTablaTemp; |
| 742 | $scope.notaPedido.cotizacion = cotizacion; | 743 | $scope.notaPedido.cotizacion = cotizacion; |
| 743 | $scope.notaPedido.cotizacion.moneda = moneda; | 744 | $scope.notaPedido.cotizacion.moneda = moneda; |
| 744 | if (moneda.DETALLE === 'PESOS ARGENTINOS') { | 745 | if (moneda.DETALLE === 'PESOS ARGENTINOS') { |
| 745 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 746 | $scope.$broadcast('removeCabecera', 'Moneda:'); |
| 746 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 747 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); |
| 747 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 748 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); |
| 748 | } else { | 749 | } else { |
| 749 | $scope.$broadcast('addCabecera', { | 750 | $scope.$broadcast('addCabecera', { |
| 750 | label: 'Moneda:', | 751 | label: 'Moneda:', |
| 751 | valor: moneda.DETALLE | 752 | valor: moneda.DETALLE |
| 752 | }); | 753 | }); |
| 753 | $scope.$broadcast('addCabecera', { | 754 | $scope.$broadcast('addCabecera', { |
| 754 | label: 'Fecha cotizacion:', | 755 | label: 'Fecha cotizacion:', |
| 755 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 756 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') |
| 756 | }); | 757 | }); |
| 757 | $scope.$broadcast('addCabecera', { | 758 | $scope.$broadcast('addCabecera', { |
| 758 | label: 'Cotizacion:', | 759 | label: 'Cotizacion:', |
| 759 | valor: $filter('number')(cotizacion.VENDEDOR, '2') | 760 | valor: $filter('number')(cotizacion.VENDEDOR, '2') |
| 760 | }); | 761 | }); |
| 761 | } | 762 | } |
| 762 | }, function() { | 763 | }, function() { |
| 763 | 764 | ||
| 764 | } | 765 | } |
| 765 | ); | 766 | ); |
| 766 | }; | 767 | }; |
| 767 | 768 | ||
| 768 | $scope.agregarATabla = function(key) { | 769 | $scope.agregarATabla = function(key) { |
| 769 | if (key === 13) { | 770 | if (key === 13) { |
| 770 | if ($scope.articuloACargar.cantidad === undefined || | 771 | if ($scope.articuloACargar.cantidad === undefined || |
| 771 | $scope.articuloACargar.cantidad === 0 || | 772 | $scope.articuloACargar.cantidad === 0 || |
| 772 | $scope.articuloACargar.cantidad === null ) { | 773 | $scope.articuloACargar.cantidad === null ) { |
| 773 | focaModalService.alert('El valor debe ser al menos 1'); | 774 | focaModalService.alert('El valor debe ser al menos 1'); |
| 774 | return; | 775 | return; |
| 775 | } | 776 | } |
| 776 | delete $scope.articuloACargar.sectorCodigo; | 777 | delete $scope.articuloACargar.sectorCodigo; |
| 777 | $scope.notaPedido.articulosNotaPedido.push($scope.articuloACargar); | 778 | $scope.notaPedido.articulosNotaPedido.push($scope.articuloACargar); |
| 778 | $scope.cargando = true; | 779 | $scope.cargando = true; |
| 779 | } | 780 | } |
| 780 | }; | 781 | }; |
| 781 | 782 | ||
| 782 | $scope.quitarArticulo = function(key) { | 783 | $scope.quitarArticulo = function(key) { |
| 783 | $scope.notaPedido.articulosNotaPedido.splice(key, 1); | 784 | $scope.notaPedido.articulosNotaPedido.splice(key, 1); |
| 784 | }; | 785 | }; |
| 785 | 786 | ||
| 786 | $scope.editarArticulo = function(key, articulo, tmpCantidad, tmpPrecio) { | 787 | $scope.editarArticulo = function(key, articulo, tmpCantidad, tmpPrecio) { |
| 787 | if (key === 13) { | 788 | if (key === 13) { |
| 788 | if (!articulo.cantidad || !articulo.precio) { | 789 | if (!articulo.cantidad || !articulo.precio) { |
| 789 | focaModalService.alert('Los valores deben ser al menos 1'); | 790 | focaModalService.alert('Los valores deben ser al menos 1'); |
| 790 | return; | 791 | return; |
| 791 | } else if (articulo.cantidad < 0 || articulo.precio < 0) { | 792 | } else if (articulo.cantidad < 0 || articulo.precio < 0) { |
| 792 | focaModalService.alert('Los valores no pueden ser negativos'); | 793 | focaModalService.alert('Los valores no pueden ser negativos'); |
| 793 | return; | 794 | return; |
| 794 | } | 795 | } |
| 795 | articulo.cantidad = tmpCantidad; | 796 | articulo.cantidad = tmpCantidad; |
| 796 | articulo.precio = tmpPrecio; | 797 | articulo.precio = tmpPrecio; |
| 797 | $scope.getTotal(); | 798 | $scope.getTotal(); |
| 798 | articulo.editCantidad = articulo.editPrecio = false; | 799 | articulo.editCantidad = articulo.editPrecio = false; |
| 799 | } | 800 | } |
| 800 | }; | 801 | }; |
| 801 | 802 | ||
| 802 | $scope.cancelarEditar = function(articulo) { | 803 | $scope.cancelarEditar = function(articulo) { |
| 803 | $scope.tmpCantidad = articulo.cantidad; | 804 | $scope.tmpCantidad = articulo.cantidad; |
| 804 | $scope.tmpPrecio = articulo.precio; | 805 | $scope.tmpPrecio = articulo.precio; |
| 805 | articulo.editCantidad = articulo.editPrecio = false; | 806 | articulo.editCantidad = articulo.editPrecio = false; |
| 806 | }; | 807 | }; |
| 807 | 808 | ||
| 808 | $scope.cambioEdit = function(articulo, propiedad) { | 809 | $scope.cambioEdit = function(articulo, propiedad) { |
| 809 | if (propiedad === 'cantidad') { | 810 | if (propiedad === 'cantidad') { |
| 810 | articulo.editCantidad = true; | 811 | articulo.editCantidad = true; |
| 811 | } else if (propiedad === 'precio') { | 812 | } else if (propiedad === 'precio') { |
| 812 | articulo.editPrecio = true; | 813 | articulo.editPrecio = true; |
| 813 | } | 814 | } |
| 814 | }; | 815 | }; |
| 815 | 816 | ||
| 816 | $scope.resetFilter = function() { | 817 | $scope.resetFilter = function() { |
| 817 | $scope.articuloACargar = {}; | 818 | $scope.articuloACargar = {}; |
| 818 | $scope.cargando = true; | 819 | $scope.cargando = true; |
| 819 | }; | 820 | }; |
| 820 | //Recibe aviso si el teclado está en uso | 821 | //Recibe aviso si el teclado está en uso |
| 821 | $rootScope.$on('usarTeclado', function(event, data) { | 822 | $rootScope.$on('usarTeclado', function(event, data) { |
| 822 | if (data) { | 823 | if (data) { |
| 823 | $scope.mostrarTeclado = true; | 824 | $scope.mostrarTeclado = true; |
| 824 | return; | 825 | return; |
| 825 | } | 826 | } |
| 826 | $scope.mostrarTeclado = false; | 827 | $scope.mostrarTeclado = false; |
| 827 | }); | 828 | }); |
| 828 | 829 | ||
| 829 | $scope.selectFocus = function($event) { | 830 | $scope.selectFocus = function($event) { |
| 830 | // Si el teclado esta en uso no selecciona el valor | 831 | // Si el teclado esta en uso no selecciona el valor |
| 831 | if ($scope.mostrarTeclado) { | 832 | if ($scope.mostrarTeclado) { |
| 832 | return; | 833 | return; |
| 833 | } | 834 | } |
| 834 | $event.target.select(); | 835 | $event.target.select(); |
| 835 | }; | 836 | }; |
| 836 | 837 | ||
| 837 | $scope.salir = function() { | 838 | $scope.salir = function() { |
| 838 | $location.path('/'); | 839 | $location.path('/'); |
| 839 | }; | 840 | }; |
| 840 | 841 | ||
| 841 | $scope.parsearATexto = function(articulo) { | 842 | $scope.parsearATexto = function(articulo) { |
| 842 | articulo.cantidad = parseFloat(articulo.cantidad); | 843 | articulo.cantidad = parseFloat(articulo.cantidad); |
| 843 | articulo.precio = parseFloat(articulo.precio); | 844 | articulo.precio = parseFloat(articulo.precio); |
| 844 | }; | 845 | }; |
| 845 | 846 | ||
| 846 | function setearNotaPedido(notaPedido) { | 847 | function setearNotaPedido(notaPedido) { |
| 847 | //añado cabeceras | 848 | //añado cabeceras |
| 848 | $scope.notaPedido = notaPedido; | 849 | $scope.notaPedido = notaPedido; |
| 849 | if (!$scope.notaPedido.domicilio) { | 850 | if (!$scope.notaPedido.domicilio) { |
| 850 | $scope.notaPedido.domicilio = { | 851 | $scope.notaPedido.domicilio = { |
| 851 | id: $scope.notaPedido.idDomicilio | 852 | id: $scope.notaPedido.idDomicilio |
| 852 | }; | 853 | }; |
| 853 | } | 854 | } |
| 854 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 855 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
| 855 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 856 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
| 856 | $scope.$broadcast('cleanCabecera'); | 857 | $scope.$broadcast('cleanCabecera'); |
| 857 | 858 | ||
| 858 | var cabeceras = []; | 859 | var cabeceras = []; |
| 859 | 860 | ||
| 860 | if (notaPedido.cotizacion.moneda.CODIGO_AFIP !== 'PES') { | 861 | if (notaPedido.cotizacion.moneda.CODIGO_AFIP !== 'PES') { |
| 861 | cabeceras.push({ | 862 | cabeceras.push({ |
| 862 | label: 'Moneda:', | 863 | label: 'Moneda:', |
| 863 | valor: notaPedido.cotizacion.moneda.DETALLE | 864 | valor: notaPedido.cotizacion.moneda.DETALLE |
| 864 | }); | 865 | }); |
| 865 | cabeceras.push({ | 866 | cabeceras.push({ |
| 866 | label: 'Fecha cotizacion:', | 867 | label: 'Fecha cotizacion:', |
| 867 | valor: $filter('date')(notaPedido.cotizacion.FECHA, | 868 | valor: $filter('date')(notaPedido.cotizacion.FECHA, |
| 868 | 'dd/MM/yyyy') | 869 | 'dd/MM/yyyy') |
| 869 | }); | 870 | }); |
| 870 | cabeceras.push({ | 871 | cabeceras.push({ |
| 871 | label: 'Cotizacion:', | 872 | label: 'Cotizacion:', |
| 872 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, | 873 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, |
| 873 | '2') | 874 | '2') |
| 874 | }); | 875 | }); |
| 875 | } | 876 | } |
| 876 | 877 | ||
| 877 | if (notaPedido.vendedor.NUM) { | 878 | if (notaPedido.vendedor.NUM) { |
| 878 | cabeceras.push({ | 879 | cabeceras.push({ |
| 879 | label: 'Vendedor:', | 880 | label: 'Vendedor:', |
| 880 | valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) + | 881 | valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) + |
| 881 | ' - ' + notaPedido.vendedor.NOM | 882 | ' - ' + notaPedido.vendedor.NOM |
| 882 | }); | 883 | }); |
| 883 | } | 884 | } |
| 884 | 885 | ||
| 885 | if (notaPedido.cliente.COD) { | 886 | if (notaPedido.cliente.COD) { |
| 886 | cabeceras.push({ | 887 | cabeceras.push({ |
| 887 | label: 'Cliente:', | 888 | label: 'Cliente:', |
| 888 | valor: notaPedido.cliente.NOM | 889 | valor: notaPedido.cliente.NOM |
| 889 | }); | 890 | }); |
| 890 | cabeceras.push({ | 891 | cabeceras.push({ |
| 891 | label: 'Domicilio:', | 892 | label: 'Domicilio:', |
| 892 | valor: notaPedido.domicilioStamp | 893 | valor: notaPedido.domicilioStamp |
| 893 | }); | 894 | }); |
| 894 | } | 895 | } |
| 895 | 896 | ||
| 896 | if (notaPedido.proveedor.COD) { | 897 | if (notaPedido.proveedor.COD) { |
| 897 | cabeceras.push({ | 898 | cabeceras.push({ |
| 898 | label: 'Proveedor:', | 899 | label: 'Proveedor:', |
| 899 | valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) + | 900 | valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) + |
| 900 | ' - ' + notaPedido.proveedor.NOM | 901 | ' - ' + notaPedido.proveedor.NOM |
| 901 | }); | 902 | }); |
| 902 | } | 903 | } |
| 903 | 904 | ||
| 904 | if (notaPedido.notaPedidoPlazo.length) { | 905 | if (notaPedido.notaPedidoPlazo.length) { |
| 905 | cabeceras.push({ | 906 | cabeceras.push({ |
| 906 | label: 'Precios y condiciones:', | 907 | label: 'Precios y condiciones:', |
| 907 | valor: valorPrecioCondicion() + ' ' + | 908 | valor: valorPrecioCondicion() + ' ' + |
| 908 | notaPedidoBusinessService | 909 | notaPedidoBusinessService |
| 909 | .plazoToString(notaPedido.notaPedidoPlazo) | 910 | .plazoToString(notaPedido.notaPedidoPlazo) |
| 910 | }); | 911 | }); |
| 911 | } | 912 | } |
| 912 | 913 | ||
| 913 | if (notaPedido.flete !== undefined) { | 914 | if (notaPedido.flete !== undefined) { |
| 914 | cabeceras.push({ | 915 | cabeceras.push({ |
| 915 | label: 'Flete:', | 916 | label: 'Flete:', |
| 916 | valor: notaPedido.fob === 1 ? 'FOB' : ( | 917 | valor: notaPedido.fob === 1 ? 'FOB' : ( |
| 917 | notaPedido.flete === 1 ? 'Si' : 'No') | 918 | notaPedido.flete === 1 ? 'Si' : 'No') |
| 918 | }); | 919 | }); |
| 919 | } | 920 | } |
| 920 | 921 | ||
| 921 | function valorPrecioCondicion() { | 922 | function valorPrecioCondicion() { |
| 922 | if (notaPedido.idPrecioCondicion > 0) { | 923 | if (notaPedido.idPrecioCondicion > 0) { |
| 923 | return notaPedido.precioCondicion.nombre; | 924 | return notaPedido.precioCondicion.nombre; |
| 924 | } else { | 925 | } else { |
| 925 | return 'Ingreso Manual'; | 926 | return 'Ingreso Manual'; |
| 926 | } | 927 | } |
| 927 | } | 928 | } |
| 928 | 929 | ||
| 929 | if (notaPedido.flete === 1) { | 930 | if (notaPedido.flete === 1) { |
| 930 | var cabeceraBomba = { | 931 | var cabeceraBomba = { |
| 931 | label: 'Bomba:', | 932 | label: 'Bomba:', |
| 932 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' | 933 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' |
| 933 | }; | 934 | }; |
| 934 | if (notaPedido.kilometros) { | 935 | if (notaPedido.kilometros) { |
| 935 | var cabeceraKilometros = { | 936 | var cabeceraKilometros = { |
| 936 | label: 'Kilometros:', | 937 | label: 'Kilometros:', |
| 937 | valor: notaPedido.kilometros | 938 | valor: notaPedido.kilometros |
| 938 | }; | 939 | }; |
| 939 | cabeceras.push(cabeceraKilometros); | 940 | cabeceras.push(cabeceraKilometros); |
| 940 | } | 941 | } |
| 941 | cabeceras.push(cabeceraBomba); | 942 | cabeceras.push(cabeceraBomba); |
| 942 | } | 943 | } |
| 943 | 944 | ||
| 944 | if (notaPedido.idPrecioCondicion > 0) { | 945 | if (notaPedido.idPrecioCondicion > 0) { |
| 945 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; | 946 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; |
| 946 | } else { | 947 | } else { |
| 947 | $scope.idLista = -1; | 948 | $scope.idLista = -1; |
| 948 | } | 949 | } |
| 949 | 950 | ||
| 950 | $scope.puntoVenta = $filter('rellenarDigitos')( | 951 | $scope.puntoVenta = $filter('rellenarDigitos')( |
| 951 | notaPedido.sucursal, 4 | 952 | notaPedido.sucursal, 4 |
| 952 | ); | 953 | ); |
| 953 | 954 | ||
| 954 | $scope.comprobante = $filter('rellenarDigitos')( | 955 | $scope.comprobante = $filter('rellenarDigitos')( |
| 955 | notaPedido.numeroNotaPedido, 8 | 956 | notaPedido.numeroNotaPedido, 8 |
| 956 | ); | 957 | ); |
| 957 | 958 | ||
| 958 | if (notaPedido.notaPedidoPuntoDescarga) { | 959 | if (notaPedido.notaPedidoPuntoDescarga) { |
| 959 | var puntos = []; | 960 | var puntos = []; |
| 960 | notaPedido.notaPedidoPuntoDescarga.forEach(function(notaPedidoPuntoDescarga) { | 961 | notaPedido.notaPedidoPuntoDescarga.forEach(function(notaPedidoPuntoDescarga) { |
| 961 | puntos.push(notaPedidoPuntoDescarga); | 962 | puntos.push(notaPedidoPuntoDescarga); |
| 962 | }); | 963 | }); |
| 963 | cabeceras.push({ | 964 | cabeceras.push({ |
| 964 | label: 'Puntos de descarga: ', | 965 | label: 'Puntos de descarga: ', |
| 965 | valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntos)) | 966 | valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntos)) |
| 966 | }); | 967 | }); |
| 967 | } | 968 | } |
| 968 | 969 | ||
| 969 | addArrayCabecera(cabeceras); | 970 | addArrayCabecera(cabeceras); |
| 970 | } | 971 | } |
| 971 | 972 | ||
| 972 | function getCabeceraPuntoDescarga(puntoDescarga) { | 973 | function getCabeceraPuntoDescarga(puntoDescarga) { |
| 973 | var puntosStamp = ''; | 974 | var puntosStamp = ''; |
| 974 | puntoDescarga.forEach(function(punto, idx, arr) { | 975 | puntoDescarga.forEach(function(punto, idx, arr) { |
| 975 | puntosStamp += punto.descripcion; | 976 | puntosStamp += punto.descripcion; |
| 976 | if ((idx + 1) !== arr.length) puntosStamp += ', '; | 977 | if ((idx + 1) !== arr.length) puntosStamp += ', '; |
| 977 | }); | 978 | }); |
| 978 | return puntosStamp; | 979 | return puntosStamp; |
| 979 | } | 980 | } |
| 980 | 981 | ||
| 981 | function addArrayCabecera(array) { | 982 | function addArrayCabecera(array) { |
| 982 | for (var i = 0; i < array.length; i++) { | 983 | for (var i = 0; i < array.length; i++) { |
| 983 | $scope.$broadcast('addCabecera', { | 984 | $scope.$broadcast('addCabecera', { |
| 984 | label: array[i].label, | 985 | label: array[i].label, |
| 985 | valor: array[i].valor | 986 | valor: array[i].valor |
| 986 | }); | 987 | }); |
| 987 | } | 988 | } |
| 988 | } | 989 | } |
| 989 | 990 | ||
| 990 | function validarNotaRemitada() { | 991 | function validarNotaRemitada() { |
| 991 | if (!$scope.notaPedido.idRemito) { | 992 | if (!$scope.notaPedido.idRemito) { |
| 992 | return true; | 993 | return true; |
| 993 | } else { | 994 | } else { |
| 994 | focaModalService.alert('No se puede editar una nota de pedido remitada'); | 995 | focaModalService.alert('No se puede editar una nota de pedido remitada'); |
| 995 | return false; | 996 | return false; |
| 996 | } | 997 | } |
| 997 | } | 998 | } |
| 998 | 999 | ||
| 999 | function salir() { | 1000 | function salir() { |
| 1000 | var confirmacion = false; | 1001 | var confirmacion = false; |
| 1001 | 1002 | ||
| 1002 | if (!angular.equals($scope.notaPedido, $scope.inicial)) { | 1003 | if (!angular.equals($scope.notaPedido, $scope.inicial)) { |
| 1003 | confirmacion = true; | 1004 | confirmacion = true; |
| 1004 | } | 1005 | } |
| 1005 | 1006 | ||
| 1006 | if (confirmacion) { | 1007 | if (confirmacion) { |
| 1007 | focaModalService.confirm( | 1008 | focaModalService.confirm( |
| 1008 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 1009 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
| 1009 | ).then(function(data) { | 1010 | ).then(function(data) { |
| 1010 | if (data) { | 1011 | if (data) { |
| 1011 | $location.path('/'); | 1012 | $location.path('/'); |
| 1012 | } | 1013 | } |
| 1013 | }); | 1014 | }); |
| 1014 | } else { | 1015 | } else { |
| 1015 | $location.path('/'); | 1016 | $location.path('/'); |
| 1016 | } | 1017 | } |
| 1017 | } | 1018 | } |
| 1018 | 1019 | ||
| 1019 | function getLSNotaPedido() { | 1020 | function getLSNotaPedido() { |
| 1020 | var notaPedido = JSON.parse($localStorage.notaPedido || null); | 1021 | var notaPedido = JSON.parse($localStorage.notaPedido || null); |
| 1021 | if (notaPedido) { | 1022 | if (notaPedido) { |
| 1022 | delete $localStorage.notaPedido; | 1023 | delete $localStorage.notaPedido; |
| 1023 | setearNotaPedido(notaPedido); | 1024 | setearNotaPedido(notaPedido); |
| 1024 | } | 1025 | } |
| 1025 | } | 1026 | } |
| 1026 | 1027 | ||
| 1027 | function deleteCliente() { | 1028 | function deleteCliente() { |
| 1028 | delete $scope.notaPedido.domicilioStamp; | 1029 | delete $scope.notaPedido.domicilioStamp; |
| 1029 | delete $scope.notaPedido.notaPedidoPuntoDescarga; | 1030 | delete $scope.notaPedido.notaPedidoPuntoDescarga; |
| 1030 | $scope.notaPedido.domicilio = {dom: ''}; | 1031 | $scope.notaPedido.domicilio = {dom: ''}; |
| 1031 | $scope.notaPedido.cliente = {}; | 1032 | $scope.notaPedido.cliente = {}; |
| 1032 | $scope.$broadcast('removeCabecera', 'Cliente:'); | 1033 | $scope.$broadcast('removeCabecera', 'Cliente:'); |
| 1033 | $scope.$broadcast('removeCabecera', 'Domicilio:'); | 1034 | $scope.$broadcast('removeCabecera', 'Domicilio:'); |
| 1034 | $scope.$broadcast('removeCabecera', 'Puntos de descarga:'); | 1035 | $scope.$broadcast('removeCabecera', 'Puntos de descarga:'); |
| 1035 | } | 1036 | } |
| 1036 | } | 1037 | } |
| 1037 | ]); | 1038 | ]); |
| 1038 | 1039 |