Commit 6f4cb42abad704756d9514510aa8bf0004aae838

Authored by Eric Fernandez
1 parent 4cb41e811c
Exists in master

nuevo resolve modalNotaPedido

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