Commit 135abf839dd82f1d06a83335f96d09c8723e3f83

Authored by Marcelo Puebla
1 parent ae30a41553
Exists in master

Agregada condicion para no mostrar cabecera de vendedores cuando el cliente no tenga uno asignado.

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