Commit 4c6c3994baa05fa857f225f9cc48214d994b3219

Authored by Eric Fernandez
1 parent b9d8b31449
Exists in master

código basura, muestro plazos

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