Commit c1361c1982fc84fc3b1ed3778359071b63e06fb1

Authored by Marcelo Puebla
1 parent ad8c39620c
Exists in develop

Fix

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