Commit 5447472a404010c295d134211e35b82f3e6a76dc

Authored by Eric Fernandez
1 parent f05145ae33
Exists in master and in 1 other branch develop

validacion flete

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