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