Commit a24ce94ee3bc70f048b9b44353526b65d60a814b
1 parent
2ed3c8ad38
Exists in
master
and in
1 other branch
ok tests
Showing
3 changed files
with
43 additions
and
244 deletions
Show diff stats
spec/controllerSpec.js
| 1 | describe('Controladores módulo crear nota de pedido', function() { | 1 | describe('Controladores módulo crear nota de pedido', function() { |
| 2 | 2 | ||
| 3 | var $controler; | 3 | var $controler; |
| 4 | 4 | ||
| 5 | beforeEach(function() { | 5 | beforeEach(function() { |
| 6 | module('focaCrearNotaPedido'); | 6 | module('focaCrearNotaPedido'); |
| 7 | inject(function(_$controller_) { | 7 | inject(function(_$controller_) { |
| 8 | $controler = _$controller_; | 8 | $controler = _$controller_; |
| 9 | }); | 9 | }); |
| 10 | }); | 10 | }); |
| 11 | 11 | ||
| 12 | describe('Controlador notaPedidoCtrl', function() { | 12 | describe('Controlador notaPedidoCtrl', function() { |
| 13 | 13 | ||
| 14 | var filter = function() { | 14 | var filter = function() { |
| 15 | return function() { }; | 15 | return function() { }; |
| 16 | }; | 16 | }; |
| 17 | var timeout; | 17 | var timeout; |
| 18 | 18 | ||
| 19 | beforeEach(function() { | 19 | beforeEach(function() { |
| 20 | 20 | ||
| 21 | inject(function($timeout) { | 21 | inject(function($timeout) { |
| 22 | timeout = $timeout; | 22 | timeout = $timeout; |
| 23 | }); | 23 | }); |
| 24 | }); | 24 | }); |
| 25 | 25 | ||
| 26 | it('La función seleccionarNotaPedido levanta modal', function() { | 26 | it('La función seleccionarNotaPedido levanta modal', function() { |
| 27 | //arrange | 27 | //arrange |
| 28 | var scope = { | 28 | var scope = { |
| 29 | $watch: function() { }, | 29 | $watch: function() { }, |
| 30 | $broadcast: function() { } | 30 | $broadcast: function() { } |
| 31 | }; | 31 | }; |
| 32 | var uibModal = { | 32 | var uibModal = { |
| 33 | open: function() { } | 33 | open: function() { } |
| 34 | }; | 34 | }; |
| 35 | 35 | ||
| 36 | $controler('notaPedidoCtrl', { | 36 | $controler('notaPedidoCtrl', { |
| 37 | $scope: scope, | 37 | $scope: scope, |
| 38 | $uibModal: uibModal, | 38 | $uibModal: uibModal, |
| 39 | $location: {}, | 39 | $location: {}, |
| 40 | $filter: filter, | 40 | $filter: filter, |
| 41 | $timeout: timeout, | 41 | $timeout: timeout, |
| 42 | crearNotaPedidoService: { | 42 | crearNotaPedidoService: { |
| 43 | getNumeroNotaPedido: function() { | 43 | getNumeroNotaPedido: function() { |
| 44 | return { | 44 | return { |
| 45 | then: function() { } | 45 | then: function() { } |
| 46 | }; | 46 | }; |
| 47 | }, | 47 | }, |
| 48 | getBotonera: function() { }, | 48 | getBotonera: function() { }, |
| 49 | getCotizacionByIdMoneda: function() { | 49 | getCotizacionByIdMoneda: function() { |
| 50 | return { | 50 | return { |
| 51 | then: function() { } | 51 | then: function() { } |
| 52 | }; | 52 | }; |
| 53 | } | 53 | } |
| 54 | }, | 54 | }, |
| 55 | focaBotoneraLateralService: {}, | 55 | focaBotoneraLateralService: {}, |
| 56 | focaModalService: {}, | 56 | focaModalService: {}, |
| 57 | notaPedidoBusinessService: {}, | 57 | notaPedidoBusinessService: {}, |
| 58 | $rootScope: { | 58 | $rootScope: { |
| 59 | $on: function() { } | 59 | $on: function() { } |
| 60 | }, | 60 | }, |
| 61 | focaSeguimientoService: {}, | 61 | focaSeguimientoService: {}, |
| 62 | APP: {}, | 62 | APP: {}, |
| 63 | focaLoginService: {}, | 63 | focaLoginService: {}, |
| 64 | $localStorage: {} | 64 | $localStorage: {} |
| 65 | }); | 65 | }); |
| 66 | var respuesta = { result: { then: function() { } } }; | 66 | var respuesta = { result: { then: function() { } } }; |
| 67 | 67 | ||
| 68 | //act | 68 | //act |
| 69 | spyOn(uibModal, 'open').and.returnValue(respuesta); | 69 | spyOn(uibModal, 'open').and.returnValue(respuesta); |
| 70 | scope.seleccionarNotaPedido(); | 70 | scope.seleccionarNotaPedido(); |
| 71 | 71 | ||
| 72 | //assert | 72 | //assert |
| 73 | expect(uibModal.open).toHaveBeenCalled(); | 73 | expect(uibModal.open).toHaveBeenCalled(); |
| 74 | }); | 74 | }); |
| 75 | 75 | ||
| 76 | it('La función seleccionarNotaPedido llama a broadCast en promesa', function(done) { | 76 | it('La función seleccionarNotaPedido llama a broadCast en promesa', function(done) { |
| 77 | //arrange | 77 | //arrange |
| 78 | var scope = { | 78 | var scope = { |
| 79 | $watch: function() { }, | 79 | $watch: function() { }, |
| 80 | $broadcast: function() { } | 80 | $broadcast: function() { } |
| 81 | }; | 81 | }; |
| 82 | var uibModal = { | 82 | var uibModal = { |
| 83 | open: function() { } | 83 | open: function() { } |
| 84 | }; | 84 | }; |
| 85 | 85 | ||
| 86 | $controler('notaPedidoCtrl', { | 86 | $controler('notaPedidoCtrl', { |
| 87 | $scope: scope, | 87 | $scope: scope, |
| 88 | $uibModal: uibModal, | 88 | $uibModal: uibModal, |
| 89 | $location: {}, | 89 | $location: {}, |
| 90 | $filter: filter, | 90 | $filter: filter, |
| 91 | $timeout: timeout, | 91 | $timeout: timeout, |
| 92 | crearNotaPedidoService: { | 92 | crearNotaPedidoService: { |
| 93 | getNumeroNotaPedido: function() { | 93 | getNumeroNotaPedido: function() { |
| 94 | return { | 94 | return { |
| 95 | then: function() { } | 95 | then: function() { } |
| 96 | }; | 96 | }; |
| 97 | }, | 97 | }, |
| 98 | getBotonera: function() { }, | 98 | getBotonera: function() { }, |
| 99 | getCotizacionByIdMoneda: function() { | 99 | getCotizacionByIdMoneda: function() { |
| 100 | return { | 100 | return { |
| 101 | then: function() { } | 101 | then: function() { } |
| 102 | }; | 102 | }; |
| 103 | } | 103 | } |
| 104 | }, | 104 | }, |
| 105 | focaBotoneraLateralService: {}, | 105 | focaBotoneraLateralService: {}, |
| 106 | focaModalService: {}, | 106 | focaModalService: {}, |
| 107 | notaPedidoBusinessService: { | 107 | notaPedidoBusinessService: { |
| 108 | plazoToString: function() { }, | 108 | plazoToString: function() { }, |
| 109 | calcularArticulos: function() { } | 109 | calcularArticulos: function() { } |
| 110 | }, | 110 | }, |
| 111 | $rootScope: { | 111 | $rootScope: { |
| 112 | $on: function() { } | 112 | $on: function() { } |
| 113 | }, | 113 | }, |
| 114 | focaSeguimientoService: {}, | 114 | focaSeguimientoService: {}, |
| 115 | APP: {}, | 115 | APP: {}, |
| 116 | focaLoginService: {}, | 116 | focaLoginService: {}, |
| 117 | $localStorage: {} | 117 | $localStorage: {} |
| 118 | }); | 118 | }); |
| 119 | var notaPedido = { | 119 | var notaPedido = { |
| 120 | cotizacion: { | 120 | cotizacion: { |
| 121 | moneda: {} | 121 | moneda: {} |
| 122 | }, | 122 | }, |
| 123 | cliente: {}, | 123 | cliente: {}, |
| 124 | vendedor: {}, | 124 | vendedor: {}, |
| 125 | proveedor: {}, | 125 | proveedor: {}, |
| 126 | notaPedidoPlazo: [], | 126 | notaPedidoPlazo: [], |
| 127 | notaPedidoPuntoDescarga: [] | 127 | notaPedidoPuntoDescarga: [] |
| 128 | }; | 128 | }; |
| 129 | var respuesta = { result: Promise.resolve(notaPedido) }; | 129 | var respuesta = { result: Promise.resolve(notaPedido) }; |
| 130 | 130 | ||
| 131 | //act | 131 | //act |
| 132 | scope.notaPedido = {}; | 132 | scope.notaPedido = {}; |
| 133 | scope.$broadcast = function() { }; | 133 | scope.$broadcast = function() { }; |
| 134 | spyOn(uibModal, 'open').and.returnValue(respuesta); | 134 | spyOn(uibModal, 'open').and.returnValue(respuesta); |
| 135 | spyOn(scope, '$broadcast'); | 135 | spyOn(scope, '$broadcast'); |
| 136 | scope.seleccionarNotaPedido(); | 136 | scope.seleccionarNotaPedido(); |
| 137 | 137 | ||
| 138 | //assert | 138 | //assert |
| 139 | respuesta.result.then(function() { | 139 | respuesta.result.then(function() { |
| 140 | expect(scope.$broadcast).toHaveBeenCalledWith('removeCabecera', 'Bomba:'); | 140 | expect(scope.$broadcast).toHaveBeenCalledWith('removeCabecera', 'Bomba:'); |
| 141 | expect(scope.$broadcast).toHaveBeenCalledWith('removeCabecera', 'Kilometros:'); | 141 | expect(scope.$broadcast).toHaveBeenCalledWith('removeCabecera', 'Kilometros:'); |
| 142 | done(); | 142 | done(); |
| 143 | }); | 143 | }); |
| 144 | }); | 144 | }); |
| 145 | 145 | ||
| 146 | it('función seleccionarProductos muestra alerta cuando idLista undefined', function() { | 146 | it('función seleccionarProductos muestra alerta cuando idLista undefined', function() { |
| 147 | //arrange | 147 | //arrange |
| 148 | var scope = { | 148 | var scope = { |
| 149 | $watch: function() { }, | 149 | $watch: function() { }, |
| 150 | $broadcast: function() { } | 150 | $broadcast: function() { } |
| 151 | }; | 151 | }; |
| 152 | var focaModalService = { | 152 | var focaModalService = { |
| 153 | alert: function() { } | 153 | alert: function() { } |
| 154 | }; | 154 | }; |
| 155 | 155 | ||
| 156 | $controler('notaPedidoCtrl', { | 156 | $controler('notaPedidoCtrl', { |
| 157 | $scope: scope, | 157 | $scope: scope, |
| 158 | $uibModal: {}, | 158 | $uibModal: {}, |
| 159 | $location: {}, | 159 | $location: {}, |
| 160 | $filter: filter, | 160 | $filter: filter, |
| 161 | $timeout: timeout, | 161 | $timeout: timeout, |
| 162 | crearNotaPedidoService: { | 162 | crearNotaPedidoService: { |
| 163 | getNumeroNotaPedido: function() { | 163 | getNumeroNotaPedido: function() { |
| 164 | return { | 164 | return { |
| 165 | then: function() { } | 165 | then: function() { } |
| 166 | }; | 166 | }; |
| 167 | }, | 167 | }, |
| 168 | getBotonera: function() { }, | 168 | getBotonera: function() { }, |
| 169 | getCotizacionByIdMoneda: function() { | 169 | getCotizacionByIdMoneda: function() { |
| 170 | return { | 170 | return { |
| 171 | then: function() { } | 171 | then: function() { } |
| 172 | }; | 172 | }; |
| 173 | } | 173 | } |
| 174 | }, | 174 | }, |
| 175 | focaBotoneraLateralService: {}, | 175 | focaBotoneraLateralService: {}, |
| 176 | focaModalService: focaModalService, | 176 | focaModalService: focaModalService, |
| 177 | notaPedidoBusinessService: {}, | 177 | notaPedidoBusinessService: {}, |
| 178 | $rootScope: { | 178 | $rootScope: { |
| 179 | $on: function() { } | 179 | $on: function() { } |
| 180 | }, | 180 | }, |
| 181 | focaSeguimientoService: {}, | 181 | focaSeguimientoService: {}, |
| 182 | APP: {}, | 182 | APP: {}, |
| 183 | focaLoginService: {}, | 183 | focaLoginService: {}, |
| 184 | $localStorage: {} | 184 | $localStorage: {} |
| 185 | }); | 185 | }); |
| 186 | 186 | ||
| 187 | //act | 187 | //act |
| 188 | spyOn(focaModalService, 'alert'); | 188 | spyOn(focaModalService, 'alert'); |
| 189 | scope.idLista = undefined; | 189 | scope.idLista = undefined; |
| 190 | scope.seleccionarProductos(); | 190 | scope.seleccionarProductos(); |
| 191 | 191 | ||
| 192 | //assert | 192 | //assert |
| 193 | expect(focaModalService.alert) | 193 | expect(focaModalService.alert) |
| 194 | .toHaveBeenCalledWith('Primero seleccione una lista de precio y condicion'); | 194 | .toHaveBeenCalledWith('Primero seleccione una lista de precio y condicion'); |
| 195 | }); | 195 | }); |
| 196 | 196 | ||
| 197 | it('función seleccionarProductos abre modal', function() { | 197 | it('función seleccionarProductos abre modal', function() { |
| 198 | //arrange | 198 | //arrange |
| 199 | var scope = { | 199 | var scope = { |
| 200 | $watch: function() { }, | 200 | $watch: function() { }, |
| 201 | $broadcast: function() { } | 201 | $broadcast: function() { } |
| 202 | }; | 202 | }; |
| 203 | var uibModal = { | 203 | var uibModal = { |
| 204 | open: function() { } | 204 | open: function() { } |
| 205 | }; | 205 | }; |
| 206 | 206 | ||
| 207 | $controler('notaPedidoCtrl', { | 207 | $controler('notaPedidoCtrl', { |
| 208 | $scope: scope, | 208 | $scope: scope, |
| 209 | $uibModal: uibModal, | 209 | $uibModal: uibModal, |
| 210 | $location: {}, | 210 | $location: {}, |
| 211 | $filter: filter, | 211 | $filter: filter, |
| 212 | $timeout: timeout, | 212 | $timeout: timeout, |
| 213 | crearNotaPedidoService: { | 213 | crearNotaPedidoService: { |
| 214 | getNumeroNotaPedido: function() { | 214 | getNumeroNotaPedido: function() { |
| 215 | return { | 215 | return { |
| 216 | then: function() { } | 216 | then: function() { } |
| 217 | }; | 217 | }; |
| 218 | }, | 218 | }, |
| 219 | getBotonera: function() { }, | 219 | getBotonera: function() { }, |
| 220 | getCotizacionByIdMoneda: function() { | 220 | getCotizacionByIdMoneda: function() { |
| 221 | return { | 221 | return { |
| 222 | then: function() { } | 222 | then: function() { } |
| 223 | }; | 223 | }; |
| 224 | } | 224 | } |
| 225 | }, | 225 | }, |
| 226 | focaBotoneraLateralService: {}, | 226 | focaBotoneraLateralService: {}, |
| 227 | focaModalService: {}, | 227 | focaModalService: {}, |
| 228 | notaPedidoBusinessService: {}, | 228 | notaPedidoBusinessService: {}, |
| 229 | $rootScope: { | 229 | $rootScope: { |
| 230 | $on: function() { } | 230 | $on: function() { } |
| 231 | }, | 231 | }, |
| 232 | focaSeguimientoService: {}, | 232 | focaSeguimientoService: {}, |
| 233 | APP: {}, | 233 | APP: {}, |
| 234 | focaLoginService: {}, | 234 | focaLoginService: {}, |
| 235 | $localStorage: {} | 235 | $localStorage: {} |
| 236 | }); | 236 | }); |
| 237 | scope.idLista = true; | 237 | scope.idLista = true; |
| 238 | scope.notaPedido = { | 238 | scope.notaPedido = { |
| 239 | cotizacion: { | 239 | cotizacion: { |
| 240 | moneda: {} | 240 | moneda: {} |
| 241 | }, | 241 | }, |
| 242 | 242 | ||
| 243 | }; | 243 | }; |
| 244 | var respuesta = { result: {then: function() { } } }; | 244 | var respuesta = { result: {then: function() { } } }; |
| 245 | 245 | ||
| 246 | //act | 246 | //act |
| 247 | spyOn(uibModal, 'open').and.returnValue(respuesta); | 247 | spyOn(uibModal, 'open').and.returnValue(respuesta); |
| 248 | scope.seleccionarProductos(); | 248 | scope.seleccionarProductos(); |
| 249 | 249 | ||
| 250 | //assert | 250 | //assert |
| 251 | expect(uibModal.open).toHaveBeenCalled(); | 251 | expect(uibModal.open).toHaveBeenCalled(); |
| 252 | }); | 252 | }); |
| 253 | 253 | ||
| 254 | it('función seleccionarPuntosDeDescarga muestra alerta cuando cliente y domicilio son' + | 254 | it('función seleccionarPuntosDeDescarga muestra alerta cuando cliente y domicilio son' + |
| 255 | 'undefined', function() | 255 | 'undefined', function() |
| 256 | { | 256 | { |
| 257 | //arrange | 257 | //arrange |
| 258 | var scope = { | 258 | var scope = { |
| 259 | $watch: function() { }, | 259 | $watch: function() { }, |
| 260 | $broadcast: function() { } | 260 | $broadcast: function() { } |
| 261 | }; | 261 | }; |
| 262 | var focaModalService = { | 262 | var focaModalService = { |
| 263 | alert: function() { } | 263 | alert: function() { } |
| 264 | }; | 264 | }; |
| 265 | 265 | ||
| 266 | $controler('notaPedidoCtrl', { | 266 | $controler('notaPedidoCtrl', { |
| 267 | $scope: scope, | 267 | $scope: scope, |
| 268 | $uibModal: {}, | 268 | $uibModal: {}, |
| 269 | $location: {}, | 269 | $location: {}, |
| 270 | $filter: filter, | 270 | $filter: filter, |
| 271 | $timeout: timeout, | 271 | $timeout: timeout, |
| 272 | crearNotaPedidoService: { | 272 | crearNotaPedidoService: { |
| 273 | getNumeroNotaPedido: function() { | 273 | getNumeroNotaPedido: function() { |
| 274 | return { | 274 | return { |
| 275 | then: function() { } | 275 | then: function() { } |
| 276 | }; | 276 | }; |
| 277 | }, | 277 | }, |
| 278 | getBotonera: function() { }, | 278 | getBotonera: function() { }, |
| 279 | getCotizacionByIdMoneda: function() { | 279 | getCotizacionByIdMoneda: function() { |
| 280 | return { | 280 | return { |
| 281 | then: function() { } | 281 | then: function() { } |
| 282 | }; | 282 | }; |
| 283 | } | 283 | } |
| 284 | }, | 284 | }, |
| 285 | focaBotoneraLateralService: {}, | 285 | focaBotoneraLateralService: {}, |
| 286 | focaModalService: focaModalService, | 286 | focaModalService: focaModalService, |
| 287 | notaPedidoBusinessService: {}, | 287 | notaPedidoBusinessService: {}, |
| 288 | $rootScope: { | 288 | $rootScope: { |
| 289 | $on: function() { } | 289 | $on: function() { } |
| 290 | }, | 290 | }, |
| 291 | focaSeguimientoService: {}, | 291 | focaSeguimientoService: {}, |
| 292 | APP: {}, | 292 | APP: {}, |
| 293 | focaLoginService: {}, | 293 | focaLoginService: {}, |
| 294 | $localStorage: {} | 294 | $localStorage: {} |
| 295 | }); | 295 | }); |
| 296 | scope.idLista = true; | 296 | scope.idLista = true; |
| 297 | scope.notaPedido = { | 297 | scope.notaPedido = { |
| 298 | cliente: { COD: false }, | 298 | cliente: { COD: false }, |
| 299 | domicilio: { id: false} | 299 | domicilio: { id: false} |
| 300 | }; | 300 | }; |
| 301 | 301 | ||
| 302 | //act | 302 | //act |
| 303 | spyOn(focaModalService, 'alert'); | 303 | spyOn(focaModalService, 'alert'); |
| 304 | scope.seleccionarPuntosDeDescarga(); | 304 | scope.seleccionarPuntosDeDescarga(); |
| 305 | 305 | ||
| 306 | //assert | 306 | //assert |
| 307 | expect(focaModalService.alert).toHaveBeenCalled(); | 307 | expect(focaModalService.alert).toHaveBeenCalled(); |
| 308 | }); | 308 | }); |
| 309 | 309 | ||
| 310 | it('función seleccionarPuntosDeDescarga abre modal', function() { | 310 | it('función seleccionarPuntosDeDescarga abre modal', function() { |
| 311 | //arrange | 311 | //arrange |
| 312 | var scope = { | 312 | var scope = { |
| 313 | $watch: function() { }, | 313 | $watch: function() { }, |
| 314 | $broadcast: function() { } | 314 | $broadcast: function() { } |
| 315 | }; | 315 | }; |
| 316 | var uibModal = { | 316 | var uibModal = { |
| 317 | open: function() { } | 317 | open: function() { } |
| 318 | }; | 318 | }; |
| 319 | 319 | ||
| 320 | $controler('notaPedidoCtrl', { | 320 | $controler('notaPedidoCtrl', { |
| 321 | $scope: scope, | 321 | $scope: scope, |
| 322 | $uibModal: uibModal, | 322 | $uibModal: uibModal, |
| 323 | $location: {}, | 323 | $location: {}, |
| 324 | $filter: filter, | 324 | $filter: filter, |
| 325 | $timeout: timeout, | 325 | $timeout: timeout, |
| 326 | crearNotaPedidoService: { | 326 | crearNotaPedidoService: { |
| 327 | getNumeroNotaPedido: function() { | 327 | getNumeroNotaPedido: function() { |
| 328 | return { | 328 | return { |
| 329 | then: function() { } | 329 | then: function() { } |
| 330 | }; | 330 | }; |
| 331 | }, | 331 | }, |
| 332 | getBotonera: function() { }, | 332 | getBotonera: function() { }, |
| 333 | getCotizacionByIdMoneda: function() { | 333 | getCotizacionByIdMoneda: function() { |
| 334 | return { | 334 | return { |
| 335 | then: function() { } | 335 | then: function() { } |
| 336 | }; | 336 | }; |
| 337 | } | 337 | } |
| 338 | }, | 338 | }, |
| 339 | focaBotoneraLateralService: {}, | 339 | focaBotoneraLateralService: {}, |
| 340 | focaModalService: {}, | 340 | focaModalService: {}, |
| 341 | notaPedidoBusinessService: {}, | 341 | notaPedidoBusinessService: {}, |
| 342 | $rootScope: { | 342 | $rootScope: { |
| 343 | $on: function() { } | 343 | $on: function() { } |
| 344 | }, | 344 | }, |
| 345 | focaSeguimientoService: {}, | 345 | focaSeguimientoService: {}, |
| 346 | APP: {}, | 346 | APP: {}, |
| 347 | focaLoginService: {}, | 347 | focaLoginService: {}, |
| 348 | $localStorage: {} | 348 | $localStorage: {} |
| 349 | }); | 349 | }); |
| 350 | scope.idLista = true; | 350 | scope.idLista = true; |
| 351 | scope.notaPedido = { | 351 | scope.notaPedido = { |
| 352 | cliente: { COD: true }, | 352 | cliente: { COD: true }, |
| 353 | domicilio: { id: true } | 353 | domicilio: { id: true } |
| 354 | }; | 354 | }; |
| 355 | var respuesta = { result: { then: function() { } } }; | 355 | var respuesta = { result: { then: function() { } } }; |
| 356 | 356 | ||
| 357 | //act | 357 | //act |
| 358 | spyOn(uibModal, 'open').and.returnValue(respuesta); | 358 | spyOn(uibModal, 'open').and.returnValue(respuesta); |
| 359 | scope.seleccionarPuntosDeDescarga(); | 359 | scope.seleccionarPuntosDeDescarga(); |
| 360 | 360 | ||
| 361 | //assert | 361 | //assert |
| 362 | expect(uibModal.open).toHaveBeenCalled(); | 362 | expect(uibModal.open).toHaveBeenCalled(); |
| 363 | }); | 363 | }); |
| 364 | 364 | ||
| 365 | it('función seleccionarPuntosDeDescarga setea punto elegido', function(done) { | 365 | it('función seleccionarPuntosDeDescarga setea punto elegido', function(done) { |
| 366 | //arrange | 366 | //arrange |
| 367 | var scope = { | 367 | var scope = { |
| 368 | $watch: function() { }, | 368 | $watch: function() { }, |
| 369 | $broadcast: function() { } | 369 | $broadcast: function() { } |
| 370 | }; | 370 | }; |
| 371 | var uibModal = { | 371 | var uibModal = { |
| 372 | open: function() { } | 372 | open: function() { } |
| 373 | }; | 373 | }; |
| 374 | 374 | ||
| 375 | $controler('notaPedidoCtrl', { | 375 | $controler('notaPedidoCtrl', { |
| 376 | $scope: scope, | 376 | $scope: scope, |
| 377 | $uibModal: uibModal, | 377 | $uibModal: uibModal, |
| 378 | $location: {}, | 378 | $location: {}, |
| 379 | $filter: filter, | 379 | $filter: filter, |
| 380 | $timeout: timeout, | 380 | $timeout: timeout, |
| 381 | crearNotaPedidoService: { | 381 | crearNotaPedidoService: { |
| 382 | getNumeroNotaPedido: function() { | 382 | getNumeroNotaPedido: function() { |
| 383 | return { | 383 | return { |
| 384 | then: function() { } | 384 | then: function() { } |
| 385 | }; | 385 | }; |
| 386 | }, | 386 | }, |
| 387 | getBotonera: function() { }, | 387 | getBotonera: function() { }, |
| 388 | getCotizacionByIdMoneda: function() { | 388 | getCotizacionByIdMoneda: function() { |
| 389 | return { | 389 | return { |
| 390 | then: function() { } | 390 | then: function() { } |
| 391 | }; | 391 | }; |
| 392 | } | 392 | } |
| 393 | }, | 393 | }, |
| 394 | focaBotoneraLateralService: {}, | 394 | focaBotoneraLateralService: {}, |
| 395 | focaModalService: {}, | 395 | focaModalService: {}, |
| 396 | notaPedidoBusinessService: {}, | 396 | notaPedidoBusinessService: {}, |
| 397 | $rootScope: { | 397 | $rootScope: { |
| 398 | $on: function() { } | 398 | $on: function() { } |
| 399 | }, | 399 | }, |
| 400 | focaSeguimientoService: {}, | 400 | focaSeguimientoService: {}, |
| 401 | APP: {}, | 401 | APP: {}, |
| 402 | focaLoginService: {}, | 402 | focaLoginService: {}, |
| 403 | $localStorage: {} | 403 | $localStorage: {} |
| 404 | }); | 404 | }); |
| 405 | scope.idLista = true; | 405 | scope.idLista = true; |
| 406 | scope.notaPedido = { | 406 | scope.notaPedido = { |
| 407 | cliente: { COD: true }, | 407 | cliente: { COD: true }, |
| 408 | domicilio: { id: true }, | 408 | domicilio: { id: true }, |
| 409 | puntosDescarga: [] | 409 | puntosDescarga: [] |
| 410 | }; | 410 | }; |
| 411 | var respuesta = []; | 411 | var respuesta = []; |
| 412 | var promiseRespuesta = { result: Promise.resolve(respuesta) }; | 412 | var promiseRespuesta = { result: Promise.resolve(respuesta) }; |
| 413 | scope.$broadcast = function() { }; | 413 | scope.$broadcast = function() { }; |
| 414 | 414 | ||
| 415 | //act | 415 | //act |
| 416 | spyOn(uibModal, 'open').and.returnValue(promiseRespuesta); | 416 | spyOn(uibModal, 'open').and.returnValue(promiseRespuesta); |
| 417 | scope.seleccionarPuntosDeDescarga(); | 417 | scope.seleccionarPuntosDeDescarga(); |
| 418 | 418 | ||
| 419 | //assert | 419 | //assert |
| 420 | promiseRespuesta.result.then(function() { | 420 | promiseRespuesta.result.then(function() { |
| 421 | expect(scope.notaPedido.puntosDescarga).toEqual(respuesta); | 421 | expect(scope.notaPedido.puntosDescarga).toEqual(respuesta); |
| 422 | done(); | 422 | done(); |
| 423 | }); | 423 | }); |
| 424 | }); | 424 | }); |
| 425 | 425 | ||
| 426 | it('función seleccionarVendedor abre modal', function() { | 426 | it('función seleccionarVendedor abre modal', function() { |
| 427 | //arrange | 427 | //arrange |
| 428 | var scope = { | 428 | var scope = { |
| 429 | $watch: function() { }, | 429 | $watch: function() { }, |
| 430 | $broadcast: function() { } | 430 | $broadcast: function() { } |
| 431 | }; | 431 | }; |
| 432 | var focaModalService = { | 432 | var focaModalService = { |
| 433 | modal: function() { } | 433 | modal: function() { } |
| 434 | }; | 434 | }; |
| 435 | 435 | ||
| 436 | $controler('notaPedidoCtrl', { | 436 | $controler('notaPedidoCtrl', { |
| 437 | $scope: scope, | 437 | $scope: scope, |
| 438 | $uibModal: {}, | 438 | $uibModal: {}, |
| 439 | $location: {}, | 439 | $location: {}, |
| 440 | $filter: filter, | 440 | $filter: filter, |
| 441 | $timeout: timeout, | 441 | $timeout: timeout, |
| 442 | crearNotaPedidoService: { | 442 | crearNotaPedidoService: { |
| 443 | getNumeroNotaPedido: function() { | 443 | getNumeroNotaPedido: function() { |
| 444 | return { | 444 | return { |
| 445 | then: function() { } | 445 | then: function() { } |
| 446 | }; | 446 | }; |
| 447 | }, | 447 | }, |
| 448 | getBotonera: function() { }, | 448 | getBotonera: function() { }, |
| 449 | getCotizacionByIdMoneda: function() { | 449 | getCotizacionByIdMoneda: function() { |
| 450 | return { | 450 | return { |
| 451 | then: function() { } | 451 | then: function() { } |
| 452 | }; | 452 | }; |
| 453 | } | 453 | } |
| 454 | }, | 454 | }, |
| 455 | focaBotoneraLateralService: {}, | 455 | focaBotoneraLateralService: {}, |
| 456 | focaModalService: focaModalService, | 456 | focaModalService: focaModalService, |
| 457 | notaPedidoBusinessService: {}, | 457 | notaPedidoBusinessService: {}, |
| 458 | $rootScope: { | 458 | $rootScope: { |
| 459 | $on: function() { } | 459 | $on: function() { } |
| 460 | }, | 460 | }, |
| 461 | focaSeguimientoService: {}, | 461 | focaSeguimientoService: {}, |
| 462 | APP: {}, | 462 | APP: {}, |
| 463 | focaLoginService: {}, | 463 | focaLoginService: {}, |
| 464 | $localStorage: {} | 464 | $localStorage: {} |
| 465 | }); | 465 | }); |
| 466 | scope.idLista = true; | 466 | scope.idLista = true; |
| 467 | scope.notaPedido = { | 467 | scope.notaPedido = { |
| 468 | cliente: { COD: true }, | 468 | cliente: { COD: true }, |
| 469 | domicilio: { id: true } | 469 | domicilio: { id: true } |
| 470 | }; | 470 | }; |
| 471 | 471 | ||
| 472 | var respuesta = { then: function() { } }; | 472 | var respuesta = { then: function() { } }; |
| 473 | 473 | ||
| 474 | //act | 474 | //act |
| 475 | spyOn(focaModalService, 'modal').and.returnValue(respuesta); | 475 | spyOn(focaModalService, 'modal').and.returnValue(respuesta); |
| 476 | scope.seleccionarVendedor(); | 476 | scope.seleccionarVendedor(); |
| 477 | 477 | ||
| 478 | //assert | 478 | //assert |
| 479 | expect(focaModalService.modal).toHaveBeenCalled(); | 479 | expect(focaModalService.modal).toHaveBeenCalled(); |
| 480 | }); | 480 | }); |
| 481 | 481 | ||
| 482 | it('función seleccionarVendedor setea vendedor y cabecera', function(done) { | 482 | it('función seleccionarVendedor setea vendedor y cabecera', function(done) { |
| 483 | //arrange | 483 | //arrange |
| 484 | var scope = { | 484 | var scope = { |
| 485 | $watch: function() { }, | 485 | $watch: function() { }, |
| 486 | $broadcast: function() { } | 486 | $broadcast: function() { } |
| 487 | }; | 487 | }; |
| 488 | var focaModalService = { | 488 | var focaModalService = { |
| 489 | modal: function() { } | 489 | modal: function() { } |
| 490 | }; | 490 | }; |
| 491 | 491 | ||
| 492 | $controler('notaPedidoCtrl', { | 492 | $controler('notaPedidoCtrl', { |
| 493 | $scope: scope, | 493 | $scope: scope, |
| 494 | $uibModal: {}, | 494 | $uibModal: {}, |
| 495 | $location: {}, | 495 | $location: {}, |
| 496 | $filter: filter, | 496 | $filter: filter, |
| 497 | $timeout: timeout, | 497 | $timeout: timeout, |
| 498 | crearNotaPedidoService: { | 498 | crearNotaPedidoService: { |
| 499 | getNumeroNotaPedido: function() { | 499 | getNumeroNotaPedido: function() { |
| 500 | return { | 500 | return { |
| 501 | then: function() { } | 501 | then: function() { } |
| 502 | }; | 502 | }; |
| 503 | }, | 503 | }, |
| 504 | getBotonera: function() { }, | 504 | getBotonera: function() { }, |
| 505 | getCotizacionByIdMoneda: function() { | 505 | getCotizacionByIdMoneda: function() { |
| 506 | return { | 506 | return { |
| 507 | then: function() { } | 507 | then: function() { } |
| 508 | }; | 508 | }; |
| 509 | } | 509 | } |
| 510 | }, | 510 | }, |
| 511 | focaBotoneraLateralService: {}, | 511 | focaBotoneraLateralService: {}, |
| 512 | focaModalService: focaModalService, | 512 | focaModalService: focaModalService, |
| 513 | notaPedidoBusinessService: {}, | 513 | notaPedidoBusinessService: {}, |
| 514 | $rootScope: { | 514 | $rootScope: { |
| 515 | $on: function() { } | 515 | $on: function() { } |
| 516 | }, | 516 | }, |
| 517 | focaSeguimientoService: {}, | 517 | focaSeguimientoService: {}, |
| 518 | APP: {}, | 518 | APP: {}, |
| 519 | focaLoginService: {}, | 519 | focaLoginService: {}, |
| 520 | $localStorage: {} | 520 | $localStorage: {} |
| 521 | }); | 521 | }); |
| 522 | scope.idLista = true; | 522 | scope.idLista = true; |
| 523 | scope.notaPedido = { | 523 | scope.notaPedido = { |
| 524 | cliente: { COD: true }, | 524 | cliente: { COD: true }, |
| 525 | domicilio: { id: true } | 525 | domicilio: { id: true } |
| 526 | }; | 526 | }; |
| 527 | var respuesta = {}; | 527 | var respuesta = {}; |
| 528 | var promesaRespuesta = Promise.resolve(respuesta); | 528 | var promesaRespuesta = Promise.resolve(respuesta); |
| 529 | scope.$broadcast = function() { }; | 529 | scope.$broadcast = function() { }; |
| 530 | 530 | ||
| 531 | //act | 531 | //act |
| 532 | spyOn(focaModalService, 'modal').and.returnValue(promesaRespuesta); | 532 | spyOn(focaModalService, 'modal').and.returnValue(promesaRespuesta); |
| 533 | spyOn(scope, '$broadcast'); | 533 | spyOn(scope, '$broadcast'); |
| 534 | scope.seleccionarVendedor(); | 534 | scope.seleccionarVendedor(); |
| 535 | 535 | ||
| 536 | //assert | 536 | //assert |
| 537 | promesaRespuesta.then(function() { | 537 | promesaRespuesta.then(function() { |
| 538 | expect(scope.notaPedido.vendedor).toEqual(respuesta); | 538 | expect(scope.notaPedido.vendedor).toEqual(respuesta); |
| 539 | expect(scope.$broadcast).toHaveBeenCalled(); | 539 | expect(scope.$broadcast).toHaveBeenCalled(); |
| 540 | done(); | 540 | done(); |
| 541 | }); | 541 | }); |
| 542 | }); | 542 | }); |
| 543 | 543 | ||
| 544 | it('función seleccionarProveedor abre modal', function() { | 544 | it('función seleccionarProveedor abre modal', function() { |
| 545 | //arrange | 545 | //arrange |
| 546 | var scope = { | 546 | var scope = { |
| 547 | $watch: function() { }, | 547 | $watch: function() { }, |
| 548 | $broadcast: function() { } | 548 | $broadcast: function() { } |
| 549 | }; | 549 | }; |
| 550 | var focaModalService = { | 550 | var focaModalService = { |
| 551 | modal: function() { } | 551 | modal: function() { } |
| 552 | }; | 552 | }; |
| 553 | 553 | ||
| 554 | $controler('notaPedidoCtrl', { | 554 | $controler('notaPedidoCtrl', { |
| 555 | $scope: scope, | 555 | $scope: scope, |
| 556 | $uibModal: {}, | 556 | $uibModal: {}, |
| 557 | $location: {}, | 557 | $location: {}, |
| 558 | $filter: filter, | 558 | $filter: filter, |
| 559 | $timeout: timeout, | 559 | $timeout: timeout, |
| 560 | crearNotaPedidoService: { | 560 | crearNotaPedidoService: { |
| 561 | getNumeroNotaPedido: function() { | 561 | getNumeroNotaPedido: function() { |
| 562 | return { | 562 | return { |
| 563 | then: function() { } | 563 | then: function() { } |
| 564 | }; | 564 | }; |
| 565 | }, | 565 | }, |
| 566 | getBotonera: function() { }, | 566 | getBotonera: function() { }, |
| 567 | getCotizacionByIdMoneda: function() { | 567 | getCotizacionByIdMoneda: function() { |
| 568 | return { | 568 | return { |
| 569 | then: function() { } | 569 | then: function() { } |
| 570 | }; | 570 | }; |
| 571 | } | 571 | } |
| 572 | }, | 572 | }, |
| 573 | focaBotoneraLateralService: {}, | 573 | focaBotoneraLateralService: {}, |
| 574 | focaModalService: focaModalService, | 574 | focaModalService: focaModalService, |
| 575 | notaPedidoBusinessService: {}, | 575 | notaPedidoBusinessService: {}, |
| 576 | $rootScope: { | 576 | $rootScope: { |
| 577 | $on: function() { } | 577 | $on: function() { } |
| 578 | }, | 578 | }, |
| 579 | focaSeguimientoService: {}, | 579 | focaSeguimientoService: {}, |
| 580 | APP: {}, | 580 | APP: {}, |
| 581 | focaLoginService: {}, | 581 | focaLoginService: {}, |
| 582 | $localStorage: {} | 582 | $localStorage: {} |
| 583 | }); | 583 | }); |
| 584 | scope.notaPedido = {}; | 584 | scope.notaPedido = {}; |
| 585 | 585 | ||
| 586 | var respuesta = { then: function() { } }; | 586 | var respuesta = { then: function() { } }; |
| 587 | 587 | ||
| 588 | //act | 588 | //act |
| 589 | spyOn(focaModalService, 'modal').and.returnValue(respuesta); | 589 | spyOn(focaModalService, 'modal').and.returnValue(respuesta); |
| 590 | scope.seleccionarProveedor(); | 590 | scope.seleccionarProveedor(); |
| 591 | 591 | ||
| 592 | //assert | 592 | //assert |
| 593 | expect(focaModalService.modal).toHaveBeenCalled(); | 593 | expect(focaModalService.modal).toHaveBeenCalled(); |
| 594 | }); | 594 | }); |
| 595 | 595 | ||
| 596 | it('función seleccionarProveedor setea vendedor y cabecera', function(done) { | 596 | it('función seleccionarProveedor setea vendedor y cabecera', function(done) { |
| 597 | //arrange | 597 | //arrange |
| 598 | var scope = { | 598 | var scope = { |
| 599 | $watch: function() { }, | 599 | $watch: function() { }, |
| 600 | $broadcast: function() { } | 600 | $broadcast: function() { } |
| 601 | }; | 601 | }; |
| 602 | var focaModalService = { | 602 | var focaModalService = { |
| 603 | modal: function() { } | 603 | modal: function() { } |
| 604 | }; | 604 | }; |
| 605 | 605 | ||
| 606 | $controler('notaPedidoCtrl', { | 606 | $controler('notaPedidoCtrl', { |
| 607 | $scope: scope, | 607 | $scope: scope, |
| 608 | $uibModal: {}, | 608 | $uibModal: {}, |
| 609 | $location: {}, | 609 | $location: {}, |
| 610 | $filter: filter, | 610 | $filter: filter, |
| 611 | $timeout: timeout, | 611 | $timeout: timeout, |
| 612 | crearNotaPedidoService: { | 612 | crearNotaPedidoService: { |
| 613 | getNumeroNotaPedido: function() { | 613 | getNumeroNotaPedido: function() { |
| 614 | return { | 614 | return { |
| 615 | then: function() { } | 615 | then: function() { } |
| 616 | }; | 616 | }; |
| 617 | }, | 617 | }, |
| 618 | getBotonera: function() { }, | 618 | getBotonera: function() { }, |
| 619 | getCotizacionByIdMoneda: function() { | 619 | getCotizacionByIdMoneda: function() { |
| 620 | return { | 620 | return { |
| 621 | then: function() { } | 621 | then: function() { } |
| 622 | }; | 622 | }; |
| 623 | } | 623 | } |
| 624 | }, | 624 | }, |
| 625 | focaBotoneraLateralService: {}, | 625 | focaBotoneraLateralService: {}, |
| 626 | focaModalService: focaModalService, | 626 | focaModalService: focaModalService, |
| 627 | notaPedidoBusinessService: {}, | 627 | notaPedidoBusinessService: {}, |
| 628 | $rootScope: { | 628 | $rootScope: { |
| 629 | $on: function() { } | 629 | $on: function() { } |
| 630 | }, | 630 | }, |
| 631 | focaSeguimientoService: {}, | 631 | focaSeguimientoService: {}, |
| 632 | APP: {}, | 632 | APP: {}, |
| 633 | focaLoginService: {}, | 633 | focaLoginService: {}, |
| 634 | $localStorage: {} | 634 | $localStorage: {} |
| 635 | }); | 635 | }); |
| 636 | 636 | ||
| 637 | scope.notaPedido = {}; | 637 | scope.notaPedido = {}; |
| 638 | var respuesta = {}; | 638 | var respuesta = {}; |
| 639 | var promesaRespuesta = Promise.resolve(respuesta); | 639 | var promesaRespuesta = Promise.resolve(respuesta); |
| 640 | scope.$broadcast = function() { }; | 640 | scope.$broadcast = function() { }; |
| 641 | 641 | ||
| 642 | //act | 642 | //act |
| 643 | spyOn(focaModalService, 'modal').and.returnValue(promesaRespuesta); | 643 | spyOn(focaModalService, 'modal').and.returnValue(promesaRespuesta); |
| 644 | spyOn(scope, '$broadcast'); | 644 | spyOn(scope, '$broadcast'); |
| 645 | scope.seleccionarProveedor(); | 645 | scope.seleccionarProveedor(); |
| 646 | 646 | ||
| 647 | //assert | 647 | //assert |
| 648 | promesaRespuesta.then(function() { | 648 | promesaRespuesta.then(function() { |
| 649 | expect(scope.notaPedido.proveedor).toEqual(respuesta); | 649 | expect(scope.notaPedido.proveedor).toEqual(respuesta); |
| 650 | expect(scope.$broadcast).toHaveBeenCalled(); | 650 | expect(scope.$broadcast).toHaveBeenCalled(); |
| 651 | done(); | 651 | done(); |
| 652 | }); | 652 | }); |
| 653 | }); | 653 | }); |
| 654 | 654 | ||
| 655 | it('función seleccionarCliente abre alerta cuando no se elije vendedor', function() { | ||
| 656 | //arrange | ||
| 657 | var scope = { | ||
| 658 | $watch: function() { }, | ||
| 659 | $broadcast: function() { } | ||
| 660 | }; | ||
| 661 | var focaModalService = { | ||
| 662 | alert: function() { } | ||
| 663 | }; | ||
| 664 | |||
| 665 | $controler('notaPedidoCtrl', { | ||
| 666 | $scope: scope, | ||
| 667 | $uibModal: {}, | ||
| 668 | $location: {}, | ||
| 669 | $filter: filter, | ||
| 670 | $timeout: timeout, | ||
| 671 | crearNotaPedidoService: { | ||
| 672 | getNumeroNotaPedido: function() { | ||
| 673 | return { | ||
| 674 | then: function() { } | ||
| 675 | }; | ||
| 676 | }, | ||
| 677 | getBotonera: function() { }, | ||
| 678 | getCotizacionByIdMoneda: function() { | ||
| 679 | return { | ||
| 680 | then: function() { } | ||
| 681 | }; | ||
| 682 | } | ||
| 683 | }, | ||
| 684 | focaBotoneraLateralService: {}, | ||
| 685 | focaModalService: focaModalService, | ||
| 686 | notaPedidoBusinessService: {}, | ||
| 687 | $rootScope: { | ||
| 688 | $on: function() { } | ||
| 689 | }, | ||
| 690 | focaSeguimientoService: {}, | ||
| 691 | APP: {}, | ||
| 692 | focaLoginService: {}, | ||
| 693 | $localStorage: {} | ||
| 694 | }); | ||
| 695 | scope.notaPedido = { | ||
| 696 | vendedor: { NUM: false } | ||
| 697 | }; | ||
| 698 | |||
| 699 | //act | ||
| 700 | spyOn(focaModalService, 'alert'); | ||
| 701 | scope.seleccionarCliente(); | ||
| 702 | |||
| 703 | //assert | ||
| 704 | expect(focaModalService.alert).toHaveBeenCalledWith('Primero seleccione un vendedor'); | ||
| 705 | }); | ||
| 706 | |||
| 707 | it('función seleccionarCliente abre modal', function() { | 655 | it('función seleccionarCliente abre modal', function() { |
| 708 | //arrange | 656 | //arrange |
| 709 | var scope = { | 657 | var scope = { |
| 710 | $watch: function() { }, | 658 | $watch: function() { }, |
| 711 | $broadcast: function() { } | 659 | $broadcast: function() { } |
| 712 | }; | 660 | }; |
| 713 | var uibModal = { | 661 | var uibModal = { |
| 714 | open: function() { } | 662 | open: function() { } |
| 715 | }; | 663 | }; |
| 716 | 664 | ||
| 717 | $controler('notaPedidoCtrl', { | 665 | $controler('notaPedidoCtrl', { |
| 718 | $scope: scope, | 666 | $scope: scope, |
| 719 | $uibModal: uibModal, | 667 | $uibModal: uibModal, |
| 720 | $location: {}, | 668 | $location: {}, |
| 721 | $filter: filter, | 669 | $filter: filter, |
| 722 | $timeout: timeout, | 670 | $timeout: timeout, |
| 723 | crearNotaPedidoService: { | 671 | crearNotaPedidoService: { |
| 724 | getNumeroNotaPedido: function() { | 672 | getNumeroNotaPedido: function() { |
| 725 | return { | 673 | return { |
| 726 | then: function() { } | 674 | then: function() { } |
| 727 | }; | 675 | }; |
| 728 | }, | 676 | }, |
| 729 | getBotonera: function() { }, | 677 | getBotonera: function() { }, |
| 730 | getCotizacionByIdMoneda: function() { | 678 | getCotizacionByIdMoneda: function() { |
| 731 | return { | 679 | return { |
| 732 | then: function() { } | 680 | then: function() { } |
| 733 | }; | 681 | }; |
| 682 | }, | ||
| 683 | getVendedorById: function() { | ||
| 684 | return { | ||
| 685 | then: function() { } | ||
| 686 | }; | ||
| 734 | } | 687 | } |
| 735 | }, | 688 | }, |
| 736 | focaBotoneraLateralService: {}, | 689 | focaBotoneraLateralService: {}, |
| 737 | focaModalService: {}, | 690 | focaModalService: { |
| 691 | modal: function() { | ||
| 692 | return { | ||
| 693 | then: function() {} | ||
| 694 | }; | ||
| 695 | } | ||
| 696 | }, | ||
| 738 | notaPedidoBusinessService: {}, | 697 | notaPedidoBusinessService: {}, |
| 739 | $rootScope: { | 698 | $rootScope: { |
| 740 | $on: function() { } | 699 | $on: function() { } |
| 741 | }, | 700 | }, |
| 742 | focaSeguimientoService: {}, | 701 | focaSeguimientoService: {}, |
| 743 | APP: {}, | 702 | APP: 'distribuidor', |
| 744 | focaLoginService: {}, | 703 | focaLoginService: { |
| 704 | getLoginData: function() { | ||
| 705 | return { | ||
| 706 | vendedorCorbrador: true | ||
| 707 | } | ||
| 708 | } | ||
| 709 | }, | ||
| 745 | $localStorage: {} | 710 | $localStorage: {} |
| 746 | }); | 711 | }); |
| 747 | scope.notaPedido = { | 712 | scope.notaPedido = { |
| 748 | vendedor: { NUM: true } | 713 | vendedor: { NUM: true } |
| 749 | }; | 714 | }; |
| 750 | 715 | ||
| 751 | var respuesta = { result: {then: function() { } } }; | 716 | var respuesta = { result: {then: function() { } } }; |
| 752 | 717 | ||
| 753 | //act | 718 | //act |
| 754 | spyOn(uibModal, 'open').and.returnValue(respuesta); | 719 | spyOn(uibModal, 'open').and.returnValue(respuesta); |
| 755 | scope.seleccionarCliente(); | 720 | scope.seleccionarCliente(); |
| 756 | 721 | ||
| 757 | //assert | 722 | //assert |
| 758 | expect(uibModal.open).toHaveBeenCalled(); | 723 | expect(uibModal.open).toHaveBeenCalled(); |
| 759 | }); | 724 | }); |
| 760 | 725 | ||
| 761 | it('función seleccionarCliente setea vendedor y llama a domicilios', function(done) { | 726 | it('función seleccionarCliente setea vendedor y llama a domicilios', function(done) { |
| 762 | 727 | ||
| 763 | //arrange | 728 | //arrange |
| 764 | var scope = { | 729 | var scope = { |
| 765 | $watch: function() { }, | 730 | $watch: function() { }, |
| 766 | $broadcast: function() { } | 731 | $broadcast: function() { }, |
| 732 | seleccionarVendedor: function() { }, | ||
| 733 | notaPedido: {} | ||
| 767 | }; | 734 | }; |
| 768 | var uibModal = { | 735 | var uibModal = { |
| 769 | open: function() { } | 736 | open: function() { } |
| 770 | }; | 737 | }; |
| 771 | 738 | ||
| 772 | $controler('notaPedidoCtrl', { | 739 | $controler('notaPedidoCtrl', { |
| 773 | $scope: scope, | 740 | $scope: scope, |
| 774 | $uibModal: uibModal, | 741 | $uibModal: uibModal, |
| 775 | $location: {}, | 742 | $location: {}, |
| 776 | $filter: filter, | 743 | $filter: filter, |
| 777 | $timeout: timeout, | 744 | $timeout: timeout, |
| 778 | crearNotaPedidoService: { | 745 | crearNotaPedidoService: { |
| 779 | getNumeroNotaPedido: function() { | 746 | getNumeroNotaPedido: function() { |
| 780 | return { | 747 | return { |
| 781 | then: function() { } | 748 | then: function() { } |
| 782 | }; | 749 | }; |
| 783 | }, | 750 | }, |
| 784 | getBotonera: function() { }, | 751 | getBotonera: function() { }, |
| 785 | getCotizacionByIdMoneda: function() { | 752 | getCotizacionByIdMoneda: function() { |
| 786 | return { | 753 | return { |
| 787 | then: function() { } | 754 | then: function() { } |
| 788 | }; | 755 | }; |
| 756 | }, | ||
| 757 | getVendedorById : function() { | ||
| 758 | return { | ||
| 759 | then: function() { } | ||
| 760 | } | ||
| 789 | } | 761 | } |
| 790 | }, | 762 | }, |
| 791 | focaBotoneraLateralService: {}, | 763 | focaBotoneraLateralService: {}, |
| 792 | focaModalService: {}, | 764 | focaModalService: { |
| 765 | modal: function() { | ||
| 766 | return { | ||
| 767 | then: function() { } | ||
| 768 | }; | ||
| 769 | } | ||
| 770 | }, | ||
| 793 | notaPedidoBusinessService: {}, | 771 | notaPedidoBusinessService: {}, |
| 794 | $rootScope: { | 772 | $rootScope: { |
| 795 | $on: function() { } | 773 | $on: function() { } |
| 796 | }, | 774 | }, |
| 797 | focaSeguimientoService: {}, | 775 | focaSeguimientoService: {}, |
| 798 | APP: {}, | 776 | APP: 'distribuidor', |
| 799 | focaLoginService: {}, | 777 | focaLoginService: { |
| 778 | getLoginData: function() { | ||
| 779 | return { | ||
| 780 | vendedorCorbrador: true | ||
| 781 | }; | ||
| 782 | } | ||
| 783 | }, | ||
| 800 | $localStorage: {} | 784 | $localStorage: {} |
| 801 | }); | 785 | }); |
| 802 | scope.idLista = true; | 786 | scope.idLista = true; |
| 803 | scope.notaPedido = { | 787 | scope.notaPedido = { |
| 804 | vendedor: { NUM: true } | 788 | vendedor: { NUM: true } |
| 805 | }; | 789 | }; |
| 806 | var respuesta = {}; | 790 | var respuesta = {}; |
| 807 | var promesaRespuesta = { result: Promise.resolve(respuesta) }; | 791 | var promesaRespuesta = { result: Promise.resolve(respuesta) }; |
| 808 | 792 | ||
| 809 | //act | 793 | //act |
| 810 | spyOn(uibModal, 'open').and.returnValue(promesaRespuesta); | 794 | spyOn(uibModal, 'open').and.returnValue(promesaRespuesta); |
| 811 | spyOn(scope, 'abrirModalDomicilios'); | 795 | spyOn(scope, 'abrirModalDomicilios'); |
| 812 | scope.seleccionarCliente(); | 796 | scope.seleccionarCliente(); |
| 813 | 797 | ||
| 814 | //assert | 798 | //assert |
| 815 | promesaRespuesta.result.then(function() { | 799 | promesaRespuesta.result.then(function() { |
| 816 | expect(scope.cliente).toEqual(respuesta); | 800 | expect(scope.cliente).toEqual(respuesta); |
| 817 | expect(scope.abrirModalDomicilios).toHaveBeenCalled(); | 801 | expect(scope.abrirModalDomicilios).toHaveBeenCalled(); |
| 818 | done(); | 802 | done(); |
| 819 | }); | 803 | }); |
| 820 | }); | 804 | }); |
| 821 | 805 | ||
| 822 | it('función abrirModalDomicilios abre modal', function() { | 806 | it('función abrirModalDomicilios abre modal', function() { |
| 823 | //arrange | 807 | //arrange |
| 824 | var scope = { | 808 | var scope = { |
| 825 | $watch: function() { }, | 809 | $watch: function() { }, |
| 826 | $broadcast: function() { } | 810 | $broadcast: function() { } |
| 827 | }; | 811 | }; |
| 828 | var uibModal = { | 812 | var uibModal = { |
| 829 | open: function() { } | 813 | open: function() { } |
| 830 | }; | 814 | }; |
| 831 | 815 | ||
| 832 | $controler('notaPedidoCtrl', { | 816 | $controler('notaPedidoCtrl', { |
| 833 | $scope: scope, | 817 | $scope: scope, |
| 834 | $uibModal: uibModal, | 818 | $uibModal: uibModal, |
| 835 | $location: {}, | 819 | $location: {}, |
| 836 | $filter: filter, | 820 | $filter: filter, |
| 837 | $timeout: timeout, | 821 | $timeout: timeout, |
| 838 | crearNotaPedidoService: { | 822 | crearNotaPedidoService: { |
| 839 | getNumeroNotaPedido: function() { | 823 | getNumeroNotaPedido: function() { |
| 840 | return { | 824 | return { |
| 841 | then: function() { } | 825 | then: function() { } |
| 842 | }; | 826 | }; |
| 843 | }, | 827 | }, |
| 844 | getBotonera: function() { }, | 828 | getBotonera: function() { }, |
| 845 | getCotizacionByIdMoneda: function() { | 829 | getCotizacionByIdMoneda: function() { |
| 846 | return { | 830 | return { |
| 847 | then: function() { } | 831 | then: function() { } |
| 848 | }; | 832 | }; |
| 849 | } | 833 | } |
| 850 | }, | 834 | }, |
| 851 | focaBotoneraLateralService: {}, | 835 | focaBotoneraLateralService: {}, |
| 852 | focaModalService: {}, | 836 | focaModalService: {}, |
| 853 | notaPedidoBusinessService: {}, | 837 | notaPedidoBusinessService: {}, |
| 854 | $rootScope: { | 838 | $rootScope: { |
| 855 | $on: function() { } | 839 | $on: function() { } |
| 856 | }, | 840 | }, |
| 857 | focaSeguimientoService: {}, | 841 | focaSeguimientoService: {}, |
| 858 | APP: {}, | 842 | APP: {}, |
| 859 | focaLoginService: {}, | 843 | focaLoginService: {}, |
| 860 | $localStorage: {} | 844 | $localStorage: {} |
| 861 | }); | 845 | }); |
| 862 | 846 | ||
| 863 | var respuesta = { result: {then: function() { } } }; | 847 | var respuesta = { result: {then: function() { } } }; |
| 864 | 848 | ||
| 865 | //act | 849 | //act |
| 866 | spyOn(uibModal, 'open').and.returnValue(respuesta); | 850 | spyOn(uibModal, 'open').and.returnValue(respuesta); |
| 867 | scope.abrirModalDomicilios(); | 851 | scope.abrirModalDomicilios(); |
| 868 | 852 | ||
| 869 | //assert | 853 | //assert |
| 870 | expect(uibModal.open).toHaveBeenCalled(); | 854 | expect(uibModal.open).toHaveBeenCalled(); |
| 871 | }); | 855 | }); |
| 872 | 856 | ||
| 873 | it('función abrirModalDomicilios setea domicilio, cliente y cabeceras', function(done) { | 857 | it('función abrirModalDomicilios setea domicilio, cliente y cabeceras', function(done) { |
| 874 | 858 | ||
| 875 | //arrange | 859 | //arrange |
| 876 | var scope = { | 860 | var scope = { |
| 877 | $watch: function() { }, | 861 | $watch: function() { }, |
| 878 | $broadcast: function() { } | 862 | $broadcast: function() { } |
| 879 | }; | 863 | }; |
| 880 | var uibModal = { | 864 | var uibModal = { |
| 881 | open: function() { } | 865 | open: function() { } |
| 882 | }; | 866 | }; |
| 883 | 867 | ||
| 884 | $controler('notaPedidoCtrl', { | 868 | $controler('notaPedidoCtrl', { |
| 885 | $scope: scope, | 869 | $scope: scope, |
| 886 | $uibModal: uibModal, | 870 | $uibModal: uibModal, |
| 887 | $location: {}, | 871 | $location: {}, |
| 888 | $filter: filter, | 872 | $filter: filter, |
| 889 | $timeout: timeout, | 873 | $timeout: timeout, |
| 890 | crearNotaPedidoService: { | 874 | crearNotaPedidoService: { |
| 891 | getNumeroNotaPedido: function() { | 875 | getNumeroNotaPedido: function() { |
| 892 | return { | 876 | return { |
| 893 | then: function() { } | 877 | then: function() { } |
| 894 | }; | 878 | }; |
| 895 | }, | 879 | }, |
| 896 | getBotonera: function() { }, | 880 | getBotonera: function() { }, |
| 897 | getCotizacionByIdMoneda: function() { | 881 | getCotizacionByIdMoneda: function() { |
| 898 | return { | 882 | return { |
| 899 | then: function() { } | 883 | then: function() { } |
| 900 | }; | 884 | }; |
| 901 | }, | 885 | }, |
| 902 | getPuntosDescargaByClienDom: function() { | 886 | getPuntosDescargaByClienDom: function() { |
| 903 | return { | 887 | return { |
| 904 | then: function() { } | 888 | then: function() { } |
| 905 | }; | 889 | }; |
| 906 | } | 890 | } |
| 907 | }, | 891 | }, |
| 908 | focaBotoneraLateralService: {}, | 892 | focaBotoneraLateralService: {}, |
| 909 | focaModalService: {}, | 893 | focaModalService: {}, |
| 910 | notaPedidoBusinessService: {}, | 894 | notaPedidoBusinessService: {}, |
| 911 | $rootScope: { | 895 | $rootScope: { |
| 912 | $on: function() { } | 896 | $on: function() { } |
| 913 | }, | 897 | }, |
| 914 | focaSeguimientoService: {}, | 898 | focaSeguimientoService: {}, |
| 915 | APP: {}, | 899 | APP: {}, |
| 916 | focaLoginService: {}, | 900 | focaLoginService: {}, |
| 917 | $localStorage: {} | 901 | $localStorage: {} |
| 918 | }); | 902 | }); |
| 919 | scope.idLista = true; | 903 | scope.idLista = true; |
| 920 | scope.notaPedido = { | 904 | scope.notaPedido = { |
| 921 | vendedor: { NUM: true } | 905 | vendedor: { NUM: true } |
| 922 | }; | 906 | }; |
| 923 | var respuesta = {}; | 907 | var respuesta = {}; |
| 924 | var promesaRespuesta = { result: Promise.resolve(respuesta) }; | 908 | var promesaRespuesta = { result: Promise.resolve(respuesta) }; |
| 925 | scope.$broadcast = function() { }; | 909 | scope.$broadcast = function() { }; |
| 926 | var cliente = { | 910 | var cliente = { |
| 927 | COD: undefined, | 911 | COD: undefined, |
| 928 | CUIT: undefined, | 912 | CUIT: undefined, |
| 929 | NOM: undefined | 913 | NOM: undefined |
| 930 | }; | 914 | }; |
| 931 | 915 | ||
| 932 | //act | 916 | //act |
| 933 | spyOn(uibModal, 'open').and.returnValue(promesaRespuesta); | 917 | spyOn(uibModal, 'open').and.returnValue(promesaRespuesta); |
| 934 | spyOn(scope, '$broadcast'); | 918 | spyOn(scope, '$broadcast'); |
| 935 | scope.abrirModalDomicilios({ }); | 919 | scope.abrirModalDomicilios({ }); |
| 936 | 920 | ||
| 937 | //assert | 921 | //assert |
| 938 | promesaRespuesta.result.then(function() { | 922 | promesaRespuesta.result.then(function() { |
| 939 | expect(scope.notaPedido.domicilio).toEqual(respuesta); | 923 | expect(scope.notaPedido.domicilio).toEqual(respuesta); |
| 940 | expect(scope.notaPedido.cliente).toEqual(cliente); | 924 | expect(scope.notaPedido.cliente).toEqual(cliente); |
| 941 | expect(scope.$broadcast).toHaveBeenCalled(); | 925 | expect(scope.$broadcast).toHaveBeenCalled(); |
| 942 | done(); | 926 | done(); |
| 943 | }); | 927 | }); |
| 944 | }); | 928 | }); |
| 945 | 929 | ||
| 946 | it('función getTotal devulve correctamente', function() { | 930 | it('función getTotal devulve correctamente', function() { |
| 947 | 931 | ||
| 948 | //arrange | 932 | //arrange |
| 949 | var scope = { | 933 | var scope = { |
| 950 | $watch: function() { }, | 934 | $watch: function() { }, |
| 951 | $broadcast: function() { } | 935 | $broadcast: function() { } |
| 952 | }; | 936 | }; |
| 953 | 937 | ||
| 954 | $controler('notaPedidoCtrl', { | 938 | $controler('notaPedidoCtrl', { |
| 955 | $scope: scope, | 939 | $scope: scope, |
| 956 | $uibModal: {}, | 940 | $uibModal: {}, |
| 957 | $location: {}, | 941 | $location: {}, |
| 958 | $filter: filter, | 942 | $filter: filter, |
| 959 | $timeout: timeout, | 943 | $timeout: timeout, |
| 960 | crearNotaPedidoService: { | 944 | crearNotaPedidoService: { |
| 961 | getNumeroNotaPedido: function() { | 945 | getNumeroNotaPedido: function() { |
| 962 | return { | 946 | return { |
| 963 | then: function() { } | 947 | then: function() { } |
| 964 | }; | 948 | }; |
| 965 | }, | 949 | }, |
| 966 | getBotonera: function() { }, | 950 | getBotonera: function() { }, |
| 967 | getCotizacionByIdMoneda: function() { | 951 | getCotizacionByIdMoneda: function() { |
| 968 | return { | 952 | return { |
| 969 | then: function() { } | 953 | then: function() { } |
| 970 | }; | 954 | }; |
| 971 | } | 955 | } |
| 972 | }, | 956 | }, |
| 973 | focaBotoneraLateralService: {}, | 957 | focaBotoneraLateralService: {}, |
| 974 | focaModalService: {}, | 958 | focaModalService: {}, |
| 975 | notaPedidoBusinessService: {}, | 959 | notaPedidoBusinessService: {}, |
| 976 | $rootScope: { | 960 | $rootScope: { |
| 977 | $on: function() { } | 961 | $on: function() { } |
| 978 | }, | 962 | }, |
| 979 | focaSeguimientoService: {}, | 963 | focaSeguimientoService: {}, |
| 980 | APP: {}, | 964 | APP: {}, |
| 981 | focaLoginService: {}, | 965 | focaLoginService: {}, |
| 982 | $localStorage: {} | 966 | $localStorage: {} |
| 983 | }); | 967 | }); |
| 984 | scope.idLista = true; | 968 | scope.idLista = true; |
| 985 | scope.notaPedido = { | 969 | scope.notaPedido = { |
| 986 | vendedor: { NUM: true } | 970 | vendedor: { NUM: true } |
| 987 | }; | 971 | }; |
| 988 | 972 | ||
| 989 | //act | 973 | //act |
| 990 | scope.notaPedido.articulosNotaPedido = [{ precio: 2, cantidad: 1}]; | 974 | scope.notaPedido.articulosNotaPedido = [{ precio: 2, cantidad: 1}]; |
| 991 | var esperado = 2; | 975 | var esperado = 2; |
| 992 | var resultado = scope.getTotal(); | 976 | var resultado = scope.getTotal(); |
| 993 | 977 | ||
| 994 | //assert | 978 | //assert |
| 995 | expect(resultado).toEqual(esperado); | 979 | expect(resultado).toEqual(esperado); |
| 996 | }); | 980 | }); |
| 997 | 981 | ||
| 998 | it('función getSubTotal devulve correctamente', function() { | 982 | it('función getSubTotal devulve correctamente', function() { |
| 999 | 983 | ||
| 1000 | //arrange | 984 | //arrange |
| 1001 | var scope = { | 985 | var scope = { |
| 1002 | $watch: function() { }, | 986 | $watch: function() { }, |
| 1003 | $broadcast: function() { } | 987 | $broadcast: function() { } |
| 1004 | }; | 988 | }; |
| 1005 | 989 | ||
| 1006 | $controler('notaPedidoCtrl', { | 990 | $controler('notaPedidoCtrl', { |
| 1007 | $scope: scope, | 991 | $scope: scope, |
| 1008 | $uibModal: {}, | 992 | $uibModal: {}, |
| 1009 | $location: {}, | 993 | $location: {}, |
| 1010 | $filter: filter, | 994 | $filter: filter, |
| 1011 | $timeout: timeout, | 995 | $timeout: timeout, |
| 1012 | crearNotaPedidoService: { | 996 | crearNotaPedidoService: { |
| 1013 | getNumeroNotaPedido: function() { | 997 | getNumeroNotaPedido: function() { |
| 1014 | return { | 998 | return { |
| 1015 | then: function() { } | 999 | then: function() { } |
| 1016 | }; | 1000 | }; |
| 1017 | }, | 1001 | }, |
| 1018 | getBotonera: function() { }, | 1002 | getBotonera: function() { }, |
| 1019 | getCotizacionByIdMoneda: function() { | 1003 | getCotizacionByIdMoneda: function() { |
| 1020 | return { | 1004 | return { |
| 1021 | then: function() { } | 1005 | then: function() { } |
| 1022 | }; | 1006 | }; |
| 1023 | } | 1007 | } |
| 1024 | }, | 1008 | }, |
| 1025 | focaBotoneraLateralService: {}, | 1009 | focaBotoneraLateralService: {}, |
| 1026 | focaModalService: {}, | 1010 | focaModalService: {}, |
| 1027 | notaPedidoBusinessService: {}, | 1011 | notaPedidoBusinessService: {}, |
| 1028 | $rootScope: { | 1012 | $rootScope: { |
| 1029 | $on: function() { } | 1013 | $on: function() { } |
| 1030 | }, | 1014 | }, |
| 1031 | focaSeguimientoService: {}, | 1015 | focaSeguimientoService: {}, |
| 1032 | APP: {}, | 1016 | APP: {}, |
| 1033 | focaLoginService: {}, | 1017 | focaLoginService: {}, |
| 1034 | $localStorage: {} | 1018 | $localStorage: {} |
| 1035 | }); | 1019 | }); |
| 1036 | scope.idLista = true; | 1020 | scope.idLista = true; |
| 1037 | scope.notaPedido = { | 1021 | scope.notaPedido = { |
| 1038 | vendedor: { NUM: true } | 1022 | vendedor: { NUM: true } |
| 1039 | }; | 1023 | }; |
| 1040 | 1024 | ||
| 1041 | //act | 1025 | //act |
| 1042 | scope.articuloACargar = { precio: 2, cantidad: 1}; | 1026 | scope.articuloACargar = { precio: 2, cantidad: 1}; |
| 1043 | var esperado = 2; | 1027 | var esperado = 2; |
| 1044 | var resultado = scope.getSubTotal(); | 1028 | var resultado = scope.getSubTotal(); |
| 1045 | 1029 | ||
| 1046 | //assert | 1030 | //assert |
| 1047 | expect(resultado).toEqual(esperado); | 1031 | expect(resultado).toEqual(esperado); |
| 1048 | }); | 1032 | }); |
| 1049 | 1033 | ||
| 1050 | it('función seleccionarPreciosYCondiciones abre modal', function() { | 1034 | it('función seleccionarPreciosYCondiciones abre modal', function() { |
| 1051 | 1035 | ||
| 1052 | //arrange | 1036 | //arrange |
| 1053 | var scope = { | 1037 | var scope = { |
| 1054 | $watch: function() { }, | 1038 | $watch: function() { }, |
| 1055 | $broadcast: function() { } | 1039 | $broadcast: function() { } |
| 1056 | }; | 1040 | }; |
| 1057 | var uibModal = { | 1041 | var uibModal = { |
| 1058 | open: function() { } | 1042 | open: function() { } |
| 1059 | }; | 1043 | }; |
| 1060 | 1044 | ||
| 1061 | $controler('notaPedidoCtrl', { | 1045 | $controler('notaPedidoCtrl', { |
| 1062 | $scope: scope, | 1046 | $scope: scope, |
| 1063 | $uibModal: uibModal, | 1047 | $uibModal: uibModal, |
| 1064 | $location: {}, | 1048 | $location: {}, |
| 1065 | $filter: filter, | 1049 | $filter: filter, |
| 1066 | $timeout: timeout, | 1050 | $timeout: timeout, |
| 1067 | crearNotaPedidoService: { | 1051 | crearNotaPedidoService: { |
| 1068 | getNumeroNotaPedido: function() { | 1052 | getNumeroNotaPedido: function() { |
| 1069 | return { | 1053 | return { |
| 1070 | then: function() { } | 1054 | then: function() { } |
| 1071 | }; | 1055 | }; |
| 1072 | }, | 1056 | }, |
| 1073 | getBotonera: function() { }, | 1057 | getBotonera: function() { }, |
| 1074 | getCotizacionByIdMoneda: function() { | 1058 | getCotizacionByIdMoneda: function() { |
| 1075 | return { | 1059 | return { |
| 1076 | then: function() { } | 1060 | then: function() { } |
| 1077 | }; | 1061 | }; |
| 1078 | } | 1062 | } |
| 1079 | }, | 1063 | }, |
| 1080 | focaBotoneraLateralService: {}, | 1064 | focaBotoneraLateralService: {}, |
| 1081 | focaModalService: {}, | 1065 | focaModalService: {}, |
| 1082 | notaPedidoBusinessService: {}, | 1066 | notaPedidoBusinessService: {}, |
| 1083 | $rootScope: { | 1067 | $rootScope: { |
| 1084 | $on: function() { } | 1068 | $on: function() { } |
| 1085 | }, | 1069 | }, |
| 1086 | focaSeguimientoService: {}, | 1070 | focaSeguimientoService: {}, |
| 1087 | APP: {}, | 1071 | APP: {}, |
| 1088 | focaLoginService: {}, | 1072 | focaLoginService: {}, |
| 1089 | $localStorage: {} | 1073 | $localStorage: {} |
| 1090 | }); | 1074 | }); |
| 1091 | 1075 | ||
| 1092 | scope.notaPedido = {}; | 1076 | scope.notaPedido = {}; |
| 1093 | 1077 | ||
| 1094 | var respuesta = { result: {then: function() { } } }; | 1078 | var respuesta = { result: {then: function() { } } }; |
| 1095 | 1079 | ||
| 1096 | //act | 1080 | //act |
| 1097 | spyOn(uibModal, 'open').and.returnValue(respuesta); | 1081 | spyOn(uibModal, 'open').and.returnValue(respuesta); |
| 1098 | scope.seleccionarPreciosYCondiciones(); | 1082 | scope.seleccionarPreciosYCondiciones(); |
| 1099 | 1083 | ||
| 1100 | //assert | 1084 | //assert |
| 1101 | expect(uibModal.open).toHaveBeenCalled(); | 1085 | expect(uibModal.open).toHaveBeenCalled(); |
| 1102 | }); | 1086 | }); |
| 1103 | 1087 | ||
| 1104 | it('función seleccionarPreciosYCondiciones setea articulos y cabecera', function(done) { | 1088 | it('función seleccionarPreciosYCondiciones setea articulos y cabecera', function(done) { |
| 1105 | 1089 | ||
| 1106 | //arrange | 1090 | //arrange |
| 1107 | var scope = { | 1091 | var scope = { |
| 1108 | $watch: function() { }, | 1092 | $watch: function() { }, |
| 1109 | $broadcast: function() { } | 1093 | $broadcast: function() { } |
| 1110 | }; | 1094 | }; |
| 1111 | var uibModal = { | 1095 | var uibModal = { |
| 1112 | open: function() { } | 1096 | open: function() { } |
| 1113 | }; | 1097 | }; |
| 1114 | 1098 | ||
| 1115 | $controler('notaPedidoCtrl', { | 1099 | $controler('notaPedidoCtrl', { |
| 1116 | $scope: scope, | 1100 | $scope: scope, |
| 1117 | $uibModal: uibModal, | 1101 | $uibModal: uibModal, |
| 1118 | $location: {}, | 1102 | $location: {}, |
| 1119 | $filter: filter, | 1103 | $filter: filter, |
| 1120 | $timeout: timeout, | 1104 | $timeout: timeout, |
| 1121 | crearNotaPedidoService: { | 1105 | crearNotaPedidoService: { |
| 1122 | getNumeroNotaPedido: function() { | 1106 | getNumeroNotaPedido: function() { |
| 1123 | return { | 1107 | return { |
| 1124 | then: function() { } | 1108 | then: function() { } |
| 1125 | }; | 1109 | }; |
| 1126 | }, | 1110 | }, |
| 1127 | getBotonera: function() { }, | 1111 | getBotonera: function() { }, |
| 1128 | getCotizacionByIdMoneda: function() { | 1112 | getCotizacionByIdMoneda: function() { |
| 1129 | return { | 1113 | return { |
| 1130 | then: function() { } | 1114 | then: function() { } |
| 1131 | }; | 1115 | }; |
| 1132 | } | 1116 | } |
| 1133 | }, | 1117 | }, |
| 1134 | focaBotoneraLateralService: {}, | 1118 | focaBotoneraLateralService: {}, |
| 1135 | focaModalService: {}, | 1119 | focaModalService: {}, |
| 1136 | notaPedidoBusinessService: {}, | 1120 | notaPedidoBusinessService: {}, |
| 1137 | $rootScope: { | 1121 | $rootScope: { |
| 1138 | $on: function() { } | 1122 | $on: function() { } |
| 1139 | }, | 1123 | }, |
| 1140 | focaSeguimientoService: {}, | 1124 | focaSeguimientoService: {}, |
| 1141 | APP: {}, | 1125 | APP: {}, |
| 1142 | focaLoginService: {}, | 1126 | focaLoginService: {}, |
| 1143 | $localStorage: {} | 1127 | $localStorage: {} |
| 1144 | }); | 1128 | }); |
| 1145 | scope.idLista = true; | 1129 | scope.idLista = true; |
| 1146 | scope.notaPedido = { | 1130 | scope.notaPedido = { |
| 1147 | vendedor: { NUM: true } | 1131 | vendedor: { NUM: true } |
| 1148 | }; | 1132 | }; |
| 1149 | var respuesta = { plazoPago: { } }; | 1133 | var respuesta = { plazoPago: { } }; |
| 1150 | var promesaRespuesta = { result: Promise.resolve(respuesta) }; | 1134 | var promesaRespuesta = { result: Promise.resolve(respuesta) }; |
| 1151 | scope.$broadcast = function() { }; | 1135 | scope.$broadcast = function() { }; |
| 1152 | 1136 | ||
| 1153 | //act | 1137 | //act |
| 1154 | spyOn(uibModal, 'open').and.returnValue(promesaRespuesta); | 1138 | spyOn(uibModal, 'open').and.returnValue(promesaRespuesta); |
| 1155 | spyOn(scope, '$broadcast'); | 1139 | spyOn(scope, '$broadcast'); |
| 1156 | scope.seleccionarPreciosYCondiciones(); | 1140 | scope.seleccionarPreciosYCondiciones(); |
| 1157 | 1141 | ||
| 1158 | //assert | 1142 | //assert |
| 1159 | promesaRespuesta.result.then(function() { | 1143 | promesaRespuesta.result.then(function() { |
| 1160 | expect(scope.notaPedido.articulosNotaPedido.length).toEqual(0); | 1144 | expect(scope.notaPedido.articulosNotaPedido.length).toEqual(0); |
| 1161 | expect(scope.$broadcast).toHaveBeenCalled(); | 1145 | expect(scope.$broadcast).toHaveBeenCalled(); |
| 1162 | done(); | 1146 | done(); |
| 1163 | }); | 1147 | }); |
| 1164 | }); | 1148 | }); |
| 1165 | 1149 | ||
| 1166 | it('función seleccionarFlete abre modal', function() { | ||
| 1167 | |||
| 1168 | //arrange | ||
| 1169 | var scope = { | ||
| 1170 | $watch: function() { }, | ||
| 1171 | $broadcast: function() { } | ||
| 1172 | }; | ||
| 1173 | var uibModal = { | ||
| 1174 | open: function() { } | ||
| 1175 | }; | ||
| 1176 | |||
| 1177 | $controler('notaPedidoCtrl', { | ||
| 1178 | $scope: scope, | ||
| 1179 | $uibModal: uibModal, | ||
| 1180 | $location: {}, | ||
| 1181 | $filter: filter, | ||
| 1182 | $timeout: timeout, | ||
| 1183 | crearNotaPedidoService: { | ||
| 1184 | getNumeroNotaPedido: function() { | ||
| 1185 | return { | ||
| 1186 | then: function() { } | ||
| 1187 | }; | ||
| 1188 | }, | ||
| 1189 | getBotonera: function() { }, | ||
| 1190 | getCotizacionByIdMoneda: function() { | ||
| 1191 | return { | ||
| 1192 | then: function() { } | ||
| 1193 | }; | ||
| 1194 | } | ||
| 1195 | }, | ||
| 1196 | focaBotoneraLateralService: {}, | ||
| 1197 | focaModalService: {}, | ||
| 1198 | notaPedidoBusinessService: {}, | ||
| 1199 | $rootScope: { | ||
| 1200 | $on: function() { } | ||
| 1201 | }, | ||
| 1202 | focaSeguimientoService: {}, | ||
| 1203 | APP: {}, | ||
| 1204 | focaLoginService: {}, | ||
| 1205 | $localStorage: {} | ||
| 1206 | }); | ||
| 1207 | |||
| 1208 | scope.notaPedido = {}; | ||
| 1209 | |||
| 1210 | var respuesta = { result: {then: function() { } } }; | ||
| 1211 | |||
| 1212 | //act | ||
| 1213 | spyOn(uibModal, 'open').and.returnValue(respuesta); | ||
| 1214 | scope.seleccionarFlete(); | ||
| 1215 | |||
| 1216 | //assert | ||
| 1217 | expect(uibModal.open).toHaveBeenCalled(); | ||
| 1218 | }); | ||
| 1219 | |||
| 1220 | it('función seleccionarFlete setea flete y cabecera', function(done) { | ||
| 1221 | |||
| 1222 | //arrange | ||
| 1223 | var scope = { | ||
| 1224 | $watch: function() { }, | ||
| 1225 | $broadcast: function() { } | ||
| 1226 | }; | ||
| 1227 | var uibModal = { | ||
| 1228 | open: function() { } | ||
| 1229 | }; | ||
| 1230 | |||
| 1231 | $controler('notaPedidoCtrl', { | ||
| 1232 | $scope: scope, | ||
| 1233 | $uibModal: uibModal, | ||
| 1234 | $location: {}, | ||
| 1235 | $filter: filter, | ||
| 1236 | $timeout: timeout, | ||
| 1237 | crearNotaPedidoService: { | ||
| 1238 | getNumeroNotaPedido: function() { | ||
| 1239 | return { | ||
| 1240 | then: function() { } | ||
| 1241 | }; | ||
| 1242 | }, | ||
| 1243 | getBotonera: function() { }, | ||
| 1244 | getCotizacionByIdMoneda: function() { | ||
| 1245 | return { | ||
| 1246 | then: function() { } | ||
| 1247 | }; | ||
| 1248 | } | ||
| 1249 | }, | ||
| 1250 | focaBotoneraLateralService: {}, | ||
| 1251 | focaModalService: {}, | ||
| 1252 | notaPedidoBusinessService: {}, | ||
| 1253 | $rootScope: { | ||
| 1254 | $on: function() { } | ||
| 1255 | }, | ||
| 1256 | focaSeguimientoService: {}, | ||
| 1257 | APP: {}, | ||
| 1258 | focaLoginService: {}, | ||
| 1259 | $localStorage: {} | ||
| 1260 | }); | ||
| 1261 | scope.idLista = true; | ||
| 1262 | scope.notaPedido = { | ||
| 1263 | vendedor: { NUM: true } | ||
| 1264 | }; | ||
| 1265 | var respuesta = { flete: 1, FOB: 2, bomba: 3, kilometros: 4 }; | ||
| 1266 | var promesaRespuesta = { result: Promise.resolve(respuesta) }; | ||
| 1267 | scope.$broadcast = function() { }; | ||
| 1268 | |||
| 1269 | //act | ||
| 1270 | spyOn(uibModal, 'open').and.returnValue(promesaRespuesta); | ||
| 1271 | spyOn(scope, '$broadcast'); | ||
| 1272 | scope.seleccionarFlete(); | ||
| 1273 | |||
| 1274 | //assert | ||
| 1275 | |||
| 1276 | promesaRespuesta.result.then(function() { | ||
| 1277 | expect(scope.notaPedido.flete).toEqual(respuesta.flete); | ||
| 1278 | expect(scope.notaPedido.fob).toEqual(respuesta.FOB); | ||
| 1279 | expect(scope.notaPedido.bomba).toEqual(respuesta.bomba); | ||
| 1280 | expect(scope.notaPedido.kilometros).toEqual(respuesta.kilometros); | ||
| 1281 | expect(scope.$broadcast).toHaveBeenCalled(); | ||
| 1282 | done(); | ||
| 1283 | }); | ||
| 1284 | }); | ||
| 1285 | |||
| 1286 | it('función seleccionarMoneda abre modal', function() { | 1150 | it('función seleccionarMoneda abre modal', function() { |
| 1287 | //arrange | 1151 | //arrange |
| 1288 | var scope = { | 1152 | var scope = { |
| 1289 | $watch: function() { }, | 1153 | $watch: function() { }, |
| 1290 | $broadcast: function() { } | 1154 | $broadcast: function() { } |
| 1291 | }; | 1155 | }; |
| 1292 | var focaModalService = { | 1156 | var focaModalService = { |
| 1293 | modal: function() { } | 1157 | modal: function() { } |
| 1294 | }; | 1158 | }; |
| 1295 | 1159 | ||
| 1296 | $controler('notaPedidoCtrl', { | 1160 | $controler('notaPedidoCtrl', { |
| 1297 | $scope: scope, | 1161 | $scope: scope, |
| 1298 | $uibModal: {}, | 1162 | $uibModal: {}, |
| 1299 | $location: {}, | 1163 | $location: {}, |
| 1300 | $filter: filter, | 1164 | $filter: filter, |
| 1301 | $timeout: timeout, | 1165 | $timeout: timeout, |
| 1302 | crearNotaPedidoService: { | 1166 | crearNotaPedidoService: { |
| 1303 | getNumeroNotaPedido: function() { | 1167 | getNumeroNotaPedido: function() { |
| 1304 | return { | 1168 | return { |
| 1305 | then: function() { } | 1169 | then: function() { } |
| 1306 | }; | 1170 | }; |
| 1307 | }, | 1171 | }, |
| 1308 | getBotonera: function() { }, | 1172 | getBotonera: function() { }, |
| 1309 | getCotizacionByIdMoneda: function() { | 1173 | getCotizacionByIdMoneda: function() { |
| 1310 | return { | 1174 | return { |
| 1311 | then: function() { } | 1175 | then: function() { } |
| 1312 | }; | 1176 | }; |
| 1313 | } | 1177 | } |
| 1314 | }, | 1178 | }, |
| 1315 | focaBotoneraLateralService: {}, | 1179 | focaBotoneraLateralService: {}, |
| 1316 | focaModalService: focaModalService, | 1180 | focaModalService: focaModalService, |
| 1317 | notaPedidoBusinessService: {}, | 1181 | notaPedidoBusinessService: {}, |
| 1318 | $rootScope: { | 1182 | $rootScope: { |
| 1319 | $on: function() { } | 1183 | $on: function() { } |
| 1320 | }, | 1184 | }, |
| 1321 | focaSeguimientoService: {}, | 1185 | focaSeguimientoService: {}, |
| 1322 | APP: {}, | 1186 | APP: {}, |
| 1323 | focaLoginService: {}, | 1187 | focaLoginService: {}, |
| 1324 | $localStorage: {} | 1188 | $localStorage: {} |
| 1325 | }); | 1189 | }); |
| 1326 | scope.notaPedido = {}; | 1190 | scope.notaPedido = {}; |
| 1327 | 1191 | ||
| 1328 | var respuesta = { then: function() { } }; | 1192 | var respuesta = { then: function() { } }; |
| 1329 | 1193 | ||
| 1330 | //act | 1194 | //act |
| 1331 | spyOn(focaModalService, 'modal').and.returnValue(respuesta); | 1195 | spyOn(focaModalService, 'modal').and.returnValue(respuesta); |
| 1332 | scope.seleccionarMoneda(); | 1196 | scope.seleccionarMoneda(); |
| 1333 | 1197 | ||
| 1334 | //assert | 1198 | //assert |
| 1335 | expect(focaModalService.modal).toHaveBeenCalled(); | 1199 | expect(focaModalService.modal).toHaveBeenCalled(); |
| 1336 | }); | 1200 | }); |
| 1337 | 1201 | ||
| 1338 | it('función seleccionarMoneda llama Modal Cotizacion', function(done) { | 1202 | it('función seleccionarMoneda llama Modal Cotizacion', function(done) { |
| 1339 | //arrange | 1203 | //arrange |
| 1340 | var scope = { | 1204 | var scope = { |
| 1341 | $watch: function() { }, | 1205 | $watch: function() { }, |
| 1342 | $broadcast: function() { } | 1206 | $broadcast: function() { } |
| 1343 | }; | 1207 | }; |
| 1344 | var focaModalService = { | 1208 | var focaModalService = { |
| 1345 | modal: function() { } | 1209 | modal: function() { } |
| 1346 | }; | 1210 | }; |
| 1347 | 1211 | ||
| 1348 | $controler('notaPedidoCtrl', { | 1212 | $controler('notaPedidoCtrl', { |
| 1349 | $scope: scope, | 1213 | $scope: scope, |
| 1350 | $uibModal: {}, | 1214 | $uibModal: {}, |
| 1351 | $location: {}, | 1215 | $location: {}, |
| 1352 | $filter: filter, | 1216 | $filter: filter, |
| 1353 | $timeout: timeout, | 1217 | $timeout: timeout, |
| 1354 | crearNotaPedidoService: { | 1218 | crearNotaPedidoService: { |
| 1355 | getNumeroNotaPedido: function() { | 1219 | getNumeroNotaPedido: function() { |
| 1356 | return { | 1220 | return { |
| 1357 | then: function() { } | 1221 | then: function() { } |
| 1358 | }; | 1222 | }; |
| 1359 | }, | 1223 | }, |
| 1360 | getBotonera: function() { }, | 1224 | getBotonera: function() { }, |
| 1361 | getCotizacionByIdMoneda: function() { | 1225 | getCotizacionByIdMoneda: function() { |
| 1362 | return { | 1226 | return { |
| 1363 | then: function() { } | 1227 | then: function() { } |
| 1364 | }; | 1228 | }; |
| 1365 | } | 1229 | } |
| 1366 | }, | 1230 | }, |
| 1367 | focaBotoneraLateralService: {}, | 1231 | focaBotoneraLateralService: {}, |
| 1368 | focaModalService: focaModalService, | 1232 | focaModalService: focaModalService, |
| 1369 | notaPedidoBusinessService: {}, | 1233 | notaPedidoBusinessService: {}, |
| 1370 | $rootScope: { | 1234 | $rootScope: { |
| 1371 | $on: function() { } | 1235 | $on: function() { } |
| 1372 | }, | 1236 | }, |
| 1373 | focaSeguimientoService: {}, | 1237 | focaSeguimientoService: {}, |
| 1374 | APP: {}, | 1238 | APP: {}, |
| 1375 | focaLoginService: {}, | 1239 | focaLoginService: {}, |
| 1376 | $localStorage: {} | 1240 | $localStorage: {} |
| 1377 | }); | 1241 | }); |
| 1378 | 1242 | ||
| 1379 | scope.notaPedido = {}; | 1243 | scope.notaPedido = {}; |
| 1380 | var respuesta = 'test'; | 1244 | var respuesta = 'test'; |
| 1381 | var promesaRespuesta = Promise.resolve(respuesta); | 1245 | var promesaRespuesta = Promise.resolve(respuesta); |
| 1382 | 1246 | ||
| 1383 | //act | 1247 | //act |
| 1384 | spyOn(focaModalService, 'modal').and.returnValue(promesaRespuesta); | 1248 | spyOn(focaModalService, 'modal').and.returnValue(promesaRespuesta); |
| 1385 | spyOn(scope, 'abrirModalCotizacion'); | 1249 | spyOn(scope, 'abrirModalCotizacion'); |
| 1386 | scope.seleccionarMoneda(); | 1250 | scope.seleccionarMoneda(); |
| 1387 | 1251 | ||
| 1388 | //assert | 1252 | //assert |
| 1389 | promesaRespuesta.then(function() { | 1253 | promesaRespuesta.then(function() { |
| 1390 | expect(scope.abrirModalCotizacion).toHaveBeenCalledWith('test'); | 1254 | expect(scope.abrirModalCotizacion).toHaveBeenCalledWith('test'); |
| 1391 | done(); | 1255 | done(); |
| 1392 | }); | 1256 | }); |
| 1393 | }); | 1257 | }); |
| 1394 | 1258 | ||
| 1395 | it('función seleccionarObservaciones llama a prompt', function() { | 1259 | it('función seleccionarObservaciones llama a prompt', function() { |
| 1396 | 1260 | ||
| 1397 | //arrange | 1261 | //arrange |
| 1398 | var scope = { | 1262 | var scope = { |
| 1399 | $watch: function() { }, | 1263 | $watch: function() { }, |
| 1400 | $broadcast: function() { } | 1264 | $broadcast: function() { } |
| 1401 | }; | 1265 | }; |
| 1402 | var focaModalService = { | 1266 | var focaModalService = { |
| 1403 | prompt: function() { } | 1267 | prompt: function() { } |
| 1404 | }; | 1268 | }; |
| 1405 | 1269 | ||
| 1406 | $controler('notaPedidoCtrl', { | 1270 | $controler('notaPedidoCtrl', { |
| 1407 | $scope: scope, | 1271 | $scope: scope, |
| 1408 | $uibModal: {}, | 1272 | $uibModal: {}, |
| 1409 | $location: {}, | 1273 | $location: {}, |
| 1410 | $filter: filter, | 1274 | $filter: filter, |
| 1411 | $timeout: timeout, | 1275 | $timeout: timeout, |
| 1412 | crearNotaPedidoService: { | 1276 | crearNotaPedidoService: { |
| 1413 | getNumeroNotaPedido: function() { | 1277 | getNumeroNotaPedido: function() { |
| 1414 | return { | 1278 | return { |
| 1415 | then: function() { } | 1279 | then: function() { } |
| 1416 | }; | 1280 | }; |
| 1417 | }, | 1281 | }, |
| 1418 | getBotonera: function() { }, | 1282 | getBotonera: function() { }, |
| 1419 | getCotizacionByIdMoneda: function() { | 1283 | getCotizacionByIdMoneda: function() { |
| 1420 | return { | 1284 | return { |
| 1421 | then: function() { } | 1285 | then: function() { } |
| 1422 | }; | 1286 | }; |
| 1423 | } | 1287 | } |
| 1424 | }, | 1288 | }, |
| 1425 | focaBotoneraLateralService: {}, | 1289 | focaBotoneraLateralService: {}, |
| 1426 | focaModalService: focaModalService, | 1290 | focaModalService: focaModalService, |
| 1427 | notaPedidoBusinessService: {}, | 1291 | notaPedidoBusinessService: {}, |
| 1428 | $rootScope: { | 1292 | $rootScope: { |
| 1429 | $on: function() { } | 1293 | $on: function() { } |
| 1430 | }, | 1294 | }, |
| 1431 | focaSeguimientoService: {}, | 1295 | focaSeguimientoService: {}, |
| 1432 | APP: {}, | 1296 | APP: {}, |
| 1433 | focaLoginService: {}, | 1297 | focaLoginService: {}, |
| 1434 | $localStorage: {} | 1298 | $localStorage: {} |
| 1435 | }); | 1299 | }); |
| 1436 | var respuesta = { then: function() { } }; | 1300 | var respuesta = { then: function() { } }; |
| 1437 | scope.notaPedido = {}; | 1301 | scope.notaPedido = {}; |
| 1438 | 1302 | ||
| 1439 | //act | 1303 | //act |
| 1440 | spyOn(focaModalService, 'prompt').and.returnValue(respuesta); | 1304 | spyOn(focaModalService, 'prompt').and.returnValue(respuesta); |
| 1441 | scope.seleccionarObservaciones(); | 1305 | scope.seleccionarObservaciones(); |
| 1442 | 1306 | ||
| 1443 | //assert | 1307 | //assert |
| 1444 | expect(focaModalService.prompt).toHaveBeenCalled(); | 1308 | expect(focaModalService.prompt).toHaveBeenCalled(); |
| 1445 | }); | 1309 | }); |
| 1446 | 1310 | ||
| 1447 | it('función seleccionarObservaciones setea observaciones', function(done) { | 1311 | it('función seleccionarObservaciones setea observaciones', function(done) { |
| 1448 | 1312 | ||
| 1449 | //arrange | 1313 | //arrange |
| 1450 | var scope = { | 1314 | var scope = { |
| 1451 | $watch: function() { }, | 1315 | $watch: function() { }, |
| 1452 | $broadcast: function() { } | 1316 | $broadcast: function() { } |
| 1453 | }; | 1317 | }; |
| 1454 | var focaModalService = { | 1318 | var focaModalService = { |
| 1455 | prompt: function() { } | 1319 | prompt: function() { } |
| 1456 | }; | 1320 | }; |
| 1457 | 1321 | ||
| 1458 | $controler('notaPedidoCtrl', { | 1322 | $controler('notaPedidoCtrl', { |
| 1459 | $scope: scope, | 1323 | $scope: scope, |
| 1460 | $uibModal: {}, | 1324 | $uibModal: {}, |
| 1461 | $location: {}, | 1325 | $location: {}, |
| 1462 | $filter: filter, | 1326 | $filter: filter, |
| 1463 | $timeout: timeout, | 1327 | $timeout: timeout, |
| 1464 | crearNotaPedidoService: { | 1328 | crearNotaPedidoService: { |
| 1465 | getNumeroNotaPedido: function() { | 1329 | getNumeroNotaPedido: function() { |
| 1466 | return { | 1330 | return { |
| 1467 | then: function() { } | 1331 | then: function() { } |
| 1468 | }; | 1332 | }; |
| 1469 | }, | 1333 | }, |
| 1470 | getBotonera: function() { }, | 1334 | getBotonera: function() { }, |
| 1471 | getCotizacionByIdMoneda: function() { | 1335 | getCotizacionByIdMoneda: function() { |
| 1472 | return { | 1336 | return { |
| 1473 | then: function() { } | 1337 | then: function() { } |
| 1474 | }; | 1338 | }; |
| 1475 | } | 1339 | } |
| 1476 | }, | 1340 | }, |
| 1477 | focaBotoneraLateralService: {}, | 1341 | focaBotoneraLateralService: {}, |
| 1478 | focaModalService: focaModalService, | 1342 | focaModalService: focaModalService, |
| 1479 | notaPedidoBusinessService: {}, | 1343 | notaPedidoBusinessService: {}, |
| 1480 | $rootScope: { | 1344 | $rootScope: { |
| 1481 | $on: function() { } | 1345 | $on: function() { } |
| 1482 | }, | 1346 | }, |
| 1483 | focaSeguimientoService: {}, | 1347 | focaSeguimientoService: {}, |
| 1484 | APP: {}, | 1348 | APP: {}, |
| 1485 | focaLoginService: {}, | 1349 | focaLoginService: {}, |
| 1486 | $localStorage: {} | 1350 | $localStorage: {} |
| 1487 | }); | 1351 | }); |
| 1488 | var respuesta = 'unit test'; | 1352 | var respuesta = 'unit test'; |
| 1489 | var promesa = Promise.resolve(respuesta); | 1353 | var promesa = Promise.resolve(respuesta); |
| 1490 | scope.notaPedido = {}; | 1354 | scope.notaPedido = {}; |
| 1491 | 1355 | ||
| 1492 | //act | 1356 | //act |
| 1493 | spyOn(focaModalService, 'prompt').and.returnValue(promesa); | 1357 | spyOn(focaModalService, 'prompt').and.returnValue(promesa); |
| 1494 | scope.seleccionarObservaciones(); | 1358 | scope.seleccionarObservaciones(); |
| 1495 | 1359 | ||
| 1496 | //assert | 1360 | //assert |
| 1497 | promesa.then(function() { | 1361 | promesa.then(function() { |
| 1498 | expect(scope.notaPedido.observaciones).toEqual(respuesta); | 1362 | expect(scope.notaPedido.observaciones).toEqual(respuesta); |
| 1499 | done(); | 1363 | done(); |
| 1500 | }); | 1364 | }); |
| 1501 | }); | 1365 | }); |
| 1502 | 1366 | ||
| 1503 | it('función abrirModalCotizacion abre modal', function() { | 1367 | it('función abrirModalCotizacion abre modal', function() { |
| 1504 | 1368 | ||
| 1505 | //arrange | 1369 | //arrange |
| 1506 | var scope = { | 1370 | var scope = { |
| 1507 | $watch: function() { }, | 1371 | $watch: function() { }, |
| 1508 | $broadcast: function() { } | 1372 | $broadcast: function() { } |
| 1509 | }; | 1373 | }; |
| 1510 | var uibModal = { | 1374 | var uibModal = { |
| 1511 | open: function() { } | 1375 | open: function() { } |
| 1512 | }; | 1376 | }; |
| 1513 | 1377 | ||
| 1514 | $controler('notaPedidoCtrl', { | 1378 | $controler('notaPedidoCtrl', { |
| 1515 | $scope: scope, | 1379 | $scope: scope, |
| 1516 | $uibModal: uibModal, | 1380 | $uibModal: uibModal, |
| 1517 | $location: {}, | 1381 | $location: {}, |
| 1518 | $filter: filter, | 1382 | $filter: filter, |
| 1519 | $timeout: timeout, | 1383 | $timeout: timeout, |
| 1520 | crearNotaPedidoService: { | 1384 | crearNotaPedidoService: { |
| 1521 | getNumeroNotaPedido: function() { | 1385 | getNumeroNotaPedido: function() { |
| 1522 | return { | 1386 | return { |
| 1523 | then: function() { } | 1387 | then: function() { } |
| 1524 | }; | 1388 | }; |
| 1525 | }, | 1389 | }, |
| 1526 | getBotonera: function() { }, | 1390 | getBotonera: function() { }, |
| 1527 | getCotizacionByIdMoneda: function() { | 1391 | getCotizacionByIdMoneda: function() { |
| 1528 | return { | 1392 | return { |
| 1529 | then: function() { } | 1393 | then: function() { } |
| 1530 | }; | 1394 | }; |
| 1531 | } | 1395 | } |
| 1532 | }, | 1396 | }, |
| 1533 | focaBotoneraLateralService: {}, | 1397 | focaBotoneraLateralService: {}, |
| 1534 | focaModalService: {}, | 1398 | focaModalService: {}, |
| 1535 | notaPedidoBusinessService: {}, | 1399 | notaPedidoBusinessService: {}, |
| 1536 | $rootScope: { | 1400 | $rootScope: { |
| 1537 | $on: function() { } | 1401 | $on: function() { } |
| 1538 | }, | 1402 | }, |
| 1539 | focaSeguimientoService: {}, | 1403 | focaSeguimientoService: {}, |
| 1540 | APP: {}, | 1404 | APP: {}, |
| 1541 | focaLoginService: {}, | 1405 | focaLoginService: {}, |
| 1542 | $localStorage: {} | 1406 | $localStorage: {} |
| 1543 | }); | 1407 | }); |
| 1544 | 1408 | ||
| 1545 | scope.notaPedido = {}; | 1409 | scope.notaPedido = {}; |
| 1546 | 1410 | ||
| 1547 | var respuesta = { result: {then: function() { } } }; | 1411 | var respuesta = { result: {then: function() { } } }; |
| 1548 | 1412 | ||
| 1549 | //act | 1413 | //act |
| 1550 | spyOn(uibModal, 'open').and.returnValue(respuesta); | 1414 | spyOn(uibModal, 'open').and.returnValue(respuesta); |
| 1551 | scope.abrirModalCotizacion(); | 1415 | scope.abrirModalCotizacion(); |
| 1552 | 1416 | ||
| 1553 | //assert | 1417 | //assert |
| 1554 | expect(uibModal.open).toHaveBeenCalled(); | 1418 | expect(uibModal.open).toHaveBeenCalled(); |
| 1555 | }); | 1419 | }); |
| 1556 | 1420 | ||
| 1557 | it('función abrirModalCotizacion setea datos y cabecera', function(done) { | 1421 | it('función abrirModalCotizacion setea datos y cabecera', function(done) { |
| 1558 | //arrange | 1422 | //arrange |
| 1559 | var scope = { | 1423 | var scope = { |
| 1560 | $watch: function() { }, | 1424 | $watch: function() { }, |
| 1561 | $broadcast: function() { } | 1425 | $broadcast: function() { } |
| 1562 | }; | 1426 | }; |
| 1563 | var uibModal = { | 1427 | var uibModal = { |
| 1564 | open: function() { } | 1428 | open: function() { } |
| 1565 | }; | 1429 | }; |
| 1566 | 1430 | ||
| 1567 | $controler('notaPedidoCtrl', { | 1431 | $controler('notaPedidoCtrl', { |
| 1568 | $scope: scope, | 1432 | $scope: scope, |
| 1569 | $uibModal: uibModal, | 1433 | $uibModal: uibModal, |
| 1570 | $location: {}, | 1434 | $location: {}, |
| 1571 | $filter: filter, | 1435 | $filter: filter, |
| 1572 | $timeout: timeout, | 1436 | $timeout: timeout, |
| 1573 | crearNotaPedidoService: { | 1437 | crearNotaPedidoService: { |
| 1574 | getNumeroNotaPedido: function() { | 1438 | getNumeroNotaPedido: function() { |
| 1575 | return { | 1439 | return { |
| 1576 | then: function() { } | 1440 | then: function() { } |
| 1577 | }; | 1441 | }; |
| 1578 | }, | 1442 | }, |
| 1579 | getBotonera: function() { }, | 1443 | getBotonera: function() { }, |
| 1580 | getCotizacionByIdMoneda: function() { | 1444 | getCotizacionByIdMoneda: function() { |
| 1581 | return { | 1445 | return { |
| 1582 | then: function() { } | 1446 | then: function() { } |
| 1583 | }; | 1447 | }; |
| 1584 | } | 1448 | } |
| 1585 | }, | 1449 | }, |
| 1586 | focaBotoneraLateralService: {}, | 1450 | focaBotoneraLateralService: {}, |
| 1587 | focaModalService: {}, | 1451 | focaModalService: {}, |
| 1588 | notaPedidoBusinessService: {}, | 1452 | notaPedidoBusinessService: {}, |
| 1589 | $rootScope: { | 1453 | $rootScope: { |
| 1590 | $on: function() { } | 1454 | $on: function() { } |
| 1591 | }, | 1455 | }, |
| 1592 | focaSeguimientoService: {}, | 1456 | focaSeguimientoService: {}, |
| 1593 | APP: {}, | 1457 | APP: {}, |
| 1594 | focaLoginService: {}, | 1458 | focaLoginService: {}, |
| 1595 | $localStorage: {}, | 1459 | $localStorage: {}, |
| 1596 | articulosNotaPedido: [] | 1460 | articulosNotaPedido: [] |
| 1597 | }); | 1461 | }); |
| 1598 | 1462 | ||
| 1599 | scope.notaPedido = {}; | 1463 | scope.notaPedido = {}; |
| 1600 | scope.articulosTabla = []; | 1464 | scope.articulosTabla = []; |
| 1601 | scope.$broadcast = function() { }; | 1465 | scope.$broadcast = function() { }; |
| 1602 | var moneda = 'moneda'; | 1466 | var moneda = 'moneda'; |
| 1603 | var cotizacion = 'test'; | 1467 | var cotizacion = 'test'; |
| 1604 | var promesaRespuesta = { result: Promise.resolve(cotizacion) }; | 1468 | var promesaRespuesta = { result: Promise.resolve(cotizacion) }; |
| 1605 | 1469 | ||
| 1606 | //act | 1470 | //act |
| 1607 | spyOn(uibModal, 'open').and.returnValue(promesaRespuesta); | 1471 | spyOn(uibModal, 'open').and.returnValue(promesaRespuesta); |
| 1608 | spyOn(scope, '$broadcast'); | 1472 | spyOn(scope, '$broadcast'); |
| 1609 | scope.abrirModalCotizacion(moneda); | 1473 | scope.abrirModalCotizacion(moneda); |
| 1610 | 1474 | ||
| 1611 | //assert | 1475 | //assert |
| 1612 | promesaRespuesta.result.then(function() { | 1476 | promesaRespuesta.result.then(function() { |
| 1613 | 1477 | ||
| 1614 | expect(scope.$broadcast).toHaveBeenCalled(); | 1478 | expect(scope.$broadcast).toHaveBeenCalled(); |
| 1615 | expect(scope.notaPedido.cotizacion).toEqual(cotizacion); | 1479 | expect(scope.notaPedido.cotizacion).toEqual(cotizacion); |
| 1616 | done(); | 1480 | done(); |
| 1617 | }); | 1481 | }); |
| 1618 | }); | 1482 | }); |
| 1619 | 1483 | ||
| 1620 | it('función agregarATabla muestra alerta cuando a cargar undefined', function() { | 1484 | it('función agregarATabla muestra alerta cuando a cargar undefined', function() { |
| 1621 | 1485 | ||
| 1622 | //arrange | 1486 | //arrange |
| 1623 | var scope = { | 1487 | var scope = { |
| 1624 | $watch: function() { }, | 1488 | $watch: function() { }, |
| 1625 | $broadcast: function() { } | 1489 | $broadcast: function() { } |
| 1626 | }; | 1490 | }; |
| 1627 | var focaModalService = { | 1491 | var focaModalService = { |
| 1628 | alert: function() { } | 1492 | alert: function() { } |
| 1629 | }; | 1493 | }; |
| 1630 | 1494 | ||
| 1631 | $controler('notaPedidoCtrl', { | 1495 | $controler('notaPedidoCtrl', { |
| 1632 | $scope: scope, | 1496 | $scope: scope, |
| 1633 | $uibModal: {}, | 1497 | $uibModal: {}, |
| 1634 | $location: {}, | 1498 | $location: {}, |
| 1635 | $filter: filter, | 1499 | $filter: filter, |
| 1636 | $timeout: timeout, | 1500 | $timeout: timeout, |
| 1637 | crearNotaPedidoService: { | 1501 | crearNotaPedidoService: { |
| 1638 | getNumeroNotaPedido: function() { | 1502 | getNumeroNotaPedido: function() { |
| 1639 | return { | 1503 | return { |
| 1640 | then: function() { } | 1504 | then: function() { } |
| 1641 | }; | 1505 | }; |
| 1642 | }, | 1506 | }, |
| 1643 | getBotonera: function() { }, | 1507 | getBotonera: function() { }, |
| 1644 | getCotizacionByIdMoneda: function() { | 1508 | getCotizacionByIdMoneda: function() { |
| 1645 | return { | 1509 | return { |
| 1646 | then: function() { } | 1510 | then: function() { } |
| 1647 | }; | 1511 | }; |
| 1648 | } | 1512 | } |
| 1649 | }, | 1513 | }, |
| 1650 | focaBotoneraLateralService: {}, | 1514 | focaBotoneraLateralService: {}, |
| 1651 | focaModalService: focaModalService, | 1515 | focaModalService: focaModalService, |
| 1652 | notaPedidoBusinessService: {}, | 1516 | notaPedidoBusinessService: {}, |
| 1653 | $rootScope: { | 1517 | $rootScope: { |
| 1654 | $on: function() { } | 1518 | $on: function() { } |
| 1655 | }, | 1519 | }, |
| 1656 | focaSeguimientoService: {}, | 1520 | focaSeguimientoService: {}, |
| 1657 | APP: {}, | 1521 | APP: {}, |
| 1658 | focaLoginService: {}, | 1522 | focaLoginService: {}, |
| 1659 | $localStorage: {} | 1523 | $localStorage: {} |
| 1660 | }); | 1524 | }); |
| 1661 | scope.articuloACargar = {}; | 1525 | scope.articuloACargar = {}; |
| 1662 | 1526 | ||
| 1663 | //act | 1527 | //act |
| 1664 | spyOn(focaModalService, 'alert'); | 1528 | spyOn(focaModalService, 'alert'); |
| 1665 | scope.agregarATabla(13); | 1529 | scope.agregarATabla(13); |
| 1666 | 1530 | ||
| 1667 | //assert | 1531 | //assert |
| 1668 | expect(focaModalService.alert).toHaveBeenCalledWith('El valor debe ser al menos 1'); | 1532 | expect(focaModalService.alert).toHaveBeenCalledWith('El valor debe ser al menos 1'); |
| 1669 | }); | 1533 | }); |
| 1670 | 1534 | ||
| 1671 | it('función editarArticulo muestra alerta cuando a cargar es undefined', function() { | 1535 | it('función editarArticulo muestra alerta cuando a cargar es undefined', function() { |
| 1672 | 1536 | ||
| 1673 | //arrange | 1537 | //arrange |
| 1674 | var scope = { | 1538 | var scope = { |
| 1675 | $watch: function() { }, | 1539 | $watch: function() { }, |
| 1676 | $broadcast: function() { } | 1540 | $broadcast: function() { } |
| 1677 | }; | 1541 | }; |
| 1678 | var focaModalService = { | 1542 | var focaModalService = { |
| 1679 | alert: function() { } | 1543 | alert: function() { } |
| 1680 | }; | 1544 | }; |
| 1681 | 1545 | ||
| 1682 | $controler('notaPedidoCtrl', { | 1546 | $controler('notaPedidoCtrl', { |
| 1683 | $scope: scope, | 1547 | $scope: scope, |
| 1684 | $uibModal: {}, | 1548 | $uibModal: {}, |
| 1685 | $location: {}, | 1549 | $location: {}, |
| 1686 | $filter: filter, | 1550 | $filter: filter, |
| 1687 | $timeout: timeout, | 1551 | $timeout: timeout, |
| 1688 | crearNotaPedidoService: { | 1552 | crearNotaPedidoService: { |
| 1689 | getNumeroNotaPedido: function() { | 1553 | getNumeroNotaPedido: function() { |
| 1690 | return { | 1554 | return { |
| 1691 | then: function() { } | 1555 | then: function() { } |
| 1692 | }; | 1556 | }; |
| 1693 | }, | 1557 | }, |
| 1694 | getBotonera: function() { }, | 1558 | getBotonera: function() { }, |
| 1695 | getCotizacionByIdMoneda: function() { | 1559 | getCotizacionByIdMoneda: function() { |
| 1696 | return { | 1560 | return { |
| 1697 | then: function() { } | 1561 | then: function() { } |
| 1698 | }; | 1562 | }; |
| 1699 | } | 1563 | } |
| 1700 | }, | 1564 | }, |
| 1701 | focaBotoneraLateralService: {}, | 1565 | focaBotoneraLateralService: {}, |
| 1702 | focaModalService: focaModalService, | 1566 | focaModalService: focaModalService, |
| 1703 | notaPedidoBusinessService: {}, | 1567 | notaPedidoBusinessService: {}, |
| 1704 | $rootScope: { | 1568 | $rootScope: { |
| 1705 | $on: function() { } | 1569 | $on: function() { } |
| 1706 | }, | 1570 | }, |
| 1707 | focaSeguimientoService: {}, | 1571 | focaSeguimientoService: {}, |
| 1708 | APP: {}, | 1572 | APP: {}, |
| 1709 | focaLoginService: {}, | 1573 | focaLoginService: {}, |
| 1710 | $localStorage: {} | 1574 | $localStorage: {} |
| 1711 | }); | 1575 | }); |
| 1712 | scope.articuloACargar = {}; | 1576 | scope.articuloACargar = {}; |
| 1713 | 1577 | ||
| 1714 | //act | 1578 | //act |
| 1715 | spyOn(focaModalService, 'alert'); | 1579 | spyOn(focaModalService, 'alert'); |
| 1716 | scope.agregarATabla(13); | 1580 | scope.agregarATabla(13); |
| 1717 | 1581 | ||
| 1718 | //assert | 1582 | //assert |
| 1719 | expect(focaModalService.alert).toHaveBeenCalledWith('El valor debe ser al menos 1'); | 1583 | expect(focaModalService.alert).toHaveBeenCalledWith('El valor debe ser al menos 1'); |
| 1720 | }); | 1584 | }); |
| 1721 | 1585 | ||
| 1722 | it('función salir lleva a ruta correcta', function() { | 1586 | it('función salir lleva a ruta correcta', function() { |
| 1723 | 1587 | ||
| 1724 | inject(function($location) { | 1588 | inject(function($location) { |
| 1725 | 1589 | ||
| 1726 | //arrange | 1590 | //arrange |
| 1727 | var scope = { | 1591 | var scope = { |
| 1728 | $watch: function() { }, | 1592 | $watch: function() { }, |
| 1729 | $broadcast: function() { } | 1593 | $broadcast: function() { } |
| 1730 | }; | 1594 | }; |
| 1731 | 1595 | ||
| 1732 | $controler('notaPedidoCtrl', { | 1596 | $controler('notaPedidoCtrl', { |
| 1733 | $scope: scope, | 1597 | $scope: scope, |
| 1734 | $uibModal: {}, | 1598 | $uibModal: {}, |
| 1735 | $location: $location, | 1599 | $location: $location, |
| 1736 | $filter: filter, | 1600 | $filter: filter, |
spec/controllerSpecCrearPedido.js
| 1 | describe('Controladores módulo crear nota de pedido', function() { | 1 | describe('Controladores módulo crear nota de pedido', function() { |
| 2 | 2 | ||
| 3 | var $controler; | 3 | var $controler; |
| 4 | 4 | ||
| 5 | beforeEach(function() { | 5 | beforeEach(function() { |
| 6 | module('focaCrearNotaPedido'); | 6 | module('focaCrearNotaPedido'); |
| 7 | inject(function(_$controller_) { | 7 | inject(function(_$controller_) { |
| 8 | $controler = _$controller_; | 8 | $controler = _$controller_; |
| 9 | }); | 9 | }); |
| 10 | }); | 10 | }); |
| 11 | 11 | ||
| 12 | describe('Controlador notaPedidoCtrl crear nota de pedido', function() { | 12 | describe('Controlador notaPedidoCtrl crear nota de pedido', function() { |
| 13 | 13 | ||
| 14 | var filter = function() { | 14 | var filter = function() { |
| 15 | return function() { }; | 15 | return function() { }; |
| 16 | }; | 16 | }; |
| 17 | var timeout; | 17 | var timeout; |
| 18 | 18 | ||
| 19 | beforeEach(function() { | 19 | beforeEach(function() { |
| 20 | 20 | ||
| 21 | inject(function($timeout) { | 21 | inject(function($timeout) { |
| 22 | timeout = $timeout; | 22 | timeout = $timeout; |
| 23 | }); | 23 | }); |
| 24 | }); | 24 | }); |
| 25 | 25 | ||
| 26 | it('Existe el controlador notaPedidoCtrl', function() { | 26 | it('Existe el controlador notaPedidoCtrl', function() { |
| 27 | 27 | ||
| 28 | //act | 28 | //act |
| 29 | var controlador = $controler('notaPedidoCtrl', { | 29 | var controlador = $controler('notaPedidoCtrl', { |
| 30 | $scope: { | 30 | $scope: { |
| 31 | $watch: function() { }, | 31 | $watch: function() { }, |
| 32 | $broadcast: function() {} | 32 | $broadcast: function() {} |
| 33 | }, | 33 | }, |
| 34 | $uibModal: {}, | 34 | $uibModal: {}, |
| 35 | $location: {}, | 35 | $location: {}, |
| 36 | $filter: filter, | 36 | $filter: filter, |
| 37 | $timeout: timeout, | 37 | $timeout: timeout, |
| 38 | crearNotaPedidoService: { | 38 | crearNotaPedidoService: { |
| 39 | getNumeroNotaPedido: function() { | 39 | getNumeroNotaPedido: function() { |
| 40 | return { | 40 | return { |
| 41 | then: function() { } | 41 | then: function() { } |
| 42 | }; | 42 | }; |
| 43 | }, | 43 | }, |
| 44 | getBotonera: function() { }, | 44 | getBotonera: function() { }, |
| 45 | getCotizacionByIdMoneda: function() { | 45 | getCotizacionByIdMoneda: function() { |
| 46 | return { | 46 | return { |
| 47 | then: function() {} | 47 | then: function() {} |
| 48 | }; | 48 | }; |
| 49 | } | 49 | } |
| 50 | }, | 50 | }, |
| 51 | focaBotoneraLateralService: {}, | 51 | focaBotoneraLateralService: {}, |
| 52 | focaModalService: {}, | 52 | focaModalService: {}, |
| 53 | notaPedidoBusinessService: {}, | 53 | notaPedidoBusinessService: {}, |
| 54 | $rootScope: { | 54 | $rootScope: { |
| 55 | $on: function() { } | 55 | $on: function() { } |
| 56 | }, | 56 | }, |
| 57 | focaSeguimientoService: {}, | 57 | focaSeguimientoService: {}, |
| 58 | APP: {}, | 58 | APP: {}, |
| 59 | focaLoginService: {}, | 59 | focaLoginService: {}, |
| 60 | $localStorage: {} | 60 | $localStorage: {} |
| 61 | }); | 61 | }); |
| 62 | 62 | ||
| 63 | //expect | 63 | //expect |
| 64 | expect(typeof controlador).toEqual('object'); | 64 | expect(typeof controlador).toEqual('object'); |
| 65 | }); | 65 | }); |
| 66 | 66 | ||
| 67 | it('la funcion $scope.crearNotaPedido muestra alerta cuando vendedor es null', function() { | ||
| 68 | |||
| 69 | //arrange | ||
| 70 | var scope = { | ||
| 71 | $watch: function() { }, | ||
| 72 | $broadcast: function() {} | ||
| 73 | }; | ||
| 74 | var focaModalService = { | ||
| 75 | alert: function() { } | ||
| 76 | }; | ||
| 77 | |||
| 78 | $controler('notaPedidoCtrl', { | ||
| 79 | $scope: scope, | ||
| 80 | $uibModal: {}, | ||
| 81 | $location: {}, | ||
| 82 | $filter: filter, | ||
| 83 | $timeout: timeout, | ||
| 84 | crearNotaPedidoService: { | ||
| 85 | getNumeroNotaPedido: function() { | ||
| 86 | return { | ||
| 87 | then: function() { } | ||
| 88 | }; | ||
| 89 | }, | ||
| 90 | getBotonera: function() { }, | ||
| 91 | getCotizacionByIdMoneda: function() { | ||
| 92 | return { | ||
| 93 | then: function() {} | ||
| 94 | }; | ||
| 95 | } | ||
| 96 | }, | ||
| 97 | focaBotoneraLateralService: {}, | ||
| 98 | focaModalService: focaModalService, | ||
| 99 | notaPedidoBusinessService: {}, | ||
| 100 | $rootScope: { | ||
| 101 | $on: function() { } | ||
| 102 | }, | ||
| 103 | focaSeguimientoService: {}, | ||
| 104 | APP: {}, | ||
| 105 | focaLoginService: {}, | ||
| 106 | $localStorage: {}, | ||
| 107 | $watch: function() { }, | ||
| 108 | $broadcast: function() {} | ||
| 109 | }); | ||
| 110 | |||
| 111 | //act | ||
| 112 | scope.notaPedido = { | ||
| 113 | vendedor: { | ||
| 114 | id: null | ||
| 115 | } | ||
| 116 | }; | ||
| 117 | spyOn(focaModalService, 'alert'); | ||
| 118 | scope.crearNotaPedido(); | ||
| 119 | |||
| 120 | //expect | ||
| 121 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Vendedor'); | ||
| 122 | }); | ||
| 123 | |||
| 124 | it('la funcion $scope.crearNotaPedido muestra alerta cuando cliente es null', function() { | 67 | it('la funcion $scope.crearNotaPedido muestra alerta cuando cliente es null', function() { |
| 125 | 68 | ||
| 126 | //arrange | 69 | //arrange |
| 127 | var scope = { | 70 | var scope = { |
| 128 | $watch: function() { }, | 71 | $watch: function() { }, |
| 129 | $broadcast: function() {} | 72 | $broadcast: function() {} |
| 130 | }; | 73 | }; |
| 131 | var focaModalService = { | 74 | var focaModalService = { |
| 132 | alert: function() { } | 75 | alert: function() { } |
| 133 | }; | 76 | }; |
| 134 | 77 | ||
| 135 | $controler('notaPedidoCtrl', { | 78 | $controler('notaPedidoCtrl', { |
| 136 | $scope: scope, | 79 | $scope: scope, |
| 137 | $uibModal: {}, | 80 | $uibModal: {}, |
| 138 | $location: {}, | 81 | $location: {}, |
| 139 | $filter: filter, | 82 | $filter: filter, |
| 140 | $timeout: timeout, | 83 | $timeout: timeout, |
| 141 | crearNotaPedidoService: { | 84 | crearNotaPedidoService: { |
| 142 | getNumeroNotaPedido: function() { | 85 | getNumeroNotaPedido: function() { |
| 143 | return { | 86 | return { |
| 144 | then: function() { } | 87 | then: function() { } |
| 145 | }; | 88 | }; |
| 146 | }, | 89 | }, |
| 147 | getBotonera: function() { }, | 90 | getBotonera: function() { }, |
| 148 | getCotizacionByIdMoneda: function() { | 91 | getCotizacionByIdMoneda: function() { |
| 149 | return { | 92 | return { |
| 150 | then: function() {} | 93 | then: function() {} |
| 151 | }; | 94 | }; |
| 152 | } | 95 | } |
| 153 | }, | 96 | }, |
| 154 | focaBotoneraLateralService: {}, | 97 | focaBotoneraLateralService: {}, |
| 155 | focaModalService: focaModalService, | 98 | focaModalService: focaModalService, |
| 156 | notaPedidoBusinessService: {}, | 99 | notaPedidoBusinessService: {}, |
| 157 | $rootScope: { | 100 | $rootScope: { |
| 158 | $on: function() { } | 101 | $on: function() { } |
| 159 | }, | 102 | }, |
| 160 | focaSeguimientoService: {}, | 103 | focaSeguimientoService: {}, |
| 161 | APP: {}, | 104 | APP: {}, |
| 162 | focaLoginService: {}, | 105 | focaLoginService: {}, |
| 163 | $localStorage: {}, | 106 | $localStorage: {}, |
| 164 | $watch: function() { }, | 107 | $watch: function() { }, |
| 165 | $broadcast: function() {} | 108 | $broadcast: function() {} |
| 166 | }); | 109 | }); |
| 167 | 110 | ||
| 168 | scope.notaPedido = { | 111 | scope.notaPedido = { |
| 169 | vendedor: { | 112 | vendedor: { |
| 170 | id: true | 113 | id: true |
| 171 | }, | 114 | }, |
| 172 | cliente:{ | 115 | cliente:{ |
| 173 | COD: false | 116 | COD: false |
| 174 | } | 117 | } |
| 175 | }; | 118 | }; |
| 176 | 119 | ||
| 177 | //act | 120 | //act |
| 178 | spyOn(focaModalService, 'alert'); | 121 | spyOn(focaModalService, 'alert'); |
| 179 | scope.crearNotaPedido(); | 122 | scope.crearNotaPedido(); |
| 180 | 123 | ||
| 181 | //expect | 124 | //expect |
| 182 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cliente'); | 125 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cliente'); |
| 183 | }); | 126 | }); |
| 184 | 127 | ||
| 185 | it('funcion $scope.crearNotaPedido muestra alerta cuando proveedor es null', function() { | 128 | it('funcion $scope.crearNotaPedido muestra alerta cuando proveedor es null', function() { |
| 186 | 129 | ||
| 187 | //arrange | 130 | //arrange |
| 188 | var scope = { | 131 | var scope = { |
| 189 | $watch: function() { }, | 132 | $watch: function() { }, |
| 190 | $broadcast: function() {} | 133 | $broadcast: function() {} |
| 191 | }; | 134 | }; |
| 192 | var focaModalService = { | 135 | var focaModalService = { |
| 193 | alert: function() { } | 136 | alert: function() { } |
| 194 | }; | 137 | }; |
| 195 | 138 | ||
| 196 | $controler('notaPedidoCtrl', { | 139 | $controler('notaPedidoCtrl', { |
| 197 | $scope: scope, | 140 | $scope: scope, |
| 198 | $uibModal: {}, | 141 | $uibModal: {}, |
| 199 | $location: {}, | 142 | $location: {}, |
| 200 | $filter: filter, | 143 | $filter: filter, |
| 201 | $timeout: timeout, | 144 | $timeout: timeout, |
| 202 | crearNotaPedidoService: { | 145 | crearNotaPedidoService: { |
| 203 | getNumeroNotaPedido: function() { | 146 | getNumeroNotaPedido: function() { |
| 204 | return { | 147 | return { |
| 205 | then: function() { } | 148 | then: function() { } |
| 206 | }; | 149 | }; |
| 207 | }, | 150 | }, |
| 208 | getBotonera: function() { }, | 151 | getBotonera: function() { }, |
| 209 | getCotizacionByIdMoneda: function() { | 152 | getCotizacionByIdMoneda: function() { |
| 210 | return { | 153 | return { |
| 211 | then: function() {} | 154 | then: function() {} |
| 212 | }; | 155 | }; |
| 213 | } | 156 | } |
| 214 | }, | 157 | }, |
| 215 | focaBotoneraLateralService: {}, | 158 | focaBotoneraLateralService: {}, |
| 216 | focaModalService: focaModalService, | 159 | focaModalService: focaModalService, |
| 217 | notaPedidoBusinessService: {}, | 160 | notaPedidoBusinessService: {}, |
| 218 | $rootScope: { | 161 | $rootScope: { |
| 219 | $on: function() { } | 162 | $on: function() { } |
| 220 | }, | 163 | }, |
| 221 | focaSeguimientoService: {}, | 164 | focaSeguimientoService: {}, |
| 222 | APP: {}, | 165 | APP: {}, |
| 223 | focaLoginService: {}, | 166 | focaLoginService: {}, |
| 224 | $localStorage: {}, | 167 | $localStorage: {}, |
| 225 | $watch: function() { }, | 168 | $watch: function() { }, |
| 226 | $broadcast: function() {} | 169 | $broadcast: function() {} |
| 227 | }); | 170 | }); |
| 228 | 171 | ||
| 229 | scope.notaPedido = { | 172 | scope.notaPedido = { |
| 230 | vendedor: { | 173 | vendedor: { |
| 231 | id: true | 174 | id: true |
| 232 | }, | 175 | }, |
| 233 | cliente:{ | 176 | cliente:{ |
| 234 | COD: true | 177 | COD: true |
| 235 | }, | 178 | }, |
| 236 | proveedor:{ | 179 | proveedor:{ |
| 237 | COD: null | 180 | COD: null |
| 238 | } | 181 | } |
| 239 | }; | 182 | }; |
| 240 | 183 | ||
| 241 | //act | 184 | //act |
| 242 | spyOn(focaModalService, 'alert'); | 185 | spyOn(focaModalService, 'alert'); |
| 243 | scope.crearNotaPedido(); | 186 | scope.crearNotaPedido(); |
| 244 | 187 | ||
| 245 | //expect | 188 | //expect |
| 246 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Proveedor'); | 189 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Proveedor'); |
| 247 | }); | 190 | }); |
| 248 | 191 | ||
| 249 | it('funcion $scope.crearNotaPedido muestra alerta cuando Moneda es null', function() { | 192 | it('funcion $scope.crearNotaPedido muestra alerta cuando Moneda es null', function() { |
| 250 | 193 | ||
| 251 | //arrange | 194 | //arrange |
| 252 | var scope = { | 195 | var scope = { |
| 253 | $watch: function() { }, | 196 | $watch: function() { }, |
| 254 | $broadcast: function() {} | 197 | $broadcast: function() {} |
| 255 | }; | 198 | }; |
| 256 | var focaModalService = { | 199 | var focaModalService = { |
| 257 | alert: function() { } | 200 | alert: function() { } |
| 258 | }; | 201 | }; |
| 259 | 202 | ||
| 260 | $controler('notaPedidoCtrl', { | 203 | $controler('notaPedidoCtrl', { |
| 261 | $scope: scope, | 204 | $scope: scope, |
| 262 | $uibModal: {}, | 205 | $uibModal: {}, |
| 263 | $location: {}, | 206 | $location: {}, |
| 264 | $filter: filter, | 207 | $filter: filter, |
| 265 | $timeout: timeout, | 208 | $timeout: timeout, |
| 266 | crearNotaPedidoService: { | 209 | crearNotaPedidoService: { |
| 267 | getNumeroNotaPedido: function() { | 210 | getNumeroNotaPedido: function() { |
| 268 | return { | 211 | return { |
| 269 | then: function() { } | 212 | then: function() { } |
| 270 | }; | 213 | }; |
| 271 | }, | 214 | }, |
| 272 | getBotonera: function() { }, | 215 | getBotonera: function() { }, |
| 273 | getCotizacionByIdMoneda: function() { | 216 | getCotizacionByIdMoneda: function() { |
| 274 | return { | 217 | return { |
| 275 | then: function() {} | 218 | then: function() {} |
| 276 | }; | 219 | }; |
| 277 | } | 220 | } |
| 278 | }, | 221 | }, |
| 279 | focaBotoneraLateralService: {}, | 222 | focaBotoneraLateralService: {}, |
| 280 | focaModalService: focaModalService, | 223 | focaModalService: focaModalService, |
| 281 | notaPedidoBusinessService: {}, | 224 | notaPedidoBusinessService: {}, |
| 282 | $rootScope: { | 225 | $rootScope: { |
| 283 | $on: function() { } | 226 | $on: function() { } |
| 284 | }, | 227 | }, |
| 285 | focaSeguimientoService: {}, | 228 | focaSeguimientoService: {}, |
| 286 | APP: {}, | 229 | APP: {}, |
| 287 | focaLoginService: {}, | 230 | focaLoginService: {}, |
| 288 | $localStorage: {}, | 231 | $localStorage: {}, |
| 289 | $watch: function() { }, | 232 | $watch: function() { }, |
| 290 | $broadcast: function() {} | 233 | $broadcast: function() {} |
| 291 | }); | 234 | }); |
| 292 | 235 | ||
| 293 | scope.notaPedido = { | 236 | scope.notaPedido = { |
| 294 | vendedor: { | 237 | vendedor: { |
| 295 | id: true | 238 | id: true |
| 296 | }, | 239 | }, |
| 297 | cliente:{ | 240 | cliente:{ |
| 298 | COD: true | 241 | COD: true |
| 299 | }, | 242 | }, |
| 300 | proveedor:{ | 243 | proveedor:{ |
| 301 | COD: true | 244 | COD: true |
| 302 | }, | 245 | }, |
| 303 | cotizacion: { | 246 | cotizacion: { |
| 304 | ID: true, | 247 | ID: true, |
| 305 | moneda:{ | 248 | moneda:{ |
| 306 | ID: null | 249 | ID: null |
| 307 | } | 250 | } |
| 308 | } | 251 | } |
| 309 | }; | 252 | }; |
| 310 | 253 | ||
| 311 | //act | 254 | //act |
| 312 | spyOn(focaModalService, 'alert'); | 255 | spyOn(focaModalService, 'alert'); |
| 313 | scope.crearNotaPedido(); | 256 | scope.crearNotaPedido(); |
| 314 | 257 | ||
| 315 | //expect | 258 | //expect |
| 316 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Moneda'); | 259 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Moneda'); |
| 317 | }); | 260 | }); |
| 318 | 261 | ||
| 319 | it('funcion $scope.crearNotaPedido muestra alerta cuando cotizacion es null', function() { | 262 | it('funcion $scope.crearNotaPedido muestra alerta cuando cotizacion es null', function() { |
| 320 | 263 | ||
| 321 | //arrange | 264 | //arrange |
| 322 | var scope = { | 265 | var scope = { |
| 323 | $watch: function() { }, | 266 | $watch: function() { }, |
| 324 | $broadcast: function() {} | 267 | $broadcast: function() {} |
| 325 | }; | 268 | }; |
| 326 | var focaModalService = { | 269 | var focaModalService = { |
| 327 | alert: function() { } | 270 | alert: function() { } |
| 328 | }; | 271 | }; |
| 329 | 272 | ||
| 330 | $controler('notaPedidoCtrl', { | 273 | $controler('notaPedidoCtrl', { |
| 331 | $scope: scope, | 274 | $scope: scope, |
| 332 | $uibModal: {}, | 275 | $uibModal: {}, |
| 333 | $location: {}, | 276 | $location: {}, |
| 334 | $filter: filter, | 277 | $filter: filter, |
| 335 | $timeout: timeout, | 278 | $timeout: timeout, |
| 336 | crearNotaPedidoService: { | 279 | crearNotaPedidoService: { |
| 337 | getNumeroNotaPedido: function() { | 280 | getNumeroNotaPedido: function() { |
| 338 | return { | 281 | return { |
| 339 | then: function() { } | 282 | then: function() { } |
| 340 | }; | 283 | }; |
| 341 | }, | 284 | }, |
| 342 | getBotonera: function() { }, | 285 | getBotonera: function() { }, |
| 343 | getCotizacionByIdMoneda: function() { | 286 | getCotizacionByIdMoneda: function() { |
| 344 | return { | 287 | return { |
| 345 | then: function() {} | 288 | then: function() {} |
| 346 | }; | 289 | }; |
| 347 | } | 290 | } |
| 348 | }, | 291 | }, |
| 349 | focaBotoneraLateralService: {}, | 292 | focaBotoneraLateralService: {}, |
| 350 | focaModalService: focaModalService, | 293 | focaModalService: focaModalService, |
| 351 | notaPedidoBusinessService: {}, | 294 | notaPedidoBusinessService: {}, |
| 352 | $rootScope: { | 295 | $rootScope: { |
| 353 | $on: function() { } | 296 | $on: function() { } |
| 354 | }, | 297 | }, |
| 355 | focaSeguimientoService: {}, | 298 | focaSeguimientoService: {}, |
| 356 | APP: {}, | 299 | APP: {}, |
| 357 | focaLoginService: {}, | 300 | focaLoginService: {}, |
| 358 | $localStorage: {}, | 301 | $localStorage: {}, |
| 359 | $watch: function() { }, | 302 | $watch: function() { }, |
| 360 | $broadcast: function() {} | 303 | $broadcast: function() {} |
| 361 | }); | 304 | }); |
| 362 | 305 | ||
| 363 | scope.notaPedido = { | 306 | scope.notaPedido = { |
| 364 | vendedor: { | 307 | vendedor: { |
| 365 | id: true | 308 | id: true |
| 366 | }, | 309 | }, |
| 367 | cliente:{ | 310 | cliente:{ |
| 368 | COD: true | 311 | COD: true |
| 369 | }, | 312 | }, |
| 370 | proveedor:{ | 313 | proveedor:{ |
| 371 | COD: true | 314 | COD: true |
| 372 | }, | 315 | }, |
| 373 | cotizacion:{ | 316 | cotizacion:{ |
| 374 | ID: null, | 317 | ID: null, |
| 375 | moneda: { | 318 | moneda: { |
| 376 | ID: true | 319 | ID: true |
| 377 | } | 320 | } |
| 378 | } | 321 | } |
| 379 | }; | 322 | }; |
| 380 | 323 | ||
| 381 | //act | 324 | //act |
| 382 | spyOn(focaModalService, 'alert'); | 325 | spyOn(focaModalService, 'alert'); |
| 383 | scope.crearNotaPedido(); | 326 | scope.crearNotaPedido(); |
| 384 | 327 | ||
| 385 | //expect | 328 | //expect |
| 386 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cotización'); | 329 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Cotización'); |
| 387 | }); | 330 | }); |
| 388 | 331 | ||
| 389 | it('funcion $scope.crearNotaPedido muestra alerta cuando plazos es null', function() { | 332 | it('funcion $scope.crearNotaPedido muestra alerta cuando plazos es null', function() { |
| 390 | 333 | ||
| 391 | //arrange | 334 | //arrange |
| 392 | var scope = { | 335 | var scope = { |
| 393 | $watch: function() { }, | 336 | $watch: function() { }, |
| 394 | $broadcast: function() {} | 337 | $broadcast: function() {} |
| 395 | }; | 338 | }; |
| 396 | var focaModalService = { | 339 | var focaModalService = { |
| 397 | alert: function() { } | 340 | alert: function() { } |
| 398 | }; | 341 | }; |
| 399 | 342 | ||
| 400 | $controler('notaPedidoCtrl', { | 343 | $controler('notaPedidoCtrl', { |
| 401 | $scope: scope, | 344 | $scope: scope, |
| 402 | $uibModal: {}, | 345 | $uibModal: {}, |
| 403 | $location: {}, | 346 | $location: {}, |
| 404 | $filter: filter, | 347 | $filter: filter, |
| 405 | $timeout: timeout, | 348 | $timeout: timeout, |
| 406 | crearNotaPedidoService: { | 349 | crearNotaPedidoService: { |
| 407 | getNumeroNotaPedido: function() { | 350 | getNumeroNotaPedido: function() { |
| 408 | return { | 351 | return { |
| 409 | then: function() { } | 352 | then: function() { } |
| 410 | }; | 353 | }; |
| 411 | }, | 354 | }, |
| 412 | getBotonera: function() { }, | 355 | getBotonera: function() { }, |
| 413 | getCotizacionByIdMoneda: function() { | 356 | getCotizacionByIdMoneda: function() { |
| 414 | return { | 357 | return { |
| 415 | then: function() {} | 358 | then: function() {} |
| 416 | }; | 359 | }; |
| 417 | } | 360 | } |
| 418 | }, | 361 | }, |
| 419 | focaBotoneraLateralService: {}, | 362 | focaBotoneraLateralService: {}, |
| 420 | focaModalService: focaModalService, | 363 | focaModalService: focaModalService, |
| 421 | notaPedidoBusinessService: {}, | 364 | notaPedidoBusinessService: {}, |
| 422 | $rootScope: { | 365 | $rootScope: { |
| 423 | $on: function() { } | 366 | $on: function() { } |
| 424 | }, | 367 | }, |
| 425 | focaSeguimientoService: {}, | 368 | focaSeguimientoService: {}, |
| 426 | APP: {}, | 369 | APP: {}, |
| 427 | focaLoginService: {}, | 370 | focaLoginService: {}, |
| 428 | $localStorage: {}, | 371 | $localStorage: {}, |
| 429 | $watch: function() { }, | 372 | $watch: function() { }, |
| 430 | $broadcast: function() {} | 373 | $broadcast: function() {} |
| 431 | }); | 374 | }); |
| 432 | 375 | ||
| 433 | scope.notaPedido = { | 376 | scope.notaPedido = { |
| 434 | vendedor: { | 377 | vendedor: { |
| 435 | id: true | 378 | id: true |
| 436 | }, | 379 | }, |
| 437 | cliente:{ | 380 | cliente:{ |
| 438 | COD: true | 381 | COD: true |
| 439 | }, | 382 | }, |
| 440 | proveedor:{ | 383 | proveedor:{ |
| 441 | COD: true | 384 | COD: true |
| 442 | }, | 385 | }, |
| 443 | cotizacion:{ | 386 | cotizacion:{ |
| 444 | ID: true, | 387 | ID: true, |
| 445 | moneda:{ | 388 | moneda:{ |
| 446 | ID: true | 389 | ID: true |
| 447 | } | 390 | } |
| 448 | } | 391 | } |
| 449 | }; | 392 | }; |
| 450 | 393 | ||
| 451 | scope.plazosPagos = null; | 394 | scope.plazosPagos = null; |
| 452 | 395 | ||
| 453 | //act | 396 | //act |
| 454 | spyOn(focaModalService, 'alert'); | 397 | spyOn(focaModalService, 'alert'); |
| 455 | scope.crearNotaPedido(); | 398 | scope.crearNotaPedido(); |
| 456 | 399 | ||
| 457 | //expect | 400 | //expect |
| 458 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Precios y Condiciones'); | 401 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Precios y Condiciones'); |
| 459 | }); | 402 | }); |
| 460 | 403 | ||
| 461 | it('funcion $scope.crearNotaPedido muestra alerta cuando flete es null', function() { | 404 | it('funcion $scope.crearNotaPedido muestra alerta cuando flete es null', function() { |
| 462 | 405 | ||
| 463 | //arrange | 406 | //arrange |
| 464 | var scope = { | 407 | var scope = { |
| 465 | $watch: function() { }, | 408 | $watch: function() { }, |
| 466 | $broadcast: function() {} | 409 | $broadcast: function() {} |
| 467 | }; | 410 | }; |
| 468 | var focaModalService = { | 411 | var focaModalService = { |
| 469 | alert: function() { } | 412 | alert: function() { } |
| 470 | }; | 413 | }; |
| 471 | 414 | ||
| 472 | $controler('notaPedidoCtrl', { | 415 | $controler('notaPedidoCtrl', { |
| 473 | $scope: scope, | 416 | $scope: scope, |
| 474 | $uibModal: {}, | 417 | $uibModal: {}, |
| 475 | $location: {}, | 418 | $location: {}, |
| 476 | $filter: filter, | 419 | $filter: filter, |
| 477 | $timeout: timeout, | 420 | $timeout: timeout, |
| 478 | crearNotaPedidoService: { | 421 | crearNotaPedidoService: { |
| 479 | getNumeroNotaPedido: function() { | 422 | getNumeroNotaPedido: function() { |
| 480 | return { | 423 | return { |
| 481 | then: function() { } | 424 | then: function() { } |
| 482 | }; | 425 | }; |
| 483 | }, | 426 | }, |
| 484 | getBotonera: function() { }, | 427 | getBotonera: function() { }, |
| 485 | getCotizacionByIdMoneda: function() { | 428 | getCotizacionByIdMoneda: function() { |
| 486 | return { | 429 | return { |
| 487 | then: function() {} | 430 | then: function() {} |
| 488 | }; | 431 | }; |
| 489 | } | 432 | } |
| 490 | }, | 433 | }, |
| 491 | focaBotoneraLateralService: {}, | 434 | focaBotoneraLateralService: {}, |
| 492 | focaModalService: focaModalService, | 435 | focaModalService: focaModalService, |
| 493 | notaPedidoBusinessService: {}, | 436 | notaPedidoBusinessService: {}, |
| 494 | $rootScope: { | 437 | $rootScope: { |
| 495 | $on: function() { } | 438 | $on: function() { } |
| 496 | }, | 439 | }, |
| 497 | focaSeguimientoService: {}, | 440 | focaSeguimientoService: {}, |
| 498 | APP: {}, | 441 | APP: {}, |
| 499 | focaLoginService: {}, | 442 | focaLoginService: {}, |
| 500 | $localStorage: {}, | 443 | $localStorage: {}, |
| 501 | $watch: function() { }, | 444 | $watch: function() { }, |
| 502 | $broadcast: function() {} | 445 | $broadcast: function() {} |
| 503 | }); | 446 | }); |
| 504 | 447 | ||
| 505 | scope.notaPedido = { | 448 | scope.notaPedido = { |
| 506 | vendedor: { | 449 | vendedor: { |
| 507 | id: true | 450 | id: true |
| 508 | }, | 451 | }, |
| 509 | cliente:{ | 452 | cliente:{ |
| 510 | COD: true | 453 | COD: true |
| 511 | }, | 454 | }, |
| 512 | proveedor:{ | 455 | proveedor:{ |
| 513 | COD: true | 456 | COD: true |
| 514 | }, | 457 | }, |
| 515 | cotizacion:{ | 458 | cotizacion:{ |
| 516 | ID: true, | 459 | ID: true, |
| 517 | moneda:{ | 460 | moneda:{ |
| 518 | ID: true | 461 | ID: true |
| 519 | } | 462 | } |
| 520 | }, | 463 | }, |
| 521 | flete: null, | 464 | flete: null, |
| 522 | notaPedidoPlazo: [] | 465 | notaPedidoPlazo: [] |
| 523 | }; | 466 | }; |
| 524 | 467 | ||
| 525 | scope.plazosPagos = true; | 468 | scope.plazosPagos = true; |
| 526 | 469 | ||
| 527 | //act | 470 | //act |
| 528 | spyOn(focaModalService, 'alert'); | 471 | spyOn(focaModalService, 'alert'); |
| 529 | scope.crearNotaPedido(); | 472 | scope.crearNotaPedido(); |
| 530 | 473 | ||
| 531 | //expect | 474 | //expect |
| 532 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Flete'); | 475 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Flete'); |
| 533 | }); | 476 | }); |
| 534 | 477 | ||
| 535 | it('funcion $scope.crearNotaPedido muestra alerta cuando domicilio es null', function() { | 478 | it('funcion $scope.crearNotaPedido muestra alerta cuando domicilio es null', function() { |
| 536 | 479 | ||
| 537 | //arrange | 480 | //arrange |
| 538 | var scope = { | 481 | var scope = { |
| 539 | $watch: function() { }, | 482 | $watch: function() { }, |
| 540 | $broadcast: function() {} | 483 | $broadcast: function() {} |
| 541 | }; | 484 | }; |
| 542 | var focaModalService = { | 485 | var focaModalService = { |
| 543 | alert: function() { } | 486 | alert: function() { } |
| 544 | }; | 487 | }; |
| 545 | 488 | ||
| 546 | $controler('notaPedidoCtrl', { | 489 | $controler('notaPedidoCtrl', { |
| 547 | $scope: scope, | 490 | $scope: scope, |
| 548 | $uibModal: {}, | 491 | $uibModal: {}, |
| 549 | $location: {}, | 492 | $location: {}, |
| 550 | $filter: filter, | 493 | $filter: filter, |
| 551 | $timeout: timeout, | 494 | $timeout: timeout, |
| 552 | crearNotaPedidoService: { | 495 | crearNotaPedidoService: { |
| 553 | getNumeroNotaPedido: function() { | 496 | getNumeroNotaPedido: function() { |
| 554 | return { | 497 | return { |
| 555 | then: function() { } | 498 | then: function() { } |
| 556 | }; | 499 | }; |
| 557 | }, | 500 | }, |
| 558 | getBotonera: function() { }, | 501 | getBotonera: function() { }, |
| 559 | getCotizacionByIdMoneda: function() { | 502 | getCotizacionByIdMoneda: function() { |
| 560 | return { | 503 | return { |
| 561 | then: function() {} | 504 | then: function() {} |
| 562 | }; | 505 | }; |
| 563 | } | 506 | } |
| 564 | }, | 507 | }, |
| 565 | focaBotoneraLateralService: {}, | 508 | focaBotoneraLateralService: {}, |
| 566 | focaModalService: focaModalService, | 509 | focaModalService: focaModalService, |
| 567 | notaPedidoBusinessService: {}, | 510 | notaPedidoBusinessService: {}, |
| 568 | $rootScope: { | 511 | $rootScope: { |
| 569 | $on: function() { } | 512 | $on: function() { } |
| 570 | }, | 513 | }, |
| 571 | focaSeguimientoService: {}, | 514 | focaSeguimientoService: {}, |
| 572 | APP: {}, | 515 | APP: {}, |
| 573 | focaLoginService: {}, | 516 | focaLoginService: {}, |
| 574 | $localStorage: {}, | 517 | $localStorage: {}, |
| 575 | $watch: function() { }, | 518 | $watch: function() { }, |
| 576 | $broadcast: function() {} | 519 | $broadcast: function() {} |
| 577 | }); | 520 | }); |
| 578 | 521 | ||
| 579 | scope.notaPedido = { | 522 | scope.notaPedido = { |
| 580 | vendedor: { | 523 | vendedor: { |
| 581 | id: true | 524 | id: true |
| 582 | }, | 525 | }, |
| 583 | cliente:{ | 526 | cliente:{ |
| 584 | COD: true | 527 | COD: true |
| 585 | }, | 528 | }, |
| 586 | proveedor:{ | 529 | proveedor:{ |
| 587 | COD: true | 530 | COD: true |
| 588 | }, | 531 | }, |
| 589 | cotizacion:{ | 532 | cotizacion:{ |
| 590 | ID: true, | 533 | ID: true, |
| 591 | moneda:{ | 534 | moneda:{ |
| 592 | ID: true | 535 | ID: true |
| 593 | } | 536 | } |
| 594 | }, | 537 | }, |
| 595 | flete: true, | 538 | flete: true, |
| 596 | domicilioStamp: null, | 539 | domicilioStamp: null, |
| 597 | notaPedidoPlazo: [] | 540 | notaPedidoPlazo: [] |
| 598 | }; | 541 | }; |
| 599 | 542 | ||
| 600 | scope.plazosPagos = true; | 543 | scope.plazosPagos = true; |
| 601 | 544 | ||
| 602 | //act | 545 | //act |
| 603 | spyOn(focaModalService, 'alert'); | 546 | spyOn(focaModalService, 'alert'); |
| 604 | scope.crearNotaPedido(); | 547 | scope.crearNotaPedido(); |
| 605 | 548 | ||
| 606 | //expect | 549 | //expect |
| 607 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Domicilio'); | 550 | expect(focaModalService.alert).toHaveBeenCalledWith('Ingrese Domicilio'); |
| 608 | }); | 551 | }); |
| 609 | 552 | ||
| 610 | it('funcion $scope.crearNotaPedido muestra alerta cuando no se cargaron articulos', | 553 | it('funcion $scope.crearNotaPedido muestra alerta cuando no se cargaron articulos', |
| 611 | function() | 554 | function() |
| 612 | { | 555 | { |
| 613 | 556 | ||
| 614 | //arrange | 557 | //arrange |
| 615 | var scope = { | 558 | var scope = { |
| 616 | $watch: function() { }, | 559 | $watch: function() { }, |
| 617 | $broadcast: function() {} | 560 | $broadcast: function() {} |
| 618 | }; | 561 | }; |
| 619 | var focaModalService = { | 562 | var focaModalService = { |
| 620 | alert: function() { } | 563 | alert: function() { } |
| 621 | }; | 564 | }; |
| 622 | 565 | ||
| 623 | $controler('notaPedidoCtrl', { | 566 | $controler('notaPedidoCtrl', { |
| 624 | $scope: scope, | 567 | $scope: scope, |
| 625 | $uibModal: {}, | 568 | $uibModal: {}, |
| 626 | $location: {}, | 569 | $location: {}, |
| 627 | $filter: filter, | 570 | $filter: filter, |
| 628 | $timeout: timeout, | 571 | $timeout: timeout, |
| 629 | crearNotaPedidoService: { | 572 | crearNotaPedidoService: { |
| 630 | getNumeroNotaPedido: function() { | 573 | getNumeroNotaPedido: function() { |
| 631 | return { | 574 | return { |
| 632 | then: function() {} | 575 | then: function() {} |
| 633 | }; | 576 | }; |
| 634 | }, | 577 | }, |
| 635 | getBotonera: function() { }, | 578 | getBotonera: function() { }, |
| 636 | getCotizacionByIdMoneda: function() { | 579 | getCotizacionByIdMoneda: function() { |
| 637 | return { | 580 | return { |
| 638 | then: function() {} | 581 | then: function() {} |
| 639 | }; | 582 | }; |
| 640 | }, | 583 | }, |
| 641 | crearNotaPedido: function() { | 584 | crearNotaPedido: function() { |
| 642 | return { | 585 | return { |
| 643 | then: function() { } | 586 | then: function() { } |
| 644 | }; | 587 | }; |
| 645 | } | 588 | } |
| 646 | }, | 589 | }, |
| 647 | focaBotoneraLateralService: { | 590 | focaBotoneraLateralService: { |
| 648 | startGuardar: function() {} | 591 | startGuardar: function() {} |
| 649 | }, | 592 | }, |
| 650 | focaModalService: focaModalService, | 593 | focaModalService: focaModalService, |
| 651 | notaPedidoBusinessService: {}, | 594 | notaPedidoBusinessService: {}, |
| 652 | $rootScope: { | 595 | $rootScope: { |
| 653 | $on: function() { } | 596 | $on: function() { } |
| 654 | }, | 597 | }, |
| 655 | focaSeguimientoService: {}, | 598 | focaSeguimientoService: {}, |
| 656 | APP: {}, | 599 | APP: {}, |
| 657 | focaLoginService: {}, | 600 | focaLoginService: {}, |
| 658 | $localStorage: {}, | 601 | $localStorage: {}, |
| 659 | $watch: function() { }, | 602 | $watch: function() { }, |
| 660 | $broadcast: function() {} | 603 | $broadcast: function() {} |
| 661 | }); | 604 | }); |
| 662 | 605 | ||
| 663 | scope.notaPedido = { | 606 | scope.notaPedido = { |
| 664 | vendedor: { | 607 | vendedor: { |
| 665 | id: true | 608 | id: true |
| 666 | }, | 609 | }, |
| 667 | cliente:{ | 610 | cliente:{ |
| 668 | COD: true | 611 | COD: true |
| 669 | }, | 612 | }, |
| 670 | proveedor:{ | 613 | proveedor:{ |
| 671 | COD: true | 614 | COD: true |
| 672 | }, | 615 | }, |
| 673 | cotizacion:{ | 616 | cotizacion:{ |
| 674 | ID: true, | 617 | ID: true, |
| 675 | moneda:{ | 618 | moneda:{ |
| 676 | ID: true | 619 | ID: true |
| 677 | } | 620 | } |
| 678 | }, | 621 | }, |
| 679 | precioCondicion: { | 622 | precioCondicion: { |
| 680 | id: true | 623 | id: true |
| 681 | }, | 624 | }, |
| 682 | domicilio: { | 625 | domicilio: { |
| 683 | id: true | 626 | id: true |
| 684 | }, | 627 | }, |
| 685 | flete: true, | 628 | flete: true, |
| 686 | domicilioStamp: true, | 629 | domicilioStamp: true, |
| 687 | notaPedidoPlazo: [], | 630 | notaPedidoPlazo: [], |
| 688 | articulosNotaPedido: [], | 631 | articulosNotaPedido: [], |
| 689 | fechaCarga: true | 632 | fechaCarga: true |
| 690 | }; | 633 | }; |
| 691 | 634 | ||
| 692 | scope.articulosTabla = []; | 635 | scope.articulosTabla = []; |
| 693 | 636 | ||
| 694 | //act | 637 | //act |
| 695 | spyOn(focaModalService, 'alert'); | 638 | spyOn(focaModalService, 'alert'); |
| 696 | scope.crearNotaPedido(); | 639 | scope.crearNotaPedido(); |
| 697 | 640 | ||
| 698 | //expect | 641 | //expect |
| 699 | expect(focaModalService.alert) | 642 | expect(focaModalService.alert) |
| 700 | .toHaveBeenCalledWith('Debe cargar al menos un articulo'); | 643 | .toHaveBeenCalledWith('Debe cargar al menos un articulo'); |
| 701 | }); | 644 | }); |
| 702 | 645 | ||
| 703 | it('funcion $scope.crearNotaPedido llama startGuardar', function() { | 646 | it('funcion $scope.crearNotaPedido llama startGuardar', function() { |
| 704 | 647 | ||
| 705 | //arrange | 648 | //arrange |
| 706 | var scope = { | 649 | var scope = { |
| 707 | $watch: function() { }, | 650 | $watch: function() { }, |
| 708 | $broadcast: function() {} | 651 | $broadcast: function() {} |
| 709 | }; | 652 | }; |
| 710 | var focaBotoneraLateralService = { | 653 | var focaBotoneraLateralService = { |
| 711 | startGuardar: function() { } | 654 | startGuardar: function() { } |
| 712 | }; | 655 | }; |
| 713 | 656 | ||
| 714 | $controler('notaPedidoCtrl', { | 657 | $controler('notaPedidoCtrl', { |
| 715 | $scope: scope, | 658 | $scope: scope, |
| 716 | $uibModal: {}, | 659 | $uibModal: {}, |
| 717 | $location: {}, | 660 | $location: {}, |
| 718 | $filter: filter, | 661 | $filter: filter, |
| 719 | $timeout: timeout, | 662 | $timeout: timeout, |
| 720 | crearNotaPedidoService: { | 663 | crearNotaPedidoService: { |
| 721 | getNumeroNotaPedido: function() { | 664 | getNumeroNotaPedido: function() { |
| 722 | return { | 665 | return { |
| 723 | then: function() { } | 666 | then: function() { } |
| 724 | }; | 667 | }; |
| 725 | }, | 668 | }, |
| 726 | getBotonera: function() { }, | 669 | getBotonera: function() { }, |
| 727 | getCotizacionByIdMoneda: function() { | 670 | getCotizacionByIdMoneda: function() { |
| 728 | return { | 671 | return { |
| 729 | then: function() {} | 672 | then: function() {} |
| 730 | }; | 673 | }; |
| 731 | }, | 674 | }, |
| 732 | crearNotaPedido: function() { | 675 | crearNotaPedido: function() { |
| 733 | return { | 676 | return { |
| 734 | then: function() { } | 677 | then: function() { } |
| 735 | }; | 678 | }; |
| 736 | } | 679 | } |
| 737 | }, | 680 | }, |
| 738 | focaBotoneraLateralService: focaBotoneraLateralService, | 681 | focaBotoneraLateralService: focaBotoneraLateralService, |
| 739 | focaModalService: { | 682 | focaModalService: { |
| 740 | alert: function() {} | 683 | alert: function() {} |
| 741 | }, | 684 | }, |
| 742 | notaPedidoBusinessService: {}, | 685 | notaPedidoBusinessService: {}, |
| 743 | $rootScope: { | 686 | $rootScope: { |
| 744 | $on: function() { } | 687 | $on: function() { } |
| 745 | }, | 688 | }, |
| 746 | focaSeguimientoService: {}, | 689 | focaSeguimientoService: {}, |
| 747 | APP: {}, | 690 | APP: {}, |
| 748 | focaLoginService: {}, | 691 | focaLoginService: {}, |
| 749 | $localStorage: {}, | 692 | $localStorage: {}, |
| 750 | $watch: function() { }, | 693 | $watch: function() { }, |
| 751 | $broadcast: function() {} | 694 | $broadcast: function() {} |
| 752 | }); | 695 | }); |
| 753 | 696 | ||
| 754 | scope.notaPedido = { | 697 | scope.notaPedido = { |
| 755 | vendedor: { | 698 | vendedor: { |
| 756 | id: true | 699 | id: true |
| 757 | }, | 700 | }, |
| 758 | cliente:{ | 701 | cliente:{ |
| 759 | COD: true | 702 | COD: true |
| 760 | }, | 703 | }, |
| 761 | proveedor:{ | 704 | proveedor:{ |
| 762 | COD: true | 705 | COD: true |
| 763 | }, | 706 | }, |
| 764 | cotizacion:{ | 707 | cotizacion:{ |
| 765 | ID: true, | 708 | ID: true, |
| 766 | moneda:{ | 709 | moneda:{ |
| 767 | ID: true | 710 | ID: true |
| 768 | } | 711 | } |
| 769 | }, | 712 | }, |
| 770 | flete: true, | 713 | flete: true, |
| 771 | domicilioStamp: true, | 714 | domicilioStamp: true, |
| 772 | domicilio: { | 715 | domicilio: { |
| 773 | id: true | 716 | id: true |
| 774 | }, | 717 | }, |
| 775 | notaPedidoPlazo: [], | 718 | notaPedidoPlazo: [], |
| 776 | articulosNotaPedido: true, | 719 | articulosNotaPedido: true, |
| 777 | fechaCarga: true | 720 | fechaCarga: true |
| 778 | }; | 721 | }; |
| 779 | 722 | ||
| 780 | scope.plazosPagos = true; | 723 | scope.plazosPagos = true; |
| 781 | scope.articulosTabla = [1]; | 724 | scope.articulosTabla = [1]; |
| 782 | 725 | ||
| 783 | //act | 726 | //act |
| 784 | spyOn(focaBotoneraLateralService, 'startGuardar'); | 727 | spyOn(focaBotoneraLateralService, 'startGuardar'); |
| 785 | scope.crearNotaPedido(scope.notaPedido); | 728 | scope.crearNotaPedido(scope.notaPedido); |
| 786 | 729 | ||
| 787 | //expect | 730 | //expect |
| 788 | expect(focaBotoneraLateralService.startGuardar).toHaveBeenCalled(); | 731 | expect(focaBotoneraLateralService.startGuardar).toHaveBeenCalled(); |
| 789 | }); | 732 | }); |
| 790 | 733 | ||
| 791 | it('funcion $scope.crearNotaPedido llama funciones al guardar', function(done) { | 734 | it('funcion $scope.crearNotaPedido llama funciones al guardar', function(done) { |
| 792 | 735 | ||
| 793 | //arrange | 736 | //arrange |
| 794 | var scope = { | 737 | var scope = { |
| 795 | $watch: function() { }, | 738 | $watch: function() { }, |
| 796 | $broadcast: function() {} | 739 | $broadcast: function() {} |
| 797 | }; | 740 | }; |
| 798 | var focaBotoneraLateralService = { | 741 | var focaBotoneraLateralService = { |
| 799 | startGuardar: function() { }, | 742 | startGuardar: function() { }, |
| 800 | endGuardar: function() { } | 743 | endGuardar: function() { } |
| 801 | }; | 744 | }; |
| 802 | var focaSeguimientoService = { | 745 | var focaSeguimientoService = { |
| 803 | guardarPosicion: function() { } | 746 | guardarPosicion: function() { } |
| 804 | }; | 747 | }; |
| 805 | var notaPedidoBusinessService = { | 748 | var notaPedidoBusinessService = { |
| 806 | addArticulos: function() { }, | 749 | addArticulos: function() { }, |
| 807 | addEstado: function() { } | 750 | addEstado: function() { } |
| 808 | }; | 751 | }; |
| 809 | var crearNotaPedidoService = { | 752 | var crearNotaPedidoService = { |
| 810 | getBotonera: function() { }, | 753 | getBotonera: function() { }, |
| 811 | getCotizacionByIdMoneda: function() { | 754 | getCotizacionByIdMoneda: function() { |
| 812 | return { | 755 | return { |
| 813 | then: function() {} | 756 | then: function() {} |
| 814 | }; | 757 | }; |
| 815 | }, | 758 | }, |
| 816 | crearNotaPedido: function() { | 759 | crearNotaPedido: function() { |
| 817 | return { | 760 | return { |
| 818 | then: function() { } | 761 | then: function() { } |
| 819 | }; | 762 | }; |
| 820 | }, | 763 | }, |
| 821 | getNumeroNotaPedido: function() { | 764 | getNumeroNotaPedido: function() { |
| 822 | return { | 765 | return { |
| 823 | then: function() { } | 766 | then: function() { } |
| 824 | }; | 767 | }; |
| 825 | } | 768 | } |
| 826 | }; | 769 | }; |
| 827 | 770 | ||
| 828 | $controler('notaPedidoCtrl', { | 771 | $controler('notaPedidoCtrl', { |
| 829 | $scope: scope, | 772 | $scope: scope, |
| 830 | $uibModal: {}, | 773 | $uibModal: {}, |
| 831 | $location: {}, | 774 | $location: {}, |
| 832 | $filter: filter, | 775 | $filter: filter, |
| 833 | $timeout: timeout, | 776 | $timeout: timeout, |
| 834 | crearNotaPedidoService: crearNotaPedidoService, | 777 | crearNotaPedidoService: crearNotaPedidoService, |
| 835 | focaBotoneraLateralService: focaBotoneraLateralService, | 778 | focaBotoneraLateralService: focaBotoneraLateralService, |
| 836 | focaModalService: { | 779 | focaModalService: { |
| 837 | alert: function() {} | 780 | alert: function() {} |
| 838 | }, | 781 | }, |
| 839 | notaPedidoBusinessService: notaPedidoBusinessService, | 782 | notaPedidoBusinessService: notaPedidoBusinessService, |
| 840 | $rootScope: { | 783 | $rootScope: { |
| 841 | $on: function() { } | 784 | $on: function() { } |
| 842 | }, | 785 | }, |
| 843 | focaSeguimientoService: focaSeguimientoService, | 786 | focaSeguimientoService: focaSeguimientoService, |
| 844 | APP: {}, | 787 | APP: {}, |
| 845 | focaLoginService: {}, | 788 | focaLoginService: {}, |
| 846 | $localStorage: {}, | 789 | $localStorage: {}, |
| 847 | $watch: function() { }, | 790 | $watch: function() { }, |
| 848 | $broadcast: function() {} | 791 | $broadcast: function() {} |
| 849 | }); | 792 | }); |
| 850 | 793 | ||
| 851 | scope.notaPedido = { | 794 | scope.notaPedido = { |
| 852 | vendedor: { | 795 | vendedor: { |
| 853 | id: true | 796 | id: true |
| 854 | }, | 797 | }, |
| 855 | cliente:{ | 798 | cliente:{ |
| 856 | COD: true | 799 | COD: true |
| 857 | }, | 800 | }, |
| 858 | proveedor:{ | 801 | proveedor:{ |
| 859 | COD: true | 802 | COD: true |
| 860 | }, | 803 | }, |
| 861 | cotizacion:{ | 804 | cotizacion:{ |
| 862 | ID: true, | 805 | ID: true, |
| 863 | moneda:{ | 806 | moneda:{ |
| 864 | ID: true | 807 | ID: true |
| 865 | } | 808 | } |
| 866 | }, | 809 | }, |
| 867 | flete: true, | 810 | flete: true, |
| 868 | domicilioStamp: true, | 811 | domicilioStamp: true, |
| 869 | domicilio: { | 812 | domicilio: { |
| 870 | id: true | 813 | id: true |
| 871 | }, | 814 | }, |
| 872 | notaPedidoPlazo: [], | 815 | notaPedidoPlazo: [], |
| 873 | articulosNotaPedido: [1], | 816 | articulosNotaPedido: [1], |
| 874 | fechaCarga: true | 817 | fechaCarga: true |
| 875 | }; | 818 | }; |
| 876 | 819 | ||
| 877 | scope.plazosPagos = []; | 820 | scope.plazosPagos = []; |
| 878 | scope.articulosTabla = [1]; | 821 | scope.articulosTabla = [1]; |
| 879 | 822 | ||
| 880 | var promesa = Promise.resolve({ data: 1 }); | 823 | var promesa = Promise.resolve({ data: 1 }); |
| 881 | scope.$broadcast = function() { }; | 824 | scope.$broadcast = function() { }; |
| 882 | 825 | ||
| 883 | //act | 826 | //act |
| 884 | spyOn(crearNotaPedidoService, 'crearNotaPedido').and.returnValue(promesa); | 827 | spyOn(crearNotaPedidoService, 'crearNotaPedido').and.returnValue(promesa); |
| 885 | spyOn(focaSeguimientoService, 'guardarPosicion'); | 828 | spyOn(focaSeguimientoService, 'guardarPosicion'); |
| 886 | spyOn(notaPedidoBusinessService, 'addArticulos'); | 829 | spyOn(notaPedidoBusinessService, 'addArticulos'); |
| 887 | scope.crearNotaPedido(); | 830 | scope.crearNotaPedido(); |
| 888 | //expect | 831 | //expect |
| 889 | 832 | ||
| 890 | promesa.then(function() { | 833 | promesa.then(function() { |
| 891 | expect(focaSeguimientoService.guardarPosicion).toHaveBeenCalled(); | 834 | expect(focaSeguimientoService.guardarPosicion).toHaveBeenCalled(); |
| 892 | expect(notaPedidoBusinessService.addArticulos).toHaveBeenCalled(); | 835 | expect(notaPedidoBusinessService.addArticulos).toHaveBeenCalled(); |
| 893 | done(); | 836 | done(); |
| 894 | }); | 837 | }); |
| 895 | 838 | ||
| 896 | }); | 839 | }); |
| 897 | }); | 840 | }); |
| 898 | }); | 841 | }); |
| 899 | 842 |
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.notaPedido = {}; | 26 | $scope.notaPedido = {}; |
| 27 | $scope.isNumber = angular.isNumber; | 27 | $scope.isNumber = angular.isNumber; |
| 28 | $scope.datepickerAbierto = false; | 28 | $scope.datepickerAbierto = false; |
| 29 | $scope.show = false; | 29 | $scope.show = false; |
| 30 | $scope.cargando = true; | 30 | $scope.cargando = true; |
| 31 | $scope.botonera = crearNotaPedidoService.getBotonera(); | 31 | $scope.botonera = crearNotaPedidoService.getBotonera(); |
| 32 | $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); | 32 | $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); |
| 33 | $scope.comprobante = $filter('rellenarDigitos')(0, 8); | 33 | $scope.comprobante = $filter('rellenarDigitos')(0, 8); |
| 34 | $scope.dateOptions = { | 34 | $scope.dateOptions = { |
| 35 | maxDate: new Date(), | 35 | maxDate: new Date(), |
| 36 | minDate: new Date(2010, 0, 1) | 36 | minDate: new Date(2010, 0, 1) |
| 37 | }; | 37 | }; |
| 38 | 38 | ||
| 39 | //SETEO BOTONERA LATERAL | 39 | //SETEO BOTONERA LATERAL |
| 40 | $timeout(function() { | 40 | $timeout(function() { |
| 41 | focaBotoneraLateralService.showSalir(false); | 41 | focaBotoneraLateralService.showSalir(false); |
| 42 | focaBotoneraLateralService.showPausar(true); | 42 | focaBotoneraLateralService.showPausar(true); |
| 43 | focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido); | 43 | focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido); |
| 44 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 44 | focaBotoneraLateralService.addCustomButton('Salir', salir); |
| 45 | }); | 45 | }); |
| 46 | 46 | ||
| 47 | // SETEA BOTONERA DE FACTURADOR TENIENDO EN CUENTA SI ESTA SETEADO EL VENDEDOR | 47 | // SETEA BOTONERA DE FACTURADOR TENIENDO EN CUENTA SI ESTA SETEADO EL VENDEDOR |
| 48 | if (APP === 'distribuidor') { | 48 | if (APP === 'distribuidor') { |
| 49 | $scope.idVendedor = focaLoginService.getLoginData().vendedorCobrador; | 49 | $scope.idVendedor = focaLoginService.getLoginData().vendedorCobrador; |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' | 52 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' |
| 53 | crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { | 53 | crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { |
| 54 | var monedaPorDefecto = res.data[0]; | 54 | var monedaPorDefecto = res.data[0]; |
| 55 | 55 | ||
| 56 | $scope.notaPedido.cotizacion = Object.assign( | 56 | $scope.notaPedido.cotizacion = Object.assign( |
| 57 | {moneda: monedaPorDefecto}, | 57 | {moneda: monedaPorDefecto}, |
| 58 | monedaPorDefecto.cotizaciones[0] | 58 | monedaPorDefecto.cotizaciones[0] |
| 59 | ); | 59 | ); |
| 60 | $scope.inicial.cotizacion = $scope.notaPedido.cotizacion; | 60 | $scope.inicial.cotizacion = $scope.notaPedido.cotizacion; |
| 61 | }); | 61 | }); |
| 62 | 62 | ||
| 63 | init(); | 63 | init(); |
| 64 | $timeout(function() {getLSNotaPedido();}); | 64 | $timeout(function() {getLSNotaPedido();}); |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | function init() { | 67 | function init() { |
| 68 | $scope.$broadcast('cleanCabecera'); | 68 | $scope.$broadcast('cleanCabecera'); |
| 69 | 69 | ||
| 70 | $scope.notaPedido = { | 70 | $scope.notaPedido = { |
| 71 | id: 0, | 71 | id: 0, |
| 72 | cliente: {}, | 72 | cliente: {}, |
| 73 | proveedor: {}, | 73 | proveedor: {}, |
| 74 | domicilio: {dom: ''}, | 74 | domicilio: {dom: ''}, |
| 75 | vendedor: {}, | 75 | vendedor: {}, |
| 76 | fechaCarga: new Date(), | 76 | fechaCarga: new Date(), |
| 77 | cotizacion: {}, | 77 | cotizacion: {}, |
| 78 | articulosNotaPedido: [], | 78 | articulosNotaPedido: [], |
| 79 | notaPedidoPlazo: [] | 79 | notaPedidoPlazo: [] |
| 80 | }; | 80 | }; |
| 81 | $scope.idLista = undefined; | 81 | $scope.idLista = undefined; |
| 82 | 82 | ||
| 83 | crearNotaPedidoService.getNumeroNotaPedido().then( | 83 | crearNotaPedidoService.getNumeroNotaPedido().then( |
| 84 | function(res) { | 84 | function(res) { |
| 85 | $scope.puntoVenta = $filter('rellenarDigitos')( | 85 | $scope.puntoVenta = $filter('rellenarDigitos')( |
| 86 | res.data.sucursal, 4 | 86 | res.data.sucursal, 4 |
| 87 | ); | 87 | ); |
| 88 | 88 | ||
| 89 | $scope.comprobante = $filter('rellenarDigitos')( | 89 | $scope.comprobante = $filter('rellenarDigitos')( |
| 90 | res.data.numeroNotaPedido, 8 | 90 | res.data.numeroNotaPedido, 8 |
| 91 | ); | 91 | ); |
| 92 | }, | 92 | }, |
| 93 | function(err) { | 93 | function(err) { |
| 94 | focaModalService.alert('La terminal no esta configurada correctamente'); | 94 | focaModalService.alert('La terminal no esta configurada correctamente'); |
| 95 | console.info(err); | 95 | console.info(err); |
| 96 | } | 96 | } |
| 97 | ); | 97 | ); |
| 98 | 98 | ||
| 99 | if (APP === 'distribuidor') { | 99 | if (APP === 'distribuidor') { |
| 100 | crearNotaPedidoService.getVendedorById($scope.idVendedor).then( | 100 | crearNotaPedidoService.getVendedorById($scope.idVendedor).then( |
| 101 | function(res) { | 101 | function(res) { |
| 102 | var vendedor = res.data; | 102 | var vendedor = res.data; |
| 103 | $scope.$broadcast('addCabecera', { | 103 | $scope.$broadcast('addCabecera', { |
| 104 | label: 'Vendedor:', | 104 | label: 'Vendedor:', |
| 105 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + | 105 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + |
| 106 | vendedor.NOM | 106 | vendedor.NOM |
| 107 | }); | 107 | }); |
| 108 | 108 | ||
| 109 | $scope.notaPedido.vendedor = vendedor; | 109 | $scope.notaPedido.vendedor = vendedor; |
| 110 | $scope.inicial.notaPedido.vendedor =$scope.notaPedido.vendedor; | 110 | $scope.inicial.notaPedido.vendedor =$scope.notaPedido.vendedor; |
| 111 | } | 111 | } |
| 112 | ); | 112 | ); |
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | $scope.inicial = angular.copy($scope.notaPedido); | 115 | $scope.inicial = angular.copy($scope.notaPedido); |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | $scope.$watch('notaPedido', function(newValue) { | 118 | $scope.$watch('notaPedido', function(newValue) { |
| 119 | focaBotoneraLateralService.setPausarData({ | 119 | focaBotoneraLateralService.setPausarData({ |
| 120 | label: 'notaPedido', | 120 | label: 'notaPedido', |
| 121 | val: newValue | 121 | val: newValue |
| 122 | }); | 122 | }); |
| 123 | }, true); | 123 | }, true); |
| 124 | 124 | ||
| 125 | $scope.crearNotaPedido = function() { | 125 | $scope.crearNotaPedido = function() { |
| 126 | if (!$scope.notaPedido.cliente.COD) { | 126 | if (!$scope.notaPedido.cliente.COD) { |
| 127 | focaModalService.alert('Ingrese Cliente'); | 127 | focaModalService.alert('Ingrese Cliente'); |
| 128 | return; | 128 | return; |
| 129 | } else if (!$scope.notaPedido.proveedor.COD) { | 129 | } else if (!$scope.notaPedido.proveedor.COD) { |
| 130 | focaModalService.alert('Ingrese Proveedor'); | 130 | focaModalService.alert('Ingrese Proveedor'); |
| 131 | return; | 131 | return; |
| 132 | } else if (!$scope.notaPedido.cotizacion.ID) { | 132 | } else if (!$scope.notaPedido.cotizacion.ID) { |
| 133 | focaModalService.alert('Ingrese Cotización'); | 133 | focaModalService.alert('Ingrese Cotización'); |
| 134 | return; | 134 | return; |
| 135 | } else if (!$scope.notaPedido.cotizacion.moneda.ID) { | 135 | } else if (!$scope.notaPedido.cotizacion.moneda.ID) { |
| 136 | focaModalService.alert('Ingrese Moneda'); | 136 | focaModalService.alert('Ingrese Moneda'); |
| 137 | return; | 137 | return; |
| 138 | } else if (!$scope.notaPedido.notaPedidoPlazo) { | 138 | } else if (!$scope.notaPedido.notaPedidoPlazo) { |
| 139 | focaModalService.alert('Ingrese Precios y Condiciones'); | 139 | focaModalService.alert('Ingrese Precios y Condiciones'); |
| 140 | return; | 140 | return; |
| 141 | } else if ( | 141 | } else if ( |
| 142 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) | 142 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) |
| 143 | { | 143 | { |
| 144 | focaModalService.alert('Ingrese Flete'); | 144 | focaModalService.alert('Ingrese Flete'); |
| 145 | return; | 145 | return; |
| 146 | } else if (!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto | 146 | } else if (!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto |
| 147 | focaModalService.alert('Ingrese Domicilio'); | 147 | focaModalService.alert('Ingrese Domicilio'); |
| 148 | return; | 148 | return; |
| 149 | } else if ($scope.notaPedido.articulosNotaPedido.length === 0) { | 149 | } else if ($scope.notaPedido.articulosNotaPedido.length === 0) { |
| 150 | focaModalService.alert('Debe cargar al menos un articulo'); | 150 | focaModalService.alert('Debe cargar al menos un articulo'); |
| 151 | return; | 151 | return; |
| 152 | } | 152 | } |
| 153 | focaBotoneraLateralService.startGuardar(); | 153 | focaBotoneraLateralService.startGuardar(); |
| 154 | $scope.saveLoading = true; | 154 | $scope.saveLoading = true; |
| 155 | var notaPedido = { | 155 | var notaPedido = { |
| 156 | id: $scope.notaPedido.id, | 156 | id: $scope.notaPedido.id, |
| 157 | fechaCarga: new Date($scope.notaPedido.fechaCarga) | 157 | fechaCarga: new Date($scope.notaPedido.fechaCarga) |
| 158 | .toISOString().slice(0, 19).replace('T', ' '), | 158 | .toISOString().slice(0, 19).replace('T', ' '), |
| 159 | idVendedor: $scope.notaPedido.vendedor.id, | 159 | idVendedor: $scope.notaPedido.vendedor.id, |
| 160 | idCliente: $scope.notaPedido.cliente.COD, | 160 | idCliente: $scope.notaPedido.cliente.COD, |
| 161 | nombreCliente: $scope.notaPedido.cliente.NOM, | 161 | nombreCliente: $scope.notaPedido.cliente.NOM, |
| 162 | cuitCliente: $scope.notaPedido.cliente.CUIT, | 162 | cuitCliente: $scope.notaPedido.cliente.CUIT, |
| 163 | idProveedor: $scope.notaPedido.proveedor.COD, | 163 | idProveedor: $scope.notaPedido.proveedor.COD, |
| 164 | idDomicilio: $scope.notaPedido.domicilio.id, | 164 | idDomicilio: $scope.notaPedido.domicilio.id, |
| 165 | idCotizacion: $scope.notaPedido.cotizacion.ID, | 165 | idCotizacion: $scope.notaPedido.cotizacion.ID, |
| 166 | idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, | 166 | idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, |
| 167 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 167 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
| 168 | flete: $scope.notaPedido.flete, | 168 | flete: $scope.notaPedido.flete, |
| 169 | fob: $scope.notaPedido.fob, | 169 | fob: $scope.notaPedido.fob, |
| 170 | bomba: $scope.notaPedido.bomba, | 170 | bomba: $scope.notaPedido.bomba, |
| 171 | kilometros: $scope.notaPedido.kilometros, | 171 | kilometros: $scope.notaPedido.kilometros, |
| 172 | domicilioStamp: $scope.notaPedido.domicilioStamp, | 172 | domicilioStamp: $scope.notaPedido.domicilioStamp, |
| 173 | observaciones: $scope.notaPedido.observaciones, | 173 | observaciones: $scope.notaPedido.observaciones, |
| 174 | estado: 0, | 174 | estado: 0, |
| 175 | total: $scope.getTotal() | 175 | total: $scope.getTotal() |
| 176 | }; | 176 | }; |
| 177 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( | 177 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( |
| 178 | function(data) { | 178 | function(data) { |
| 179 | // Al guardar los datos de la nota de pedido logueamos la | 179 | // Al guardar los datos de la nota de pedido logueamos la |
| 180 | // actividad para su seguimiento. | 180 | // actividad para su seguimiento. |
| 181 | //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? | 181 | //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? |
| 182 | focaSeguimientoService.guardarPosicion( | 182 | focaSeguimientoService.guardarPosicion( |
| 183 | 'Nota de pedido', | 183 | 'Nota de pedido', |
| 184 | data.data.id, | 184 | data.data.id, |
| 185 | '' | 185 | '' |
| 186 | ); | 186 | ); |
| 187 | notaPedidoBusinessService.addArticulos( | 187 | notaPedidoBusinessService.addArticulos( |
| 188 | $scope.notaPedido.articulosNotaPedido, | 188 | $scope.notaPedido.articulosNotaPedido, |
| 189 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); | 189 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); |
| 190 | 190 | ||
| 191 | if ($scope.notaPedido.notaPedidoPuntoDescarga) { | 191 | if ($scope.notaPedido.notaPedidoPuntoDescarga) { |
| 192 | notaPedidoBusinessService.addPuntosDescarga(data.data.id, | 192 | notaPedidoBusinessService.addPuntosDescarga(data.data.id, |
| 193 | $scope.notaPedido.notaPedidoPuntoDescarga); | 193 | $scope.notaPedido.notaPedidoPuntoDescarga); |
| 194 | } | 194 | } |
| 195 | 195 | ||
| 196 | var plazos = $scope.notaPedido.notaPedidoPlazo; | 196 | var plazos = $scope.notaPedido.notaPedidoPlazo; |
| 197 | var plazosACrear = []; | 197 | var plazosACrear = []; |
| 198 | plazos.forEach(function(plazo) { | 198 | plazos.forEach(function(plazo) { |
| 199 | plazosACrear.push({ | 199 | plazosACrear.push({ |
| 200 | idNotaPedido: data.data.id, | 200 | idNotaPedido: data.data.id, |
| 201 | dias: plazo.dias | 201 | dias: plazo.dias |
| 202 | }); | 202 | }); |
| 203 | }); | 203 | }); |
| 204 | 204 | ||
| 205 | if (plazosACrear.length) { | 205 | if (plazosACrear.length) { |
| 206 | crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear); | 206 | crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear); |
| 207 | } | 207 | } |
| 208 | 208 | ||
| 209 | notaPedidoBusinessService.addEstado(data.data.id, | 209 | notaPedidoBusinessService.addEstado(data.data.id, |
| 210 | $scope.notaPedido.vendedor.id); | 210 | $scope.notaPedido.vendedor.id); |
| 211 | 211 | ||
| 212 | focaBotoneraLateralService.endGuardar(true); | 212 | focaBotoneraLateralService.endGuardar(true); |
| 213 | $scope.saveLoading = false; | 213 | $scope.saveLoading = false; |
| 214 | 214 | ||
| 215 | init(); | 215 | init(); |
| 216 | }, function(error) { | 216 | }, function(error) { |
| 217 | focaModalService.alert('Hubo un error al crear la nota de pedido'); | 217 | focaModalService.alert('Hubo un error al crear la nota de pedido'); |
| 218 | focaBotoneraLateralService.endGuardar(); | 218 | focaBotoneraLateralService.endGuardar(); |
| 219 | $scope.saveLoading = false; | 219 | $scope.saveLoading = false; |
| 220 | console.info(error); | 220 | console.info(error); |
| 221 | } | 221 | } |
| 222 | ); | 222 | ); |
| 223 | }; | 223 | }; |
| 224 | 224 | ||
| 225 | $scope.seleccionarNotaPedido = function() { | 225 | $scope.seleccionarNotaPedido = function() { |
| 226 | var modalInstance = $uibModal.open( | 226 | var modalInstance = $uibModal.open( |
| 227 | { | 227 | { |
| 228 | ariaLabelledBy: 'Busqueda de Nota de Pedido', | 228 | ariaLabelledBy: 'Busqueda de Nota de Pedido', |
| 229 | templateUrl: 'foca-modal-nota-pedido.html', | 229 | templateUrl: 'foca-modal-nota-pedido.html', |
| 230 | controller: 'focaModalNotaPedidoController', | 230 | controller: 'focaModalNotaPedidoController', |
| 231 | size: 'lg', | 231 | size: 'lg', |
| 232 | resolve: { | 232 | resolve: { |
| 233 | usadoPor: function() {return 'notaPedido';}, | 233 | usadoPor: function() {return 'notaPedido';}, |
| 234 | idVendedor: function() { | 234 | idVendedor: function() { |
| 235 | if(APP === 'distribuidor') | 235 | if(APP === 'distribuidor') |
| 236 | return $scope.notaPedido.vendedor.id; | 236 | return $scope.notaPedido.vendedor.id; |
| 237 | else | 237 | else |
| 238 | return null; | 238 | return null; |
| 239 | } | 239 | } |
| 240 | } | 240 | } |
| 241 | } | 241 | } |
| 242 | ); | 242 | ); |
| 243 | modalInstance.result.then(setearNotaPedido); | 243 | modalInstance.result.then(setearNotaPedido); |
| 244 | }; | 244 | }; |
| 245 | 245 | ||
| 246 | $scope.seleccionarProductos = function() { | 246 | $scope.seleccionarProductos = function() { |
| 247 | if ($scope.idLista === undefined) { | 247 | if ($scope.idLista === undefined) { |
| 248 | focaModalService.alert( | 248 | focaModalService.alert( |
| 249 | 'Primero seleccione una lista de precio y condicion'); | 249 | 'Primero seleccione una lista de precio y condicion'); |
| 250 | return; | 250 | return; |
| 251 | } | 251 | } |
| 252 | var modalInstance = $uibModal.open( | 252 | var modalInstance = $uibModal.open( |
| 253 | { | 253 | { |
| 254 | ariaLabelledBy: 'Busqueda de Productos', | 254 | ariaLabelledBy: 'Busqueda de Productos', |
| 255 | templateUrl: 'modal-busqueda-productos.html', | 255 | templateUrl: 'modal-busqueda-productos.html', |
| 256 | controller: 'modalBusquedaProductosCtrl', | 256 | controller: 'modalBusquedaProductosCtrl', |
| 257 | resolve: { | 257 | resolve: { |
| 258 | parametroProducto: { | 258 | parametroProducto: { |
| 259 | idLista: $scope.idLista, | 259 | idLista: $scope.idLista, |
| 260 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 260 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
| 261 | simbolo: $scope.notaPedido.cotizacion.moneda.SIMBOLO | 261 | simbolo: $scope.notaPedido.cotizacion.moneda.SIMBOLO |
| 262 | } | 262 | } |
| 263 | }, | 263 | }, |
| 264 | size: 'lg' | 264 | size: 'lg' |
| 265 | } | 265 | } |
| 266 | ); | 266 | ); |
| 267 | modalInstance.result.then( | 267 | modalInstance.result.then( |
| 268 | function(producto) { | 268 | function(producto) { |
| 269 | var newArt = | 269 | var newArt = |
| 270 | { | 270 | { |
| 271 | id: 0, | 271 | id: 0, |
| 272 | codigo: producto.codigo, | 272 | codigo: producto.codigo, |
| 273 | sector: producto.sector, | 273 | sector: producto.sector, |
| 274 | sectorCodigo: producto.sector + '-' + producto.codigo, | 274 | sectorCodigo: producto.sector + '-' + producto.codigo, |
| 275 | descripcion: producto.descripcion, | 275 | descripcion: producto.descripcion, |
| 276 | item: $scope.notaPedido.articulosNotaPedido.length + 1, | 276 | item: $scope.notaPedido.articulosNotaPedido.length + 1, |
| 277 | nombre: producto.descripcion, | 277 | nombre: producto.descripcion, |
| 278 | precio: parseFloat(producto.precio.toFixed(4)), | 278 | precio: parseFloat(producto.precio.toFixed(4)), |
| 279 | costoUnitario: producto.costo, | 279 | costoUnitario: producto.costo, |
| 280 | editCantidad: false, | 280 | editCantidad: false, |
| 281 | editPrecio: false, | 281 | editPrecio: false, |
| 282 | rubro: producto.CodRub, | 282 | rubro: producto.CodRub, |
| 283 | exentoUnitario: producto.precio, | 283 | exentoUnitario: producto.precio, |
| 284 | ivaUnitario: producto.IMPIVA, | 284 | ivaUnitario: producto.IMPIVA, |
| 285 | impuestoInternoUnitario: producto.ImpInt, | 285 | impuestoInternoUnitario: producto.ImpInt, |
| 286 | impuestoInterno1Unitario: producto.ImpInt2, | 286 | impuestoInterno1Unitario: producto.ImpInt2, |
| 287 | impuestoInterno2Unitario: producto.ImpInt3, | 287 | impuestoInterno2Unitario: producto.ImpInt3, |
| 288 | precioLista: producto.precio, | 288 | precioLista: producto.precio, |
| 289 | combustible: 1, | 289 | combustible: 1, |
| 290 | facturado: 0, | 290 | facturado: 0, |
| 291 | idArticulo: producto.id | 291 | idArticulo: producto.id |
| 292 | }; | 292 | }; |
| 293 | $scope.articuloACargar = newArt; | 293 | $scope.articuloACargar = newArt; |
| 294 | $scope.cargando = false; | 294 | $scope.cargando = false; |
| 295 | }, function() { | 295 | }, function() { |
| 296 | // funcion ejecutada cuando se cancela el modal | 296 | // funcion ejecutada cuando se cancela el modal |
| 297 | } | 297 | } |
| 298 | ); | 298 | ); |
| 299 | }; | 299 | }; |
| 300 | 300 | ||
| 301 | $scope.seleccionarPuntosDeDescarga = function() { | 301 | $scope.seleccionarPuntosDeDescarga = function() { |
| 302 | if(!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { | 302 | if(!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { |
| 303 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); | 303 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); |
| 304 | return; | 304 | return; |
| 305 | }else { | 305 | }else { |
| 306 | var modalInstance = $uibModal.open( | 306 | var modalInstance = $uibModal.open( |
| 307 | { | 307 | { |
| 308 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', | 308 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', |
| 309 | templateUrl: 'modal-punto-descarga.html', | 309 | templateUrl: 'modal-punto-descarga.html', |
| 310 | controller: 'focaModalPuntoDescargaController', | 310 | controller: 'focaModalPuntoDescargaController', |
| 311 | size: 'lg', | 311 | size: 'lg', |
| 312 | resolve: { | 312 | resolve: { |
| 313 | filters: { | 313 | filters: { |
| 314 | idDomicilio: $scope.notaPedido.domicilio.id, | 314 | idDomicilio: $scope.notaPedido.domicilio.id, |
| 315 | idCliente: $scope.notaPedido.cliente.COD, | 315 | idCliente: $scope.notaPedido.cliente.COD, |
| 316 | articulos: $scope.notaPedido.articulosNotaPedido, | 316 | articulos: $scope.notaPedido.articulosNotaPedido, |
| 317 | puntosDescarga: $scope.notaPedido.notaPedidoPuntoDescarga | 317 | puntosDescarga: $scope.notaPedido.notaPedidoPuntoDescarga |
| 318 | } | 318 | } |
| 319 | } | 319 | } |
| 320 | } | 320 | } |
| 321 | ); | 321 | ); |
| 322 | modalInstance.result.then( | 322 | modalInstance.result.then( |
| 323 | function(puntosDescarga) { | 323 | function(puntosDescarga) { |
| 324 | $scope.notaPedido.notaPedidoPuntoDescarga = puntosDescarga; | 324 | $scope.notaPedido.notaPedidoPuntoDescarga = puntosDescarga; |
| 325 | 325 | ||
| 326 | //AGREGO PUNTOS DE DESCARGA A CABECERA | 326 | //AGREGO PUNTOS DE DESCARGA A CABECERA |
| 327 | var puntosStamp = ''; | 327 | var puntosStamp = ''; |
| 328 | puntosDescarga.forEach(function(punto, idx, arr) { | 328 | puntosDescarga.forEach(function(punto, idx, arr) { |
| 329 | puntosStamp += punto.descripcion; | 329 | puntosStamp += punto.descripcion; |
| 330 | if((idx + 1) !== arr.length) puntosStamp += ', '; | 330 | if((idx + 1) !== arr.length) puntosStamp += ', '; |
| 331 | }); | 331 | }); |
| 332 | 332 | ||
| 333 | $scope.$broadcast('addCabecera', { | 333 | $scope.$broadcast('addCabecera', { |
| 334 | label: 'Puntos de descarga:', | 334 | label: 'Puntos de descarga:', |
| 335 | valor: puntosStamp | 335 | valor: puntosStamp |
| 336 | }); | 336 | }); |
| 337 | }, function() { | 337 | }, function() { |
| 338 | $scope.abrirModalDomicilios($scope.cliente); | 338 | $scope.abrirModalDomicilios($scope.cliente); |
| 339 | } | 339 | } |
| 340 | ); | 340 | ); |
| 341 | } | 341 | } |
| 342 | }; | 342 | }; |
| 343 | 343 | ||
| 344 | $scope.seleccionarTransportista = function() { | 344 | $scope.seleccionarTransportista = function() { |
| 345 | $scope.seleccionarProveedor(function() { | 345 | $scope.seleccionarProveedor(function() { |
| 346 | if (validarNotaRemitada()) { | 346 | if (validarNotaRemitada()) { |
| 347 | var modalInstance = $uibModal.open( | 347 | var modalInstance = $uibModal.open( |
| 348 | { | 348 | { |
| 349 | ariaLabelledBy: 'Busqueda de Flete', | 349 | ariaLabelledBy: 'Busqueda de Flete', |
| 350 | templateUrl: 'modal-flete.html', | 350 | templateUrl: 'modal-flete.html', |
| 351 | controller: 'focaModalFleteController', | 351 | controller: 'focaModalFleteController', |
| 352 | size: 'lg', | 352 | size: 'lg', |
| 353 | resolve: { | 353 | resolve: { |
| 354 | parametrosFlete: | 354 | parametrosFlete: |
| 355 | function() { | 355 | function() { |
| 356 | return { | 356 | return { |
| 357 | flete: $scope.notaPedido.fob ? 'FOB' : | 357 | flete: $scope.notaPedido.fob ? 'FOB' : |
| 358 | ( $scope.notaPedido.flete ? '1' : | 358 | ( $scope.notaPedido.flete ? '1' : |
| 359 | ($scope.notaPedido.flete === undefined ? | 359 | ($scope.notaPedido.flete === undefined ? |
| 360 | null : '0')), | 360 | null : '0')), |
| 361 | bomba: $scope.notaPedido.bomba ? '1' : | 361 | bomba: $scope.notaPedido.bomba ? '1' : |
| 362 | ($scope.notaPedido.bomba === undefined ? | 362 | ($scope.notaPedido.bomba === undefined ? |
| 363 | null : '0'), | 363 | null : '0'), |
| 364 | kilometros: $scope.notaPedido.kilometros | 364 | kilometros: $scope.notaPedido.kilometros |
| 365 | }; | 365 | }; |
| 366 | } | 366 | } |
| 367 | } | 367 | } |
| 368 | } | 368 | } |
| 369 | ); | 369 | ); |
| 370 | modalInstance.result.then( | 370 | modalInstance.result.then( |
| 371 | function(datos) { | 371 | function(datos) { |
| 372 | $scope.notaPedido.flete = datos.flete; | 372 | $scope.notaPedido.flete = datos.flete; |
| 373 | $scope.notaPedido.fob = datos.FOB; | 373 | $scope.notaPedido.fob = datos.FOB; |
| 374 | $scope.notaPedido.bomba = datos.bomba; | 374 | $scope.notaPedido.bomba = datos.bomba; |
| 375 | $scope.notaPedido.kilometros = datos.kilometros; | 375 | $scope.notaPedido.kilometros = datos.kilometros; |
| 376 | $scope.$broadcast('addCabecera', { | 376 | $scope.$broadcast('addCabecera', { |
| 377 | label: 'Flete:', | 377 | label: 'Flete:', |
| 378 | valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') | 378 | valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') |
| 379 | }); | 379 | }); |
| 380 | if (datos.flete) { | 380 | if (datos.flete) { |
| 381 | $scope.$broadcast('addCabecera', { | 381 | $scope.$broadcast('addCabecera', { |
| 382 | label: 'Bomba:', | 382 | label: 'Bomba:', |
| 383 | valor: datos.bomba ? 'Si' : 'No' | 383 | valor: datos.bomba ? 'Si' : 'No' |
| 384 | }); | 384 | }); |
| 385 | $scope.$broadcast('addCabecera', { | 385 | $scope.$broadcast('addCabecera', { |
| 386 | label: 'Kilometros:', | 386 | label: 'Kilometros:', |
| 387 | valor: datos.kilometros | 387 | valor: datos.kilometros |
| 388 | }); | 388 | }); |
| 389 | } else { | 389 | } else { |
| 390 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 390 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
| 391 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 391 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
| 392 | $scope.notaPedido.bomba = false; | 392 | $scope.notaPedido.bomba = false; |
| 393 | $scope.notaPedido.kilometros = null; | 393 | $scope.notaPedido.kilometros = null; |
| 394 | } | 394 | } |
| 395 | }, function() { | 395 | }, function() { |
| 396 | $scope.seleccionarTransportista(); | 396 | $scope.seleccionarTransportista(); |
| 397 | } | 397 | } |
| 398 | ); | 398 | ); |
| 399 | } | 399 | } |
| 400 | }); | 400 | }); |
| 401 | }; | 401 | }; |
| 402 | 402 | ||
| 403 | $scope.seleccionarVendedor = function(callback, ocultarVendedor) { | 403 | $scope.seleccionarVendedor = function(callback, ocultarVendedor) { |
| 404 | if (APP === 'distribuidor' || ocultarVendedor) { | 404 | if (APP === 'distribuidor' || ocultarVendedor) { |
| 405 | callback(); | 405 | callback(); |
| 406 | return; | 406 | return; |
| 407 | } | 407 | } |
| 408 | 408 | ||
| 409 | if(validarNotaRemitada()) { | 409 | if(validarNotaRemitada()) { |
| 410 | var parametrosModal = { | 410 | var parametrosModal = { |
| 411 | titulo: 'Búsqueda vendedores', | 411 | titulo: 'Búsqueda vendedores', |
| 412 | query: '/vendedor', | 412 | query: '/vendedor', |
| 413 | columnas: [ | 413 | columnas: [ |
| 414 | { | 414 | { |
| 415 | propiedad: 'NUM', | 415 | propiedad: 'NUM', |
| 416 | nombre: 'Código', | 416 | nombre: 'Código', |
| 417 | filtro: { | 417 | filtro: { |
| 418 | nombre: 'rellenarDigitos', | 418 | nombre: 'rellenarDigitos', |
| 419 | parametro: 3 | 419 | parametro: 3 |
| 420 | } | 420 | } |
| 421 | }, | 421 | }, |
| 422 | { | 422 | { |
| 423 | propiedad: 'NOM', | 423 | propiedad: 'NOM', |
| 424 | nombre: 'Nombre' | 424 | nombre: 'Nombre' |
| 425 | } | 425 | } |
| 426 | ], | 426 | ], |
| 427 | size: 'md' | 427 | size: 'md' |
| 428 | }; | 428 | }; |
| 429 | focaModalService.modal(parametrosModal).then( | 429 | focaModalService.modal(parametrosModal).then( |
| 430 | function(vendedor) { | 430 | function(vendedor) { |
| 431 | $scope.$broadcast('addCabecera', { | 431 | $scope.$broadcast('addCabecera', { |
| 432 | label: 'Vendedor:', | 432 | label: 'Vendedor:', |
| 433 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + | 433 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + |
| 434 | vendedor.NOM | 434 | vendedor.NOM |
| 435 | }); | 435 | }); |
| 436 | $scope.notaPedido.vendedor = vendedor; | 436 | $scope.notaPedido.vendedor = vendedor; |
| 437 | deleteCliente(); | 437 | deleteCliente(); |
| 438 | callback(); | 438 | callback(); |
| 439 | }, function() {} | 439 | }, function() {} |
| 440 | ); | 440 | ); |
| 441 | } | 441 | } |
| 442 | }; | 442 | }; |
| 443 | 443 | ||
| 444 | $scope.seleccionarCliente = function(ocultarVendedor) { | 444 | $scope.seleccionarCliente = function(ocultarVendedor) { |
| 445 | $scope.seleccionarVendedor(function() { | 445 | $scope.seleccionarVendedor(function() { |
| 446 | if (!$scope.notaPedido.vendedor.NUM) { | ||
| 447 | focaModalService.alert('Primero seleccione un vendedor'); | ||
| 448 | return; | ||
| 449 | } | ||
| 450 | if (validarNotaRemitada()) { | 446 | if (validarNotaRemitada()) { |
| 451 | var modalInstance = $uibModal.open( | 447 | var modalInstance = $uibModal.open( |
| 452 | { | 448 | { |
| 453 | ariaLabelledBy: 'Busqueda de Cliente', | 449 | ariaLabelledBy: 'Busqueda de Cliente', |
| 454 | templateUrl: 'foca-busqueda-cliente-modal.html', | 450 | templateUrl: 'foca-busqueda-cliente-modal.html', |
| 455 | controller: 'focaBusquedaClienteModalController', | 451 | controller: 'focaBusquedaClienteModalController', |
| 456 | resolve: { | 452 | resolve: { |
| 457 | vendedor: function() { return $scope.notaPedido.vendedor; }, | 453 | vendedor: function() { return $scope.notaPedido.vendedor; }, |
| 458 | cobrador: function() { return null; } | 454 | cobrador: function() { return null; } |
| 459 | }, | 455 | }, |
| 460 | size: 'lg' | 456 | size: 'lg' |
| 461 | } | 457 | } |
| 462 | ); | 458 | ); |
| 463 | modalInstance.result.then( | 459 | modalInstance.result.then( |
| 464 | function(cliente) { | 460 | function(cliente) { |
| 465 | $scope.abrirModalDomicilios(cliente); | 461 | $scope.abrirModalDomicilios(cliente); |
| 466 | $scope.cliente = cliente; | 462 | $scope.cliente = cliente; |
| 467 | }, function() { | 463 | }, function() { |
| 468 | if (APP !== 'distribuidor') $scope.seleccionarCliente(); | 464 | if (APP !== 'distribuidor') $scope.seleccionarCliente(); |
| 469 | } | 465 | } |
| 470 | ); | 466 | ); |
| 471 | } | 467 | } |
| 472 | }, ocultarVendedor); | 468 | }, ocultarVendedor); |
| 473 | }; | 469 | }; |
| 474 | 470 | ||
| 475 | $scope.seleccionarProveedor = function(callback) { | 471 | $scope.seleccionarProveedor = function(callback) { |
| 476 | if(validarNotaRemitada()) { | 472 | if(validarNotaRemitada()) { |
| 477 | var parametrosModal = { | 473 | var parametrosModal = { |
| 478 | titulo: 'Búsqueda de Proveedor', | 474 | titulo: 'Búsqueda de Proveedor', |
| 479 | query: '/proveedor', | 475 | query: '/proveedor', |
| 480 | columnas: [ | 476 | columnas: [ |
| 481 | { | 477 | { |
| 482 | nombre: 'Código', | 478 | nombre: 'Código', |
| 483 | propiedad: 'COD', | 479 | propiedad: 'COD', |
| 484 | filtro: { | 480 | filtro: { |
| 485 | nombre: 'rellenarDigitos', | 481 | nombre: 'rellenarDigitos', |
| 486 | parametro: 5 | 482 | parametro: 5 |
| 487 | } | 483 | } |
| 488 | }, | 484 | }, |
| 489 | { | 485 | { |
| 490 | nombre: 'Nombre', | 486 | nombre: 'Nombre', |
| 491 | propiedad: 'NOM' | 487 | propiedad: 'NOM' |
| 492 | }, | 488 | }, |
| 493 | { | 489 | { |
| 494 | nombre: 'CUIT', | 490 | nombre: 'CUIT', |
| 495 | propiedad: 'CUIT' | 491 | propiedad: 'CUIT' |
| 496 | } | 492 | } |
| 497 | ], | 493 | ], |
| 498 | tipo: 'POST', | 494 | tipo: 'POST', |
| 499 | json: {razonCuitCod: ''} | 495 | json: {razonCuitCod: ''} |
| 500 | }; | 496 | }; |
| 501 | focaModalService.modal(parametrosModal).then( | 497 | focaModalService.modal(parametrosModal).then( |
| 502 | function(proveedor) { | 498 | function(proveedor) { |
| 503 | $scope.notaPedido.proveedor = proveedor; | 499 | $scope.notaPedido.proveedor = proveedor; |
| 504 | $scope.$broadcast('addCabecera', { | 500 | $scope.$broadcast('addCabecera', { |
| 505 | label: 'Proveedor:', | 501 | label: 'Proveedor:', |
| 506 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + | 502 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + |
| 507 | proveedor.NOM | 503 | proveedor.NOM |
| 508 | }); | 504 | }); |
| 509 | callback(); | 505 | callback(); |
| 510 | }, function() { | 506 | }, function() { |
| 511 | 507 | ||
| 512 | } | 508 | } |
| 513 | ); | 509 | ); |
| 514 | } | 510 | } |
| 515 | }; | 511 | }; |
| 516 | 512 | ||
| 517 | $scope.abrirModalDomicilios = function(cliente) { | 513 | $scope.abrirModalDomicilios = function(cliente) { |
| 518 | var modalInstanceDomicilio = $uibModal.open( | 514 | var modalInstanceDomicilio = $uibModal.open( |
| 519 | { | 515 | { |
| 520 | ariaLabelledBy: 'Busqueda de Domicilios', | 516 | ariaLabelledBy: 'Busqueda de Domicilios', |
| 521 | templateUrl: 'modal-domicilio.html', | 517 | templateUrl: 'modal-domicilio.html', |
| 522 | controller: 'focaModalDomicilioController', | 518 | controller: 'focaModalDomicilioController', |
| 523 | resolve: { | 519 | resolve: { |
| 524 | idCliente: function() { return cliente.cod; }, | 520 | idCliente: function() { return cliente.cod; }, |
| 525 | esNuevo: function() { return cliente.esNuevo; } | 521 | esNuevo: function() { return cliente.esNuevo; } |
| 526 | }, | 522 | }, |
| 527 | size: 'lg', | 523 | size: 'lg', |
| 528 | } | 524 | } |
| 529 | ); | 525 | ); |
| 530 | modalInstanceDomicilio.result.then( | 526 | modalInstanceDomicilio.result.then( |
| 531 | function(domicilio) { | 527 | function(domicilio) { |
| 532 | $scope.notaPedido.domicilio = domicilio; | 528 | $scope.notaPedido.domicilio = domicilio; |
| 533 | $scope.notaPedido.cliente = { | 529 | $scope.notaPedido.cliente = { |
| 534 | COD: cliente.cod, | 530 | COD: cliente.cod, |
| 535 | CUIT: cliente.cuit, | 531 | CUIT: cliente.cuit, |
| 536 | NOM: cliente.nom | 532 | NOM: cliente.nom |
| 537 | }; | 533 | }; |
| 538 | var domicilioStamp = | 534 | var domicilioStamp = |
| 539 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + | 535 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + |
| 540 | domicilio.Localidad + ', ' + domicilio.Provincia; | 536 | domicilio.Localidad + ', ' + domicilio.Provincia; |
| 541 | $scope.notaPedido.domicilioStamp = domicilioStamp; | 537 | $scope.notaPedido.domicilioStamp = domicilioStamp; |
| 542 | 538 | ||
| 543 | $scope.notaPedido.notaPedidoPuntoDescarga = domicilio.puntosDescarga; | 539 | $scope.notaPedido.notaPedidoPuntoDescarga = domicilio.puntosDescarga; |
| 544 | 540 | ||
| 545 | $scope.$broadcast('addCabecera', { | 541 | $scope.$broadcast('addCabecera', { |
| 546 | label: 'Cliente:', | 542 | label: 'Cliente:', |
| 547 | valor: $filter('rellenarDigitos')(cliente.cod, 5) + ' - ' + cliente.nom | 543 | valor: $filter('rellenarDigitos')(cliente.cod, 5) + ' - ' + cliente.nom |
| 548 | }); | 544 | }); |
| 549 | $scope.$broadcast('addCabecera', { | 545 | $scope.$broadcast('addCabecera', { |
| 550 | label: 'Domicilio:', | 546 | label: 'Domicilio:', |
| 551 | valor: domicilioStamp | 547 | valor: domicilioStamp |
| 552 | }); | 548 | }); |
| 553 | if (domicilio.verPuntos) { | 549 | if (domicilio.verPuntos) { |
| 554 | delete $scope.notaPedido.domicilio.verPuntos; | 550 | delete $scope.notaPedido.domicilio.verPuntos; |
| 555 | $scope.seleccionarPuntosDeDescarga(); | 551 | $scope.seleccionarPuntosDeDescarga(); |
| 556 | } else { | 552 | } else { |
| 557 | crearNotaPedidoService | 553 | crearNotaPedidoService |
| 558 | .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) | 554 | .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) |
| 559 | .then(function(res) { | 555 | .then(function(res) { |
| 560 | if(res.data.length) $scope.seleccionarPuntosDeDescarga(); | 556 | if(res.data.length) $scope.seleccionarPuntosDeDescarga(); |
| 561 | }); | 557 | }); |
| 562 | } | 558 | } |
| 563 | }, function() { | 559 | }, function() { |
| 564 | $scope.seleccionarCliente(true); | 560 | $scope.seleccionarCliente(true); |
| 565 | return; | 561 | return; |
| 566 | } | 562 | } |
| 567 | ); | 563 | ); |
| 568 | }; | 564 | }; |
| 569 | 565 | ||
| 570 | $scope.getTotal = function() { | 566 | $scope.getTotal = function() { |
| 571 | var total = 0; | 567 | var total = 0; |
| 572 | if ($scope.notaPedido.articulosNotaPedido) { | 568 | if ($scope.notaPedido.articulosNotaPedido) { |
| 573 | var arrayTempArticulos = $scope.notaPedido.articulosNotaPedido; | 569 | var arrayTempArticulos = $scope.notaPedido.articulosNotaPedido; |
| 574 | for (var i = 0; i < arrayTempArticulos.length; i++) { | 570 | for (var i = 0; i < arrayTempArticulos.length; i++) { |
| 575 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | 571 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; |
| 576 | } | 572 | } |
| 577 | } | 573 | } |
| 578 | 574 | ||
| 579 | return parseFloat(total.toFixed(2)); | 575 | return parseFloat(total.toFixed(2)); |
| 580 | }; | 576 | }; |
| 581 | 577 | ||
| 582 | $scope.getSubTotal = function() { | 578 | $scope.getSubTotal = function() { |
| 583 | if($scope.articuloACargar) { | 579 | if($scope.articuloACargar) { |
| 584 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; | 580 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
| 585 | } | 581 | } |
| 586 | }; | 582 | }; |
| 587 | 583 | ||
| 588 | $scope.seleccionarPreciosYCondiciones = function() { | 584 | $scope.seleccionarPreciosYCondiciones = function() { |
| 589 | if(validarNotaRemitada()) { | 585 | if(validarNotaRemitada()) { |
| 590 | var modalInstance = $uibModal.open( | 586 | var modalInstance = $uibModal.open( |
| 591 | { | 587 | { |
| 592 | ariaLabelledBy: 'Busqueda de Precio Condición', | 588 | ariaLabelledBy: 'Busqueda de Precio Condición', |
| 593 | templateUrl: 'modal-precio-condicion.html', | 589 | templateUrl: 'modal-precio-condicion.html', |
| 594 | controller: 'focaModalPrecioCondicionController', | 590 | controller: 'focaModalPrecioCondicionController', |
| 595 | size: 'lg' | 591 | size: 'lg' |
| 596 | } | 592 | } |
| 597 | ); | 593 | ); |
| 598 | modalInstance.result.then( | 594 | modalInstance.result.then( |
| 599 | function(precioCondicion) { | 595 | function(precioCondicion) { |
| 600 | var cabecera = ''; | 596 | var cabecera = ''; |
| 601 | var plazosConcat = ''; | 597 | var plazosConcat = ''; |
| 602 | if(!Array.isArray(precioCondicion)) { | 598 | if(!Array.isArray(precioCondicion)) { |
| 603 | $scope.notaPedido.notaPedidoPlazo = precioCondicion.plazoPago; | 599 | $scope.notaPedido.notaPedidoPlazo = precioCondicion.plazoPago; |
| 604 | $scope.notaPedido.precioCondicion = precioCondicion; | 600 | $scope.notaPedido.precioCondicion = precioCondicion; |
| 605 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; | 601 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; |
| 606 | $scope.idLista = precioCondicion.idListaPrecio; | 602 | $scope.idLista = precioCondicion.idListaPrecio; |
| 607 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { | 603 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { |
| 608 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; | 604 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; |
| 609 | } | 605 | } |
| 610 | cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + | 606 | cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + |
| 611 | ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); | 607 | ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); |
| 612 | } else { //Cuando se ingresan los plazos manualmente | 608 | } else { //Cuando se ingresan los plazos manualmente |
| 613 | $scope.notaPedido.idPrecioCondicion = 0; | 609 | $scope.notaPedido.idPrecioCondicion = 0; |
| 614 | //-1, el modal productos busca todos los productos | 610 | //-1, el modal productos busca todos los productos |
| 615 | $scope.idLista = -1; | 611 | $scope.idLista = -1; |
| 616 | $scope.notaPedido.notaPedidoPlazo = precioCondicion; | 612 | $scope.notaPedido.notaPedidoPlazo = precioCondicion; |
| 617 | for(var j = 0; j < precioCondicion.length; j++) { | 613 | for(var j = 0; j < precioCondicion.length; j++) { |
| 618 | plazosConcat += precioCondicion[j].dias + ' '; | 614 | plazosConcat += precioCondicion[j].dias + ' '; |
| 619 | } | 615 | } |
| 620 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); | 616 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); |
| 621 | } | 617 | } |
| 622 | $scope.notaPedido.articulosNotaPedido = []; | 618 | $scope.notaPedido.articulosNotaPedido = []; |
| 623 | $scope.$broadcast('addCabecera', { | 619 | $scope.$broadcast('addCabecera', { |
| 624 | label: 'Precios y condiciones:', | 620 | label: 'Precios y condiciones:', |
| 625 | valor: cabecera | 621 | valor: cabecera |
| 626 | }); | 622 | }); |
| 627 | }, function() { | 623 | }, function() { |
| 628 | 624 | ||
| 629 | } | 625 | } |
| 630 | ); | 626 | ); |
| 631 | } | 627 | } |
| 632 | }; | 628 | }; |
| 633 | 629 | ||
| 634 | $scope.seleccionarFlete = function() { | ||
| 635 | |||
| 636 | }; | ||
| 637 | |||
| 638 | $scope.seleccionarMoneda = function() { | 630 | $scope.seleccionarMoneda = function() { |
| 639 | if(validarNotaRemitada()) { | 631 | if(validarNotaRemitada()) { |
| 640 | var parametrosModal = { | 632 | var parametrosModal = { |
| 641 | titulo: 'Búsqueda de monedas', | 633 | titulo: 'Búsqueda de monedas', |
| 642 | query: '/moneda', | 634 | query: '/moneda', |
| 643 | columnas: [ | 635 | columnas: [ |
| 644 | { | 636 | { |
| 645 | propiedad: 'DETALLE', | 637 | propiedad: 'DETALLE', |
| 646 | nombre: 'Nombre' | 638 | nombre: 'Nombre' |
| 647 | }, | 639 | }, |
| 648 | { | 640 | { |
| 649 | propiedad: 'SIMBOLO', | 641 | propiedad: 'SIMBOLO', |
| 650 | nombre: 'Símbolo' | 642 | nombre: 'Símbolo' |
| 651 | } | 643 | } |
| 652 | ], | 644 | ], |
| 653 | size: 'md' | 645 | size: 'md' |
| 654 | }; | 646 | }; |
| 655 | focaModalService.modal(parametrosModal).then( | 647 | focaModalService.modal(parametrosModal).then( |
| 656 | function(moneda) { | 648 | function(moneda) { |
| 657 | $scope.abrirModalCotizacion(moneda); | 649 | $scope.abrirModalCotizacion(moneda); |
| 658 | }, function() { | 650 | }, function() { |
| 659 | 651 | ||
| 660 | } | 652 | } |
| 661 | ); | 653 | ); |
| 662 | } | 654 | } |
| 663 | }; | 655 | }; |
| 664 | 656 | ||
| 665 | $scope.seleccionarObservaciones = function() { | 657 | $scope.seleccionarObservaciones = function() { |
| 666 | focaModalService | 658 | focaModalService |
| 667 | .prompt({ | 659 | .prompt({ |
| 668 | titulo: 'Ingrese observaciones', | 660 | titulo: 'Ingrese observaciones', |
| 669 | value: $scope.notaPedido.observaciones, | 661 | value: $scope.notaPedido.observaciones, |
| 670 | textarea: true | 662 | textarea: true |
| 671 | }) | 663 | }) |
| 672 | .then(function(observaciones) { | 664 | .then(function(observaciones) { |
| 673 | $scope.notaPedido.observaciones = observaciones; | 665 | $scope.notaPedido.observaciones = observaciones; |
| 674 | }); | 666 | }); |
| 675 | }; | 667 | }; |
| 676 | 668 | ||
| 677 | $scope.abrirModalCotizacion = function(moneda) { | 669 | $scope.abrirModalCotizacion = function(moneda) { |
| 678 | var modalInstance = $uibModal.open( | 670 | var modalInstance = $uibModal.open( |
| 679 | { | 671 | { |
| 680 | ariaLabelledBy: 'Busqueda de Cotización', | 672 | ariaLabelledBy: 'Busqueda de Cotización', |
| 681 | templateUrl: 'modal-cotizacion.html', | 673 | templateUrl: 'modal-cotizacion.html', |
| 682 | controller: 'focaModalCotizacionController', | 674 | controller: 'focaModalCotizacionController', |
| 683 | size: 'lg', | 675 | size: 'lg', |
| 684 | resolve: { | 676 | resolve: { |
| 685 | idMoneda: function() { | 677 | idMoneda: function() { |
| 686 | return moneda.ID; | 678 | return moneda.ID; |
| 687 | } | 679 | } |
| 688 | } | 680 | } |
| 689 | } | 681 | } |
| 690 | ); | 682 | ); |
| 691 | modalInstance.result.then( | 683 | modalInstance.result.then( |
| 692 | function(cotizacion) { | 684 | function(cotizacion) { |
| 693 | var articulosTablaTemp = $scope.notaPedido.articulosNotaPedido || []; | 685 | var articulosTablaTemp = $scope.notaPedido.articulosNotaPedido || []; |
| 694 | for(var i = 0; i < articulosTablaTemp.length; i++) { | 686 | for(var i = 0; i < articulosTablaTemp.length; i++) { |
| 695 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * | 687 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * |
| 696 | $scope.notaPedido.cotizacion.VENDEDOR; | 688 | $scope.notaPedido.cotizacion.VENDEDOR; |
| 697 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / | 689 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / |
| 698 | cotizacion.VENDEDOR; | 690 | cotizacion.VENDEDOR; |
| 699 | } | 691 | } |
| 700 | $scope.notaPedido.articulosNotaPedido = articulosTablaTemp; | 692 | $scope.notaPedido.articulosNotaPedido = articulosTablaTemp; |
| 701 | $scope.notaPedido.cotizacion = cotizacion; | 693 | $scope.notaPedido.cotizacion = cotizacion; |
| 702 | $scope.notaPedido.cotizacion.moneda = moneda; | 694 | $scope.notaPedido.cotizacion.moneda = moneda; |
| 703 | if(moneda.DETALLE === 'PESOS ARGENTINOS') { | 695 | if(moneda.DETALLE === 'PESOS ARGENTINOS') { |
| 704 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 696 | $scope.$broadcast('removeCabecera', 'Moneda:'); |
| 705 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 697 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); |
| 706 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 698 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); |
| 707 | } else { | 699 | } else { |
| 708 | $scope.$broadcast('addCabecera', { | 700 | $scope.$broadcast('addCabecera', { |
| 709 | label: 'Moneda:', | 701 | label: 'Moneda:', |
| 710 | valor: moneda.DETALLE | 702 | valor: moneda.DETALLE |
| 711 | }); | 703 | }); |
| 712 | $scope.$broadcast('addCabecera', { | 704 | $scope.$broadcast('addCabecera', { |
| 713 | label: 'Fecha cotizacion:', | 705 | label: 'Fecha cotizacion:', |
| 714 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 706 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') |
| 715 | }); | 707 | }); |
| 716 | $scope.$broadcast('addCabecera', { | 708 | $scope.$broadcast('addCabecera', { |
| 717 | label: 'Cotizacion:', | 709 | label: 'Cotizacion:', |
| 718 | valor: $filter('number')(cotizacion.VENDEDOR, '2') | 710 | valor: $filter('number')(cotizacion.VENDEDOR, '2') |
| 719 | }); | 711 | }); |
| 720 | } | 712 | } |
| 721 | }, function() { | 713 | }, function() { |
| 722 | 714 | ||
| 723 | } | 715 | } |
| 724 | ); | 716 | ); |
| 725 | }; | 717 | }; |
| 726 | 718 | ||
| 727 | $scope.agregarATabla = function(key) { | 719 | $scope.agregarATabla = function(key) { |
| 728 | if(key === 13) { | 720 | if(key === 13) { |
| 729 | if($scope.articuloACargar.cantidad === undefined || | 721 | if($scope.articuloACargar.cantidad === undefined || |
| 730 | $scope.articuloACargar.cantidad === 0 || | 722 | $scope.articuloACargar.cantidad === 0 || |
| 731 | $scope.articuloACargar.cantidad === null ) { | 723 | $scope.articuloACargar.cantidad === null ) { |
| 732 | focaModalService.alert('El valor debe ser al menos 1'); | 724 | focaModalService.alert('El valor debe ser al menos 1'); |
| 733 | return; | 725 | return; |
| 734 | } | 726 | } |
| 735 | delete $scope.articuloACargar.sectorCodigo; | 727 | delete $scope.articuloACargar.sectorCodigo; |
| 736 | $scope.notaPedido.articulosNotaPedido.push($scope.articuloACargar); | 728 | $scope.notaPedido.articulosNotaPedido.push($scope.articuloACargar); |
| 737 | $scope.cargando = true; | 729 | $scope.cargando = true; |
| 738 | } | 730 | } |
| 739 | }; | 731 | }; |
| 740 | 732 | ||
| 741 | $scope.quitarArticulo = function(key) { | 733 | $scope.quitarArticulo = function(key) { |
| 742 | $scope.notaPedido.articulosNotaPedido.splice(key, 1); | 734 | $scope.notaPedido.articulosNotaPedido.splice(key, 1); |
| 743 | }; | 735 | }; |
| 744 | 736 | ||
| 745 | $scope.editarArticulo = function(key, articulo) { | 737 | $scope.editarArticulo = function(key, articulo) { |
| 746 | if(key === 13) { | 738 | if(key === 13) { |
| 747 | if(articulo.cantidad === null || articulo.cantidad === 0 || | 739 | if(articulo.cantidad === null || articulo.cantidad === 0 || |
| 748 | articulo.cantidad === undefined) { | 740 | articulo.cantidad === undefined) { |
| 749 | focaModalService.alert('El valor debe ser al menos 1'); | 741 | focaModalService.alert('El valor debe ser al menos 1'); |
| 750 | return; | 742 | return; |
| 751 | } | 743 | } |
| 752 | articulo.editCantidad = false; | 744 | articulo.editCantidad = false; |
| 753 | articulo.editPrecio = false; | 745 | articulo.editPrecio = false; |
| 754 | } | 746 | } |
| 755 | }; | 747 | }; |
| 756 | 748 | ||
| 757 | $scope.cambioEdit = function(articulo, propiedad) { | 749 | $scope.cambioEdit = function(articulo, propiedad) { |
| 758 | if(propiedad === 'cantidad') { | 750 | if(propiedad === 'cantidad') { |
| 759 | articulo.editCantidad = true; | 751 | articulo.editCantidad = true; |
| 760 | } else if(propiedad === 'precio') { | 752 | } else if(propiedad === 'precio') { |
| 761 | articulo.editPrecio = true; | 753 | articulo.editPrecio = true; |
| 762 | } | 754 | } |
| 763 | }; | 755 | }; |
| 764 | 756 | ||
| 765 | $scope.resetFilter = function() { | 757 | $scope.resetFilter = function() { |
| 766 | $scope.articuloACargar = {}; | 758 | $scope.articuloACargar = {}; |
| 767 | $scope.cargando = true; | 759 | $scope.cargando = true; |
| 768 | }; | 760 | }; |
| 769 | //Recibe aviso si el teclado está en uso | 761 | //Recibe aviso si el teclado está en uso |
| 770 | $rootScope.$on('usarTeclado', function(event, data) { | 762 | $rootScope.$on('usarTeclado', function(event, data) { |
| 771 | if(data) { | 763 | if(data) { |
| 772 | $scope.mostrarTeclado = true; | 764 | $scope.mostrarTeclado = true; |
| 773 | return; | 765 | return; |
| 774 | } | 766 | } |
| 775 | $scope.mostrarTeclado = false; | 767 | $scope.mostrarTeclado = false; |
| 776 | }); | 768 | }); |
| 777 | 769 | ||
| 778 | $scope.selectFocus = function($event) { | 770 | $scope.selectFocus = function($event) { |
| 779 | // Si el teclado esta en uso no selecciona el valor | 771 | // Si el teclado esta en uso no selecciona el valor |
| 780 | if($scope.mostrarTeclado) { | 772 | if($scope.mostrarTeclado) { |
| 781 | return; | 773 | return; |
| 782 | } | 774 | } |
| 783 | $event.target.select(); | 775 | $event.target.select(); |
| 784 | }; | 776 | }; |
| 785 | 777 | ||
| 786 | $scope.salir = function() { | 778 | $scope.salir = function() { |
| 787 | $location.path('/'); | 779 | $location.path('/'); |
| 788 | }; | 780 | }; |
| 789 | 781 | ||
| 790 | $scope.parsearATexto = function(articulo) { | 782 | $scope.parsearATexto = function(articulo) { |
| 791 | articulo.cantidad = parseFloat(articulo.cantidad); | 783 | articulo.cantidad = parseFloat(articulo.cantidad); |
| 792 | articulo.precio = parseFloat(articulo.precio); | 784 | articulo.precio = parseFloat(articulo.precio); |
| 793 | }; | 785 | }; |
| 794 | 786 | ||
| 795 | function setearNotaPedido(notaPedido) { | 787 | function setearNotaPedido(notaPedido) { |
| 796 | //añado cabeceras | 788 | //añado cabeceras |
| 797 | $scope.notaPedido = notaPedido; | 789 | $scope.notaPedido = notaPedido; |
| 798 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 790 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
| 799 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 791 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
| 800 | 792 | ||
| 801 | var cabeceras = []; | 793 | var cabeceras = []; |
| 802 | 794 | ||
| 803 | if (notaPedido.cotizacion) { | 795 | if (notaPedido.cotizacion) { |
| 804 | cabeceras.push({ | 796 | cabeceras.push({ |
| 805 | label: 'Moneda:', | 797 | label: 'Moneda:', |
| 806 | valor: notaPedido.cotizacion.moneda.DETALLE | 798 | valor: notaPedido.cotizacion.moneda.DETALLE |
| 807 | }); | 799 | }); |
| 808 | cabeceras.push({ | 800 | cabeceras.push({ |
| 809 | label: 'Fecha cotizacion:', | 801 | label: 'Fecha cotizacion:', |
| 810 | valor: $filter('date')(notaPedido.cotizacion.FECHA, | 802 | valor: $filter('date')(notaPedido.cotizacion.FECHA, |
| 811 | 'dd/MM/yyyy') | 803 | 'dd/MM/yyyy') |
| 812 | }); | 804 | }); |
| 813 | cabeceras.push({ | 805 | cabeceras.push({ |
| 814 | label: 'Cotizacion:', | 806 | label: 'Cotizacion:', |
| 815 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, | 807 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, |
| 816 | '2') | 808 | '2') |
| 817 | }); | 809 | }); |
| 818 | } | 810 | } |
| 819 | if (notaPedido.cliente.COD) { | 811 | if (notaPedido.cliente.COD) { |
| 820 | cabeceras.push({ | 812 | cabeceras.push({ |
| 821 | label: 'Cliente:', | 813 | label: 'Cliente:', |
| 822 | valor: notaPedido.cliente.NOM | 814 | valor: notaPedido.cliente.NOM |
| 823 | }); | 815 | }); |
| 824 | cabeceras.push({ | 816 | cabeceras.push({ |
| 825 | label: 'Domicilio:', | 817 | label: 'Domicilio:', |
| 826 | valor: notaPedido.domicilioStamp | 818 | valor: notaPedido.domicilioStamp |
| 827 | }); | 819 | }); |
| 828 | } | 820 | } |
| 829 | if (notaPedido.vendedor.NUM) { | 821 | if (notaPedido.vendedor.NUM) { |
| 830 | cabeceras.push({ | 822 | cabeceras.push({ |
| 831 | label: 'Vendedor:', | 823 | label: 'Vendedor:', |
| 832 | valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) + | 824 | valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) + |
| 833 | ' - ' + notaPedido.vendedor.NOM | 825 | ' - ' + notaPedido.vendedor.NOM |
| 834 | }); | 826 | }); |
| 835 | } | 827 | } |
| 836 | if (notaPedido.proveedor.COD) { | 828 | if (notaPedido.proveedor.COD) { |
| 837 | cabeceras.push({ | 829 | cabeceras.push({ |
| 838 | label: 'Proveedor:', | 830 | label: 'Proveedor:', |
| 839 | valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) + | 831 | valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) + |
| 840 | ' - ' + notaPedido.proveedor.NOM | 832 | ' - ' + notaPedido.proveedor.NOM |
| 841 | }); | 833 | }); |
| 842 | } | 834 | } |
| 843 | if (notaPedido.notaPedidoPlazo.length) { | 835 | if (notaPedido.notaPedidoPlazo.length) { |
| 844 | cabeceras.push({ | 836 | cabeceras.push({ |
| 845 | label: 'Precios y condiciones:', | 837 | label: 'Precios y condiciones:', |
| 846 | valor: valorPrecioCondicion() + ' ' + | 838 | valor: valorPrecioCondicion() + ' ' + |
| 847 | notaPedidoBusinessService | 839 | notaPedidoBusinessService |
| 848 | .plazoToString(notaPedido.notaPedidoPlazo) | 840 | .plazoToString(notaPedido.notaPedidoPlazo) |
| 849 | }); | 841 | }); |
| 850 | } | 842 | } |
| 851 | if (notaPedido.flete !== undefined) { | 843 | if (notaPedido.flete !== undefined) { |
| 852 | cabeceras.push({ | 844 | cabeceras.push({ |
| 853 | label: 'Flete:', | 845 | label: 'Flete:', |
| 854 | valor: notaPedido.fob === 1 ? 'FOB' : ( | 846 | valor: notaPedido.fob === 1 ? 'FOB' : ( |
| 855 | notaPedido.flete === 1 ? 'Si' : 'No') | 847 | notaPedido.flete === 1 ? 'Si' : 'No') |
| 856 | }); | 848 | }); |
| 857 | } | 849 | } |
| 858 | 850 | ||
| 859 | 851 | ||
| 860 | function valorPrecioCondicion() { | 852 | function valorPrecioCondicion() { |
| 861 | if (notaPedido.idPrecioCondicion > 0) { | 853 | if (notaPedido.idPrecioCondicion > 0) { |
| 862 | return notaPedido.precioCondicion.nombre; | 854 | return notaPedido.precioCondicion.nombre; |
| 863 | } else { | 855 | } else { |
| 864 | return 'Ingreso Manual'; | 856 | return 'Ingreso Manual'; |
| 865 | } | 857 | } |
| 866 | } | 858 | } |
| 867 | 859 | ||
| 868 | if (notaPedido.flete === 1) { | 860 | if (notaPedido.flete === 1) { |
| 869 | var cabeceraBomba = { | 861 | var cabeceraBomba = { |
| 870 | label: 'Bomba:', | 862 | label: 'Bomba:', |
| 871 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' | 863 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' |
| 872 | }; | 864 | }; |
| 873 | if (notaPedido.kilometros) { | 865 | if (notaPedido.kilometros) { |
| 874 | var cabeceraKilometros = { | 866 | var cabeceraKilometros = { |
| 875 | label: 'Kilometros:', | 867 | label: 'Kilometros:', |
| 876 | valor: notaPedido.kilometros | 868 | valor: notaPedido.kilometros |
| 877 | }; | 869 | }; |
| 878 | cabeceras.push(cabeceraKilometros); | 870 | cabeceras.push(cabeceraKilometros); |
| 879 | } | 871 | } |
| 880 | cabeceras.push(cabeceraBomba); | 872 | cabeceras.push(cabeceraBomba); |
| 881 | } | 873 | } |
| 882 | 874 | ||
| 883 | notaPedidoBusinessService.calcularArticulos($scope.notaPedido.articulosNotaPedido, | 875 | notaPedidoBusinessService.calcularArticulos($scope.notaPedido.articulosNotaPedido, |
| 884 | notaPedido.cotizacion.VENDEDOR); | 876 | notaPedido.cotizacion.VENDEDOR); |
| 885 | 877 | ||
| 886 | if (notaPedido.idPrecioCondicion > 0) { | 878 | if (notaPedido.idPrecioCondicion > 0) { |
| 887 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; | 879 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; |
| 888 | } else { | 880 | } else { |
| 889 | $scope.idLista = -1; | 881 | $scope.idLista = -1; |
| 890 | } | 882 | } |
| 891 | 883 | ||
| 892 | $scope.puntoVenta = $filter('rellenarDigitos')( | 884 | $scope.puntoVenta = $filter('rellenarDigitos')( |
| 893 | notaPedido.sucursal, 4 | 885 | notaPedido.sucursal, 4 |
| 894 | ); | 886 | ); |
| 895 | 887 | ||
| 896 | $scope.comprobante = $filter('rellenarDigitos')( | 888 | $scope.comprobante = $filter('rellenarDigitos')( |
| 897 | notaPedido.numeroNotaPedido, 8 | 889 | notaPedido.numeroNotaPedido, 8 |
| 898 | ); | 890 | ); |
| 899 | 891 | ||
| 900 | $scope.notaPedido.notaPedidoPuntoDescarga = | 892 | $scope.notaPedido.notaPedidoPuntoDescarga = |
| 901 | formatearPuntosDescarga(notaPedido.notaPedidoPuntoDescarga || []); | 893 | formatearPuntosDescarga(notaPedido.notaPedidoPuntoDescarga || []); |
| 902 | addArrayCabecera(cabeceras); | 894 | addArrayCabecera(cabeceras); |
| 903 | } | 895 | } |
| 904 | 896 | ||
| 905 | function addArrayCabecera(array) { | 897 | function addArrayCabecera(array) { |
| 906 | for(var i = 0; i < array.length; i++) { | 898 | for(var i = 0; i < array.length; i++) { |
| 907 | $scope.$broadcast('addCabecera', { | 899 | $scope.$broadcast('addCabecera', { |
| 908 | label: array[i].label, | 900 | label: array[i].label, |
| 909 | valor: array[i].valor | 901 | valor: array[i].valor |
| 910 | }); | 902 | }); |
| 911 | } | 903 | } |
| 912 | } | 904 | } |
| 913 | 905 | ||
| 914 | function validarNotaRemitada() { | 906 | function validarNotaRemitada() { |
| 915 | if(!$scope.notaPedido.idRemito) { | 907 | if(!$scope.notaPedido.idRemito) { |
| 916 | return true; | 908 | return true; |
| 917 | }else{ | 909 | }else{ |
| 918 | focaModalService.alert('No se puede editar una nota de pedido remitada'); | 910 | focaModalService.alert('No se puede editar una nota de pedido remitada'); |
| 919 | return false; | 911 | return false; |
| 920 | } | 912 | } |
| 921 | } | 913 | } |
| 922 | 914 | ||
| 923 | function formatearPuntosDescarga(puntosDescarga) { | 915 | function formatearPuntosDescarga(puntosDescarga) { |
| 924 | var result = []; | 916 | var result = []; |
| 925 | 917 | ||
| 926 | puntosDescarga.forEach(function(el) { | 918 | puntosDescarga.forEach(function(el) { |
| 927 | var puntoDescarga = result.filter(function(resultPunto) { | 919 | var puntoDescarga = result.filter(function(resultPunto) { |
| 928 | return resultPunto.id === el.idPuntoDescarga; | 920 | return resultPunto.id === el.idPuntoDescarga; |
| 929 | }); | 921 | }); |
| 930 | 922 | ||
| 931 | if (puntoDescarga.length) { | 923 | if (puntoDescarga.length) { |
| 932 | puntoDescarga[0].articulosAgregados.push({ | 924 | puntoDescarga[0].articulosAgregados.push({ |
| 933 | cantidad: el.cantidad, | 925 | cantidad: el.cantidad, |
| 934 | descripcion: el.producto.descripcion, | 926 | descripcion: el.producto.descripcion, |
| 935 | id: el.producto.id | 927 | id: el.producto.id |
| 936 | }); | 928 | }); |
| 937 | } else { | 929 | } else { |
| 938 | result.push({ | 930 | result.push({ |
| 939 | id: el.puntoDescarga.id, | 931 | id: el.puntoDescarga.id, |
| 940 | id_cliente: el.puntoDescarga.id_cliente, | 932 | id_cliente: el.puntoDescarga.id_cliente, |
| 941 | id_da_config_0: el.puntoDescarga.id_da_config_0, | 933 | id_da_config_0: el.puntoDescarga.id_da_config_0, |
| 942 | latitud: el.puntoDescarga.latitud, | 934 | latitud: el.puntoDescarga.latitud, |
| 943 | longitud: el.puntoDescarga.longitud, | 935 | longitud: el.puntoDescarga.longitud, |
| 944 | descripcion: el.puntoDescarga.descripcion, | 936 | descripcion: el.puntoDescarga.descripcion, |
| 945 | articulosAgregados: [ | 937 | articulosAgregados: [ |
| 946 | { | 938 | { |
| 947 | cantidad: el.cantidad, | 939 | cantidad: el.cantidad, |
| 948 | descripcion: el.producto.descripcion, | 940 | descripcion: el.producto.descripcion, |
| 949 | id: el.producto.id | 941 | id: el.producto.id |
| 950 | } | 942 | } |
| 951 | ] | 943 | ] |
| 952 | }); | 944 | }); |
| 953 | } | 945 | } |
| 954 | }); | 946 | }); |
| 955 | return result; | 947 | return result; |
| 956 | } | 948 | } |
| 957 | 949 | ||
| 958 | function salir() { | 950 | function salir() { |
| 959 | var confirmacion = false; | 951 | var confirmacion = false; |
| 960 | 952 | ||
| 961 | if (!angular.equals($scope.notaPedido, $scope.inicial)) { | 953 | if (!angular.equals($scope.notaPedido, $scope.inicial)) { |
| 962 | confirmacion = true; | 954 | confirmacion = true; |
| 963 | } | 955 | } |
| 964 | 956 | ||
| 965 | if (confirmacion) { | 957 | if (confirmacion) { |
| 966 | focaModalService.confirm( | 958 | focaModalService.confirm( |
| 967 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 959 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
| 968 | ).then(function(data) { | 960 | ).then(function(data) { |
| 969 | if (data) { | 961 | if (data) { |
| 970 | $location.path('/'); | 962 | $location.path('/'); |
| 971 | } | 963 | } |
| 972 | }); | 964 | }); |
| 973 | } else { | 965 | } else { |
| 974 | $location.path('/'); | 966 | $location.path('/'); |
| 975 | } | 967 | } |
| 976 | } | 968 | } |
| 977 | 969 | ||
| 978 | function getLSNotaPedido() { | 970 | function getLSNotaPedido() { |
| 979 | var notaPedido = JSON.parse($localStorage.notaPedido || null); | 971 | var notaPedido = JSON.parse($localStorage.notaPedido || null); |
| 980 | if (notaPedido) { | 972 | if (notaPedido) { |
| 981 | setearNotaPedido(notaPedido); | 973 | setearNotaPedido(notaPedido); |
| 982 | delete $localStorage.notaPedido; | 974 | delete $localStorage.notaPedido; |
| 983 | } | 975 | } |
| 984 | } | 976 | } |
| 985 | 977 | ||
| 986 | function deleteCliente() { | 978 | function deleteCliente() { |
| 987 | delete $scope.notaPedido.domicilioStamp; | 979 | delete $scope.notaPedido.domicilioStamp; |
| 988 | delete $scope.notaPedido.notaPedidoPuntoDescarga; | 980 | delete $scope.notaPedido.notaPedidoPuntoDescarga; |
| 989 | $scope.notaPedido.domicilio = {dom: ''}; | 981 | $scope.notaPedido.domicilio = {dom: ''}; |
| 990 | $scope.notaPedido.cliente = {}; | 982 | $scope.notaPedido.cliente = {}; |
| 991 | $scope.$broadcast('removeCabecera', 'Cliente:'); | 983 | $scope.$broadcast('removeCabecera', 'Cliente:'); |
| 992 | $scope.$broadcast('removeCabecera', 'Domicilio:'); | 984 | $scope.$broadcast('removeCabecera', 'Domicilio:'); |
| 993 | $scope.$broadcast('removeCabecera', 'Puntos de descarga:'); | 985 | $scope.$broadcast('removeCabecera', 'Puntos de descarga:'); |
| 994 | } | 986 | } |
| 995 | } | 987 | } |
| 996 | ]); | 988 | ]); |
| 997 | 989 |