Commit 3e04616ff2a67dcf96a716e217325fc5262c18ba

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

implementación para guardar plazos

Showing 2 changed files with 13 additions and 2 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', 4 'focaModalService',
5 function( 5 function(
6 $scope, $uibModal, $location, $filter, crearNotaPedidoService, focaModalService 6 $scope, $uibModal, $location, $filter, crearNotaPedidoService, focaModalService
7 ) { 7 ) {
8 $scope.botonera = [ 8 $scope.botonera = [
9 {texto: 'Vendedor', accion: function() {$scope.seleccionarVendedor();}}, 9 {texto: 'Vendedor', accion: function() {$scope.seleccionarVendedor();}},
10 {texto: 'Cliente', accion: function() {$scope.seleccionarCliente();}}, 10 {texto: 'Cliente', accion: function() {$scope.seleccionarCliente();}},
11 {texto: 'Proveedor', accion: function() {$scope.seleccionarProveedor();}}, 11 {texto: 'Proveedor', accion: function() {$scope.seleccionarProveedor();}},
12 {texto: 'Moneda', accion: function() {$scope.abrirModalMoneda();}}, 12 {texto: 'Moneda', accion: function() {$scope.abrirModalMoneda();}},
13 { 13 {
14 texto: 'Precios y condiciones', 14 texto: 'Precios y condiciones',
15 accion: function() {$scope.abrirModalListaPrecio();}}, 15 accion: function() {$scope.abrirModalListaPrecio();}},
16 {texto: 'Flete', accion: function() {$scope.abrirModalFlete();}}, 16 {texto: 'Flete', accion: function() {$scope.abrirModalFlete();}},
17 {texto: '', accion: function() {}}, 17 {texto: '', accion: function() {}},
18 {texto: '', accion: function() {}} 18 {texto: '', accion: function() {}}
19 ]; 19 ];
20 20
21 $scope.show = false; 21 $scope.show = false;
22 $scope.cargando = true; 22 $scope.cargando = true;
23 $scope.dateOptions = { 23 $scope.dateOptions = {
24 maxDate: new Date(), 24 maxDate: new Date(),
25 minDate: new Date(2010, 0, 1) 25 minDate: new Date(2010, 0, 1)
26 }; 26 };
27 27
28 $scope.notaPedido = { 28 $scope.notaPedido = {
29 vendedor: {}, 29 vendedor: {},
30 cliente: {}, 30 cliente: {},
31 domicilio: {dom: ''}, 31 domicilio: {dom: ''},
32 moneda: {detalle: ''} 32 moneda: {detalle: ''}
33 }; 33 };
34 34
35 $scope.cabecera = []; 35 $scope.cabecera = [];
36 $scope.showCabecera = true; 36 $scope.showCabecera = true;
37 37
38 $scope.now = new Date(); 38 $scope.now = new Date();
39 $scope.puntoVenta = Math.round(Math.random() * 10000); 39 $scope.puntoVenta = Math.round(Math.random() * 10000);
40 $scope.comprobante = Math.round(Math.random() * 1000000); 40 $scope.comprobante = Math.round(Math.random() * 1000000);
41 41
42 $scope.articulosTabla = []; 42 $scope.articulosTabla = [];
43 var idLista; 43 var idLista;
44 var notaPedidoTemp = crearNotaPedidoService.getNotaPedido(); 44 var notaPedidoTemp = crearNotaPedidoService.getNotaPedido();
45 crearNotaPedidoService.getPrecioCondicion().then( 45 crearNotaPedidoService.getPrecioCondicion().then(
46 function(res) { 46 function(res) {
47 $scope.precioCondiciones = res.data; 47 $scope.precioCondiciones = res.data;
48 } 48 }
49 ); 49 );
50 if (notaPedidoTemp !== undefined) { 50 if (notaPedidoTemp !== undefined) {
51 notaPedidoTemp.fechaCarga = new Date(notaPedidoTemp.fechaCarga); 51 notaPedidoTemp.fechaCarga = new Date(notaPedidoTemp.fechaCarga);
52 $scope.notaPedido = notaPedidoTemp; 52 $scope.notaPedido = notaPedidoTemp;
53 $scope.notaPedido.flete = ($scope.notaPedido.flete).toString(); 53 $scope.notaPedido.flete = ($scope.notaPedido.flete).toString();
54 $scope.notaPedido.bomba = ($scope.notaPedido.bomba).toString(); 54 $scope.notaPedido.bomba = ($scope.notaPedido.bomba).toString();
55 idLista = $scope.notaPedido.precioCondicion; 55 idLista = $scope.notaPedido.precioCondicion;
56 crearNotaPedidoService 56 crearNotaPedidoService
57 .getArticulosByIdNotaPedido($scope.notaPedido.id).then( 57 .getArticulosByIdNotaPedido($scope.notaPedido.id).then(
58 function(res) { 58 function(res) {
59 $scope.articulosTabla = res.data; 59 $scope.articulosTabla = res.data;
60 } 60 }
61 ); 61 );
62 //TODO DOMICILIOS QUE SE CARGAN AL EDITAR NOTA DE PEDIDO 62 //TODO DOMICILIOS QUE SE CARGAN AL EDITAR NOTA DE PEDIDO
63 //(NO REQUERIDO EN ESTA VERSION) 63 //(NO REQUERIDO EN ESTA VERSION)
64 // crearNotaPedidoService.getDomiciliosByIdNotaPedido($scope.notaPedido.id).then( 64 // crearNotaPedidoService.getDomiciliosByIdNotaPedido($scope.notaPedido.id).then(
65 // function(res) { 65 // function(res) {
66 // $scope.notaPedido.domicilio = res.data; 66 // $scope.notaPedido.domicilio = res.data;
67 // } 67 // }
68 // ); 68 // );
69 } else { 69 } else {
70 $scope.notaPedido.fechaCarga = new Date(); 70 $scope.notaPedido.fechaCarga = new Date();
71 $scope.notaPedido.bomba = '0'; 71 $scope.notaPedido.bomba = '0';
72 $scope.notaPedido.flete = '0'; 72 $scope.notaPedido.flete = '0';
73 idLista = undefined; 73 idLista = undefined;
74 } 74 }
75 //TO DO - FUNCIONES PARA MULTIPLES DOMICILIOS NO IMPLEMENTADAS EN ESTA DEMO 75 //TO DO - FUNCIONES PARA MULTIPLES DOMICILIOS NO IMPLEMENTADAS EN ESTA DEMO
76 // $scope.addNewDom = function() { 76 // $scope.addNewDom = function() {
77 // $scope.notaPedido.domicilio.push({ 'id': 0 }); 77 // $scope.notaPedido.domicilio.push({ 'id': 0 });
78 // }; 78 // };
79 // $scope.removeNewChoice = function(choice) { 79 // $scope.removeNewChoice = function(choice) {
80 // if ($scope.notaPedido.domicilio.length > 1) { 80 // if ($scope.notaPedido.domicilio.length > 1) {
81 // $scope.notaPedido.domicilio.splice($scope.notaPedido.domicilio.findIndex( 81 // $scope.notaPedido.domicilio.splice($scope.notaPedido.domicilio.findIndex(
82 // function(c) { 82 // function(c) {
83 // return c.$$hashKey === choice.$$hashKey; 83 // return c.$$hashKey === choice.$$hashKey;
84 // } 84 // }
85 // ), 1); 85 // ), 1);
86 // } 86 // }
87 // }; 87 // };
88 $scope.crearNotaPedido = function() { 88 $scope.crearNotaPedido = function() {
89 if($scope.articulosTabla.length === 0) { 89 if($scope.articulosTabla.length === 0) {
90 focaModalService.alert('Debe cargar almenos un articulo'); 90 focaModalService.alert('Debe cargar almenos un articulo');
91 return; 91 return;
92 } 92 }
93 if($scope.notaPedido.domicilio.id === undefined) { 93 if($scope.notaPedido.domicilio.id === undefined) {
94 $scope.notaPedido.domicilio.id = 0; 94 $scope.notaPedido.domicilio.id = 0;
95 } 95 }
96 var date = new Date(); 96 var date = new Date();
97 var notaPedido = { 97 var notaPedido = {
98 id: 0, 98 id: 0,
99 fechaCarga: new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) 99 fechaCarga: new Date(date.getTime() - (date.getTimezoneOffset() * 60000))
100 .toISOString().slice(0, 19).replace('T', ' '), 100 .toISOString().slice(0, 19).replace('T', ' '),
101 vendedor: $scope.notaPedido.vendedor.nombre, 101 vendedor: $scope.notaPedido.vendedor.nombre,
102 idCliente: $scope.notaPedido.cliente.id, 102 idCliente: $scope.notaPedido.cliente.id,
103 domicilio: $scope.notaPedido.domicilio, 103 domicilio: $scope.notaPedido.domicilio,
104 bomba: $scope.notaPedido.bomba, 104 bomba: $scope.notaPedido.bomba,
105 flete: $scope.notaPedido.flete, 105 flete: $scope.notaPedido.flete,
106 total: $scope.getTotal() 106 total: $scope.getTotal()
107 }; 107 };
108 crearNotaPedidoService.crearNotaPedido(notaPedido).then( 108 crearNotaPedidoService.crearNotaPedido(notaPedido).then(
109 function(data) { 109 function(data) {
110 focaModalService.alert('Nota pedido creada');
111 if($scope.notaPedido.flete === 1) { 110 if($scope.notaPedido.flete === 1) {
112 var flete = { 111 var flete = {
113 idNotaPedido: data.data.id, 112 idNotaPedido: data.data.id,
114 idTransportista: $scope.notaPedido.fleteId, 113 idTransportista: $scope.notaPedido.fleteId,
115 idChofer: $scope.notaPedido.chofer.id, 114 idChofer: $scope.notaPedido.chofer.id,
116 idVehiculo: $scope.notaPedido.vehiculo.id, 115 idVehiculo: $scope.notaPedido.vehiculo.id,
117 kilometros: $scope.notaPedido.kilometros, 116 kilometros: $scope.notaPedido.kilometros,
118 costoKilometro: $scope.notaPedido.costoUnitarioKmFlete 117 costoKilometro: $scope.notaPedido.costoUnitarioKmFlete
119 }; 118 };
120 crearNotaPedidoService.crearFlete(flete); 119 crearNotaPedidoService.crearFlete(flete);
121 } 120 }
122 var articulosNotaPedido = $scope.articulosTabla; 121 var articulosNotaPedido = $scope.articulosTabla;
123 for(var i = 0; i < articulosNotaPedido.length; i++) { 122 for(var i = 0; i < articulosNotaPedido.length; i++) {
124 delete articulosNotaPedido[i].edit; 123 delete articulosNotaPedido[i].edit;
125 articulosNotaPedido[i].idNotaPedido = data.data.id; 124 articulosNotaPedido[i].idNotaPedido = data.data.id;
126 crearNotaPedidoService 125 crearNotaPedidoService
127 .crearArticulosParaNotaPedido(articulosNotaPedido[i]); 126 .crearArticulosParaNotaPedido(articulosNotaPedido[i]);
128 } 127 }
128 var plazos = $scope.plazosPagos;
129 for(var j = 0; j < plazos.length; j++) {
130 var json = {
131 idPedido: data.data.id,
132 dias: plazos[j].dias
133 };
134 crearNotaPedidoService.crearPlazosParaNotaPedido(json);
135 }
136 focaModalService.alert('Nota pedido creada');
129 $scope.limpiarPantalla(); 137 $scope.limpiarPantalla();
130 } 138 }
131 ); 139 );
132 }; 140 };
133 141
134 $scope.seleccionarArticulo = function() { 142 $scope.seleccionarArticulo = function() {
135 if (idLista === undefined) { 143 if (idLista === undefined) {
136 focaModalService.alert( 144 focaModalService.alert(
137 'Primero seleccione una lista de precio y condicion'); 145 'Primero seleccione una lista de precio y condicion');
138 return; 146 return;
139 } 147 }
140 var modalInstance = $uibModal.open( 148 var modalInstance = $uibModal.open(
141 { 149 {
142 ariaLabelledBy: 'Busqueda de Productos', 150 ariaLabelledBy: 'Busqueda de Productos',
143 templateUrl: 'modal-busqueda-productos.html', 151 templateUrl: 'modal-busqueda-productos.html',
144 controller: 'modalBusquedaProductosCtrl', 152 controller: 'modalBusquedaProductosCtrl',
145 resolve: { idLista: function() { return idLista; } }, 153 resolve: { idLista: function() { return idLista; } },
146 size: 'lg' 154 size: 'lg'
147 } 155 }
148 ); 156 );
149 modalInstance.result.then( 157 modalInstance.result.then(
150 function(producto) { 158 function(producto) {
151 var newArt = 159 var newArt =
152 { 160 {
153 id: 0, 161 id: 0,
154 codigo: producto.codigo, 162 codigo: producto.codigo,
155 sector: producto.sector, 163 sector: producto.sector,
156 sectorCodigo: producto.sector + '-' + producto.codigo, 164 sectorCodigo: producto.sector + '-' + producto.codigo,
157 descripcion: producto.descripcion, 165 descripcion: producto.descripcion,
158 item: $scope.articulosTabla.length + 1, 166 item: $scope.articulosTabla.length + 1,
159 nombre: producto.descripcion, 167 nombre: producto.descripcion,
160 precio: producto.precio.toFixed(2), 168 precio: producto.precio.toFixed(2),
161 costoUnitario: producto.costo, 169 costoUnitario: producto.costo,
162 edit: false 170 edit: false
163 }; 171 };
164 $scope.articuloACargar = newArt; 172 $scope.articuloACargar = newArt;
165 $scope.cargando = false; 173 $scope.cargando = false;
166 }, function() { 174 }, function() {
167 // funcion ejecutada cuando se cancela el modal 175 // funcion ejecutada cuando se cancela el modal
168 } 176 }
169 ); 177 );
170 }; 178 };
171 179
172 $scope.seleccionarVendedor = function() { 180 $scope.seleccionarVendedor = function() {
173 var modalInstance = $uibModal.open( 181 var modalInstance = $uibModal.open(
174 { 182 {
175 ariaLabelledBy: 'Busqueda de Vendedores', 183 ariaLabelledBy: 'Busqueda de Vendedores',
176 templateUrl: 'modal-vendedores.html', 184 templateUrl: 'modal-vendedores.html',
177 controller: 'modalVendedoresCtrl', 185 controller: 'modalVendedoresCtrl',
178 size: 'lg' 186 size: 'lg'
179 } 187 }
180 ); 188 );
181 modalInstance.result.then( 189 modalInstance.result.then(
182 function(vendedor) { 190 function(vendedor) {
183 addCabecera('Vendedor:', vendedor.NomVen); 191 addCabecera('Vendedor:', vendedor.NomVen);
184 $scope.notaPedido.vendedor.nombre = vendedor.NomVen; 192 $scope.notaPedido.vendedor.nombre = vendedor.NomVen;
185 }, function() { 193 }, function() {
186 194
187 } 195 }
188 ); 196 );
189 }; 197 };
190 198
191 $scope.seleccionarProveedor = function() { 199 $scope.seleccionarProveedor = function() {
192 var modalInstance = $uibModal.open( 200 var modalInstance = $uibModal.open(
193 { 201 {
194 ariaLabelledBy: 'Busqueda de Proveedor', 202 ariaLabelledBy: 'Busqueda de Proveedor',
195 templateUrl: 'modal-proveedor.html', 203 templateUrl: 'modal-proveedor.html',
196 controller: 'focaModalProveedorCtrl', 204 controller: 'focaModalProveedorCtrl',
197 size: 'lg' 205 size: 'lg'
198 } 206 }
199 ); 207 );
200 modalInstance.result.then( 208 modalInstance.result.then(
201 function(proveedor) { 209 function(proveedor) {
202 $scope.notaPedido.proveedor = proveedor.NOM; 210 $scope.notaPedido.proveedor = proveedor.NOM;
203 addCabecera('Proveedor:', proveedor.NOM); 211 addCabecera('Proveedor:', proveedor.NOM);
204 }, function() { 212 }, function() {
205 213
206 } 214 }
207 ); 215 );
208 }; 216 };
209 217
210 $scope.seleccionarCliente = function() { 218 $scope.seleccionarCliente = function() {
211 var modalInstance = $uibModal.open( 219 var modalInstance = $uibModal.open(
212 { 220 {
213 ariaLabelledBy: 'Busqueda de Cliente', 221 ariaLabelledBy: 'Busqueda de Cliente',
214 templateUrl: 'foca-busqueda-cliente-modal.html', 222 templateUrl: 'foca-busqueda-cliente-modal.html',
215 controller: 'focaBusquedaClienteModalController', 223 controller: 'focaBusquedaClienteModalController',
216 size: 'lg' 224 size: 'lg'
217 } 225 }
218 ); 226 );
219 modalInstance.result.then( 227 modalInstance.result.then(
220 function(cliente) { 228 function(cliente) {
221 $scope.notaPedido.cliente.nombre = cliente.nom; 229 $scope.notaPedido.cliente.nombre = cliente.nom;
222 $scope.notaPedido.cliente.id = cliente.cod; 230 $scope.notaPedido.cliente.id = cliente.cod;
223 crearNotaPedidoService.getDomiciliosByIdCliente(cliente.cod).then( 231 crearNotaPedidoService.getDomiciliosByIdCliente(cliente.cod).then(
224 function(data) { 232 function(data) {
225 if(data.data.length === 0){ 233 if(data.data.length === 0){
226 focaModalService 234 focaModalService
227 .alert('El cliente no tienen domicilios de entrega') 235 .alert('El cliente no tienen domicilios de entrega')
228 .then( 236 .then(
229 function() { 237 function() {
230 $scope.seleccionarCliente(); 238 $scope.seleccionarCliente();
231 $scope.notaPedido.cliente = {nombre: ''}; 239 $scope.notaPedido.cliente = {nombre: ''};
232 } 240 }
233 ); 241 );
234 return; 242 return;
235 } 243 }
236 var modalInstanceDomicilio = $uibModal.open( 244 var modalInstanceDomicilio = $uibModal.open(
237 { 245 {
238 ariaLabelledBy: 'Busqueda de Domicilios', 246 ariaLabelledBy: 'Busqueda de Domicilios',
239 templateUrl: 'modal-domicilio.html', 247 templateUrl: 'modal-domicilio.html',
240 controller: 'focaModalDomicilioController', 248 controller: 'focaModalDomicilioController',
241 resolve: { idCliente: function() { return cliente.cod; }}, 249 resolve: { idCliente: function() { return cliente.cod; }},
242 size: 'lg', 250 size: 'lg',
243 backdrop: 'static', 251 backdrop: 'static',
244 } 252 }
245 ); 253 );
246 modalInstanceDomicilio.result.then( 254 modalInstanceDomicilio.result.then(
247 function(domicilio) { 255 function(domicilio) {
248 focaModalService.alert('Domicilio elegido' + domicilio.dom); 256 focaModalService.alert('Domicilio elegido' + domicilio.dom);
249 }, function() { 257 }, function() {
250 $scope.notaPedido.cliente.nombre = ''; 258 $scope.notaPedido.cliente.nombre = '';
251 $scope.notaPedido.cliente.id = ''; 259 $scope.notaPedido.cliente.id = '';
252 removeCabecera('Cliente:'); 260 removeCabecera('Cliente:');
253 $scope.seleccionarCliente(); 261 $scope.seleccionarCliente();
254 return; 262 return;
255 } 263 }
256 ); 264 );
257 } 265 }
258 ); 266 );
259 addCabecera('Cliente:', cliente.nom); 267 addCabecera('Cliente:', cliente.nom);
260 }, function() { 268 }, function() {
261 269
262 } 270 }
263 ); 271 );
264 }; 272 };
265 273
266 $scope.mostrarFichaCliente = function() { 274 $scope.mostrarFichaCliente = function() {
267 $uibModal.open( 275 $uibModal.open(
268 { 276 {
269 ariaLabelledBy: 'Datos del Cliente', 277 ariaLabelledBy: 'Datos del Cliente',
270 templateUrl: 'foca-crear-nota-pedido-ficha-cliente.html', 278 templateUrl: 'foca-crear-nota-pedido-ficha-cliente.html',
271 controller: 'focaCrearNotaPedidoFichaClienteController', 279 controller: 'focaCrearNotaPedidoFichaClienteController',
272 size: 'lg' 280 size: 'lg'
273 } 281 }
274 ); 282 );
275 }; 283 };
276 284
277 $scope.getTotal = function() { 285 $scope.getTotal = function() {
278 var total = 0; 286 var total = 0;
279 var arrayTempArticulos = $scope.articulosTabla; 287 var arrayTempArticulos = $scope.articulosTabla;
280 for (var i = 0; i < arrayTempArticulos.length; i++) { 288 for (var i = 0; i < arrayTempArticulos.length; i++) {
281 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; 289 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad;
282 } 290 }
283 return total.toFixed(2); 291 return total.toFixed(2);
284 }; 292 };
285 293
286 $scope.getSubTotal = function() { 294 $scope.getSubTotal = function() {
287 if($scope.articuloACargar) { 295 if($scope.articuloACargar) {
288 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; 296 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
289 } 297 }
290 }; 298 };
291 299
292 $scope.abrirModalListaPrecio = function() { 300 $scope.abrirModalListaPrecio = function() {
293 var modalInstance = $uibModal.open( 301 var modalInstance = $uibModal.open(
294 { 302 {
295 ariaLabelledBy: 'Busqueda de Precio Condición', 303 ariaLabelledBy: 'Busqueda de Precio Condición',
296 templateUrl: 'modal-precio-condicion.html', 304 templateUrl: 'modal-precio-condicion.html',
297 controller: 'focaModalPrecioCondicionController', 305 controller: 'focaModalPrecioCondicionController',
298 size: 'lg' 306 size: 'lg'
299 } 307 }
300 ); 308 );
301 modalInstance.result.then( 309 modalInstance.result.then(
302 function(precioCondicion) { 310 function(precioCondicion) {
303 var cabecera = ''; 311 var cabecera = '';
304 var plazosConcat = ''; 312 var plazosConcat = '';
305 if(!Array.isArray(precioCondicion)) { 313 if(!Array.isArray(precioCondicion)) {
306 $scope.plazosPagos = precioCondicion.plazoPago; 314 $scope.plazosPagos = precioCondicion.plazoPago;
307 idLista = precioCondicion.idListaPrecio; 315 idLista = precioCondicion.idListaPrecio;
308 for(var i = 0; i < precioCondicion.plazoPago.length; i++) { 316 for(var i = 0; i < precioCondicion.plazoPago.length; i++) {
309 plazosConcat += precioCondicion.plazoPago[i].dias + ' '; 317 plazosConcat += precioCondicion.plazoPago[i].dias + ' ';
310 } 318 }
311 cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); 319 cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim();
312 } else { //Cuando se ingresan los plazos manualmente 320 } else { //Cuando se ingresan los plazos manualmente
313 idLista = -1; //-1, el modal productos busca todos los productos 321 idLista = -1; //-1, el modal productos busca todos los productos
314 $scope.notaPedido.plazoPago = precioCondicion; 322 $scope.plazosPagos = precioCondicion;
315 for(var j = 0; j < precioCondicion.length; j++) { 323 for(var j = 0; j < precioCondicion.length; j++) {
316 plazosConcat += precioCondicion[j].dias + ' '; 324 plazosConcat += precioCondicion[j].dias + ' ';
317 } 325 }
318 cabecera = 'Ingreso manual ' + plazosConcat.trim(); 326 cabecera = 'Ingreso manual ' + plazosConcat.trim();
319 } 327 }
320 $scope.articulosTabla = []; 328 $scope.articulosTabla = [];
321 addCabecera('Precios y condiciones:', cabecera); 329 addCabecera('Precios y condiciones:', cabecera);
322 }, function() { 330 }, function() {
323 331
324 } 332 }
325 ); 333 );
326 }; 334 };
327 335
328 $scope.abrirModalFlete = function() { 336 $scope.abrirModalFlete = function() {
329 var modalInstance = $uibModal.open( 337 var modalInstance = $uibModal.open(
330 { 338 {
331 ariaLabelledBy: 'Busqueda de Flete', 339 ariaLabelledBy: 'Busqueda de Flete',
332 templateUrl: 'modal-flete.html', 340 templateUrl: 'modal-flete.html',
333 controller: 'focaModalFleteController', 341 controller: 'focaModalFleteController',
334 size: 'lg', 342 size: 'lg',
335 resolve: { 343 resolve: {
336 parametrosFlete: 344 parametrosFlete:
337 function() { 345 function() {
338 return { 346 return {
339 flete: $scope.notaPedido.flete, 347 flete: $scope.notaPedido.flete,
340 bomba: $scope.notaPedido.bomba, 348 bomba: $scope.notaPedido.bomba,
341 kilometros: $scope.notaPedido.kilometros 349 kilometros: $scope.notaPedido.kilometros
342 }; 350 };
343 } 351 }
344 } 352 }
345 } 353 }
346 ); 354 );
347 modalInstance.result.then( 355 modalInstance.result.then(
348 function(datos) { 356 function(datos) {
349 $scope.notaPedido.flete = datos.flete; 357 $scope.notaPedido.flete = datos.flete;
350 $scope.notaPedido.bomba = datos.bomba; 358 $scope.notaPedido.bomba = datos.bomba;
351 $scope.notaPedido.kilometros = datos.kilometros; 359 $scope.notaPedido.kilometros = datos.kilometros;
352 360
353 addCabecera('Flete:', datos.flete); 361 addCabecera('Flete:', datos.flete);
354 if(datos.flete === 'si') { 362 if(datos.flete === 'si') {
355 addCabecera('Bomba:', datos.bomba); 363 addCabecera('Bomba:', datos.bomba);
356 addCabecera('Kilometros:', datos.kilometros); 364 addCabecera('Kilometros:', datos.kilometros);
357 } else { 365 } else {
358 removeCabecera('Bomba:'); 366 removeCabecera('Bomba:');
359 removeCabecera('Kilometros:'); 367 removeCabecera('Kilometros:');
360 } 368 }
361 }, function() { 369 }, function() {
362 370
363 } 371 }
364 ); 372 );
365 }; 373 };
366 374
367 $scope.abrirModalMoneda = function() { 375 $scope.abrirModalMoneda = function() {
368 var modalInstance = $uibModal.open( 376 var modalInstance = $uibModal.open(
369 { 377 {
370 ariaLabelledBy: 'Busqueda de Moneda', 378 ariaLabelledBy: 'Busqueda de Moneda',
371 templateUrl: 'modal-moneda.html', 379 templateUrl: 'modal-moneda.html',
372 controller: 'focaModalMonedaController', 380 controller: 'focaModalMonedaController',
373 size: 'lg' 381 size: 'lg'
374 } 382 }
375 ); 383 );
376 modalInstance.result.then( 384 modalInstance.result.then(
377 function(moneda) { 385 function(moneda) {
378 $scope.notaPedido.moneda = { 386 $scope.notaPedido.moneda = {
379 id: moneda.ID, 387 id: moneda.ID,
380 detalle: moneda.DETALLE, 388 detalle: moneda.DETALLE,
381 simbolo: moneda.SIMBOLO 389 simbolo: moneda.SIMBOLO
382 }; 390 };
383 391
384 addCabecera('Moneda:', moneda.DETALLE); 392 addCabecera('Moneda:', moneda.DETALLE);
385 }, function() { 393 }, function() {
386 394
387 } 395 }
388 ); 396 );
389 }; 397 };
390 398
391 $scope.agregarATabla = function(key) { 399 $scope.agregarATabla = function(key) {
392 if(key === 13) { 400 if(key === 13) {
393 if($scope.articuloACargar.cantidad === undefined || 401 if($scope.articuloACargar.cantidad === undefined ||
394 $scope.articuloACargar.cantidad === 0 || 402 $scope.articuloACargar.cantidad === 0 ||
395 $scope.articuloACargar.cantidad === null ){ 403 $scope.articuloACargar.cantidad === null ){
396 focaModalService.alert('El valor debe ser al menos 1'); 404 focaModalService.alert('El valor debe ser al menos 1');
397 return; 405 return;
398 } 406 }
399 delete $scope.articuloACargar.sectorCodigo; 407 delete $scope.articuloACargar.sectorCodigo;
400 $scope.articulosTabla.push($scope.articuloACargar); 408 $scope.articulosTabla.push($scope.articuloACargar);
401 $scope.cargando = true; 409 $scope.cargando = true;
402 } 410 }
403 }; 411 };
404 412
405 $scope.quitarArticulo = function(key) { 413 $scope.quitarArticulo = function(key) {
406 $scope.articulosTabla.splice(key, 1); 414 $scope.articulosTabla.splice(key, 1);
407 }; 415 };
408 416
409 $scope.editarArticulo = function(key, articulo) { 417 $scope.editarArticulo = function(key, articulo) {
410 if(key === 13) { 418 if(key === 13) {
411 if(articulo.cantidad === null || articulo.cantidad === 0 || 419 if(articulo.cantidad === null || articulo.cantidad === 0 ||
412 articulo.cantidad === undefined){ 420 articulo.cantidad === undefined){
413 focaModalService.alert('El valor debe ser al menos 1'); 421 focaModalService.alert('El valor debe ser al menos 1');
414 return; 422 return;
415 } 423 }
416 articulo.edit = false; 424 articulo.edit = false;
417 } 425 }
418 }; 426 };
419 427
420 $scope.cambioEdit = function(articulo) { 428 $scope.cambioEdit = function(articulo) {
421 articulo.edit = true; 429 articulo.edit = true;
422 }; 430 };
423 431
424 $scope.limpiarFlete = function() { 432 $scope.limpiarFlete = function() {
425 $scope.notaPedido.fleteNombre = ''; 433 $scope.notaPedido.fleteNombre = '';
426 $scope.notaPedido.chofer = ''; 434 $scope.notaPedido.chofer = '';
427 $scope.notaPedido.vehiculo = ''; 435 $scope.notaPedido.vehiculo = '';
428 $scope.notaPedido.kilometros = ''; 436 $scope.notaPedido.kilometros = '';
429 $scope.notaPedido.costoUnitarioKmFlete = ''; 437 $scope.notaPedido.costoUnitarioKmFlete = '';
430 $scope.choferes = ''; 438 $scope.choferes = '';
431 $scope.vehiculos = ''; 439 $scope.vehiculos = '';
432 }; 440 };
433 441
434 $scope.limpiarPantalla = function() { 442 $scope.limpiarPantalla = function() {
435 $scope.limpiarFlete(); 443 $scope.limpiarFlete();
436 $scope.notaPedido.flete = '0'; 444 $scope.notaPedido.flete = '0';
437 $scope.notaPedido.bomba = '0'; 445 $scope.notaPedido.bomba = '0';
438 $scope.notaPedido.precioCondicion = ''; 446 $scope.notaPedido.precioCondicion = '';
439 $scope.articulosTabla = []; 447 $scope.articulosTabla = [];
440 $scope.notaPedido.vendedor.nombre = ''; 448 $scope.notaPedido.vendedor.nombre = '';
441 $scope.notaPedido.cliente = {nombre: ''}; 449 $scope.notaPedido.cliente = {nombre: ''};
442 $scope.notaPedido.domicilio = {dom: ''}; 450 $scope.notaPedido.domicilio = {dom: ''};
443 $scope.domiciliosCliente = []; 451 $scope.domiciliosCliente = [];
444 }; 452 };
445 453
446 $scope.resetFilter = function() { 454 $scope.resetFilter = function() {
447 $scope.articuloACargar = {}; 455 $scope.articuloACargar = {};
448 $scope.cargando = true; 456 $scope.cargando = true;
449 }; 457 };
450 458
451 $scope.selectFocus = function($event) { 459 $scope.selectFocus = function($event) {
452 $event.target.select(); 460 $event.target.select();
453 }; 461 };
454 462
455 $scope.salir = function() { 463 $scope.salir = function() {
456 $location.path('/'); 464 $location.path('/');
457 }; 465 };
458 466
459 function addCabecera(label, valor) { 467 function addCabecera(label, valor) {
460 var propiedad = $filter('filter')($scope.cabecera, {label: label}); 468 var propiedad = $filter('filter')($scope.cabecera, {label: label});
461 if(propiedad.length === 1) { 469 if(propiedad.length === 1) {
462 propiedad[0].valor = valor; 470 propiedad[0].valor = valor;
463 } else { 471 } else {
464 $scope.cabecera.push({label: label, valor: valor}); 472 $scope.cabecera.push({label: label, valor: valor});
465 } 473 }
466 } 474 }
467 475
468 function removeCabecera(label) { 476 function removeCabecera(label) {
469 var propiedad = $filter('filter')($scope.cabecera, {label: label}); 477 var propiedad = $filter('filter')($scope.cabecera, {label: label});
470 if(propiedad.length === 1){ 478 if(propiedad.length === 1){
471 $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); 479 $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1);
472 } 480 }
473 } 481 }
474 } 482 }
475 ] 483 ]
476 ) 484 )
477 .controller('notaPedidoListaCtrl', [ 485 .controller('notaPedidoListaCtrl', [
478 '$scope', 486 '$scope',
479 'crearNotaPedidoService', 487 'crearNotaPedidoService',
480 '$location', 488 '$location',
481 function($scope, crearNotaPedidoService, $location) { 489 function($scope, crearNotaPedidoService, $location) {
482 crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { 490 crearNotaPedidoService.obtenerNotaPedido().then(function(datos) {
483 $scope.notaPedidos = datos.data; 491 $scope.notaPedidos = datos.data;
484 }); 492 });
485 $scope.editar = function(notaPedido) { 493 $scope.editar = function(notaPedido) {
486 crearNotaPedidoService.setNotaPedido(notaPedido); 494 crearNotaPedidoService.setNotaPedido(notaPedido);
487 $location.path('/venta-nota-pedido/abm/'); 495 $location.path('/venta-nota-pedido/abm/');
488 }; 496 };
489 $scope.crearPedido = function() { 497 $scope.crearPedido = function() {
490 crearNotaPedidoService.clearNotaPedido(); 498 crearNotaPedidoService.clearNotaPedido();
491 $location.path('/venta-nota-pedido/abm/'); 499 $location.path('/venta-nota-pedido/abm/');
492 }; 500 };
493 } 501 }
494 ]) 502 ])
495 .controller('focaCrearNotaPedidoFichaClienteController', [ 503 .controller('focaCrearNotaPedidoFichaClienteController', [
496 '$scope', 504 '$scope',
497 'crearNotaPedidoService', 505 'crearNotaPedidoService',
498 '$location', 506 '$location',
499 function($scope, crearNotaPedidoService, $location) { 507 function($scope, crearNotaPedidoService, $location) {
500 crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { 508 crearNotaPedidoService.obtenerNotaPedido().then(function(datos) {
501 $scope.notaPedidos = datos.data; 509 $scope.notaPedidos = datos.data;
502 }); 510 });
503 $scope.editar = function(notaPedido) { 511 $scope.editar = function(notaPedido) {
504 crearNotaPedidoService.setNotaPedido(notaPedido); 512 crearNotaPedidoService.setNotaPedido(notaPedido);
505 $location.path('/venta-nota-pedido/abm/'); 513 $location.path('/venta-nota-pedido/abm/');
506 }; 514 };
507 $scope.crearPedido = function() { 515 $scope.crearPedido = function() {
508 crearNotaPedidoService.clearNotaPedido(); 516 crearNotaPedidoService.clearNotaPedido();
509 $location.path('/venta-nota-pedido/abm/'); 517 $location.path('/venta-nota-pedido/abm/');
510 }; 518 };
511 } 519 }
512 ]); 520 ]);
1 angular.module('focaCrearNotaPedido') 1 angular.module('focaCrearNotaPedido')
2 .service('crearNotaPedidoService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { 2 .service('crearNotaPedidoService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) {
3 var route = API_ENDPOINT.URL; 3 var route = API_ENDPOINT.URL;
4 return { 4 return {
5 crearNotaPedido: function(notaPedido) { 5 crearNotaPedido: function(notaPedido) {
6 return $http.post(route + '/nota-pedido', {notaPedido: notaPedido}); 6 return $http.post(route + '/nota-pedido', {notaPedido: notaPedido});
7 }, 7 },
8 obtenerNotaPedido: function() { 8 obtenerNotaPedido: function() {
9 return $http.get(route +'/nota-pedido'); 9 return $http.get(route +'/nota-pedido');
10 }, 10 },
11 setNotaPedido: function(notaPedido) { 11 setNotaPedido: function(notaPedido) {
12 this.notaPedido = notaPedido; 12 this.notaPedido = notaPedido;
13 }, 13 },
14 clearNotaPedido: function() { 14 clearNotaPedido: function() {
15 this.notaPedido = undefined; 15 this.notaPedido = undefined;
16 }, 16 },
17 getNotaPedido: function() { 17 getNotaPedido: function() {
18 return this.notaPedido; 18 return this.notaPedido;
19 }, 19 },
20 getArticulosByIdNotaPedido: function(id) { 20 getArticulosByIdNotaPedido: function(id) {
21 return $http.get(route+'/articulos/nota-pedido/'+id); 21 return $http.get(route+'/articulos/nota-pedido/'+id);
22 }, 22 },
23 crearArticulosParaNotaPedido: function(articuloNotaPedido) { 23 crearArticulosParaNotaPedido: function(articuloNotaPedido) {
24 return $http.post(route + '/articulos/nota-pedido', 24 return $http.post(route + '/articulos/nota-pedido',
25 {articuloNotaPedido: articuloNotaPedido}); 25 {articuloNotaPedido: articuloNotaPedido});
26 }, 26 },
27 getDomiciliosByIdNotaPedido: function(id) { 27 getDomiciliosByIdNotaPedido: function(id) {
28 return $http.get(route +'/nota-pedido/'+id+'/domicilios'); 28 return $http.get(route +'/nota-pedido/'+id+'/domicilios');
29 }, 29 },
30 getDomiciliosByIdCliente: function(id) { 30 getDomiciliosByIdCliente: function(id) {
31 var idTipoEntrega = 2;//Solo traigo los domicilios que tienen tipo 2 (tipo entrega) 31 var idTipoEntrega = 2;//Solo traigo los domicilios que tienen tipo 2 (tipo entrega)
32 return $http.get(route + '/domicilio/tipo/' + idTipoEntrega + '/cliente/' + id ); 32 return $http.get(route + '/domicilio/tipo/' + idTipoEntrega + '/cliente/' + id );
33 }, 33 },
34 getPrecioCondicion: function() { 34 getPrecioCondicion: function() {
35 return $http.get(route + '/precio-condicion'); 35 return $http.get(route + '/precio-condicion');
36 }, 36 },
37 getPrecioCondicionById: function(id) { 37 getPrecioCondicionById: function(id) {
38 return $http.get(route + '/precio-condicion/' + id); 38 return $http.get(route + '/precio-condicion/' + id);
39 }, 39 },
40 getPlazoPagoByPrecioCondicion: function(id) { 40 getPlazoPagoByPrecioCondicion: function(id) {
41 return $http.get(route + '/plazo-pago/precio-condicion/'+ id); 41 return $http.get(route + '/plazo-pago/precio-condicion/'+ id);
42 }, 42 },
43 crearFlete: function(flete) { 43 crearFlete: function(flete) {
44 return $http.post(route + '/flete', {flete : flete}); 44 return $http.post(route + '/flete', {flete : flete});
45 },
46 crearPlazosParaNotaPedido: function(plazos) {
47 return $http.post(route + '/plazo-pago/nota-pedido', plazos);
45 } 48 }
46 }; 49 };
47 }]); 50 }]);
48 51