Commit 76e3abdef918e74f86d77936d87d78bacc29bb10

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'develop'

Master

Se corrige indentacion de codigo, se agrega mensaje de alerta.

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