Commit c960e78e3ba80a535b57351fcc106dbb6d7c1642

Authored by Jose Pinto
1 parent 2674312b76
Exists in master

envio vendedor a modal cliente

Showing 1 changed file with 9 additions and 6 deletions   Show diff stats
src/js/controller.js
1 angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', 1 angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
2 [ 2 [
3 '$scope', 3 '$scope',
4 '$uibModal', 4 '$uibModal',
5 '$location', 5 '$location',
6 '$filter', 6 '$filter',
7 '$timeout', 7 '$timeout',
8 'crearNotaPedidoService', 8 'crearNotaPedidoService',
9 'focaBotoneraLateralService', 9 'focaBotoneraLateralService',
10 'focaModalService', 10 'focaModalService',
11 'notaPedidoBusinessService', 11 'notaPedidoBusinessService',
12 '$rootScope', 12 '$rootScope',
13 'focaSeguimientoService', 13 'focaSeguimientoService',
14 function( 14 function(
15 $scope, $uibModal, $location, $filter, $timeout, 15 $scope, $uibModal, $location, $filter, $timeout,
16 crearNotaPedidoService, focaBotoneraLateralService, 16 crearNotaPedidoService, focaBotoneraLateralService,
17 focaModalService, notaPedidoBusinessService, $rootScope, focaSeguimientoService) 17 focaModalService, notaPedidoBusinessService, $rootScope, focaSeguimientoService)
18 { 18 {
19 19
20 $scope.botonera = crearNotaPedidoService.getBotonera(); 20 $scope.botonera = crearNotaPedidoService.getBotonera();
21 21
22 $scope.isNumber = angular.isNumber; 22 $scope.isNumber = angular.isNumber;
23 $scope.datepickerAbierto = false; 23 $scope.datepickerAbierto = false;
24 $scope.show = false; 24 $scope.show = false;
25 $scope.cargando = true; 25 $scope.cargando = true;
26 $scope.dateOptions = { 26 $scope.dateOptions = {
27 maxDate: new Date(), 27 maxDate: new Date(),
28 minDate: new Date(2010, 0, 1) 28 minDate: new Date(2010, 0, 1)
29 }; 29 };
30 30
31 $scope.notaPedido = { 31 $scope.notaPedido = {
32 id: 0, 32 id: 0,
33 vendedor: {}, 33 vendedor: {},
34 cliente: {}, 34 cliente: {},
35 proveedor: {}, 35 proveedor: {},
36 domicilio: {dom: ''}, 36 domicilio: {dom: ''},
37 moneda: {}, 37 moneda: {},
38 cotizacion: {} 38 cotizacion: {}
39 }; 39 };
40 var monedaPorDefecto; 40 var monedaPorDefecto;
41 //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' 41 //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]'
42 crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { 42 crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) {
43 monedaPorDefecto = res.data[0]; 43 monedaPorDefecto = res.data[0];
44 $scope.notaPedido.moneda = monedaPorDefecto; 44 $scope.notaPedido.moneda = monedaPorDefecto;
45 $scope.notaPedido.cotizacion = monedaPorDefecto.cotizaciones[0]; 45 $scope.notaPedido.cotizacion = monedaPorDefecto.cotizaciones[0];
46 }); 46 });
47 47
48 $scope.cabecera = []; 48 $scope.cabecera = [];
49 $scope.showCabecera = true; 49 $scope.showCabecera = true;
50 50
51 $scope.now = new Date(); 51 $scope.now = new Date();
52 $scope.puntoVenta = '0000'; 52 $scope.puntoVenta = '0000';
53 $scope.comprobante = '00000000'; 53 $scope.comprobante = '00000000';
54 $scope.articulosTabla = []; 54 $scope.articulosTabla = [];
55 $scope.idLista = undefined; 55 $scope.idLista = undefined;
56 56
57 //SETEO BOTONERA LATERAL 57 //SETEO BOTONERA LATERAL
58 $timeout(function() { 58 $timeout(function() {
59 focaBotoneraLateralService.showSalir(false); 59 focaBotoneraLateralService.showSalir(false);
60 focaBotoneraLateralService.showPausar(true); 60 focaBotoneraLateralService.showPausar(true);
61 focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido); 61 focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido);
62 focaBotoneraLateralService.addCustomButton('Salir', salir); 62 focaBotoneraLateralService.addCustomButton('Salir', salir);
63 }); 63 });
64 64
65 crearNotaPedidoService.getNumeroNotaPedido().then( 65 crearNotaPedidoService.getNumeroNotaPedido().then(
66 function(res) { 66 function(res) {
67 $scope.puntoVenta = rellenar(res.data.sucursal, 4); 67 $scope.puntoVenta = rellenar(res.data.sucursal, 4);
68 $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); 68 $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8);
69 }, 69 },
70 function(err) { 70 function(err) {
71 focaModalService.alert('La terminal no esta configurada correctamente'); 71 focaModalService.alert('La terminal no esta configurada correctamente');
72 console.info(err); 72 console.info(err);
73 } 73 }
74 ); 74 );
75 75
76 $scope.crearNotaPedido = function() { 76 $scope.crearNotaPedido = function() {
77 if(!$scope.notaPedido.vendedor.CodVen) { 77 if(!$scope.notaPedido.vendedor.CodVen) {
78 focaModalService.alert('Ingrese Vendedor'); 78 focaModalService.alert('Ingrese Vendedor');
79 return; 79 return;
80 } else if(!$scope.notaPedido.cliente.COD) { 80 } else if(!$scope.notaPedido.cliente.COD) {
81 focaModalService.alert('Ingrese Cliente'); 81 focaModalService.alert('Ingrese Cliente');
82 return; 82 return;
83 } else if(!$scope.notaPedido.proveedor.COD) { 83 } else if(!$scope.notaPedido.proveedor.COD) {
84 focaModalService.alert('Ingrese Proveedor'); 84 focaModalService.alert('Ingrese Proveedor');
85 return; 85 return;
86 } else if(!$scope.notaPedido.moneda.ID) { 86 } else if(!$scope.notaPedido.moneda.ID) {
87 focaModalService.alert('Ingrese Moneda'); 87 focaModalService.alert('Ingrese Moneda');
88 return; 88 return;
89 } else if(!$scope.notaPedido.cotizacion.ID) { 89 } else if(!$scope.notaPedido.cotizacion.ID) {
90 focaModalService.alert('Ingrese Cotización'); 90 focaModalService.alert('Ingrese Cotización');
91 return; 91 return;
92 } else if(!$scope.plazosPagos) { 92 } else if(!$scope.plazosPagos) {
93 focaModalService.alert('Ingrese Precios y Condiciones'); 93 focaModalService.alert('Ingrese Precios y Condiciones');
94 return; 94 return;
95 } else if( 95 } else if(
96 $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) 96 $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null)
97 { 97 {
98 focaModalService.alert('Ingrese Flete'); 98 focaModalService.alert('Ingrese Flete');
99 return; 99 return;
100 } else if(!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto 100 } else if(!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto
101 focaModalService.alert('Ingrese Domicilio'); 101 focaModalService.alert('Ingrese Domicilio');
102 return; 102 return;
103 } else if($scope.articulosTabla.length === 0) { 103 } else if($scope.articulosTabla.length === 0) {
104 focaModalService.alert('Debe cargar al menos un articulo'); 104 focaModalService.alert('Debe cargar al menos un articulo');
105 return; 105 return;
106 } 106 }
107 focaBotoneraLateralService.startGuardar(); 107 focaBotoneraLateralService.startGuardar();
108 $scope.saveLoading = true; 108 $scope.saveLoading = true;
109 var notaPedido = { 109 var notaPedido = {
110 id: $scope.notaPedido.id, 110 id: $scope.notaPedido.id,
111 fechaCarga: $scope.now.toISOString().slice(0, 19).replace('T', ' '), 111 fechaCarga: $scope.now.toISOString().slice(0, 19).replace('T', ' '),
112 idVendedor: $scope.notaPedido.vendedor.CodVen, 112 idVendedor: $scope.notaPedido.vendedor.CodVen,
113 idCliente: $scope.notaPedido.cliente.COD, 113 idCliente: $scope.notaPedido.cliente.COD,
114 nombreCliente: $scope.notaPedido.cliente.NOM, 114 nombreCliente: $scope.notaPedido.cliente.NOM,
115 cuitCliente: $scope.notaPedido.cliente.CUIT, 115 cuitCliente: $scope.notaPedido.cliente.CUIT,
116 idProveedor: $scope.notaPedido.proveedor.COD, 116 idProveedor: $scope.notaPedido.proveedor.COD,
117 //idDomicilio: $scope.notaPedido.domicilio.id,TODO GUARDAR DOMICILIO ID 117 //idDomicilio: $scope.notaPedido.domicilio.id,TODO GUARDAR DOMICILIO ID
118 idCotizacion: $scope.notaPedido.cotizacion.ID, 118 idCotizacion: $scope.notaPedido.cotizacion.ID,
119 idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, 119 idPrecioCondicion: $scope.notaPedido.idPrecioCondicion,
120 cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, 120 cotizacion: $scope.notaPedido.cotizacion.VENDEDOR,
121 flete: $scope.notaPedido.flete, 121 flete: $scope.notaPedido.flete,
122 fob: $scope.notaPedido.fob, 122 fob: $scope.notaPedido.fob,
123 bomba: $scope.notaPedido.bomba, 123 bomba: $scope.notaPedido.bomba,
124 kilometros: $scope.notaPedido.kilometros, 124 kilometros: $scope.notaPedido.kilometros,
125 domicilioStamp: $scope.notaPedido.domicilioStamp, 125 domicilioStamp: $scope.notaPedido.domicilioStamp,
126 estado: 0, 126 estado: 0,
127 total: $scope.getTotal() 127 total: $scope.getTotal()
128 }; 128 };
129 crearNotaPedidoService.crearNotaPedido(notaPedido).then( 129 crearNotaPedidoService.crearNotaPedido(notaPedido).then(
130 function(data) { 130 function(data) {
131 // Al guardar los datos de la nota de pedido logueamos la 131 // Al guardar los datos de la nota de pedido logueamos la
132 // actividad para su seguimiento. 132 // actividad para su seguimiento.
133 //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? 133 //TODO: GUARDAR POSISIONAMIENTO AL EDITAR?
134 focaSeguimientoService.guardarPosicion( 134 focaSeguimientoService.guardarPosicion(
135 'Nota de pedido', 135 'Nota de pedido',
136 data.data.id, 136 data.data.id,
137 '' 137 ''
138 ); 138 );
139 notaPedidoBusinessService.addArticulos($scope.articulosTabla, 139 notaPedidoBusinessService.addArticulos($scope.articulosTabla,
140 data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); 140 data.data.id, $scope.notaPedido.cotizacion.VENDEDOR);
141 141
142 if($scope.notaPedido.puntosDescarga) { 142 if($scope.notaPedido.puntosDescarga) {
143 notaPedidoBusinessService.addPuntosDescarga(data.data.id, 143 notaPedidoBusinessService.addPuntosDescarga(data.data.id,
144 $scope.notaPedido.puntosDescarga); 144 $scope.notaPedido.puntosDescarga);
145 } 145 }
146 146
147 var plazos = $scope.plazosPagos; 147 var plazos = $scope.plazosPagos;
148 var plazosACrear = []; 148 var plazosACrear = [];
149 plazos.forEach(function(plazo) { 149 plazos.forEach(function(plazo) {
150 plazosACrear.push({ 150 plazosACrear.push({
151 idNotaPedido: data.data.id, 151 idNotaPedido: data.data.id,
152 dias: plazo.dias 152 dias: plazo.dias
153 }); 153 });
154 }); 154 });
155 if(plazosACrear.length){ 155 if(plazosACrear.length){
156 crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear); 156 crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear);
157 } 157 }
158 158
159 notaPedidoBusinessService.addEstado(data.data.id, 159 notaPedidoBusinessService.addEstado(data.data.id,
160 $scope.notaPedido.vendedor.CodVen); 160 $scope.notaPedido.vendedor.CodVen);
161 161
162 focaBotoneraLateralService.endGuardar(true); 162 focaBotoneraLateralService.endGuardar(true);
163 $scope.saveLoading = false; 163 $scope.saveLoading = false;
164 $scope.$broadcast('cleanCabecera'); 164 $scope.$broadcast('cleanCabecera');
165 $scope.$broadcast('addCabecera', { 165 $scope.$broadcast('addCabecera', {
166 label: 'Moneda:', 166 label: 'Moneda:',
167 valor: $scope.notaPedido.moneda.DETALLE 167 valor: $scope.notaPedido.moneda.DETALLE
168 }); 168 });
169 $scope.$broadcast('addCabecera', { 169 $scope.$broadcast('addCabecera', {
170 label: 'Fecha cotizacion:', 170 label: 'Fecha cotizacion:',
171 valor: $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy') 171 valor: $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy')
172 }); 172 });
173 $scope.$broadcast('addCabecera', { 173 $scope.$broadcast('addCabecera', {
174 label: 'Moneda:', 174 label: 'Moneda:',
175 valor: $scope.notaPedido.moneda.DETALLE 175 valor: $scope.notaPedido.moneda.DETALLE
176 }); 176 });
177 $scope.$broadcast('addCabecera', { 177 $scope.$broadcast('addCabecera', {
178 label: 'Cotizacion:', 178 label: 'Cotizacion:',
179 valor: $filter('number')($scope.notaPedido.cotizacion.VENDEDOR, '2') 179 valor: $filter('number')($scope.notaPedido.cotizacion.VENDEDOR, '2')
180 }); 180 });
181 crearNotaPedidoService.getNumeroNotaPedido().then( 181 crearNotaPedidoService.getNumeroNotaPedido().then(
182 function(res) { 182 function(res) {
183 $scope.puntoVenta = rellenar(res.data.sucursal, 4); 183 $scope.puntoVenta = rellenar(res.data.sucursal, 4);
184 $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); 184 $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8);
185 }, 185 },
186 function(err) { 186 function(err) {
187 focaModalService.alert( 187 focaModalService.alert(
188 'La terminal no esta configurada correctamente'); 188 'La terminal no esta configurada correctamente');
189 console.info(err); 189 console.info(err);
190 } 190 }
191 ); 191 );
192 $scope.notaPedido.vendedor = {}; 192 $scope.notaPedido.vendedor = {};
193 $scope.notaPedido.cliente = {}; 193 $scope.notaPedido.cliente = {};
194 $scope.notaPedido.proveedor = {}; 194 $scope.notaPedido.proveedor = {};
195 $scope.notaPedido.domicilio = {}; 195 $scope.notaPedido.domicilio = {};
196 $scope.notaPedido.flete = null; 196 $scope.notaPedido.flete = null;
197 $scope.notaPedido.fob = null; 197 $scope.notaPedido.fob = null;
198 $scope.notaPedido.bomba = null; 198 $scope.notaPedido.bomba = null;
199 $scope.notaPedido.kilometros = null; 199 $scope.notaPedido.kilometros = null;
200 $scope.articulosTabla = []; 200 $scope.articulosTabla = [];
201 }, 201 },
202 function(error) { 202 function(error) {
203 focaModalService.alert('Hubo un error al crear la nota de pedido'); 203 focaModalService.alert('Hubo un error al crear la nota de pedido');
204 focaBotoneraLateralService.endGuardar(); 204 focaBotoneraLateralService.endGuardar();
205 $scope.saveLoading = false; 205 $scope.saveLoading = false;
206 console.info(error); 206 console.info(error);
207 } 207 }
208 ); 208 );
209 }; 209 };
210 210
211 $scope.seleccionarNotaPedido = function() { 211 $scope.seleccionarNotaPedido = function() {
212 var modalInstance = $uibModal.open( 212 var modalInstance = $uibModal.open(
213 { 213 {
214 ariaLabelledBy: 'Busqueda de Nota de Pedido', 214 ariaLabelledBy: 'Busqueda de Nota de Pedido',
215 templateUrl: 'foca-modal-nota-pedido.html', 215 templateUrl: 'foca-modal-nota-pedido.html',
216 controller: 'focaModalNotaPedidoController', 216 controller: 'focaModalNotaPedidoController',
217 size: 'lg', 217 size: 'lg',
218 resolve: {usadoPor: function() {return 'notaPedido';}} 218 resolve: {usadoPor: function() {return 'notaPedido';}}
219 } 219 }
220 ); 220 );
221 modalInstance.result.then( 221 modalInstance.result.then(
222 function(notaPedido) { 222 function(notaPedido) {
223 $scope.now = new Date(notaPedido.fechaCarga); 223 $scope.now = new Date(notaPedido.fechaCarga);
224 //añado cabeceras 224 //añado cabeceras
225 $scope.notaPedido.id = notaPedido.id; 225 $scope.notaPedido.id = notaPedido.id;
226 $scope.$broadcast('removeCabecera', 'Bomba:'); 226 $scope.$broadcast('removeCabecera', 'Bomba:');
227 $scope.$broadcast('removeCabecera', 'Kilometros:'); 227 $scope.$broadcast('removeCabecera', 'Kilometros:');
228 var cabeceras = [ 228 var cabeceras = [
229 { 229 {
230 label: 'Moneda:', 230 label: 'Moneda:',
231 valor: notaPedido.cotizacion.moneda.DETALLE 231 valor: notaPedido.cotizacion.moneda.DETALLE
232 }, 232 },
233 { 233 {
234 label: 'Fecha cotizacion:', 234 label: 'Fecha cotizacion:',
235 valor: $filter('date')(notaPedido.cotizacion.FECHA, 235 valor: $filter('date')(notaPedido.cotizacion.FECHA,
236 'dd/MM/yyyy') 236 'dd/MM/yyyy')
237 }, 237 },
238 { 238 {
239 label: 'Cotizacion:', 239 label: 'Cotizacion:',
240 valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, 240 valor: $filter('number')(notaPedido.cotizacion.VENDEDOR,
241 '2') 241 '2')
242 }, 242 },
243 { 243 {
244 label: 'Cliente:', 244 label: 'Cliente:',
245 valor: notaPedido.cliente.NOM 245 valor: notaPedido.cliente.NOM
246 }, 246 },
247 { 247 {
248 label: 'Domicilio:', 248 label: 'Domicilio:',
249 valor: notaPedido.domicilioStamp 249 valor: notaPedido.domicilioStamp
250 }, 250 },
251 { 251 {
252 label: 'Vendedor:', 252 label: 'Vendedor:',
253 valor: notaPedido.vendedor.NomVen 253 valor: notaPedido.vendedor.NomVen
254 }, 254 },
255 { 255 {
256 label: 'Proveedor:', 256 label: 'Proveedor:',
257 valor: notaPedido.proveedor.NOM 257 valor: notaPedido.proveedor.NOM
258 }, 258 },
259 { 259 {
260 label: 'Precios y condiciones:', 260 label: 'Precios y condiciones:',
261 valor: valorPrecioCondicion() + ' ' + 261 valor: valorPrecioCondicion() + ' ' +
262 notaPedidoBusinessService 262 notaPedidoBusinessService
263 .plazoToString(notaPedido.notaPedidoPlazo) 263 .plazoToString(notaPedido.notaPedidoPlazo)
264 }, 264 },
265 { 265 {
266 label: 'Flete:', 266 label: 'Flete:',
267 valor: notaPedido.fob === 1 ? 'FOB' : ( 267 valor: notaPedido.fob === 1 ? 'FOB' : (
268 notaPedido.flete === 1 ? 'Si' : 'No') 268 notaPedido.flete === 1 ? 'Si' : 'No')
269 } 269 }
270 ]; 270 ];
271 271
272 function valorPrecioCondicion() { 272 function valorPrecioCondicion() {
273 if(notaPedido.idPrecioCondicion > 0) { 273 if(notaPedido.idPrecioCondicion > 0) {
274 return notaPedido.precioCondicion.nombre; 274 return notaPedido.precioCondicion.nombre;
275 } else { 275 } else {
276 return 'Ingreso Manual'; 276 return 'Ingreso Manual';
277 } 277 }
278 } 278 }
279 279
280 if(notaPedido.flete === 1) { 280 if(notaPedido.flete === 1) {
281 var cabeceraBomba = { 281 var cabeceraBomba = {
282 label: 'Bomba:', 282 label: 'Bomba:',
283 valor: notaPedido.bomba === 1 ? 'Si' : 'No' 283 valor: notaPedido.bomba === 1 ? 'Si' : 'No'
284 }; 284 };
285 if(notaPedido.kilometros) { 285 if(notaPedido.kilometros) {
286 var cabeceraKilometros = { 286 var cabeceraKilometros = {
287 label: 'Kilometros:', 287 label: 'Kilometros:',
288 valor: notaPedido.kilometros 288 valor: notaPedido.kilometros
289 }; 289 };
290 cabeceras.push(cabeceraKilometros); 290 cabeceras.push(cabeceraKilometros);
291 } 291 }
292 cabeceras.push(cabeceraBomba); 292 cabeceras.push(cabeceraBomba);
293 } 293 }
294 $scope.articulosTabla = notaPedido.articulosNotaPedido; 294 $scope.articulosTabla = notaPedido.articulosNotaPedido;
295 notaPedidoBusinessService.calcularArticulos($scope.articulosTabla, 295 notaPedidoBusinessService.calcularArticulos($scope.articulosTabla,
296 notaPedido.cotizacion.VENDEDOR); 296 notaPedido.cotizacion.VENDEDOR);
297 if(notaPedido.idPrecioCondicion > 0) { 297 if(notaPedido.idPrecioCondicion > 0) {
298 $scope.idLista = notaPedido.precioCondicion.idListaPrecio; 298 $scope.idLista = notaPedido.precioCondicion.idListaPrecio;
299 } else { 299 } else {
300 $scope.idLista = -1; 300 $scope.idLista = -1;
301 } 301 }
302 $scope.puntoVenta = rellenar(notaPedido.sucursal, 4); 302 $scope.puntoVenta = rellenar(notaPedido.sucursal, 4);
303 $scope.comprobante = rellenar(notaPedido.numeroNotaPedido, 8); 303 $scope.comprobante = rellenar(notaPedido.numeroNotaPedido, 8);
304 $scope.notaPedido = notaPedido; 304 $scope.notaPedido = notaPedido;
305 $scope.notaPedido.moneda = notaPedido.cotizacion.moneda; 305 $scope.notaPedido.moneda = notaPedido.cotizacion.moneda;
306 $scope.plazosPagos = notaPedido.notaPedidoPlazo; 306 $scope.plazosPagos = notaPedido.notaPedidoPlazo;
307 $scope.notaPedido.puntosDescarga = 307 $scope.notaPedido.puntosDescarga =
308 formatearPuntosDescarga(notaPedido.notaPedidoPuntoDescarga); 308 formatearPuntosDescarga(notaPedido.notaPedidoPuntoDescarga);
309 addArrayCabecera(cabeceras); 309 addArrayCabecera(cabeceras);
310 310
311 }, function() { 311 }, function() {
312 // funcion ejecutada cuando se cancela el modal 312 // funcion ejecutada cuando se cancela el modal
313 } 313 }
314 ); 314 );
315 }; 315 };
316 316
317 $scope.seleccionarProductos = function() { 317 $scope.seleccionarProductos = function() {
318 if ($scope.idLista === undefined) { 318 if ($scope.idLista === undefined) {
319 focaModalService.alert( 319 focaModalService.alert(
320 'Primero seleccione una lista de precio y condicion'); 320 'Primero seleccione una lista de precio y condicion');
321 return; 321 return;
322 } 322 }
323 var modalInstance = $uibModal.open( 323 var modalInstance = $uibModal.open(
324 { 324 {
325 ariaLabelledBy: 'Busqueda de Productos', 325 ariaLabelledBy: 'Busqueda de Productos',
326 templateUrl: 'modal-busqueda-productos.html', 326 templateUrl: 'modal-busqueda-productos.html',
327 controller: 'modalBusquedaProductosCtrl', 327 controller: 'modalBusquedaProductosCtrl',
328 resolve: { 328 resolve: {
329 parametroProducto: { 329 parametroProducto: {
330 idLista: $scope.idLista, 330 idLista: $scope.idLista,
331 cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, 331 cotizacion: $scope.notaPedido.cotizacion.VENDEDOR,
332 simbolo: $scope.notaPedido.moneda.SIMBOLO 332 simbolo: $scope.notaPedido.moneda.SIMBOLO
333 } 333 }
334 }, 334 },
335 size: 'lg' 335 size: 'lg'
336 } 336 }
337 ); 337 );
338 modalInstance.result.then( 338 modalInstance.result.then(
339 function(producto) { 339 function(producto) {
340 var newArt = 340 var newArt =
341 { 341 {
342 id: 0, 342 id: 0,
343 codigo: producto.codigo, 343 codigo: producto.codigo,
344 sector: producto.sector, 344 sector: producto.sector,
345 sectorCodigo: producto.sector + '-' + producto.codigo, 345 sectorCodigo: producto.sector + '-' + producto.codigo,
346 descripcion: producto.descripcion, 346 descripcion: producto.descripcion,
347 item: $scope.articulosTabla.length + 1, 347 item: $scope.articulosTabla.length + 1,
348 nombre: producto.descripcion, 348 nombre: producto.descripcion,
349 precio: parseFloat(producto.precio.toFixed(4)), 349 precio: parseFloat(producto.precio.toFixed(4)),
350 costoUnitario: producto.costo, 350 costoUnitario: producto.costo,
351 editCantidad: false, 351 editCantidad: false,
352 editPrecio: false, 352 editPrecio: false,
353 rubro: producto.CodRub, 353 rubro: producto.CodRub,
354 exentoUnitario: producto.precio, 354 exentoUnitario: producto.precio,
355 ivaUnitario: producto.IMPIVA, 355 ivaUnitario: producto.IMPIVA,
356 impuestoInternoUnitario: producto.ImpInt, 356 impuestoInternoUnitario: producto.ImpInt,
357 impuestoInterno1Unitario: producto.ImpInt2, 357 impuestoInterno1Unitario: producto.ImpInt2,
358 impuestoInterno2Unitario: producto.ImpInt3, 358 impuestoInterno2Unitario: producto.ImpInt3,
359 precioLista: producto.precio, 359 precioLista: producto.precio,
360 combustible: 1, 360 combustible: 1,
361 facturado: 0, 361 facturado: 0,
362 idArticulo: producto.id 362 idArticulo: producto.id
363 }; 363 };
364 $scope.articuloACargar = newArt; 364 $scope.articuloACargar = newArt;
365 $scope.cargando = false; 365 $scope.cargando = false;
366 }, function() { 366 }, function() {
367 // funcion ejecutada cuando se cancela el modal 367 // funcion ejecutada cuando se cancela el modal
368 } 368 }
369 ); 369 );
370 }; 370 };
371 371
372 $scope.seleccionarPuntosDeDescarga = function() { 372 $scope.seleccionarPuntosDeDescarga = function() {
373 if(!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { 373 if(!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) {
374 focaModalService.alert('Primero seleccione un cliente y un domicilio'); 374 focaModalService.alert('Primero seleccione un cliente y un domicilio');
375 return; 375 return;
376 }else { 376 }else {
377 var modalInstance = $uibModal.open( 377 var modalInstance = $uibModal.open(
378 { 378 {
379 ariaLabelledBy: 'Búsqueda de Puntos de descarga', 379 ariaLabelledBy: 'Búsqueda de Puntos de descarga',
380 templateUrl: 'modal-punto-descarga.html', 380 templateUrl: 'modal-punto-descarga.html',
381 controller: 'focaModalPuntoDescargaController', 381 controller: 'focaModalPuntoDescargaController',
382 size: 'lg', 382 size: 'lg',
383 resolve: { 383 resolve: {
384 filters: { 384 filters: {
385 /*TODO: al traer nota de pedido ya creada 385 /*TODO: al traer nota de pedido ya creada
386 obtener idDomicilio correctamente*/ 386 obtener idDomicilio correctamente*/
387 idDomicilio: $scope.notaPedido.domicilio.id, 387 idDomicilio: $scope.notaPedido.domicilio.id,
388 idCliente: $scope.notaPedido.cliente.COD, 388 idCliente: $scope.notaPedido.cliente.COD,
389 articulos: $scope.articulosTabla, 389 articulos: $scope.articulosTabla,
390 puntosDescarga: $scope.notaPedido.puntosDescarga 390 puntosDescarga: $scope.notaPedido.puntosDescarga
391 } 391 }
392 } 392 }
393 } 393 }
394 ); 394 );
395 modalInstance.result.then( 395 modalInstance.result.then(
396 function(puntosDescarga) { 396 function(puntosDescarga) {
397 $scope.notaPedido.puntosDescarga = puntosDescarga; 397 $scope.notaPedido.puntosDescarga = puntosDescarga;
398 }, function() { 398 }, function() {
399 399
400 } 400 }
401 ); 401 );
402 } 402 }
403 }; 403 };
404 404
405 $scope.seleccionarVendedor = function() { 405 $scope.seleccionarVendedor = function() {
406 if(validarNotaRemitada()) { 406 if(validarNotaRemitada()) {
407 var modalInstance = $uibModal.open( 407 var modalInstance = $uibModal.open(
408 { 408 {
409 ariaLabelledBy: 'Busqueda de Vendedores', 409 ariaLabelledBy: 'Busqueda de Vendedores',
410 templateUrl: 'modal-vendedores.html', 410 templateUrl: 'modal-vendedores.html',
411 controller: 'modalVendedoresCtrl', 411 controller: 'modalVendedoresCtrl',
412 size: 'lg' 412 size: 'lg'
413 } 413 }
414 ); 414 );
415 modalInstance.result.then( 415 modalInstance.result.then(
416 function(vendedor) { 416 function(vendedor) {
417 $scope.$broadcast('addCabecera', { 417 $scope.$broadcast('addCabecera', {
418 label: 'Vendedor:', 418 label: 'Vendedor:',
419 valor: vendedor.NomVen 419 valor: vendedor.NomVen
420 }); 420 });
421 $scope.notaPedido.vendedor = vendedor; 421 $scope.notaPedido.vendedor = vendedor;
422 }, function() { 422 }, function() {
423 423
424 } 424 }
425 ); 425 );
426 } 426 }
427 }; 427 };
428 428
429 $scope.seleccionarProveedor = function() { 429 $scope.seleccionarProveedor = function() {
430 if(validarNotaRemitada()) { 430 if(validarNotaRemitada()) {
431 var modalInstance = $uibModal.open( 431 var modalInstance = $uibModal.open(
432 { 432 {
433 ariaLabelledBy: 'Busqueda de Proveedor', 433 ariaLabelledBy: 'Busqueda de Proveedor',
434 templateUrl: 'modal-proveedor.html', 434 templateUrl: 'modal-proveedor.html',
435 controller: 'focaModalProveedorCtrl', 435 controller: 'focaModalProveedorCtrl',
436 size: 'lg', 436 size: 'lg',
437 resolve: { 437 resolve: {
438 transportista: function() { 438 transportista: function() {
439 return false; 439 return false;
440 } 440 }
441 } 441 }
442 } 442 }
443 ); 443 );
444 modalInstance.result.then( 444 modalInstance.result.then(
445 function(proveedor) { 445 function(proveedor) {
446 $scope.notaPedido.proveedor = proveedor; 446 $scope.notaPedido.proveedor = proveedor;
447 $scope.$broadcast('addCabecera', { 447 $scope.$broadcast('addCabecera', {
448 label: 'Proveedor:', 448 label: 'Proveedor:',
449 valor: proveedor.NOM 449 valor: proveedor.NOM
450 }); 450 });
451 }, function() { 451 }, function() {
452 452
453 } 453 }
454 ); 454 );
455 } 455 }
456 }; 456 };
457 457
458 $scope.seleccionarCliente = function() { 458 $scope.seleccionarCliente = function() {
459 if(!$scope.notaPedido.vendedor.CodVen) {
460 focaModalService.alert('Primero seleccione un vendedor');
461 return;
462 }
459 if(validarNotaRemitada()) { 463 if(validarNotaRemitada()) {
460 var modalInstance = $uibModal.open( 464 var modalInstance = $uibModal.open(
461 { 465 {
462 ariaLabelledBy: 'Busqueda de Cliente', 466 ariaLabelledBy: 'Busqueda de Cliente',
463 templateUrl: 'foca-busqueda-cliente-modal.html', 467 templateUrl: 'foca-busqueda-cliente-modal.html',
464 controller: 'focaBusquedaClienteModalController', 468 controller: 'focaBusquedaClienteModalController',
469 resolve: {
470 vendedor: function() { return $scope.notaPedido.vendedor; }
471 },
465 size: 'lg' 472 size: 'lg'
466 } 473 }
467 ); 474 );
468 modalInstance.result.then( 475 modalInstance.result.then(
469 function(cliente) { 476 function(cliente) {
470 $scope.abrirModalDomicilios(cliente); 477 $scope.abrirModalDomicilios(cliente);
471 }, function() {} 478 }, function() {}
472 ); 479 );
473 } 480 }
474 }; 481 };
475 482
476 $scope.abrirModalDomicilios = function(cliente) { 483 $scope.abrirModalDomicilios = function(cliente) {
477 var modalInstanceDomicilio = $uibModal.open( 484 var modalInstanceDomicilio = $uibModal.open(
478 { 485 {
479 ariaLabelledBy: 'Busqueda de Domicilios', 486 ariaLabelledBy: 'Busqueda de Domicilios',
480 templateUrl: 'modal-domicilio.html', 487 templateUrl: 'modal-domicilio.html',
481 controller: 'focaModalDomicilioController', 488 controller: 'focaModalDomicilioController',
482 resolve: { 489 resolve: {
483 idCliente: function() { 490 idCliente: function() { return cliente.cod; },
484 return cliente.cod;
485 },
486 esNuevo: function() { return cliente.esNuevo; }, 491 esNuevo: function() { return cliente.esNuevo; },
487 articulos: function() { 492 articulos: function() { return $scope.articulosTabla; },
488 return $scope.articulosTabla;
489 }
490 }, 493 },
491 size: 'lg', 494 size: 'lg',
492 } 495 }
493 ); 496 );
494 modalInstanceDomicilio.result.then( 497 modalInstanceDomicilio.result.then(
495 function(domicilio) { 498 function(domicilio) {
496 $scope.notaPedido.domicilio = domicilio; 499 $scope.notaPedido.domicilio = domicilio;
497 $scope.notaPedido.cliente = { 500 $scope.notaPedido.cliente = {
498 COD: cliente.cod, 501 COD: cliente.cod,
499 CUIT: cliente.cuit, 502 CUIT: cliente.cuit,
500 NOM: cliente.nom 503 NOM: cliente.nom
501 }; 504 };
502 var domicilioStamp = 505 var domicilioStamp =
503 domicilio.Calle + ' ' + domicilio.Numero + ', ' + 506 domicilio.Calle + ' ' + domicilio.Numero + ', ' +
504 domicilio.Localidad + ', ' + domicilio.Provincia; 507 domicilio.Localidad + ', ' + domicilio.Provincia;
505 $scope.notaPedido.domicilioStamp = domicilioStamp; 508 $scope.notaPedido.domicilioStamp = domicilioStamp;
506 509
507 $scope.notaPedido.puntosDescarga = domicilio.puntosDescarga; 510 $scope.notaPedido.puntosDescarga = domicilio.puntosDescarga;
508 511
509 $scope.$broadcast('addCabecera', { 512 $scope.$broadcast('addCabecera', {
510 label: 'Cliente:', 513 label: 'Cliente:',
511 valor: cliente.nom 514 valor: cliente.nom
512 }); 515 });
513 $scope.$broadcast('addCabecera', { 516 $scope.$broadcast('addCabecera', {
514 label: 'Domicilio:', 517 label: 'Domicilio:',
515 valor: domicilioStamp 518 valor: domicilioStamp
516 }); 519 });
517 crearNotaPedidoService 520 crearNotaPedidoService
518 .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) 521 .getPuntosDescargaByClienDom(domicilio.id, cliente.cod)
519 .then(function(res) { 522 .then(function(res) {
520 if(res.data.length) $scope.seleccionarPuntosDeDescarga(); 523 if(res.data.length) $scope.seleccionarPuntosDeDescarga();
521 }); 524 });
522 }, function() { 525 }, function() {
523 $scope.seleccionarCliente(); 526 $scope.seleccionarCliente();
524 return; 527 return;
525 } 528 }
526 ); 529 );
527 }; 530 };
528 531
529 $scope.getTotal = function() { 532 $scope.getTotal = function() {
530 var total = 0; 533 var total = 0;
531 var arrayTempArticulos = $scope.articulosTabla; 534 var arrayTempArticulos = $scope.articulosTabla;
532 for (var i = 0; i < arrayTempArticulos.length; i++) { 535 for (var i = 0; i < arrayTempArticulos.length; i++) {
533 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; 536 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad;
534 } 537 }
535 return parseFloat(total.toFixed(2)); 538 return parseFloat(total.toFixed(2));
536 }; 539 };
537 540
538 $scope.getSubTotal = function() { 541 $scope.getSubTotal = function() {
539 if($scope.articuloACargar) { 542 if($scope.articuloACargar) {
540 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; 543 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
541 } 544 }
542 }; 545 };
543 546
544 $scope.seleccionarPreciosYCondiciones = function() { 547 $scope.seleccionarPreciosYCondiciones = function() {
545 if(validarNotaRemitada()) { 548 if(validarNotaRemitada()) {
546 var modalInstance = $uibModal.open( 549 var modalInstance = $uibModal.open(
547 { 550 {
548 ariaLabelledBy: 'Busqueda de Precio Condición', 551 ariaLabelledBy: 'Busqueda de Precio Condición',
549 templateUrl: 'modal-precio-condicion.html', 552 templateUrl: 'modal-precio-condicion.html',
550 controller: 'focaModalPrecioCondicionController', 553 controller: 'focaModalPrecioCondicionController',
551 size: 'lg' 554 size: 'lg'
552 } 555 }
553 ); 556 );
554 modalInstance.result.then( 557 modalInstance.result.then(
555 function(precioCondicion) { 558 function(precioCondicion) {
556 var cabecera = ''; 559 var cabecera = '';
557 var plazosConcat = ''; 560 var plazosConcat = '';
558 if(!Array.isArray(precioCondicion)) { 561 if(!Array.isArray(precioCondicion)) {
559 $scope.notaPedido.idPrecioCondicion = precioCondicion.id; 562 $scope.notaPedido.idPrecioCondicion = precioCondicion.id;
560 $scope.plazosPagos = precioCondicion.plazoPago; 563 $scope.plazosPagos = precioCondicion.plazoPago;
561 $scope.idLista = precioCondicion.idListaPrecio; 564 $scope.idLista = precioCondicion.idListaPrecio;
562 for(var i = 0; i < precioCondicion.plazoPago.length; i++) { 565 for(var i = 0; i < precioCondicion.plazoPago.length; i++) {
563 plazosConcat += precioCondicion.plazoPago[i].dias + ' '; 566 plazosConcat += precioCondicion.plazoPago[i].dias + ' ';
564 } 567 }
565 cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); 568 cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim();
566 } else { //Cuando se ingresan los plazos manualmente 569 } else { //Cuando se ingresan los plazos manualmente
567 $scope.notaPedido.idPrecioCondicion = 0; 570 $scope.notaPedido.idPrecioCondicion = 0;
568 //-1, el modal productos busca todos los productos 571 //-1, el modal productos busca todos los productos
569 $scope.idLista = -1; 572 $scope.idLista = -1;
570 $scope.plazosPagos = precioCondicion; 573 $scope.plazosPagos = precioCondicion;
571 for(var j = 0; j < precioCondicion.length; j++) { 574 for(var j = 0; j < precioCondicion.length; j++) {
572 plazosConcat += precioCondicion[j].dias + ' '; 575 plazosConcat += precioCondicion[j].dias + ' ';
573 } 576 }
574 cabecera = 'Ingreso manual ' + plazosConcat.trim(); 577 cabecera = 'Ingreso manual ' + plazosConcat.trim();
575 } 578 }
576 $scope.articulosTabla = []; 579 $scope.articulosTabla = [];
577 $scope.$broadcast('addCabecera', { 580 $scope.$broadcast('addCabecera', {
578 label: 'Precios y condiciones:', 581 label: 'Precios y condiciones:',
579 valor: cabecera 582 valor: cabecera
580 }); 583 });
581 }, function() { 584 }, function() {
582 585
583 } 586 }
584 ); 587 );
585 } 588 }
586 }; 589 };
587 590
588 $scope.seleccionarFlete = function() { 591 $scope.seleccionarFlete = function() {
589 if(validarNotaRemitada()) { 592 if(validarNotaRemitada()) {
590 var modalInstance = $uibModal.open( 593 var modalInstance = $uibModal.open(
591 { 594 {
592 ariaLabelledBy: 'Busqueda de Flete', 595 ariaLabelledBy: 'Busqueda de Flete',
593 templateUrl: 'modal-flete.html', 596 templateUrl: 'modal-flete.html',
594 controller: 'focaModalFleteController', 597 controller: 'focaModalFleteController',
595 size: 'lg', 598 size: 'lg',
596 resolve: { 599 resolve: {
597 parametrosFlete: 600 parametrosFlete:
598 function() { 601 function() {
599 return { 602 return {
600 flete: $scope.notaPedido.fob ? 'FOB' : 603 flete: $scope.notaPedido.fob ? 'FOB' :
601 ( $scope.notaPedido.flete ? '1' : 604 ( $scope.notaPedido.flete ? '1' :
602 ($scope.notaPedido.flete === undefined ? 605 ($scope.notaPedido.flete === undefined ?
603 null : '0')), 606 null : '0')),
604 bomba: $scope.notaPedido.bomba ? '1' : 607 bomba: $scope.notaPedido.bomba ? '1' :
605 ($scope.notaPedido.bomba === undefined ? 608 ($scope.notaPedido.bomba === undefined ?
606 null : '0'), 609 null : '0'),
607 kilometros: $scope.notaPedido.kilometros 610 kilometros: $scope.notaPedido.kilometros
608 }; 611 };
609 } 612 }
610 } 613 }
611 } 614 }
612 ); 615 );
613 modalInstance.result.then( 616 modalInstance.result.then(
614 function(datos) { 617 function(datos) {
615 $scope.notaPedido.flete = datos.flete; 618 $scope.notaPedido.flete = datos.flete;
616 $scope.notaPedido.fob = datos.FOB; 619 $scope.notaPedido.fob = datos.FOB;
617 $scope.notaPedido.bomba = datos.bomba; 620 $scope.notaPedido.bomba = datos.bomba;
618 $scope.notaPedido.kilometros = datos.kilometros; 621 $scope.notaPedido.kilometros = datos.kilometros;
619 $scope.$broadcast('addCabecera', { 622 $scope.$broadcast('addCabecera', {
620 label: 'Flete:', 623 label: 'Flete:',
621 valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') 624 valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No')
622 }); 625 });
623 if(datos.flete) { 626 if(datos.flete) {
624 $scope.$broadcast('addCabecera', { 627 $scope.$broadcast('addCabecera', {
625 label: 'Bomba:', 628 label: 'Bomba:',
626 valor: datos.bomba ? 'Si' : 'No' 629 valor: datos.bomba ? 'Si' : 'No'
627 }); 630 });
628 $scope.$broadcast('addCabecera', { 631 $scope.$broadcast('addCabecera', {
629 label: 'Kilometros:', 632 label: 'Kilometros:',
630 valor: datos.kilometros 633 valor: datos.kilometros
631 }); 634 });
632 } else { 635 } else {
633 $scope.$broadcast('removeCabecera', 'Bomba:'); 636 $scope.$broadcast('removeCabecera', 'Bomba:');
634 $scope.$broadcast('removeCabecera', 'Kilometros:'); 637 $scope.$broadcast('removeCabecera', 'Kilometros:');
635 $scope.notaPedido.bomba = false; 638 $scope.notaPedido.bomba = false;
636 $scope.notaPedido.kilometros = null; 639 $scope.notaPedido.kilometros = null;
637 } 640 }
638 }, function() { 641 }, function() {
639 642
640 } 643 }
641 ); 644 );
642 } 645 }
643 }; 646 };
644 647
645 $scope.seleccionarMoneda = function() { 648 $scope.seleccionarMoneda = function() {
646 if(validarNotaRemitada()) { 649 if(validarNotaRemitada()) {
647 var modalInstance = $uibModal.open( 650 var modalInstance = $uibModal.open(
648 { 651 {
649 ariaLabelledBy: 'Busqueda de Moneda', 652 ariaLabelledBy: 'Busqueda de Moneda',
650 templateUrl: 'modal-moneda.html', 653 templateUrl: 'modal-moneda.html',
651 controller: 'focaModalMonedaController', 654 controller: 'focaModalMonedaController',
652 size: 'lg' 655 size: 'lg'
653 } 656 }
654 ); 657 );
655 modalInstance.result.then( 658 modalInstance.result.then(
656 function(moneda) { 659 function(moneda) {
657 $scope.abrirModalCotizacion(moneda); 660 $scope.abrirModalCotizacion(moneda);
658 }, function() { 661 }, function() {
659 662
660 } 663 }
661 ); 664 );
662 } 665 }
663 }; 666 };
664 667
665 $scope.abrirModalCotizacion = function(moneda) { 668 $scope.abrirModalCotizacion = function(moneda) {
666 var modalInstance = $uibModal.open( 669 var modalInstance = $uibModal.open(
667 { 670 {
668 ariaLabelledBy: 'Busqueda de Cotización', 671 ariaLabelledBy: 'Busqueda de Cotización',
669 templateUrl: 'modal-cotizacion.html', 672 templateUrl: 'modal-cotizacion.html',
670 controller: 'focaModalCotizacionController', 673 controller: 'focaModalCotizacionController',
671 size: 'lg', 674 size: 'lg',
672 resolve: {idMoneda: function() {return moneda.ID;}} 675 resolve: {idMoneda: function() {return moneda.ID;}}
673 } 676 }
674 ); 677 );
675 modalInstance.result.then( 678 modalInstance.result.then(
676 function(cotizacion) { 679 function(cotizacion) {
677 var articulosTablaTemp = $scope.articulosTabla; 680 var articulosTablaTemp = $scope.articulosTabla;
678 for(var i = 0; i < articulosTablaTemp.length; i++) { 681 for(var i = 0; i < articulosTablaTemp.length; i++) {
679 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * 682 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio *
680 $scope.notaPedido.cotizacion.VENDEDOR; 683 $scope.notaPedido.cotizacion.VENDEDOR;
681 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / 684 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio /
682 cotizacion.VENDEDOR; 685 cotizacion.VENDEDOR;
683 } 686 }
684 $scope.articulosTabla = articulosTablaTemp; 687 $scope.articulosTabla = articulosTablaTemp;
685 $scope.notaPedido.moneda = moneda; 688 $scope.notaPedido.moneda = moneda;
686 $scope.notaPedido.cotizacion = cotizacion; 689 $scope.notaPedido.cotizacion = cotizacion;
687 if(moneda.DETALLE === 'PESOS ARGENTINOS') { 690 if(moneda.DETALLE === 'PESOS ARGENTINOS') {
688 $scope.$broadcast('removeCabecera', 'Moneda:'); 691 $scope.$broadcast('removeCabecera', 'Moneda:');
689 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 692 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
690 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 693 $scope.$broadcast('removeCabecera', 'Cotizacion:');
691 }else { 694 }else {
692 $scope.$broadcast('addCabecera', { 695 $scope.$broadcast('addCabecera', {
693 label: 'Moneda:', 696 label: 'Moneda:',
694 valor: moneda.DETALLE 697 valor: moneda.DETALLE
695 }); 698 });
696 $scope.$broadcast('addCabecera', { 699 $scope.$broadcast('addCabecera', {
697 label: 'Fecha cotizacion:', 700 label: 'Fecha cotizacion:',
698 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 701 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
699 }); 702 });
700 $scope.$broadcast('addCabecera', { 703 $scope.$broadcast('addCabecera', {
701 label: 'Cotizacion:', 704 label: 'Cotizacion:',
702 valor: $filter('number')(cotizacion.VENDEDOR, '2') 705 valor: $filter('number')(cotizacion.VENDEDOR, '2')
703 }); 706 });
704 } 707 }
705 }, function() { 708 }, function() {
706 709
707 } 710 }
708 ); 711 );
709 }; 712 };
710 713
711 $scope.agregarATabla = function(key) { 714 $scope.agregarATabla = function(key) {
712 if(key === 13) { 715 if(key === 13) {
713 if($scope.articuloACargar.cantidad === undefined || 716 if($scope.articuloACargar.cantidad === undefined ||
714 $scope.articuloACargar.cantidad === 0 || 717 $scope.articuloACargar.cantidad === 0 ||
715 $scope.articuloACargar.cantidad === null ) { 718 $scope.articuloACargar.cantidad === null ) {
716 focaModalService.alert('El valor debe ser al menos 1'); 719 focaModalService.alert('El valor debe ser al menos 1');
717 return; 720 return;
718 } 721 }
719 delete $scope.articuloACargar.sectorCodigo; 722 delete $scope.articuloACargar.sectorCodigo;
720 $scope.articulosTabla.push($scope.articuloACargar); 723 $scope.articulosTabla.push($scope.articuloACargar);
721 $scope.cargando = true; 724 $scope.cargando = true;
722 } 725 }
723 }; 726 };
724 727
725 $scope.quitarArticulo = function(key) { 728 $scope.quitarArticulo = function(key) {
726 $scope.articulosTabla.splice(key, 1); 729 $scope.articulosTabla.splice(key, 1);
727 }; 730 };
728 731
729 $scope.editarArticulo = function(key, articulo) { 732 $scope.editarArticulo = function(key, articulo) {
730 if(key === 13) { 733 if(key === 13) {
731 if(articulo.cantidad === null || articulo.cantidad === 0 || 734 if(articulo.cantidad === null || articulo.cantidad === 0 ||
732 articulo.cantidad === undefined) { 735 articulo.cantidad === undefined) {
733 focaModalService.alert('El valor debe ser al menos 1'); 736 focaModalService.alert('El valor debe ser al menos 1');
734 return; 737 return;
735 } 738 }
736 articulo.editCantidad = false; 739 articulo.editCantidad = false;
737 articulo.editPrecio = false; 740 articulo.editPrecio = false;
738 } 741 }
739 }; 742 };
740 743
741 $scope.cambioEdit = function(articulo, propiedad) { 744 $scope.cambioEdit = function(articulo, propiedad) {
742 if(propiedad === 'cantidad') { 745 if(propiedad === 'cantidad') {
743 articulo.editCantidad = true; 746 articulo.editCantidad = true;
744 } else if(propiedad === 'precio') { 747 } else if(propiedad === 'precio') {
745 articulo.editPrecio = true; 748 articulo.editPrecio = true;
746 } 749 }
747 }; 750 };
748 751
749 $scope.resetFilter = function() { 752 $scope.resetFilter = function() {
750 $scope.articuloACargar = {}; 753 $scope.articuloACargar = {};
751 $scope.cargando = true; 754 $scope.cargando = true;
752 }; 755 };
753 //Recibe aviso si el teclado está en uso 756 //Recibe aviso si el teclado está en uso
754 $rootScope.$on('usarTeclado', function(event, data) { 757 $rootScope.$on('usarTeclado', function(event, data) {
755 if(data) { 758 if(data) {
756 $scope.mostrarTeclado = true; 759 $scope.mostrarTeclado = true;
757 return; 760 return;
758 } 761 }
759 $scope.mostrarTeclado = false; 762 $scope.mostrarTeclado = false;
760 }); 763 });
761 764
762 $scope.selectFocus = function($event) { 765 $scope.selectFocus = function($event) {
763 // Si el teclado esta en uso no selecciona el valor 766 // Si el teclado esta en uso no selecciona el valor
764 if($scope.mostrarTeclado) { 767 if($scope.mostrarTeclado) {
765 return; 768 return;
766 } 769 }
767 $event.target.select(); 770 $event.target.select();
768 }; 771 };
769 772
770 $scope.salir = function() { 773 $scope.salir = function() {
771 $location.path('/'); 774 $location.path('/');
772 }; 775 };
773 776
774 $scope.parsearATexto = function(articulo) { 777 $scope.parsearATexto = function(articulo) {
775 articulo.cantidad = parseFloat(articulo.cantidad); 778 articulo.cantidad = parseFloat(articulo.cantidad);
776 articulo.precio = parseFloat(articulo.precio); 779 articulo.precio = parseFloat(articulo.precio);
777 }; 780 };
778 781
779 function addArrayCabecera(array) { 782 function addArrayCabecera(array) {
780 for(var i = 0; i < array.length; i++) { 783 for(var i = 0; i < array.length; i++) {
781 $scope.$broadcast('addCabecera', { 784 $scope.$broadcast('addCabecera', {
782 label: array[i].label, 785 label: array[i].label,
783 valor: array[i].valor 786 valor: array[i].valor
784 }); 787 });
785 } 788 }
786 } 789 }
787 790
788 function rellenar(relleno, longitud) { 791 function rellenar(relleno, longitud) {
789 relleno = '' + relleno; 792 relleno = '' + relleno;
790 while (relleno.length < longitud) { 793 while (relleno.length < longitud) {
791 relleno = '0' + relleno; 794 relleno = '0' + relleno;
792 } 795 }
793 796
794 return relleno; 797 return relleno;
795 } 798 }
796 799
797 function validarNotaRemitada() { 800 function validarNotaRemitada() {
798 if(!$scope.notaPedido.idRemito) { 801 if(!$scope.notaPedido.idRemito) {
799 return true; 802 return true;
800 }else{ 803 }else{
801 focaModalService.alert('No se puede editar una nota de pedido remitada'); 804 focaModalService.alert('No se puede editar una nota de pedido remitada');
802 return false; 805 return false;
803 } 806 }
804 } 807 }
805 function formatearPuntosDescarga(puntosDescarga) { 808 function formatearPuntosDescarga(puntosDescarga) {
806 var result = []; 809 var result = [];
807 810
808 puntosDescarga.forEach(function(el) { 811 puntosDescarga.forEach(function(el) {
809 var puntoDescarga = result.filter(function(resultPunto) { 812 var puntoDescarga = result.filter(function(resultPunto) {
810 return resultPunto.id == el.idPuntoDescarga; 813 return resultPunto.id == el.idPuntoDescarga;
811 }); 814 });
812 815
813 if(puntoDescarga.length) { 816 if(puntoDescarga.length) {
814 puntoDescarga[0].articulosAgregados.push({ 817 puntoDescarga[0].articulosAgregados.push({
815 cantidad: el.cantidad, 818 cantidad: el.cantidad,
816 descripcion: el.producto.descripcion, 819 descripcion: el.producto.descripcion,
817 id: el.producto.id 820 id: el.producto.id
818 }); 821 });
819 }else { 822 }else {
820 result.push({ 823 result.push({
821 id: el.puntoDescarga.id, 824 id: el.puntoDescarga.id,
822 id_cliente: el.puntoDescarga.id_cliente, 825 id_cliente: el.puntoDescarga.id_cliente,
823 id_da_config_0: el.puntoDescarga.id_da_config_0, 826 id_da_config_0: el.puntoDescarga.id_da_config_0,
824 latitud: el.puntoDescarga.latitud, 827 latitud: el.puntoDescarga.latitud,
825 longitud: el.puntoDescarga.longitud, 828 longitud: el.puntoDescarga.longitud,
826 descripcion: el.puntoDescarga.descripcion, 829 descripcion: el.puntoDescarga.descripcion,
827 articulosAgregados: [ 830 articulosAgregados: [
828 { 831 {
829 cantidad: el.cantidad, 832 cantidad: el.cantidad,
830 descripcion: el.producto.descripcion, 833 descripcion: el.producto.descripcion,
831 id: el.producto.id 834 id: el.producto.id
832 } 835 }
833 ] 836 ]
834 }); 837 });
835 } 838 }
836 }); 839 });
837 return result; 840 return result;
838 } 841 }
839 842
840 function salir() { 843 function salir() {
841 var notaPedido = { 844 var notaPedido = {
842 id: 0, 845 id: 0,
843 vendedor: {}, 846 vendedor: {},
844 cliente: {}, 847 cliente: {},
845 proveedor: {}, 848 proveedor: {},
846 domicilio: {dom: ''}, 849 domicilio: {dom: ''},
847 moneda: $scope.notaPedido.moneda, 850 moneda: $scope.notaPedido.moneda,
848 cotizacion: $scope.notaPedido.cotizacion 851 cotizacion: $scope.notaPedido.cotizacion
849 }; 852 };
850 if(JSON.stringify($scope.notaPedido) !== JSON.stringify(notaPedido)) { 853 if(JSON.stringify($scope.notaPedido) !== JSON.stringify(notaPedido)) {
851 focaModalService 854 focaModalService
852 .confirm('¿Esta seguro de que desea salir? ' + 855 .confirm('¿Esta seguro de que desea salir? ' +
853 'Se perderán todos los datos cargados.') 856 'Se perderán todos los datos cargados.')
854 .then(function(data) { 857 .then(function(data) {
855 if(data) $location.path('/'); 858 if(data) $location.path('/');
856 }); 859 });
857 }else { 860 }else {
858 $location.path('/'); 861 $location.path('/');
859 } 862 }