Commit 1720fd12243b454da60030132dbe2dae759fbc82

Authored by Eric Fernandez
Exists in master and in 1 other branch develop

Merge branch 'master' into 'develop'

Master(efernandez)

See merge request !126
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
548 if (angular.equals({}, cliente.vendedor)) {
549
550 focaModalService
551 .alert('El cliente seleccionado no tiene tiene ' +
552 'vendedor asignado.')
553 .then($scope.seleccionarCliente);
554
555 return;
556 }
557
547 $scope.cliente = cliente; 558 $scope.cliente = cliente;
548 $scope.abrirModalDomicilios(cliente); 559 $scope.abrirModalDomicilios(cliente);
549 }, function () { 560 }, function () {
550 } 561 }
551 ); 562 );
552 }; 563 };
553 564
554 $scope.seleccionarEliminarRemito = function () { 565 $scope.seleccionarEliminarRemito = function () {
555 focaModalService.confirm('¿Desea eliminar este remito?').then(function (data) { 566 focaModalService.confirm('¿Desea eliminar este remito?').then(function (data) {
556 if (data) { 567 if (data) {
557 $scope.remito.anulado = true; 568 $scope.remito.anulado = true;
558 delete $scope.remito.remitoPlazo; 569 delete $scope.remito.remitoPlazo;
559 delete $scope.remito.vendedor; 570 delete $scope.remito.vendedor;
560 delete $scope.remito.proveedor; 571 delete $scope.remito.proveedor;
561 delete $scope.remito.cliente; 572 delete $scope.remito.cliente;
562 delete $scope.remito.cotizacion; 573 delete $scope.remito.cotizacion;
563 delete $scope.remito.remitoPuntoDescarga; 574 delete $scope.remito.remitoPuntoDescarga;
564 delete $scope.remito.articulosRemito; 575 delete $scope.remito.articulosRemito;
565 delete $scope.remito.fechaRemito; 576 delete $scope.remito.fechaRemito;
566 crearRemitoService.eliminarRemito($scope.remito); 577 crearRemitoService.eliminarRemito($scope.remito);
567 } 578 }
568 config(); 579 config();
569 }); 580 });
570 }; 581 };
571 582
572 $scope.seleccionarProveedor = function () { 583 $scope.seleccionarProveedor = function () {
573 if (!varlidarRemitoFacturado()) return; 584 if (!varlidarRemitoFacturado()) return;
574 if (!varlidarRemitoAbierto()) return; 585 if (!varlidarRemitoAbierto()) return;
575 var parametrosModal = { 586 var parametrosModal = {
576 titulo: 'Búsqueda de Proveedor', 587 titulo: 'Búsqueda de Proveedor',
577 query: '/proveedor', 588 query: '/proveedor',
578 columnas: [ 589 columnas: [
579 { 590 {
580 nombre: 'Código', 591 nombre: 'Código',
581 propiedad: 'COD', 592 propiedad: 'COD',
582 filtro: { 593 filtro: {
583 nombre: 'rellenarDigitos', 594 nombre: 'rellenarDigitos',
584 parametro: 5 595 parametro: 5
585 } 596 }
586 }, 597 },
587 { 598 {
588 nombre: 'Nombre', 599 nombre: 'Nombre',
589 propiedad: 'NOM' 600 propiedad: 'NOM'
590 }, 601 },
591 { 602 {
592 nombre: 'CUIT', 603 nombre: 'CUIT',
593 propiedad: 'CUIT' 604 propiedad: 'CUIT'
594 } 605 }
595 ], 606 ],
596 tipo: 'POST', 607 tipo: 'POST',
597 json: { razonCuitCod: '' } 608 json: { razonCuitCod: '' }
598 }; 609 };
599 focaModalService.modal(parametrosModal).then( 610 focaModalService.modal(parametrosModal).then(
600 function (proveedor) { 611 function (proveedor) {
601 $scope.seleccionarFlete(proveedor); 612 $scope.seleccionarFlete(proveedor);
602 }, function () { } 613 }, function () { }
603 ); 614 );
604 }; 615 };
605 616
606 $scope.seleccionarDomicilioDeEntrega = function () { 617 $scope.seleccionarDomicilioDeEntrega = function () {
607 if (!varlidarRemitoFacturado()) return; 618 if (!varlidarRemitoFacturado()) return;
608 if (!varlidarRemitoAbierto()) return; 619 if (!varlidarRemitoAbierto()) return;
609 if (!$scope.remito.cliente.COD && !$scope.cliente) { 620 if (!$scope.remito.cliente.COD && !$scope.cliente) {
610 focaModalService.alert('Seleccione un Cliente'); 621 focaModalService.alert('Seleccione un Cliente');
611 return; 622 return;
612 } else { 623 } else {
613 $scope.abrirModalDomicilios($scope.remito.cliente.COD ? 624 $scope.abrirModalDomicilios($scope.remito.cliente.COD ?
614 $scope.remito.cliente.COD : $scope.cliente); 625 $scope.remito.cliente.COD : $scope.cliente);
615 } 626 }
616 }; 627 };
617 628
618 $scope.abrirModalDomicilios = function (cliente) { 629 $scope.abrirModalDomicilios = function (cliente) {
619 var modalInstanceDomicilio = $uibModal.open( 630 var modalInstanceDomicilio = $uibModal.open(
620 { 631 {
621 ariaLabelledBy: 'Busqueda de Domicilios', 632 ariaLabelledBy: 'Busqueda de Domicilios',
622 templateUrl: 'modal-domicilio.html', 633 templateUrl: 'modal-domicilio.html',
623 controller: 'focaModalDomicilioController', 634 controller: 'focaModalDomicilioController',
624 size: 'lg', 635 size: 'lg',
625 resolve: { 636 resolve: {
626 idCliente: function () { 637 idCliente: function () {
627 return $scope.remito.cliente.COD ? $scope.remito.cliente.COD : 638 return $scope.remito.cliente.COD ? $scope.remito.cliente.COD :
628 cliente.cod; 639 cliente.COD;
629 }, 640 },
630 esNuevo: function () { 641 esNuevo: function () {
631 return ($scope.remito.cliente.COD ? false : cliente.esNuevo); 642 return ($scope.remito.cliente.COD ? false : cliente.esNuevo);
632 } 643 }
633 } 644 }
634 } 645 }
635 ); 646 );
636 modalInstanceDomicilio.result 647 modalInstanceDomicilio.result
637 .then(function (domicilio) { 648 .then(function (domicilio) {
638 $scope.remito.domicilio = domicilio; 649 $scope.remito.domicilio = domicilio;
639 if (!$scope.remito.cliente.COD) { 650 $scope.remito.cliente = cliente;
640 $scope.remito.cliente = { 651 $scope.remito.vendedor = cliente.vendedor;
641 COD: cliente.cod, 652
642 CUIT: cliente.cuit, 653 var domicilioStamp =
643 NOM: cliente.nom, 654 domicilio.Calle + ' ' + domicilio.Numero + ', ' +
644 MAIL: cliente.mail, 655 domicilio.Localidad + ', ' + domicilio.Provincia;
645 MOD: cliente.mod, 656
646 IVA: cliente.iva, 657 $scope.remito.domicilioStamp = domicilioStamp;
647 VEN: cliente.ven 658
648 }; 659 $scope.$broadcast('addCabecera', {
649 } 660 label: 'Vendedor:',
650 crearRemitoService.getVendedorById($scope.remito.cliente.VEN) 661 valor: $filter('rellenarDigitos')($scope.remito.vendedor
651 .then(function (res) { 662 .NUM, 3) + ' - ' + $scope.remito.vendedor.NOM
652 if (res.data !== '') { 663 });
653 $scope.remito.vendedor = res.data; 664 $scope.$broadcast('addCabecera', {
654 $scope.$broadcast('addCabecera', { 665 label: 'Cliente:',
655 label: 'Vendedor:', 666 valor: $filter('rellenarDigitos')
656 valor: $filter('rellenarDigitos')($scope.remito.vendedor 667 ($scope.remito.cliente.COD, 3) +
657 .NUM, 3) + ' - ' + $scope.remito.vendedor.NOM 668 ' - ' + $scope.remito.cliente.NOM
658 }); 669 });
659 } 670 $scope.$broadcast('addCabecera', {
660 var domicilioStamp = 671 label: 'Domicilio:',
661 domicilio.Calle + ' ' + domicilio.Numero + ', ' + 672 valor: domicilioStamp
662 domicilio.Localidad + ', ' + domicilio.Provincia; 673 });
663 $scope.remito.domicilioStamp = domicilioStamp; 674
664 $scope.$broadcast('addCabecera', { 675 if (domicilio.verPuntos) {
665 label: 'Cliente:', 676 delete $scope.remito.domicilio.verPuntos;
666 valor: $filter('rellenarDigitos') 677 $scope.seleccionarPuntosDeDescarga();
667 ($scope.remito.cliente.COD, 3) + 678 } else {
668 ' - ' + $scope.remito.cliente.NOM 679 crearRemitoService
669 }); 680 .getPuntosDescargaByClienDom(domicilio.id,
670 $scope.$broadcast('addCabecera', { 681 $scope.remito.cliente.COD)
671 label: 'Domicilio:', 682 .then(function (res) {
672 valor: domicilioStamp 683 if (res.data.length) {
684 $scope.seleccionarPuntosDeDescarga();
685 }
673 }); 686 });
687 }
674 688
675 if (domicilio.verPuntos) { 689 $filter('filter')($scope.botonera,
676 delete $scope.remito.domicilio.verPuntos; 690 { label: 'Cliente' })[0].checked = true;
677 $scope.seleccionarPuntosDeDescarga(); 691 $filter('filter')($scope.botonera,
678 } else { 692 { label: 'Domicilio de Entrega' })[0].checked = true;
679 crearRemitoService
680 .getPuntosDescargaByClienDom(domicilio.id,
681 $scope.remito.cliente.COD)
682 .then(function (res) {
683 if (res.data.length) {
684 $scope.seleccionarPuntosDeDescarga();
685 }
686 });
687 }
688 693
689 $filter('filter')($scope.botonera,
690 { label: 'Cliente' })[0].checked = true;
691 $filter('filter')($scope.botonera,
692 { label: 'Domicilio de Entrega' })[0].checked = true;
693 })
694 .catch(function (e) { console.info(e); });
695 }) 694 })
696 .catch(function (e) { 695 .catch(function (e) {
697 console.info(e); 696 console.info(e);
698 $scope.seleccionarCliente(true); 697 $scope.seleccionarCliente(true);
699 return; 698 return;
700 }); 699 });
701 }; 700 };
702 701
703 $scope.getTotal = function () { 702 $scope.getTotal = function () {
704 var total = 0; 703 var total = 0;
705 var arrayTempArticulos = $scope.articulosFiltro(); 704 var arrayTempArticulos = $scope.articulosFiltro();
706 for (var i = 0; i < arrayTempArticulos.length; i++) { 705 for (var i = 0; i < arrayTempArticulos.length; i++) {
707 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; 706 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad;
708 } 707 }
709 return parseFloat(total.toFixed(2)); 708 return parseFloat(total.toFixed(2));
710 }; 709 };
711 710
712 $scope.getSubTotal = function () { 711 $scope.getSubTotal = function () {
713 if ($scope.articuloACargar) { 712 if ($scope.articuloACargar) {
714 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; 713 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
715 } 714 }
716 }; 715 };
717 716
718 $scope.seleccionarPreciosYCondiciones = function () { 717 $scope.seleccionarPreciosYCondiciones = function () {
719 if (!$scope.remito.cliente.COD) { 718 if (!$scope.remito.cliente.COD) {
720 focaModalService.alert('Primero seleccione un cliente'); 719 focaModalService.alert('Primero seleccione un cliente');
721 return; 720 return;
722 } 721 }
723 if ($scope.remito.articulosRemito.length !== 0) { 722 if ($scope.remito.articulosRemito.length !== 0) {
724 if (varlidarRemitoFacturado() && varlidarRemitoAbierto()) { 723 if (varlidarRemitoFacturado() && varlidarRemitoAbierto()) {
725 abrirModal(); 724 abrirModal();
726 } 725 }
727 } else { 726 } else {
728 abrirModal(); 727 abrirModal();
729 } 728 }
730 729
731 function abrirModal() { 730 function abrirModal() {
732 var parametros = { 731 var parametros = {
733 idCliente: $scope.remito.cliente.COD, 732 idCliente: $scope.remito.cliente.COD,
734 idListaPrecio: $scope.remito.cliente.MOD 733 idListaPrecio: $scope.remito.cliente.MOD
735 }; 734 };
736 var modalInstance = $uibModal.open( 735 var modalInstance = $uibModal.open(
737 { 736 {
738 ariaLabelledBy: 'Busqueda de Precio Condición', 737 ariaLabelledBy: 'Busqueda de Precio Condición',
739 templateUrl: 'modal-precio-condicion.html', 738 templateUrl: 'modal-precio-condicion.html',
740 controller: 'focaModalPrecioCondicionController', 739 controller: 'focaModalPrecioCondicionController',
741 size: 'lg', 740 size: 'lg',
742 resolve: { 741 resolve: {
743 parametros: function () { return parametros; } 742 parametros: function () { return parametros; }
744 } 743 }
745 } 744 }
746 ); 745 );
747 modalInstance.result.then( 746 modalInstance.result.then(
748 function (precioCondicion) { 747 function (precioCondicion) {
749 var cabecera = ''; 748 var cabecera = '';
750 var plazosConcat = ''; 749 var plazosConcat = '';
751 if (!Array.isArray(precioCondicion)) { 750 if (!Array.isArray(precioCondicion)) {
752 $scope.remito.idPrecioCondicion = precioCondicion.listaPrecio.ID; 751 $scope.remito.idPrecioCondicion = precioCondicion.listaPrecio.ID;
753 $scope.remito.remitoPlazo = precioCondicion.plazoPago; 752 $scope.remito.remitoPlazo = precioCondicion.plazoPago;
754 $scope.idLista = parseInt(precioCondicion.listaPrecio.ID) ? 753 $scope.idLista = parseInt(precioCondicion.listaPrecio.ID) ?
755 parseInt(precioCondicion.listaPrecio.ID) : -1; 754 parseInt(precioCondicion.listaPrecio.ID) : -1;
756 $scope.remito.cliente.MOD = precioCondicion.listaPrecio.ID; 755 $scope.remito.cliente.MOD = precioCondicion.listaPrecio.ID;
757 for (var i = 0; i < precioCondicion.plazoPago.length; i++) { 756 for (var i = 0; i < precioCondicion.plazoPago.length; i++) {
758 plazosConcat += precioCondicion.plazoPago[i].dias + ', '; 757 plazosConcat += precioCondicion.plazoPago[i].dias + ', ';
759 } 758 }
760 plazosConcat = plazosConcat.substring(0, plazosConcat.length - 2); 759 plazosConcat = plazosConcat.substring(0, plazosConcat.length - 2);
761 cabecera = $filter('rellenarDigitos') 760 cabecera = $filter('rellenarDigitos')
762 (parseInt(precioCondicion.listaPrecio.ID), 4) + 761 (parseInt(precioCondicion.listaPrecio.ID), 4) +
763 ' - ' + precioCondicion.listaPrecio.DES + ' ' + 762 ' - ' + precioCondicion.listaPrecio.DES + ' ' +
764 plazosConcat.trim(); 763 plazosConcat.trim();
765 } else { //Cuando se ingresan los plazos manualmente 764 } else { //Cuando se ingresan los plazos manualmente
766 $scope.remito.idPrecioCondicion = 0; 765 $scope.remito.idPrecioCondicion = 0;
767 //-1, el modal productos busca todos los productos 766 //-1, el modal productos busca todos los productos
768 $scope.idLista = -1; 767 $scope.idLista = -1;
769 $scope.remito.remitoPlazo = precioCondicion; 768 $scope.remito.remitoPlazo = precioCondicion;
770 for (var j = 0; j < precioCondicion.length; j++) { 769 for (var j = 0; j < precioCondicion.length; j++) {
771 plazosConcat += precioCondicion[j].dias + ' '; 770 plazosConcat += precioCondicion[j].dias + ' ';
772 } 771 }
773 cabecera = plazosConcat.trim(); 772 cabecera = plazosConcat.trim();
774 } 773 }
775 var cabecerasFilter = !$filter('filter')($scope.cabeceras, 774 var cabecerasFilter = !$filter('filter')($scope.cabeceras,
776 { label: 'Precios y Condiciones' }); 775 { label: 'Precios y Condiciones' });
777 if (!cabecerasFilter) { 776 if (!cabecerasFilter) {
778 $scope.cabeceras.push({ 777 $scope.cabeceras.push({
779 label: 'Precios y Condiciones:', 778 label: 'Precios y Condiciones:',
780 valor: parseInt(precioCondicion.listaPrecio.ID) + ' - ' + 779 valor: parseInt(precioCondicion.listaPrecio.ID) + ' - ' +
781 precioCondicion.listaPrecio.DES + ' ' + 780 precioCondicion.listaPrecio.DES + ' ' +
782 remitoBusinessService 781 remitoBusinessService
783 .plazoToString(precioCondicion.plazoPago) 782 .plazoToString(precioCondicion.plazoPago)
784 }); 783 });
785 $scope.remito.idListaPrecio = parseInt(precioCondicion.listaPrecio.ID); 784
785 $scope.remito.idListaPrecio = parseInt(
786 precioCondicion.listaPrecio.ID);
786 } 787 }
787 $filter('filter')($scope.cabeceras, 788 $filter('filter')($scope.cabeceras,
788 { label: 'Precios y Condiciones' })[0].valor = cabecera; 789 { label: 'Precios y Condiciones' })[0].valor = cabecera;
789 790
790 $scope.remito.precioCondicion = precioCondicion; 791 $scope.remito.precioCondicion = precioCondicion;
791 $filter('filter')($scope.botonera, 792 $filter('filter')($scope.botonera,
792 { label: 'Precios y Condiciones' })[0].checked = true; 793 { label: 'Precios y Condiciones' })[0].checked = true;
793 addArrayCabecera($scope.cabeceras); 794 addArrayCabecera($scope.cabeceras);
794 }, function () { 795 }, function () {
795 796
796 } 797 }
797 ); 798 );
798 } 799 }
799 }; 800 };
800 801
801 $scope.seleccionarFlete = function (proveedor) { 802 $scope.seleccionarFlete = function (proveedor) {
802 if (!varlidarRemitoFacturado()) return; 803 if (!varlidarRemitoFacturado()) return;
803 if (!varlidarRemitoAbierto()) return; 804 if (!varlidarRemitoAbierto()) return;
804 var modalInstance = $uibModal.open( 805 var modalInstance = $uibModal.open(
805 { 806 {
806 ariaLabelledBy: 'Busqueda de Flete', 807 ariaLabelledBy: 'Busqueda de Flete',
807 templateUrl: 'modal-flete.html', 808 templateUrl: 'modal-flete.html',
808 controller: 'focaModalFleteController', 809 controller: 'focaModalFleteController',
809 size: 'lg', 810 size: 'lg',
810 resolve: { 811 resolve: {
811 parametrosFlete: 812 parametrosFlete:
812 function () { 813 function () {
813 return { 814 return {
814 flete: $scope.remito.flete ? '1' : 815 flete: $scope.remito.flete ? '1' :
815 ($scope.remito.fob ? 'FOB' : 816 ($scope.remito.fob ? 'FOB' :
816 ($scope.remito.flete === undefined ? 817 ($scope.remito.flete === undefined ?
817 null : '0')), 818 null : '0')),
818 bomba: $scope.remito.bomba ? '1' : 819 bomba: $scope.remito.bomba ? '1' :
819 ($scope.remito.bomba === undefined ? 820 ($scope.remito.bomba === undefined ?
820 null : '0'), 821 null : '0'),
821 kilometros: $scope.remito.kilometros 822 kilometros: $scope.remito.kilometros
822 }; 823 };
823 } 824 }
824 } 825 }
825 } 826 }
826 ); 827 );
827 modalInstance.result.then( 828 modalInstance.result.then(
828 function (datos) { 829 function (datos) {
829 $scope.remitoIsDirty = true; 830 $scope.remitoIsDirty = true;
830 $scope.remito.proveedor = proveedor; 831 $scope.remito.proveedor = proveedor;
831 $scope.remito.idProveedor = proveedor.COD; 832 $scope.remito.idProveedor = proveedor.COD;
832 $scope.$broadcast('addCabecera', { 833 $scope.$broadcast('addCabecera', {
833 label: 'Proveedor:', 834 label: 'Proveedor:',
834 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + 835 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' +
835 proveedor.NOM 836 proveedor.NOM
836 }); 837 });
837 838
838 $scope.remito.flete = datos.flete; 839 $scope.remito.flete = datos.flete;
839 $scope.remito.fob = datos.FOB; 840 $scope.remito.fob = datos.FOB;
840 $scope.remito.bomba = datos.bomba; 841 $scope.remito.bomba = datos.bomba;
841 $scope.remito.kilometros = datos.kilometros; 842 $scope.remito.kilometros = datos.kilometros;
842 843
843 $scope.$broadcast('addCabecera', { 844 $scope.$broadcast('addCabecera', {
844 label: 'Flete:', 845 label: 'Flete:',
845 valor: datos.flete ? 'Si' : ($scope.remito.fob ? 'FOB' : 'No') 846 valor: datos.flete ? 'Si' : ($scope.remito.fob ? 'FOB' : 'No')
846 }); 847 });
847 if (datos.flete) { 848 if (datos.flete) {
848 $scope.$broadcast('addCabecera', { 849 $scope.$broadcast('addCabecera', {
849 label: 'Bomba:', 850 label: 'Bomba:',
850 valor: datos.bomba ? 'Si' : 'No' 851 valor: datos.bomba ? 'Si' : 'No'
851 }); 852 });
852 $scope.$broadcast('addCabecera', { 853 $scope.$broadcast('addCabecera', {
853 label: 'Kilometros:', 854 label: 'Kilometros:',
854 valor: datos.kilometros 855 valor: datos.kilometros
855 }); 856 });
856 } else { 857 } else {
857 $scope.$broadcast('removeCabecera', 'Bomba:'); 858 $scope.$broadcast('removeCabecera', 'Bomba:');
858 $scope.$broadcast('removeCabecera', 'Kilometros:'); 859 $scope.$broadcast('removeCabecera', 'Kilometros:');
859 $scope.remito.bomba = false; 860 $scope.remito.bomba = false;
860 $scope.remito.kilometros = null; 861 $scope.remito.kilometros = null;
861 } 862 }
862 863
863 $filter('filter')($scope.botonera, 864 $filter('filter')($scope.botonera,
864 { label: 'Proveedor' })[0].checked = true; 865 { label: 'Proveedor' })[0].checked = true;
865 }, function () { 866 }, function () {
866 $scope.seleccionarTransportista(); 867 $scope.seleccionarTransportista();
867 } 868 }
868 ); 869 );
869 }; 870 };
870 871
871 $scope.seleccionarMoneda = function () { 872 $scope.seleccionarMoneda = function () {
872 if (!varlidarRemitoFacturado()) return; 873 if (!varlidarRemitoFacturado()) return;
873 if (!varlidarRemitoAbierto()) return; 874 if (!varlidarRemitoAbierto()) return;
874 var parametrosModal = { 875 var parametrosModal = {
875 titulo: 'Búsqueda de monedas', 876 titulo: 'Búsqueda de monedas',
876 query: '/moneda', 877 query: '/moneda',
877 columnas: [ 878 columnas: [
878 { 879 {
879 propiedad: 'DETALLE', 880 propiedad: 'DETALLE',
880 nombre: 'Nombre' 881 nombre: 'Nombre'
881 }, 882 },
882 { 883 {
883 propiedad: 'SIMBOLO', 884 propiedad: 'SIMBOLO',
884 nombre: 'Símbolo' 885 nombre: 'Símbolo'
885 } 886 }
886 ], 887 ],
887 size: 'md' 888 size: 'md'
888 }; 889 };
889 focaModalService.modal(parametrosModal).then( 890 focaModalService.modal(parametrosModal).then(
890 function (moneda) { 891 function (moneda) {
891 892
892 if (moneda.ID !== 1) { 893 if (moneda.ID !== 1) {
893 $scope.abrirModalCotizacion(moneda); 894 $scope.abrirModalCotizacion(moneda);
894 return; 895 return;
895 } 896 }
896 897
897 crearRemitoService.getCotizacionByIdMoneda(1) 898 crearRemitoService.getCotizacionByIdMoneda(1)
898 .then(function (res) { 899 .then(function (res) {
899 900
900 cotizacionPArgentino = res.data[0].cotizaciones[0]; 901 cotizacionPArgentino = res.data[0].cotizaciones[0];
901 cotizacionPArgentino.moneda = moneda; 902 cotizacionPArgentino.moneda = moneda;
902 903
903 actualizarCabeceraMoneda(cotizacionPArgentino); 904 actualizarCabeceraMoneda(cotizacionPArgentino);
904 905
905 $scope.remito.cotizacion = cotizacionPArgentino; 906 $scope.remito.cotizacion = cotizacionPArgentino;
906 }); 907 });
907 }, function () { 908 }, function () {
908 909
909 } 910 }
910 ); 911 );
911 }; 912 };
912 913
913 $scope.seleccionarObservaciones = function () { 914 $scope.seleccionarObservaciones = function () {
914 focaModalService 915 focaModalService
915 .prompt({ 916 .prompt({
916 titulo: 'Observaciones', 917 titulo: 'Observaciones',
917 value: $scope.remito.observaciones, 918 value: $scope.remito.observaciones,
918 textarea: true, 919 textarea: true,
919 readonly: true 920 readonly: true
920 }) 921 })
921 .then(function (observaciones) { 922 .then(function (observaciones) {
922 $scope.remito.observaciones = observaciones; 923 $scope.remito.observaciones = observaciones;
923 }); 924 });
924 }; 925 };
925 926
926 $scope.abrirModalCotizacion = function (moneda) { 927 $scope.abrirModalCotizacion = function (moneda) {
927 var modalInstance = $uibModal.open( 928 var modalInstance = $uibModal.open(
928 { 929 {
929 ariaLabelledBy: 'Busqueda de Cotización', 930 ariaLabelledBy: 'Busqueda de Cotización',
930 templateUrl: 'modal-cotizacion.html', 931 templateUrl: 'modal-cotizacion.html',
931 controller: 'focaModalCotizacionController', 932 controller: 'focaModalCotizacionController',
932 size: 'lg', 933 size: 'lg',
933 resolve: { idMoneda: function () { return moneda.ID; } } 934 resolve: { idMoneda: function () { return moneda.ID; } }
934 } 935 }
935 ); 936 );
936 modalInstance.result.then( 937 modalInstance.result.then(
937 function (cotizacion) { 938 function (cotizacion) {
938 cotizacion.moneda = moneda; 939 cotizacion.moneda = moneda;
939 $scope.remitoIsDirty = true; 940 $scope.remitoIsDirty = true;
940 actualizarCabeceraMoneda(cotizacion); 941 actualizarCabeceraMoneda(cotizacion);
941 $scope.remito.cotizacion = cotizacion; 942 $scope.remito.cotizacion = cotizacion;
942 }, function () { 943 }, function () {
943 944
944 } 945 }
945 ); 946 );
946 }; 947 };
947 948
948 function actualizarCabeceraMoneda(cotizacion) { 949 function actualizarCabeceraMoneda(cotizacion) {
949 950
950 $scope.remito.articulosRemito.forEach(function (art) { 951 $scope.remito.articulosRemito.forEach(function (art) {
951 art.precio = (art.precio * $scope.remito.cotizacion.VENDEDOR).toFixed(4); 952 art.precio = (art.precio * $scope.remito.cotizacion.VENDEDOR).toFixed(4);
952 art.precio = (art.precio / cotizacion.VENDEDOR).toFixed(4); 953 art.precio = (art.precio / cotizacion.VENDEDOR).toFixed(4);
953 }); 954 });
954 955
955 if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { 956 if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') {
956 $scope.$broadcast('removeCabecera', 'Moneda:'); 957 $scope.$broadcast('removeCabecera', 'Moneda:');
957 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 958 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
958 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 959 $scope.$broadcast('removeCabecera', 'Cotizacion:');
959 } else { 960 } else {
960 $scope.$broadcast('addCabecera', { 961 $scope.$broadcast('addCabecera', {
961 label: 'Moneda:', 962 label: 'Moneda:',
962 valor: cotizacion.moneda.DETALLE 963 valor: cotizacion.moneda.DETALLE
963 }); 964 });
964 $scope.$broadcast('addCabecera', { 965 $scope.$broadcast('addCabecera', {
965 label: 'Fecha cotizacion:', 966 label: 'Fecha cotizacion:',
966 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 967 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
967 }); 968 });
968 $scope.$broadcast('addCabecera', { 969 $scope.$broadcast('addCabecera', {
969 label: 'Cotizacion:', 970 label: 'Cotizacion:',
970 valor: $filter('number')(cotizacion.VENDEDOR, '2') 971 valor: $filter('number')(cotizacion.VENDEDOR, '2')
971 }); 972 });
972 } 973 }
973 } 974 }
974 975
975 $scope.agregarATabla = function (key) { 976 $scope.agregarATabla = function (key) {
976 if (key === 13) { 977 if (key === 13) {
977 if (!$scope.articuloACargar.cantidad || !$scope.articuloACargar.precio) { 978 if (!$scope.articuloACargar.cantidad || !$scope.articuloACargar.precio) {
978 focaModalService.alert('El valor debe ser al menos 1'); 979 focaModalService.alert('El valor debe ser al menos 1');
979 return; 980 return;
980 } 981 }
981 delete $scope.articuloACargar.sectorCodigo; 982 delete $scope.articuloACargar.sectorCodigo;
982 $scope.remito.articulosRemito.push($scope.articuloACargar); 983 $scope.remito.articulosRemito.push($scope.articuloACargar);
983 $scope.cargando = true; 984 $scope.cargando = true;
984 } 985 }
985 }; 986 };
986 987
987 $scope.quitarArticulo = function (articulo) { 988 $scope.quitarArticulo = function (articulo) {
988 articulo.idRemito = -1; 989 articulo.idRemito = -1;
989 }; 990 };
990 991
991 $scope.articulosFiltro = function () { 992 $scope.articulosFiltro = function () {
992 993
993 var result = $scope.remito.articulosRemito.filter(function (articulo) { 994 var result = $scope.remito.articulosRemito.filter(function (articulo) {
994 return articulo.idRemito >= 0; 995 return articulo.idRemito >= 0;
995 }); 996 });
996 997
997 // Agrego checked en cabecera si hay datos 998 // Agrego checked en cabecera si hay datos
998 if (result.length) { 999 if (result.length) {
999 $filter('filter')($scope.botonera, { label: 'Productos' })[0].checked = true; 1000 $filter('filter')($scope.botonera, { label: 'Productos' })[0].checked = true;
1000 } else { 1001 } else {
1001 $filter('filter')($scope.botonera, { label: 'Productos' })[0].checked = false; 1002 $filter('filter')($scope.botonera, { label: 'Productos' })[0].checked = false;
1002 } 1003 }
1003 return result; 1004 return result;
1004 }; 1005 };
1005 1006
1006 $scope.editarArticulo = function (key, articulo, tmpCantidad, tmpPrecio) { 1007 $scope.editarArticulo = function (key, articulo, tmpCantidad, tmpPrecio) {
1007 if (key === 13) { 1008 if (key === 13) {
1008 if (!articulo.cantidad || !articulo.precio || !tmpCantidad || !tmpPrecio) { 1009 if (!articulo.cantidad || !articulo.precio || !tmpCantidad || !tmpPrecio) {
1009 focaModalService.alert('Los valores deben ser al menos 1'); 1010 focaModalService.alert('Los valores deben ser al menos 1');
1010 return; 1011 return;
1011 } else if (tmpCantidad === '0' || tmpPrecio === '0') { 1012 } else if (tmpCantidad === '0' || tmpPrecio === '0') {
1012 focaModalService.alert('Esta ingresando un producto con valor 0'); 1013 focaModalService.alert('Esta ingresando un producto con valor 0');
1013 } else if (articulo.cantidad < 0 || articulo.precio < 0) { 1014 } else if (articulo.cantidad < 0 || articulo.precio < 0) {
1014 focaModalService.alert('Los valores no pueden ser negativos'); 1015 focaModalService.alert('Los valores no pueden ser negativos');
1015 return; 1016 return;
1016 } 1017 }
1017 articulo.cantidad = tmpCantidad; 1018 articulo.cantidad = tmpCantidad;
1018 articulo.precio = tmpPrecio; 1019 articulo.precio = tmpPrecio;
1019 $scope.getTotal(); 1020 $scope.getTotal();
1020 articulo.editCantidad = articulo.editPrecio = false; 1021 articulo.editCantidad = articulo.editPrecio = false;
1021 } 1022 }
1022 }; 1023 };
1023 1024
1024 $scope.cancelarEditar = function (articulo) { 1025 $scope.cancelarEditar = function (articulo) {
1025 $scope.tmpCantidad = articulo.cantidad; 1026 $scope.tmpCantidad = articulo.cantidad;
1026 $scope.tmpPrecio = articulo.precio; 1027 $scope.tmpPrecio = articulo.precio;
1027 articulo.editCantidad = articulo.editPrecio = false; 1028 articulo.editCantidad = articulo.editPrecio = false;
1028 }; 1029 };
1029 1030
1030 $scope.cambioEdit = function (articulo, propiedad) { 1031 $scope.cambioEdit = function (articulo, propiedad) {
1031 if (propiedad === 'cantidad') { 1032 if (propiedad === 'cantidad') {
1032 articulo.editCantidad = true; 1033 articulo.editCantidad = true;
1033 } else if (propiedad === 'precio') { 1034 } else if (propiedad === 'precio') {
1034 articulo.editPrecio = true; 1035 articulo.editPrecio = true;
1035 } 1036 }
1036 }; 1037 };
1037 1038
1038 $scope.resetFilter = function () { 1039 $scope.resetFilter = function () {
1039 $scope.articuloACargar = {}; 1040 $scope.articuloACargar = {};
1040 $scope.cargando = true; 1041 $scope.cargando = true;
1041 }; 1042 };
1042 //Recibe aviso si el teclado está en uso 1043 //Recibe aviso si el teclado está en uso
1043 $rootScope.$on('usarTeclado', function (event, data) { 1044 $rootScope.$on('usarTeclado', function (event, data) {
1044 if (data) { 1045 if (data) {
1045 $scope.mostrarTeclado = true; 1046 $scope.mostrarTeclado = true;
1046 return; 1047 return;
1047 } 1048 }
1048 $scope.mostrarTeclado = false; 1049 $scope.mostrarTeclado = false;
1049 }); 1050 });
1050 1051
1051 $scope.selectFocus = function ($event) { 1052 $scope.selectFocus = function ($event) {
1052 // Si el teclado esta en uso no selecciona el valor 1053 // Si el teclado esta en uso no selecciona el valor
1053 if ($scope.mostrarTeclado) { 1054 if ($scope.mostrarTeclado) {
1054 return; 1055 return;
1055 } 1056 }
1056 $event.target.select(); 1057 $event.target.select();
1057 }; 1058 };
1058 1059
1059 function addArrayCabecera(array) { 1060 function addArrayCabecera(array) {
1060 for (var i = 0; i < array.length; i++) { 1061 for (var i = 0; i < array.length; i++) {
1061 $scope.$broadcast('addCabecera', { 1062 $scope.$broadcast('addCabecera', {
1062 label: array[i].label, 1063 label: array[i].label,
1063 valor: array[i].valor 1064 valor: array[i].valor
1064 }); 1065 });
1065 } 1066 }
1066 } 1067 }
1067 1068
1068 function rellenar(relleno, longitud) { 1069 function rellenar(relleno, longitud) {
1069 relleno = '' + relleno; 1070 relleno = '' + relleno;
1070 while (relleno.length < longitud) { 1071 while (relleno.length < longitud) {
1071 relleno = '0' + relleno; 1072 relleno = '0' + relleno;
1072 } 1073 }
1073 return relleno; 1074 return relleno;
1074 } 1075 }
1075 1076
1076 function varlidarRemitoFacturado() { 1077 function varlidarRemitoFacturado() {
1077 if ($scope.remito.estado !== 5) { 1078 if ($scope.remito.estado !== 5) {
1078 return true; 1079 return true;
1079 } else { 1080 } else {
1080 focaModalService.alert('No se puede editar un remito facturado'); 1081 focaModalService.alert('No se puede editar un remito facturado');
1081 return false; 1082 return false;
1082 } 1083 }
1083 } 1084 }
1084 1085
1085 function varlidarRemitoAbierto() { 1086 function varlidarRemitoAbierto() {
1086 if (!$scope.remito.hojaRuta) return true; 1087 if (!$scope.remito.hojaRuta) return true;
1087 if ($scope.remito.hojaRuta.abierta !== '1') { 1088 if ($scope.remito.hojaRuta.abierta !== '1') {
1088 return true; 1089 return true;
1089 } else { 1090 } else {
1090 focaModalService.alert('No se puede editar un remito abierto'); 1091 focaModalService.alert('No se puede editar un remito abierto');
1091 return false; 1092 return false;
1092 } 1093 }
1093 } 1094 }
1094 1095
1095 function salir() { 1096 function salir() {
1096 var confirmacion = false; 1097 var confirmacion = false;
1097 1098
1098 if (!angular.equals($scope.remito, $scope.inicial)) { 1099 if (!angular.equals($scope.remito, $scope.inicial)) {
1099 confirmacion = true; 1100 confirmacion = true;
1100 } 1101 }
1101 1102
1102 if (confirmacion) { 1103 if (confirmacion) {
1103 focaModalService.confirm( 1104 focaModalService.confirm(
1104 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 1105 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
1105 ).then(function (data) { 1106 ).then(function (data) {
1106 if (data) { 1107 if (data) {
1107 $location.path('/'); 1108 $location.path('/');
1108 } 1109 }
1109 }); 1110 });
1110 } else { 1111 } else {
1111 $location.path('/'); 1112 $location.path('/');
1112 } 1113 }
1113 } 1114 }
1114 1115
1115 function enableObservaciones(val) { 1116 function enableObservaciones(val) {
1116 var boton = $scope.botonera.filter(function (botonObs) { 1117 var boton = $scope.botonera.filter(function (botonObs) {
1117 return botonObs.label === 'Observaciones'; 1118 return botonObs.label === 'Observaciones';
1118 }); 1119 });
1119 boton[0].disable = !val; 1120 boton[0].disable = !val;
1120 } 1121 }
1121 1122
1122 function setearRemito(remito) { 1123 function setearRemito(remito) {
1123 //añado cabeceras 1124 //añado cabeceras
1124 console.log(remito); 1125 console.log(remito);
1125 var esAbierto = remito.hojaRuta ? 1126 var esAbierto = remito.hojaRuta ?
1126 (remito.hojaRuta.abierta === '1') : false; 1127 (remito.hojaRuta.abierta === '1') : false;
1127 if (remito.estado !== 5 && remito.id && !esAbierto) { 1128 if (remito.estado !== 5 && remito.id && !esAbierto) {
1128 1129
1129 $scope.botonera.forEach(function (boton) { 1130 $scope.botonera.forEach(function (boton) {
1130 1131
1131 if (boton.label === 'Eliminar Remito') { 1132 if (boton.label === 'Eliminar Remito') {
1132 boton.disable = false; 1133 boton.disable = false;
1133 } 1134 }
1134 }); 1135 });
1135 } 1136 }
1136 $scope.$broadcast('removeCabecera', 'Moneda:'); 1137 $scope.$broadcast('removeCabecera', 'Moneda:');
1137 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 1138 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
1138 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 1139 $scope.$broadcast('removeCabecera', 'Cotizacion:');
1139 $scope.$broadcast('removeCabecera', 'Vendedor:'); 1140 $scope.$broadcast('removeCabecera', 'Vendedor:');
1140 1141
1141 $scope.cabeceras = []; 1142 $scope.cabeceras = [];
1142 1143
1143 if (remito.cotizacion && remito.cotizacion.moneda.CODIGO_AFIP !== 'PES') { 1144 if (remito.cotizacion && remito.cotizacion.moneda.CODIGO_AFIP !== 'PES') {
1144 $scope.cabeceras.push({ 1145 $scope.cabeceras.push({
1145 label: 'Moneda:', 1146 label: 'Moneda:',
1146 valor: remito.cotizacion.moneda.DETALLE 1147 valor: remito.cotizacion.moneda.DETALLE
1147 }); 1148 });
1148 $scope.cabeceras.push({ 1149 $scope.cabeceras.push({
1149 label: 'Fecha cotizacion:', 1150 label: 'Fecha cotizacion:',
1150 valor: $filter('date')(remito.cotizacion.FECHA, 1151 valor: $filter('date')(remito.cotizacion.FECHA,
1151 'dd/MM/yyyy') 1152 'dd/MM/yyyy')
1152 }); 1153 });
1153 $scope.cabeceras.push({ 1154 $scope.cabeceras.push({
1154 label: 'Cotizacion:', 1155 label: 'Cotizacion:',
1155 valor: $filter('number')(remito.cotizacion.VENDEDOR, 1156 valor: $filter('number')(remito.cotizacion.VENDEDOR,
1156 '2') 1157 '2')
1157 }); 1158 });
1158 } 1159 }
1159 1160
1160 if (remito.cotizacion && remito.cotizacion.moneda) { 1161 if (remito.cotizacion && remito.cotizacion.moneda) {
1161 $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; 1162 $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true;
1162 } 1163 }
1163 1164
1164 if (remito.cliente && remito.cliente.COD) { 1165 if (remito.cliente && remito.cliente.COD) {
1165 $scope.cabeceras.push({ 1166 $scope.cabeceras.push({
1166 label: 'Cliente:', 1167 label: 'Cliente:',
1167 valor: $filter('rellenarDigitos')(remito.cliente.COD, 3) + ' - ' + 1168 valor: $filter('rellenarDigitos')(remito.cliente.COD, 3) + ' - ' +
1168 remito.cliente.NOM 1169 remito.cliente.NOM
1169 }); 1170 });
1170 $scope.cabeceras.push({ 1171 $scope.cabeceras.push({
1171 label: 'Domicilio:', 1172 label: 'Domicilio:',
1172 valor: remito.domicilioStamp 1173 valor: remito.domicilioStamp
1173 }); 1174 });
1174 1175
1175 $filter('filter')($scope.botonera, 1176 $filter('filter')($scope.botonera,
1176 { label: 'Domicilio de Entrega' })[0].checked = true; 1177 { label: 'Domicilio de Entrega' })[0].checked = true;
1177 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; 1178 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true;
1178 } 1179 }
1179 if (remito.vendedor && remito.vendedor.NUM) { 1180 if (remito.vendedor && remito.vendedor.NUM) {
1180 $scope.cabeceras.push({ 1181 $scope.cabeceras.push({
1181 label: 'Vendedor:', 1182 label: 'Vendedor:',
1182 valor: $filter('rellenarDigitos')(remito.vendedor.NUM, 3) + 1183 valor: $filter('rellenarDigitos')(remito.vendedor.NUM, 3) +
1183 ' - ' + remito.vendedor.NOM 1184 ' - ' + remito.vendedor.NOM
1184 }); 1185 });
1185 } 1186 }
1186 if (remito.proveedor && remito.proveedor.COD) { 1187 if (remito.proveedor && remito.proveedor.COD) {
1187 $scope.cabeceras.push({ 1188 $scope.cabeceras.push({
1188 label: 'Proveedor:', 1189 label: 'Proveedor:',
1189 valor: $filter('rellenarDigitos')(remito.proveedor.COD, 5) + 1190 valor: $filter('rellenarDigitos')(remito.proveedor.COD, 5) +
1190 ' - ' + remito.proveedor.NOM 1191 ' - ' + remito.proveedor.NOM
1191 }); 1192 });
1192 1193
1193 $filter('filter')($scope.botonera, { label: 'Proveedor' })[0].checked = true; 1194 $filter('filter')($scope.botonera, { label: 'Proveedor' })[0].checked = true;
1194 } 1195 }
1195 if (remito.flete !== undefined && remito.fob !== undefined) { 1196 if (remito.flete !== undefined && remito.fob !== undefined) {
1196 $scope.cabeceras.push({ 1197 $scope.cabeceras.push({
1197 label: 'Flete:', 1198 label: 'Flete:',
1198 valor: remito.fob ? 'FOB' : ( 1199 valor: remito.fob ? 'FOB' : (
1199 remito.flete ? 'Si' : 'No') 1200 remito.flete ? 'Si' : 'No')
1200 }); 1201 });
1201 } 1202 }
1202 if (remito.remitoPlazo) { 1203 if (remito.remitoPlazo) {
1203 valorPrecioCondicion(); 1204 valorPrecioCondicion();
1204 $filter('filter')($scope.botonera, 1205 $filter('filter')($scope.botonera,
1205 { label: 'Precios y condiciones' })[0].checked = true; 1206 { label: 'Precios y condiciones' })[0].checked = true;
1206 } 1207 }
1207 1208
1208 function valorPrecioCondicion() { 1209 function valorPrecioCondicion() {
1209 if (parseInt(remito.idListaPrecio)) { 1210 if (parseInt(remito.idListaPrecio)) {
1210 crearRemitoService.getListaPrecioById(parseInt(remito.idListaPrecio)) 1211 crearRemitoService.getListaPrecioById(parseInt(remito.idListaPrecio))
1211 .then(function (res) { 1212 .then(function (res) {
1212 $timeout(function () { 1213 $timeout(function () {
1213 $scope.cabeceras.push({ 1214 $scope.cabeceras.push({
1214 label: 'Precios y Condiciones:', 1215 label: 'Precios y Condiciones:',
1215 valor: parseInt(res.data[0].ID) + ' - ' + 1216 valor: parseInt(res.data[0].ID) + ' - ' +
1216 res.data[0].DES + ' ' + 1217 res.data[0].DES + ' ' +
1217 remitoBusinessService 1218 remitoBusinessService
1218 .plazoToString(remito.remitoPlazo) 1219 .plazoToString(remito.remitoPlazo)
1219 }); 1220 });
1220 addArrayCabecera($scope.cabeceras); 1221 addArrayCabecera($scope.cabeceras);
1221 }, true); 1222 }, true);
1222 1223
1223 }); 1224 });
1224 $scope.idLista = parseInt(remito.idListaPrecio); 1225 $scope.idLista = parseInt(remito.idListaPrecio);
1225 } 1226 }
1226 } 1227 }
1227 1228
1228 if (remito.flete === 1) { 1229 if (remito.flete === 1) {
1229 var cabeceraBomba = { 1230 var cabeceraBomba = {
1230 label: 'Bomba', 1231 label: 'Bomba',
1231 valor: remito.bomba === 1 ? 'Si' : 'No' 1232 valor: remito.bomba === 1 ? 'Si' : 'No'
1232 }; 1233 };
1233 if (remito.kilometros) { 1234 if (remito.kilometros) {
1234 var cabeceraKilometros = { 1235 var cabeceraKilometros = {
1235 label: 'Kilometros', 1236 label: 'Kilometros',
1236 valor: remito.kilometros 1237 valor: remito.kilometros
1237 }; 1238 };
1238 $scope.cabeceras.push(cabeceraKilometros); 1239 $scope.cabeceras.push(cabeceraKilometros);
1239 } 1240 }
1240 $scope.cabeceras.push(cabeceraBomba); 1241 $scope.cabeceras.push(cabeceraBomba);
1241 } 1242 }
1242 1243
1243 if (remito.idPrecioCondicion > 0) { 1244 if (remito.idPrecioCondicion > 0) {
1244 $scope.idLista = remito.precioCondicion.idListaPrecio; 1245 $scope.idLista = remito.precioCondicion.idListaPrecio;
1245 } else if (remito.idPrecioCondicion) { 1246 } else if (remito.idPrecioCondicion) {
1246 $scope.idLista = -1; 1247 $scope.idLista = -1;
1247 } 1248 }
1248 $scope.puntoVenta = rellenar(remito.sucursal, 4); 1249 $scope.puntoVenta = rellenar(remito.sucursal, 4);
1249 $scope.comprobante = rellenar(remito.numeroRemito, 8); 1250 $scope.comprobante = rellenar(remito.numeroRemito, 8);
1250 $scope.remito = remito; 1251 $scope.remito = remito;
1251 if ($scope.remito.remitoPuntoDescarga.length) { 1252 if ($scope.remito.remitoPuntoDescarga.length) {
1252 var puntoDescarga = []; 1253 var puntoDescarga = [];
1253 1254
1254 $scope.remito.remitoPuntoDescarga.forEach(function (remitoPuntoDescarga) { 1255 $scope.remito.remitoPuntoDescarga.forEach(function (remitoPuntoDescarga) {
1255 puntoDescarga.push(remitoPuntoDescarga.puntoDescarga); 1256 puntoDescarga.push(remitoPuntoDescarga.puntoDescarga);
1256 }); 1257 });
1257 1258
1258 $scope.cabeceras.push({ 1259 $scope.cabeceras.push({
1259 label: 'Puntos de descarga: ', 1260 label: 'Puntos de descarga: ',
1260 valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntoDescarga)) 1261 valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntoDescarga))
1261 }); 1262 });
1262 } 1263 }
1263 $scope.remitoIsDirty = false; 1264 $scope.remitoIsDirty = false;
1264 1265
1265 1266
1266 addArrayCabecera($scope.cabeceras); 1267 addArrayCabecera($scope.cabeceras);
1267 } 1268 }
1268 1269
1269 function getLSRemito() { 1270 function getLSRemito() {
1270 var remito = JSON.parse($localStorage.remito || null); 1271 var remito = JSON.parse($localStorage.remito || null);
1271 if (remito) { 1272 if (remito) {
1272 setearRemito(remito); 1273 setearRemito(remito);
1273 delete $localStorage.remito; 1274 delete $localStorage.remito;
1274 } 1275 }
1275 } 1276 }
1276 1277
1277 function getCabeceraPuntoDescarga(puntosDescarga) { 1278 function getCabeceraPuntoDescarga(puntosDescarga) {
1278 var puntosStamp = ''; 1279 var puntosStamp = '';
1279 puntosDescarga.forEach(function (punto, idx, arr) { 1280 puntosDescarga.forEach(function (punto, idx, arr) {
1280 puntosStamp += punto.descripcion; 1281 puntosStamp += punto.descripcion;
1281 if ((idx + 1) !== arr.length) puntosStamp += ', '; 1282 if ((idx + 1) !== arr.length) puntosStamp += ', ';
1282 }); 1283 });
1283 return puntosStamp; 1284 return puntosStamp;
1284 } 1285 }
1285 1286
1286 function abrirModalMail(id, cliente, numeroRemito) { 1287 function abrirModalMail(id, cliente, numeroRemito) {
1287 focaModalService.mail( 1288 focaModalService.mail(
1288 { 1289 {
1289 titulo: 'Comprobante de remito Nº ' + numeroRemito, 1290 titulo: 'Comprobante de remito Nº ' + numeroRemito,
1290 descarga: { 1291 descarga: {
1291 nombre: numeroRemito + '.pdf', 1292 nombre: numeroRemito + '.pdf',
1292 url: '/remito/comprobante', 1293 url: '/remito/comprobante',
1293 }, 1294 },
1294 envio: { 1295 envio: {
1295 mailCliente: cliente.MAIL, 1296 mailCliente: cliente.MAIL,
1296 url: '/remito/mail', 1297 url: '/remito/mail',
1297 }, 1298 },
1298 options: { 1299 options: {
1299 idRemito: id 1300 idRemito: id
1300 } 1301 }
1301 } 1302 }
1302 ) 1303 )
1303 .then(function (res) { 1304 .then(function (res) {
1304 if (res === false) { 1305 if (res === false) {
1305 abrirModalMail(id); 1306 abrirModalMail(id);
1306 focaModalService.alert('Descarga o envíe su remito ' + 1307 focaModalService.alert('Descarga o envíe su remito ' +
1307 'antes de cerrar esta ventana'); 1308 'antes de cerrar esta ventana');
1308 } 1309 }
1309 }); 1310 });
1310 } 1311 }
1311 //recibo la propiedad por la cual quiero obtener el valor 1312 //recibo la propiedad por la cual quiero obtener el valor
1312 function getImporte(propiedad) { 1313 function getImporte(propiedad) {
1313 var importe = 0; 1314 var importe = 0;