Commit b588c944a0165f2ba1dbd32acf08d9a8d40eb83a

Authored by Luigi
1 parent fa1f1b5167
Exists in master

Arreglo tilde en botón moneda

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