Commit e75f313e6a8be98d2270acb6c39e67db96f6c1b6

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'master'

envío id notaPedido en vez de idVendedor

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