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