Commit ab0f5bfabe2230160bfd22ba7ac06a3664ac0cae

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'master'

Master (pmarco)

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