Commit 6ddcff44163e8d9dd0fdf540c414745c1a345581

Authored by Joel Vitelli
1 parent 977cd9c32a
Exists in master

Arreglado check moneda

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