Commit d7bab3eb69879786905140b40ea1c8bb42f7ef1c

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

envio de info al modal de busqueda de cliente.

Showing 1 changed file with 4 additions and 1 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 vendedor: function () { return null; },
535 cobrador: function () { return null; } 535 cobrador: function () { return null; },
536 searchText: function () {
537 return $scope.cliente ? $scope.cliente.nom : '';
538 }
536 }, 539 },
537 size: 'lg' 540 size: 'lg'
538 } 541 }
539 ); 542 );
540 modalInstance.result.then( 543 modalInstance.result.then(
541 function (cliente) { 544 function (cliente) {
542 $scope.cliente = cliente; 545 $scope.cliente = cliente;
543 $scope.abrirModalDomicilios(cliente); 546 $scope.abrirModalDomicilios(cliente);
544 }, function () { 547 }, function () {
545 } 548 }
546 ); 549 );
547 }; 550 };
548 551
549 $scope.seleccionarEliminarRemito = function () { 552 $scope.seleccionarEliminarRemito = function () {
550 focaModalService.confirm('¿Desea eliminar este remito?').then(function (data) { 553 focaModalService.confirm('¿Desea eliminar este remito?').then(function (data) {
551 if (data) { 554 if (data) {
552 $scope.remito.anulado = true; 555 $scope.remito.anulado = true;
553 delete $scope.remito.remitoPlazo; 556 delete $scope.remito.remitoPlazo;
554 delete $scope.remito.vendedor; 557 delete $scope.remito.vendedor;
555 delete $scope.remito.proveedor; 558 delete $scope.remito.proveedor;
556 delete $scope.remito.cliente; 559 delete $scope.remito.cliente;
557 delete $scope.remito.cotizacion; 560 delete $scope.remito.cotizacion;
558 delete $scope.remito.remitoPuntoDescarga; 561 delete $scope.remito.remitoPuntoDescarga;
559 delete $scope.remito.articulosRemito; 562 delete $scope.remito.articulosRemito;
560 delete $scope.remito.fechaRemito; 563 delete $scope.remito.fechaRemito;
561 crearRemitoService.eliminarRemito($scope.remito); 564 crearRemitoService.eliminarRemito($scope.remito);
562 } 565 }
563 config(); 566 config();
564 }); 567 });
565 }; 568 };
566 569
567 $scope.seleccionarProveedor = function () { 570 $scope.seleccionarProveedor = function () {
568 if (!varlidarRemitoFacturado()) return; 571 if (!varlidarRemitoFacturado()) return;
569 if (!varlidarRemitoAbierto()) return; 572 if (!varlidarRemitoAbierto()) return;
570 var parametrosModal = { 573 var parametrosModal = {
571 titulo: 'Búsqueda de Proveedor', 574 titulo: 'Búsqueda de Proveedor',
572 query: '/proveedor', 575 query: '/proveedor',
573 columnas: [ 576 columnas: [
574 { 577 {
575 nombre: 'Código', 578 nombre: 'Código',
576 propiedad: 'COD', 579 propiedad: 'COD',
577 filtro: { 580 filtro: {
578 nombre: 'rellenarDigitos', 581 nombre: 'rellenarDigitos',
579 parametro: 5 582 parametro: 5
580 } 583 }
581 }, 584 },
582 { 585 {
583 nombre: 'Nombre', 586 nombre: 'Nombre',
584 propiedad: 'NOM' 587 propiedad: 'NOM'
585 }, 588 },
586 { 589 {
587 nombre: 'CUIT', 590 nombre: 'CUIT',
588 propiedad: 'CUIT' 591 propiedad: 'CUIT'
589 } 592 }
590 ], 593 ],
591 tipo: 'POST', 594 tipo: 'POST',
592 json: { razonCuitCod: '' } 595 json: { razonCuitCod: '' }
593 }; 596 };
594 focaModalService.modal(parametrosModal).then( 597 focaModalService.modal(parametrosModal).then(
595 function (proveedor) { 598 function (proveedor) {
596 $scope.seleccionarFlete(proveedor); 599 $scope.seleccionarFlete(proveedor);
597 }, function () { } 600 }, function () { }
598 ); 601 );
599 }; 602 };
600 603
601 $scope.seleccionarDomicilioDeEntrega = function () { 604 $scope.seleccionarDomicilioDeEntrega = function () {
602 if (!varlidarRemitoFacturado()) return; 605 if (!varlidarRemitoFacturado()) return;
603 if (!varlidarRemitoAbierto()) return; 606 if (!varlidarRemitoAbierto()) return;
604 if (!$scope.remito.cliente.COD && !$scope.cliente) { 607 if (!$scope.remito.cliente.COD && !$scope.cliente) {
605 focaModalService.alert('Seleccione un Cliente'); 608 focaModalService.alert('Seleccione un Cliente');
606 return; 609 return;
607 } else { 610 } else {
608 $scope.abrirModalDomicilios($scope.remito.cliente.COD ? 611 $scope.abrirModalDomicilios($scope.remito.cliente.COD ?
609 $scope.remito.cliente.COD : $scope.cliente); 612 $scope.remito.cliente.COD : $scope.cliente);
610 } 613 }
611 }; 614 };
612 615
613 $scope.abrirModalDomicilios = function (cliente) { 616 $scope.abrirModalDomicilios = function (cliente) {
614 var modalInstanceDomicilio = $uibModal.open( 617 var modalInstanceDomicilio = $uibModal.open(
615 { 618 {
616 ariaLabelledBy: 'Busqueda de Domicilios', 619 ariaLabelledBy: 'Busqueda de Domicilios',
617 templateUrl: 'modal-domicilio.html', 620 templateUrl: 'modal-domicilio.html',
618 controller: 'focaModalDomicilioController', 621 controller: 'focaModalDomicilioController',
619 size: 'lg', 622 size: 'lg',
620 resolve: { 623 resolve: {
621 idCliente: function () { 624 idCliente: function () {
622 return $scope.remito.cliente.COD ? $scope.remito.cliente.COD : 625 return $scope.remito.cliente.COD ? $scope.remito.cliente.COD :
623 cliente.cod; 626 cliente.cod;
624 }, 627 },
625 esNuevo: function () { 628 esNuevo: function () {
626 return ($scope.remito.cliente.COD ? false : cliente.esNuevo); 629 return ($scope.remito.cliente.COD ? false : cliente.esNuevo);
627 } 630 }
628 } 631 }
629 } 632 }
630 ); 633 );
631 modalInstanceDomicilio.result 634 modalInstanceDomicilio.result
632 .then(function (domicilio) { 635 .then(function (domicilio) {
633 $scope.remito.domicilio = domicilio; 636 $scope.remito.domicilio = domicilio;
634 if (!$scope.remito.cliente.COD) { 637 if (!$scope.remito.cliente.COD) {
635 $scope.remito.cliente = { 638 $scope.remito.cliente = {
636 COD: cliente.cod, 639 COD: cliente.cod,
637 CUIT: cliente.cuit, 640 CUIT: cliente.cuit,
638 NOM: cliente.nom, 641 NOM: cliente.nom,
639 MAIL: cliente.mail, 642 MAIL: cliente.mail,
640 MOD: cliente.mod, 643 MOD: cliente.mod,
641 IVA: cliente.iva, 644 IVA: cliente.iva,
642 VEN: cliente.ven 645 VEN: cliente.ven
643 }; 646 };
644 } 647 }
645 crearRemitoService.getVendedorById($scope.remito.cliente.VEN) 648 crearRemitoService.getVendedorById($scope.remito.cliente.VEN)
646 .then(function (res) { 649 .then(function (res) {
647 if (res.data !== '') { 650 if (res.data !== '') {
648 $scope.remito.vendedor = res.data; 651 $scope.remito.vendedor = res.data;
649 $scope.$broadcast('addCabecera', { 652 $scope.$broadcast('addCabecera', {
650 label: 'Vendedor:', 653 label: 'Vendedor:',
651 valor: $filter('rellenarDigitos')($scope.remito.vendedor 654 valor: $filter('rellenarDigitos')($scope.remito.vendedor
652 .NUM, 3) + ' - ' + $scope.remito.vendedor.NOM 655 .NUM, 3) + ' - ' + $scope.remito.vendedor.NOM
653 }); 656 });
654 } 657 }
655 var domicilioStamp = 658 var domicilioStamp =
656 domicilio.Calle + ' ' + domicilio.Numero + ', ' + 659 domicilio.Calle + ' ' + domicilio.Numero + ', ' +
657 domicilio.Localidad + ', ' + domicilio.Provincia; 660 domicilio.Localidad + ', ' + domicilio.Provincia;
658 $scope.remito.domicilioStamp = domicilioStamp; 661 $scope.remito.domicilioStamp = domicilioStamp;
659 $scope.$broadcast('addCabecera', { 662 $scope.$broadcast('addCabecera', {
660 label: 'Cliente:', 663 label: 'Cliente:',
661 valor: $filter('rellenarDigitos') 664 valor: $filter('rellenarDigitos')
662 ($scope.remito.cliente.COD, 3) + 665 ($scope.remito.cliente.COD, 3) +
663 ' - ' + $scope.remito.cliente.NOM 666 ' - ' + $scope.remito.cliente.NOM
664 }); 667 });
665 $scope.$broadcast('addCabecera', { 668 $scope.$broadcast('addCabecera', {
666 label: 'Domicilio:', 669 label: 'Domicilio:',
667 valor: domicilioStamp 670 valor: domicilioStamp
668 }); 671 });
669 672
670 if (domicilio.verPuntos) { 673 if (domicilio.verPuntos) {
671 delete $scope.remito.domicilio.verPuntos; 674 delete $scope.remito.domicilio.verPuntos;
672 $scope.seleccionarPuntosDeDescarga(); 675 $scope.seleccionarPuntosDeDescarga();
673 } else { 676 } else {
674 crearRemitoService 677 crearRemitoService
675 .getPuntosDescargaByClienDom(domicilio.id, 678 .getPuntosDescargaByClienDom(domicilio.id,
676 $scope.remito.cliente.COD) 679 $scope.remito.cliente.COD)
677 .then(function (res) { 680 .then(function (res) {
678 if (res.data.length) { 681 if (res.data.length) {
679 $scope.seleccionarPuntosDeDescarga(); 682 $scope.seleccionarPuntosDeDescarga();
680 } 683 }
681 }); 684 });
682 } 685 }
683 686
684 $filter('filter')($scope.botonera, 687 $filter('filter')($scope.botonera,
685 { label: 'Cliente' })[0].checked = true; 688 { label: 'Cliente' })[0].checked = true;
686 $filter('filter')($scope.botonera, 689 $filter('filter')($scope.botonera,
687 { label: 'Domicilio de Entrega' })[0].checked = true; 690 { label: 'Domicilio de Entrega' })[0].checked = true;
688 }) 691 })
689 .catch(function (e) { console.info(e); }); 692 .catch(function (e) { console.info(e); });
690 }) 693 })
691 .catch(function (e) { 694 .catch(function (e) {
692 console.info(e); 695 console.info(e);
693 $scope.seleccionarCliente(true); 696 $scope.seleccionarCliente(true);
694 return; 697 return;
695 }); 698 });
696 }; 699 };
697 700
698 $scope.getTotal = function () { 701 $scope.getTotal = function () {
699 var total = 0; 702 var total = 0;
700 var arrayTempArticulos = $scope.articulosFiltro(); 703 var arrayTempArticulos = $scope.articulosFiltro();
701 for (var i = 0; i < arrayTempArticulos.length; i++) { 704 for (var i = 0; i < arrayTempArticulos.length; i++) {
702 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; 705 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad;
703 } 706 }
704 return parseFloat(total.toFixed(2)); 707 return parseFloat(total.toFixed(2));
705 }; 708 };
706 709
707 $scope.getSubTotal = function () { 710 $scope.getSubTotal = function () {
708 if ($scope.articuloACargar) { 711 if ($scope.articuloACargar) {
709 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; 712 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
710 } 713 }
711 }; 714 };
712 715
713 $scope.seleccionarPreciosYCondiciones = function () { 716 $scope.seleccionarPreciosYCondiciones = function () {
714 if (!$scope.remito.cliente.COD) { 717 if (!$scope.remito.cliente.COD) {
715 focaModalService.alert('Primero seleccione un cliente'); 718 focaModalService.alert('Primero seleccione un cliente');
716 return; 719 return;
717 } 720 }
718 if ($scope.remito.articulosRemito.length !== 0) { 721 if ($scope.remito.articulosRemito.length !== 0) {
719 if (varlidarRemitoFacturado() && varlidarRemitoAbierto()) { 722 if (varlidarRemitoFacturado() && varlidarRemitoAbierto()) {
720 abrirModal(); 723 abrirModal();
721 } 724 }
722 } else { 725 } else {
723 abrirModal(); 726 abrirModal();
724 } 727 }
725 728
726 function abrirModal() { 729 function abrirModal() {
727 var parametros = { 730 var parametros = {
728 idCliente: $scope.remito.cliente.COD, 731 idCliente: $scope.remito.cliente.COD,
729 idListaPrecio: $scope.remito.cliente.MOD 732 idListaPrecio: $scope.remito.cliente.MOD
730 }; 733 };
731 var modalInstance = $uibModal.open( 734 var modalInstance = $uibModal.open(
732 { 735 {
733 ariaLabelledBy: 'Busqueda de Precio Condición', 736 ariaLabelledBy: 'Busqueda de Precio Condición',
734 templateUrl: 'modal-precio-condicion.html', 737 templateUrl: 'modal-precio-condicion.html',
735 controller: 'focaModalPrecioCondicionController', 738 controller: 'focaModalPrecioCondicionController',
736 size: 'lg', 739 size: 'lg',
737 resolve: { 740 resolve: {
738 parametros: function () { return parametros; } 741 parametros: function () { return parametros; }
739 } 742 }
740 } 743 }
741 ); 744 );
742 modalInstance.result.then( 745 modalInstance.result.then(
743 function (precioCondicion) { 746 function (precioCondicion) {
744 var cabecera = ''; 747 var cabecera = '';
745 var plazosConcat = ''; 748 var plazosConcat = '';
746 if (!Array.isArray(precioCondicion)) { 749 if (!Array.isArray(precioCondicion)) {
747 $scope.remito.idPrecioCondicion = precioCondicion.listaPrecio.ID; 750 $scope.remito.idPrecioCondicion = precioCondicion.listaPrecio.ID;
748 $scope.remito.remitoPlazo = precioCondicion.plazoPago; 751 $scope.remito.remitoPlazo = precioCondicion.plazoPago;
749 $scope.idLista = parseInt(precioCondicion.listaPrecio.ID) ? 752 $scope.idLista = parseInt(precioCondicion.listaPrecio.ID) ?
750 parseInt(precioCondicion.listaPrecio.ID) : -1; 753 parseInt(precioCondicion.listaPrecio.ID) : -1;
751 $scope.remito.cliente.MOD = precioCondicion.listaPrecio.ID; 754 $scope.remito.cliente.MOD = precioCondicion.listaPrecio.ID;
752 for (var i = 0; i < precioCondicion.plazoPago.length; i++) { 755 for (var i = 0; i < precioCondicion.plazoPago.length; i++) {
753 plazosConcat += precioCondicion.plazoPago[i].dias + ', '; 756 plazosConcat += precioCondicion.plazoPago[i].dias + ', ';
754 } 757 }
755 plazosConcat = plazosConcat.substring(0, plazosConcat.length - 2); 758 plazosConcat = plazosConcat.substring(0, plazosConcat.length - 2);
756 cabecera = $filter('rellenarDigitos') 759 cabecera = $filter('rellenarDigitos')
757 (parseInt(precioCondicion.listaPrecio.ID), 4) + 760 (parseInt(precioCondicion.listaPrecio.ID), 4) +
758 ' - ' + precioCondicion.listaPrecio.DES + ' ' + 761 ' - ' + precioCondicion.listaPrecio.DES + ' ' +
759 plazosConcat.trim(); 762 plazosConcat.trim();
760 } else { //Cuando se ingresan los plazos manualmente 763 } else { //Cuando se ingresan los plazos manualmente
761 $scope.remito.idPrecioCondicion = 0; 764 $scope.remito.idPrecioCondicion = 0;
762 //-1, el modal productos busca todos los productos 765 //-1, el modal productos busca todos los productos
763 $scope.idLista = -1; 766 $scope.idLista = -1;
764 $scope.remito.remitoPlazo = precioCondicion; 767 $scope.remito.remitoPlazo = precioCondicion;
765 for (var j = 0; j < precioCondicion.length; j++) { 768 for (var j = 0; j < precioCondicion.length; j++) {
766 plazosConcat += precioCondicion[j].dias + ' '; 769 plazosConcat += precioCondicion[j].dias + ' ';
767 } 770 }
768 cabecera = plazosConcat.trim(); 771 cabecera = plazosConcat.trim();
769 } 772 }
770 var cabecerasFilter = !$filter('filter')($scope.cabeceras, 773 var cabecerasFilter = !$filter('filter')($scope.cabeceras,
771 { label: 'Precios y Condiciones' }); 774 { label: 'Precios y Condiciones' });
772 if (!cabecerasFilter) { 775 if (!cabecerasFilter) {
773 $scope.cabeceras.push({ 776 $scope.cabeceras.push({
774 label: 'Precios y Condiciones:', 777 label: 'Precios y Condiciones:',
775 valor: parseInt(precioCondicion.listaPrecio.ID) + ' - ' + 778 valor: parseInt(precioCondicion.listaPrecio.ID) + ' - ' +
776 precioCondicion.listaPrecio.DES + ' ' + 779 precioCondicion.listaPrecio.DES + ' ' +
777 remitoBusinessService 780 remitoBusinessService
778 .plazoToString(precioCondicion.plazoPago) 781 .plazoToString(precioCondicion.plazoPago)
779 }); 782 });
780 $scope.remito.idListaPrecio = parseInt(precioCondicion.listaPrecio.ID); 783 $scope.remito.idListaPrecio = parseInt(precioCondicion.listaPrecio.ID);
781 } 784 }
782 $filter('filter')($scope.cabeceras, 785 $filter('filter')($scope.cabeceras,
783 { label: 'Precios y Condiciones' })[0].valor = cabecera; 786 { label: 'Precios y Condiciones' })[0].valor = cabecera;
784 787
785 $scope.remito.precioCondicion = precioCondicion; 788 $scope.remito.precioCondicion = precioCondicion;
786 $filter('filter')($scope.botonera, 789 $filter('filter')($scope.botonera,
787 { label: 'Precios y Condiciones' })[0].checked = true; 790 { label: 'Precios y Condiciones' })[0].checked = true;
788 addArrayCabecera($scope.cabeceras); 791 addArrayCabecera($scope.cabeceras);
789 }, function () { 792 }, function () {
790 793
791 } 794 }
792 ); 795 );
793 } 796 }
794 }; 797 };
795 798
796 $scope.seleccionarFlete = function (proveedor) { 799 $scope.seleccionarFlete = function (proveedor) {
797 if (!varlidarRemitoFacturado()) return; 800 if (!varlidarRemitoFacturado()) return;
798 if (!varlidarRemitoAbierto()) return; 801 if (!varlidarRemitoAbierto()) return;
799 var modalInstance = $uibModal.open( 802 var modalInstance = $uibModal.open(
800 { 803 {
801 ariaLabelledBy: 'Busqueda de Flete', 804 ariaLabelledBy: 'Busqueda de Flete',
802 templateUrl: 'modal-flete.html', 805 templateUrl: 'modal-flete.html',
803 controller: 'focaModalFleteController', 806 controller: 'focaModalFleteController',
804 size: 'lg', 807 size: 'lg',
805 resolve: { 808 resolve: {
806 parametrosFlete: 809 parametrosFlete:
807 function () { 810 function () {
808 return { 811 return {
809 flete: $scope.remito.flete ? '1' : 812 flete: $scope.remito.flete ? '1' :
810 ($scope.remito.fob ? 'FOB' : 813 ($scope.remito.fob ? 'FOB' :
811 ($scope.remito.flete === undefined ? 814 ($scope.remito.flete === undefined ?
812 null : '0')), 815 null : '0')),
813 bomba: $scope.remito.bomba ? '1' : 816 bomba: $scope.remito.bomba ? '1' :
814 ($scope.remito.bomba === undefined ? 817 ($scope.remito.bomba === undefined ?
815 null : '0'), 818 null : '0'),
816 kilometros: $scope.remito.kilometros 819 kilometros: $scope.remito.kilometros
817 }; 820 };
818 } 821 }
819 } 822 }
820 } 823 }
821 ); 824 );
822 modalInstance.result.then( 825 modalInstance.result.then(
823 function (datos) { 826 function (datos) {
824 $scope.remitoIsDirty = true; 827 $scope.remitoIsDirty = true;
825 $scope.remito.proveedor = proveedor; 828 $scope.remito.proveedor = proveedor;
826 $scope.remito.idProveedor = proveedor.COD; 829 $scope.remito.idProveedor = proveedor.COD;
827 $scope.$broadcast('addCabecera', { 830 $scope.$broadcast('addCabecera', {
828 label: 'Proveedor:', 831 label: 'Proveedor:',
829 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + 832 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' +
830 proveedor.NOM 833 proveedor.NOM
831 }); 834 });
832 835
833 $scope.remito.flete = datos.flete; 836 $scope.remito.flete = datos.flete;
834 $scope.remito.fob = datos.FOB; 837 $scope.remito.fob = datos.FOB;
835 $scope.remito.bomba = datos.bomba; 838 $scope.remito.bomba = datos.bomba;
836 $scope.remito.kilometros = datos.kilometros; 839 $scope.remito.kilometros = datos.kilometros;
837 840
838 $scope.$broadcast('addCabecera', { 841 $scope.$broadcast('addCabecera', {
839 label: 'Flete:', 842 label: 'Flete:',
840 valor: datos.flete ? 'Si' : ($scope.remito.fob ? 'FOB' : 'No') 843 valor: datos.flete ? 'Si' : ($scope.remito.fob ? 'FOB' : 'No')
841 }); 844 });
842 if (datos.flete) { 845 if (datos.flete) {
843 $scope.$broadcast('addCabecera', { 846 $scope.$broadcast('addCabecera', {
844 label: 'Bomba:', 847 label: 'Bomba:',
845 valor: datos.bomba ? 'Si' : 'No' 848 valor: datos.bomba ? 'Si' : 'No'
846 }); 849 });
847 $scope.$broadcast('addCabecera', { 850 $scope.$broadcast('addCabecera', {
848 label: 'Kilometros:', 851 label: 'Kilometros:',
849 valor: datos.kilometros 852 valor: datos.kilometros
850 }); 853 });
851 } else { 854 } else {
852 $scope.$broadcast('removeCabecera', 'Bomba:'); 855 $scope.$broadcast('removeCabecera', 'Bomba:');
853 $scope.$broadcast('removeCabecera', 'Kilometros:'); 856 $scope.$broadcast('removeCabecera', 'Kilometros:');
854 $scope.remito.bomba = false; 857 $scope.remito.bomba = false;
855 $scope.remito.kilometros = null; 858 $scope.remito.kilometros = null;
856 } 859 }
857 860
858 $filter('filter')($scope.botonera, 861 $filter('filter')($scope.botonera,
859 { label: 'Proveedor' })[0].checked = true; 862 { label: 'Proveedor' })[0].checked = true;
860 }, function () { 863 }, function () {
861 $scope.seleccionarTransportista(); 864 $scope.seleccionarTransportista();
862 } 865 }
863 ); 866 );
864 }; 867 };
865 868
866 $scope.seleccionarMoneda = function () { 869 $scope.seleccionarMoneda = function () {
867 if (!varlidarRemitoFacturado()) return; 870 if (!varlidarRemitoFacturado()) return;
868 if (!varlidarRemitoAbierto()) return; 871 if (!varlidarRemitoAbierto()) return;
869 var parametrosModal = { 872 var parametrosModal = {
870 titulo: 'Búsqueda de monedas', 873 titulo: 'Búsqueda de monedas',
871 query: '/moneda', 874 query: '/moneda',
872 columnas: [ 875 columnas: [
873 { 876 {
874 propiedad: 'DETALLE', 877 propiedad: 'DETALLE',
875 nombre: 'Nombre' 878 nombre: 'Nombre'
876 }, 879 },
877 { 880 {
878 propiedad: 'SIMBOLO', 881 propiedad: 'SIMBOLO',
879 nombre: 'Símbolo' 882 nombre: 'Símbolo'
880 } 883 }
881 ], 884 ],
882 size: 'md' 885 size: 'md'
883 }; 886 };
884 focaModalService.modal(parametrosModal).then( 887 focaModalService.modal(parametrosModal).then(
885 function (moneda) { 888 function (moneda) {
886 889
887 if (moneda.ID !== 1) { 890 if (moneda.ID !== 1) {
888 $scope.abrirModalCotizacion(moneda); 891 $scope.abrirModalCotizacion(moneda);
889 return; 892 return;
890 } 893 }
891 894
892 crearRemitoService.getCotizacionByIdMoneda(1) 895 crearRemitoService.getCotizacionByIdMoneda(1)
893 .then(function (res) { 896 .then(function (res) {
894 897
895 cotizacionPArgentino = res.data[0].cotizaciones[0]; 898 cotizacionPArgentino = res.data[0].cotizaciones[0];
896 cotizacionPArgentino.moneda = moneda; 899 cotizacionPArgentino.moneda = moneda;
897 900
898 actualizarCabeceraMoneda(cotizacionPArgentino); 901 actualizarCabeceraMoneda(cotizacionPArgentino);
899 902
900 $scope.remito.cotizacion = cotizacionPArgentino; 903 $scope.remito.cotizacion = cotizacionPArgentino;
901 }); 904 });
902 }, function () { 905 }, function () {
903 906
904 } 907 }
905 ); 908 );
906 }; 909 };
907 910
908 $scope.seleccionarObservaciones = function () { 911 $scope.seleccionarObservaciones = function () {
909 focaModalService 912 focaModalService
910 .prompt({ 913 .prompt({
911 titulo: 'Observaciones', 914 titulo: 'Observaciones',
912 value: $scope.remito.observaciones, 915 value: $scope.remito.observaciones,
913 textarea: true, 916 textarea: true,
914 readonly: true 917 readonly: true
915 }) 918 })
916 .then(function (observaciones) { 919 .then(function (observaciones) {
917 $scope.remito.observaciones = observaciones; 920 $scope.remito.observaciones = observaciones;
918 }); 921 });
919 }; 922 };
920 923
921 $scope.abrirModalCotizacion = function (moneda) { 924 $scope.abrirModalCotizacion = function (moneda) {
922 var modalInstance = $uibModal.open( 925 var modalInstance = $uibModal.open(
923 { 926 {
924 ariaLabelledBy: 'Busqueda de Cotización', 927 ariaLabelledBy: 'Busqueda de Cotización',
925 templateUrl: 'modal-cotizacion.html', 928 templateUrl: 'modal-cotizacion.html',
926 controller: 'focaModalCotizacionController', 929 controller: 'focaModalCotizacionController',
927 size: 'lg', 930 size: 'lg',
928 resolve: { idMoneda: function () { return moneda.ID; } } 931 resolve: { idMoneda: function () { return moneda.ID; } }
929 } 932 }
930 ); 933 );
931 modalInstance.result.then( 934 modalInstance.result.then(
932 function (cotizacion) { 935 function (cotizacion) {
933 cotizacion.moneda = moneda; 936 cotizacion.moneda = moneda;
934 $scope.remitoIsDirty = true; 937 $scope.remitoIsDirty = true;
935 actualizarCabeceraMoneda(cotizacion); 938 actualizarCabeceraMoneda(cotizacion);
936 $scope.remito.cotizacion = cotizacion; 939 $scope.remito.cotizacion = cotizacion;
937 }, function () { 940 }, function () {
938 941
939 } 942 }
940 ); 943 );
941 }; 944 };
942 945
943 function actualizarCabeceraMoneda(cotizacion) { 946 function actualizarCabeceraMoneda(cotizacion) {
944 947
945 $scope.remito.articulosRemito.forEach(function (art) { 948 $scope.remito.articulosRemito.forEach(function (art) {
946 art.precio = (art.precio * $scope.remito.cotizacion.VENDEDOR).toFixed(4); 949 art.precio = (art.precio * $scope.remito.cotizacion.VENDEDOR).toFixed(4);
947 art.precio = (art.precio / cotizacion.VENDEDOR).toFixed(4); 950 art.precio = (art.precio / cotizacion.VENDEDOR).toFixed(4);
948 }); 951 });
949 952
950 if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { 953 if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') {
951 $scope.$broadcast('removeCabecera', 'Moneda:'); 954 $scope.$broadcast('removeCabecera', 'Moneda:');
952 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 955 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
953 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 956 $scope.$broadcast('removeCabecera', 'Cotizacion:');
954 } else { 957 } else {
955 $scope.$broadcast('addCabecera', { 958 $scope.$broadcast('addCabecera', {
956 label: 'Moneda:', 959 label: 'Moneda:',
957 valor: cotizacion.moneda.DETALLE 960 valor: cotizacion.moneda.DETALLE
958 }); 961 });
959 $scope.$broadcast('addCabecera', { 962 $scope.$broadcast('addCabecera', {
960 label: 'Fecha cotizacion:', 963 label: 'Fecha cotizacion:',
961 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 964 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
962 }); 965 });
963 $scope.$broadcast('addCabecera', { 966 $scope.$broadcast('addCabecera', {
964 label: 'Cotizacion:', 967 label: 'Cotizacion:',
965 valor: $filter('number')(cotizacion.VENDEDOR, '2') 968 valor: $filter('number')(cotizacion.VENDEDOR, '2')
966 }); 969 });
967 } 970 }
968 } 971 }
969 972
970 $scope.agregarATabla = function (key) { 973 $scope.agregarATabla = function (key) {
971 if (key === 13) { 974 if (key === 13) {
972 if (!$scope.articuloACargar.cantidad || !$scope.articuloACargar.precio) { 975 if (!$scope.articuloACargar.cantidad || !$scope.articuloACargar.precio) {
973 focaModalService.alert('El valor debe ser al menos 1'); 976 focaModalService.alert('El valor debe ser al menos 1');
974 return; 977 return;
975 } 978 }
976 delete $scope.articuloACargar.sectorCodigo; 979 delete $scope.articuloACargar.sectorCodigo;
977 $scope.remito.articulosRemito.push($scope.articuloACargar); 980 $scope.remito.articulosRemito.push($scope.articuloACargar);
978 $scope.cargando = true; 981 $scope.cargando = true;
979 } 982 }
980 }; 983 };
981 984
982 $scope.quitarArticulo = function (articulo) { 985 $scope.quitarArticulo = function (articulo) {
983 articulo.idRemito = -1; 986 articulo.idRemito = -1;
984 }; 987 };
985 988
986 $scope.articulosFiltro = function () { 989 $scope.articulosFiltro = function () {
987 990
988 var result = $scope.remito.articulosRemito.filter(function (articulo) { 991 var result = $scope.remito.articulosRemito.filter(function (articulo) {
989 return articulo.idRemito >= 0; 992 return articulo.idRemito >= 0;
990 }); 993 });
991 994
992 // Agrego checked en cabecera si hay datos 995 // Agrego checked en cabecera si hay datos
993 if (result.length) { 996 if (result.length) {
994 $filter('filter')($scope.botonera, { label: 'Productos' })[0].checked = true; 997 $filter('filter')($scope.botonera, { label: 'Productos' })[0].checked = true;
995 } else { 998 } else {
996 $filter('filter')($scope.botonera, { label: 'Productos' })[0].checked = false; 999 $filter('filter')($scope.botonera, { label: 'Productos' })[0].checked = false;
997 } 1000 }
998 return result; 1001 return result;
999 }; 1002 };
1000 1003
1001 $scope.editarArticulo = function (key, articulo, tmpCantidad, tmpPrecio) { 1004 $scope.editarArticulo = function (key, articulo, tmpCantidad, tmpPrecio) {
1002 if (key === 13) { 1005 if (key === 13) {
1003 if (!articulo.cantidad || !articulo.precio || !tmpCantidad || !tmpPrecio) { 1006 if (!articulo.cantidad || !articulo.precio || !tmpCantidad || !tmpPrecio) {
1004 focaModalService.alert('Los valores deben ser al menos 1'); 1007 focaModalService.alert('Los valores deben ser al menos 1');
1005 return; 1008 return;
1006 } else if (tmpCantidad === '0' || tmpPrecio === '0') { 1009 } else if (tmpCantidad === '0' || tmpPrecio === '0') {
1007 focaModalService.alert('Esta ingresando un producto con valor 0'); 1010 focaModalService.alert('Esta ingresando un producto con valor 0');
1008 } else if (articulo.cantidad < 0 || articulo.precio < 0) { 1011 } else if (articulo.cantidad < 0 || articulo.precio < 0) {
1009 focaModalService.alert('Los valores no pueden ser negativos'); 1012 focaModalService.alert('Los valores no pueden ser negativos');
1010 return; 1013 return;
1011 } 1014 }
1012 articulo.cantidad = tmpCantidad; 1015 articulo.cantidad = tmpCantidad;
1013 articulo.precio = tmpPrecio; 1016 articulo.precio = tmpPrecio;
1014 $scope.getTotal(); 1017 $scope.getTotal();
1015 articulo.editCantidad = articulo.editPrecio = false; 1018 articulo.editCantidad = articulo.editPrecio = false;
1016 } 1019 }
1017 }; 1020 };
1018 1021
1019 $scope.cancelarEditar = function (articulo) { 1022 $scope.cancelarEditar = function (articulo) {
1020 $scope.tmpCantidad = articulo.cantidad; 1023 $scope.tmpCantidad = articulo.cantidad;
1021 $scope.tmpPrecio = articulo.precio; 1024 $scope.tmpPrecio = articulo.precio;
1022 articulo.editCantidad = articulo.editPrecio = false; 1025 articulo.editCantidad = articulo.editPrecio = false;
1023 }; 1026 };
1024 1027
1025 $scope.cambioEdit = function (articulo, propiedad) { 1028 $scope.cambioEdit = function (articulo, propiedad) {
1026 if (propiedad === 'cantidad') { 1029 if (propiedad === 'cantidad') {
1027 articulo.editCantidad = true; 1030 articulo.editCantidad = true;
1028 } else if (propiedad === 'precio') { 1031 } else if (propiedad === 'precio') {
1029 articulo.editPrecio = true; 1032 articulo.editPrecio = true;
1030 } 1033 }
1031 }; 1034 };
1032 1035
1033 $scope.resetFilter = function () { 1036 $scope.resetFilter = function () {
1034 $scope.articuloACargar = {}; 1037 $scope.articuloACargar = {};
1035 $scope.cargando = true; 1038 $scope.cargando = true;
1036 }; 1039 };
1037 //Recibe aviso si el teclado está en uso 1040 //Recibe aviso si el teclado está en uso
1038 $rootScope.$on('usarTeclado', function (event, data) { 1041 $rootScope.$on('usarTeclado', function (event, data) {
1039 if (data) { 1042 if (data) {
1040 $scope.mostrarTeclado = true; 1043 $scope.mostrarTeclado = true;
1041 return; 1044 return;
1042 } 1045 }
1043 $scope.mostrarTeclado = false; 1046 $scope.mostrarTeclado = false;
1044 }); 1047 });
1045 1048
1046 $scope.selectFocus = function ($event) { 1049 $scope.selectFocus = function ($event) {
1047 // Si el teclado esta en uso no selecciona el valor 1050 // Si el teclado esta en uso no selecciona el valor
1048 if ($scope.mostrarTeclado) { 1051 if ($scope.mostrarTeclado) {
1049 return; 1052 return;
1050 } 1053 }
1051 $event.target.select(); 1054 $event.target.select();
1052 }; 1055 };
1053 1056
1054 function addArrayCabecera(array) { 1057 function addArrayCabecera(array) {
1055 for (var i = 0; i < array.length; i++) { 1058 for (var i = 0; i < array.length; i++) {
1056 $scope.$broadcast('addCabecera', { 1059 $scope.$broadcast('addCabecera', {
1057 label: array[i].label, 1060 label: array[i].label,
1058 valor: array[i].valor 1061 valor: array[i].valor
1059 }); 1062 });
1060 } 1063 }
1061 } 1064 }
1062 1065
1063 function rellenar(relleno, longitud) { 1066 function rellenar(relleno, longitud) {
1064 relleno = '' + relleno; 1067 relleno = '' + relleno;
1065 while (relleno.length < longitud) { 1068 while (relleno.length < longitud) {
1066 relleno = '0' + relleno; 1069 relleno = '0' + relleno;
1067 } 1070 }
1068 return relleno; 1071 return relleno;
1069 } 1072 }
1070 1073
1071 function varlidarRemitoFacturado() { 1074 function varlidarRemitoFacturado() {
1072 if ($scope.remito.estado !== 5) { 1075 if ($scope.remito.estado !== 5) {
1073 return true; 1076 return true;
1074 } else { 1077 } else {
1075 focaModalService.alert('No se puede editar un remito facturado'); 1078 focaModalService.alert('No se puede editar un remito facturado');
1076 return false; 1079 return false;
1077 } 1080 }
1078 } 1081 }
1079 1082
1080 function varlidarRemitoAbierto() { 1083 function varlidarRemitoAbierto() {
1081 if (!$scope.remito.hojaRuta) return true; 1084 if (!$scope.remito.hojaRuta) return true;
1082 if ($scope.remito.hojaRuta.abierta !== '1') { 1085 if ($scope.remito.hojaRuta.abierta !== '1') {
1083 return true; 1086 return true;
1084 } else { 1087 } else {
1085 focaModalService.alert('No se puede editar un remito abierto'); 1088 focaModalService.alert('No se puede editar un remito abierto');
1086 return false; 1089 return false;
1087 } 1090 }
1088 } 1091 }
1089 1092
1090 function salir() { 1093 function salir() {
1091 var confirmacion = false; 1094 var confirmacion = false;
1092 1095
1093 if (!angular.equals($scope.remito, $scope.inicial)) { 1096 if (!angular.equals($scope.remito, $scope.inicial)) {
1094 confirmacion = true; 1097 confirmacion = true;
1095 } 1098 }
1096 1099
1097 if (confirmacion) { 1100 if (confirmacion) {
1098 focaModalService.confirm( 1101 focaModalService.confirm(
1099 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 1102 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
1100 ).then(function (data) { 1103 ).then(function (data) {
1101 if (data) { 1104 if (data) {
1102 $location.path('/'); 1105 $location.path('/');
1103 } 1106 }
1104 }); 1107 });
1105 } else { 1108 } else {
1106 $location.path('/'); 1109 $location.path('/');
1107 } 1110 }
1108 } 1111 }
1109 1112
1110 function enableObservaciones(val) { 1113 function enableObservaciones(val) {
1111 var boton = $scope.botonera.filter(function (botonObs) { 1114 var boton = $scope.botonera.filter(function (botonObs) {
1112 return botonObs.label === 'Observaciones'; 1115 return botonObs.label === 'Observaciones';
1113 }); 1116 });
1114 boton[0].disable = !val; 1117 boton[0].disable = !val;
1115 } 1118 }
1116 1119
1117 function setearRemito(remito) { 1120 function setearRemito(remito) {
1118 //añado cabeceras 1121 //añado cabeceras
1119 console.log(remito); 1122 console.log(remito);
1120 var esAbierto = remito.hojaRuta ? 1123 var esAbierto = remito.hojaRuta ?
1121 (remito.hojaRuta.abierta === '1') : false; 1124 (remito.hojaRuta.abierta === '1') : false;
1122 if (remito.estado !== 5 && remito.id && !esAbierto) { 1125 if (remito.estado !== 5 && remito.id && !esAbierto) {
1123 1126
1124 $scope.botonera.forEach(function (boton) { 1127 $scope.botonera.forEach(function (boton) {
1125 1128
1126 if (boton.label === 'Eliminar Remito') { 1129 if (boton.label === 'Eliminar Remito') {
1127 boton.disable = false; 1130 boton.disable = false;
1128 } 1131 }
1129 }); 1132 });
1130 } 1133 }
1131 $scope.$broadcast('removeCabecera', 'Moneda:'); 1134 $scope.$broadcast('removeCabecera', 'Moneda:');
1132 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 1135 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
1133 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 1136 $scope.$broadcast('removeCabecera', 'Cotizacion:');
1134 $scope.$broadcast('removeCabecera', 'Vendedor:'); 1137 $scope.$broadcast('removeCabecera', 'Vendedor:');
1135 1138
1136 $scope.cabeceras = []; 1139 $scope.cabeceras = [];
1137 1140
1138 if (remito.cotizacion && remito.cotizacion.moneda.CODIGO_AFIP !== 'PES') { 1141 if (remito.cotizacion && remito.cotizacion.moneda.CODIGO_AFIP !== 'PES') {
1139 $scope.cabeceras.push({ 1142 $scope.cabeceras.push({
1140 label: 'Moneda:', 1143 label: 'Moneda:',
1141 valor: remito.cotizacion.moneda.DETALLE 1144 valor: remito.cotizacion.moneda.DETALLE
1142 }); 1145 });
1143 $scope.cabeceras.push({ 1146 $scope.cabeceras.push({
1144 label: 'Fecha cotizacion:', 1147 label: 'Fecha cotizacion:',
1145 valor: $filter('date')(remito.cotizacion.FECHA, 1148 valor: $filter('date')(remito.cotizacion.FECHA,
1146 'dd/MM/yyyy') 1149 'dd/MM/yyyy')
1147 }); 1150 });
1148 $scope.cabeceras.push({ 1151 $scope.cabeceras.push({
1149 label: 'Cotizacion:', 1152 label: 'Cotizacion:',
1150 valor: $filter('number')(remito.cotizacion.VENDEDOR, 1153 valor: $filter('number')(remito.cotizacion.VENDEDOR,
1151 '2') 1154 '2')
1152 }); 1155 });
1153 } 1156 }
1154 1157
1155 if (remito.cotizacion && remito.cotizacion.moneda) { 1158 if (remito.cotizacion && remito.cotizacion.moneda) {
1156 $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; 1159 $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true;
1157 } 1160 }
1158 1161
1159 if (remito.cliente && remito.cliente.COD) { 1162 if (remito.cliente && remito.cliente.COD) {
1160 $scope.cabeceras.push({ 1163 $scope.cabeceras.push({
1161 label: 'Cliente:', 1164 label: 'Cliente:',
1162 valor: $filter('rellenarDigitos')(remito.cliente.COD, 3) + ' - ' + 1165 valor: $filter('rellenarDigitos')(remito.cliente.COD, 3) + ' - ' +
1163 remito.cliente.NOM 1166 remito.cliente.NOM
1164 }); 1167 });
1165 $scope.cabeceras.push({ 1168 $scope.cabeceras.push({
1166 label: 'Domicilio:', 1169 label: 'Domicilio:',
1167 valor: remito.domicilioStamp 1170 valor: remito.domicilioStamp
1168 }); 1171 });
1169 1172
1170 $filter('filter')($scope.botonera, 1173 $filter('filter')($scope.botonera,
1171 { label: 'Domicilio de Entrega' })[0].checked = true; 1174 { label: 'Domicilio de Entrega' })[0].checked = true;
1172 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; 1175 $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true;
1173 } 1176 }
1174 if (remito.vendedor && remito.vendedor.NUM) { 1177 if (remito.vendedor && remito.vendedor.NUM) {
1175 $scope.cabeceras.push({ 1178 $scope.cabeceras.push({
1176 label: 'Vendedor:', 1179 label: 'Vendedor:',
1177 valor: $filter('rellenarDigitos')(remito.vendedor.NUM, 3) + 1180 valor: $filter('rellenarDigitos')(remito.vendedor.NUM, 3) +
1178 ' - ' + remito.vendedor.NOM 1181 ' - ' + remito.vendedor.NOM
1179 }); 1182 });
1180 } 1183 }
1181 if (remito.proveedor && remito.proveedor.COD) { 1184 if (remito.proveedor && remito.proveedor.COD) {
1182 $scope.cabeceras.push({ 1185 $scope.cabeceras.push({
1183 label: 'Proveedor:', 1186 label: 'Proveedor:',
1184 valor: $filter('rellenarDigitos')(remito.proveedor.COD, 5) + 1187 valor: $filter('rellenarDigitos')(remito.proveedor.COD, 5) +
1185 ' - ' + remito.proveedor.NOM 1188 ' - ' + remito.proveedor.NOM
1186 }); 1189 });
1187 1190
1188 $filter('filter')($scope.botonera, { label: 'Proveedor' })[0].checked = true; 1191 $filter('filter')($scope.botonera, { label: 'Proveedor' })[0].checked = true;
1189 } 1192 }
1190 if (remito.flete !== undefined && remito.fob !== undefined) { 1193 if (remito.flete !== undefined && remito.fob !== undefined) {
1191 $scope.cabeceras.push({ 1194 $scope.cabeceras.push({
1192 label: 'Flete:', 1195 label: 'Flete:',
1193 valor: remito.fob ? 'FOB' : ( 1196 valor: remito.fob ? 'FOB' : (
1194 remito.flete ? 'Si' : 'No') 1197 remito.flete ? 'Si' : 'No')
1195 }); 1198 });
1196 } 1199 }
1197 if (remito.remitoPlazo) { 1200 if (remito.remitoPlazo) {
1198 valorPrecioCondicion(); 1201 valorPrecioCondicion();
1199 $filter('filter')($scope.botonera, 1202 $filter('filter')($scope.botonera,
1200 { label: 'Precios y condiciones' })[0].checked = true; 1203 { label: 'Precios y condiciones' })[0].checked = true;
1201 } 1204 }
1202 1205
1203 function valorPrecioCondicion() { 1206 function valorPrecioCondicion() {
1204 if (parseInt(remito.idListaPrecio)) { 1207 if (parseInt(remito.idListaPrecio)) {
1205 crearRemitoService.getListaPrecioById(parseInt(remito.idListaPrecio)) 1208 crearRemitoService.getListaPrecioById(parseInt(remito.idListaPrecio))
1206 .then(function (res) { 1209 .then(function (res) {
1207 $timeout(function () { 1210 $timeout(function () {
1208 $scope.cabeceras.push({ 1211 $scope.cabeceras.push({
1209 label: 'Precios y Condiciones:', 1212 label: 'Precios y Condiciones:',
1210 valor: parseInt(res.data[0].ID) + ' - ' + 1213 valor: parseInt(res.data[0].ID) + ' - ' +
1211 res.data[0].DES + ' ' + 1214 res.data[0].DES + ' ' +
1212 remitoBusinessService 1215 remitoBusinessService
1213 .plazoToString(remito.remitoPlazo) 1216 .plazoToString(remito.remitoPlazo)
1214 }); 1217 });
1215 addArrayCabecera($scope.cabeceras); 1218 addArrayCabecera($scope.cabeceras);
1216 }, true); 1219 }, true);
1217 1220
1218 }); 1221 });
1219 $scope.idLista = parseInt(remito.idListaPrecio); 1222 $scope.idLista = parseInt(remito.idListaPrecio);
1220 } 1223 }
1221 } 1224 }
1222 1225
1223 if (remito.flete === 1) { 1226 if (remito.flete === 1) {
1224 var cabeceraBomba = { 1227 var cabeceraBomba = {
1225 label: 'Bomba', 1228 label: 'Bomba',
1226 valor: remito.bomba === 1 ? 'Si' : 'No' 1229 valor: remito.bomba === 1 ? 'Si' : 'No'
1227 }; 1230 };
1228 if (remito.kilometros) { 1231 if (remito.kilometros) {
1229 var cabeceraKilometros = { 1232 var cabeceraKilometros = {
1230 label: 'Kilometros', 1233 label: 'Kilometros',
1231 valor: remito.kilometros 1234 valor: remito.kilometros
1232 }; 1235 };
1233 $scope.cabeceras.push(cabeceraKilometros); 1236 $scope.cabeceras.push(cabeceraKilometros);
1234 } 1237 }
1235 $scope.cabeceras.push(cabeceraBomba); 1238 $scope.cabeceras.push(cabeceraBomba);
1236 } 1239 }
1237 1240
1238 if (remito.idPrecioCondicion > 0) { 1241 if (remito.idPrecioCondicion > 0) {
1239 $scope.idLista = remito.precioCondicion.idListaPrecio; 1242 $scope.idLista = remito.precioCondicion.idListaPrecio;
1240 } else if (remito.idPrecioCondicion) { 1243 } else if (remito.idPrecioCondicion) {
1241 $scope.idLista = -1; 1244 $scope.idLista = -1;
1242 } 1245 }
1243 $scope.puntoVenta = rellenar(remito.sucursal, 4); 1246 $scope.puntoVenta = rellenar(remito.sucursal, 4);
1244 $scope.comprobante = rellenar(remito.numeroRemito, 8); 1247 $scope.comprobante = rellenar(remito.numeroRemito, 8);
1245 $scope.remito = remito; 1248 $scope.remito = remito;
1246 if ($scope.remito.remitoPuntoDescarga.length) { 1249 if ($scope.remito.remitoPuntoDescarga.length) {
1247 var puntoDescarga = []; 1250 var puntoDescarga = [];
1248 1251
1249 $scope.remito.remitoPuntoDescarga.forEach(function (remitoPuntoDescarga) { 1252 $scope.remito.remitoPuntoDescarga.forEach(function (remitoPuntoDescarga) {
1250 puntoDescarga.push(remitoPuntoDescarga.puntoDescarga); 1253 puntoDescarga.push(remitoPuntoDescarga.puntoDescarga);
1251 }); 1254 });
1252 1255
1253 $scope.cabeceras.push({ 1256 $scope.cabeceras.push({
1254 label: 'Puntos de descarga: ', 1257 label: 'Puntos de descarga: ',
1255 valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntoDescarga)) 1258 valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntoDescarga))
1256 }); 1259 });
1257 } 1260 }
1258 $scope.remitoIsDirty = false; 1261 $scope.remitoIsDirty = false;
1259 1262
1260 1263
1261 addArrayCabecera($scope.cabeceras); 1264 addArrayCabecera($scope.cabeceras);
1262 } 1265 }
1263 1266
1264 function getLSRemito() { 1267 function getLSRemito() {
1265 var remito = JSON.parse($localStorage.remito || null); 1268 var remito = JSON.parse($localStorage.remito || null);
1266 if (remito) { 1269 if (remito) {
1267 setearRemito(remito); 1270 setearRemito(remito);
1268 delete $localStorage.remito; 1271 delete $localStorage.remito;
1269 } 1272 }
1270 } 1273 }
1271 1274
1272 function getCabeceraPuntoDescarga(puntosDescarga) { 1275 function getCabeceraPuntoDescarga(puntosDescarga) {
1273 var puntosStamp = ''; 1276 var puntosStamp = '';
1274 puntosDescarga.forEach(function (punto, idx, arr) { 1277 puntosDescarga.forEach(function (punto, idx, arr) {
1275 puntosStamp += punto.descripcion; 1278 puntosStamp += punto.descripcion;
1276 if ((idx + 1) !== arr.length) puntosStamp += ', '; 1279 if ((idx + 1) !== arr.length) puntosStamp += ', ';
1277 }); 1280 });
1278 return puntosStamp; 1281 return puntosStamp;
1279 } 1282 }
1280 1283
1281 function abrirModalMail(id, cliente, numeroRemito) { 1284 function abrirModalMail(id, cliente, numeroRemito) {
1282 focaModalService.mail( 1285 focaModalService.mail(
1283 { 1286 {
1284 titulo: 'Comprobante de remito Nº ' + numeroRemito, 1287 titulo: 'Comprobante de remito Nº ' + numeroRemito,
1285 descarga: { 1288 descarga: {
1286 nombre: numeroRemito + '.pdf', 1289 nombre: numeroRemito + '.pdf',
1287 url: '/remito/comprobante', 1290 url: '/remito/comprobante',
1288 }, 1291 },
1289 envio: { 1292 envio: {
1290 mailCliente: cliente.MAIL, 1293 mailCliente: cliente.MAIL,
1291 url: '/remito/mail', 1294 url: '/remito/mail',
1292 }, 1295 },
1293 options: { 1296 options: {
1294 idRemito: id 1297 idRemito: id
1295 } 1298 }
1296 } 1299 }
1297 ) 1300 )
1298 .then(function (res) { 1301 .then(function (res) {
1299 if (res === false) { 1302 if (res === false) {
1300 abrirModalMail(id); 1303 abrirModalMail(id);
1301 focaModalService.alert('Descarga o envíe su remito ' + 1304 focaModalService.alert('Descarga o envíe su remito ' +
1302 'antes de cerrar esta ventana'); 1305 'antes de cerrar esta ventana');
1303 } 1306 }
1304 }); 1307 });
1305 } 1308 }
1306 //recibo la propiedad por la cual quiero obtener el valor 1309 //recibo la propiedad por la cual quiero obtener el valor
1307 function getImporte(propiedad) { 1310 function getImporte(propiedad) {
1308 var importe = 0; 1311 var importe = 0;
1309 1312
1310 $scope.articulosFiltro().forEach(function (articulo) { 1313 $scope.articulosFiltro().forEach(function (articulo) {
1311 1314
1312 if (articulo[propiedad]) { 1315 if (articulo[propiedad]) {
1313 importe += articulo[propiedad] * articulo.cantidad; 1316 importe += articulo[propiedad] * articulo.cantidad;
1314 } 1317 }
1315 return; 1318 return;
1316 1319
1317 }); 1320 });
1318 1321
1319 return importe; 1322 return importe;
1320 } 1323 }
1321 } 1324 }
1322 ]); 1325 ]);
1323 1326