Commit dc9232fb8567627830d428a8df068e08dc4ed219

Authored by Luigi
1 parent 59676d2f30
Exists in master

Arreglo en busqueda de notas de pedido

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