Commit a93cf44e37fd5bec7a4faa7fd13d8616eec6b7bf

Authored by Eric Fernandez
1 parent 3a15cf255e
Exists in master

Obtengo el número de nota pedido al guardar

Showing 1 changed file with 10 additions and 0 deletions   Show diff stats
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 date = new Date(); 154 var date = new Date();
155 var notaPedido = { 155 var notaPedido = {
156 id: $scope.notaPedido.id, 156 id: $scope.notaPedido.id,
157 fechaCarga: new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) 157 fechaCarga: new Date(date.getTime() - (date.getTimezoneOffset() * 60000))
158 .toISOString().slice(0, 19).replace('T', ' '), 158 .toISOString().slice(0, 19).replace('T', ' '),
159 idVendedor: $scope.notaPedido.vendedor.CodVen, 159 idVendedor: $scope.notaPedido.vendedor.CodVen,
160 idCliente: $scope.notaPedido.cliente.COD, 160 idCliente: $scope.notaPedido.cliente.COD,
161 nombreCliente: $scope.notaPedido.cliente.NOM, 161 nombreCliente: $scope.notaPedido.cliente.NOM,
162 cuitCliente: $scope.notaPedido.cliente.CUIT, 162 cuitCliente: $scope.notaPedido.cliente.CUIT,
163 idProveedor: $scope.notaPedido.proveedor.COD, 163 idProveedor: $scope.notaPedido.proveedor.COD,
164 idDomicilio: $scope.notaPedido.domicilio.id, 164 idDomicilio: $scope.notaPedido.domicilio.id,
165 idCotizacion: $scope.notaPedido.cotizacion.ID, 165 idCotizacion: $scope.notaPedido.cotizacion.ID,
166 idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, 166 idPrecioCondicion: $scope.notaPedido.idPrecioCondicion,
167 cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, 167 cotizacion: $scope.notaPedido.cotizacion.VENDEDOR,
168 flete: $scope.notaPedido.flete, 168 flete: $scope.notaPedido.flete,
169 fob: $scope.notaPedido.fob, 169 fob: $scope.notaPedido.fob,
170 bomba: $scope.notaPedido.bomba, 170 bomba: $scope.notaPedido.bomba,
171 kilometros: $scope.notaPedido.kilometros, 171 kilometros: $scope.notaPedido.kilometros,
172 domicilioStamp: $scope.notaPedido.domicilioStamp, 172 domicilioStamp: $scope.notaPedido.domicilioStamp,
173 estado: 0, 173 estado: 0,
174 total: $scope.getTotal() 174 total: $scope.getTotal()
175 }; 175 };
176 crearNotaPedidoService.crearNotaPedido(notaPedido).then( 176 crearNotaPedidoService.crearNotaPedido(notaPedido).then(
177 function(data) { 177 function(data) {
178 // Al guardar los datos de la nota de pedido logueamos la 178 // Al guardar los datos de la nota de pedido logueamos la
179 // actividad para su seguimiento. 179 // actividad para su seguimiento.
180 focaSeguimientoService.guardarPosicion( 180 focaSeguimientoService.guardarPosicion(
181 $scope.notaPedido.vendedor.codigo, 181 $scope.notaPedido.vendedor.codigo,
182 'Nota de pedido', 182 'Nota de pedido',
183 'Nº: ' + $filter('comprobante')([ 183 'Nº: ' + $filter('comprobante')([
184 $scope.puntoVenta, 184 $scope.puntoVenta,
185 $scope.comprobante 185 $scope.comprobante
186 ]) 186 ])
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.codigo); 200 $scope.notaPedido.vendedor.codigo);
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(
211 function(res) {
212 $scope.puntoVenta = rellenar(res.data.sucursal, 4);
213 $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8);
214 },
215 function(err) {
216 focaModalService.alert('La terminal no esta configurada correctamente');
217 console.info(err);
218 }
219 );
210 $scope.notaPedido.vendedor = {}; 220 $scope.notaPedido.vendedor = {};
211 $scope.notaPedido.cliente = {}; 221 $scope.notaPedido.cliente = {};
212 $scope.notaPedido.proveedor = {}; 222 $scope.notaPedido.proveedor = {};
213 $scope.notaPedido.domicilio = {}; 223 $scope.notaPedido.domicilio = {};
214 $scope.notaPedido.flete = null; 224 $scope.notaPedido.flete = null;
215 $scope.notaPedido.fob = null; 225 $scope.notaPedido.fob = null;
216 $scope.notaPedido.bomba = null; 226 $scope.notaPedido.bomba = null;
217 $scope.notaPedido.kilometros = null; 227 $scope.notaPedido.kilometros = null;
218 $scope.articulosTabla = []; 228 $scope.articulosTabla = [];
219 }, 229 },
220 function(error) { 230 function(error) {
221 focaModalService.alert('Hubo un error al crear la nota de pedido'); 231 focaModalService.alert('Hubo un error al crear la nota de pedido');
222 console.info(error); 232 console.info(error);
223 } 233 }
224 ); 234 );
225 }; 235 };
226 236
227 $scope.seleccionarNotaPedido = function() { 237 $scope.seleccionarNotaPedido = function() {
228 var modalInstance = $uibModal.open( 238 var modalInstance = $uibModal.open(
229 { 239 {
230 ariaLabelledBy: 'Busqueda de Nota de Pedido', 240 ariaLabelledBy: 'Busqueda de Nota de Pedido',
231 templateUrl: 'foca-modal-nota-pedido.html', 241 templateUrl: 'foca-modal-nota-pedido.html',
232 controller: 'focaModalNotaPedidoController', 242 controller: 'focaModalNotaPedidoController',
233 size: 'lg' 243 size: 'lg'
234 } 244 }
235 ); 245 );
236 modalInstance.result.then( 246 modalInstance.result.then(
237 function(notaPedido) { 247 function(notaPedido) {
238 //añado cabeceras 248 //añado cabeceras
239 $scope.notaPedido.id = notaPedido.id; 249 $scope.notaPedido.id = notaPedido.id;
240 removeCabecera('Moneda:'); 250 removeCabecera('Moneda:');
241 removeCabecera('Fecha cotizacion:'); 251 removeCabecera('Fecha cotizacion:');
242 removeCabecera('Cotizacion:'); 252 removeCabecera('Cotizacion:');
243 var cabeceras = [ 253 var cabeceras = [
244 { 254 {
245 label: 'Moneda', 255 label: 'Moneda',
246 valor: notaPedido.cotizacion[0].moneda[0].DETALLE 256 valor: notaPedido.cotizacion[0].moneda[0].DETALLE
247 }, 257 },
248 { 258 {
249 label: 'Fecha cotizacion', 259 label: 'Fecha cotizacion',
250 valor: $filter('date')(notaPedido.cotizacion[0].FECHA, 260 valor: $filter('date')(notaPedido.cotizacion[0].FECHA,
251 'dd/MM/yyyy') 261 'dd/MM/yyyy')
252 }, 262 },
253 { 263 {
254 label: 'Cotizacion', 264 label: 'Cotizacion',
255 valor: notaPedido.cotizacion[0].VENDEDOR 265 valor: notaPedido.cotizacion[0].VENDEDOR
256 }, 266 },
257 { 267 {
258 label: 'Cliente:', 268 label: 'Cliente:',
259 valor: notaPedido.cliente[0].NOM 269 valor: notaPedido.cliente[0].NOM
260 }, 270 },
261 { 271 {
262 label: 'Domicilio:', 272 label: 'Domicilio:',
263 valor: notaPedido.domicilioStamp 273 valor: notaPedido.domicilioStamp
264 }, 274 },
265 { 275 {
266 label: 'Vendedor:', 276 label: 'Vendedor:',
267 valor: notaPedido.vendedor[0].NomVen 277 valor: notaPedido.vendedor[0].NomVen
268 }, 278 },
269 { 279 {
270 label: 'Proveedor:', 280 label: 'Proveedor:',
271 valor: notaPedido.proveedor[0].NOM 281 valor: notaPedido.proveedor[0].NOM
272 }, 282 },
273 { 283 {
274 label: 'Flete:', 284 label: 'Flete:',
275 valor: notaPedido.flete === 1 ? 'Si' : 'No' 285 valor: notaPedido.flete === 1 ? 'Si' : 'No'
276 }, 286 },
277 { 287 {
278 label: 'FOB:', 288 label: 'FOB:',
279 valor: notaPedido.fob === 1 ? 'Si' : 'No' 289 valor: notaPedido.fob === 1 ? 'Si' : 'No'
280 }, 290 },
281 { 291 {
282 label: 'Precio condicion:', 292 label: 'Precio condicion:',
283 valor: valorPrecioCondicion() 293 valor: valorPrecioCondicion()
284 } 294 }
285 ]; 295 ];
286 //TODO MOSTRAR PLAZOS 296 //TODO MOSTRAR PLAZOS
287 function valorPrecioCondicion() { 297 function valorPrecioCondicion() {
288 if(notaPedido.idPrecioCondicion > 0) { 298 if(notaPedido.idPrecioCondicion > 0) {
289 return notaPedido.precioCondicion[0].nombre; 299 return notaPedido.precioCondicion[0].nombre;
290 } else { 300 } else {
291 return 'Ingreso Manual'; 301 return 'Ingreso Manual';
292 } 302 }
293 } 303 }
294 304
295 if(notaPedido.flete === 1) { 305 if(notaPedido.flete === 1) {
296 var cabeceraBomba = { 306 var cabeceraBomba = {
297 label: 'Bomba', 307 label: 'Bomba',
298 valor: notaPedido.bomba === 1 ? 'Si' : 'No' 308 valor: notaPedido.bomba === 1 ? 'Si' : 'No'
299 }; 309 };
300 if(notaPedido.kilometros) { 310 if(notaPedido.kilometros) {
301 var cabeceraKilometros = { 311 var cabeceraKilometros = {
302 label: 'Kilometros', 312 label: 'Kilometros',
303 valor: notaPedido.kilometros 313 valor: notaPedido.kilometros
304 }; 314 };
305 cabeceras.push(cabeceraKilometros); 315 cabeceras.push(cabeceraKilometros);
306 } 316 }
307 cabeceras.push(cabeceraBomba); 317 cabeceras.push(cabeceraBomba);
308 } 318 }
309 $scope.articulosTabla = notaPedido.articulosNotaPedido; 319 $scope.articulosTabla = notaPedido.articulosNotaPedido;
310 if(notaPedido.precioCondicion.length > 0) { 320 if(notaPedido.precioCondicion.length > 0) {
311 $scope.idLista = notaPedido.precioCondicion[0].idListaPrecio; 321 $scope.idLista = notaPedido.precioCondicion[0].idListaPrecio;
312 } else { 322 } else {
313 $scope.idLista = -1; 323 $scope.idLista = -1;
314 } 324 }
315 $scope.comprobante = rellenar(notaPedido.numeroNotaPedido, 8); 325 $scope.comprobante = rellenar(notaPedido.numeroNotaPedido, 8);
316 $scope.notaPedido = notaPedido; 326 $scope.notaPedido = notaPedido;
317 $scope.notaPedido.vendedor = notaPedido.vendedor[0]; 327 $scope.notaPedido.vendedor = notaPedido.vendedor[0];
318 $scope.notaPedido.cliente = notaPedido.cliente[0]; 328 $scope.notaPedido.cliente = notaPedido.cliente[0];
319 $scope.notaPedido.proveedor = notaPedido.proveedor[0]; 329 $scope.notaPedido.proveedor = notaPedido.proveedor[0];
320 $scope.notaPedido.moneda = notaPedido.cotizacion[0].moneda[0]; 330 $scope.notaPedido.moneda = notaPedido.cotizacion[0].moneda[0];
321 $scope.notaPedido.cotizacion = notaPedido.cotizacion[0]; 331 $scope.notaPedido.cotizacion = notaPedido.cotizacion[0];
322 $scope.plazosPagos = notaPedido.plazoPago; 332 $scope.plazosPagos = notaPedido.plazoPago;
323 addArrayCabecera(cabeceras); 333 addArrayCabecera(cabeceras);
324 334
325 }, function() { 335 }, function() {
326 // funcion ejecutada cuando se cancela el modal 336 // funcion ejecutada cuando se cancela el modal
327 } 337 }
328 ); 338 );
329 } 339 }
330 340
331 $scope.seleccionarArticulo = function() { 341 $scope.seleccionarArticulo = function() {
332 if ($scope.idLista === undefined) { 342 if ($scope.idLista === undefined) {
333 focaModalService.alert( 343 focaModalService.alert(
334 'Primero seleccione una lista de precio y condicion'); 344 'Primero seleccione una lista de precio y condicion');
335 return; 345 return;
336 } 346 }
337 var modalInstance = $uibModal.open( 347 var modalInstance = $uibModal.open(
338 { 348 {
339 ariaLabelledBy: 'Busqueda de Productos', 349 ariaLabelledBy: 'Busqueda de Productos',
340 templateUrl: 'modal-busqueda-productos.html', 350 templateUrl: 'modal-busqueda-productos.html',
341 controller: 'modalBusquedaProductosCtrl', 351 controller: 'modalBusquedaProductosCtrl',
342 resolve: { 352 resolve: {
343 parametroProducto: { 353 parametroProducto: {
344 idLista: $scope.idLista, 354 idLista: $scope.idLista,
345 cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, 355 cotizacion: $scope.notaPedido.cotizacion.VENDEDOR,
346 simbolo: $scope.notaPedido.moneda.simbolo 356 simbolo: $scope.notaPedido.moneda.simbolo
347 } 357 }
348 }, 358 },
349 size: 'lg' 359 size: 'lg'
350 } 360 }
351 ); 361 );
352 modalInstance.result.then( 362 modalInstance.result.then(
353 function(producto) { 363 function(producto) {
354 var newArt = 364 var newArt =
355 { 365 {
356 id: 0, 366 id: 0,
357 codigo: producto.codigo, 367 codigo: producto.codigo,
358 sector: producto.sector, 368 sector: producto.sector,
359 sectorCodigo: producto.sector + '-' + producto.codigo, 369 sectorCodigo: producto.sector + '-' + producto.codigo,
360 descripcion: producto.descripcion, 370 descripcion: producto.descripcion,
361 item: $scope.articulosTabla.length + 1, 371 item: $scope.articulosTabla.length + 1,
362 nombre: producto.descripcion, 372 nombre: producto.descripcion,
363 precio: parseFloat(producto.precio.toFixed(4)), 373 precio: parseFloat(producto.precio.toFixed(4)),
364 costoUnitario: producto.costo, 374 costoUnitario: producto.costo,
365 editCantidad: false, 375 editCantidad: false,
366 editPrecio: false, 376 editPrecio: false,
367 rubro: producto.CodRub, 377 rubro: producto.CodRub,
368 exentoUnitario: producto.precio, 378 exentoUnitario: producto.precio,
369 ivaUnitario: producto.IMPIVA, 379 ivaUnitario: producto.IMPIVA,
370 impuestoInternoUnitario: producto.ImpInt, 380 impuestoInternoUnitario: producto.ImpInt,
371 impuestoInterno1Unitario: producto.ImpInt2, 381 impuestoInterno1Unitario: producto.ImpInt2,
372 impuestoInterno2Unitario: producto.ImpInt3, 382 impuestoInterno2Unitario: producto.ImpInt3,
373 precioLista: producto.precio, 383 precioLista: producto.precio,
374 combustible: 1, 384 combustible: 1,
375 facturado: 0 385 facturado: 0
376 }; 386 };
377 $scope.articuloACargar = newArt; 387 $scope.articuloACargar = newArt;
378 $scope.cargando = false; 388 $scope.cargando = false;
379 }, function() { 389 }, function() {
380 // funcion ejecutada cuando se cancela el modal 390 // funcion ejecutada cuando se cancela el modal
381 } 391 }
382 ); 392 );
383 }; 393 };
384 394
385 $scope.seleccionarVendedor = function() { 395 $scope.seleccionarVendedor = function() {
386 var modalInstance = $uibModal.open( 396 var modalInstance = $uibModal.open(
387 { 397 {
388 ariaLabelledBy: 'Busqueda de Vendedores', 398 ariaLabelledBy: 'Busqueda de Vendedores',
389 templateUrl: 'modal-vendedores.html', 399 templateUrl: 'modal-vendedores.html',
390 controller: 'modalVendedoresCtrl', 400 controller: 'modalVendedoresCtrl',
391 size: 'lg' 401 size: 'lg'
392 } 402 }
393 ); 403 );
394 modalInstance.result.then( 404 modalInstance.result.then(
395 function(vendedor) { 405 function(vendedor) {
396 addCabecera('Vendedor:', vendedor.NomVen); 406 addCabecera('Vendedor:', vendedor.NomVen);
397 $scope.notaPedido.vendedor = vendedor; 407 $scope.notaPedido.vendedor = vendedor;
398 }, function() { 408 }, function() {
399 409
400 } 410 }
401 ); 411 );
402 }; 412 };
403 413
404 $scope.seleccionarProveedor = function() { 414 $scope.seleccionarProveedor = function() {
405 var modalInstance = $uibModal.open( 415 var modalInstance = $uibModal.open(
406 { 416 {
407 ariaLabelledBy: 'Busqueda de Proveedor', 417 ariaLabelledBy: 'Busqueda de Proveedor',
408 templateUrl: 'modal-proveedor.html', 418 templateUrl: 'modal-proveedor.html',
409 controller: 'focaModalProveedorCtrl', 419 controller: 'focaModalProveedorCtrl',
410 size: 'lg', 420 size: 'lg',
411 resolve: { 421 resolve: {
412 transportista: function() { 422 transportista: function() {
413 return false; 423 return false;
414 } 424 }
415 } 425 }
416 } 426 }
417 ); 427 );
418 modalInstance.result.then( 428 modalInstance.result.then(
419 function(proveedor) { 429 function(proveedor) {
420 $scope.notaPedido.proveedor = proveedor; 430 $scope.notaPedido.proveedor = proveedor;
421 addCabecera('Proveedor:', proveedor.NOM); 431 addCabecera('Proveedor:', proveedor.NOM);
422 }, function() { 432 }, function() {
423 433
424 } 434 }
425 ); 435 );
426 }; 436 };
427 437
428 $scope.seleccionarCliente = function() { 438 $scope.seleccionarCliente = function() {
429 439
430 var modalInstance = $uibModal.open( 440 var modalInstance = $uibModal.open(
431 { 441 {
432 ariaLabelledBy: 'Busqueda de Cliente', 442 ariaLabelledBy: 'Busqueda de Cliente',
433 templateUrl: 'foca-busqueda-cliente-modal.html', 443 templateUrl: 'foca-busqueda-cliente-modal.html',
434 controller: 'focaBusquedaClienteModalController', 444 controller: 'focaBusquedaClienteModalController',
435 size: 'lg' 445 size: 'lg'
436 } 446 }
437 ); 447 );
438 modalInstance.result.then( 448 modalInstance.result.then(
439 function(cliente) { 449 function(cliente) {
440 $scope.abrirModalDomicilios(cliente); 450 $scope.abrirModalDomicilios(cliente);
441 }, function() { 451 }, function() {
442 452
443 } 453 }
444 ); 454 );
445 }; 455 };
446 456
447 $scope.abrirModalDomicilios = function(cliente) { 457 $scope.abrirModalDomicilios = function(cliente) {
448 var modalInstanceDomicilio = $uibModal.open( 458 var modalInstanceDomicilio = $uibModal.open(
449 { 459 {
450 ariaLabelledBy: 'Busqueda de Domicilios', 460 ariaLabelledBy: 'Busqueda de Domicilios',
451 templateUrl: 'modal-domicilio.html', 461 templateUrl: 'modal-domicilio.html',
452 controller: 'focaModalDomicilioController', 462 controller: 'focaModalDomicilioController',
453 resolve: { idCliente: function() { return cliente.cod; }}, 463 resolve: { idCliente: function() { return cliente.cod; }},
454 size: 'lg', 464 size: 'lg',
455 } 465 }
456 ); 466 );
457 modalInstanceDomicilio.result.then( 467 modalInstanceDomicilio.result.then(
458 function(domicilio) { 468 function(domicilio) {
459 $scope.notaPedido.domicilio = domicilio; 469 $scope.notaPedido.domicilio = domicilio;
460 $scope.notaPedido.cliente = { 470 $scope.notaPedido.cliente = {
461 COD: cliente.cod, 471 COD: cliente.cod,
462 CUIT: cliente.cuit, 472 CUIT: cliente.cuit,
463 NOM: cliente.nom 473 NOM: cliente.nom
464 }; 474 };
465 addCabecera('Cliente:', cliente.nom); 475 addCabecera('Cliente:', cliente.nom);
466 var domicilioStamp = 476 var domicilioStamp =
467 domicilio.Calle + ' ' + domicilio.Numero + ', ' + 477 domicilio.Calle + ' ' + domicilio.Numero + ', ' +
468 domicilio.Localidad + ', ' + domicilio.Provincia; 478 domicilio.Localidad + ', ' + domicilio.Provincia;
469 $scope.notaPedido.domicilioStamp = domicilioStamp; 479 $scope.notaPedido.domicilioStamp = domicilioStamp;
470 addCabecera('Domicilio:', domicilioStamp); 480 addCabecera('Domicilio:', domicilioStamp);
471 }, function() { 481 }, function() {
472 $scope.seleccionarCliente(); 482 $scope.seleccionarCliente();
473 return; 483 return;
474 } 484 }
475 ); 485 );
476 }; 486 };
477 487
478 $scope.mostrarFichaCliente = function() { 488 $scope.mostrarFichaCliente = function() {
479 $uibModal.open( 489 $uibModal.open(
480 { 490 {
481 ariaLabelledBy: 'Datos del Cliente', 491 ariaLabelledBy: 'Datos del Cliente',
482 templateUrl: 'foca-crear-nota-pedido-ficha-cliente.html', 492 templateUrl: 'foca-crear-nota-pedido-ficha-cliente.html',
483 controller: 'focaCrearNotaPedidoFichaClienteController', 493 controller: 'focaCrearNotaPedidoFichaClienteController',
484 size: 'lg' 494 size: 'lg'
485 } 495 }
486 ); 496 );
487 }; 497 };
488 498
489 $scope.getTotal = function() { 499 $scope.getTotal = function() {
490 var total = 0; 500 var total = 0;
491 var arrayTempArticulos = $scope.articulosTabla; 501 var arrayTempArticulos = $scope.articulosTabla;
492 for (var i = 0; i < arrayTempArticulos.length; i++) { 502 for (var i = 0; i < arrayTempArticulos.length; i++) {
493 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; 503 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad;
494 } 504 }
495 return parseFloat(total.toFixed(2)); 505 return parseFloat(total.toFixed(2));
496 }; 506 };
497 507
498 $scope.getSubTotal = function() { 508 $scope.getSubTotal = function() {
499 if($scope.articuloACargar) { 509 if($scope.articuloACargar) {
500 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; 510 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
501 } 511 }
502 }; 512 };
503 513
504 $scope.abrirModalListaPrecio = function() { 514 $scope.abrirModalListaPrecio = function() {
505 var modalInstance = $uibModal.open( 515 var modalInstance = $uibModal.open(
506 { 516 {
507 ariaLabelledBy: 'Busqueda de Precio Condición', 517 ariaLabelledBy: 'Busqueda de Precio Condición',
508 templateUrl: 'modal-precio-condicion.html', 518 templateUrl: 'modal-precio-condicion.html',
509 controller: 'focaModalPrecioCondicionController', 519 controller: 'focaModalPrecioCondicionController',
510 size: 'lg' 520 size: 'lg'
511 } 521 }
512 ); 522 );
513 modalInstance.result.then( 523 modalInstance.result.then(
514 function(precioCondicion) { 524 function(precioCondicion) {
515 var cabecera = ''; 525 var cabecera = '';
516 var plazosConcat = ''; 526 var plazosConcat = '';
517 if(!Array.isArray(precioCondicion)) { 527 if(!Array.isArray(precioCondicion)) {
518 $scope.notaPedido.idPrecioCondicion = precioCondicion.id; 528 $scope.notaPedido.idPrecioCondicion = precioCondicion.id;
519 $scope.plazosPagos = precioCondicion.plazoPago; 529 $scope.plazosPagos = precioCondicion.plazoPago;
520 $scope.idLista = precioCondicion.idListaPrecio; 530 $scope.idLista = precioCondicion.idListaPrecio;
521 for(var i = 0; i < precioCondicion.plazoPago.length; i++) { 531 for(var i = 0; i < precioCondicion.plazoPago.length; i++) {
522 plazosConcat += precioCondicion.plazoPago[i].dias + ' '; 532 plazosConcat += precioCondicion.plazoPago[i].dias + ' ';
523 } 533 }
524 cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); 534 cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim();
525 } else { //Cuando se ingresan los plazos manualmente 535 } else { //Cuando se ingresan los plazos manualmente
526 $scope.notaPedido.idPrecioCondicion = 0; 536 $scope.notaPedido.idPrecioCondicion = 0;
527 $scope.idLista = -1; //-1, el modal productos busca todos los productos 537 $scope.idLista = -1; //-1, el modal productos busca todos los productos
528 $scope.plazosPagos = precioCondicion; 538 $scope.plazosPagos = precioCondicion;
529 for(var j = 0; j < precioCondicion.length; j++) { 539 for(var j = 0; j < precioCondicion.length; j++) {
530 plazosConcat += precioCondicion[j].dias + ' '; 540 plazosConcat += precioCondicion[j].dias + ' ';
531 } 541 }
532 cabecera = 'Ingreso manual ' + plazosConcat.trim(); 542 cabecera = 'Ingreso manual ' + plazosConcat.trim();
533 } 543 }
534 $scope.articulosTabla = []; 544 $scope.articulosTabla = [];
535 addCabecera('Precios y condiciones:', cabecera); 545 addCabecera('Precios y condiciones:', cabecera);
536 }, function() { 546 }, function() {
537 547
538 } 548 }
539 ); 549 );
540 }; 550 };
541 551
542 $scope.abrirModalFlete = function() { 552 $scope.abrirModalFlete = function() {
543 var modalInstance = $uibModal.open( 553 var modalInstance = $uibModal.open(
544 { 554 {
545 ariaLabelledBy: 'Busqueda de Flete', 555 ariaLabelledBy: 'Busqueda de Flete',
546 templateUrl: 'modal-flete.html', 556 templateUrl: 'modal-flete.html',
547 controller: 'focaModalFleteController', 557 controller: 'focaModalFleteController',
548 size: 'lg', 558 size: 'lg',
549 resolve: { 559 resolve: {
550 parametrosFlete: 560 parametrosFlete:
551 function() { 561 function() {
552 return { 562 return {
553 flete: $scope.notaPedido.flete ? '1' : 563 flete: $scope.notaPedido.flete ? '1' :
554 ($scope.notaPedido.fob ? 'FOB' : 564 ($scope.notaPedido.fob ? 'FOB' :
555 ($scope.notaPedido.flete === undefined ? null : '0')), 565 ($scope.notaPedido.flete === undefined ? null : '0')),
556 bomba: $scope.notaPedido.bomba ? '1' : 566 bomba: $scope.notaPedido.bomba ? '1' :
557 ($scope.notaPedido.bomba === undefined ? null : '0'), 567 ($scope.notaPedido.bomba === undefined ? null : '0'),
558 kilometros: $scope.notaPedido.kilometros 568 kilometros: $scope.notaPedido.kilometros
559 }; 569 };
560 } 570 }
561 } 571 }
562 } 572 }
563 ); 573 );
564 modalInstance.result.then( 574 modalInstance.result.then(
565 function(datos) { 575 function(datos) {
566 $scope.notaPedido.flete = datos.flete; 576 $scope.notaPedido.flete = datos.flete;
567 $scope.notaPedido.fob = datos.FOB; 577 $scope.notaPedido.fob = datos.FOB;
568 $scope.notaPedido.bomba = datos.bomba; 578 $scope.notaPedido.bomba = datos.bomba;
569 $scope.notaPedido.kilometros = datos.kilometros; 579 $scope.notaPedido.kilometros = datos.kilometros;
570 580
571 addCabecera('Flete:', datos.flete ? 'Si' : 581 addCabecera('Flete:', datos.flete ? 'Si' :
572 ($scope.notaPedido.fob ? 'FOB' : 'No')); 582 ($scope.notaPedido.fob ? 'FOB' : 'No'));
573 if(datos.flete) { 583 if(datos.flete) {
574 addCabecera('Bomba:', datos.bomba ? 'Si' : 'No'); 584 addCabecera('Bomba:', datos.bomba ? 'Si' : 'No');
575 addCabecera('Kilometros:', datos.kilometros); 585 addCabecera('Kilometros:', datos.kilometros);
576 } else { 586 } else {
577 removeCabecera('Bomba:'); 587 removeCabecera('Bomba:');
578 removeCabecera('Kilometros:'); 588 removeCabecera('Kilometros:');
579 $scope.notaPedido.fob = false; 589 $scope.notaPedido.fob = false;
580 $scope.notaPedido.bomba = false; 590 $scope.notaPedido.bomba = false;
581 $scope.notaPedido.kilometros = null; 591 $scope.notaPedido.kilometros = null;
582 } 592 }
583 }, function() { 593 }, function() {
584 594
585 } 595 }
586 ); 596 );
587 }; 597 };
588 598
589 $scope.abrirModalMoneda = function() { 599 $scope.abrirModalMoneda = function() {
590 var modalInstance = $uibModal.open( 600 var modalInstance = $uibModal.open(
591 { 601 {
592 ariaLabelledBy: 'Busqueda de Moneda', 602 ariaLabelledBy: 'Busqueda de Moneda',
593 templateUrl: 'modal-moneda.html', 603 templateUrl: 'modal-moneda.html',
594 controller: 'focaModalMonedaController', 604 controller: 'focaModalMonedaController',
595 size: 'lg' 605 size: 'lg'
596 } 606 }
597 ); 607 );
598 modalInstance.result.then( 608 modalInstance.result.then(
599 function(moneda) { 609 function(moneda) {
600 $scope.abrirModalCotizacion(moneda); 610 $scope.abrirModalCotizacion(moneda);
601 }, function() { 611 }, function() {
602 612
603 } 613 }
604 ); 614 );
605 }; 615 };
606 616
607 $scope.abrirModalCotizacion = function(moneda) { 617 $scope.abrirModalCotizacion = function(moneda) {
608 var modalInstance = $uibModal.open( 618 var modalInstance = $uibModal.open(
609 { 619 {
610 ariaLabelledBy: 'Busqueda de Cotización', 620 ariaLabelledBy: 'Busqueda de Cotización',
611 templateUrl: 'modal-cotizacion.html', 621 templateUrl: 'modal-cotizacion.html',
612 controller: 'focaModalCotizacionController', 622 controller: 'focaModalCotizacionController',
613 size: 'lg', 623 size: 'lg',
614 resolve: {idMoneda: function() {return moneda.ID;}} 624 resolve: {idMoneda: function() {return moneda.ID;}}
615 } 625 }
616 ); 626 );
617 modalInstance.result.then( 627 modalInstance.result.then(
618 function(cotizacion) { 628 function(cotizacion) {
619 var articulosTablaTemp = $scope.articulosTabla; 629 var articulosTablaTemp = $scope.articulosTabla;
620 for(var i = 0; i < articulosTablaTemp.length; i++) { 630 for(var i = 0; i < articulosTablaTemp.length; i++) {
621 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * 631 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio *
622 $scope.notaPedido.cotizacion.VENDEDOR; 632 $scope.notaPedido.cotizacion.VENDEDOR;
623 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / 633 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio /
624 cotizacion.VENDEDOR; 634 cotizacion.VENDEDOR;
625 } 635 }
626 $scope.articulosTabla = articulosTablaTemp; 636 $scope.articulosTabla = articulosTablaTemp;
627 $scope.notaPedido.moneda = moneda; 637 $scope.notaPedido.moneda = moneda;
628 $scope.notaPedido.cotizacion = cotizacion; 638 $scope.notaPedido.cotizacion = cotizacion;
629 addCabecera('Moneda:', moneda.DETALLE); 639 addCabecera('Moneda:', moneda.DETALLE);
630 addCabecera( 640 addCabecera(
631 'Fecha cotizacion:', 641 'Fecha cotizacion:',
632 $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 642 $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
633 ); 643 );
634 addCabecera('Cotizacion:', cotizacion.VENDEDOR); 644 addCabecera('Cotizacion:', cotizacion.VENDEDOR);
635 }, function() { 645 }, function() {
636 646
637 } 647 }
638 ); 648 );
639 }; 649 };
640 650
641 $scope.agregarATabla = function(key) { 651 $scope.agregarATabla = function(key) {
642 if(key === 13) { 652 if(key === 13) {
643 if($scope.articuloACargar.cantidad === undefined || 653 if($scope.articuloACargar.cantidad === undefined ||
644 $scope.articuloACargar.cantidad === 0 || 654 $scope.articuloACargar.cantidad === 0 ||
645 $scope.articuloACargar.cantidad === null ) { 655 $scope.articuloACargar.cantidad === null ) {
646 focaModalService.alert('El valor debe ser al menos 1'); 656 focaModalService.alert('El valor debe ser al menos 1');
647 return; 657 return;
648 } 658 }
649 delete $scope.articuloACargar.sectorCodigo; 659 delete $scope.articuloACargar.sectorCodigo;
650 $scope.articulosTabla.push($scope.articuloACargar); 660 $scope.articulosTabla.push($scope.articuloACargar);
651 $scope.cargando = true; 661 $scope.cargando = true;
652 } 662 }
653 }; 663 };
654 664
655 $scope.quitarArticulo = function(key) { 665 $scope.quitarArticulo = function(key) {
656 $scope.articulosTabla.splice(key, 1); 666 $scope.articulosTabla.splice(key, 1);
657 }; 667 };
658 668
659 $scope.editarArticulo = function(key, articulo) { 669 $scope.editarArticulo = function(key, articulo) {
660 if(key === 13) { 670 if(key === 13) {
661 if(articulo.cantidad === null || articulo.cantidad === 0 || 671 if(articulo.cantidad === null || articulo.cantidad === 0 ||
662 articulo.cantidad === undefined) { 672 articulo.cantidad === undefined) {
663 focaModalService.alert('El valor debe ser al menos 1'); 673 focaModalService.alert('El valor debe ser al menos 1');
664 return; 674 return;
665 } 675 }
666 articulo.editCantidad = false; 676 articulo.editCantidad = false;
667 articulo.editPrecio = false; 677 articulo.editPrecio = false;
668 } 678 }
669 }; 679 };
670 680
671 $scope.cambioEdit = function(articulo, propiedad) { 681 $scope.cambioEdit = function(articulo, propiedad) {
672 if(propiedad === 'cantidad') { 682 if(propiedad === 'cantidad') {
673 articulo.editCantidad = true; 683 articulo.editCantidad = true;
674 } else if(propiedad === 'precio') { 684 } else if(propiedad === 'precio') {
675 articulo.editPrecio = true; 685 articulo.editPrecio = true;
676 } 686 }
677 }; 687 };
678 688
679 $scope.limpiarFlete = function() { 689 $scope.limpiarFlete = function() {
680 $scope.notaPedido.fleteNombre = ''; 690 $scope.notaPedido.fleteNombre = '';
681 $scope.notaPedido.chofer = ''; 691 $scope.notaPedido.chofer = '';
682 $scope.notaPedido.vehiculo = ''; 692 $scope.notaPedido.vehiculo = '';
683 $scope.notaPedido.kilometros = ''; 693 $scope.notaPedido.kilometros = '';
684 $scope.notaPedido.costoUnitarioKmFlete = ''; 694 $scope.notaPedido.costoUnitarioKmFlete = '';
685 $scope.choferes = ''; 695 $scope.choferes = '';
686 $scope.vehiculos = ''; 696 $scope.vehiculos = '';
687 }; 697 };
688 698
689 $scope.limpiarPantalla = function() { 699 $scope.limpiarPantalla = function() {
690 $scope.limpiarFlete(); 700 $scope.limpiarFlete();
691 $scope.notaPedido.flete = '0'; 701 $scope.notaPedido.flete = '0';
692 $scope.notaPedido.bomba = '0'; 702 $scope.notaPedido.bomba = '0';
693 $scope.notaPedido.precioCondicion = ''; 703 $scope.notaPedido.precioCondicion = '';
694 $scope.articulosTabla = []; 704 $scope.articulosTabla = [];
695 $scope.notaPedido.vendedor.nombre = ''; 705 $scope.notaPedido.vendedor.nombre = '';
696 $scope.notaPedido.cliente = {nombre: ''}; 706 $scope.notaPedido.cliente = {nombre: ''};
697 $scope.notaPedido.domicilio = {dom: ''}; 707 $scope.notaPedido.domicilio = {dom: ''};
698 $scope.domiciliosCliente = []; 708 $scope.domiciliosCliente = [];
699 }; 709 };
700 710
701 $scope.resetFilter = function() { 711 $scope.resetFilter = function() {
702 $scope.articuloACargar = {}; 712 $scope.articuloACargar = {};
703 $scope.cargando = true; 713 $scope.cargando = true;
704 }; 714 };
705 //Recibe aviso si el teclado está en uso 715 //Recibe aviso si el teclado está en uso
706 $rootScope.$on('usarTeclado', function(event, data) { 716 $rootScope.$on('usarTeclado', function(event, data) {
707 if(data) { 717 if(data) {
708 $scope.mostrarTeclado = true; 718 $scope.mostrarTeclado = true;
709 return; 719 return;
710 } 720 }
711 $scope.mostrarTeclado = false; 721 $scope.mostrarTeclado = false;
712 }); 722 });
713 723
714 $scope.selectFocus = function($event) { 724 $scope.selectFocus = function($event) {
715 // Si el teclado esta en uso no selecciona el valor 725 // Si el teclado esta en uso no selecciona el valor
716 if($scope.mostrarTeclado) { 726 if($scope.mostrarTeclado) {
717 return; 727 return;
718 } 728 }
719 $event.target.select(); 729 $event.target.select();
720 }; 730 };
721 731
722 $scope.salir = function() { 732 $scope.salir = function() {
723 $location.path('/'); 733 $location.path('/');
724 }; 734 };
725 735
726 $scope.parsearATexto = function(articulo) { 736 $scope.parsearATexto = function(articulo) {
727 articulo.cantidad = parseFloat(articulo.cantidad); 737 articulo.cantidad = parseFloat(articulo.cantidad);
728 articulo.precio = parseFloat(articulo.precio); 738 articulo.precio = parseFloat(articulo.precio);
729 }; 739 };
730 740
731 function addArrayCabecera(array) { 741 function addArrayCabecera(array) {
732 for(var i = 0; i < array.length; i++) { 742 for(var i = 0; i < array.length; i++) {
733 addCabecera(array[i].label, array[i].valor); 743 addCabecera(array[i].label, array[i].valor);
734 } 744 }
735 } 745 }
736 746
737 function addCabecera(label, valor) { 747 function addCabecera(label, valor) {
738 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); 748 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true);
739 if(propiedad.length === 1) { 749 if(propiedad.length === 1) {
740 propiedad[0].valor = valor; 750 propiedad[0].valor = valor;
741 } else { 751 } else {
742 $scope.cabecera.push({label: label, valor: valor}); 752 $scope.cabecera.push({label: label, valor: valor});
743 } 753 }
744 } 754 }
745 755
746 function removeCabecera(label) { 756 function removeCabecera(label) {
747 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); 757 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true);
748 if(propiedad.length === 1) { 758 if(propiedad.length === 1) {
749 $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); 759 $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1);
750 } 760 }
751 } 761 }
752 762
753 function rellenar(relleno, longitud) { 763 function rellenar(relleno, longitud) {
754 relleno = '' + relleno; 764 relleno = '' + relleno;
755 while (relleno.length < longitud) { 765 while (relleno.length < longitud) {
756 relleno = '0' + relleno; 766 relleno = '0' + relleno;
757 } 767 }
758 768
759 return relleno; 769 return relleno;
760 } 770 }
761 771
762 function validarNotaRemitada(funcion) { 772 function validarNotaRemitada(funcion) {
763 if($scope.notaPedido.idRemito) { 773 if($scope.notaPedido.idRemito) {
764 focaModalService.alert('No se puede editar una nota de pedido remitada'); 774 focaModalService.alert('No se puede editar una nota de pedido remitada');
765 } 775 }
766 else { 776 else {
767 funcion(); 777 funcion();
768 } 778 }
769 } 779 }
770 } 780 }
771 ] 781 ]
772 ) 782 )
773 .controller('notaPedidoListaCtrl', [ 783 .controller('notaPedidoListaCtrl', [
774 '$scope', 784 '$scope',
775 'crearNotaPedidoService', 785 'crearNotaPedidoService',
776 '$location', 786 '$location',
777 function($scope, crearNotaPedidoService, $location) { 787 function($scope, crearNotaPedidoService, $location) {
778 crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { 788 crearNotaPedidoService.obtenerNotaPedido().then(function(datos) {
779 $scope.notaPedidos = datos.data; 789 $scope.notaPedidos = datos.data;
780 }); 790 });
781 $scope.editar = function(notaPedido) { 791 $scope.editar = function(notaPedido) {
782 crearNotaPedidoService.setNotaPedido(notaPedido); 792 crearNotaPedidoService.setNotaPedido(notaPedido);
783 $location.path('/venta-nota-pedido/abm/'); 793 $location.path('/venta-nota-pedido/abm/');
784 }; 794 };
785 $scope.crearPedido = function() { 795 $scope.crearPedido = function() {
786 crearNotaPedidoService.clearNotaPedido(); 796 crearNotaPedidoService.clearNotaPedido();
787 $location.path('/venta-nota-pedido/abm/'); 797 $location.path('/venta-nota-pedido/abm/');
788 }; 798 };
789 } 799 }
790 ]) 800 ])
791 .controller('focaCrearNotaPedidoFichaClienteController', [ 801 .controller('focaCrearNotaPedidoFichaClienteController', [
792 '$scope', 802 '$scope',
793 'crearNotaPedidoService', 803 'crearNotaPedidoService',
794 '$location', 804 '$location',
795 function($scope, crearNotaPedidoService, $location) { 805 function($scope, crearNotaPedidoService, $location) {
796 crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { 806 crearNotaPedidoService.obtenerNotaPedido().then(function(datos) {
797 $scope.notaPedidos = datos.data; 807 $scope.notaPedidos = datos.data;
798 }); 808 });
799 $scope.editar = function(notaPedido) { 809 $scope.editar = function(notaPedido) {
800 crearNotaPedidoService.setNotaPedido(notaPedido); 810 crearNotaPedidoService.setNotaPedido(notaPedido);
801 $location.path('/venta-nota-pedido/abm/'); 811 $location.path('/venta-nota-pedido/abm/');
802 }; 812 };
803 $scope.crearPedido = function() { 813 $scope.crearPedido = function() {
804 crearNotaPedidoService.clearNotaPedido(); 814 crearNotaPedidoService.clearNotaPedido();
805 $location.path('/venta-nota-pedido/abm/'); 815 $location.path('/venta-nota-pedido/abm/');
806 }; 816 };
807 } 817 }
808 ]); 818 ]);
809 819