Commit 777102158e293a75a8adc8feb1a7aa76caa8528b

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'master'

Master

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