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