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