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