Commit c67108edd7d28510802a5d107c10806109a2b0b0

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

agrego estados a la nota de pedido

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