Commit df6fe070eaa4fe230dab3d70a5e2bdcfc945cb32

Authored by Nicolás Guarnieri
1 parent 287af29b09
Exists in master

obtener sucursal y numero de pedido

Showing 1 changed file with 8 additions and 0 deletions   Show diff stats
src/js/controller.js
1 angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', 1 angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
2 [ 2 [
3 '$scope', '$uibModal', '$location', '$filter', 'crearNotaPedidoService', 3 '$scope', '$uibModal', '$location', '$filter', 'crearNotaPedidoService',
4 'focaModalService', 'focaSeguimientoService', 'notaPedidoBusinessService', 4 'focaModalService', 'focaSeguimientoService', 'notaPedidoBusinessService',
5 function( 5 function(
6 $scope, $uibModal, $location, $filter, crearNotaPedidoService, focaModalService, 6 $scope, $uibModal, $location, $filter, crearNotaPedidoService, focaModalService,
7 focaSeguimientoService, notaPedidoBusinessService 7 focaSeguimientoService, notaPedidoBusinessService
8 ) { 8 ) {
9 $scope.botonera = [ 9 $scope.botonera = [
10 {texto: 'Vendedor', accion: function() {$scope.seleccionarVendedor();}}, 10 {texto: 'Vendedor', accion: function() {$scope.seleccionarVendedor();}},
11 {texto: 'Cliente', accion: function() {$scope.seleccionarCliente();}}, 11 {texto: 'Cliente', accion: function() {$scope.seleccionarCliente();}},
12 {texto: 'Proveedor', accion: function() {$scope.seleccionarProveedor();}}, 12 {texto: 'Proveedor', accion: function() {$scope.seleccionarProveedor();}},
13 {texto: 'Moneda', accion: function() {$scope.abrirModalMoneda();}}, 13 {texto: 'Moneda', accion: function() {$scope.abrirModalMoneda();}},
14 { 14 {
15 texto: 'Precios y condiciones', 15 texto: 'Precios y condiciones',
16 accion: function() {$scope.abrirModalListaPrecio();}}, 16 accion: function() {$scope.abrirModalListaPrecio();}},
17 {texto: 'Flete', accion: function() {$scope.abrirModalFlete();}}, 17 {texto: 'Flete', accion: function() {$scope.abrirModalFlete();}},
18 {texto: '', accion: function() {}}, 18 {texto: '', accion: function() {}},
19 {texto: '', accion: function() {}} 19 {texto: '', accion: function() {}}
20 ]; 20 ];
21 $scope.datepickerAbierto = false; 21 $scope.datepickerAbierto = false;
22 22
23 $scope.show = false; 23 $scope.show = false;
24 $scope.cargando = true; 24 $scope.cargando = true;
25 $scope.dateOptions = { 25 $scope.dateOptions = {
26 maxDate: new Date(), 26 maxDate: new Date(),
27 minDate: new Date(2010, 0, 1) 27 minDate: new Date(2010, 0, 1)
28 }; 28 };
29 29
30 $scope.notaPedido = { 30 $scope.notaPedido = {
31 vendedor: {}, 31 vendedor: {},
32 cliente: {}, 32 cliente: {},
33 proveedor: {}, 33 proveedor: {},
34 domicilio: {dom: ''}, 34 domicilio: {dom: ''},
35 moneda: {}, 35 moneda: {},
36 cotizacion: {} 36 cotizacion: {}
37 }; 37 };
38 var monedaPorDefecto; 38 var monedaPorDefecto;
39 //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' 39 //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]'
40 crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { 40 crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) {
41 monedaPorDefecto = { 41 monedaPorDefecto = {
42 id: res.data[0].ID, 42 id: res.data[0].ID,
43 detalle: res.data[0].DETALLE, 43 detalle: res.data[0].DETALLE,
44 simbolo: res.data[0].SIMBOLO, 44 simbolo: res.data[0].SIMBOLO,
45 cotizaciones: res.data[0].cotizaciones 45 cotizaciones: res.data[0].cotizaciones
46 }; 46 };
47 addCabecera('Moneda:', monedaPorDefecto.detalle); 47 addCabecera('Moneda:', monedaPorDefecto.detalle);
48 addCabecera('Fecha cotizacion:', 48 addCabecera('Fecha cotizacion:',
49 new Date(monedaPorDefecto.cotizaciones[0].FECHA).toLocaleDateString()); 49 new Date(monedaPorDefecto.cotizaciones[0].FECHA).toLocaleDateString());
50 addCabecera('Cotizacion:', monedaPorDefecto.cotizaciones[0].COTIZACION); 50 addCabecera('Cotizacion:', monedaPorDefecto.cotizaciones[0].COTIZACION);
51 $scope.notaPedido.moneda = monedaPorDefecto; 51 $scope.notaPedido.moneda = monedaPorDefecto;
52 $scope.notaPedido.cotizacion = monedaPorDefecto.cotizaciones[0]; 52 $scope.notaPedido.cotizacion = monedaPorDefecto.cotizaciones[0];
53 }); 53 });
54 54
55 $scope.cabecera = []; 55 $scope.cabecera = [];
56 $scope.showCabecera = true; 56 $scope.showCabecera = true;
57 57
58 $scope.now = new Date(); 58 $scope.now = new Date();
59 $scope.puntoVenta = '0000'; 59 $scope.puntoVenta = '0000';
60 $scope.comprobante = '00000000'; 60 $scope.comprobante = '00000000';
61 $scope.articulosTabla = []; 61 $scope.articulosTabla = [];
62 $scope.idLista = undefined; 62 $scope.idLista = undefined;
63 //La pantalla solo se usa para cargar pedidos 63 //La pantalla solo se usa para cargar pedidos
64 //var notaPedidoTemp = crearNotaPedidoService.getNotaPedido(); 64 //var notaPedidoTemp = crearNotaPedidoService.getNotaPedido();
65 65
66 crearNotaPedidoService.getPrecioCondicion().then( 66 crearNotaPedidoService.getPrecioCondicion().then(
67 function(res) { 67 function(res) {
68 $scope.precioCondiciones = res.data; 68 $scope.precioCondiciones = res.data;
69 } 69 }
70 ); 70 );
71 71
72 crearNotaPedidoService.getNumeroNotaPedido().then( 72 crearNotaPedidoService.getNumeroNotaPedido().then(
73 function(res) { 73 function(res) {
74 $scope.puntoVenta = rellenar(res.data.sucursal, 4); 74 $scope.puntoVenta = rellenar(res.data.sucursal, 4);
75 $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); 75 $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8);
76 },
77 function(err) {
78 focaModalService.alert('La terminal no esta configurada correctamente');
79 console.info(err);
76 } 80 }
77 ); 81 );
78 //La pantalla solo se usa para cargar pedidos 82 //La pantalla solo se usa para cargar pedidos
79 // if (notaPedidoTemp !== undefined) { 83 // if (notaPedidoTemp !== undefined) {
80 // notaPedidoTemp.fechaCarga = new Date(notaPedidoTemp.fechaCarga); 84 // notaPedidoTemp.fechaCarga = new Date(notaPedidoTemp.fechaCarga);
81 // $scope.notaPedido = notaPedidoTemp; 85 // $scope.notaPedido = notaPedidoTemp;
82 // $scope.notaPedido.flete = ($scope.notaPedido.flete).toString(); 86 // $scope.notaPedido.flete = ($scope.notaPedido.flete).toString();
83 // $scope.notaPedido.bomba = ($scope.notaPedido.bomba).toString(); 87 // $scope.notaPedido.bomba = ($scope.notaPedido.bomba).toString();
84 // $scope.idLista = $scope.notaPedido.precioCondicion; 88 // $scope.idLista = $scope.notaPedido.precioCondicion;
85 // crearNotaPedidoService 89 // crearNotaPedidoService
86 // .getArticulosByIdNotaPedido($scope.notaPedido.id).then( 90 // .getArticulosByIdNotaPedido($scope.notaPedido.id).then(
87 // function(res) { 91 // function(res) {
88 // $scope.articulosTabla = res.data; 92 // $scope.articulosTabla = res.data;
89 // } 93 // }
90 // ); 94 // );
91 //TODO DOMICILIOS QUE SE CARGAN AL EDITAR NOTA DE PEDIDO 95 //TODO DOMICILIOS QUE SE CARGAN AL EDITAR NOTA DE PEDIDO
92 //(NO REQUERIDO EN ESTA VERSION) 96 //(NO REQUERIDO EN ESTA VERSION)
93 // crearNotaPedidoService.getDomiciliosByIdNotaPedido($scope.notaPedido.id).then( 97 // crearNotaPedidoService.getDomiciliosByIdNotaPedido($scope.notaPedido.id).then(
94 // function(res) { 98 // function(res) {
95 // $scope.notaPedido.domicilio = res.data; 99 // $scope.notaPedido.domicilio = res.data;
96 // } 100 // }
97 // ); 101 // );
98 // } else { 102 // } else {
99 // $scope.notaPedido.fechaCarga = new Date(); 103 // $scope.notaPedido.fechaCarga = new Date();
100 // $scope.notaPedido.bomba = '0'; 104 // $scope.notaPedido.bomba = '0';
101 // $scope.notaPedido.flete = '0'; 105 // $scope.notaPedido.flete = '0';
102 // $scope.idLista = undefined; 106 // $scope.idLista = undefined;
103 // } 107 // }
104 //TO DO - FUNCIONES PARA MULTIPLES DOMICILIOS NO IMPLEMENTADAS EN ESTA DEMO 108 //TO DO - FUNCIONES PARA MULTIPLES DOMICILIOS NO IMPLEMENTADAS EN ESTA DEMO
105 // $scope.addNewDom = function() { 109 // $scope.addNewDom = function() {
106 // $scope.notaPedido.domicilio.push({ 'id': 0 }); 110 // $scope.notaPedido.domicilio.push({ 'id': 0 });
107 // }; 111 // };
108 // $scope.removeNewChoice = function(choice) { 112 // $scope.removeNewChoice = function(choice) {
109 // if ($scope.notaPedido.domicilio.length > 1) { 113 // if ($scope.notaPedido.domicilio.length > 1) {
110 // $scope.notaPedido.domicilio.splice($scope.notaPedido.domicilio.findIndex( 114 // $scope.notaPedido.domicilio.splice($scope.notaPedido.domicilio.findIndex(
111 // function(c) { 115 // function(c) {
112 // return c.$$hashKey === choice.$$hashKey; 116 // return c.$$hashKey === choice.$$hashKey;
113 // } 117 // }
114 // ), 1); 118 // ), 1);
115 // } 119 // }
116 // }; 120 // };
117 121
118 $scope.crearNotaPedido = function() { 122 $scope.crearNotaPedido = function() {
119 if(!$scope.notaPedido.vendedor.codigo) { 123 if(!$scope.notaPedido.vendedor.codigo) {
120 focaModalService.alert('Ingrese Vendedor'); 124 focaModalService.alert('Ingrese Vendedor');
121 return; 125 return;
122 } else if(!$scope.notaPedido.cliente.cod) { 126 } else if(!$scope.notaPedido.cliente.cod) {
123 focaModalService.alert('Ingrese Cliente'); 127 focaModalService.alert('Ingrese Cliente');
124 return; 128 return;
125 } else if(!$scope.notaPedido.proveedor.codigo) { 129 } else if(!$scope.notaPedido.proveedor.codigo) {
126 focaModalService.alert('Ingrese Proveedor'); 130 focaModalService.alert('Ingrese Proveedor');
127 return; 131 return;
128 } else if(!$scope.notaPedido.moneda.id) { 132 } else if(!$scope.notaPedido.moneda.id) {
129 focaModalService.alert('Ingrese Moneda'); 133 focaModalService.alert('Ingrese Moneda');
130 return; 134 return;
131 } else if(!$scope.notaPedido.cotizacion.ID) { 135 } else if(!$scope.notaPedido.cotizacion.ID) {
132 focaModalService.alert('Ingrese Cotización'); 136 focaModalService.alert('Ingrese Cotización');
133 return; 137 return;
134 } else if(!$scope.plazosPagos) { 138 } else if(!$scope.plazosPagos) {
135 focaModalService.alert('Ingrese Precios y Condiciones'); 139 focaModalService.alert('Ingrese Precios y Condiciones');
136 return; 140 return;
137 } else if( 141 } else if(
138 $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) 142 $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null)
139 { 143 {
140 focaModalService.alert('Ingrese Flete'); 144 focaModalService.alert('Ingrese Flete');
141 return; 145 return;
142 } else if(!$scope.notaPedido.domicilio.id) { 146 } else if(!$scope.notaPedido.domicilio.id) {
143 focaModalService.aler('Ingrese Domicilio'); 147 focaModalService.aler('Ingrese Domicilio');
144 return; 148 return;
145 } else if($scope.articulosTabla.length === 0) { 149 } else if($scope.articulosTabla.length === 0) {
146 focaModalService.alert('Debe cargar al menos un articulo'); 150 focaModalService.alert('Debe cargar al menos un articulo');
147 return; 151 return;
148 } 152 }
149 var date = new Date(); 153 var date = new Date();
150 var notaPedido = { 154 var notaPedido = {
151 id: 0, 155 id: 0,
152 fechaCarga: new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) 156 fechaCarga: new Date(date.getTime() - (date.getTimezoneOffset() * 60000))
153 .toISOString().slice(0, 19).replace('T', ' '), 157 .toISOString().slice(0, 19).replace('T', ' '),
154 idVendedor: $scope.notaPedido.vendedor.codigo, 158 idVendedor: $scope.notaPedido.vendedor.codigo,
155 idCliente: $scope.notaPedido.cliente.cod, 159 idCliente: $scope.notaPedido.cliente.cod,
156 nombreCliente: $scope.notaPedido.cliente.nom, 160 nombreCliente: $scope.notaPedido.cliente.nom,
157 cuitCliente: $scope.notaPedido.cliente.cuit, 161 cuitCliente: $scope.notaPedido.cliente.cuit,
158 idProveedor: $scope.notaPedido.proveedor.codigo, 162 idProveedor: $scope.notaPedido.proveedor.codigo,
159 idDomicilio: $scope.notaPedido.domicilio.id, 163 idDomicilio: $scope.notaPedido.domicilio.id,
160 idCotizacion: $scope.notaPedido.cotizacion.ID, 164 idCotizacion: $scope.notaPedido.cotizacion.ID,
161 cotizacion: $scope.notaPedido.cotizacion.COTIZACION, 165 cotizacion: $scope.notaPedido.cotizacion.COTIZACION,
162 flete: $scope.notaPedido.flete, 166 flete: $scope.notaPedido.flete,
163 fob: $scope.notaPedido.fob, 167 fob: $scope.notaPedido.fob,
164 bomba: $scope.notaPedido.bomba, 168 bomba: $scope.notaPedido.bomba,
165 kilometros: $scope.notaPedido.kilometros, 169 kilometros: $scope.notaPedido.kilometros,
166 estado: 0, 170 estado: 0,
167 total: $scope.getTotal() 171 total: $scope.getTotal()
168 }; 172 };
169 crearNotaPedidoService.crearNotaPedido(notaPedido).then( 173 crearNotaPedidoService.crearNotaPedido(notaPedido).then(
170 function(data) { 174 function(data) {
171 notaPedidoBusinessService.addArticulos($scope.articulosTabla, 175 notaPedidoBusinessService.addArticulos($scope.articulosTabla,
172 data.data.id, $scope.notaPedido.cotizacion.COTIZACION); 176 data.data.id, $scope.notaPedido.cotizacion.COTIZACION);
173 focaSeguimientoService.guardarPosicion('crear nota pedido', ''); 177 focaSeguimientoService.guardarPosicion('crear nota pedido', '');
174 var plazos = $scope.plazosPagos; 178 var plazos = $scope.plazosPagos;
175 179
176 for(var j = 0; j < plazos.length; j++) { 180 for(var j = 0; j < plazos.length; j++) {
177 var json = { 181 var json = {
178 idPedido: data.data.id, 182 idPedido: data.data.id,
179 dias: plazos[j].dias 183 dias: plazos[j].dias
180 }; 184 };
181 crearNotaPedidoService.crearPlazosParaNotaPedido(json); 185 crearNotaPedidoService.crearPlazosParaNotaPedido(json);
182 } 186 }
183 notaPedidoBusinessService.addEstado(data.data.id, 187 notaPedidoBusinessService.addEstado(data.data.id,
184 $scope.notaPedido.vendedor.codigo); 188 $scope.notaPedido.vendedor.codigo);
185 189
186 focaModalService.alert('Nota pedido creada'); 190 focaModalService.alert('Nota pedido creada');
187 $scope.cabecera = []; 191 $scope.cabecera = [];
188 addCabecera('Moneda:', $scope.notaPedido.moneda.detalle); 192 addCabecera('Moneda:', $scope.notaPedido.moneda.detalle);
189 addCabecera( 193 addCabecera(
190 'Fecha cotizacion:', 194 'Fecha cotizacion:',
191 $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy') 195 $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy')
192 ); 196 );
193 addCabecera('Cotizacion:', $scope.notaPedido.cotizacion.COTIZACION); 197 addCabecera('Cotizacion:', $scope.notaPedido.cotizacion.COTIZACION);
194 $scope.notaPedido.vendedor = {}; 198 $scope.notaPedido.vendedor = {};
195 $scope.notaPedido.cliente = {}; 199 $scope.notaPedido.cliente = {};
196 $scope.notaPedido.proveedor = {}; 200 $scope.notaPedido.proveedor = {};
197 $scope.notaPedido.domicilio = {}; 201 $scope.notaPedido.domicilio = {};
198 $scope.notaPedido.flete = null; 202 $scope.notaPedido.flete = null;
199 $scope.notaPedido.fob = null; 203 $scope.notaPedido.fob = null;
200 $scope.notaPedido.bomba = null; 204 $scope.notaPedido.bomba = null;
201 $scope.notaPedido.kilometros = null; 205 $scope.notaPedido.kilometros = null;
202 $scope.articulosTabla = []; 206 $scope.articulosTabla = [];
207 },
208 function(error) {
209 focaModalService.alert('Hubo un error al crear la nota de pedido');
210 console.info(error);
203 } 211 }
204 ); 212 );
205 }; 213 };
206 214
207 $scope.seleccionarArticulo = function() { 215 $scope.seleccionarArticulo = function() {
208 if ($scope.idLista === undefined) { 216 if ($scope.idLista === undefined) {
209 focaModalService.alert( 217 focaModalService.alert(
210 'Primero seleccione una lista de precio y condicion'); 218 'Primero seleccione una lista de precio y condicion');
211 return; 219 return;
212 } 220 }
213 var modalInstance = $uibModal.open( 221 var modalInstance = $uibModal.open(
214 { 222 {
215 ariaLabelledBy: 'Busqueda de Productos', 223 ariaLabelledBy: 'Busqueda de Productos',
216 templateUrl: 'modal-busqueda-productos.html', 224 templateUrl: 'modal-busqueda-productos.html',
217 controller: 'modalBusquedaProductosCtrl', 225 controller: 'modalBusquedaProductosCtrl',
218 resolve: { 226 resolve: {
219 parametroProducto: { 227 parametroProducto: {
220 idLista: $scope.idLista, 228 idLista: $scope.idLista,
221 cotizacion: $scope.notaPedido.cotizacion.COTIZACION, 229 cotizacion: $scope.notaPedido.cotizacion.COTIZACION,
222 simbolo: $scope.notaPedido.moneda.simbolo 230 simbolo: $scope.notaPedido.moneda.simbolo
223 } 231 }
224 }, 232 },
225 size: 'lg' 233 size: 'lg'
226 } 234 }
227 ); 235 );
228 modalInstance.result.then( 236 modalInstance.result.then(
229 function(producto) { 237 function(producto) {
230 var newArt = 238 var newArt =
231 { 239 {
232 id: 0, 240 id: 0,
233 codigo: producto.codigo, 241 codigo: producto.codigo,
234 sector: producto.sector, 242 sector: producto.sector,
235 sectorCodigo: producto.sector + '-' + producto.codigo, 243 sectorCodigo: producto.sector + '-' + producto.codigo,
236 descripcion: producto.descripcion, 244 descripcion: producto.descripcion,
237 item: $scope.articulosTabla.length + 1, 245 item: $scope.articulosTabla.length + 1,
238 nombre: producto.descripcion, 246 nombre: producto.descripcion,
239 precio: parseFloat(producto.precio.toFixed(4)), 247 precio: parseFloat(producto.precio.toFixed(4)),
240 costoUnitario: producto.costo, 248 costoUnitario: producto.costo,
241 editCantidad: false, 249 editCantidad: false,
242 editPrecio: false 250 editPrecio: false
243 }; 251 };
244 $scope.articuloACargar = newArt; 252 $scope.articuloACargar = newArt;
245 $scope.cargando = false; 253 $scope.cargando = false;
246 }, function() { 254 }, function() {
247 // funcion ejecutada cuando se cancela el modal 255 // funcion ejecutada cuando se cancela el modal
248 } 256 }
249 ); 257 );
250 }; 258 };
251 259
252 $scope.seleccionarVendedor = function() { 260 $scope.seleccionarVendedor = function() {
253 var modalInstance = $uibModal.open( 261 var modalInstance = $uibModal.open(
254 { 262 {
255 ariaLabelledBy: 'Busqueda de Vendedores', 263 ariaLabelledBy: 'Busqueda de Vendedores',
256 templateUrl: 'modal-vendedores.html', 264 templateUrl: 'modal-vendedores.html',
257 controller: 'modalVendedoresCtrl', 265 controller: 'modalVendedoresCtrl',
258 size: 'lg' 266 size: 'lg'
259 } 267 }
260 ); 268 );
261 modalInstance.result.then( 269 modalInstance.result.then(
262 function(vendedor) { 270 function(vendedor) {
263 addCabecera('Vendedor:', vendedor.NomVen); 271 addCabecera('Vendedor:', vendedor.NomVen);
264 $scope.notaPedido.vendedor.codigo = vendedor.CodVen; 272 $scope.notaPedido.vendedor.codigo = vendedor.CodVen;
265 }, function() { 273 }, function() {
266 274
267 } 275 }
268 ); 276 );
269 }; 277 };
270 278
271 $scope.seleccionarProveedor = function() { 279 $scope.seleccionarProveedor = function() {
272 var modalInstance = $uibModal.open( 280 var modalInstance = $uibModal.open(
273 { 281 {
274 ariaLabelledBy: 'Busqueda de Proveedor', 282 ariaLabelledBy: 'Busqueda de Proveedor',
275 templateUrl: 'modal-proveedor.html', 283 templateUrl: 'modal-proveedor.html',
276 controller: 'focaModalProveedorCtrl', 284 controller: 'focaModalProveedorCtrl',
277 size: 'lg' 285 size: 'lg'
278 } 286 }
279 ); 287 );
280 modalInstance.result.then( 288 modalInstance.result.then(
281 function(proveedor) { 289 function(proveedor) {
282 $scope.notaPedido.proveedor.codigo = proveedor.COD; 290 $scope.notaPedido.proveedor.codigo = proveedor.COD;
283 addCabecera('Proveedor:', proveedor.NOM); 291 addCabecera('Proveedor:', proveedor.NOM);
284 }, function() { 292 }, function() {
285 293
286 } 294 }
287 ); 295 );
288 }; 296 };
289 297
290 $scope.seleccionarCliente = function() { 298 $scope.seleccionarCliente = function() {
291 299
292 var modalInstance = $uibModal.open( 300 var modalInstance = $uibModal.open(
293 { 301 {
294 ariaLabelledBy: 'Busqueda de Cliente', 302 ariaLabelledBy: 'Busqueda de Cliente',
295 templateUrl: 'foca-busqueda-cliente-modal.html', 303 templateUrl: 'foca-busqueda-cliente-modal.html',
296 controller: 'focaBusquedaClienteModalController', 304 controller: 'focaBusquedaClienteModalController',
297 size: 'lg' 305 size: 'lg'
298 } 306 }
299 ); 307 );
300 modalInstance.result.then( 308 modalInstance.result.then(
301 function(cliente) { 309 function(cliente) {
302 $scope.abrirModalDomicilios(cliente); 310 $scope.abrirModalDomicilios(cliente);
303 }, function() { 311 }, function() {
304 312
305 } 313 }
306 ); 314 );
307 }; 315 };
308 316
309 $scope.abrirModalDomicilios = function(cliente) { 317 $scope.abrirModalDomicilios = function(cliente) {
310 var modalInstanceDomicilio = $uibModal.open( 318 var modalInstanceDomicilio = $uibModal.open(
311 { 319 {
312 ariaLabelledBy: 'Busqueda de Domicilios', 320 ariaLabelledBy: 'Busqueda de Domicilios',
313 templateUrl: 'modal-domicilio.html', 321 templateUrl: 'modal-domicilio.html',
314 controller: 'focaModalDomicilioController', 322 controller: 'focaModalDomicilioController',
315 resolve: { idCliente: function() { return cliente.cod; }}, 323 resolve: { idCliente: function() { return cliente.cod; }},
316 size: 'lg', 324 size: 'lg',
317 } 325 }
318 ); 326 );
319 modalInstanceDomicilio.result.then( 327 modalInstanceDomicilio.result.then(
320 function(domicilio) { 328 function(domicilio) {
321 $scope.notaPedido.domicilio.id = domicilio.id; 329 $scope.notaPedido.domicilio.id = domicilio.id;
322 $scope.notaPedido.cliente = cliente; 330 $scope.notaPedido.cliente = cliente;
323 331
324 addCabecera('Cliente:', cliente.nom); 332 addCabecera('Cliente:', cliente.nom);
325 addCabecera('Domicilio:', domicilio.dom); 333 addCabecera('Domicilio:', domicilio.dom);
326 }, function() { 334 }, function() {
327 $scope.seleccionarCliente(); 335 $scope.seleccionarCliente();
328 return; 336 return;
329 } 337 }
330 ); 338 );
331 }; 339 };
332 340
333 $scope.mostrarFichaCliente = function() { 341 $scope.mostrarFichaCliente = function() {
334 $uibModal.open( 342 $uibModal.open(
335 { 343 {
336 ariaLabelledBy: 'Datos del Cliente', 344 ariaLabelledBy: 'Datos del Cliente',
337 templateUrl: 'foca-crear-nota-pedido-ficha-cliente.html', 345 templateUrl: 'foca-crear-nota-pedido-ficha-cliente.html',
338 controller: 'focaCrearNotaPedidoFichaClienteController', 346 controller: 'focaCrearNotaPedidoFichaClienteController',
339 size: 'lg' 347 size: 'lg'
340 } 348 }
341 ); 349 );
342 }; 350 };
343 351
344 $scope.getTotal = function() { 352 $scope.getTotal = function() {
345 var total = 0; 353 var total = 0;
346 var arrayTempArticulos = $scope.articulosTabla; 354 var arrayTempArticulos = $scope.articulosTabla;
347 for (var i = 0; i < arrayTempArticulos.length; i++) { 355 for (var i = 0; i < arrayTempArticulos.length; i++) {
348 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; 356 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad;
349 } 357 }
350 return parseFloat(total.toFixed(2)); 358 return parseFloat(total.toFixed(2));
351 }; 359 };
352 360
353 $scope.getSubTotal = function() { 361 $scope.getSubTotal = function() {
354 if($scope.articuloACargar) { 362 if($scope.articuloACargar) {
355 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; 363 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
356 } 364 }
357 }; 365 };
358 366
359 $scope.abrirModalListaPrecio = function() { 367 $scope.abrirModalListaPrecio = function() {
360 var modalInstance = $uibModal.open( 368 var modalInstance = $uibModal.open(
361 { 369 {
362 ariaLabelledBy: 'Busqueda de Precio Condición', 370 ariaLabelledBy: 'Busqueda de Precio Condición',
363 templateUrl: 'modal-precio-condicion.html', 371 templateUrl: 'modal-precio-condicion.html',
364 controller: 'focaModalPrecioCondicionController', 372 controller: 'focaModalPrecioCondicionController',
365 size: 'lg' 373 size: 'lg'
366 } 374 }
367 ); 375 );
368 modalInstance.result.then( 376 modalInstance.result.then(
369 function(precioCondicion) { 377 function(precioCondicion) {
370 var cabecera = ''; 378 var cabecera = '';
371 var plazosConcat = ''; 379 var plazosConcat = '';
372 if(!Array.isArray(precioCondicion)) { 380 if(!Array.isArray(precioCondicion)) {
373 $scope.plazosPagos = precioCondicion.plazoPago; 381 $scope.plazosPagos = precioCondicion.plazoPago;
374 $scope.idLista = precioCondicion.idListaPrecio; 382 $scope.idLista = precioCondicion.idListaPrecio;
375 for(var i = 0; i < precioCondicion.plazoPago.length; i++) { 383 for(var i = 0; i < precioCondicion.plazoPago.length; i++) {
376 plazosConcat += precioCondicion.plazoPago[i].dias + ' '; 384 plazosConcat += precioCondicion.plazoPago[i].dias + ' ';
377 } 385 }
378 cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); 386 cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim();
379 } else { //Cuando se ingresan los plazos manualmente 387 } else { //Cuando se ingresan los plazos manualmente
380 $scope.idLista = -1; //-1, el modal productos busca todos los productos 388 $scope.idLista = -1; //-1, el modal productos busca todos los productos
381 $scope.plazosPagos = precioCondicion; 389 $scope.plazosPagos = precioCondicion;
382 for(var j = 0; j < precioCondicion.length; j++) { 390 for(var j = 0; j < precioCondicion.length; j++) {
383 plazosConcat += precioCondicion[j].dias + ' '; 391 plazosConcat += precioCondicion[j].dias + ' ';
384 } 392 }
385 cabecera = 'Ingreso manual ' + plazosConcat.trim(); 393 cabecera = 'Ingreso manual ' + plazosConcat.trim();
386 } 394 }
387 $scope.articulosTabla = []; 395 $scope.articulosTabla = [];
388 addCabecera('Precios y condiciones:', cabecera); 396 addCabecera('Precios y condiciones:', cabecera);
389 }, function() { 397 }, function() {
390 398
391 } 399 }
392 ); 400 );
393 }; 401 };
394 402
395 $scope.abrirModalFlete = function() { 403 $scope.abrirModalFlete = function() {
396 var modalInstance = $uibModal.open( 404 var modalInstance = $uibModal.open(
397 { 405 {
398 ariaLabelledBy: 'Busqueda de Flete', 406 ariaLabelledBy: 'Busqueda de Flete',
399 templateUrl: 'modal-flete.html', 407 templateUrl: 'modal-flete.html',
400 controller: 'focaModalFleteController', 408 controller: 'focaModalFleteController',
401 size: 'lg', 409 size: 'lg',
402 resolve: { 410 resolve: {
403 parametrosFlete: 411 parametrosFlete:
404 function() { 412 function() {
405 return { 413 return {
406 flete: $scope.notaPedido.flete ? '1' : 414 flete: $scope.notaPedido.flete ? '1' :
407 ($scope.notaPedido.fob ? 'FOB' : 415 ($scope.notaPedido.fob ? 'FOB' :
408 ($scope.notaPedido.flete === undefined ? null : '0')), 416 ($scope.notaPedido.flete === undefined ? null : '0')),
409 bomba: $scope.notaPedido.bomba ? '1' : 417 bomba: $scope.notaPedido.bomba ? '1' :
410 ($scope.notaPedido.bomba === undefined ? null : '0'), 418 ($scope.notaPedido.bomba === undefined ? null : '0'),
411 kilometros: $scope.notaPedido.kilometros 419 kilometros: $scope.notaPedido.kilometros
412 }; 420 };
413 } 421 }
414 } 422 }
415 } 423 }
416 ); 424 );
417 modalInstance.result.then( 425 modalInstance.result.then(
418 function(datos) { 426 function(datos) {
419 $scope.notaPedido.flete = datos.flete; 427 $scope.notaPedido.flete = datos.flete;
420 $scope.notaPedido.fob = datos.FOB; 428 $scope.notaPedido.fob = datos.FOB;
421 $scope.notaPedido.bomba = datos.bomba; 429 $scope.notaPedido.bomba = datos.bomba;
422 $scope.notaPedido.kilometros = datos.kilometros; 430 $scope.notaPedido.kilometros = datos.kilometros;
423 431
424 addCabecera('Flete:', datos.flete ? 'Si' : 432 addCabecera('Flete:', datos.flete ? 'Si' :
425 ($scope.notaPedido.fob ? 'FOB' : 'No')); 433 ($scope.notaPedido.fob ? 'FOB' : 'No'));
426 if(datos.flete) { 434 if(datos.flete) {
427 addCabecera('Bomba:', datos.bomba ? 'Si' : 'No'); 435 addCabecera('Bomba:', datos.bomba ? 'Si' : 'No');
428 addCabecera('Kilometros:', datos.kilometros); 436 addCabecera('Kilometros:', datos.kilometros);
429 } else { 437 } else {
430 removeCabecera('Bomba:'); 438 removeCabecera('Bomba:');
431 removeCabecera('Kilometros:'); 439 removeCabecera('Kilometros:');
432 $scope.notaPedido.fob = false; 440 $scope.notaPedido.fob = false;
433 $scope.notaPedido.bomba = false; 441 $scope.notaPedido.bomba = false;
434 $scope.notaPedido.kilometros = null; 442 $scope.notaPedido.kilometros = null;
435 } 443 }
436 }, function() { 444 }, function() {
437 445
438 } 446 }
439 ); 447 );
440 }; 448 };
441 449
442 $scope.abrirModalMoneda = function() { 450 $scope.abrirModalMoneda = function() {
443 var modalInstance = $uibModal.open( 451 var modalInstance = $uibModal.open(
444 { 452 {
445 ariaLabelledBy: 'Busqueda de Moneda', 453 ariaLabelledBy: 'Busqueda de Moneda',
446 templateUrl: 'modal-moneda.html', 454 templateUrl: 'modal-moneda.html',
447 controller: 'focaModalMonedaController', 455 controller: 'focaModalMonedaController',
448 size: 'lg' 456 size: 'lg'
449 } 457 }
450 ); 458 );
451 modalInstance.result.then( 459 modalInstance.result.then(
452 function(moneda) { 460 function(moneda) {
453 $scope.abrirModalCotizacion(moneda); 461 $scope.abrirModalCotizacion(moneda);
454 }, function() { 462 }, function() {
455 463
456 } 464 }
457 ); 465 );
458 }; 466 };
459 467
460 $scope.abrirModalCotizacion = function(moneda) { 468 $scope.abrirModalCotizacion = function(moneda) {
461 var modalInstance = $uibModal.open( 469 var modalInstance = $uibModal.open(
462 { 470 {
463 ariaLabelledBy: 'Busqueda de Cotización', 471 ariaLabelledBy: 'Busqueda de Cotización',
464 templateUrl: 'modal-cotizacion.html', 472 templateUrl: 'modal-cotizacion.html',
465 controller: 'focaModalCotizacionController', 473 controller: 'focaModalCotizacionController',
466 size: 'lg', 474 size: 'lg',
467 resolve: {idMoneda: function() {return moneda.ID;}} 475 resolve: {idMoneda: function() {return moneda.ID;}}
468 } 476 }
469 ); 477 );
470 modalInstance.result.then( 478 modalInstance.result.then(
471 function(cotizacion) { 479 function(cotizacion) {
472 var articulosTablaTemp = $scope.articulosTabla; 480 var articulosTablaTemp = $scope.articulosTabla;
473 for(var i = 0; i < articulosTablaTemp.length; i++) { 481 for(var i = 0; i < articulosTablaTemp.length; i++) {
474 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * 482 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio *
475 $scope.notaPedido.cotizacion.COTIZACION; 483 $scope.notaPedido.cotizacion.COTIZACION;
476 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / 484 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio /
477 cotizacion.COTIZACION; 485 cotizacion.COTIZACION;
478 } 486 }
479 $scope.articulosTabla = articulosTablaTemp; 487 $scope.articulosTabla = articulosTablaTemp;
480 $scope.notaPedido.moneda = { 488 $scope.notaPedido.moneda = {
481 id: moneda.ID, 489 id: moneda.ID,
482 detalle: moneda.DETALLE, 490 detalle: moneda.DETALLE,
483 simbolo: moneda.SIMBOLO 491 simbolo: moneda.SIMBOLO
484 }; 492 };
485 $scope.notaPedido.cotizacion = { 493 $scope.notaPedido.cotizacion = {
486 ID: cotizacion.ID, 494 ID: cotizacion.ID,
487 COTIZACION: cotizacion.COTIZACION, 495 COTIZACION: cotizacion.COTIZACION,
488 FECHA: cotizacion.FECHA 496 FECHA: cotizacion.FECHA
489 }; 497 };
490 addCabecera('Moneda:', moneda.DETALLE); 498 addCabecera('Moneda:', moneda.DETALLE);
491 addCabecera( 499 addCabecera(
492 'Fecha cotizacion:', 500 'Fecha cotizacion:',
493 $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 501 $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
494 ); 502 );
495 addCabecera('Cotizacion:', cotizacion.COTIZACION); 503 addCabecera('Cotizacion:', cotizacion.COTIZACION);
496 }, function() { 504 }, function() {
497 505
498 } 506 }
499 ); 507 );
500 }; 508 };
501 509
502 $scope.agregarATabla = function(key) { 510 $scope.agregarATabla = function(key) {
503 if(key === 13) { 511 if(key === 13) {
504 if($scope.articuloACargar.cantidad === undefined || 512 if($scope.articuloACargar.cantidad === undefined ||
505 $scope.articuloACargar.cantidad === 0 || 513 $scope.articuloACargar.cantidad === 0 ||
506 $scope.articuloACargar.cantidad === null ){ 514 $scope.articuloACargar.cantidad === null ){
507 focaModalService.alert('El valor debe ser al menos 1'); 515 focaModalService.alert('El valor debe ser al menos 1');
508 return; 516 return;
509 } 517 }
510 delete $scope.articuloACargar.sectorCodigo; 518 delete $scope.articuloACargar.sectorCodigo;
511 $scope.articulosTabla.push($scope.articuloACargar); 519 $scope.articulosTabla.push($scope.articuloACargar);
512 $scope.cargando = true; 520 $scope.cargando = true;
513 } 521 }
514 }; 522 };
515 523
516 $scope.quitarArticulo = function(key) { 524 $scope.quitarArticulo = function(key) {
517 $scope.articulosTabla.splice(key, 1); 525 $scope.articulosTabla.splice(key, 1);
518 }; 526 };
519 527
520 $scope.editarArticulo = function(key, articulo) { 528 $scope.editarArticulo = function(key, articulo) {
521 if(key === 13) { 529 if(key === 13) {
522 if(articulo.cantidad === null || articulo.cantidad === 0 || 530 if(articulo.cantidad === null || articulo.cantidad === 0 ||
523 articulo.cantidad === undefined){ 531 articulo.cantidad === undefined){
524 focaModalService.alert('El valor debe ser al menos 1'); 532 focaModalService.alert('El valor debe ser al menos 1');
525 return; 533 return;
526 } 534 }
527 articulo.editCantidad = false; 535 articulo.editCantidad = false;
528 articulo.editPrecio = false; 536 articulo.editPrecio = false;
529 } 537 }
530 }; 538 };
531 539
532 $scope.cambioEdit = function(articulo, propiedad) { 540 $scope.cambioEdit = function(articulo, propiedad) {
533 if(propiedad === 'cantidad') { 541 if(propiedad === 'cantidad') {
534 articulo.editCantidad = true; 542 articulo.editCantidad = true;
535 } else if(propiedad === 'precio') { 543 } else if(propiedad === 'precio') {
536 articulo.editPrecio = true; 544 articulo.editPrecio = true;
537 } 545 }
538 }; 546 };
539 547
540 $scope.limpiarFlete = function() { 548 $scope.limpiarFlete = function() {
541 $scope.notaPedido.fleteNombre = ''; 549 $scope.notaPedido.fleteNombre = '';
542 $scope.notaPedido.chofer = ''; 550 $scope.notaPedido.chofer = '';
543 $scope.notaPedido.vehiculo = ''; 551 $scope.notaPedido.vehiculo = '';
544 $scope.notaPedido.kilometros = ''; 552 $scope.notaPedido.kilometros = '';
545 $scope.notaPedido.costoUnitarioKmFlete = ''; 553 $scope.notaPedido.costoUnitarioKmFlete = '';
546 $scope.choferes = ''; 554 $scope.choferes = '';
547 $scope.vehiculos = ''; 555 $scope.vehiculos = '';
548 }; 556 };
549 557
550 $scope.limpiarPantalla = function() { 558 $scope.limpiarPantalla = function() {
551 $scope.limpiarFlete(); 559 $scope.limpiarFlete();
552 $scope.notaPedido.flete = '0'; 560 $scope.notaPedido.flete = '0';
553 $scope.notaPedido.bomba = '0'; 561 $scope.notaPedido.bomba = '0';
554 $scope.notaPedido.precioCondicion = ''; 562 $scope.notaPedido.precioCondicion = '';
555 $scope.articulosTabla = []; 563 $scope.articulosTabla = [];
556 $scope.notaPedido.vendedor.nombre = ''; 564 $scope.notaPedido.vendedor.nombre = '';
557 $scope.notaPedido.cliente = {nombre: ''}; 565 $scope.notaPedido.cliente = {nombre: ''};
558 $scope.notaPedido.domicilio = {dom: ''}; 566 $scope.notaPedido.domicilio = {dom: ''};
559 $scope.domiciliosCliente = []; 567 $scope.domiciliosCliente = [];
560 }; 568 };
561 569
562 $scope.resetFilter = function() { 570 $scope.resetFilter = function() {
563 $scope.articuloACargar = {}; 571 $scope.articuloACargar = {};
564 $scope.cargando = true; 572 $scope.cargando = true;
565 }; 573 };
566 574
567 $scope.selectFocus = function($event) { 575 $scope.selectFocus = function($event) {
568 $event.target.select(); 576 $event.target.select();
569 }; 577 };
570 578
571 $scope.salir = function() { 579 $scope.salir = function() {
572 $location.path('/'); 580 $location.path('/');
573 }; 581 };
574 582
575 function addCabecera(label, valor) { 583 function addCabecera(label, valor) {
576 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); 584 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true);
577 if(propiedad.length === 1) { 585 if(propiedad.length === 1) {
578 propiedad[0].valor = valor; 586 propiedad[0].valor = valor;
579 } else { 587 } else {
580 $scope.cabecera.push({label: label, valor: valor}); 588 $scope.cabecera.push({label: label, valor: valor});
581 } 589 }
582 } 590 }
583 591
584 function removeCabecera(label) { 592 function removeCabecera(label) {
585 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); 593 var propiedad = $filter('filter')($scope.cabecera, {label: label}, true);
586 if(propiedad.length === 1){ 594 if(propiedad.length === 1){
587 $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); 595 $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1);
588 } 596 }
589 } 597 }
590 598
591 function rellenar(relleno, longitud) { 599 function rellenar(relleno, longitud) {
592 relleno = '' + relleno; 600 relleno = '' + relleno;
593 while (relleno.length < longitud) { 601 while (relleno.length < longitud) {
594 relleno = '0' + relleno; 602 relleno = '0' + relleno;
595 } 603 }
596 604
597 return relleno; 605 return relleno;
598 } 606 }
599 } 607 }
600 ] 608 ]
601 ) 609 )
602 .controller('notaPedidoListaCtrl', [ 610 .controller('notaPedidoListaCtrl', [
603 '$scope', 611 '$scope',
604 'crearNotaPedidoService', 612 'crearNotaPedidoService',
605 '$location', 613 '$location',
606 function($scope, crearNotaPedidoService, $location) { 614 function($scope, crearNotaPedidoService, $location) {
607 crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { 615 crearNotaPedidoService.obtenerNotaPedido().then(function(datos) {
608 $scope.notaPedidos = datos.data; 616 $scope.notaPedidos = datos.data;
609 }); 617 });
610 $scope.editar = function(notaPedido) { 618 $scope.editar = function(notaPedido) {
611 crearNotaPedidoService.setNotaPedido(notaPedido); 619 crearNotaPedidoService.setNotaPedido(notaPedido);
612 $location.path('/venta-nota-pedido/abm/'); 620 $location.path('/venta-nota-pedido/abm/');
613 }; 621 };
614 $scope.crearPedido = function() { 622 $scope.crearPedido = function() {
615 crearNotaPedidoService.clearNotaPedido(); 623 crearNotaPedidoService.clearNotaPedido();
616 $location.path('/venta-nota-pedido/abm/'); 624 $location.path('/venta-nota-pedido/abm/');
617 }; 625 };
618 } 626 }
619 ]) 627 ])
620 .controller('focaCrearNotaPedidoFichaClienteController', [ 628 .controller('focaCrearNotaPedidoFichaClienteController', [
621 '$scope', 629 '$scope',
622 'crearNotaPedidoService', 630 'crearNotaPedidoService',
623 '$location', 631 '$location',
624 function($scope, crearNotaPedidoService, $location) { 632 function($scope, crearNotaPedidoService, $location) {
625 crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { 633 crearNotaPedidoService.obtenerNotaPedido().then(function(datos) {
626 $scope.notaPedidos = datos.data; 634 $scope.notaPedidos = datos.data;
627 }); 635 });
628 $scope.editar = function(notaPedido) { 636 $scope.editar = function(notaPedido) {
629 crearNotaPedidoService.setNotaPedido(notaPedido); 637 crearNotaPedidoService.setNotaPedido(notaPedido);
630 $location.path('/venta-nota-pedido/abm/'); 638 $location.path('/venta-nota-pedido/abm/');
631 }; 639 };
632 $scope.crearPedido = function() { 640 $scope.crearPedido = function() {
633 crearNotaPedidoService.clearNotaPedido(); 641 crearNotaPedidoService.clearNotaPedido();
634 $location.path('/venta-nota-pedido/abm/'); 642 $location.path('/venta-nota-pedido/abm/');
635 }; 643 };
636 } 644 }
637 ]); 645 ]);
638 646