Commit 96479fd1d55bfb06dbc8fa6d5183dcd2e9a38e30

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

Merge branch 'develop' into 'master'

Develop

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