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