Commit 3a15cf255e316118f31f8a00fa1763a96f01fab5
Exists in
master
Merge branch 'master' of https://debo.suite.repo/modulos-npm/foca-crear-nota-pedido
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', 'notaPedidoBusinessService', '$rootScope', | 4 | 'focaModalService', 'notaPedidoBusinessService', '$rootScope', 'focaSeguimientoService', |
5 | function( | 5 | function( |
6 | $scope, $uibModal, $location, $filter, crearNotaPedidoService, focaModalService, | 6 | $scope, $uibModal, $location, $filter, crearNotaPedidoService, focaModalService, |
7 | notaPedidoBusinessService, $rootScope | 7 | notaPedidoBusinessService, $rootScope, focaSeguimientoService |
8 | ) { | 8 | ) { |
9 | $scope.botonera = [ | 9 | $scope.botonera = [ |
10 | {texto: 'Vendedor', accion: function() { | 10 | {texto: 'Vendedor', accion: function() { |
11 | validarNotaRemitada($scope.seleccionarVendedor);}}, | 11 | validarNotaRemitada($scope.seleccionarVendedor);}}, |
12 | {texto: 'Cliente', accion: function() { | 12 | {texto: 'Cliente', accion: function() { |
13 | validarNotaRemitada($scope.seleccionarCliente);}}, | 13 | validarNotaRemitada($scope.seleccionarCliente);}}, |
14 | {texto: 'Proveedor', accion: function() { | 14 | {texto: 'Proveedor', accion: function() { |
15 | validarNotaRemitada($scope.seleccionarProveedor);}}, | 15 | validarNotaRemitada($scope.seleccionarProveedor);}}, |
16 | {texto: 'Moneda', accion: function() { | 16 | {texto: 'Moneda', accion: function() { |
17 | validarNotaRemitada($scope.abrirModalMoneda);}}, | 17 | validarNotaRemitada($scope.abrirModalMoneda);}}, |
18 | {texto: 'Precios y condiciones', accion: function() { | 18 | {texto: 'Precios y condiciones', accion: function() { |
19 | validarNotaRemitada($scope.abrirModalListaPrecio);}}, | 19 | validarNotaRemitada($scope.abrirModalListaPrecio);}}, |
20 | {texto: 'Flete', accion: function() { | 20 | {texto: 'Flete', accion: function() { |
21 | validarNotaRemitada($scope.abrirModalFlete);}}, | 21 | validarNotaRemitada($scope.abrirModalFlete);}}, |
22 | {texto: '', accion: function() {}}, | 22 | {texto: '', accion: function() {}}, |
23 | {texto: '', accion: function() {}} | 23 | {texto: '', accion: function() {}} |
24 | ]; | 24 | ]; |
25 | 25 | ||
26 | $scope.datepickerAbierto = false; | 26 | $scope.datepickerAbierto = false; |
27 | 27 | ||
28 | $scope.show = false; | 28 | $scope.show = false; |
29 | $scope.cargando = true; | 29 | $scope.cargando = true; |
30 | $scope.dateOptions = { | 30 | $scope.dateOptions = { |
31 | maxDate: new Date(), | 31 | maxDate: new Date(), |
32 | minDate: new Date(2010, 0, 1) | 32 | minDate: new Date(2010, 0, 1) |
33 | }; | 33 | }; |
34 | 34 | ||
35 | $scope.notaPedido = { | 35 | $scope.notaPedido = { |
36 | id: 0, | 36 | id: 0, |
37 | vendedor: {}, | 37 | vendedor: {}, |
38 | cliente: {}, | 38 | cliente: {}, |
39 | proveedor: {}, | 39 | proveedor: {}, |
40 | domicilio: {dom: ''}, | 40 | domicilio: {dom: ''}, |
41 | moneda: {}, | 41 | moneda: {}, |
42 | cotizacion: {} | 42 | cotizacion: {} |
43 | }; | 43 | }; |
44 | var monedaPorDefecto; | 44 | var monedaPorDefecto; |
45 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' | 45 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' |
46 | crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { | 46 | crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { |
47 | monedaPorDefecto = res.data[0]; | 47 | monedaPorDefecto = res.data[0]; |
48 | addCabecera('Moneda:', monedaPorDefecto.DETALLE); | 48 | addCabecera('Moneda:', monedaPorDefecto.DETALLE); |
49 | addCabecera('Fecha cotizacion:', | 49 | addCabecera('Fecha cotizacion:', |
50 | new Date(monedaPorDefecto.cotizaciones[0].FECHA).toLocaleDateString()); | 50 | new Date(monedaPorDefecto.cotizaciones[0].FECHA).toLocaleDateString()); |
51 | addCabecera('Cotizacion:', monedaPorDefecto.cotizaciones[0].VENDEDOR); | 51 | addCabecera('Cotizacion:', monedaPorDefecto.cotizaciones[0].VENDEDOR); |
52 | $scope.notaPedido.moneda = monedaPorDefecto; | 52 | $scope.notaPedido.moneda = monedaPorDefecto; |
53 | $scope.notaPedido.cotizacion = monedaPorDefecto.cotizaciones[0]; | 53 | $scope.notaPedido.cotizacion = monedaPorDefecto.cotizaciones[0]; |
54 | }); | 54 | }); |
55 | 55 | ||
56 | $scope.cabecera = []; | 56 | $scope.cabecera = []; |
57 | $scope.showCabecera = true; | 57 | $scope.showCabecera = true; |
58 | 58 | ||
59 | $scope.now = new Date(); | 59 | $scope.now = new Date(); |
60 | $scope.puntoVenta = '0000'; | 60 | $scope.puntoVenta = '0000'; |
61 | $scope.comprobante = '00000000'; | 61 | $scope.comprobante = '00000000'; |
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 | 72 | ||
73 | crearNotaPedidoService.getNumeroNotaPedido().then( | 73 | crearNotaPedidoService.getNumeroNotaPedido().then( |
74 | function(res) { | 74 | function(res) { |
75 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); | 75 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); |
76 | $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); | 76 | $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); |
77 | }, | 77 | }, |
78 | function(err) { | 78 | function(err) { |
79 | focaModalService.alert('La terminal no esta configurada correctamente'); | 79 | focaModalService.alert('La terminal no esta configurada correctamente'); |
80 | console.info(err); | 80 | console.info(err); |
81 | } | 81 | } |
82 | ); | 82 | ); |
83 | //La pantalla solo se usa para cargar pedidos | 83 | //La pantalla solo se usa para cargar pedidos |
84 | // if (notaPedidoTemp !== undefined) { | 84 | // if (notaPedidoTemp !== undefined) { |
85 | // notaPedidoTemp.fechaCarga = new Date(notaPedidoTemp.fechaCarga); | 85 | // notaPedidoTemp.fechaCarga = new Date(notaPedidoTemp.fechaCarga); |
86 | // $scope.notaPedido = notaPedidoTemp; | 86 | // $scope.notaPedido = notaPedidoTemp; |
87 | // $scope.notaPedido.flete = ($scope.notaPedido.flete).toString(); | 87 | // $scope.notaPedido.flete = ($scope.notaPedido.flete).toString(); |
88 | // $scope.notaPedido.bomba = ($scope.notaPedido.bomba).toString(); | 88 | // $scope.notaPedido.bomba = ($scope.notaPedido.bomba).toString(); |
89 | // $scope.idLista = $scope.notaPedido.precioCondicion; | 89 | // $scope.idLista = $scope.notaPedido.precioCondicion; |
90 | // crearNotaPedidoService | 90 | // crearNotaPedidoService |
91 | // .getArticulosByIdNotaPedido($scope.notaPedido.id).then( | 91 | // .getArticulosByIdNotaPedido($scope.notaPedido.id).then( |
92 | // function(res) { | 92 | // function(res) { |
93 | // $scope.articulosTabla = res.data; | 93 | // $scope.articulosTabla = res.data; |
94 | // } | 94 | // } |
95 | // ); | 95 | // ); |
96 | //TODO DOMICILIOS QUE SE CARGAN AL EDITAR NOTA DE PEDIDO | 96 | //TODO DOMICILIOS QUE SE CARGAN AL EDITAR NOTA DE PEDIDO |
97 | //(NO REQUERIDO EN ESTA VERSION) | 97 | //(NO REQUERIDO EN ESTA VERSION) |
98 | // crearNotaPedidoService.getDomiciliosByIdNotaPedido($scope.notaPedido.id).then( | 98 | // crearNotaPedidoService.getDomiciliosByIdNotaPedido($scope.notaPedido.id).then( |
99 | // function(res) { | 99 | // function(res) { |
100 | // $scope.notaPedido.domicilio = res.data; | 100 | // $scope.notaPedido.domicilio = res.data; |
101 | // } | 101 | // } |
102 | // ); | 102 | // ); |
103 | // } else { | 103 | // } else { |
104 | // $scope.notaPedido.fechaCarga = new Date(); | 104 | // $scope.notaPedido.fechaCarga = new Date(); |
105 | // $scope.notaPedido.bomba = '0'; | 105 | // $scope.notaPedido.bomba = '0'; |
106 | // $scope.notaPedido.flete = '0'; | 106 | // $scope.notaPedido.flete = '0'; |
107 | // $scope.idLista = undefined; | 107 | // $scope.idLista = undefined; |
108 | // } | 108 | // } |
109 | //TO DO - FUNCIONES PARA MULTIPLES DOMICILIOS NO IMPLEMENTADAS EN ESTA DEMO | 109 | //TO DO - FUNCIONES PARA MULTIPLES DOMICILIOS NO IMPLEMENTADAS EN ESTA DEMO |
110 | // $scope.addNewDom = function() { | 110 | // $scope.addNewDom = function() { |
111 | // $scope.notaPedido.domicilio.push({ 'id': 0 }); | 111 | // $scope.notaPedido.domicilio.push({ 'id': 0 }); |
112 | // }; | 112 | // }; |
113 | // $scope.removeNewChoice = function(choice) { | 113 | // $scope.removeNewChoice = function(choice) { |
114 | // if ($scope.notaPedido.domicilio.length > 1) { | 114 | // if ($scope.notaPedido.domicilio.length > 1) { |
115 | // $scope.notaPedido.domicilio.splice($scope.notaPedido.domicilio.findIndex( | 115 | // $scope.notaPedido.domicilio.splice($scope.notaPedido.domicilio.findIndex( |
116 | // function(c) { | 116 | // function(c) { |
117 | // return c.$$hashKey === choice.$$hashKey; | 117 | // return c.$$hashKey === choice.$$hashKey; |
118 | // } | 118 | // } |
119 | // ), 1); | 119 | // ), 1); |
120 | // } | 120 | // } |
121 | // }; | 121 | // }; |
122 | 122 | ||
123 | $scope.crearNotaPedido = function() { | 123 | $scope.crearNotaPedido = function() { |
124 | if(!$scope.notaPedido.vendedor.CodVen) { | 124 | if(!$scope.notaPedido.vendedor.CodVen) { |
125 | focaModalService.alert('Ingrese Vendedor'); | 125 | focaModalService.alert('Ingrese Vendedor'); |
126 | return; | 126 | return; |
127 | } else if(!$scope.notaPedido.cliente.COD) { | 127 | } else if(!$scope.notaPedido.cliente.COD) { |
128 | focaModalService.alert('Ingrese Cliente'); | 128 | focaModalService.alert('Ingrese Cliente'); |
129 | return; | 129 | return; |
130 | } else if(!$scope.notaPedido.proveedor.COD) { | 130 | } else if(!$scope.notaPedido.proveedor.COD) { |
131 | focaModalService.alert('Ingrese Proveedor'); | 131 | focaModalService.alert('Ingrese Proveedor'); |
132 | return; | 132 | return; |
133 | } else if(!$scope.notaPedido.moneda.ID) { | 133 | } else if(!$scope.notaPedido.moneda.ID) { |
134 | focaModalService.alert('Ingrese Moneda'); | 134 | focaModalService.alert('Ingrese Moneda'); |
135 | return; | 135 | return; |
136 | } else if(!$scope.notaPedido.cotizacion.ID) { | 136 | } else if(!$scope.notaPedido.cotizacion.ID) { |
137 | focaModalService.alert('Ingrese Cotización'); | 137 | focaModalService.alert('Ingrese Cotización'); |
138 | return; | 138 | return; |
139 | } else if(!$scope.plazosPagos) { | 139 | } else if(!$scope.plazosPagos) { |
140 | focaModalService.alert('Ingrese Precios y Condiciones'); | 140 | focaModalService.alert('Ingrese Precios y Condiciones'); |
141 | return; | 141 | return; |
142 | } else if( | 142 | } else if( |
143 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) | 143 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) |
144 | { | 144 | { |
145 | focaModalService.alert('Ingrese Flete'); | 145 | focaModalService.alert('Ingrese Flete'); |
146 | return; | 146 | return; |
147 | } else if(!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto | 147 | } else if(!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto |
148 | focaModalService.alert('Ingrese Domicilio'); | 148 | focaModalService.alert('Ingrese Domicilio'); |
149 | return; | 149 | return; |
150 | } else if($scope.articulosTabla.length === 0) { | 150 | } else if($scope.articulosTabla.length === 0) { |
151 | focaModalService.alert('Debe cargar al menos un articulo'); | 151 | focaModalService.alert('Debe cargar al menos un articulo'); |
152 | return; | 152 | return; |
153 | } | 153 | } |
154 | var date = new Date(); | 154 | var date = new Date(); |
155 | var notaPedido = { | 155 | var notaPedido = { |
156 | id: $scope.notaPedido.id, | 156 | id: $scope.notaPedido.id, |
157 | fechaCarga: new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) | 157 | fechaCarga: new Date(date.getTime() - (date.getTimezoneOffset() * 60000)) |
158 | .toISOString().slice(0, 19).replace('T', ' '), | 158 | .toISOString().slice(0, 19).replace('T', ' '), |
159 | idVendedor: $scope.notaPedido.vendedor.CodVen, | 159 | idVendedor: $scope.notaPedido.vendedor.CodVen, |
160 | idCliente: $scope.notaPedido.cliente.COD, | 160 | idCliente: $scope.notaPedido.cliente.COD, |
161 | nombreCliente: $scope.notaPedido.cliente.NOM, | 161 | nombreCliente: $scope.notaPedido.cliente.NOM, |
162 | cuitCliente: $scope.notaPedido.cliente.CUIT, | 162 | cuitCliente: $scope.notaPedido.cliente.CUIT, |
163 | idProveedor: $scope.notaPedido.proveedor.COD, | 163 | idProveedor: $scope.notaPedido.proveedor.COD, |
164 | idDomicilio: $scope.notaPedido.domicilio.id, | 164 | idDomicilio: $scope.notaPedido.domicilio.id, |
165 | idCotizacion: $scope.notaPedido.cotizacion.ID, | 165 | idCotizacion: $scope.notaPedido.cotizacion.ID, |
166 | idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, | 166 | idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, |
167 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 167 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
168 | flete: $scope.notaPedido.flete, | 168 | flete: $scope.notaPedido.flete, |
169 | fob: $scope.notaPedido.fob, | 169 | fob: $scope.notaPedido.fob, |
170 | bomba: $scope.notaPedido.bomba, | 170 | bomba: $scope.notaPedido.bomba, |
171 | kilometros: $scope.notaPedido.kilometros, | 171 | kilometros: $scope.notaPedido.kilometros, |
172 | domicilioStamp: $scope.notaPedido.domicilioStamp, | 172 | domicilioStamp: $scope.notaPedido.domicilioStamp, |
173 | estado: 0, | 173 | estado: 0, |
174 | total: $scope.getTotal() | 174 | total: $scope.getTotal() |
175 | }; | 175 | }; |
176 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( | 176 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( |
177 | function(data) { | 177 | function(data) { |
178 | notaPedidoBusinessService.addArticulos($scope.articulosTabla, | 178 | // Al guardar los datos de la nota de pedido logueamos la |
179 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); | 179 | // actividad para su seguimiento. |
180 | var plazos = $scope.plazosPagos; | 180 | focaSeguimientoService.guardarPosicion( |
181 | 181 | $scope.notaPedido.vendedor.codigo, | |
182 | for(var j = 0; j < plazos.length; j++) { | 182 | 'Nota de pedido', |
183 | 'Nº: ' + $filter('comprobante')([ | ||
184 | $scope.puntoVenta, | ||
185 | $scope.comprobante | ||
186 | ]) | ||
187 | ); | ||
188 | notaPedidoBusinessService.addArticulos($scope.articulosTabla, | ||
189 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); | ||
190 | var plazos = $scope.plazosPagos; | ||
191 | |||
192 | for(var j = 0; j < plazos.length; j++) { | ||
183 | var json = { | 193 | var json = { |
184 | idPedido: data.data.id, | 194 | idPedido: data.data.id, |
185 | dias: plazos[j].dias | 195 | dias: plazos[j].dias |
186 | }; | 196 | }; |
187 | crearNotaPedidoService.crearPlazosParaNotaPedido(json); | 197 | crearNotaPedidoService.crearPlazosParaNotaPedido(json); |
188 | } | 198 | } |
189 | notaPedidoBusinessService.addEstado(data.data.id, | 199 | notaPedidoBusinessService.addEstado(data.data.id, |
190 | $scope.notaPedido.vendedor.codigo); | 200 | $scope.notaPedido.vendedor.codigo); |
191 | 201 | ||
192 | focaModalService.alert('Nota pedido creada'); | 202 | focaModalService.alert('Nota pedido creada'); |
193 | $scope.cabecera = []; | 203 | $scope.cabecera = []; |
194 | addCabecera('Moneda:', $scope.notaPedido.moneda.detalle); | 204 | addCabecera('Moneda:', $scope.notaPedido.moneda.detalle); |
195 | addCabecera( | 205 | addCabecera( |
196 | 'Fecha cotizacion:', | 206 | 'Fecha cotizacion:', |
197 | $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy') | 207 | $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy') |
198 | ); | 208 | ); |
199 | addCabecera('Cotizacion:', $scope.notaPedido.cotizacion.VENDEDOR); | 209 | addCabecera('Cotizacion:', $scope.notaPedido.cotizacion.VENDEDOR); |
200 | $scope.notaPedido.vendedor = {}; | 210 | $scope.notaPedido.vendedor = {}; |
201 | $scope.notaPedido.cliente = {}; | 211 | $scope.notaPedido.cliente = {}; |
202 | $scope.notaPedido.proveedor = {}; | 212 | $scope.notaPedido.proveedor = {}; |
203 | $scope.notaPedido.domicilio = {}; | 213 | $scope.notaPedido.domicilio = {}; |
204 | $scope.notaPedido.flete = null; | 214 | $scope.notaPedido.flete = null; |
205 | $scope.notaPedido.fob = null; | 215 | $scope.notaPedido.fob = null; |
206 | $scope.notaPedido.bomba = null; | 216 | $scope.notaPedido.bomba = null; |
207 | $scope.notaPedido.kilometros = null; | 217 | $scope.notaPedido.kilometros = null; |
208 | $scope.articulosTabla = []; | 218 | $scope.articulosTabla = []; |
209 | }, | 219 | }, |
210 | function(error) { | 220 | function(error) { |
211 | focaModalService.alert('Hubo un error al crear la nota de pedido'); | 221 | focaModalService.alert('Hubo un error al crear la nota de pedido'); |
212 | console.info(error); | 222 | console.info(error); |
213 | } | 223 | } |
214 | ); | 224 | ); |
215 | }; | 225 | }; |
216 | 226 | ||
217 | $scope.seleccionarNotaPedido = function() { | 227 | $scope.seleccionarNotaPedido = function() { |
218 | var modalInstance = $uibModal.open( | 228 | var modalInstance = $uibModal.open( |
219 | { | 229 | { |
220 | ariaLabelledBy: 'Busqueda de Nota de Pedido', | 230 | ariaLabelledBy: 'Busqueda de Nota de Pedido', |
221 | templateUrl: 'foca-modal-nota-pedido.html', | 231 | templateUrl: 'foca-modal-nota-pedido.html', |
222 | controller: 'focaModalNotaPedidoController', | 232 | controller: 'focaModalNotaPedidoController', |
223 | size: 'lg' | 233 | size: 'lg' |
224 | } | 234 | } |
225 | ); | 235 | ); |
226 | modalInstance.result.then( | 236 | modalInstance.result.then( |
227 | function(notaPedido) { | 237 | function(notaPedido) { |
228 | //añado cabeceras | 238 | //añado cabeceras |
229 | $scope.notaPedido.id = notaPedido.id; | 239 | $scope.notaPedido.id = notaPedido.id; |
230 | removeCabecera('Moneda:'); | 240 | removeCabecera('Moneda:'); |
231 | removeCabecera('Fecha cotizacion:'); | 241 | removeCabecera('Fecha cotizacion:'); |
232 | removeCabecera('Cotizacion:'); | 242 | removeCabecera('Cotizacion:'); |
233 | var cabeceras = [ | 243 | var cabeceras = [ |
234 | { | 244 | { |
235 | label: 'Moneda', | 245 | label: 'Moneda', |
236 | valor: notaPedido.cotizacion[0].moneda[0].DETALLE | 246 | valor: notaPedido.cotizacion[0].moneda[0].DETALLE |
237 | }, | 247 | }, |
238 | { | 248 | { |
239 | label: 'Fecha cotizacion', | 249 | label: 'Fecha cotizacion', |
240 | valor: $filter('date')(notaPedido.cotizacion[0].FECHA, | 250 | valor: $filter('date')(notaPedido.cotizacion[0].FECHA, |
241 | 'dd/MM/yyyy') | 251 | 'dd/MM/yyyy') |
242 | }, | 252 | }, |
243 | { | 253 | { |
244 | label: 'Cotizacion', | 254 | label: 'Cotizacion', |
245 | valor: notaPedido.cotizacion[0].VENDEDOR | 255 | valor: notaPedido.cotizacion[0].VENDEDOR |
246 | }, | 256 | }, |
247 | { | 257 | { |
248 | label: 'Cliente:', | 258 | label: 'Cliente:', |
249 | valor: notaPedido.cliente[0].NOM | 259 | valor: notaPedido.cliente[0].NOM |
250 | }, | 260 | }, |
251 | { | 261 | { |
252 | label: 'Domicilio:', | 262 | label: 'Domicilio:', |
253 | valor: notaPedido.domicilioStamp | 263 | valor: notaPedido.domicilioStamp |
254 | }, | 264 | }, |
255 | { | 265 | { |
256 | label: 'Vendedor:', | 266 | label: 'Vendedor:', |
257 | valor: notaPedido.vendedor[0].NomVen | 267 | valor: notaPedido.vendedor[0].NomVen |
258 | }, | 268 | }, |
259 | { | 269 | { |
260 | label: 'Proveedor:', | 270 | label: 'Proveedor:', |
261 | valor: notaPedido.proveedor[0].NOM | 271 | valor: notaPedido.proveedor[0].NOM |
262 | }, | 272 | }, |
263 | { | 273 | { |
264 | label: 'Flete:', | 274 | label: 'Flete:', |
265 | valor: notaPedido.flete === 1 ? 'Si' : 'No' | 275 | valor: notaPedido.flete === 1 ? 'Si' : 'No' |
266 | }, | 276 | }, |
267 | { | 277 | { |
268 | label: 'FOB:', | 278 | label: 'FOB:', |
269 | valor: notaPedido.fob === 1 ? 'Si' : 'No' | 279 | valor: notaPedido.fob === 1 ? 'Si' : 'No' |
270 | }, | 280 | }, |
271 | { | 281 | { |
272 | label: 'Precio condicion:', | 282 | label: 'Precio condicion:', |
273 | valor: valorPrecioCondicion() | 283 | valor: valorPrecioCondicion() |
274 | } | 284 | } |
275 | ]; | 285 | ]; |
276 | //TODO MOSTRAR PLAZOS | 286 | //TODO MOSTRAR PLAZOS |
277 | function valorPrecioCondicion() { | 287 | function valorPrecioCondicion() { |
278 | if(notaPedido.idPrecioCondicion > 0) { | 288 | if(notaPedido.idPrecioCondicion > 0) { |
279 | return notaPedido.precioCondicion[0].nombre; | 289 | return notaPedido.precioCondicion[0].nombre; |
280 | } else { | 290 | } else { |
281 | return 'Ingreso Manual'; | 291 | return 'Ingreso Manual'; |
282 | } | 292 | } |
283 | } | 293 | } |
284 | 294 | ||
285 | if(notaPedido.flete === 1) { | 295 | if(notaPedido.flete === 1) { |
286 | var cabeceraBomba = { | 296 | var cabeceraBomba = { |
287 | label: 'Bomba', | 297 | label: 'Bomba', |
288 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' | 298 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' |
289 | }; | 299 | }; |
290 | if(notaPedido.kilometros) { | 300 | if(notaPedido.kilometros) { |
291 | var cabeceraKilometros = { | 301 | var cabeceraKilometros = { |
292 | label: 'Kilometros', | 302 | label: 'Kilometros', |
293 | valor: notaPedido.kilometros | 303 | valor: notaPedido.kilometros |
294 | }; | 304 | }; |
295 | cabeceras.push(cabeceraKilometros); | 305 | cabeceras.push(cabeceraKilometros); |
296 | } | 306 | } |
297 | cabeceras.push(cabeceraBomba); | 307 | cabeceras.push(cabeceraBomba); |
298 | } | 308 | } |
299 | $scope.articulosTabla = notaPedido.articulosNotaPedido; | 309 | $scope.articulosTabla = notaPedido.articulosNotaPedido; |
300 | if(notaPedido.precioCondicion.length > 0) { | 310 | if(notaPedido.precioCondicion.length > 0) { |
301 | $scope.idLista = notaPedido.precioCondicion[0].idListaPrecio; | 311 | $scope.idLista = notaPedido.precioCondicion[0].idListaPrecio; |
302 | } else { | 312 | } else { |
303 | $scope.idLista = -1; | 313 | $scope.idLista = -1; |
304 | } | 314 | } |
305 | $scope.comprobante = rellenar(notaPedido.numeroNotaPedido, 8); | 315 | $scope.comprobante = rellenar(notaPedido.numeroNotaPedido, 8); |
306 | $scope.notaPedido = notaPedido; | 316 | $scope.notaPedido = notaPedido; |
307 | $scope.notaPedido.vendedor = notaPedido.vendedor[0]; | 317 | $scope.notaPedido.vendedor = notaPedido.vendedor[0]; |
308 | $scope.notaPedido.cliente = notaPedido.cliente[0]; | 318 | $scope.notaPedido.cliente = notaPedido.cliente[0]; |
309 | $scope.notaPedido.proveedor = notaPedido.proveedor[0]; | 319 | $scope.notaPedido.proveedor = notaPedido.proveedor[0]; |
310 | $scope.notaPedido.moneda = notaPedido.cotizacion[0].moneda[0]; | 320 | $scope.notaPedido.moneda = notaPedido.cotizacion[0].moneda[0]; |
311 | $scope.notaPedido.cotizacion = notaPedido.cotizacion[0]; | 321 | $scope.notaPedido.cotizacion = notaPedido.cotizacion[0]; |
312 | $scope.plazosPagos = notaPedido.plazoPago; | 322 | $scope.plazosPagos = notaPedido.plazoPago; |
313 | addArrayCabecera(cabeceras); | 323 | addArrayCabecera(cabeceras); |
314 | 324 | ||
315 | }, function() { | 325 | }, function() { |
316 | // funcion ejecutada cuando se cancela el modal | 326 | // funcion ejecutada cuando se cancela el modal |
317 | } | 327 | } |
318 | ); | 328 | ); |
319 | } | 329 | } |
320 | 330 | ||
321 | $scope.seleccionarArticulo = function() { | 331 | $scope.seleccionarArticulo = function() { |
322 | if ($scope.idLista === undefined) { | 332 | if ($scope.idLista === undefined) { |
323 | focaModalService.alert( | 333 | focaModalService.alert( |
324 | 'Primero seleccione una lista de precio y condicion'); | 334 | 'Primero seleccione una lista de precio y condicion'); |
325 | return; | 335 | return; |
326 | } | 336 | } |
327 | var modalInstance = $uibModal.open( | 337 | var modalInstance = $uibModal.open( |
328 | { | 338 | { |
329 | ariaLabelledBy: 'Busqueda de Productos', | 339 | ariaLabelledBy: 'Busqueda de Productos', |
330 | templateUrl: 'modal-busqueda-productos.html', | 340 | templateUrl: 'modal-busqueda-productos.html', |
331 | controller: 'modalBusquedaProductosCtrl', | 341 | controller: 'modalBusquedaProductosCtrl', |
332 | resolve: { | 342 | resolve: { |
333 | parametroProducto: { | 343 | parametroProducto: { |
334 | idLista: $scope.idLista, | 344 | idLista: $scope.idLista, |
335 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 345 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
336 | simbolo: $scope.notaPedido.moneda.simbolo | 346 | simbolo: $scope.notaPedido.moneda.simbolo |
337 | } | 347 | } |
338 | }, | 348 | }, |
339 | size: 'lg' | 349 | size: 'lg' |
340 | } | 350 | } |
341 | ); | 351 | ); |
342 | modalInstance.result.then( | 352 | modalInstance.result.then( |
343 | function(producto) { | 353 | function(producto) { |
344 | var newArt = | 354 | var newArt = |
345 | { | 355 | { |
346 | id: 0, | 356 | id: 0, |
347 | codigo: producto.codigo, | 357 | codigo: producto.codigo, |
348 | sector: producto.sector, | 358 | sector: producto.sector, |
349 | sectorCodigo: producto.sector + '-' + producto.codigo, | 359 | sectorCodigo: producto.sector + '-' + producto.codigo, |
350 | descripcion: producto.descripcion, | 360 | descripcion: producto.descripcion, |
351 | item: $scope.articulosTabla.length + 1, | 361 | item: $scope.articulosTabla.length + 1, |
352 | nombre: producto.descripcion, | 362 | nombre: producto.descripcion, |
353 | precio: parseFloat(producto.precio.toFixed(4)), | 363 | precio: parseFloat(producto.precio.toFixed(4)), |
354 | costoUnitario: producto.costo, | 364 | costoUnitario: producto.costo, |
355 | editCantidad: false, | 365 | editCantidad: false, |
356 | editPrecio: false, | 366 | editPrecio: false, |
357 | rubro: producto.CodRub, | 367 | rubro: producto.CodRub, |
358 | exentoUnitario: producto.precio, | 368 | exentoUnitario: producto.precio, |
359 | ivaUnitario: producto.IMPIVA, | 369 | ivaUnitario: producto.IMPIVA, |
360 | impuestoInternoUnitario: producto.ImpInt, | 370 | impuestoInternoUnitario: producto.ImpInt, |
361 | impuestoInterno1Unitario: producto.ImpInt2, | 371 | impuestoInterno1Unitario: producto.ImpInt2, |
362 | impuestoInterno2Unitario: producto.ImpInt3, | 372 | impuestoInterno2Unitario: producto.ImpInt3, |
363 | precioLista: producto.precio, | 373 | precioLista: producto.precio, |
364 | combustible: 1, | 374 | combustible: 1, |
365 | facturado: 0 | 375 | facturado: 0 |
366 | }; | 376 | }; |
367 | $scope.articuloACargar = newArt; | 377 | $scope.articuloACargar = newArt; |
368 | $scope.cargando = false; | 378 | $scope.cargando = false; |
369 | }, function() { | 379 | }, function() { |
370 | // funcion ejecutada cuando se cancela el modal | 380 | // funcion ejecutada cuando se cancela el modal |
371 | } | 381 | } |
372 | ); | 382 | ); |
373 | }; | 383 | }; |
374 | 384 | ||
375 | $scope.seleccionarVendedor = function() { | 385 | $scope.seleccionarVendedor = function() { |
376 | var modalInstance = $uibModal.open( | 386 | var modalInstance = $uibModal.open( |
377 | { | 387 | { |
378 | ariaLabelledBy: 'Busqueda de Vendedores', | 388 | ariaLabelledBy: 'Busqueda de Vendedores', |
379 | templateUrl: 'modal-vendedores.html', | 389 | templateUrl: 'modal-vendedores.html', |
380 | controller: 'modalVendedoresCtrl', | 390 | controller: 'modalVendedoresCtrl', |
381 | size: 'lg' | 391 | size: 'lg' |
382 | } | 392 | } |
383 | ); | 393 | ); |
384 | modalInstance.result.then( | 394 | modalInstance.result.then( |
385 | function(vendedor) { | 395 | function(vendedor) { |
386 | addCabecera('Vendedor:', vendedor.NomVen); | 396 | addCabecera('Vendedor:', vendedor.NomVen); |
387 | $scope.notaPedido.vendedor = vendedor; | 397 | $scope.notaPedido.vendedor = vendedor; |
388 | }, function() { | 398 | }, function() { |
389 | 399 | ||
390 | } | 400 | } |
391 | ); | 401 | ); |
392 | }; | 402 | }; |
393 | 403 | ||
394 | $scope.seleccionarProveedor = function() { | 404 | $scope.seleccionarProveedor = function() { |
395 | var modalInstance = $uibModal.open( | 405 | var modalInstance = $uibModal.open( |
396 | { | 406 | { |
397 | ariaLabelledBy: 'Busqueda de Proveedor', | 407 | ariaLabelledBy: 'Busqueda de Proveedor', |
398 | templateUrl: 'modal-proveedor.html', | 408 | templateUrl: 'modal-proveedor.html', |
399 | controller: 'focaModalProveedorCtrl', | 409 | controller: 'focaModalProveedorCtrl', |
400 | size: 'lg', | 410 | size: 'lg', |
401 | resolve: { | 411 | resolve: { |
402 | transportista: function() { | 412 | transportista: function() { |
403 | return false; | 413 | return false; |
404 | } | 414 | } |
405 | } | 415 | } |
406 | } | 416 | } |
407 | ); | 417 | ); |
408 | modalInstance.result.then( | 418 | modalInstance.result.then( |
409 | function(proveedor) { | 419 | function(proveedor) { |
410 | $scope.notaPedido.proveedor = proveedor; | 420 | $scope.notaPedido.proveedor = proveedor; |
411 | addCabecera('Proveedor:', proveedor.NOM); | 421 | addCabecera('Proveedor:', proveedor.NOM); |
412 | }, function() { | 422 | }, function() { |
413 | 423 | ||
414 | } | 424 | } |
415 | ); | 425 | ); |
416 | }; | 426 | }; |
417 | 427 | ||
418 | $scope.seleccionarCliente = function() { | 428 | $scope.seleccionarCliente = function() { |
419 | 429 | ||
420 | var modalInstance = $uibModal.open( | 430 | var modalInstance = $uibModal.open( |
421 | { | 431 | { |
422 | ariaLabelledBy: 'Busqueda de Cliente', | 432 | ariaLabelledBy: 'Busqueda de Cliente', |
423 | templateUrl: 'foca-busqueda-cliente-modal.html', | 433 | templateUrl: 'foca-busqueda-cliente-modal.html', |
424 | controller: 'focaBusquedaClienteModalController', | 434 | controller: 'focaBusquedaClienteModalController', |
425 | size: 'lg' | 435 | size: 'lg' |
426 | } | 436 | } |
427 | ); | 437 | ); |
428 | modalInstance.result.then( | 438 | modalInstance.result.then( |
429 | function(cliente) { | 439 | function(cliente) { |
430 | $scope.abrirModalDomicilios(cliente); | 440 | $scope.abrirModalDomicilios(cliente); |
431 | }, function() { | 441 | }, function() { |
432 | 442 | ||
433 | } | 443 | } |
434 | ); | 444 | ); |
435 | }; | 445 | }; |
436 | 446 | ||
437 | $scope.abrirModalDomicilios = function(cliente) { | 447 | $scope.abrirModalDomicilios = function(cliente) { |
438 | var modalInstanceDomicilio = $uibModal.open( | 448 | var modalInstanceDomicilio = $uibModal.open( |
439 | { | 449 | { |
440 | ariaLabelledBy: 'Busqueda de Domicilios', | 450 | ariaLabelledBy: 'Busqueda de Domicilios', |
441 | templateUrl: 'modal-domicilio.html', | 451 | templateUrl: 'modal-domicilio.html', |
442 | controller: 'focaModalDomicilioController', | 452 | controller: 'focaModalDomicilioController', |
443 | resolve: { idCliente: function() { return cliente.cod; }}, | 453 | resolve: { idCliente: function() { return cliente.cod; }}, |
444 | size: 'lg', | 454 | size: 'lg', |
445 | } | 455 | } |
446 | ); | 456 | ); |
447 | modalInstanceDomicilio.result.then( | 457 | modalInstanceDomicilio.result.then( |
448 | function(domicilio) { | 458 | function(domicilio) { |
449 | $scope.notaPedido.domicilio = domicilio; | 459 | $scope.notaPedido.domicilio = domicilio; |
450 | $scope.notaPedido.cliente = { | 460 | $scope.notaPedido.cliente = { |
451 | COD: cliente.cod, | 461 | COD: cliente.cod, |
452 | CUIT: cliente.cuit, | 462 | CUIT: cliente.cuit, |
453 | NOM: cliente.nom | 463 | NOM: cliente.nom |
454 | }; | 464 | }; |
455 | addCabecera('Cliente:', cliente.nom); | 465 | addCabecera('Cliente:', cliente.nom); |
456 | var domicilioStamp = | 466 | var domicilioStamp = |
457 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + | 467 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + |
458 | domicilio.Localidad + ', ' + domicilio.Provincia; | 468 | domicilio.Localidad + ', ' + domicilio.Provincia; |
459 | $scope.notaPedido.domicilioStamp = domicilioStamp; | 469 | $scope.notaPedido.domicilioStamp = domicilioStamp; |
460 | addCabecera('Domicilio:', domicilioStamp); | 470 | addCabecera('Domicilio:', domicilioStamp); |
461 | }, function() { | 471 | }, function() { |
462 | $scope.seleccionarCliente(); | 472 | $scope.seleccionarCliente(); |
463 | return; | 473 | return; |
464 | } | 474 | } |
465 | ); | 475 | ); |
466 | }; | 476 | }; |
467 | 477 | ||
468 | $scope.mostrarFichaCliente = function() { | 478 | $scope.mostrarFichaCliente = function() { |
469 | $uibModal.open( | 479 | $uibModal.open( |
470 | { | 480 | { |
471 | ariaLabelledBy: 'Datos del Cliente', | 481 | ariaLabelledBy: 'Datos del Cliente', |
472 | templateUrl: 'foca-crear-nota-pedido-ficha-cliente.html', | 482 | templateUrl: 'foca-crear-nota-pedido-ficha-cliente.html', |
473 | controller: 'focaCrearNotaPedidoFichaClienteController', | 483 | controller: 'focaCrearNotaPedidoFichaClienteController', |
474 | size: 'lg' | 484 | size: 'lg' |
475 | } | 485 | } |
476 | ); | 486 | ); |
477 | }; | 487 | }; |
478 | 488 | ||
479 | $scope.getTotal = function() { | 489 | $scope.getTotal = function() { |
480 | var total = 0; | 490 | var total = 0; |
481 | var arrayTempArticulos = $scope.articulosTabla; | 491 | var arrayTempArticulos = $scope.articulosTabla; |
482 | for (var i = 0; i < arrayTempArticulos.length; i++) { | 492 | for (var i = 0; i < arrayTempArticulos.length; i++) { |
483 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | 493 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; |
484 | } | 494 | } |
485 | return parseFloat(total.toFixed(2)); | 495 | return parseFloat(total.toFixed(2)); |
486 | }; | 496 | }; |
487 | 497 | ||
488 | $scope.getSubTotal = function() { | 498 | $scope.getSubTotal = function() { |
489 | if($scope.articuloACargar) { | 499 | if($scope.articuloACargar) { |
490 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; | 500 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
491 | } | 501 | } |
492 | }; | 502 | }; |
493 | 503 | ||
494 | $scope.abrirModalListaPrecio = function() { | 504 | $scope.abrirModalListaPrecio = function() { |
495 | var modalInstance = $uibModal.open( | 505 | var modalInstance = $uibModal.open( |
496 | { | 506 | { |
497 | ariaLabelledBy: 'Busqueda de Precio Condición', | 507 | ariaLabelledBy: 'Busqueda de Precio Condición', |
498 | templateUrl: 'modal-precio-condicion.html', | 508 | templateUrl: 'modal-precio-condicion.html', |
499 | controller: 'focaModalPrecioCondicionController', | 509 | controller: 'focaModalPrecioCondicionController', |
500 | size: 'lg' | 510 | size: 'lg' |
501 | } | 511 | } |
502 | ); | 512 | ); |
503 | modalInstance.result.then( | 513 | modalInstance.result.then( |
504 | function(precioCondicion) { | 514 | function(precioCondicion) { |
505 | var cabecera = ''; | 515 | var cabecera = ''; |
506 | var plazosConcat = ''; | 516 | var plazosConcat = ''; |
507 | if(!Array.isArray(precioCondicion)) { | 517 | if(!Array.isArray(precioCondicion)) { |
508 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; | 518 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; |
509 | $scope.plazosPagos = precioCondicion.plazoPago; | 519 | $scope.plazosPagos = precioCondicion.plazoPago; |
510 | $scope.idLista = precioCondicion.idListaPrecio; | 520 | $scope.idLista = precioCondicion.idListaPrecio; |
511 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { | 521 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { |
512 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; | 522 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; |
513 | } | 523 | } |
514 | cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); | 524 | cabecera = precioCondicion.nombre + ' ' + plazosConcat.trim(); |
515 | } else { //Cuando se ingresan los plazos manualmente | 525 | } else { //Cuando se ingresan los plazos manualmente |
516 | $scope.notaPedido.idPrecioCondicion = 0; | 526 | $scope.notaPedido.idPrecioCondicion = 0; |
517 | $scope.idLista = -1; //-1, el modal productos busca todos los productos | 527 | $scope.idLista = -1; //-1, el modal productos busca todos los productos |
518 | $scope.plazosPagos = precioCondicion; | 528 | $scope.plazosPagos = precioCondicion; |
519 | for(var j = 0; j < precioCondicion.length; j++) { | 529 | for(var j = 0; j < precioCondicion.length; j++) { |
520 | plazosConcat += precioCondicion[j].dias + ' '; | 530 | plazosConcat += precioCondicion[j].dias + ' '; |
521 | } | 531 | } |
522 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); | 532 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); |
523 | } | 533 | } |
524 | $scope.articulosTabla = []; | 534 | $scope.articulosTabla = []; |
525 | addCabecera('Precios y condiciones:', cabecera); | 535 | addCabecera('Precios y condiciones:', cabecera); |
526 | }, function() { | 536 | }, function() { |
527 | 537 | ||
528 | } | 538 | } |
529 | ); | 539 | ); |
530 | }; | 540 | }; |
531 | 541 | ||
532 | $scope.abrirModalFlete = function() { | 542 | $scope.abrirModalFlete = function() { |
533 | var modalInstance = $uibModal.open( | 543 | var modalInstance = $uibModal.open( |
534 | { | 544 | { |
535 | ariaLabelledBy: 'Busqueda de Flete', | 545 | ariaLabelledBy: 'Busqueda de Flete', |
536 | templateUrl: 'modal-flete.html', | 546 | templateUrl: 'modal-flete.html', |
537 | controller: 'focaModalFleteController', | 547 | controller: 'focaModalFleteController', |
538 | size: 'lg', | 548 | size: 'lg', |
539 | resolve: { | 549 | resolve: { |
540 | parametrosFlete: | 550 | parametrosFlete: |
541 | function() { | 551 | function() { |
542 | return { | 552 | return { |
543 | flete: $scope.notaPedido.flete ? '1' : | 553 | flete: $scope.notaPedido.flete ? '1' : |
544 | ($scope.notaPedido.fob ? 'FOB' : | 554 | ($scope.notaPedido.fob ? 'FOB' : |
545 | ($scope.notaPedido.flete === undefined ? null : '0')), | 555 | ($scope.notaPedido.flete === undefined ? null : '0')), |
546 | bomba: $scope.notaPedido.bomba ? '1' : | 556 | bomba: $scope.notaPedido.bomba ? '1' : |
547 | ($scope.notaPedido.bomba === undefined ? null : '0'), | 557 | ($scope.notaPedido.bomba === undefined ? null : '0'), |
548 | kilometros: $scope.notaPedido.kilometros | 558 | kilometros: $scope.notaPedido.kilometros |
549 | }; | 559 | }; |
550 | } | 560 | } |
551 | } | 561 | } |
552 | } | 562 | } |
553 | ); | 563 | ); |
554 | modalInstance.result.then( | 564 | modalInstance.result.then( |
555 | function(datos) { | 565 | function(datos) { |
556 | $scope.notaPedido.flete = datos.flete; | 566 | $scope.notaPedido.flete = datos.flete; |
557 | $scope.notaPedido.fob = datos.FOB; | 567 | $scope.notaPedido.fob = datos.FOB; |
558 | $scope.notaPedido.bomba = datos.bomba; | 568 | $scope.notaPedido.bomba = datos.bomba; |
559 | $scope.notaPedido.kilometros = datos.kilometros; | 569 | $scope.notaPedido.kilometros = datos.kilometros; |
560 | 570 | ||
561 | addCabecera('Flete:', datos.flete ? 'Si' : | 571 | addCabecera('Flete:', datos.flete ? 'Si' : |
562 | ($scope.notaPedido.fob ? 'FOB' : 'No')); | 572 | ($scope.notaPedido.fob ? 'FOB' : 'No')); |
563 | if(datos.flete) { | 573 | if(datos.flete) { |
564 | addCabecera('Bomba:', datos.bomba ? 'Si' : 'No'); | 574 | addCabecera('Bomba:', datos.bomba ? 'Si' : 'No'); |
565 | addCabecera('Kilometros:', datos.kilometros); | 575 | addCabecera('Kilometros:', datos.kilometros); |
566 | } else { | 576 | } else { |
567 | removeCabecera('Bomba:'); | 577 | removeCabecera('Bomba:'); |
568 | removeCabecera('Kilometros:'); | 578 | removeCabecera('Kilometros:'); |
569 | $scope.notaPedido.fob = false; | 579 | $scope.notaPedido.fob = false; |
570 | $scope.notaPedido.bomba = false; | 580 | $scope.notaPedido.bomba = false; |
571 | $scope.notaPedido.kilometros = null; | 581 | $scope.notaPedido.kilometros = null; |
572 | } | 582 | } |
573 | }, function() { | 583 | }, function() { |
574 | 584 | ||
575 | } | 585 | } |
576 | ); | 586 | ); |
577 | }; | 587 | }; |
578 | 588 | ||
579 | $scope.abrirModalMoneda = function() { | 589 | $scope.abrirModalMoneda = function() { |
580 | var modalInstance = $uibModal.open( | 590 | var modalInstance = $uibModal.open( |
581 | { | 591 | { |
582 | ariaLabelledBy: 'Busqueda de Moneda', | 592 | ariaLabelledBy: 'Busqueda de Moneda', |
583 | templateUrl: 'modal-moneda.html', | 593 | templateUrl: 'modal-moneda.html', |
584 | controller: 'focaModalMonedaController', | 594 | controller: 'focaModalMonedaController', |
585 | size: 'lg' | 595 | size: 'lg' |
586 | } | 596 | } |
587 | ); | 597 | ); |
588 | modalInstance.result.then( | 598 | modalInstance.result.then( |
589 | function(moneda) { | 599 | function(moneda) { |
590 | $scope.abrirModalCotizacion(moneda); | 600 | $scope.abrirModalCotizacion(moneda); |
591 | }, function() { | 601 | }, function() { |
592 | 602 | ||
593 | } | 603 | } |
594 | ); | 604 | ); |
595 | }; | 605 | }; |
596 | 606 | ||
597 | $scope.abrirModalCotizacion = function(moneda) { | 607 | $scope.abrirModalCotizacion = function(moneda) { |
598 | var modalInstance = $uibModal.open( | 608 | var modalInstance = $uibModal.open( |
599 | { | 609 | { |
600 | ariaLabelledBy: 'Busqueda de Cotización', | 610 | ariaLabelledBy: 'Busqueda de Cotización', |
601 | templateUrl: 'modal-cotizacion.html', | 611 | templateUrl: 'modal-cotizacion.html', |
602 | controller: 'focaModalCotizacionController', | 612 | controller: 'focaModalCotizacionController', |
603 | size: 'lg', | 613 | size: 'lg', |
604 | resolve: {idMoneda: function() {return moneda.ID;}} | 614 | resolve: {idMoneda: function() {return moneda.ID;}} |
605 | } | 615 | } |
606 | ); | 616 | ); |
607 | modalInstance.result.then( | 617 | modalInstance.result.then( |
608 | function(cotizacion) { | 618 | function(cotizacion) { |
609 | var articulosTablaTemp = $scope.articulosTabla; | 619 | var articulosTablaTemp = $scope.articulosTabla; |
610 | for(var i = 0; i < articulosTablaTemp.length; i++) { | 620 | for(var i = 0; i < articulosTablaTemp.length; i++) { |
611 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * | 621 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * |
612 | $scope.notaPedido.cotizacion.VENDEDOR; | 622 | $scope.notaPedido.cotizacion.VENDEDOR; |
613 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / | 623 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / |
614 | cotizacion.VENDEDOR; | 624 | cotizacion.VENDEDOR; |
615 | } | 625 | } |
616 | $scope.articulosTabla = articulosTablaTemp; | 626 | $scope.articulosTabla = articulosTablaTemp; |
617 | $scope.notaPedido.moneda = moneda; | 627 | $scope.notaPedido.moneda = moneda; |
618 | $scope.notaPedido.cotizacion = cotizacion; | 628 | $scope.notaPedido.cotizacion = cotizacion; |
619 | addCabecera('Moneda:', moneda.DETALLE); | 629 | addCabecera('Moneda:', moneda.DETALLE); |
620 | addCabecera( | 630 | addCabecera( |
621 | 'Fecha cotizacion:', | 631 | 'Fecha cotizacion:', |
622 | $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 632 | $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') |
623 | ); | 633 | ); |
624 | addCabecera('Cotizacion:', cotizacion.VENDEDOR); | 634 | addCabecera('Cotizacion:', cotizacion.VENDEDOR); |
625 | }, function() { | 635 | }, function() { |
626 | 636 | ||
627 | } | 637 | } |
628 | ); | 638 | ); |
629 | }; | 639 | }; |
630 | 640 | ||
631 | $scope.agregarATabla = function(key) { | 641 | $scope.agregarATabla = function(key) { |
632 | if(key === 13) { | 642 | if(key === 13) { |
633 | if($scope.articuloACargar.cantidad === undefined || | 643 | if($scope.articuloACargar.cantidad === undefined || |
634 | $scope.articuloACargar.cantidad === 0 || | 644 | $scope.articuloACargar.cantidad === 0 || |
635 | $scope.articuloACargar.cantidad === null ) { | 645 | $scope.articuloACargar.cantidad === null ) { |
636 | focaModalService.alert('El valor debe ser al menos 1'); | 646 | focaModalService.alert('El valor debe ser al menos 1'); |
637 | return; | 647 | return; |
638 | } | 648 | } |
639 | delete $scope.articuloACargar.sectorCodigo; | 649 | delete $scope.articuloACargar.sectorCodigo; |
640 | $scope.articulosTabla.push($scope.articuloACargar); | 650 | $scope.articulosTabla.push($scope.articuloACargar); |
641 | $scope.cargando = true; | 651 | $scope.cargando = true; |
642 | } | 652 | } |
643 | }; | 653 | }; |
644 | 654 | ||
645 | $scope.quitarArticulo = function(key) { | 655 | $scope.quitarArticulo = function(key) { |
646 | $scope.articulosTabla.splice(key, 1); | 656 | $scope.articulosTabla.splice(key, 1); |
647 | }; | 657 | }; |
648 | 658 | ||
649 | $scope.editarArticulo = function(key, articulo) { | 659 | $scope.editarArticulo = function(key, articulo) { |
650 | if(key === 13) { | 660 | if(key === 13) { |
651 | if(articulo.cantidad === null || articulo.cantidad === 0 || | 661 | if(articulo.cantidad === null || articulo.cantidad === 0 || |
652 | articulo.cantidad === undefined) { | 662 | articulo.cantidad === undefined) { |
653 | focaModalService.alert('El valor debe ser al menos 1'); | 663 | focaModalService.alert('El valor debe ser al menos 1'); |
654 | return; | 664 | return; |
655 | } | 665 | } |
656 | articulo.editCantidad = false; | 666 | articulo.editCantidad = false; |
657 | articulo.editPrecio = false; | 667 | articulo.editPrecio = false; |
658 | } | 668 | } |
659 | }; | 669 | }; |
660 | 670 | ||
661 | $scope.cambioEdit = function(articulo, propiedad) { | 671 | $scope.cambioEdit = function(articulo, propiedad) { |
662 | if(propiedad === 'cantidad') { | 672 | if(propiedad === 'cantidad') { |
663 | articulo.editCantidad = true; | 673 | articulo.editCantidad = true; |
664 | } else if(propiedad === 'precio') { | 674 | } else if(propiedad === 'precio') { |
665 | articulo.editPrecio = true; | 675 | articulo.editPrecio = true; |
666 | } | 676 | } |
667 | }; | 677 | }; |
668 | 678 | ||
669 | $scope.limpiarFlete = function() { | 679 | $scope.limpiarFlete = function() { |
670 | $scope.notaPedido.fleteNombre = ''; | 680 | $scope.notaPedido.fleteNombre = ''; |
671 | $scope.notaPedido.chofer = ''; | 681 | $scope.notaPedido.chofer = ''; |
672 | $scope.notaPedido.vehiculo = ''; | 682 | $scope.notaPedido.vehiculo = ''; |
673 | $scope.notaPedido.kilometros = ''; | 683 | $scope.notaPedido.kilometros = ''; |
674 | $scope.notaPedido.costoUnitarioKmFlete = ''; | 684 | $scope.notaPedido.costoUnitarioKmFlete = ''; |
675 | $scope.choferes = ''; | 685 | $scope.choferes = ''; |
676 | $scope.vehiculos = ''; | 686 | $scope.vehiculos = ''; |
677 | }; | 687 | }; |
678 | 688 | ||
679 | $scope.limpiarPantalla = function() { | 689 | $scope.limpiarPantalla = function() { |
680 | $scope.limpiarFlete(); | 690 | $scope.limpiarFlete(); |
681 | $scope.notaPedido.flete = '0'; | 691 | $scope.notaPedido.flete = '0'; |
682 | $scope.notaPedido.bomba = '0'; | 692 | $scope.notaPedido.bomba = '0'; |
683 | $scope.notaPedido.precioCondicion = ''; | 693 | $scope.notaPedido.precioCondicion = ''; |
684 | $scope.articulosTabla = []; | 694 | $scope.articulosTabla = []; |
685 | $scope.notaPedido.vendedor.nombre = ''; | 695 | $scope.notaPedido.vendedor.nombre = ''; |
686 | $scope.notaPedido.cliente = {nombre: ''}; | 696 | $scope.notaPedido.cliente = {nombre: ''}; |
687 | $scope.notaPedido.domicilio = {dom: ''}; | 697 | $scope.notaPedido.domicilio = {dom: ''}; |
688 | $scope.domiciliosCliente = []; | 698 | $scope.domiciliosCliente = []; |
689 | }; | 699 | }; |
690 | 700 | ||
691 | $scope.resetFilter = function() { | 701 | $scope.resetFilter = function() { |
692 | $scope.articuloACargar = {}; | 702 | $scope.articuloACargar = {}; |
693 | $scope.cargando = true; | 703 | $scope.cargando = true; |
694 | }; | 704 | }; |
695 | //Recibe aviso si el teclado está en uso | 705 | //Recibe aviso si el teclado está en uso |
696 | $rootScope.$on('usarTeclado', function(event, data) { | 706 | $rootScope.$on('usarTeclado', function(event, data) { |
697 | if(data) { | 707 | if(data) { |
698 | $scope.mostrarTeclado = true; | 708 | $scope.mostrarTeclado = true; |
699 | return; | 709 | return; |
700 | } | 710 | } |
701 | $scope.mostrarTeclado = false; | 711 | $scope.mostrarTeclado = false; |
702 | }); | 712 | }); |
703 | 713 | ||
704 | $scope.selectFocus = function($event) { | 714 | $scope.selectFocus = function($event) { |
705 | // Si el teclado esta en uso no selecciona el valor | 715 | // Si el teclado esta en uso no selecciona el valor |
706 | if($scope.mostrarTeclado) { | 716 | if($scope.mostrarTeclado) { |
707 | return; | 717 | return; |
708 | } | 718 | } |
709 | $event.target.select(); | 719 | $event.target.select(); |
710 | }; | 720 | }; |
711 | 721 | ||
712 | $scope.salir = function() { | 722 | $scope.salir = function() { |
713 | $location.path('/'); | 723 | $location.path('/'); |
714 | }; | 724 | }; |
715 | 725 | ||
716 | $scope.parsearATexto = function(articulo) { | 726 | $scope.parsearATexto = function(articulo) { |
717 | articulo.cantidad = parseFloat(articulo.cantidad); | 727 | articulo.cantidad = parseFloat(articulo.cantidad); |
718 | articulo.precio = parseFloat(articulo.precio); | 728 | articulo.precio = parseFloat(articulo.precio); |
719 | }; | 729 | }; |
720 | 730 | ||
721 | function addArrayCabecera(array) { | 731 | function addArrayCabecera(array) { |
722 | for(var i = 0; i < array.length; i++) { | 732 | for(var i = 0; i < array.length; i++) { |
723 | addCabecera(array[i].label, array[i].valor); | 733 | addCabecera(array[i].label, array[i].valor); |
724 | } | 734 | } |
725 | } | 735 | } |
726 | 736 | ||
727 | function addCabecera(label, valor) { | 737 | function addCabecera(label, valor) { |
728 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); | 738 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); |
729 | if(propiedad.length === 1) { | 739 | if(propiedad.length === 1) { |
730 | propiedad[0].valor = valor; | 740 | propiedad[0].valor = valor; |
731 | } else { | 741 | } else { |
732 | $scope.cabecera.push({label: label, valor: valor}); | 742 | $scope.cabecera.push({label: label, valor: valor}); |
733 | } | 743 | } |
734 | } | 744 | } |
735 | 745 | ||
736 | function removeCabecera(label) { | 746 | function removeCabecera(label) { |
737 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); | 747 | var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); |
738 | if(propiedad.length === 1) { | 748 | if(propiedad.length === 1) { |
739 | $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); | 749 | $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); |
740 | } | 750 | } |
741 | } | 751 | } |
742 | 752 | ||
743 | function rellenar(relleno, longitud) { | 753 | function rellenar(relleno, longitud) { |
744 | relleno = '' + relleno; | 754 | relleno = '' + relleno; |
745 | while (relleno.length < longitud) { | 755 | while (relleno.length < longitud) { |
746 | relleno = '0' + relleno; | 756 | relleno = '0' + relleno; |
747 | } | 757 | } |
748 | 758 | ||
749 | return relleno; | 759 | return relleno; |
750 | } | 760 | } |
751 | 761 | ||
752 | function validarNotaRemitada(funcion) { | 762 | function validarNotaRemitada(funcion) { |
753 | if($scope.notaPedido.idRemito) { | 763 | if($scope.notaPedido.idRemito) { |
754 | focaModalService.alert('No se puede editar una nota de pedido remitada'); | 764 | focaModalService.alert('No se puede editar una nota de pedido remitada'); |
755 | } | 765 | } |
756 | else { | 766 | else { |
757 | funcion(); | 767 | funcion(); |
758 | } | 768 | } |
759 | } | 769 | } |
760 | } | 770 | } |
761 | ] | 771 | ] |
762 | ) | 772 | ) |
763 | .controller('notaPedidoListaCtrl', [ | 773 | .controller('notaPedidoListaCtrl', [ |
764 | '$scope', | 774 | '$scope', |
765 | 'crearNotaPedidoService', | 775 | 'crearNotaPedidoService', |
766 | '$location', | 776 | '$location', |
767 | function($scope, crearNotaPedidoService, $location) { | 777 | function($scope, crearNotaPedidoService, $location) { |
768 | crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { | 778 | crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { |
769 | $scope.notaPedidos = datos.data; | 779 | $scope.notaPedidos = datos.data; |
770 | }); | 780 | }); |
771 | $scope.editar = function(notaPedido) { | 781 | $scope.editar = function(notaPedido) { |
772 | crearNotaPedidoService.setNotaPedido(notaPedido); | 782 | crearNotaPedidoService.setNotaPedido(notaPedido); |
773 | $location.path('/venta-nota-pedido/abm/'); | 783 | $location.path('/venta-nota-pedido/abm/'); |
774 | }; | 784 | }; |
775 | $scope.crearPedido = function() { | 785 | $scope.crearPedido = function() { |
776 | crearNotaPedidoService.clearNotaPedido(); | 786 | crearNotaPedidoService.clearNotaPedido(); |
777 | $location.path('/venta-nota-pedido/abm/'); | 787 | $location.path('/venta-nota-pedido/abm/'); |
778 | }; | 788 | }; |
779 | } | 789 | } |
780 | ]) | 790 | ]) |
781 | .controller('focaCrearNotaPedidoFichaClienteController', [ | 791 | .controller('focaCrearNotaPedidoFichaClienteController', [ |
782 | '$scope', | 792 | '$scope', |
783 | 'crearNotaPedidoService', | 793 | 'crearNotaPedidoService', |
784 | '$location', | 794 | '$location', |
785 | function($scope, crearNotaPedidoService, $location) { | 795 | function($scope, crearNotaPedidoService, $location) { |
786 | crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { | 796 | crearNotaPedidoService.obtenerNotaPedido().then(function(datos) { |
787 | $scope.notaPedidos = datos.data; | 797 | $scope.notaPedidos = datos.data; |
788 | }); | 798 | }); |
789 | $scope.editar = function(notaPedido) { | 799 | $scope.editar = function(notaPedido) { |
790 | crearNotaPedidoService.setNotaPedido(notaPedido); | 800 | crearNotaPedidoService.setNotaPedido(notaPedido); |
791 | $location.path('/venta-nota-pedido/abm/'); | 801 | $location.path('/venta-nota-pedido/abm/'); |
792 | }; | 802 | }; |
793 | $scope.crearPedido = function() { | 803 | $scope.crearPedido = function() { |
794 | crearNotaPedidoService.clearNotaPedido(); | 804 | crearNotaPedidoService.clearNotaPedido(); |
795 | $location.path('/venta-nota-pedido/abm/'); | 805 | $location.path('/venta-nota-pedido/abm/'); |
796 | }; | 806 | }; |
797 | } | 807 | } |
798 | ]); | 808 | ]); |
799 | 809 |