Commit ad95f17ebaea1a2c7b2802ecf245bc9e5b3cedb5

Authored by Luigi
1 parent 4c52cedd85
Exists in master

Validacion en precio

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