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