Commit 15f84e2871c39b8bc98cfca9ed807048469bd73b
1 parent
6103604b8c
Exists in
master
fix muestra bien nro al crear hoja ruta
Showing
1 changed file
with
2 additions
and
2 deletions
Show diff stats
src/js/controller.js
| 1 | angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', | 1 | angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', |
| 2 | [ | 2 | [ |
| 3 | '$scope', '$uibModal', '$location', '$filter', 'crearHojaRutaService', 'focaModalService', | 3 | '$scope', '$uibModal', '$location', '$filter', 'crearHojaRutaService', 'focaModalService', |
| 4 | function($scope, $uibModal, $location, $filter, crearHojaRutaService, focaModalService) { | 4 | function($scope, $uibModal, $location, $filter, crearHojaRutaService, focaModalService) { |
| 5 | $scope.botonera = [ | 5 | $scope.botonera = [ |
| 6 | {texto: 'Transportista', accion: function() {$scope.seleccionarProveedor();}}, | 6 | {texto: 'Transportista', accion: function() {$scope.seleccionarProveedor();}}, |
| 7 | {texto: 'Chofer', accion: function() {$scope.seleccionarChofer();}}, | 7 | {texto: 'Chofer', accion: function() {$scope.seleccionarChofer();}}, |
| 8 | {texto: 'Vehiculo', accion: function() {$scope.seleccionarVehiculo();}}, | 8 | {texto: 'Vehiculo', accion: function() {$scope.seleccionarVehiculo();}}, |
| 9 | {texto: 'Tarifario', accion: function() {$scope.seleccionarTarifario();}}, | 9 | {texto: 'Tarifario', accion: function() {$scope.seleccionarTarifario();}}, |
| 10 | {texto: 'Remitos', accion: function() {$scope.seleccionarRemito();}}, | 10 | {texto: 'Remitos', accion: function() {$scope.seleccionarRemito();}}, |
| 11 | {texto: '', accion: function() {}}, | 11 | {texto: '', accion: function() {}}, |
| 12 | {texto: '', accion: function() {}}, | 12 | {texto: '', accion: function() {}}, |
| 13 | {texto: '', accion: function() {}} | 13 | {texto: '', accion: function() {}} |
| 14 | ]; | 14 | ]; |
| 15 | $scope.datepickerAbierto = false; | 15 | $scope.datepickerAbierto = false; |
| 16 | 16 | ||
| 17 | $scope.show = false; | 17 | $scope.show = false; |
| 18 | $scope.cargando = true; | 18 | $scope.cargando = true; |
| 19 | $scope.dateOptions = { | 19 | $scope.dateOptions = { |
| 20 | maxDate: new Date(), | 20 | maxDate: new Date(), |
| 21 | minDate: new Date(2010, 0, 1) | 21 | minDate: new Date(2010, 0, 1) |
| 22 | }; | 22 | }; |
| 23 | 23 | ||
| 24 | $scope.hojaRuta = { | 24 | $scope.hojaRuta = { |
| 25 | fecha: new Date(), | 25 | fecha: new Date(), |
| 26 | litros: 0, | 26 | litros: 0, |
| 27 | chofer: {}, | 27 | chofer: {}, |
| 28 | vehiculo: { | 28 | vehiculo: { |
| 29 | capacidad: 0 | 29 | capacidad: 0 |
| 30 | }, | 30 | }, |
| 31 | transportista: {}, | 31 | transportista: {}, |
| 32 | tarifario: { | 32 | tarifario: { |
| 33 | costo: null | 33 | costo: null |
| 34 | } | 34 | } |
| 35 | }; | 35 | }; |
| 36 | 36 | ||
| 37 | $scope.cabecera = []; | 37 | $scope.cabecera = []; |
| 38 | $scope.showCabecera = true; | 38 | $scope.showCabecera = true; |
| 39 | 39 | ||
| 40 | $scope.now = new Date(); | 40 | $scope.now = new Date(); |
| 41 | $scope.puntoVenta = '0000'; | 41 | $scope.puntoVenta = '0000'; |
| 42 | $scope.comprobante = '00000000'; | 42 | $scope.comprobante = '00000000'; |
| 43 | $scope.remitosTabla = []; | 43 | $scope.remitosTabla = []; |
| 44 | $scope.idLista = undefined; | 44 | $scope.idLista = undefined; |
| 45 | //La pantalla solo se usa para cargar pedidos | 45 | //La pantalla solo se usa para cargar pedidos |
| 46 | //var hojaRutaTemp = crearHojaRutaService.getHojaRuta(); | 46 | //var hojaRutaTemp = crearHojaRutaService.getHojaRuta(); |
| 47 | 47 | ||
| 48 | crearHojaRutaService.getNumeroHojaRuta().then( | 48 | crearHojaRutaService.getNumeroHojaRuta().then( |
| 49 | function(res) { | 49 | function(res) { |
| 50 | $scope.puntoVenta = $scope.rellenar(res.data.sucursal, 4); | 50 | $scope.puntoVenta = $scope.rellenar(res.data.sucursal, 4); |
| 51 | $scope.comprobante = $scope.rellenar(res.data.numeroHojaRuta, 8); | 51 | $scope.comprobante = $scope.rellenar(res.data.numeroHojaRuta, 8); |
| 52 | }, | 52 | }, |
| 53 | function(err) { | 53 | function(err) { |
| 54 | focaModalService.alert('La terminal no esta configurada correctamente'); | 54 | focaModalService.alert('La terminal no esta configurada correctamente'); |
| 55 | console.info(err); | 55 | console.info(err); |
| 56 | } | 56 | } |
| 57 | ); | 57 | ); |
| 58 | //La pantalla solo se usa para cargar pedidos | 58 | //La pantalla solo se usa para cargar pedidos |
| 59 | // if (hojaRutaTemp !== undefined) { | 59 | // if (hojaRutaTemp !== undefined) { |
| 60 | // hojaRutaTemp.fechaCarga = new Date(hojaRutaTemp.fechaCarga); | 60 | // hojaRutaTemp.fechaCarga = new Date(hojaRutaTemp.fechaCarga); |
| 61 | // $scope.hojaRuta = hojaRutaTemp; | 61 | // $scope.hojaRuta = hojaRutaTemp; |
| 62 | // $scope.hojaRuta.flete = ($scope.hojaRuta.flete).toString(); | 62 | // $scope.hojaRuta.flete = ($scope.hojaRuta.flete).toString(); |
| 63 | // $scope.hojaRuta.bomba = ($scope.hojaRuta.bomba).toString(); | 63 | // $scope.hojaRuta.bomba = ($scope.hojaRuta.bomba).toString(); |
| 64 | // $scope.idLista = $scope.hojaRuta.precioCondicion; | 64 | // $scope.idLista = $scope.hojaRuta.precioCondicion; |
| 65 | // crearHojaRutaService | 65 | // crearHojaRutaService |
| 66 | // .getArticulosByIdHojaRuta($scope.hojaRuta.id).then( | 66 | // .getArticulosByIdHojaRuta($scope.hojaRuta.id).then( |
| 67 | // function(res) { | 67 | // function(res) { |
| 68 | // $scope.remitosTabla = res.data; | 68 | // $scope.remitosTabla = res.data; |
| 69 | // } | 69 | // } |
| 70 | // ); | 70 | // ); |
| 71 | //TODO DOMICILIOS QUE SE CARGAN AL EDITAR NOTA DE PEDIDO | 71 | //TODO DOMICILIOS QUE SE CARGAN AL EDITAR NOTA DE PEDIDO |
| 72 | //(NO REQUERIDO EN ESTA VERSION) | 72 | //(NO REQUERIDO EN ESTA VERSION) |
| 73 | // crearHojaRutaService.getDomiciliosByIdHojaRuta($scope.hojaRuta.id).then( | 73 | // crearHojaRutaService.getDomiciliosByIdHojaRuta($scope.hojaRuta.id).then( |
| 74 | // function(res) { | 74 | // function(res) { |
| 75 | // $scope.hojaRuta.domicilio = res.data; | 75 | // $scope.hojaRuta.domicilio = res.data; |
| 76 | // } | 76 | // } |
| 77 | // ); | 77 | // ); |
| 78 | // } else { | 78 | // } else { |
| 79 | // $scope.hojaRuta.fechaCarga = new Date(); | 79 | // $scope.hojaRuta.fechaCarga = new Date(); |
| 80 | // $scope.hojaRuta.bomba = '0'; | 80 | // $scope.hojaRuta.bomba = '0'; |
| 81 | // $scope.hojaRuta.flete = '0'; | 81 | // $scope.hojaRuta.flete = '0'; |
| 82 | // $scope.idLista = undefined; | 82 | // $scope.idLista = undefined; |
| 83 | // } | 83 | // } |
| 84 | //TO DO - FUNCIONES PARA MULTIPLES DOMICILIOS NO IMPLEMENTADAS EN ESTA DEMO | 84 | //TO DO - FUNCIONES PARA MULTIPLES DOMICILIOS NO IMPLEMENTADAS EN ESTA DEMO |
| 85 | // $scope.addNewDom = function() { | 85 | // $scope.addNewDom = function() { |
| 86 | // $scope.hojaRuta.domicilio.push({ 'id': 0 }); | 86 | // $scope.hojaRuta.domicilio.push({ 'id': 0 }); |
| 87 | // }; | 87 | // }; |
| 88 | // $scope.removeNewChoice = function(choice) { | 88 | // $scope.removeNewChoice = function(choice) { |
| 89 | // if ($scope.hojaRuta.domicilio.length > 1) { | 89 | // if ($scope.hojaRuta.domicilio.length > 1) { |
| 90 | // $scope.hojaRuta.domicilio.splice($scope.hojaRuta.domicilio.findIndex( | 90 | // $scope.hojaRuta.domicilio.splice($scope.hojaRuta.domicilio.findIndex( |
| 91 | // function(c) { | 91 | // function(c) { |
| 92 | // return c.$$hashKey === choice.$$hashKey; | 92 | // return c.$$hashKey === choice.$$hashKey; |
| 93 | // } | 93 | // } |
| 94 | // ), 1); | 94 | // ), 1); |
| 95 | // } | 95 | // } |
| 96 | // }; | 96 | // }; |
| 97 | 97 | ||
| 98 | $scope.crearHojaRuta = function() { | 98 | $scope.crearHojaRuta = function() { |
| 99 | if($scope.hojaRuta.litros <= 0) { | 99 | if($scope.hojaRuta.litros <= 0) { |
| 100 | focaModalService.alert('Ingrese Remitos'); | 100 | focaModalService.alert('Ingrese Remitos'); |
| 101 | return; | 101 | return; |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | if(!$scope.hojaRuta.chofer.id) { | 104 | if(!$scope.hojaRuta.chofer.id) { |
| 105 | focaModalService.alert('Ingrese Chofer'); | 105 | focaModalService.alert('Ingrese Chofer'); |
| 106 | return; | 106 | return; |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | if(!$scope.hojaRuta.vehiculo.id) { | 109 | if(!$scope.hojaRuta.vehiculo.id) { |
| 110 | focaModalService.alert('Ingrese Vehiculo'); | 110 | focaModalService.alert('Ingrese Vehiculo'); |
| 111 | return; | 111 | return; |
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | if(!$scope.hojaRuta.transportista.codigo) { | 114 | if(!$scope.hojaRuta.transportista.codigo) { |
| 115 | focaModalService.alert('Ingrese Transportista'); | 115 | focaModalService.alert('Ingrese Transportista'); |
| 116 | return; | 116 | return; |
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | if($scope.hojaRuta.vehiculo.capacidad < $scope.hojaRuta.litros) { | 119 | if($scope.hojaRuta.vehiculo.capacidad < $scope.hojaRuta.litros) { |
| 120 | focaModalService.alert( | 120 | focaModalService.alert( |
| 121 | 'La capacidad del Vehiculo es menor a lo ingresado en Remitos' | 121 | 'La capacidad del Vehiculo es menor a lo ingresado en Remitos' |
| 122 | ); | 122 | ); |
| 123 | return; | 123 | return; |
| 124 | } | 124 | } |
| 125 | 125 | ||
| 126 | if(!$scope.hojaRuta.tarifario.costo) { | 126 | if(!$scope.hojaRuta.tarifario.costo) { |
| 127 | focaModalService.alert('Ingrese Tarifario'); | 127 | focaModalService.alert('Ingrese Tarifario'); |
| 128 | return; | 128 | return; |
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | var date = new Date(); | 131 | var date = new Date(); |
| 132 | var save = { | 132 | var save = { |
| 133 | hojaRuta: { | 133 | hojaRuta: { |
| 134 | id: 0, | 134 | id: 0, |
| 135 | fechaCreacion: | 135 | fechaCreacion: |
| 136 | new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) | 136 | new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) |
| 137 | .toISOString().slice(0, 19) .replace('T', ' '), | 137 | .toISOString().slice(0, 19) .replace('T', ' '), |
| 138 | idTransportista: $scope.hojaRuta.transportista.codigo, | 138 | idTransportista: $scope.hojaRuta.transportista.codigo, |
| 139 | idChofer: $scope.hojaRuta.chofer.id, | 139 | idChofer: $scope.hojaRuta.chofer.id, |
| 140 | idVehiculo: $scope.hojaRuta.vehiculo.id, | 140 | idVehiculo: $scope.hojaRuta.vehiculo.id, |
| 141 | tarifaFlete: $scope.hojaRuta.tarifario.costo | 141 | tarifaFlete: $scope.hojaRuta.tarifario.costo |
| 142 | }, | 142 | }, |
| 143 | remitos: $scope.remitosTabla | 143 | remitos: $scope.remitosTabla |
| 144 | }; | 144 | }; |
| 145 | 145 | ||
| 146 | crearHojaRutaService.crearHojaRuta(save).then( | 146 | crearHojaRutaService.crearHojaRuta(save).then( |
| 147 | function(data) { | 147 | function(data) { |
| 148 | focaModalService.alert( | 148 | focaModalService.alert( |
| 149 | 'Hoja ruta creada Nº: ' + | 149 | 'Hoja ruta creada Nº: ' + |
| 150 | $scope.rellenar(data.sucursal, 4) + | 150 | $scope.rellenar(data.data.sucursal, 4) + |
| 151 | '-' + | 151 | '-' + |
| 152 | $scope.rellenar(data.numeroHojaRuta, 8) | 152 | $scope.rellenar(data.data.numeroHojaRuta, 8) |
| 153 | ); | 153 | ); |
| 154 | $scope.hojaRuta = { | 154 | $scope.hojaRuta = { |
| 155 | fecha: new Date(), | 155 | fecha: new Date(), |
| 156 | litros: 0, | 156 | litros: 0, |
| 157 | chofer: {}, | 157 | chofer: {}, |
| 158 | vehiculo: { | 158 | vehiculo: { |
| 159 | capacidad: 0 | 159 | capacidad: 0 |
| 160 | }, | 160 | }, |
| 161 | transportista: {}, | 161 | transportista: {}, |
| 162 | tarifario: { | 162 | tarifario: { |
| 163 | costo: null | 163 | costo: null |
| 164 | } | 164 | } |
| 165 | }; | 165 | }; |
| 166 | 166 | ||
| 167 | $scope.remitosTabla = []; | 167 | $scope.remitosTabla = []; |
| 168 | $scope.cabecera = []; | 168 | $scope.cabecera = []; |
| 169 | 169 | ||
| 170 | crearHojaRutaService.getNumeroHojaRuta().then(function(res) { | 170 | crearHojaRutaService.getNumeroHojaRuta().then(function(res) { |
| 171 | $scope.comprobante = $scope.rellenar(res.data.numeroHojaRuta, 8); | 171 | $scope.comprobante = $scope.rellenar(res.data.numeroHojaRuta, 8); |
| 172 | }); | 172 | }); |
| 173 | }, | 173 | }, |
| 174 | function(error) { | 174 | function(error) { |
| 175 | focaModalService.alert('Hubo un error al crear la nota de pedido'); | 175 | focaModalService.alert('Hubo un error al crear la nota de pedido'); |
| 176 | console.info(error); | 176 | console.info(error); |
| 177 | } | 177 | } |
| 178 | ); | 178 | ); |
| 179 | }; | 179 | }; |
| 180 | 180 | ||
| 181 | $scope.seleccionarProveedor = function() { | 181 | $scope.seleccionarProveedor = function() { |
| 182 | var modalInstance = $uibModal.open( | 182 | var modalInstance = $uibModal.open( |
| 183 | { | 183 | { |
| 184 | ariaLabelledBy: 'Busqueda de Transportista', | 184 | ariaLabelledBy: 'Busqueda de Transportista', |
| 185 | templateUrl: 'modal-proveedor.html', | 185 | templateUrl: 'modal-proveedor.html', |
| 186 | controller: 'focaModalProveedorCtrl', | 186 | controller: 'focaModalProveedorCtrl', |
| 187 | size: 'lg', | 187 | size: 'lg', |
| 188 | resolve: { | 188 | resolve: { |
| 189 | transportista: function() { | 189 | transportista: function() { |
| 190 | return true; | 190 | return true; |
| 191 | } | 191 | } |
| 192 | } | 192 | } |
| 193 | } | 193 | } |
| 194 | ); | 194 | ); |
| 195 | modalInstance.result.then( | 195 | modalInstance.result.then( |
| 196 | function(proveedor) { | 196 | function(proveedor) { |
| 197 | console.info($scope.hojaRuta); | 197 | console.info($scope.hojaRuta); |
| 198 | $scope.hojaRuta.transportista.codigo = proveedor.COD; | 198 | $scope.hojaRuta.transportista.codigo = proveedor.COD; |
| 199 | addCabecera('Transportista:', proveedor.NOM); | 199 | addCabecera('Transportista:', proveedor.NOM); |
| 200 | }, function() { | 200 | }, function() { |
| 201 | 201 | ||
| 202 | } | 202 | } |
| 203 | ); | 203 | ); |
| 204 | }; | 204 | }; |
| 205 | 205 | ||
| 206 | $scope.seleccionarChofer = function() { | 206 | $scope.seleccionarChofer = function() { |
| 207 | var modalInstance = $uibModal.open( | 207 | var modalInstance = $uibModal.open( |
| 208 | { | 208 | { |
| 209 | ariaLabelledBy: 'Busqueda de Chofer', | 209 | ariaLabelledBy: 'Busqueda de Chofer', |
| 210 | templateUrl: 'modal-chofer.html', | 210 | templateUrl: 'modal-chofer.html', |
| 211 | controller: 'focaModalChoferController', | 211 | controller: 'focaModalChoferController', |
| 212 | size: 'lg' | 212 | size: 'lg' |
| 213 | } | 213 | } |
| 214 | ); | 214 | ); |
| 215 | 215 | ||
| 216 | modalInstance.result.then( | 216 | modalInstance.result.then( |
| 217 | function(chofer) { | 217 | function(chofer) { |
| 218 | $scope.hojaRuta.chofer = chofer; | 218 | $scope.hojaRuta.chofer = chofer; |
| 219 | addCabecera('Chofer: ' + chofer.nombre); | 219 | addCabecera('Chofer: ' + chofer.nombre); |
| 220 | }, function() { | 220 | }, function() { |
| 221 | // funcion ejecutada cuando se cancela el modal | 221 | // funcion ejecutada cuando se cancela el modal |
| 222 | } | 222 | } |
| 223 | ); | 223 | ); |
| 224 | }; | 224 | }; |
| 225 | 225 | ||
| 226 | $scope.seleccionarVehiculo = function() { | 226 | $scope.seleccionarVehiculo = function() { |
| 227 | var modalInstance = $uibModal.open( | 227 | var modalInstance = $uibModal.open( |
| 228 | { | 228 | { |
| 229 | ariaLabelledBy: 'Busqueda de Vehiculo', | 229 | ariaLabelledBy: 'Busqueda de Vehiculo', |
| 230 | templateUrl: 'modal-vehiculo.html', | 230 | templateUrl: 'modal-vehiculo.html', |
| 231 | controller: 'focaModalVehiculoController', | 231 | controller: 'focaModalVehiculoController', |
| 232 | size: 'lg' | 232 | size: 'lg' |
| 233 | } | 233 | } |
| 234 | ); | 234 | ); |
| 235 | 235 | ||
| 236 | modalInstance.result.then( | 236 | modalInstance.result.then( |
| 237 | function(vehiculo) { | 237 | function(vehiculo) { |
| 238 | $scope.hojaRuta.vehiculo = vehiculo; | 238 | $scope.hojaRuta.vehiculo = vehiculo; |
| 239 | addCabecera('Tractor: ' + vehiculo.tractor); | 239 | addCabecera('Tractor: ' + vehiculo.tractor); |
| 240 | addCabecera('Semi: ' + vehiculo.semi); | 240 | addCabecera('Semi: ' + vehiculo.semi); |
| 241 | addCabecera('Capacidad: ' + vehiculo.capacidad); | 241 | addCabecera('Capacidad: ' + vehiculo.capacidad); |
| 242 | }, function() { | 242 | }, function() { |
| 243 | // funcion ejecutada cuando se cancela el modal | 243 | // funcion ejecutada cuando se cancela el modal |
| 244 | } | 244 | } |
| 245 | ); | 245 | ); |
| 246 | }; | 246 | }; |
| 247 | 247 | ||
| 248 | $scope.seleccionarTarifario = function() { | 248 | $scope.seleccionarTarifario = function() { |
| 249 | var modalInstance = $uibModal.open( | 249 | var modalInstance = $uibModal.open( |
| 250 | { | 250 | { |
| 251 | ariaLabelledBy: 'Busqueda de Tarifario', | 251 | ariaLabelledBy: 'Busqueda de Tarifario', |
| 252 | templateUrl: 'modal-tarifa-flete.html', | 252 | templateUrl: 'modal-tarifa-flete.html', |
| 253 | controller: 'focaModalTarifaFleteController', | 253 | controller: 'focaModalTarifaFleteController', |
| 254 | size: 'lg', | 254 | size: 'lg', |
| 255 | resolve: { | 255 | resolve: { |
| 256 | parametrosTarifaFlete: function() { | 256 | parametrosTarifaFlete: function() { |
| 257 | return $scope.hojaRuta.tarifario.costo; | 257 | return $scope.hojaRuta.tarifario.costo; |
| 258 | } | 258 | } |
| 259 | } | 259 | } |
| 260 | } | 260 | } |
| 261 | ); | 261 | ); |
| 262 | 262 | ||
| 263 | modalInstance.result.then( | 263 | modalInstance.result.then( |
| 264 | function(tarifario) { | 264 | function(tarifario) { |
| 265 | $scope.hojaRuta.tarifario = tarifario; | 265 | $scope.hojaRuta.tarifario = tarifario; |
| 266 | addCabecera('Tarifario: ' + tarifario.costo); | 266 | addCabecera('Tarifario: ' + tarifario.costo); |
| 267 | }, function() { | 267 | }, function() { |
| 268 | // funcion ejecutada cuando se cancela el modal | 268 | // funcion ejecutada cuando se cancela el modal |
| 269 | } | 269 | } |
| 270 | ); | 270 | ); |
| 271 | }; | 271 | }; |
| 272 | 272 | ||
| 273 | $scope.seleccionarRemito = function() { | 273 | $scope.seleccionarRemito = function() { |
| 274 | var modalInstance = $uibModal.open( | 274 | var modalInstance = $uibModal.open( |
| 275 | { | 275 | { |
| 276 | ariaLabelledBy: 'Busqueda de Remito', | 276 | ariaLabelledBy: 'Busqueda de Remito', |
| 277 | templateUrl: 'foca-modal-remito.html', | 277 | templateUrl: 'foca-modal-remito.html', |
| 278 | controller: 'focaModalRemitoController', | 278 | controller: 'focaModalRemitoController', |
| 279 | size: 'lg' | 279 | size: 'lg' |
| 280 | } | 280 | } |
| 281 | ); | 281 | ); |
| 282 | modalInstance.result.then( | 282 | modalInstance.result.then( |
| 283 | function(remito) { | 283 | function(remito) { |
| 284 | for (var i = $scope.remitosTabla.length - 1; i >= 0; i--) { | 284 | for (var i = $scope.remitosTabla.length - 1; i >= 0; i--) { |
| 285 | if ($scope.remitosTabla[i].id === remito.id) { | 285 | if ($scope.remitosTabla[i].id === remito.id) { |
| 286 | focaModalService.alert('Remito ya incluido'); | 286 | focaModalService.alert('Remito ya incluido'); |
| 287 | return; | 287 | return; |
| 288 | } | 288 | } |
| 289 | } | 289 | } |
| 290 | 290 | ||
| 291 | var litros = 0; | 291 | var litros = 0; |
| 292 | for (var j = remito.articulosRemito.length - 1; j >= 0; j--) { | 292 | for (var j = remito.articulosRemito.length - 1; j >= 0; j--) { |
| 293 | litros = litros + parseFloat(remito.articulosRemito[j].cantidad); | 293 | litros = litros + parseFloat(remito.articulosRemito[j].cantidad); |
| 294 | } | 294 | } |
| 295 | 295 | ||
| 296 | if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) { | 296 | if ($scope.hojaRuta.litros >= $scope.hojaRuta.vehiculo.capacidad) { |
| 297 | focaModalService.alert( | 297 | focaModalService.alert( |
| 298 | 'No se puede agregar mas recibos porque la ' + | 298 | 'No se puede agregar mas recibos porque la ' + |
| 299 | 'capacidad del vehiculo esta llena o no esta definida' | 299 | 'capacidad del vehiculo esta llena o no esta definida' |
| 300 | ); | 300 | ); |
| 301 | return; | 301 | return; |
| 302 | } | 302 | } |
| 303 | 303 | ||
| 304 | if ($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad) | 304 | if ($scope.hojaRuta.litros + litros >= $scope.hojaRuta.vehiculo.capacidad) |
| 305 | { | 305 | { |
| 306 | var litrostotales = litros; | 306 | var litrostotales = litros; |
| 307 | litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros; | 307 | litros = $scope.hojaRuta.vehiculo.capacidad - $scope.hojaRuta.litros; |
| 308 | focaModalService.alert( | 308 | focaModalService.alert( |
| 309 | 'La carga excede la capacidad disponible del vehiculo. ' + | 309 | 'La carga excede la capacidad disponible del vehiculo. ' + |
| 310 | 'Excedente no cargado: ' + (litrostotales - litros) + ' litros' | 310 | 'Excedente no cargado: ' + (litrostotales - litros) + ' litros' |
| 311 | ); | 311 | ); |
| 312 | } | 312 | } |
| 313 | 313 | ||
| 314 | remito.litros = litros; | 314 | remito.litros = litros; |
| 315 | $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros; | 315 | $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros; |
| 316 | $scope.remitosTabla.push(remito); | 316 | $scope.remitosTabla.push(remito); |
| 317 | }, function() { | 317 | }, function() { |
| 318 | // funcion ejecutada cuando se cancela el modal | 318 | // funcion ejecutada cuando se cancela el modal |
| 319 | } | 319 | } |
| 320 | ); | 320 | ); |
| 321 | }; | 321 | }; |
| 322 | 322 | ||
| 323 | $scope.getTotal = function() { | 323 | $scope.getTotal = function() { |
| 324 | var total = 0; | 324 | var total = 0; |
| 325 | var arrayTempArticulos = $scope.remitosTabla; | 325 | var arrayTempArticulos = $scope.remitosTabla; |
| 326 | for (var i = 0; i < arrayTempArticulos.length; i++) { | 326 | for (var i = 0; i < arrayTempArticulos.length; i++) { |
| 327 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | 327 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; |
| 328 | } | 328 | } |
| 329 | return parseFloat(total.toFixed(2)); | 329 | return parseFloat(total.toFixed(2)); |
| 330 | }; | 330 | }; |
| 331 | 331 | ||
| 332 | $scope.getSubTotal = function() { | 332 | $scope.getSubTotal = function() { |
| 333 | if($scope.articuloACargar) { | 333 | if($scope.articuloACargar) { |
| 334 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; | 334 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
| 335 | } | 335 | } |
| 336 | }; | 336 | }; |
| 337 | 337 | ||
| 338 | $scope.limpiarPantalla = function() { | 338 | $scope.limpiarPantalla = function() { |
| 339 | $scope.limpiarFlete(); | 339 | $scope.limpiarFlete(); |
| 340 | $scope.hojaRuta.flete = '0'; | 340 | $scope.hojaRuta.flete = '0'; |
| 341 | $scope.hojaRuta.bomba = '0'; | 341 | $scope.hojaRuta.bomba = '0'; |
| 342 | $scope.hojaRuta.precioCondicion = ''; | 342 | $scope.hojaRuta.precioCondicion = ''; |
| 343 | $scope.remitosTabla = []; | 343 | $scope.remitosTabla = []; |
| 344 | $scope.hojaRuta.vendedor.nombre = ''; | 344 | $scope.hojaRuta.vendedor.nombre = ''; |
| 345 | $scope.hojaRuta.cliente = {nombre: ''}; | 345 | $scope.hojaRuta.cliente = {nombre: ''}; |
| 346 | $scope.hojaRuta.domicilio = {dom: ''}; | 346 | $scope.hojaRuta.domicilio = {dom: ''}; |
| 347 | $scope.hojaRuta.litros = 0; | 347 | $scope.hojaRuta.litros = 0; |
| 348 | $scope.domiciliosCliente = []; | 348 | $scope.domiciliosCliente = []; |
| 349 | }; | 349 | }; |
| 350 | //Recibe aviso si el teclado está en uso | 350 | //Recibe aviso si el teclado está en uso |
| 351 | // $rootScope.$on('usarTeclado', function(event, data) { | 351 | // $rootScope.$on('usarTeclado', function(event, data) { |
| 352 | // if(data) { | 352 | // if(data) { |
| 353 | // $scope.mostrarTeclado = true; | 353 | // $scope.mostrarTeclado = true; |
| 354 | // return; | 354 | // return; |
| 355 | // } | 355 | // } |
| 356 | // $scope.mostrarTeclado = false; | 356 | // $scope.mostrarTeclado = false; |
| 357 | // }) | 357 | // }) |
| 358 | $scope.selectFocus = function($event) { | 358 | $scope.selectFocus = function($event) { |
| 359 | //Si el teclado esta en uso no selecciona el valor | 359 | //Si el teclado esta en uso no selecciona el valor |
| 360 | // if($scope.mostrarTeclado) { | 360 | // if($scope.mostrarTeclado) { |
| 361 | // return; | 361 | // return; |
| 362 | // } | 362 | // } |
| 363 | $event.target.select(); | 363 | $event.target.select(); |
| 364 | }; | 364 | }; |
| 365 | 365 | ||
| 366 | $scope.salir = function() { | 366 | $scope.salir = function() { |
| 367 | $location.path('/'); | 367 | $location.path('/'); |
| 368 | }; | 368 | }; |
| 369 | 369 | ||
| 370 | $scope.parsearATexto = function(articulo) { | 370 | $scope.parsearATexto = function(articulo) { |
| 371 | articulo.cantidad = parseFloat(articulo.cantidad); | 371 | articulo.cantidad = parseFloat(articulo.cantidad); |
| 372 | articulo.precio = parseFloat(articulo.precio); | 372 | articulo.precio = parseFloat(articulo.precio); |
| 373 | }; | 373 | }; |
| 374 | 374 | ||
| 375 | $scope.rellenar = function(relleno, longitud) { | 375 | $scope.rellenar = function(relleno, longitud) { |
| 376 | relleno = '' + relleno; | 376 | relleno = '' + relleno; |
| 377 | while (relleno.length < longitud) { | 377 | while (relleno.length < longitud) { |
| 378 | relleno = '0' + relleno; | 378 | relleno = '0' + relleno; |
| 379 | } | 379 | } |
| 380 | 380 | ||
| 381 | return relleno; | 381 | return relleno; |
| 382 | }; | 382 | }; |
| 383 | 383 | ||
| 384 | $scope.quitarArticulo = function(key) { | 384 | $scope.quitarArticulo = function(key) { |
| 385 | $scope.remitosTabla.splice(key, 1); | 385 | $scope.remitosTabla.splice(key, 1); |
| 386 | var litros = 0; | 386 | var litros = 0; |
| 387 | 387 | ||
| 388 | for (var i = $scope.remitosTabla.length - 1; i >= 0; i--) { | 388 | for (var i = $scope.remitosTabla.length - 1; i >= 0; i--) { |
| 389 | litros += parseFloat($scope.remitosTabla[i].litros); | 389 | litros += parseFloat($scope.remitosTabla[i].litros); |
| 390 | } | 390 | } |
| 391 | 391 | ||
| 392 | $scope.hojaRuta.litros = litros; | 392 | $scope.hojaRuta.litros = litros; |
| 393 | 393 | ||
| 394 | }; | 394 | }; |
| 395 | 395 | ||
| 396 | function addCabecera(label, valor) { | 396 | function addCabecera(label, valor) { |
| 397 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); | 397 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); |
| 398 | if(propiedad.length === 1) { | 398 | if(propiedad.length === 1) { |
| 399 | propiedad[0].valor = valor; | 399 | propiedad[0].valor = valor; |
| 400 | } else { | 400 | } else { |
| 401 | $scope.cabecera.push({label: label, valor: valor}); | 401 | $scope.cabecera.push({label: label, valor: valor}); |
| 402 | } | 402 | } |
| 403 | } | 403 | } |
| 404 | 404 | ||
| 405 | /*function removeCabecera(label) { | 405 | /*function removeCabecera(label) { |
| 406 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); | 406 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); |
| 407 | if(propiedad.length === 1){ | 407 | if(propiedad.length === 1){ |
| 408 | $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); | 408 | $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); |
| 409 | } | 409 | } |
| 410 | }*/ | 410 | }*/ |
| 411 | } | 411 | } |
| 412 | ] | 412 | ] |
| 413 | ) | 413 | ) |
| 414 | .controller('hojaRutaListaCtrl', [ | 414 | .controller('hojaRutaListaCtrl', [ |
| 415 | '$scope', | 415 | '$scope', |
| 416 | 'crearHojaRutaService', | 416 | 'crearHojaRutaService', |
| 417 | '$location', | 417 | '$location', |
| 418 | function($scope, crearHojaRutaService, $location) { | 418 | function($scope, crearHojaRutaService, $location) { |
| 419 | crearHojaRutaService.obtenerHojaRuta().then(function(datos) { | 419 | crearHojaRutaService.obtenerHojaRuta().then(function(datos) { |
| 420 | $scope.hojaRutas = datos.data; | 420 | $scope.hojaRutas = datos.data; |
| 421 | }); | 421 | }); |
| 422 | $scope.editar = function(hojaRuta) { | 422 | $scope.editar = function(hojaRuta) { |
| 423 | crearHojaRutaService.setHojaRuta(hojaRuta); | 423 | crearHojaRutaService.setHojaRuta(hojaRuta); |
| 424 | $location.path('/venta-nota-pedido/abm/'); | 424 | $location.path('/venta-nota-pedido/abm/'); |
| 425 | }; | 425 | }; |
| 426 | $scope.crearPedido = function() { | 426 | $scope.crearPedido = function() { |
| 427 | crearHojaRutaService.clearHojaRuta(); | 427 | crearHojaRutaService.clearHojaRuta(); |
| 428 | $location.path('/venta-nota-pedido/abm/'); | 428 | $location.path('/venta-nota-pedido/abm/'); |
| 429 | }; | 429 | }; |
| 430 | } | 430 | } |
| 431 | ]) | 431 | ]) |
| 432 | .controller('focaCrearHojaRutaFichaClienteController', [ | 432 | .controller('focaCrearHojaRutaFichaClienteController', [ |
| 433 | '$scope', | 433 | '$scope', |
| 434 | 'crearHojaRutaService', | 434 | 'crearHojaRutaService', |
| 435 | '$location', | 435 | '$location', |
| 436 | function($scope, crearHojaRutaService, $location) { | 436 | function($scope, crearHojaRutaService, $location) { |
| 437 | crearHojaRutaService.obtenerHojaRuta().then(function(datos) { | 437 | crearHojaRutaService.obtenerHojaRuta().then(function(datos) { |
| 438 | $scope.hojaRutas = datos.data; | 438 | $scope.hojaRutas = datos.data; |
| 439 | }); | 439 | }); |
| 440 | $scope.editar = function(hojaRuta) { | 440 | $scope.editar = function(hojaRuta) { |
| 441 | crearHojaRutaService.setHojaRuta(hojaRuta); | 441 | crearHojaRutaService.setHojaRuta(hojaRuta); |
| 442 | $location.path('/venta-nota-pedido/abm/'); | 442 | $location.path('/venta-nota-pedido/abm/'); |
| 443 | }; | 443 | }; |
| 444 | $scope.crearPedido = function() { | 444 | $scope.crearPedido = function() { |
| 445 | crearHojaRutaService.clearHojaRuta(); | 445 | crearHojaRutaService.clearHojaRuta(); |
| 446 | $location.path('/venta-nota-pedido/abm/'); | 446 | $location.path('/venta-nota-pedido/abm/'); |
| 447 | }; | 447 | }; |
| 448 | } | 448 | } |
| 449 | ]); | 449 | ]); |
| 450 | 450 |