Commit e5a309052677c5c2a492da47d7c5534c4241942e

Authored by Marcelo Puebla
1 parent d7bab3eb69
Exists in master and in 1 other branch develop

Cambio en envio de parametros.

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