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