Commit d42cb1f810a131513b17b73924c78a5ead9967d6

Authored by Jose Pinto
1 parent 6add83e49c
Exists in master

boton observaciones

Showing 2 changed files with 22 additions and 0 deletions   Show diff stats
src/js/controller.js
1 angular.module('focaCrearRemito') .controller('remitoController', 1 angular.module('focaCrearRemito') .controller('remitoController',
2 [ 2 [
3 '$scope', '$uibModal', '$location', '$filter', 'crearRemitoService', '$timeout', 3 '$scope', '$uibModal', '$location', '$filter', 'crearRemitoService', '$timeout',
4 'focaModalService', 'remitoBusinessService', '$rootScope', 'focaBotoneraLateralService', 4 'focaModalService', 'remitoBusinessService', '$rootScope', 'focaBotoneraLateralService',
5 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 addArrayCabecera(cabeceras); 200 addArrayCabecera(cabeceras);
200 201
201 }, function() { 202 }, function() {
202 // funcion ejecutada cuando se cancela el modal 203 // funcion ejecutada cuando se cancela el modal
203 } 204 }
204 ); 205 );
205 } 206 }
206 }; 207 };
207 208
208 $scope.seleccionarRemito = function() { 209 $scope.seleccionarRemito = function() {
209 var modalInstance = $uibModal.open( 210 var modalInstance = $uibModal.open(
210 { 211 {
211 ariaLabelledBy: 'Busqueda de Remito', 212 ariaLabelledBy: 'Busqueda de Remito',
212 templateUrl: 'foca-modal-remito.html', 213 templateUrl: 'foca-modal-remito.html',
213 controller: 'focaModalRemitoController', 214 controller: 'focaModalRemitoController',
214 size: 'lg', 215 size: 'lg',
215 resolve: {usadoPor: function() {return 'remito';}} 216 resolve: {usadoPor: function() {return 'remito';}}
216 } 217 }
217 ); 218 );
218 modalInstance.result.then( 219 modalInstance.result.then(
219 function(remito) { 220 function(remito) {
220 //añado cabeceras 221 //añado cabeceras
221 $scope.$broadcast('removeCabecera', 'Moneda:'); 222 $scope.$broadcast('removeCabecera', 'Moneda:');
222 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 223 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
223 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 224 $scope.$broadcast('removeCabecera', 'Cotizacion:');
224 var cabeceras = [ 225 var cabeceras = [
225 { 226 {
226 label: 'Moneda:', 227 label: 'Moneda:',
227 valor: remito.cotizacion.moneda.DETALLE 228 valor: remito.cotizacion.moneda.DETALLE
228 }, 229 },
229 { 230 {
230 label: 'Fecha cotizacion:', 231 label: 'Fecha cotizacion:',
231 valor: $filter('date')(remito.cotizacion.FECHA, 232 valor: $filter('date')(remito.cotizacion.FECHA,
232 'dd/MM/yyyy') 233 'dd/MM/yyyy')
233 }, 234 },
234 { 235 {
235 label: 'Cotizacion:', 236 label: 'Cotizacion:',
236 valor: $filter('number')(remito.cotizacion.VENDEDOR, 237 valor: $filter('number')(remito.cotizacion.VENDEDOR,
237 '2') 238 '2')
238 }, 239 },
239 { 240 {
240 label: 'Cliente:', 241 label: 'Cliente:',
241 valor: $filter('rellenarDigitos')(remito.cliente.COD, 3) + ' - ' + 242 valor: $filter('rellenarDigitos')(remito.cliente.COD, 3) + ' - ' +
242 remito.cliente.NOM 243 remito.cliente.NOM
243 }, 244 },
244 { 245 {
245 label: 'Domicilio:', 246 label: 'Domicilio:',
246 valor: remito.domicilioStamp 247 valor: remito.domicilioStamp
247 }, 248 },
248 { 249 {
249 label: 'Vendedor:', 250 label: 'Vendedor:',
250 valor: $filter('rellenarDigitos')(remito.vendedor.NUM, 3) + 251 valor: $filter('rellenarDigitos')(remito.vendedor.NUM, 3) +
251 ' - ' + remito.vendedor.NOM 252 ' - ' + remito.vendedor.NOM
252 }, 253 },
253 { 254 {
254 label: 'Proveedor:', 255 label: 'Proveedor:',
255 valor: $filter('rellenarDigitos')(remito.proveedor.COD, 5) + 256 valor: $filter('rellenarDigitos')(remito.proveedor.COD, 5) +
256 ' - ' + remito.proveedor.NOM 257 ' - ' + remito.proveedor.NOM
257 }, 258 },
258 { 259 {
259 label: 'Flete:', 260 label: 'Flete:',
260 valor: remito.fob === 1 ? 'FOB' : ( 261 valor: remito.fob === 1 ? 'FOB' : (
261 remito.flete === 1 ? 'Si' : 'No') 262 remito.flete === 1 ? 'Si' : 'No')
262 }, 263 },
263 { 264 {
264 label: 'Precio condicion:', 265 label: 'Precio condicion:',
265 valor: valorPrecioCondicion() + ' ' + 266 valor: valorPrecioCondicion() + ' ' +
266 remitoBusinessService.plazoToString(remito.remitoPlazo) 267 remitoBusinessService.plazoToString(remito.remitoPlazo)
267 } 268 }
268 ]; 269 ];
269 function valorPrecioCondicion() { 270 function valorPrecioCondicion() {
270 if(remito.idPrecioCondicion > 0) { 271 if(remito.idPrecioCondicion > 0) {
271 return remito.precioCondicion.nombre; 272 return remito.precioCondicion.nombre;
272 }else { 273 }else {
273 return 'Ingreso Manual'; 274 return 'Ingreso Manual';
274 } 275 }
275 } 276 }
276 277
277 if(remito.flete === 1) { 278 if(remito.flete === 1) {
278 var cabeceraBomba = { 279 var cabeceraBomba = {
279 label: 'Bomba', 280 label: 'Bomba',
280 valor: remito.bomba === 1 ? 'Si' : 'No' 281 valor: remito.bomba === 1 ? 'Si' : 'No'
281 }; 282 };
282 if(remito.kilometros) { 283 if(remito.kilometros) {
283 var cabeceraKilometros = { 284 var cabeceraKilometros = {
284 label: 'Kilometros', 285 label: 'Kilometros',
285 valor: remito.kilometros 286 valor: remito.kilometros
286 }; 287 };
287 cabeceras.push(cabeceraKilometros); 288 cabeceras.push(cabeceraKilometros);
288 } 289 }
289 cabeceras.push(cabeceraBomba); 290 cabeceras.push(cabeceraBomba);
290 } 291 }
291 $scope.articulosTabla = remito.articulosRemito; 292 $scope.articulosTabla = remito.articulosRemito;
292 remitoBusinessService.calcularArticulos($scope.articulosTabla, 293 remitoBusinessService.calcularArticulos($scope.articulosTabla,
293 remito.cotizacion.VENDEDOR); 294 remito.cotizacion.VENDEDOR);
294 if(remito.idPrecioCondicion > 0) { 295 if(remito.idPrecioCondicion > 0) {
295 $scope.idLista = remito.precioCondicion.idListaPrecio; 296 $scope.idLista = remito.precioCondicion.idListaPrecio;
296 }else { 297 }else {
297 $scope.idLista = -1; 298 $scope.idLista = -1;
298 } 299 }
299 $scope.puntoVenta = rellenar(remito.sucursal, 4); 300 $scope.puntoVenta = rellenar(remito.sucursal, 4);
300 $scope.comprobante = rellenar(remito.numeroRemito, 8); 301 $scope.comprobante = rellenar(remito.numeroRemito, 8);
301 $scope.remito = remito; 302 $scope.remito = remito;
302 $scope.remito.moneda = remito.cotizacion.moneda; 303 $scope.remito.moneda = remito.cotizacion.moneda;
303 $scope.plazosPagos = remito.remitoPlazo; 304 $scope.plazosPagos = remito.remitoPlazo;
304 addArrayCabecera(cabeceras); 305 addArrayCabecera(cabeceras);
305 }, function() { 306 }, function() {
306 // funcion ejecutada cuando se cancela el modal 307 // funcion ejecutada cuando se cancela el modal
307 } 308 }
308 ); 309 );
309 }; 310 };
310 311
311 //validacion por domicilio y por plazo pago 312 //validacion por domicilio y por plazo pago
312 $scope.crearRemito = function() { 313 $scope.crearRemito = function() {
313 if(!$scope.remito.vendedor) { 314 if(!$scope.remito.vendedor) {
314 focaModalService.alert('Ingrese Vendedor'); 315 focaModalService.alert('Ingrese Vendedor');
315 return; 316 return;
316 }else if(!$scope.remito.cliente) { 317 }else if(!$scope.remito.cliente) {
317 focaModalService.alert('Ingrese Cliente'); 318 focaModalService.alert('Ingrese Cliente');
318 return; 319 return;
319 }else if(!$scope.remito.proveedor) { 320 }else if(!$scope.remito.proveedor) {
320 focaModalService.alert('Ingrese Proveedor'); 321 focaModalService.alert('Ingrese Proveedor');
321 return; 322 return;
322 }else if(!$scope.remito.moneda.id && !$scope.remito.moneda.ID) { 323 }else if(!$scope.remito.moneda.id && !$scope.remito.moneda.ID) {
323 focaModalService.alert('Ingrese Moneda'); 324 focaModalService.alert('Ingrese Moneda');
324 return; 325 return;
325 }else if(!$scope.remito.cotizacion.ID) { 326 }else if(!$scope.remito.cotizacion.ID) {
326 focaModalService.alert('Ingrese Cotización'); 327 focaModalService.alert('Ingrese Cotización');
327 return; 328 return;
328 }else if( 329 }else if(
329 $scope.remito.flete === undefined || $scope.remito.flete === null) 330 $scope.remito.flete === undefined || $scope.remito.flete === null)
330 { 331 {
331 focaModalService.alert('Ingrese Flete'); 332 focaModalService.alert('Ingrese Flete');
332 return; 333 return;
333 }else if($scope.articulosTabla.length === 0) { 334 }else if($scope.articulosTabla.length === 0) {
334 focaModalService.alert('Debe cargar al menos un articulo'); 335 focaModalService.alert('Debe cargar al menos un articulo');
335 return; 336 return;
336 } 337 }
337 focaBotoneraLateralService.startGuardar(); 338 focaBotoneraLateralService.startGuardar();
338 $scope.saveLoading = true; 339 $scope.saveLoading = true;
339 var save = { 340 var save = {
340 remito: { 341 remito: {
341 id: $scope.remito.id, 342 id: $scope.remito.id,
342 fechaRemito: $scope.now.toISOString().slice(0, 19).replace('T', ' '), 343 fechaRemito: $scope.now.toISOString().slice(0, 19).replace('T', ' '),
343 idCliente: $scope.remito.cliente.COD, 344 idCliente: $scope.remito.cliente.COD,
344 nombreCliente: $scope.remito.cliente.NOM, 345 nombreCliente: $scope.remito.cliente.NOM,
345 cuitCliente: $scope.remito.cliente.CUIT, 346 cuitCliente: $scope.remito.cliente.CUIT,
346 responsabilidadIvaCliente: 0,//TODO, 347 responsabilidadIvaCliente: 0,//TODO,
347 descuento: 0,//TODO, 348 descuento: 0,//TODO,
348 importeNeto: 0,//TODO 349 importeNeto: 0,//TODO
349 importeExento: 0,//TODO 350 importeExento: 0,//TODO
350 importeIva: 0,//TODO 351 importeIva: 0,//TODO
351 importeIvaServicios: 0,//TODO 352 importeIvaServicios: 0,//TODO
352 importeImpuestoInterno: 0,//TODO 353 importeImpuestoInterno: 0,//TODO
353 importeImpuestoInterno1: 0,//TODO 354 importeImpuestoInterno1: 0,//TODO
354 importeImpuestoInterno2: 0,//TODO 355 importeImpuestoInterno2: 0,//TODO
355 percepcion: 0,//TODO 356 percepcion: 0,//TODO
356 percepcionIva: 0,//TODO 357 percepcionIva: 0,//TODO
357 redondeo: 0,//TODO 358 redondeo: 0,//TODO
358 total: $scope.getTotal(), 359 total: $scope.getTotal(),
359 numeroNotaPedido: $scope.remito.numeroNotaPedido, 360 numeroNotaPedido: $scope.remito.numeroNotaPedido,
360 anulado: false, 361 anulado: false,
361 planilla: 0,//TODO 362 planilla: 0,//TODO
362 lugar: 0,//TODO 363 lugar: 0,//TODO
363 cuentaMadre: 0,// 364 cuentaMadre: 0,//
364 cuentaContable: 0,//TODO 365 cuentaContable: 0,//TODO
365 asiento: 0,//TODO 366 asiento: 0,//TODO
366 e_hd: '',//TODO 367 e_hd: '',//TODO
367 c_hd: '', 368 c_hd: '',
368 numeroLiquidoProducto: 0,//TODO 369 numeroLiquidoProducto: 0,//TODO
369 idVendedor: $scope.remito.idVendedor, 370 idVendedor: $scope.remito.idVendedor,
370 idProveedor: $scope.remito.idProveedor, 371 idProveedor: $scope.remito.idProveedor,
371 idDomicilio: 0,//TODO 372 idDomicilio: 0,//TODO
372 idCotizacion: $scope.remito.cotizacion.ID, 373 idCotizacion: $scope.remito.cotizacion.ID,
373 idPrecioCondicion: $scope.remito.idPrecioCondicion, 374 idPrecioCondicion: $scope.remito.idPrecioCondicion,
374 flete: $scope.remito.flete, 375 flete: $scope.remito.flete,
375 fob: $scope.remito.fob, 376 fob: $scope.remito.fob,
376 bomba: $scope.remito.bomba, 377 bomba: $scope.remito.bomba,
377 kilometros: $scope.remito.kilometros, 378 kilometros: $scope.remito.kilometros,
378 domicilioStamp: $scope.remito.domicilioStamp, 379 domicilioStamp: $scope.remito.domicilioStamp,
379 estado: 0,//TODO 380 estado: 0,//TODO
380 destinoVenta: 0,//TODO 381 destinoVenta: 0,//TODO
381 operacionTipo: 0//TODO 382 operacionTipo: 0//TODO
382 }, 383 },
383 notaPedido: $scope.notaPedido 384 notaPedido: $scope.notaPedido
384 }; 385 };
385 crearRemitoService.crearRemito(save).then( 386 crearRemitoService.crearRemito(save).then(
386 function(data) { 387 function(data) {
387 remitoBusinessService.addArticulos($scope.articulosTabla, 388 remitoBusinessService.addArticulos($scope.articulosTabla,
388 data.data.id, $scope.remito.cotizacion.COTIZACION); 389 data.data.id, $scope.remito.cotizacion.COTIZACION);
389 390
390 focaBotoneraLateralService.endGuardar(true); 391 focaBotoneraLateralService.endGuardar(true);
391 $scope.saveLoading = false; 392 $scope.saveLoading = false;
392 //TODO: updatear plazos 393 //TODO: updatear plazos
393 if($scope.remito.id === 0) { 394 if($scope.remito.id === 0) {
394 var plazos = $scope.plazosPagos; 395 var plazos = $scope.plazosPagos;
395 396
396 for(var j = 0; j < plazos.length; j++) { 397 for(var j = 0; j < plazos.length; j++) {
397 var json = { 398 var json = {
398 idRemito: data.data.id, 399 idRemito: data.data.id,
399 dias: plazos[j].dias 400 dias: plazos[j].dias
400 }; 401 };
401 crearRemitoService.crearPlazosParaRemito(json); 402 crearRemitoService.crearPlazosParaRemito(json);
402 } 403 }
403 } 404 }
404 405
405 init(); 406 init();
406 }, function(error) { 407 }, function(error) {
407 focaModalService.alert('Hubo un error al crear el remito'); 408 focaModalService.alert('Hubo un error al crear el remito');
408 focaBotoneraLateralService.endGuardar(); 409 focaBotoneraLateralService.endGuardar();
409 $scope.saveLoading = false; 410 $scope.saveLoading = false;
410 console.info(error); 411 console.info(error);
411 } 412 }
412 ); 413 );
413 }; 414 };
414 415
415 $scope.seleccionarProductos = function() { 416 $scope.seleccionarProductos = function() {
416 if($scope.idLista === undefined) { 417 if($scope.idLista === undefined) {
417 focaModalService.alert( 418 focaModalService.alert(
418 'Primero seleccione una lista de precio y condicion'); 419 'Primero seleccione una lista de precio y condicion');
419 return; 420 return;
420 } 421 }
421 var modalInstance = $uibModal.open( 422 var modalInstance = $uibModal.open(
422 { 423 {
423 ariaLabelledBy: 'Busqueda de Productos', 424 ariaLabelledBy: 'Busqueda de Productos',
424 templateUrl: 'modal-busqueda-productos.html', 425 templateUrl: 'modal-busqueda-productos.html',
425 controller: 'modalBusquedaProductosCtrl', 426 controller: 'modalBusquedaProductosCtrl',
426 resolve: { 427 resolve: {
427 parametroProducto: { 428 parametroProducto: {
428 idLista: $scope.idLista, 429 idLista: $scope.idLista,
429 cotizacion: $scope.remito.cotizacion.COTIZACION, 430 cotizacion: $scope.remito.cotizacion.COTIZACION,
430 simbolo: $scope.remito.moneda.simbolo 431 simbolo: $scope.remito.moneda.simbolo
431 } 432 }
432 }, 433 },
433 size: 'lg' 434 size: 'lg'
434 } 435 }
435 ); 436 );
436 modalInstance.result.then( 437 modalInstance.result.then(
437 function(producto) { 438 function(producto) {
438 var newArt = 439 var newArt =
439 { 440 {
440 id: 0, 441 id: 0,
441 codigo: producto.codigo, 442 codigo: producto.codigo,
442 sector: producto.sector, 443 sector: producto.sector,
443 sectorCodigo: producto.sector + '-' + producto.codigo, 444 sectorCodigo: producto.sector + '-' + producto.codigo,
444 descripcion: producto.descripcion, 445 descripcion: producto.descripcion,
445 item: $scope.articulosTabla.length + 1, 446 item: $scope.articulosTabla.length + 1,
446 nombre: producto.descripcion, 447 nombre: producto.descripcion,
447 precio: parseFloat(producto.precio.toFixed(4)), 448 precio: parseFloat(producto.precio.toFixed(4)),
448 costoUnitario: producto.costo, 449 costoUnitario: producto.costo,
449 editCantidad: false, 450 editCantidad: false,
450 editPrecio: false, 451 editPrecio: false,
451 rubro: producto.CodRub, 452 rubro: producto.CodRub,
452 exentoUnitario: producto.precio, 453 exentoUnitario: producto.precio,
453 ivaUnitario: producto.IMPIVA, 454 ivaUnitario: producto.IMPIVA,
454 impuestoInternoUnitario: producto.ImpInt, 455 impuestoInternoUnitario: producto.ImpInt,
455 impuestoInterno1Unitario: producto.ImpInt2, 456 impuestoInterno1Unitario: producto.ImpInt2,
456 impuestoInterno2Unitario: producto.ImpInt3, 457 impuestoInterno2Unitario: producto.ImpInt3,
457 precioLista: producto.precio, 458 precioLista: producto.precio,
458 combustible: 1, 459 combustible: 1,
459 facturado: 0 460 facturado: 0
460 }; 461 };
461 $scope.articuloACargar = newArt; 462 $scope.articuloACargar = newArt;
462 $scope.cargando = false; 463 $scope.cargando = false;
463 }, function() { 464 }, function() {
464 // funcion ejecutada cuando se cancela el modal 465 // funcion ejecutada cuando se cancela el modal
465 } 466 }
466 ); 467 );
467 }; 468 };
468 469
469 $scope.seleccionarVendedor = function() { 470 $scope.seleccionarVendedor = function() {
470 if(varlidarRemitoFacturado()) { 471 if(varlidarRemitoFacturado()) {
471 var parametrosModal = { 472 var parametrosModal = {
472 titulo: 'Búsqueda vendedores', 473 titulo: 'Búsqueda vendedores',
473 query: '/vendedor', 474 query: '/vendedor',
474 columnas: [ 475 columnas: [
475 { 476 {
476 propiedad: 'NUM', 477 propiedad: 'NUM',
477 nombre: 'Código', 478 nombre: 'Código',
478 filtro: { 479 filtro: {
479 nombre: 'rellenarDigitos', 480 nombre: 'rellenarDigitos',
480 parametro: 3 481 parametro: 3
481 } 482 }
482 }, 483 },
483 { 484 {
484 propiedad: 'NOM', 485 propiedad: 'NOM',
485 nombre: 'Nombre' 486 nombre: 'Nombre'
486 } 487 }
487 ], 488 ],
488 size: 'md' 489 size: 'md'
489 }; 490 };
490 focaModalService.modal(parametrosModal).then( 491 focaModalService.modal(parametrosModal).then(
491 function(vendedor) { 492 function(vendedor) {
492 $scope.$broadcast('addCabecera',{ 493 $scope.$broadcast('addCabecera',{
493 label: 'Vendedor:', 494 label: 'Vendedor:',
494 valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + 495 valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' +
495 vendedor.NOM 496 vendedor.NOM
496 }); 497 });
497 $scope.remito.idVendedor = vendedor.id; 498 $scope.remito.idVendedor = vendedor.id;
498 $scope.vendedor = vendedor; 499 $scope.vendedor = vendedor;
499 }, function() { 500 }, function() {
500 501
501 } 502 }
502 ); 503 );
503 } 504 }
504 }; 505 };
505 506
506 $scope.seleccionarProveedor = function() { 507 $scope.seleccionarProveedor = function() {
507 if(varlidarRemitoFacturado()) { 508 if(varlidarRemitoFacturado()) {
508 var parametrosModal = { 509 var parametrosModal = {
509 titulo: 'Búsqueda de Proveedor', 510 titulo: 'Búsqueda de Proveedor',
510 query: '/proveedor', 511 query: '/proveedor',
511 columnas: [ 512 columnas: [
512 { 513 {
513 nombre: 'Código', 514 nombre: 'Código',
514 propiedad: 'COD', 515 propiedad: 'COD',
515 filtro: { 516 filtro: {
516 nombre: 'rellenarDigitos', 517 nombre: 'rellenarDigitos',
517 parametro: 5 518 parametro: 5
518 } 519 }
519 }, 520 },
520 { 521 {
521 nombre: 'Nombre', 522 nombre: 'Nombre',
522 propiedad: 'NOM' 523 propiedad: 'NOM'
523 }, 524 },
524 { 525 {
525 nombre: 'CUIT', 526 nombre: 'CUIT',
526 propiedad: 'CUIT' 527 propiedad: 'CUIT'
527 } 528 }
528 ], 529 ],
529 tipo: 'POST', 530 tipo: 'POST',
530 json: {razonCuitCod: ''} 531 json: {razonCuitCod: ''}
531 }; 532 };
532 focaModalService.modal(parametrosModal).then( 533 focaModalService.modal(parametrosModal).then(
533 function(proveedor) { 534 function(proveedor) {
534 $scope.remito.idProveedor = proveedor.COD; 535 $scope.remito.idProveedor = proveedor.COD;
535 $scope.$broadcast('addCabecera',{ 536 $scope.$broadcast('addCabecera',{
536 label: 'Proveedor:', 537 label: 'Proveedor:',
537 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + 538 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' +
538 proveedor.NOM 539 proveedor.NOM
539 }); 540 });
540 }, function() { 541 }, function() {
541 542
542 } 543 }
543 ); 544 );
544 } 545 }
545 }; 546 };
546 547
547 $scope.seleccionarCliente = function() { 548 $scope.seleccionarCliente = function() {
548 if(!$scope.vendedor) { 549 if(!$scope.vendedor) {
549 focaModalService.alert('Primero seleccione un vendedor'); 550 focaModalService.alert('Primero seleccione un vendedor');
550 return; 551 return;
551 } 552 }
552 553
553 if(varlidarRemitoFacturado()) { 554 if(varlidarRemitoFacturado()) {
554 var modalInstance = $uibModal.open( 555 var modalInstance = $uibModal.open(
555 { 556 {
556 ariaLabelledBy: 'Busqueda de Cliente', 557 ariaLabelledBy: 'Busqueda de Cliente',
557 templateUrl: 'foca-busqueda-cliente-modal.html', 558 templateUrl: 'foca-busqueda-cliente-modal.html',
558 controller: 'focaBusquedaClienteModalController', 559 controller: 'focaBusquedaClienteModalController',
559 resolve: { 560 resolve: {
560 vendedor: function() { return $scope.vendedor; } 561 vendedor: function() { return $scope.vendedor; }
561 }, 562 },
562 size: 'lg' 563 size: 'lg'
563 } 564 }
564 ); 565 );
565 modalInstance.result.then( 566 modalInstance.result.then(
566 function(cliente) { 567 function(cliente) {
567 $scope.abrirModalDomicilios(cliente); 568 $scope.abrirModalDomicilios(cliente);
568 }, function() { 569 }, function() {
569 570
570 } 571 }
571 ); 572 );
572 } 573 }
573 }; 574 };
574 575
575 $scope.abrirModalDomicilios = function(cliente) { 576 $scope.abrirModalDomicilios = function(cliente) {
576 var modalInstanceDomicilio = $uibModal.open( 577 var modalInstanceDomicilio = $uibModal.open(
577 { 578 {
578 ariaLabelledBy: 'Busqueda de Domicilios', 579 ariaLabelledBy: 'Busqueda de Domicilios',
579 templateUrl: 'modal-domicilio.html', 580 templateUrl: 'modal-domicilio.html',
580 controller: 'focaModalDomicilioController', 581 controller: 'focaModalDomicilioController',
581 size: 'lg', 582 size: 'lg',
582 resolve: { 583 resolve: {
583 idCliente: function() { return cliente.cod; }, 584 idCliente: function() { return cliente.cod; },
584 esNuevo: function() { return cliente.esNuevo; } 585 esNuevo: function() { return cliente.esNuevo; }
585 } 586 }
586 } 587 }
587 ); 588 );
588 modalInstanceDomicilio.result.then( 589 modalInstanceDomicilio.result.then(
589 function(domicilio) { 590 function(domicilio) {
590 //$scope.remito.domicilio.id = domicilio.nivel2; 591 //$scope.remito.domicilio.id = domicilio.nivel2;
591 $scope.remito.cliente = { 592 $scope.remito.cliente = {
592 COD: cliente.cod, 593 COD: cliente.cod,
593 CUIT: cliente.cuit, 594 CUIT: cliente.cuit,
594 NOM: cliente.nom 595 NOM: cliente.nom
595 }; 596 };
596 597
597 598
598 var domicilioStamp = 599 var domicilioStamp =
599 domicilio.Calle + ' ' + domicilio.Numero + ', ' + 600 domicilio.Calle + ' ' + domicilio.Numero + ', ' +
600 domicilio.Localidad + ', ' + domicilio.Provincia; 601 domicilio.Localidad + ', ' + domicilio.Provincia;
601 $scope.remito.domicilioStamp = domicilioStamp; 602 $scope.remito.domicilioStamp = domicilioStamp;
602 603
603 $scope.$broadcast('addCabecera',{ 604 $scope.$broadcast('addCabecera',{
604 label: 'Cliente:', 605 label: 'Cliente:',
605 valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + cliente.nom 606 valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + cliente.nom
606 }); 607 });
607 $scope.$broadcast('addCabecera',{ 608 $scope.$broadcast('addCabecera',{
608 label: 'Domicilio:', 609 label: 'Domicilio:',
609 valor: domicilioStamp 610 valor: domicilioStamp
610 }); 611 });
611 }, function() { 612 }, function() {
612 $scope.seleccionarCliente(); 613 $scope.seleccionarCliente();
613 return; 614 return;
614 } 615 }
615 ); 616 );
616 }; 617 };
617 618
618 $scope.mostrarFichaCliente = function() { 619 $scope.mostrarFichaCliente = function() {
619 $uibModal.open( 620 $uibModal.open(
620 { 621 {
621 ariaLabelledBy: 'Datos del Cliente', 622 ariaLabelledBy: 'Datos del Cliente',
622 templateUrl: 'foca-crear-remito-ficha-cliente.html', 623 templateUrl: 'foca-crear-remito-ficha-cliente.html',
623 controller: 'focaCrearRemitoFichaClienteController', 624 controller: 'focaCrearRemitoFichaClienteController',
624 size: 'lg' 625 size: 'lg'
625 } 626 }
626 ); 627 );
627 }; 628 };
628 629
629 $scope.getTotal = function() { 630 $scope.getTotal = function() {
630 var total = 0; 631 var total = 0;
631 var arrayTempArticulos = $scope.articulosTabla; 632 var arrayTempArticulos = $scope.articulosTabla;
632 for(var i = 0; i < arrayTempArticulos.length; i++) { 633 for(var i = 0; i < arrayTempArticulos.length; i++) {
633 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; 634 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad;
634 } 635 }
635 return parseFloat(total.toFixed(2)); 636 return parseFloat(total.toFixed(2));
636 }; 637 };
637 638
638 $scope.getSubTotal = function() { 639 $scope.getSubTotal = function() {
639 if($scope.articuloACargar) { 640 if($scope.articuloACargar) {
640 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; 641 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
641 } 642 }
642 }; 643 };
643 644
644 $scope.seleccionarPreciosYCondiciones = function() { 645 $scope.seleccionarPreciosYCondiciones = function() {
645 if(varlidarRemitoFacturado()) { 646 if(varlidarRemitoFacturado()) {
646 var modalInstance = $uibModal.open( 647 var modalInstance = $uibModal.open(
647 { 648 {
648 ariaLabelledBy: 'Busqueda de Precio Condición', 649 ariaLabelledBy: 'Busqueda de Precio Condición',
649 templateUrl: 'modal-precio-condicion.html', 650 templateUrl: 'modal-precio-condicion.html',
650 controller: 'focaModalPrecioCondicionController', 651 controller: 'focaModalPrecioCondicionController',
651 size: 'lg' 652 size: 'lg'
652 } 653 }
653 ); 654 );
654 modalInstance.result.then( 655 modalInstance.result.then(
655 function(precioCondicion) { 656 function(precioCondicion) {
656 var cabecera = ''; 657 var cabecera = '';
657 var plazosConcat = ''; 658 var plazosConcat = '';
658 if(!Array.isArray(precioCondicion)) { 659 if(!Array.isArray(precioCondicion)) {
659 $scope.remito.idPrecioCondicion = precioCondicion.id; 660 $scope.remito.idPrecioCondicion = precioCondicion.id;
660 $scope.plazosPagos = precioCondicion.plazoPago; 661 $scope.plazosPagos = precioCondicion.plazoPago;
661 $scope.idLista = precioCondicion.idListaPrecio; 662 $scope.idLista = precioCondicion.idListaPrecio;
662 for(var i = 0; i < precioCondicion.plazoPago.length; i++) { 663 for(var i = 0; i < precioCondicion.plazoPago.length; i++) {
663 plazosConcat += precioCondicion.plazoPago[i].dias + ' '; 664 plazosConcat += precioCondicion.plazoPago[i].dias + ' ';
664 } 665 }
665 cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + 666 cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) +
666 ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); 667 ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim();
667 }else { //Cuando se ingresan los plazos manualmente 668 }else { //Cuando se ingresan los plazos manualmente
668 $scope.remito.idPrecioCondicion = 0; 669 $scope.remito.idPrecioCondicion = 0;
669 //-1, el modal productos busca todos los productos 670 //-1, el modal productos busca todos los productos
670 $scope.idLista = -1; 671 $scope.idLista = -1;
671 $scope.plazosPagos = precioCondicion; 672 $scope.plazosPagos = precioCondicion;
672 for(var j = 0; j < precioCondicion.length; j++) { 673 for(var j = 0; j < precioCondicion.length; j++) {
673 plazosConcat += precioCondicion[j].dias + ' '; 674 plazosConcat += precioCondicion[j].dias + ' ';
674 } 675 }
675 cabecera = 'Ingreso manual ' + plazosConcat.trim(); 676 cabecera = 'Ingreso manual ' + plazosConcat.trim();
676 } 677 }
677 $scope.articulosTabla = []; 678 $scope.articulosTabla = [];
678 $scope.$broadcast('addCabecera',{ 679 $scope.$broadcast('addCabecera',{
679 label: 'Precios y condiciones:', 680 label: 'Precios y condiciones:',
680 valor: cabecera 681 valor: cabecera
681 }); 682 });
682 }, function() { 683 }, function() {
683 684
684 } 685 }
685 ); 686 );
686 } 687 }
687 }; 688 };
688 689
689 $scope.seleccionarFlete = function() { 690 $scope.seleccionarFlete = function() {
690 if(varlidarRemitoFacturado()) { 691 if(varlidarRemitoFacturado()) {
691 var modalInstance = $uibModal.open( 692 var modalInstance = $uibModal.open(
692 { 693 {
693 ariaLabelledBy: 'Busqueda de Flete', 694 ariaLabelledBy: 'Busqueda de Flete',
694 templateUrl: 'modal-flete.html', 695 templateUrl: 'modal-flete.html',
695 controller: 'focaModalFleteController', 696 controller: 'focaModalFleteController',
696 size: 'lg', 697 size: 'lg',
697 resolve: { 698 resolve: {
698 parametrosFlete: 699 parametrosFlete:
699 function() { 700 function() {
700 return { 701 return {
701 flete: $scope.remito.flete ? '1' : 702 flete: $scope.remito.flete ? '1' :
702 ($scope.remito.fob ? 'FOB' : 703 ($scope.remito.fob ? 'FOB' :
703 ($scope.remito.flete === undefined ? null : '0')), 704 ($scope.remito.flete === undefined ? null : '0')),
704 bomba: $scope.remito.bomba ? '1' : 705 bomba: $scope.remito.bomba ? '1' :
705 ($scope.remito.bomba === undefined ? null : '0'), 706 ($scope.remito.bomba === undefined ? null : '0'),
706 kilometros: $scope.remito.kilometros 707 kilometros: $scope.remito.kilometros
707 }; 708 };
708 } 709 }
709 } 710 }
710 } 711 }
711 ); 712 );
712 modalInstance.result.then( 713 modalInstance.result.then(
713 function(datos) { 714 function(datos) {
714 $scope.remito.flete = datos.flete; 715 $scope.remito.flete = datos.flete;
715 $scope.remito.fob = datos.FOB; 716 $scope.remito.fob = datos.FOB;
716 $scope.remito.bomba = datos.bomba; 717 $scope.remito.bomba = datos.bomba;
717 $scope.remito.kilometros = datos.kilometros; 718 $scope.remito.kilometros = datos.kilometros;
718 719
719 $scope.$broadcast('addCabecera',{ 720 $scope.$broadcast('addCabecera',{
720 label: 'Flete:', 721 label: 'Flete:',
721 valor: datos.flete ? 'Si' : ($scope.remito.fob ? 'FOB' : 'No') 722 valor: datos.flete ? 'Si' : ($scope.remito.fob ? 'FOB' : 'No')
722 }); 723 });
723 if(datos.flete) { 724 if(datos.flete) {
724 $scope.$broadcast('addCabecera',{ 725 $scope.$broadcast('addCabecera',{
725 label: 'Bomba:', 726 label: 'Bomba:',
726 valor: datos.bomba ? 'Si' : 'No' 727 valor: datos.bomba ? 'Si' : 'No'
727 }); 728 });
728 $scope.$broadcast('addCabecera',{ 729 $scope.$broadcast('addCabecera',{
729 label: 'Kilometros:', 730 label: 'Kilometros:',
730 valor: datos.kilometros 731 valor: datos.kilometros
731 }); 732 });
732 }else { 733 }else {
733 $scope.$broadcast('removeCabecera', 'Bomba:'); 734 $scope.$broadcast('removeCabecera', 'Bomba:');
734 $scope.$broadcast('removeCabecera', 'Kilometros:'); 735 $scope.$broadcast('removeCabecera', 'Kilometros:');
735 $scope.remito.fob = false; 736 $scope.remito.fob = false;
736 $scope.remito.bomba = false; 737 $scope.remito.bomba = false;
737 $scope.remito.kilometros = null; 738 $scope.remito.kilometros = null;
738 } 739 }
739 }, function() { 740 }, function() {
740 741
741 } 742 }
742 ); 743 );
743 } 744 }
744 }; 745 };
745 746
746 $scope.seleccionarMoneda = function() { 747 $scope.seleccionarMoneda = function() {
747 if(varlidarRemitoFacturado()) { 748 if(varlidarRemitoFacturado()) {
748 var parametrosModal = { 749 var parametrosModal = {
749 titulo: 'Búsqueda de monedas', 750 titulo: 'Búsqueda de monedas',
750 query: '/moneda', 751 query: '/moneda',
751 columnas: [ 752 columnas: [
752 { 753 {
753 propiedad: 'DETALLE', 754 propiedad: 'DETALLE',
754 nombre: 'Nombre' 755 nombre: 'Nombre'
755 }, 756 },
756 { 757 {
757 propiedad: 'SIMBOLO', 758 propiedad: 'SIMBOLO',
758 nombre: 'Símbolo' 759 nombre: 'Símbolo'
759 } 760 }
760 ], 761 ],
761 size: 'md' 762 size: 'md'
762 }; 763 };
763 focaModalService.modal(parametrosModal).then( 764 focaModalService.modal(parametrosModal).then(
764 function(moneda) { 765 function(moneda) {
765 $scope.abrirModalCotizacion(moneda); 766 $scope.abrirModalCotizacion(moneda);
766 }, function() { 767 }, function() {
767 768
768 } 769 }
769 ); 770 );
770 } 771 }
771 }; 772 };
772 773
774 $scope.seleccionarObservaciones = function() {
775 focaModalService
776 .prompt('Ingrese observaciones', $scope.remito.observaciones, true)
777 .then(function(observaciones) {
778 $scope.remito.observaciones = observaciones;
779 });
780 };
781
773 $scope.abrirModalCotizacion = function(moneda) { 782 $scope.abrirModalCotizacion = function(moneda) {
774 var modalInstance = $uibModal.open( 783 var modalInstance = $uibModal.open(
775 { 784 {
776 ariaLabelledBy: 'Busqueda de Cotización', 785 ariaLabelledBy: 'Busqueda de Cotización',
777 templateUrl: 'modal-cotizacion.html', 786 templateUrl: 'modal-cotizacion.html',
778 controller: 'focaModalCotizacionController', 787 controller: 'focaModalCotizacionController',
779 size: 'lg', 788 size: 'lg',
780 resolve: {idMoneda: function() {return moneda.ID;}} 789 resolve: {idMoneda: function() {return moneda.ID;}}
781 } 790 }
782 ); 791 );
783 modalInstance.result.then( 792 modalInstance.result.then(
784 function(cotizacion) { 793 function(cotizacion) {
785 var articulosTablaTemp = $scope.articulosTabla; 794 var articulosTablaTemp = $scope.articulosTabla;
786 for(var i = 0; i < articulosTablaTemp.length; i++) { 795 for(var i = 0; i < articulosTablaTemp.length; i++) {
787 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * 796 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio *
788 $scope.remito.cotizacion.COTIZACION; 797 $scope.remito.cotizacion.COTIZACION;
789 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / 798 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio /
790 cotizacion.COTIZACION; 799 cotizacion.COTIZACION;
791 } 800 }
792 $scope.articulosTabla = articulosTablaTemp; 801 $scope.articulosTabla = articulosTablaTemp;
793 $scope.remito.moneda = moneda; 802 $scope.remito.moneda = moneda;
794 $scope.remito.cotizacion = cotizacion; 803 $scope.remito.cotizacion = cotizacion;
795 if(moneda.DETALLE === 'PESOS ARGENTINOS') { 804 if(moneda.DETALLE === 'PESOS ARGENTINOS') {
796 $scope.$broadcast('removeCabecera', 'Moneda:'); 805 $scope.$broadcast('removeCabecera', 'Moneda:');
797 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 806 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
798 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 807 $scope.$broadcast('removeCabecera', 'Cotizacion:');
799 }else { 808 }else {
800 $scope.$broadcast('addCabecera',{ 809 $scope.$broadcast('addCabecera',{
801 label: 'Moneda:', 810 label: 'Moneda:',
802 valor: moneda.DETALLE 811 valor: moneda.DETALLE
803 }); 812 });
804 $scope.$broadcast('addCabecera',{ 813 $scope.$broadcast('addCabecera',{
805 label: 'Fecha cotizacion:', 814 label: 'Fecha cotizacion:',
806 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 815 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
807 }); 816 });
808 $scope.$broadcast('addCabecera',{ 817 $scope.$broadcast('addCabecera',{
809 label: 'Cotizacion:', 818 label: 'Cotizacion:',
810 valor: $filter('number')(cotizacion.COTIZACION, '2') 819 valor: $filter('number')(cotizacion.COTIZACION, '2')
811 }); 820 });
812 } 821 }
813 }, function() { 822 }, function() {
814 823
815 } 824 }
816 ); 825 );
817 }; 826 };
818 827
819 $scope.agregarATabla = function(key) { 828 $scope.agregarATabla = function(key) {
820 if(key === 13) { 829 if(key === 13) {
821 if($scope.articuloACargar.cantidad === undefined || 830 if($scope.articuloACargar.cantidad === undefined ||
822 $scope.articuloACargar.cantidad === 0 || 831 $scope.articuloACargar.cantidad === 0 ||
823 $scope.articuloACargar.cantidad === null ) { 832 $scope.articuloACargar.cantidad === null ) {
824 focaModalService.alert('El valor debe ser al menos 1'); 833 focaModalService.alert('El valor debe ser al menos 1');
825 return; 834 return;
826 } 835 }
827 delete $scope.articuloACargar.sectorCodigo; 836 delete $scope.articuloACargar.sectorCodigo;
828 $scope.articulosTabla.push($scope.articuloACargar); 837 $scope.articulosTabla.push($scope.articuloACargar);
829 $scope.cargando = true; 838 $scope.cargando = true;
830 } 839 }
831 }; 840 };
832 841
833 $scope.quitarArticulo = function(key) { 842 $scope.quitarArticulo = function(key) {
834 $scope.articulosTabla.splice(key, 1); 843 $scope.articulosTabla.splice(key, 1);
835 }; 844 };
836 845
837 $scope.editarArticulo = function(key, articulo) { 846 $scope.editarArticulo = function(key, articulo) {
838 if(key === 13) { 847 if(key === 13) {
839 if(articulo.cantidad === null || articulo.cantidad === 0 || 848 if(articulo.cantidad === null || articulo.cantidad === 0 ||
840 articulo.cantidad === undefined) { 849 articulo.cantidad === undefined) {
841 focaModalService.alert('El valor debe ser al menos 1'); 850 focaModalService.alert('El valor debe ser al menos 1');
842 return; 851 return;
843 } 852 }
844 articulo.editCantidad = false; 853 articulo.editCantidad = false;
845 articulo.editPrecio = false; 854 articulo.editPrecio = false;
846 } 855 }
847 }; 856 };
848 857
849 $scope.cambioEdit = function(articulo, propiedad) { 858 $scope.cambioEdit = function(articulo, propiedad) {
850 if(propiedad === 'cantidad') { 859 if(propiedad === 'cantidad') {
851 articulo.editCantidad = true; 860 articulo.editCantidad = true;
852 }else if(propiedad === 'precio') { 861 }else if(propiedad === 'precio') {
853 articulo.editPrecio = true; 862 articulo.editPrecio = true;
854 } 863 }
855 }; 864 };
856 865
857 $scope.limpiarFlete = function() { 866 $scope.limpiarFlete = function() {
858 $scope.remito.fleteNombre = ''; 867 $scope.remito.fleteNombre = '';
859 $scope.remito.chofer = ''; 868 $scope.remito.chofer = '';
860 $scope.remito.vehiculo = ''; 869 $scope.remito.vehiculo = '';
861 $scope.remito.kilometros = ''; 870 $scope.remito.kilometros = '';
862 $scope.remito.costoUnitarioKmFlete = ''; 871 $scope.remito.costoUnitarioKmFlete = '';
863 $scope.choferes = ''; 872 $scope.choferes = '';
864 $scope.vehiculos = ''; 873 $scope.vehiculos = '';
865 }; 874 };
866 875
867 $scope.limpiarPantalla = function() { 876 $scope.limpiarPantalla = function() {
868 $scope.limpiarFlete(); 877 $scope.limpiarFlete();
869 $scope.remito.flete = '0'; 878 $scope.remito.flete = '0';
870 $scope.remito.bomba = '0'; 879 $scope.remito.bomba = '0';
871 $scope.remito.precioCondicion = ''; 880 $scope.remito.precioCondicion = '';
872 $scope.articulosTabla = []; 881 $scope.articulosTabla = [];
873 $scope.remito.vendedor.nombre = ''; 882 $scope.remito.vendedor.nombre = '';
874 $scope.remito.cliente = {nombre: ''}; 883 $scope.remito.cliente = {nombre: ''};
875 $scope.remito.domicilio = {dom: ''}; 884 $scope.remito.domicilio = {dom: ''};
876 $scope.domiciliosCliente = []; 885 $scope.domiciliosCliente = [];
877 }; 886 };
878 887
879 $scope.resetFilter = function() { 888 $scope.resetFilter = function() {
880 $scope.articuloACargar = {}; 889 $scope.articuloACargar = {};
881 $scope.cargando = true; 890 $scope.cargando = true;
882 }; 891 };
883 //Recibe aviso si el teclado está en uso 892 //Recibe aviso si el teclado está en uso
884 $rootScope.$on('usarTeclado', function(event, data) { 893 $rootScope.$on('usarTeclado', function(event, data) {
885 if(data) { 894 if(data) {
886 $scope.mostrarTeclado = true; 895 $scope.mostrarTeclado = true;
887 return; 896 return;
888 } 897 }
889 $scope.mostrarTeclado = false; 898 $scope.mostrarTeclado = false;
890 }); 899 });
891 900
892 $scope.selectFocus = function($event) { 901 $scope.selectFocus = function($event) {
893 // Si el teclado esta en uso no selecciona el valor 902 // Si el teclado esta en uso no selecciona el valor
894 if($scope.mostrarTeclado) { 903 if($scope.mostrarTeclado) {
895 return; 904 return;
896 } 905 }
897 $event.target.select(); 906 $event.target.select();
898 }; 907 };
899 908
900 function addArrayCabecera(array) { 909 function addArrayCabecera(array) {
901 for(var i = 0; i < array.length; i++) { 910 for(var i = 0; i < array.length; i++) {
902 $scope.$broadcast('addCabecera',{ 911 $scope.$broadcast('addCabecera',{
903 label: array[i].label, 912 label: array[i].label,
904 valor: array[i].valor 913 valor: array[i].valor
905 }); 914 });
906 } 915 }
907 } 916 }
908 917
909 function rellenar(relleno, longitud) { 918 function rellenar(relleno, longitud) {
910 relleno = '' + relleno; 919 relleno = '' + relleno;
911 while (relleno.length < longitud) { 920 while (relleno.length < longitud) {
912 relleno = '0' + relleno; 921 relleno = '0' + relleno;
913 } 922 }
914 923
915 return relleno; 924 return relleno;
916 } 925 }
917 926
918 function varlidarRemitoFacturado() { 927 function varlidarRemitoFacturado() {
919 if($scope.remito.estado !== 5) { 928 if($scope.remito.estado !== 5) {
920 return true; 929 return true;
921 }else { 930 }else {
922 focaModalService.alert('No se puede editar un remito facturado'); 931 focaModalService.alert('No se puede editar un remito facturado');
923 return false(); 932 return false();
924 } 933 }
925 } 934 }
926 935
927 function salir() { 936 function salir() {
928 var confirmacion = false; 937 var confirmacion = false;
929 938
930 angular.forEach($scope.inicial, function(valor, key) { 939 angular.forEach($scope.inicial, function(valor, key) {
931 if (!angular.equals($scope[key], $scope.inicial[key])) { 940 if (!angular.equals($scope[key], $scope.inicial[key])) {
932 confirmacion = true; 941 confirmacion = true;
933 } 942 }
934 }); 943 });
935 944
936 if (confirmacion) { 945 if (confirmacion) {
937 focaModalService.confirm( 946 focaModalService.confirm(
938 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 947 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
939 ).then(function(data) { 948 ).then(function(data) {
940 if (data) { 949 if (data) {
941 $location.path('/'); 950 $location.path('/');
942 } 951 }
943 }); 952 });
944 } else { 953 } else {
945 $location.path('/'); 954 $location.path('/');
946 } 955 }
947 } 956 }
957
958 function enableObservaciones(val) {
959 var boton = $scope.botonera.filter(function(botonObs) {
960 return botonObs.label === 'Observaciones';
961 });
962
963 boton[0].disable = !val;
964 }
948 } 965 }
949 ]); 966 ]);
950 967
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 getBotonera: function() { 59 getBotonera: function() {
60 return [ 60 return [
61 { 61 {
62 label: 'Nota pedido', 62 label: 'Nota pedido',
63 image: 'notaDePedido.png' 63 image: 'notaDePedido.png'
64 }, 64 },
65 { 65 {
66 label: 'Vendedor', 66 label: 'Vendedor',
67 image: 'vendedor.png' 67 image: 'vendedor.png'
68 }, 68 },
69 { 69 {
70 label: 'Cliente', 70 label: 'Cliente',
71 image: 'cliente.png' 71 image: 'cliente.png'
72 }, 72 },
73 { 73 {
74 label: 'Proveedor', 74 label: 'Proveedor',
75 image: 'proveedor.png' 75 image: 'proveedor.png'
76 }, 76 },
77 { 77 {
78 label: 'Moneda', 78 label: 'Moneda',
79 image: 'moneda.png' 79 image: 'moneda.png'
80 }, 80 },
81 { 81 {
82 label: 'Precios y condiciones', 82 label: 'Precios y condiciones',
83 image: 'precios-condiciones.png' 83 image: 'precios-condiciones.png'
84 }, 84 },
85 { 85 {
86 label: 'Flete', 86 label: 'Flete',
87 image: 'flete.png' 87 image: 'flete.png'
88 }, 88 },
89 { 89 {
90 label: 'Productos', 90 label: 'Productos',
91 image: 'productos.png' 91 image: 'productos.png'
92 },
93 {
94 label: 'Observaciones',
95 image: 'productos.png',
96 disable: true
92 } 97 }
93 ]; 98 ];
94 } 99 }
95 }; 100 };
96 }]); 101 }]);
97 102