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