Commit 959870da9c00dc0148380e7dd08ab6cbafd08385

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'master'

Master

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