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