Commit d2fa34eb33ef7e867cf549dd53d3cfd4ef70dcdc

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

conflicts

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