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