Commit b2c28dfa2ca0c1d1afcc589af811618da55318cb

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

Merge branch 'master' into 'develop'

Master(mpuebla)

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