Commit 74023cc5f02663a11987e47b54d62114c4689549

Authored by Eric Fernandez
1 parent 31c01a8a66
Exists in master

muestro en cabecera flete

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