Commit e6fb13f4c838152d290d91e9d175cbaa39560072

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

Merge branch 'master' into 'develop'

Master(mpuebla)

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