Commit d5f7678cc3a12b30f5c240bd668a5a89f394b84a
Exists in
master
and in
1 other branch
Merge branch 'master' into 'master'
Master See merge request !38
Showing
3 changed files
Show diff stats
.jshintrc
1 | { | 1 | { |
2 | /* | 2 | /* |
3 | * ENVIRONMENTS | 3 | * ENVIRONMENTS |
4 | * ================= | 4 | * ================= |
5 | */ | 5 | */ |
6 | 6 | ||
7 | // Define globals exposed by modern browsers. | 7 | // Define globals exposed by modern browsers. |
8 | "browser": true, | 8 | "browser": true, |
9 | 9 | ||
10 | // Define globals exposed by jQuery. | 10 | // Define globals exposed by jQuery. |
11 | "jquery": true, | 11 | "jquery": true, |
12 | 12 | ||
13 | // Define globals exposed by Node.js. | 13 | // Define globals exposed by Node.js. |
14 | "node": true, | 14 | "node": true, |
15 | 15 | ||
16 | // Allow ES6. | 16 | // Allow ES6. |
17 | "esversion": 6, | 17 | "esversion": 6, |
18 | 18 | ||
19 | /* | 19 | /* |
20 | * ENFORCING OPTIONS | 20 | * ENFORCING OPTIONS |
21 | * ================= | 21 | * ================= |
22 | */ | 22 | */ |
23 | 23 | ||
24 | // Force all variable names to use either camelCase style or UPPER_CASE | 24 | // Force all variable names to use either camelCase style or UPPER_CASE |
25 | // with underscores. | 25 | // with underscores. |
26 | "camelcase": true, | 26 | "camelcase": false, |
27 | 27 | ||
28 | // Prohibit use of == and != in favor of === and !==. | 28 | // Prohibit use of == and != in favor of === and !==. |
29 | "eqeqeq": true, | 29 | "eqeqeq": true, |
30 | 30 | ||
31 | // Enforce tab width of 2 spaces. | 31 | // Enforce tab width of 2 spaces. |
32 | "indent": 4, | 32 | "indent": 4, |
33 | 33 | ||
34 | // Prohibit use of a variable before it is defined. | 34 | // Prohibit use of a variable before it is defined. |
35 | "latedef": false, | 35 | "latedef": false, |
36 | 36 | ||
37 | // Enforce line length to 100 characters | 37 | // Enforce line length to 100 characters |
38 | "maxlen": 100, | 38 | "maxlen": 100, |
39 | 39 | ||
40 | // Require capitalized names for constructor functions. | 40 | // Require capitalized names for constructor functions. |
41 | "newcap": true, | 41 | "newcap": true, |
42 | 42 | ||
43 | // Enforce use of single quotation marks for strings. | 43 | // Enforce use of single quotation marks for strings. |
44 | "quotmark": "single", | 44 | "quotmark": "single", |
45 | 45 | ||
46 | // Enforce placing 'use strict' at the top function scope | 46 | // Enforce placing 'use strict' at the top function scope |
47 | "strict": false, | 47 | "strict": false, |
48 | 48 | ||
49 | // Prohibit use of explicitly undeclared variables. | 49 | // Prohibit use of explicitly undeclared variables. |
50 | "undef": true, | 50 | "undef": true, |
51 | 51 | ||
52 | // Warn when variables are defined but never used. | 52 | // Warn when variables are defined but never used. |
53 | "unused": true, | 53 | "unused": true, |
54 | 54 | ||
55 | // Para que funcione en angular | 55 | // Para que funcione en angular |
56 | "predef": ["angular", "alert", "spyOn", "expect", "it", "inject", "beforeEach", "describe"], | 56 | "predef": ["angular", "alert", "spyOn", "expect", "it", "inject", "beforeEach", "describe"], |
57 | /* | 57 | /* |
58 | * RELAXING OPTIONS | 58 | * RELAXING OPTIONS |
59 | * ================= | 59 | * ================= |
60 | */ | 60 | */ |
61 | 61 | ||
62 | // Suppress warnings about == null comparisons. | 62 | // Suppress warnings about == null comparisons. |
63 | "eqnull": true | 63 | "eqnull": true |
64 | } | 64 | } |
65 | 65 |
src/js/controller.js
1 | angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', | 1 | angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
2 | [ | 2 | [ |
3 | '$scope', | 3 | '$scope', |
4 | '$uibModal', | 4 | '$uibModal', |
5 | '$location', | 5 | '$location', |
6 | '$filter', | 6 | '$filter', |
7 | '$timeout', | 7 | '$timeout', |
8 | 'crearNotaPedidoService', | 8 | 'crearNotaPedidoService', |
9 | 'focaBotoneraLateralService', | 9 | 'focaBotoneraLateralService', |
10 | 'focaModalService', | 10 | 'focaModalService', |
11 | 'notaPedidoBusinessService', | 11 | 'notaPedidoBusinessService', |
12 | '$rootScope', | 12 | '$rootScope', |
13 | 'focaSeguimientoService', | 13 | 'focaSeguimientoService', |
14 | 'APP', | 14 | 'APP', |
15 | 'focaLoginService', | 15 | 'focaLoginService', |
16 | function( | 16 | function( |
17 | $scope, $uibModal, $location, $filter, $timeout, crearNotaPedidoService, | 17 | $scope, $uibModal, $location, $filter, $timeout, crearNotaPedidoService, |
18 | focaBotoneraLateralService, focaModalService, notaPedidoBusinessService, | 18 | focaBotoneraLateralService, focaModalService, notaPedidoBusinessService, |
19 | $rootScope, focaSeguimientoService, APP, focaLoginService) | 19 | $rootScope, focaSeguimientoService, APP, focaLoginService) |
20 | { | 20 | { |
21 | if(APP === 'distribuidor') { | 21 | if(APP === 'distribuidor') { |
22 | var idVendedor = focaLoginService.getLoginData().vendedorCobrador; | 22 | var idVendedor = focaLoginService.getLoginData().vendedorCobrador; |
23 | $scope.botonera = crearNotaPedidoService.getBotonera(idVendedor); | 23 | $scope.botonera = crearNotaPedidoService.getBotonera(idVendedor); |
24 | crearNotaPedidoService.getVendedorById(idVendedor).then( | 24 | crearNotaPedidoService.getVendedorById(idVendedor).then( |
25 | function(res) { | 25 | function(res) { |
26 | var vendedor = res.data; | 26 | var vendedor = res.data; |
27 | $scope.$broadcast('addCabecera', { | 27 | $scope.$broadcast('addCabecera', { |
28 | label: 'Vendedor:', | 28 | label: 'Vendedor:', |
29 | valor: $filter('rellenarDigitos')(vendedor.CodVen, 3) + ' - ' + | 29 | valor: $filter('rellenarDigitos')(vendedor.CodVen, 3) + ' - ' + |
30 | vendedor.NomVen | 30 | vendedor.NomVen |
31 | }); | 31 | }); |
32 | $scope.notaPedido.vendedor = vendedor; | 32 | $scope.notaPedido.vendedor = vendedor; |
33 | } | 33 | } |
34 | ); | 34 | ); |
35 | }else { | 35 | }else { |
36 | $scope.botonera = crearNotaPedidoService.getBotonera(); | 36 | $scope.botonera = crearNotaPedidoService.getBotonera(); |
37 | } | 37 | } |
38 | 38 | ||
39 | $scope.isNumber = angular.isNumber; | 39 | $scope.isNumber = angular.isNumber; |
40 | $scope.datepickerAbierto = false; | 40 | $scope.datepickerAbierto = false; |
41 | $scope.show = false; | 41 | $scope.show = false; |
42 | $scope.cargando = true; | 42 | $scope.cargando = true; |
43 | $scope.dateOptions = { | 43 | $scope.dateOptions = { |
44 | maxDate: new Date(), | 44 | maxDate: new Date(), |
45 | minDate: new Date(2010, 0, 1) | 45 | minDate: new Date(2010, 0, 1) |
46 | }; | 46 | }; |
47 | 47 | ||
48 | $scope.notaPedido = { | 48 | $scope.notaPedido = { |
49 | id: 0, | 49 | id: 0, |
50 | vendedor: {}, | 50 | vendedor: {}, |
51 | cliente: {}, | 51 | cliente: {}, |
52 | proveedor: {}, | 52 | proveedor: {}, |
53 | domicilio: {dom: ''}, | 53 | domicilio: {dom: ''}, |
54 | moneda: {}, | 54 | moneda: {}, |
55 | cotizacion: {} | 55 | cotizacion: {} |
56 | }; | 56 | }; |
57 | var monedaPorDefecto; | 57 | var monedaPorDefecto; |
58 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' | 58 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' |
59 | crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { | 59 | crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) { |
60 | monedaPorDefecto = res.data[0]; | 60 | monedaPorDefecto = res.data[0]; |
61 | $scope.notaPedido.moneda = monedaPorDefecto; | 61 | $scope.notaPedido.moneda = monedaPorDefecto; |
62 | $scope.notaPedido.cotizacion = monedaPorDefecto.cotizaciones[0]; | 62 | $scope.notaPedido.cotizacion = monedaPorDefecto.cotizaciones[0]; |
63 | }); | 63 | }); |
64 | 64 | ||
65 | $scope.cabecera = []; | 65 | $scope.cabecera = []; |
66 | $scope.showCabecera = true; | 66 | $scope.showCabecera = true; |
67 | 67 | ||
68 | $scope.now = new Date(); | 68 | $scope.now = new Date(); |
69 | $scope.puntoVenta = '0000'; | 69 | $scope.puntoVenta = '0000'; |
70 | $scope.comprobante = '00000000'; | 70 | $scope.comprobante = '00000000'; |
71 | $scope.articulosTabla = []; | 71 | $scope.articulosTabla = []; |
72 | $scope.idLista = undefined; | 72 | $scope.idLista = undefined; |
73 | 73 | ||
74 | //SETEO BOTONERA LATERAL | 74 | //SETEO BOTONERA LATERAL |
75 | $timeout(function() { | 75 | $timeout(function() { |
76 | focaBotoneraLateralService.showSalir(false); | 76 | focaBotoneraLateralService.showSalir(false); |
77 | focaBotoneraLateralService.showPausar(true); | 77 | focaBotoneraLateralService.showPausar(true); |
78 | focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido); | 78 | focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido); |
79 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 79 | focaBotoneraLateralService.addCustomButton('Salir', salir); |
80 | }); | 80 | }); |
81 | 81 | ||
82 | crearNotaPedidoService.getNumeroNotaPedido().then( | 82 | crearNotaPedidoService.getNumeroNotaPedido().then( |
83 | function(res) { | 83 | function(res) { |
84 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); | 84 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); |
85 | $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); | 85 | $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); |
86 | }, | 86 | }, |
87 | function(err) { | 87 | function(err) { |
88 | focaModalService.alert('La terminal no esta configurada correctamente'); | 88 | focaModalService.alert('La terminal no esta configurada correctamente'); |
89 | console.info(err); | 89 | console.info(err); |
90 | } | 90 | } |
91 | ); | 91 | ); |
92 | 92 | ||
93 | $scope.crearNotaPedido = function() { | 93 | $scope.crearNotaPedido = function() { |
94 | if(!$scope.notaPedido.vendedor.CodVen) { | 94 | if(!$scope.notaPedido.vendedor.CodVen) { |
95 | focaModalService.alert('Ingrese Vendedor'); | 95 | focaModalService.alert('Ingrese Vendedor'); |
96 | return; | 96 | return; |
97 | } else if(!$scope.notaPedido.cliente.COD) { | 97 | } else if(!$scope.notaPedido.cliente.COD) { |
98 | focaModalService.alert('Ingrese Cliente'); | 98 | focaModalService.alert('Ingrese Cliente'); |
99 | return; | 99 | return; |
100 | } else if(!$scope.notaPedido.proveedor.COD) { | 100 | } else if(!$scope.notaPedido.proveedor.COD) { |
101 | focaModalService.alert('Ingrese Proveedor'); | 101 | focaModalService.alert('Ingrese Proveedor'); |
102 | return; | 102 | return; |
103 | } else if(!$scope.notaPedido.moneda.ID) { | 103 | } else if(!$scope.notaPedido.moneda.ID) { |
104 | focaModalService.alert('Ingrese Moneda'); | 104 | focaModalService.alert('Ingrese Moneda'); |
105 | return; | 105 | return; |
106 | } else if(!$scope.notaPedido.cotizacion.ID) { | 106 | } else if(!$scope.notaPedido.cotizacion.ID) { |
107 | focaModalService.alert('Ingrese Cotización'); | 107 | focaModalService.alert('Ingrese Cotización'); |
108 | return; | 108 | return; |
109 | } else if(!$scope.plazosPagos) { | 109 | } else if(!$scope.plazosPagos) { |
110 | focaModalService.alert('Ingrese Precios y Condiciones'); | 110 | focaModalService.alert('Ingrese Precios y Condiciones'); |
111 | return; | 111 | return; |
112 | } else if( | 112 | } else if( |
113 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) | 113 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) |
114 | { | 114 | { |
115 | focaModalService.alert('Ingrese Flete'); | 115 | focaModalService.alert('Ingrese Flete'); |
116 | return; | 116 | return; |
117 | } else if(!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto | 117 | } else if(!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto |
118 | focaModalService.alert('Ingrese Domicilio'); | 118 | focaModalService.alert('Ingrese Domicilio'); |
119 | return; | 119 | return; |
120 | } else if($scope.articulosTabla.length === 0) { | 120 | } else if($scope.articulosTabla.length === 0) { |
121 | focaModalService.alert('Debe cargar al menos un articulo'); | 121 | focaModalService.alert('Debe cargar al menos un articulo'); |
122 | return; | 122 | return; |
123 | } | 123 | } |
124 | focaBotoneraLateralService.startGuardar(); | 124 | focaBotoneraLateralService.startGuardar(); |
125 | $scope.saveLoading = true; | 125 | $scope.saveLoading = true; |
126 | var notaPedido = { | 126 | var notaPedido = { |
127 | id: $scope.notaPedido.id, | 127 | id: $scope.notaPedido.id, |
128 | fechaCarga: $scope.now.toISOString().slice(0, 19).replace('T', ' '), | 128 | fechaCarga: $scope.now.toISOString().slice(0, 19).replace('T', ' '), |
129 | idVendedor: $scope.notaPedido.vendedor.CodVen, | 129 | idVendedor: $scope.notaPedido.vendedor.CodVen, |
130 | idCliente: $scope.notaPedido.cliente.COD, | 130 | idCliente: $scope.notaPedido.cliente.COD, |
131 | nombreCliente: $scope.notaPedido.cliente.NOM, | 131 | nombreCliente: $scope.notaPedido.cliente.NOM, |
132 | cuitCliente: $scope.notaPedido.cliente.CUIT, | 132 | cuitCliente: $scope.notaPedido.cliente.CUIT, |
133 | idProveedor: $scope.notaPedido.proveedor.COD, | 133 | idProveedor: $scope.notaPedido.proveedor.COD, |
134 | //idDomicilio: $scope.notaPedido.domicilio.id,TODO GUARDAR DOMICILIO ID | 134 | //idDomicilio: $scope.notaPedido.domicilio.id,TODO GUARDAR DOMICILIO ID |
135 | idCotizacion: $scope.notaPedido.cotizacion.ID, | 135 | idCotizacion: $scope.notaPedido.cotizacion.ID, |
136 | idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, | 136 | idPrecioCondicion: $scope.notaPedido.idPrecioCondicion, |
137 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 137 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
138 | flete: $scope.notaPedido.flete, | 138 | flete: $scope.notaPedido.flete, |
139 | fob: $scope.notaPedido.fob, | 139 | fob: $scope.notaPedido.fob, |
140 | bomba: $scope.notaPedido.bomba, | 140 | bomba: $scope.notaPedido.bomba, |
141 | kilometros: $scope.notaPedido.kilometros, | 141 | kilometros: $scope.notaPedido.kilometros, |
142 | domicilioStamp: $scope.notaPedido.domicilioStamp, | 142 | domicilioStamp: $scope.notaPedido.domicilioStamp, |
143 | estado: 0, | 143 | estado: 0, |
144 | total: $scope.getTotal() | 144 | total: $scope.getTotal() |
145 | }; | 145 | }; |
146 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( | 146 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( |
147 | function(data) { | 147 | function(data) { |
148 | // Al guardar los datos de la nota de pedido logueamos la | 148 | // Al guardar los datos de la nota de pedido logueamos la |
149 | // actividad para su seguimiento. | 149 | // actividad para su seguimiento. |
150 | //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? | 150 | //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? |
151 | focaSeguimientoService.guardarPosicion( | 151 | focaSeguimientoService.guardarPosicion( |
152 | 'Nota de pedido', | 152 | 'Nota de pedido', |
153 | data.data.id, | 153 | data.data.id, |
154 | '' | 154 | '' |
155 | ); | 155 | ); |
156 | notaPedidoBusinessService.addArticulos($scope.articulosTabla, | 156 | notaPedidoBusinessService.addArticulos($scope.articulosTabla, |
157 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); | 157 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); |
158 | 158 | ||
159 | if($scope.notaPedido.puntosDescarga) { | 159 | if($scope.notaPedido.puntosDescarga) { |
160 | notaPedidoBusinessService.addPuntosDescarga(data.data.id, | 160 | notaPedidoBusinessService.addPuntosDescarga(data.data.id, |
161 | $scope.notaPedido.puntosDescarga); | 161 | $scope.notaPedido.puntosDescarga); |
162 | } | 162 | } |
163 | 163 | ||
164 | var plazos = $scope.plazosPagos; | 164 | var plazos = $scope.plazosPagos; |
165 | var plazosACrear = []; | 165 | var plazosACrear = []; |
166 | plazos.forEach(function(plazo) { | 166 | plazos.forEach(function(plazo) { |
167 | plazosACrear.push({ | 167 | plazosACrear.push({ |
168 | idNotaPedido: data.data.id, | 168 | idNotaPedido: data.data.id, |
169 | dias: plazo.dias | 169 | dias: plazo.dias |
170 | }); | 170 | }); |
171 | }); | 171 | }); |
172 | if(plazosACrear.length){ | 172 | if(plazosACrear.length){ |
173 | crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear); | 173 | crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear); |
174 | } | 174 | } |
175 | 175 | ||
176 | notaPedidoBusinessService.addEstado(data.data.id, | 176 | notaPedidoBusinessService.addEstado(data.data.id, |
177 | $scope.notaPedido.vendedor.CodVen); | 177 | $scope.notaPedido.vendedor.CodVen); |
178 | 178 | ||
179 | focaBotoneraLateralService.endGuardar(true); | 179 | focaBotoneraLateralService.endGuardar(true); |
180 | $scope.saveLoading = false; | 180 | $scope.saveLoading = false; |
181 | $scope.$broadcast('cleanCabecera'); | 181 | $scope.$broadcast('cleanCabecera'); |
182 | $scope.$broadcast('addCabecera', { | 182 | $scope.$broadcast('addCabecera', { |
183 | label: 'Moneda:', | 183 | label: 'Moneda:', |
184 | valor: $scope.notaPedido.moneda.DETALLE | 184 | valor: $scope.notaPedido.moneda.DETALLE |
185 | }); | 185 | }); |
186 | $scope.$broadcast('addCabecera', { | 186 | $scope.$broadcast('addCabecera', { |
187 | label: 'Fecha cotizacion:', | 187 | label: 'Fecha cotizacion:', |
188 | valor: $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy') | 188 | valor: $filter('date')($scope.notaPedido.cotizacion.FECHA, 'dd/MM/yyyy') |
189 | }); | 189 | }); |
190 | $scope.$broadcast('addCabecera', { | 190 | $scope.$broadcast('addCabecera', { |
191 | label: 'Moneda:', | 191 | label: 'Moneda:', |
192 | valor: $scope.notaPedido.moneda.DETALLE | 192 | valor: $scope.notaPedido.moneda.DETALLE |
193 | }); | 193 | }); |
194 | $scope.$broadcast('addCabecera', { | 194 | $scope.$broadcast('addCabecera', { |
195 | label: 'Cotizacion:', | 195 | label: 'Cotizacion:', |
196 | valor: $filter('number')($scope.notaPedido.cotizacion.VENDEDOR, '2') | 196 | valor: $filter('number')($scope.notaPedido.cotizacion.VENDEDOR, '2') |
197 | }); | 197 | }); |
198 | crearNotaPedidoService.getNumeroNotaPedido().then( | 198 | crearNotaPedidoService.getNumeroNotaPedido().then( |
199 | function(res) { | 199 | function(res) { |
200 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); | 200 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); |
201 | $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); | 201 | $scope.comprobante = rellenar(res.data.numeroNotaPedido, 8); |
202 | }, | 202 | }, |
203 | function(err) { | 203 | function(err) { |
204 | focaModalService.alert( | 204 | focaModalService.alert( |
205 | 'La terminal no esta configurada correctamente'); | 205 | 'La terminal no esta configurada correctamente'); |
206 | console.info(err); | 206 | console.info(err); |
207 | } | 207 | } |
208 | ); | 208 | ); |
209 | $scope.notaPedido.vendedor = {}; | 209 | $scope.notaPedido.vendedor = {}; |
210 | $scope.notaPedido.cliente = {}; | 210 | $scope.notaPedido.cliente = {}; |
211 | $scope.notaPedido.proveedor = {}; | 211 | $scope.notaPedido.proveedor = {}; |
212 | $scope.notaPedido.domicilio = {}; | 212 | $scope.notaPedido.domicilio = {}; |
213 | $scope.notaPedido.flete = undefined; | 213 | $scope.notaPedido.flete = undefined; |
214 | $scope.notaPedido.fob = undefined; | 214 | $scope.notaPedido.fob = undefined; |
215 | $scope.notaPedido.bomba = undefined; | 215 | $scope.notaPedido.bomba = undefined; |
216 | $scope.notaPedido.kilometros = undefined; | 216 | $scope.notaPedido.kilometros = undefined; |
217 | $scope.articulosTabla = []; | 217 | $scope.articulosTabla = []; |
218 | }, | 218 | }, |
219 | function(error) { | 219 | function(error) { |
220 | focaModalService.alert('Hubo un error al crear la nota de pedido'); | 220 | focaModalService.alert('Hubo un error al crear la nota de pedido'); |
221 | focaBotoneraLateralService.endGuardar(); | 221 | focaBotoneraLateralService.endGuardar(); |
222 | $scope.saveLoading = false; | 222 | $scope.saveLoading = false; |
223 | console.info(error); | 223 | console.info(error); |
224 | } | 224 | } |
225 | ); | 225 | ); |
226 | }; | 226 | }; |
227 | 227 | ||
228 | $scope.seleccionarNotaPedido = function() { | 228 | $scope.seleccionarNotaPedido = function() { |
229 | var modalInstance = $uibModal.open( | 229 | var modalInstance = $uibModal.open( |
230 | { | 230 | { |
231 | ariaLabelledBy: 'Busqueda de Nota de Pedido', | 231 | ariaLabelledBy: 'Busqueda de Nota de Pedido', |
232 | templateUrl: 'foca-modal-nota-pedido.html', | 232 | templateUrl: 'foca-modal-nota-pedido.html', |
233 | controller: 'focaModalNotaPedidoController', | 233 | controller: 'focaModalNotaPedidoController', |
234 | size: 'lg', | 234 | size: 'lg', |
235 | resolve: { | 235 | resolve: { |
236 | usadoPor: function() {return 'notaPedido';}, | 236 | usadoPor: function() {return 'notaPedido';}, |
237 | idVendedor: function() { | 237 | idVendedor: function() { |
238 | if(APP === 'distribuidor') | 238 | if(APP === 'distribuidor') |
239 | return $scope.notaPedido.vendedor.CodVen; | 239 | return $scope.notaPedido.vendedor.CodVen; |
240 | else | 240 | else |
241 | return null; | 241 | return null; |
242 | } | 242 | } |
243 | } | 243 | } |
244 | } | 244 | } |
245 | ); | 245 | ); |
246 | modalInstance.result.then( | 246 | modalInstance.result.then( |
247 | function(notaPedido) { | 247 | function(notaPedido) { |
248 | $scope.now = new Date(notaPedido.fechaCarga); | 248 | $scope.now = new Date(notaPedido.fechaCarga); |
249 | //añado cabeceras | 249 | //añado cabeceras |
250 | $scope.notaPedido.id = notaPedido.id; | 250 | $scope.notaPedido.id = notaPedido.id; |
251 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 251 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
252 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 252 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
253 | var cabeceras = [ | 253 | var cabeceras = [ |
254 | { | 254 | { |
255 | label: 'Moneda:', | 255 | label: 'Moneda:', |
256 | valor: notaPedido.cotizacion.moneda.DETALLE | 256 | valor: notaPedido.cotizacion.moneda.DETALLE |
257 | }, | 257 | }, |
258 | { | 258 | { |
259 | label: 'Fecha cotizacion:', | 259 | label: 'Fecha cotizacion:', |
260 | valor: $filter('date')(notaPedido.cotizacion.FECHA, | 260 | valor: $filter('date')(notaPedido.cotizacion.FECHA, |
261 | 'dd/MM/yyyy') | 261 | 'dd/MM/yyyy') |
262 | }, | 262 | }, |
263 | { | 263 | { |
264 | label: 'Cotizacion:', | 264 | label: 'Cotizacion:', |
265 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, | 265 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, |
266 | '2') | 266 | '2') |
267 | }, | 267 | }, |
268 | { | 268 | { |
269 | label: 'Cliente:', | 269 | label: 'Cliente:', |
270 | valor: notaPedido.cliente.NOM | 270 | valor: notaPedido.cliente.NOM |
271 | }, | 271 | }, |
272 | { | 272 | { |
273 | label: 'Domicilio:', | 273 | label: 'Domicilio:', |
274 | valor: notaPedido.domicilioStamp | 274 | valor: notaPedido.domicilioStamp |
275 | }, | 275 | }, |
276 | { | 276 | { |
277 | label: 'Vendedor:', | 277 | label: 'Vendedor:', |
278 | valor: notaPedido.vendedor.CodVen + ' - ' + | 278 | valor: $filter('rellenarDigitos')(notaPedido.vendedor.CodVen, 3) + |
279 | notaPedido.vendedor.NomVen | 279 | ' - ' + notaPedido.vendedor.NomVen |
280 | }, | 280 | }, |
281 | { | 281 | { |
282 | label: 'Proveedor:', | 282 | label: 'Proveedor:', |
283 | valor: notaPedido.proveedor.NOM | 283 | valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) + |
284 | ' - ' + notaPedido.proveedor.NOM | ||
284 | }, | 285 | }, |
285 | { | 286 | { |
286 | label: 'Precios y condiciones:', | 287 | label: 'Precios y condiciones:', |
287 | valor: valorPrecioCondicion() + ' ' + | 288 | valor: valorPrecioCondicion() + ' ' + |
288 | notaPedidoBusinessService | 289 | notaPedidoBusinessService |
289 | .plazoToString(notaPedido.notaPedidoPlazo) | 290 | .plazoToString(notaPedido.notaPedidoPlazo) |
290 | }, | 291 | }, |
291 | { | 292 | { |
292 | label: 'Flete:', | 293 | label: 'Flete:', |
293 | valor: notaPedido.fob === 1 ? 'FOB' : ( | 294 | valor: notaPedido.fob === 1 ? 'FOB' : ( |
294 | notaPedido.flete === 1 ? 'Si' : 'No') | 295 | notaPedido.flete === 1 ? 'Si' : 'No') |
295 | } | 296 | } |
296 | ]; | 297 | ]; |
297 | 298 | ||
298 | function valorPrecioCondicion() { | 299 | function valorPrecioCondicion() { |
299 | if(notaPedido.idPrecioCondicion > 0) { | 300 | if(notaPedido.idPrecioCondicion > 0) { |
300 | return notaPedido.precioCondicion.nombre; | 301 | return notaPedido.precioCondicion.nombre; |
301 | } else { | 302 | } else { |
302 | return 'Ingreso Manual'; | 303 | return 'Ingreso Manual'; |
303 | } | 304 | } |
304 | } | 305 | } |
305 | 306 | ||
306 | if(notaPedido.flete === 1) { | 307 | if(notaPedido.flete === 1) { |
307 | var cabeceraBomba = { | 308 | var cabeceraBomba = { |
308 | label: 'Bomba:', | 309 | label: 'Bomba:', |
309 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' | 310 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' |
310 | }; | 311 | }; |
311 | if(notaPedido.kilometros) { | 312 | if(notaPedido.kilometros) { |
312 | var cabeceraKilometros = { | 313 | var cabeceraKilometros = { |
313 | label: 'Kilometros:', | 314 | label: 'Kilometros:', |
314 | valor: notaPedido.kilometros | 315 | valor: notaPedido.kilometros |
315 | }; | 316 | }; |
316 | cabeceras.push(cabeceraKilometros); | 317 | cabeceras.push(cabeceraKilometros); |
317 | } | 318 | } |
318 | cabeceras.push(cabeceraBomba); | 319 | cabeceras.push(cabeceraBomba); |
319 | } | 320 | } |
320 | $scope.articulosTabla = notaPedido.articulosNotaPedido; | 321 | $scope.articulosTabla = notaPedido.articulosNotaPedido; |
321 | notaPedidoBusinessService.calcularArticulos($scope.articulosTabla, | 322 | notaPedidoBusinessService.calcularArticulos($scope.articulosTabla, |
322 | notaPedido.cotizacion.VENDEDOR); | 323 | notaPedido.cotizacion.VENDEDOR); |
323 | if(notaPedido.idPrecioCondicion > 0) { | 324 | if(notaPedido.idPrecioCondicion > 0) { |
324 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; | 325 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; |
325 | } else { | 326 | } else { |
326 | $scope.idLista = -1; | 327 | $scope.idLista = -1; |
327 | } | 328 | } |
328 | $scope.puntoVenta = rellenar(notaPedido.sucursal, 4); | 329 | $scope.puntoVenta = rellenar(notaPedido.sucursal, 4); |
329 | $scope.comprobante = rellenar(notaPedido.numeroNotaPedido, 8); | 330 | $scope.comprobante = rellenar(notaPedido.numeroNotaPedido, 8); |
330 | $scope.notaPedido = notaPedido; | 331 | $scope.notaPedido = notaPedido; |
331 | $scope.notaPedido.moneda = notaPedido.cotizacion.moneda; | 332 | $scope.notaPedido.moneda = notaPedido.cotizacion.moneda; |
332 | $scope.plazosPagos = notaPedido.notaPedidoPlazo; | 333 | $scope.plazosPagos = notaPedido.notaPedidoPlazo; |
333 | $scope.notaPedido.puntosDescarga = | 334 | $scope.notaPedido.puntosDescarga = |
334 | formatearPuntosDescarga(notaPedido.notaPedidoPuntoDescarga); | 335 | formatearPuntosDescarga(notaPedido.notaPedidoPuntoDescarga); |
335 | addArrayCabecera(cabeceras); | 336 | addArrayCabecera(cabeceras); |
336 | 337 | ||
337 | }, function() { | 338 | }, function() { |
338 | // funcion ejecutada cuando se cancela el modal | 339 | // funcion ejecutada cuando se cancela el modal |
339 | } | 340 | } |
340 | ); | 341 | ); |
341 | }; | 342 | }; |
342 | 343 | ||
343 | $scope.seleccionarProductos = function() { | 344 | $scope.seleccionarProductos = function() { |
344 | if ($scope.idLista === undefined) { | 345 | if ($scope.idLista === undefined) { |
345 | focaModalService.alert( | 346 | focaModalService.alert( |
346 | 'Primero seleccione una lista de precio y condicion'); | 347 | 'Primero seleccione una lista de precio y condicion'); |
347 | return; | 348 | return; |
348 | } | 349 | } |
349 | var modalInstance = $uibModal.open( | 350 | var modalInstance = $uibModal.open( |
350 | { | 351 | { |
351 | ariaLabelledBy: 'Busqueda de Productos', | 352 | ariaLabelledBy: 'Busqueda de Productos', |
352 | templateUrl: 'modal-busqueda-productos.html', | 353 | templateUrl: 'modal-busqueda-productos.html', |
353 | controller: 'modalBusquedaProductosCtrl', | 354 | controller: 'modalBusquedaProductosCtrl', |
354 | resolve: { | 355 | resolve: { |
355 | parametroProducto: { | 356 | parametroProducto: { |
356 | idLista: $scope.idLista, | 357 | idLista: $scope.idLista, |
357 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 358 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
358 | simbolo: $scope.notaPedido.moneda.SIMBOLO | 359 | simbolo: $scope.notaPedido.moneda.SIMBOLO |
359 | } | 360 | } |
360 | }, | 361 | }, |
361 | size: 'lg' | 362 | size: 'lg' |
362 | } | 363 | } |
363 | ); | 364 | ); |
364 | modalInstance.result.then( | 365 | modalInstance.result.then( |
365 | function(producto) { | 366 | function(producto) { |
366 | var newArt = | 367 | var newArt = |
367 | { | 368 | { |
368 | id: 0, | 369 | id: 0, |
369 | codigo: producto.codigo, | 370 | codigo: producto.codigo, |
370 | sector: producto.sector, | 371 | sector: producto.sector, |
371 | sectorCodigo: producto.sector + '-' + producto.codigo, | 372 | sectorCodigo: producto.sector + '-' + producto.codigo, |
372 | descripcion: producto.descripcion, | 373 | descripcion: producto.descripcion, |
373 | item: $scope.articulosTabla.length + 1, | 374 | item: $scope.articulosTabla.length + 1, |
374 | nombre: producto.descripcion, | 375 | nombre: producto.descripcion, |
375 | precio: parseFloat(producto.precio.toFixed(4)), | 376 | precio: parseFloat(producto.precio.toFixed(4)), |
376 | costoUnitario: producto.costo, | 377 | costoUnitario: producto.costo, |
377 | editCantidad: false, | 378 | editCantidad: false, |
378 | editPrecio: false, | 379 | editPrecio: false, |
379 | rubro: producto.CodRub, | 380 | rubro: producto.CodRub, |
380 | exentoUnitario: producto.precio, | 381 | exentoUnitario: producto.precio, |
381 | ivaUnitario: producto.IMPIVA, | 382 | ivaUnitario: producto.IMPIVA, |
382 | impuestoInternoUnitario: producto.ImpInt, | 383 | impuestoInternoUnitario: producto.ImpInt, |
383 | impuestoInterno1Unitario: producto.ImpInt2, | 384 | impuestoInterno1Unitario: producto.ImpInt2, |
384 | impuestoInterno2Unitario: producto.ImpInt3, | 385 | impuestoInterno2Unitario: producto.ImpInt3, |
385 | precioLista: producto.precio, | 386 | precioLista: producto.precio, |
386 | combustible: 1, | 387 | combustible: 1, |
387 | facturado: 0, | 388 | facturado: 0, |
388 | idArticulo: producto.id | 389 | idArticulo: producto.id |
389 | }; | 390 | }; |
390 | $scope.articuloACargar = newArt; | 391 | $scope.articuloACargar = newArt; |
391 | $scope.cargando = false; | 392 | $scope.cargando = false; |
392 | }, function() { | 393 | }, function() { |
393 | // funcion ejecutada cuando se cancela el modal | 394 | // funcion ejecutada cuando se cancela el modal |
394 | } | 395 | } |
395 | ); | 396 | ); |
396 | }; | 397 | }; |
397 | 398 | ||
398 | $scope.seleccionarPuntosDeDescarga = function() { | 399 | $scope.seleccionarPuntosDeDescarga = function() { |
399 | if(!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { | 400 | if(!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { |
400 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); | 401 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); |
401 | return; | 402 | return; |
402 | }else { | 403 | }else { |
403 | var modalInstance = $uibModal.open( | 404 | var modalInstance = $uibModal.open( |
404 | { | 405 | { |
405 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', | 406 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', |
406 | templateUrl: 'modal-punto-descarga.html', | 407 | templateUrl: 'modal-punto-descarga.html', |
407 | controller: 'focaModalPuntoDescargaController', | 408 | controller: 'focaModalPuntoDescargaController', |
408 | size: 'lg', | 409 | size: 'lg', |
409 | resolve: { | 410 | resolve: { |
410 | filters: { | 411 | filters: { |
411 | /*TODO: al traer nota de pedido ya creada | 412 | /*TODO: al traer nota de pedido ya creada |
412 | obtener idDomicilio correctamente*/ | 413 | obtener idDomicilio correctamente*/ |
413 | idDomicilio: $scope.notaPedido.domicilio.id, | 414 | idDomicilio: $scope.notaPedido.domicilio.id, |
414 | idCliente: $scope.notaPedido.cliente.COD, | 415 | idCliente: $scope.notaPedido.cliente.COD, |
415 | articulos: $scope.articulosTabla, | 416 | articulos: $scope.articulosTabla, |
416 | puntosDescarga: $scope.notaPedido.puntosDescarga | 417 | puntosDescarga: $scope.notaPedido.puntosDescarga |
417 | } | 418 | } |
418 | } | 419 | } |
419 | } | 420 | } |
420 | ); | 421 | ); |
421 | modalInstance.result.then( | 422 | modalInstance.result.then( |
422 | function(puntosDescarga) { | 423 | function(puntosDescarga) { |
423 | $scope.notaPedido.puntosDescarga = puntosDescarga; | 424 | $scope.notaPedido.puntosDescarga = puntosDescarga; |
424 | 425 | ||
425 | //AGREGO PUNTOS DE DESCARGA A CABECERA | 426 | //AGREGO PUNTOS DE DESCARGA A CABECERA |
426 | var puntosStamp = ''; | 427 | var puntosStamp = ''; |
427 | puntosDescarga.forEach(function(punto, idx, arr) { | 428 | puntosDescarga.forEach(function(punto, idx, arr) { |
428 | puntosStamp += punto.descripcion; | 429 | puntosStamp += punto.descripcion; |
429 | if((idx + 1) !== arr.length) puntosStamp += ', '; | 430 | if((idx + 1) !== arr.length) puntosStamp += ', '; |
430 | }); | 431 | }); |
431 | 432 | ||
432 | $scope.$broadcast('addCabecera', { | 433 | $scope.$broadcast('addCabecera', { |
433 | label: 'Puntos de descarga:', | 434 | label: 'Puntos de descarga:', |
434 | valor: puntosStamp | 435 | valor: puntosStamp |
435 | }); | 436 | }); |
436 | }, function() { | 437 | }, function() { |
437 | $scope.abrirModalDomicilios($scope.cliente); | 438 | $scope.abrirModalDomicilios($scope.cliente); |
438 | } | 439 | } |
439 | ); | 440 | ); |
440 | } | 441 | } |
441 | }; | 442 | }; |
442 | 443 | ||
443 | $scope.seleccionarVendedor = function() { | 444 | $scope.seleccionarVendedor = function() { |
444 | if(validarNotaRemitada()) { | 445 | if(validarNotaRemitada()) { |
445 | var parametrosModal = { | 446 | var parametrosModal = { |
446 | titulo: 'Búsqueda vendedores', | 447 | titulo: 'Búsqueda vendedores', |
447 | query: '/vendedor', | 448 | query: '/vendedor', |
448 | columnas: [ | 449 | columnas: [ |
449 | { | 450 | { |
450 | propiedad: 'CodVen', | 451 | propiedad: 'CodVen', |
451 | nombre: 'Código', | 452 | nombre: 'Código', |
452 | filtro: { | 453 | filtro: { |
453 | nombre: 'rellenarDigitos', | 454 | nombre: 'rellenarDigitos', |
454 | parametro: 3 | 455 | parametro: 3 |
455 | } | 456 | } |
456 | }, | 457 | }, |
457 | { | 458 | { |
458 | propiedad: 'NomVen', | 459 | propiedad: 'NomVen', |
459 | nombre: 'Nombre' | 460 | nombre: 'Nombre' |
460 | } | 461 | } |
461 | ], | 462 | ], |
462 | size: 'md' | 463 | size: 'md' |
463 | }; | 464 | }; |
464 | focaModalService.modal(parametrosModal).then( | 465 | focaModalService.modal(parametrosModal).then( |
465 | function(vendedor) { | 466 | function(vendedor) { |
466 | $scope.$broadcast('addCabecera', { | 467 | $scope.$broadcast('addCabecera', { |
467 | label: 'Vendedor:', | 468 | label: 'Vendedor:', |
468 | valor: $filter('rellenarDigitos')(vendedor.CodVen, 3) + ' - ' + | 469 | valor: $filter('rellenarDigitos')(vendedor.CodVen, 3) + ' - ' + |
469 | vendedor.NomVen | 470 | vendedor.NomVen |
470 | }); | 471 | }); |
471 | $scope.notaPedido.vendedor = vendedor; | 472 | $scope.notaPedido.vendedor = vendedor; |
472 | }, function() { | 473 | }, function() { |
473 | 474 | ||
474 | } | 475 | } |
475 | ); | 476 | ); |
476 | } | 477 | } |
477 | }; | 478 | }; |
478 | 479 | ||
479 | $scope.seleccionarProveedor = function() { | 480 | $scope.seleccionarProveedor = function() { |
480 | if(validarNotaRemitada()) { | 481 | if(validarNotaRemitada()) { |
481 | var modalInstance = $uibModal.open( | 482 | var modalInstance = $uibModal.open( |
482 | { | 483 | { |
483 | ariaLabelledBy: 'Busqueda de Proveedor', | 484 | ariaLabelledBy: 'Busqueda de Proveedor', |
484 | templateUrl: 'modal-proveedor.html', | 485 | templateUrl: 'modal-proveedor.html', |
485 | controller: 'focaModalProveedorCtrl', | 486 | controller: 'focaModalProveedorCtrl', |
486 | size: 'lg', | 487 | size: 'lg', |
487 | resolve: { | 488 | resolve: { |
488 | transportista: function() { | 489 | transportista: function() { |
489 | return false; | 490 | return false; |
490 | } | 491 | } |
491 | } | 492 | } |
492 | } | 493 | } |
493 | ); | 494 | ); |
494 | modalInstance.result.then( | 495 | modalInstance.result.then( |
495 | function(proveedor) { | 496 | function(proveedor) { |
496 | $scope.notaPedido.proveedor = proveedor; | 497 | $scope.notaPedido.proveedor = proveedor; |
497 | $scope.$broadcast('addCabecera', { | 498 | $scope.$broadcast('addCabecera', { |
498 | label: 'Proveedor:', | 499 | label: 'Proveedor:', |
499 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + | 500 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + |
500 | proveedor.NOM | 501 | proveedor.NOM |
501 | }); | 502 | }); |
502 | }, function() { | 503 | }, function() { |
503 | 504 | ||
504 | } | 505 | } |
505 | ); | 506 | ); |
506 | } | 507 | } |
507 | }; | 508 | }; |
508 | 509 | ||
509 | $scope.seleccionarCliente = function() { | 510 | $scope.seleccionarCliente = function() { |
510 | if(!$scope.notaPedido.vendedor.CodVen) { | 511 | if(!$scope.notaPedido.vendedor.CodVen) { |
511 | focaModalService.alert('Primero seleccione un vendedor'); | 512 | focaModalService.alert('Primero seleccione un vendedor'); |
512 | return; | 513 | return; |
513 | } | 514 | } |
514 | if(validarNotaRemitada()) { | 515 | if(validarNotaRemitada()) { |
515 | var modalInstance = $uibModal.open( | 516 | var modalInstance = $uibModal.open( |
516 | { | 517 | { |
517 | ariaLabelledBy: 'Busqueda de Cliente', | 518 | ariaLabelledBy: 'Busqueda de Cliente', |
518 | templateUrl: 'foca-busqueda-cliente-modal.html', | 519 | templateUrl: 'foca-busqueda-cliente-modal.html', |
519 | controller: 'focaBusquedaClienteModalController', | 520 | controller: 'focaBusquedaClienteModalController', |
520 | resolve: { | 521 | resolve: { |
521 | vendedor: function() { return $scope.notaPedido.vendedor; } | 522 | vendedor: function() { return $scope.notaPedido.vendedor; } |
522 | }, | 523 | }, |
523 | size: 'lg' | 524 | size: 'lg' |
524 | } | 525 | } |
525 | ); | 526 | ); |
526 | modalInstance.result.then( | 527 | modalInstance.result.then( |
527 | function(cliente) { | 528 | function(cliente) { |
528 | $scope.abrirModalDomicilios(cliente); | 529 | $scope.abrirModalDomicilios(cliente); |
529 | $scope.cliente = cliente; | 530 | $scope.cliente = cliente; |
530 | }, function() {} | 531 | }, function() {} |
531 | ); | 532 | ); |
532 | } | 533 | } |
533 | }; | 534 | }; |
534 | 535 | ||
535 | $scope.abrirModalDomicilios = function(cliente) { | 536 | $scope.abrirModalDomicilios = function(cliente) { |
536 | var modalInstanceDomicilio = $uibModal.open( | 537 | var modalInstanceDomicilio = $uibModal.open( |
537 | { | 538 | { |
538 | ariaLabelledBy: 'Busqueda de Domicilios', | 539 | ariaLabelledBy: 'Busqueda de Domicilios', |
539 | templateUrl: 'modal-domicilio.html', | 540 | templateUrl: 'modal-domicilio.html', |
540 | controller: 'focaModalDomicilioController', | 541 | controller: 'focaModalDomicilioController', |
541 | resolve: { | 542 | resolve: { |
542 | idCliente: function() { return cliente.cod; }, | 543 | idCliente: function() { return cliente.cod; }, |
543 | esNuevo: function() { return cliente.esNuevo; } | 544 | esNuevo: function() { return cliente.esNuevo; } |
544 | }, | 545 | }, |
545 | size: 'lg', | 546 | size: 'lg', |
546 | } | 547 | } |
547 | ); | 548 | ); |
548 | modalInstanceDomicilio.result.then( | 549 | modalInstanceDomicilio.result.then( |
549 | function(domicilio) { | 550 | function(domicilio) { |
550 | $scope.notaPedido.domicilio = domicilio; | 551 | $scope.notaPedido.domicilio = domicilio; |
551 | $scope.notaPedido.cliente = { | 552 | $scope.notaPedido.cliente = { |
552 | COD: cliente.cod, | 553 | COD: cliente.cod, |
553 | CUIT: cliente.cuit, | 554 | CUIT: cliente.cuit, |
554 | NOM: cliente.nom | 555 | NOM: cliente.nom |
555 | }; | 556 | }; |
556 | var domicilioStamp = | 557 | var domicilioStamp = |
557 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + | 558 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + |
558 | domicilio.Localidad + ', ' + domicilio.Provincia; | 559 | domicilio.Localidad + ', ' + domicilio.Provincia; |
559 | $scope.notaPedido.domicilioStamp = domicilioStamp; | 560 | $scope.notaPedido.domicilioStamp = domicilioStamp; |
560 | 561 | ||
561 | $scope.notaPedido.puntosDescarga = domicilio.puntosDescarga; | 562 | $scope.notaPedido.puntosDescarga = domicilio.puntosDescarga; |
562 | 563 | ||
563 | $scope.$broadcast('addCabecera', { | 564 | $scope.$broadcast('addCabecera', { |
564 | label: 'Cliente:', | 565 | label: 'Cliente:', |
565 | valor: $filter('rellenarDigitos')(cliente.cod, 5) + ' - ' + cliente.nom | 566 | valor: $filter('rellenarDigitos')(cliente.cod, 5) + ' - ' + cliente.nom |
566 | }); | 567 | }); |
567 | $scope.$broadcast('addCabecera', { | 568 | $scope.$broadcast('addCabecera', { |
568 | label: 'Domicilio:', | 569 | label: 'Domicilio:', |
569 | valor: domicilioStamp | 570 | valor: domicilioStamp |
570 | }); | 571 | }); |
571 | if(domicilio.verPuntos) { | 572 | if(domicilio.verPuntos) { |
572 | delete $scope.notaPedido.domicilio.verPuntos; | 573 | delete $scope.notaPedido.domicilio.verPuntos; |
573 | $scope.seleccionarPuntosDeDescarga(); | 574 | $scope.seleccionarPuntosDeDescarga(); |
574 | }else { | 575 | }else { |
575 | crearNotaPedidoService | 576 | crearNotaPedidoService |
576 | .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) | 577 | .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) |
577 | .then(function(res) { | 578 | .then(function(res) { |
578 | if(res.data.length) $scope.seleccionarPuntosDeDescarga(); | 579 | if(res.data.length) $scope.seleccionarPuntosDeDescarga(); |
579 | }); | 580 | }); |
580 | } | 581 | } |
581 | }, function() { | 582 | }, function() { |
582 | $scope.seleccionarCliente(); | 583 | $scope.seleccionarCliente(); |
583 | return; | 584 | return; |
584 | } | 585 | } |
585 | ); | 586 | ); |
586 | }; | 587 | }; |
587 | 588 | ||
588 | $scope.getTotal = function() { | 589 | $scope.getTotal = function() { |
589 | var total = 0; | 590 | var total = 0; |
590 | var arrayTempArticulos = $scope.articulosTabla; | 591 | var arrayTempArticulos = $scope.articulosTabla; |
591 | for (var i = 0; i < arrayTempArticulos.length; i++) { | 592 | for (var i = 0; i < arrayTempArticulos.length; i++) { |
592 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | 593 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; |
593 | } | 594 | } |
594 | return parseFloat(total.toFixed(2)); | 595 | return parseFloat(total.toFixed(2)); |
595 | }; | 596 | }; |
596 | 597 | ||
597 | $scope.getSubTotal = function() { | 598 | $scope.getSubTotal = function() { |
598 | if($scope.articuloACargar) { | 599 | if($scope.articuloACargar) { |
599 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; | 600 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
600 | } | 601 | } |
601 | }; | 602 | }; |
602 | 603 | ||
603 | $scope.seleccionarPreciosYCondiciones = function() { | 604 | $scope.seleccionarPreciosYCondiciones = function() { |
604 | if(validarNotaRemitada()) { | 605 | if(validarNotaRemitada()) { |
605 | var modalInstance = $uibModal.open( | 606 | var modalInstance = $uibModal.open( |
606 | { | 607 | { |
607 | ariaLabelledBy: 'Busqueda de Precio Condición', | 608 | ariaLabelledBy: 'Busqueda de Precio Condición', |
608 | templateUrl: 'modal-precio-condicion.html', | 609 | templateUrl: 'modal-precio-condicion.html', |
609 | controller: 'focaModalPrecioCondicionController', | 610 | controller: 'focaModalPrecioCondicionController', |
610 | size: 'lg' | 611 | size: 'lg' |
611 | } | 612 | } |
612 | ); | 613 | ); |
613 | modalInstance.result.then( | 614 | modalInstance.result.then( |
614 | function(precioCondicion) { | 615 | function(precioCondicion) { |
615 | var cabecera = ''; | 616 | var cabecera = ''; |
616 | var plazosConcat = ''; | 617 | var plazosConcat = ''; |
617 | if(!Array.isArray(precioCondicion)) { | 618 | if(!Array.isArray(precioCondicion)) { |
618 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; | 619 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; |
619 | $scope.plazosPagos = precioCondicion.plazoPago; | 620 | $scope.plazosPagos = precioCondicion.plazoPago; |
620 | $scope.idLista = precioCondicion.idListaPrecio; | 621 | $scope.idLista = precioCondicion.idListaPrecio; |
621 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { | 622 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { |
622 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; | 623 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; |
623 | } | 624 | } |
624 | cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + | 625 | cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + |
625 | ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); | 626 | ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); |
626 | } else { //Cuando se ingresan los plazos manualmente | 627 | } else { //Cuando se ingresan los plazos manualmente |
627 | $scope.notaPedido.idPrecioCondicion = 0; | 628 | $scope.notaPedido.idPrecioCondicion = 0; |
628 | //-1, el modal productos busca todos los productos | 629 | //-1, el modal productos busca todos los productos |
629 | $scope.idLista = -1; | 630 | $scope.idLista = -1; |
630 | $scope.plazosPagos = precioCondicion; | 631 | $scope.plazosPagos = precioCondicion; |
631 | for(var j = 0; j < precioCondicion.length; j++) { | 632 | for(var j = 0; j < precioCondicion.length; j++) { |
632 | plazosConcat += precioCondicion[j].dias + ' '; | 633 | plazosConcat += precioCondicion[j].dias + ' '; |
633 | } | 634 | } |
634 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); | 635 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); |
635 | } | 636 | } |
636 | $scope.articulosTabla = []; | 637 | $scope.articulosTabla = []; |
637 | $scope.$broadcast('addCabecera', { | 638 | $scope.$broadcast('addCabecera', { |
638 | label: 'Precios y condiciones:', | 639 | label: 'Precios y condiciones:', |
639 | valor: cabecera | 640 | valor: cabecera |
640 | }); | 641 | }); |
641 | }, function() { | 642 | }, function() { |
642 | 643 | ||
643 | } | 644 | } |
644 | ); | 645 | ); |
645 | } | 646 | } |
646 | }; | 647 | }; |
647 | 648 | ||
648 | $scope.seleccionarFlete = function() { | 649 | $scope.seleccionarFlete = function() { |
649 | if(validarNotaRemitada()) { | 650 | if(validarNotaRemitada()) { |
650 | var modalInstance = $uibModal.open( | 651 | var modalInstance = $uibModal.open( |
651 | { | 652 | { |
652 | ariaLabelledBy: 'Busqueda de Flete', | 653 | ariaLabelledBy: 'Busqueda de Flete', |
653 | templateUrl: 'modal-flete.html', | 654 | templateUrl: 'modal-flete.html', |
654 | controller: 'focaModalFleteController', | 655 | controller: 'focaModalFleteController', |
655 | size: 'lg', | 656 | size: 'lg', |
656 | resolve: { | 657 | resolve: { |
657 | parametrosFlete: | 658 | parametrosFlete: |
658 | function() { | 659 | function() { |
659 | return { | 660 | return { |
660 | flete: $scope.notaPedido.fob ? 'FOB' : | 661 | flete: $scope.notaPedido.fob ? 'FOB' : |
661 | ( $scope.notaPedido.flete ? '1' : | 662 | ( $scope.notaPedido.flete ? '1' : |
662 | ($scope.notaPedido.flete === undefined ? | 663 | ($scope.notaPedido.flete === undefined ? |
663 | null : '0')), | 664 | null : '0')), |
664 | bomba: $scope.notaPedido.bomba ? '1' : | 665 | bomba: $scope.notaPedido.bomba ? '1' : |
665 | ($scope.notaPedido.bomba === undefined ? | 666 | ($scope.notaPedido.bomba === undefined ? |
666 | null : '0'), | 667 | null : '0'), |
667 | kilometros: $scope.notaPedido.kilometros | 668 | kilometros: $scope.notaPedido.kilometros |
668 | }; | 669 | }; |
669 | } | 670 | } |
670 | } | 671 | } |
671 | } | 672 | } |
672 | ); | 673 | ); |
673 | modalInstance.result.then( | 674 | modalInstance.result.then( |
674 | function(datos) { | 675 | function(datos) { |
675 | $scope.notaPedido.flete = datos.flete; | 676 | $scope.notaPedido.flete = datos.flete; |
676 | $scope.notaPedido.fob = datos.FOB; | 677 | $scope.notaPedido.fob = datos.FOB; |
677 | $scope.notaPedido.bomba = datos.bomba; | 678 | $scope.notaPedido.bomba = datos.bomba; |
678 | $scope.notaPedido.kilometros = datos.kilometros; | 679 | $scope.notaPedido.kilometros = datos.kilometros; |
679 | $scope.$broadcast('addCabecera', { | 680 | $scope.$broadcast('addCabecera', { |
680 | label: 'Flete:', | 681 | label: 'Flete:', |
681 | valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') | 682 | valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') |
682 | }); | 683 | }); |
683 | if(datos.flete) { | 684 | if(datos.flete) { |
684 | $scope.$broadcast('addCabecera', { | 685 | $scope.$broadcast('addCabecera', { |
685 | label: 'Bomba:', | 686 | label: 'Bomba:', |
686 | valor: datos.bomba ? 'Si' : 'No' | 687 | valor: datos.bomba ? 'Si' : 'No' |
687 | }); | 688 | }); |
688 | $scope.$broadcast('addCabecera', { | 689 | $scope.$broadcast('addCabecera', { |
689 | label: 'Kilometros:', | 690 | label: 'Kilometros:', |
690 | valor: datos.kilometros | 691 | valor: datos.kilometros |
691 | }); | 692 | }); |
692 | } else { | 693 | } else { |
693 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 694 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
694 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 695 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
695 | $scope.notaPedido.bomba = false; | 696 | $scope.notaPedido.bomba = false; |
696 | $scope.notaPedido.kilometros = null; | 697 | $scope.notaPedido.kilometros = null; |
697 | } | 698 | } |
698 | }, function() { | 699 | }, function() { |
699 | 700 | ||
700 | } | 701 | } |
701 | ); | 702 | ); |
702 | } | 703 | } |
703 | }; | 704 | }; |
704 | 705 | ||
705 | $scope.seleccionarMoneda = function() { | 706 | $scope.seleccionarMoneda = function() { |
706 | if(validarNotaRemitada()) { | 707 | if(validarNotaRemitada()) { |
707 | var parametrosModal = { | 708 | var parametrosModal = { |
708 | titulo: 'Búsqueda de monedas', | 709 | titulo: 'Búsqueda de monedas', |
709 | query: '/moneda', | 710 | query: '/moneda', |
710 | columnas: [ | 711 | columnas: [ |
711 | { | 712 | { |
712 | propiedad: 'DETALLE', | 713 | propiedad: 'DETALLE', |
713 | nombre: 'Nombre' | 714 | nombre: 'Nombre' |
714 | }, | 715 | }, |
715 | { | 716 | { |
716 | propiedad: 'SIMBOLO', | 717 | propiedad: 'SIMBOLO', |
717 | nombre: 'Símbolo' | 718 | nombre: 'Símbolo' |
718 | } | 719 | } |
719 | ], | 720 | ], |
720 | size: 'md' | 721 | size: 'md' |
721 | }; | 722 | }; |
722 | focaModalService.modal(parametrosModal).then( | 723 | focaModalService.modal(parametrosModal).then( |
723 | function(moneda) { | 724 | function(moneda) { |
724 | $scope.abrirModalCotizacion(moneda); | 725 | $scope.abrirModalCotizacion(moneda); |
725 | }, function() { | 726 | }, function() { |
726 | 727 | ||
727 | } | 728 | } |
728 | ); | 729 | ); |
729 | } | 730 | } |
730 | }; | 731 | }; |
731 | 732 | ||
732 | $scope.abrirModalCotizacion = function(moneda) { | 733 | $scope.abrirModalCotizacion = function(moneda) { |
733 | var modalInstance = $uibModal.open( | 734 | var modalInstance = $uibModal.open( |
734 | { | 735 | { |
735 | ariaLabelledBy: 'Busqueda de Cotización', | 736 | ariaLabelledBy: 'Busqueda de Cotización', |
736 | templateUrl: 'modal-cotizacion.html', | 737 | templateUrl: 'modal-cotizacion.html', |
737 | controller: 'focaModalCotizacionController', | 738 | controller: 'focaModalCotizacionController', |
738 | size: 'lg', | 739 | size: 'lg', |
739 | resolve: {idMoneda: function() {return moneda.ID;}} | 740 | resolve: {idMoneda: function() {return moneda.ID;}} |
740 | } | 741 | } |
741 | ); | 742 | ); |
742 | modalInstance.result.then( | 743 | modalInstance.result.then( |
743 | function(cotizacion) { | 744 | function(cotizacion) { |
744 | var articulosTablaTemp = $scope.articulosTabla; | 745 | var articulosTablaTemp = $scope.articulosTabla; |
745 | for(var i = 0; i < articulosTablaTemp.length; i++) { | 746 | for(var i = 0; i < articulosTablaTemp.length; i++) { |
746 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * | 747 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * |
747 | $scope.notaPedido.cotizacion.VENDEDOR; | 748 | $scope.notaPedido.cotizacion.VENDEDOR; |
748 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / | 749 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / |
749 | cotizacion.VENDEDOR; | 750 | cotizacion.VENDEDOR; |
750 | } | 751 | } |
751 | $scope.articulosTabla = articulosTablaTemp; | 752 | $scope.articulosTabla = articulosTablaTemp; |
752 | $scope.notaPedido.moneda = moneda; | 753 | $scope.notaPedido.moneda = moneda; |
753 | $scope.notaPedido.cotizacion = cotizacion; | 754 | $scope.notaPedido.cotizacion = cotizacion; |
754 | if(moneda.DETALLE === 'PESOS ARGENTINOS') { | 755 | if(moneda.DETALLE === 'PESOS ARGENTINOS') { |
755 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 756 | $scope.$broadcast('removeCabecera', 'Moneda:'); |
756 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 757 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); |
757 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 758 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); |
758 | }else { | 759 | }else { |
759 | $scope.$broadcast('addCabecera', { | 760 | $scope.$broadcast('addCabecera', { |
760 | label: 'Moneda:', | 761 | label: 'Moneda:', |
761 | valor: moneda.DETALLE | 762 | valor: moneda.DETALLE |
762 | }); | 763 | }); |
763 | $scope.$broadcast('addCabecera', { | 764 | $scope.$broadcast('addCabecera', { |
764 | label: 'Fecha cotizacion:', | 765 | label: 'Fecha cotizacion:', |
765 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 766 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') |
766 | }); | 767 | }); |
767 | $scope.$broadcast('addCabecera', { | 768 | $scope.$broadcast('addCabecera', { |
768 | label: 'Cotizacion:', | 769 | label: 'Cotizacion:', |
769 | valor: $filter('number')(cotizacion.VENDEDOR, '2') | 770 | valor: $filter('number')(cotizacion.VENDEDOR, '2') |
770 | }); | 771 | }); |
771 | } | 772 | } |
772 | }, function() { | 773 | }, function() { |
773 | 774 | ||
774 | } | 775 | } |
775 | ); | 776 | ); |
776 | }; | 777 | }; |
777 | 778 | ||
778 | $scope.agregarATabla = function(key) { | 779 | $scope.agregarATabla = function(key) { |
779 | if(key === 13) { | 780 | if(key === 13) { |
780 | if($scope.articuloACargar.cantidad === undefined || | 781 | if($scope.articuloACargar.cantidad === undefined || |
781 | $scope.articuloACargar.cantidad === 0 || | 782 | $scope.articuloACargar.cantidad === 0 || |
782 | $scope.articuloACargar.cantidad === null ) { | 783 | $scope.articuloACargar.cantidad === null ) { |
783 | focaModalService.alert('El valor debe ser al menos 1'); | 784 | focaModalService.alert('El valor debe ser al menos 1'); |
784 | return; | 785 | return; |
785 | } | 786 | } |
786 | delete $scope.articuloACargar.sectorCodigo; | 787 | delete $scope.articuloACargar.sectorCodigo; |
787 | $scope.articulosTabla.push($scope.articuloACargar); | 788 | $scope.articulosTabla.push($scope.articuloACargar); |
788 | $scope.cargando = true; | 789 | $scope.cargando = true; |
789 | } | 790 | } |
790 | }; | 791 | }; |
791 | 792 | ||
792 | $scope.quitarArticulo = function(key) { | 793 | $scope.quitarArticulo = function(key) { |
793 | $scope.articulosTabla.splice(key, 1); | 794 | $scope.articulosTabla.splice(key, 1); |
794 | }; | 795 | }; |
795 | 796 | ||
796 | $scope.editarArticulo = function(key, articulo) { | 797 | $scope.editarArticulo = function(key, articulo) { |
797 | if(key === 13) { | 798 | if(key === 13) { |
798 | if(articulo.cantidad === null || articulo.cantidad === 0 || | 799 | if(articulo.cantidad === null || articulo.cantidad === 0 || |
799 | articulo.cantidad === undefined) { | 800 | articulo.cantidad === undefined) { |
800 | focaModalService.alert('El valor debe ser al menos 1'); | 801 | focaModalService.alert('El valor debe ser al menos 1'); |
801 | return; | 802 | return; |
802 | } | 803 | } |
803 | articulo.editCantidad = false; | 804 | articulo.editCantidad = false; |
804 | articulo.editPrecio = false; | 805 | articulo.editPrecio = false; |
805 | } | 806 | } |
806 | }; | 807 | }; |
807 | 808 | ||
808 | $scope.cambioEdit = function(articulo, propiedad) { | 809 | $scope.cambioEdit = function(articulo, propiedad) { |
809 | if(propiedad === 'cantidad') { | 810 | if(propiedad === 'cantidad') { |
810 | articulo.editCantidad = true; | 811 | articulo.editCantidad = true; |
811 | } else if(propiedad === 'precio') { | 812 | } else if(propiedad === 'precio') { |
812 | articulo.editPrecio = true; | 813 | articulo.editPrecio = true; |
813 | } | 814 | } |
814 | }; | 815 | }; |
815 | 816 | ||
816 | $scope.resetFilter = function() { | 817 | $scope.resetFilter = function() { |
817 | $scope.articuloACargar = {}; | 818 | $scope.articuloACargar = {}; |
818 | $scope.cargando = true; | 819 | $scope.cargando = true; |
819 | }; | 820 | }; |
820 | //Recibe aviso si el teclado está en uso | 821 | //Recibe aviso si el teclado está en uso |
821 | $rootScope.$on('usarTeclado', function(event, data) { | 822 | $rootScope.$on('usarTeclado', function(event, data) { |
822 | if(data) { | 823 | if(data) { |
823 | $scope.mostrarTeclado = true; | 824 | $scope.mostrarTeclado = true; |
824 | return; | 825 | return; |
825 | } | 826 | } |
826 | $scope.mostrarTeclado = false; | 827 | $scope.mostrarTeclado = false; |
827 | }); | 828 | }); |
828 | 829 | ||
829 | $scope.selectFocus = function($event) { | 830 | $scope.selectFocus = function($event) { |
830 | // Si el teclado esta en uso no selecciona el valor | 831 | // Si el teclado esta en uso no selecciona el valor |
831 | if($scope.mostrarTeclado) { | 832 | if($scope.mostrarTeclado) { |
832 | return; | 833 | return; |
833 | } | 834 | } |
834 | $event.target.select(); | 835 | $event.target.select(); |
835 | }; | 836 | }; |
836 | 837 | ||
837 | $scope.salir = function() { | 838 | $scope.salir = function() { |
838 | $location.path('/'); | 839 | $location.path('/'); |
839 | }; | 840 | }; |
840 | 841 | ||
841 | $scope.parsearATexto = function(articulo) { | 842 | $scope.parsearATexto = function(articulo) { |
842 | articulo.cantidad = parseFloat(articulo.cantidad); | 843 | articulo.cantidad = parseFloat(articulo.cantidad); |
843 | articulo.precio = parseFloat(articulo.precio); | 844 | articulo.precio = parseFloat(articulo.precio); |
844 | }; | 845 | }; |
845 | 846 | ||
846 | function addArrayCabecera(array) { | 847 | function addArrayCabecera(array) { |
847 | for(var i = 0; i < array.length; i++) { | 848 | for(var i = 0; i < array.length; i++) { |
848 | $scope.$broadcast('addCabecera', { | 849 | $scope.$broadcast('addCabecera', { |
849 | label: array[i].label, | 850 | label: array[i].label, |
850 | valor: array[i].valor | 851 | valor: array[i].valor |
851 | }); | 852 | }); |
852 | } | 853 | } |
853 | } | 854 | } |
854 | 855 | ||
855 | function rellenar(relleno, longitud) { | 856 | function rellenar(relleno, longitud) { |
856 | relleno = '' + relleno; | 857 | relleno = '' + relleno; |
857 | while (relleno.length < longitud) { | 858 | while (relleno.length < longitud) { |
858 | relleno = '0' + relleno; | 859 | relleno = '0' + relleno; |
859 | } | 860 | } |
860 | 861 | ||
861 | return relleno; | 862 | return relleno; |
862 | } | 863 | } |
863 | 864 | ||
864 | function validarNotaRemitada() { | 865 | function validarNotaRemitada() { |
865 | if(!$scope.notaPedido.idRemito) { | 866 | if(!$scope.notaPedido.idRemito) { |
866 | return true; | 867 | return true; |
867 | }else{ | 868 | }else{ |
868 | focaModalService.alert('No se puede editar una nota de pedido remitada'); | 869 | focaModalService.alert('No se puede editar una nota de pedido remitada'); |
869 | return false; | 870 | return false; |
870 | } | 871 | } |
871 | } | 872 | } |
872 | function formatearPuntosDescarga(puntosDescarga) { | 873 | function formatearPuntosDescarga(puntosDescarga) { |
873 | var result = []; | 874 | var result = []; |
874 | 875 | ||
875 | puntosDescarga.forEach(function(el) { | 876 | puntosDescarga.forEach(function(el) { |
876 | var puntoDescarga = result.filter(function(resultPunto) { | 877 | var puntoDescarga = result.filter(function(resultPunto) { |
877 | return resultPunto.id == el.idPuntoDescarga; | 878 | return resultPunto.id === el.idPuntoDescarga; |
878 | }); | 879 | }); |
879 | 880 | ||
880 | if(puntoDescarga.length) { | 881 | if(puntoDescarga.length) { |
881 | puntoDescarga[0].articulosAgregados.push({ | 882 | puntoDescarga[0].articulosAgregados.push({ |
882 | cantidad: el.cantidad, | 883 | cantidad: el.cantidad, |
883 | descripcion: el.producto.descripcion, | 884 | descripcion: el.producto.descripcion, |
884 | id: el.producto.id | 885 | id: el.producto.id |
885 | }); | 886 | }); |
886 | }else { | 887 | }else { |
887 | result.push({ | 888 | result.push({ |
888 | id: el.puntoDescarga.id, | 889 | id: el.puntoDescarga.id, |
889 | id_cliente: el.puntoDescarga.id_cliente, | 890 | id_cliente: el.puntoDescarga.id_cliente, |
890 | id_da_config_0: el.puntoDescarga.id_da_config_0, | 891 | id_da_config_0: el.puntoDescarga.id_da_config_0, |
891 | latitud: el.puntoDescarga.latitud, | 892 | latitud: el.puntoDescarga.latitud, |
892 | longitud: el.puntoDescarga.longitud, | 893 | longitud: el.puntoDescarga.longitud, |
893 | descripcion: el.puntoDescarga.descripcion, | 894 | descripcion: el.puntoDescarga.descripcion, |
894 | articulosAgregados: [ | 895 | articulosAgregados: [ |
895 | { | 896 | { |
896 | cantidad: el.cantidad, | 897 | cantidad: el.cantidad, |
897 | descripcion: el.producto.descripcion, | 898 | descripcion: el.producto.descripcion, |
898 | id: el.producto.id | 899 | id: el.producto.id |
899 | } | 900 | } |
900 | ] | 901 | ] |
901 | }); | 902 | }); |
902 | } | 903 | } |
903 | }); | 904 | }); |
904 | return result; | 905 | return result; |
905 | } | 906 | } |
906 | 907 | ||
907 | function salir() { | 908 | function salir() { |
908 | var notaPedido = { | 909 | var notaPedido = { |
909 | id: 0, | 910 | id: 0, |
910 | vendedor: {}, | 911 | vendedor: {}, |
911 | cliente: {}, | 912 | cliente: {}, |
912 | proveedor: {}, | 913 | proveedor: {}, |
913 | domicilio: {dom: ''}, | 914 | domicilio: {dom: ''}, |
914 | moneda: $scope.notaPedido.moneda, | 915 | moneda: $scope.notaPedido.moneda, |
915 | cotizacion: $scope.notaPedido.cotizacion | 916 | cotizacion: $scope.notaPedido.cotizacion |
916 | }; | 917 | }; |
917 | if(JSON.stringify($scope.notaPedido) !== JSON.stringify(notaPedido)) { | 918 | if(JSON.stringify($scope.notaPedido) !== JSON.stringify(notaPedido)) { |
918 | focaModalService | 919 | focaModalService |
919 | .confirm('¿Esta seguro de que desea salir? ' + | 920 | .confirm('¿Esta seguro de que desea salir? ' + |
920 | 'Se perderán todos los datos cargados.') | 921 | 'Se perderán todos los datos cargados.') |
921 | .then(function(data) { | 922 | .then(function(data) { |
922 | if(data) $location.path('/'); | 923 | if(data) $location.path('/'); |
923 | }); | 924 | }); |
924 | }else { | 925 | }else { |
925 | $location.path('/'); | 926 | $location.path('/'); |
926 | } | 927 | } |
927 | } | 928 | } |
928 | } | 929 | } |
929 | ]); | 930 | ]); |
930 | 931 |
src/js/service.js
1 | angular.module('focaCrearNotaPedido') | 1 | angular.module('focaCrearNotaPedido') |
2 | .service('crearNotaPedidoService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { | 2 | .service('crearNotaPedidoService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { |
3 | var route = API_ENDPOINT.URL; | 3 | var route = API_ENDPOINT.URL; |
4 | return { | 4 | return { |
5 | crearNotaPedido: function(notaPedido) { | 5 | crearNotaPedido: function(notaPedido) { |
6 | return $http.post(route + '/nota-pedido', {notaPedido: notaPedido}); | 6 | return $http.post(route + '/nota-pedido', {notaPedido: notaPedido}); |
7 | }, | 7 | }, |
8 | obtenerNotaPedido: function() { | 8 | obtenerNotaPedido: function() { |
9 | return $http.get(route +'/nota-pedido'); | 9 | return $http.get(route +'/nota-pedido'); |
10 | }, | 10 | }, |
11 | setNotaPedido: function(notaPedido) { | 11 | setNotaPedido: function(notaPedido) { |
12 | this.notaPedido = notaPedido; | 12 | this.notaPedido = notaPedido; |
13 | }, | 13 | }, |
14 | clearNotaPedido: function() { | 14 | clearNotaPedido: function() { |
15 | this.notaPedido = undefined; | 15 | this.notaPedido = undefined; |
16 | }, | 16 | }, |
17 | getNotaPedido: function() { | 17 | getNotaPedido: function() { |
18 | return this.notaPedido; | 18 | return this.notaPedido; |
19 | }, | 19 | }, |
20 | getArticulosByIdNotaPedido: function(id) { | 20 | getArticulosByIdNotaPedido: function(id) { |
21 | return $http.get(route+'/articulos/nota-pedido/'+id); | 21 | return $http.get(route+'/articulos/nota-pedido/'+id); |
22 | }, | 22 | }, |
23 | crearArticulosParaNotaPedido: function(articuloNotaPedido) { | 23 | crearArticulosParaNotaPedido: function(articuloNotaPedido) { |
24 | return $http.post(route + '/articulos/nota-pedido', | 24 | return $http.post(route + '/articulos/nota-pedido', |
25 | {articuloNotaPedido: articuloNotaPedido}); | 25 | {articuloNotaPedido: articuloNotaPedido}); |
26 | }, | 26 | }, |
27 | getDomiciliosByIdNotaPedido: function(id) { | 27 | getDomiciliosByIdNotaPedido: function(id) { |
28 | return $http.get(route +'/nota-pedido/'+id+'/domicilios'); | 28 | return $http.get(route +'/nota-pedido/'+id+'/domicilios'); |
29 | }, | 29 | }, |
30 | getDomiciliosByIdCliente: function(id) { | 30 | getDomiciliosByIdCliente: function(id) { |
31 | var idTipoEntrega = 2;//Solo traigo los domicilios que tienen tipo 2 (tipo entrega) | 31 | var idTipoEntrega = 2;//Solo traigo los domicilios que tienen tipo 2 (tipo entrega) |
32 | return $http.get(route + '/domicilio/tipo/' + idTipoEntrega + '/cliente/' + id ); | 32 | return $http.get(route + '/domicilio/tipo/' + idTipoEntrega + '/cliente/' + id ); |
33 | }, | 33 | }, |
34 | getPrecioCondicion: function() { | 34 | getPrecioCondicion: function() { |
35 | return $http.get(route + '/precio-condicion'); | 35 | return $http.get(route + '/precio-condicion'); |
36 | }, | 36 | }, |
37 | getPrecioCondicionById: function(id) { | 37 | getPrecioCondicionById: function(id) { |
38 | return $http.get(route + '/precio-condicion/' + id); | 38 | return $http.get(route + '/precio-condicion/' + id); |
39 | }, | 39 | }, |
40 | getPlazoPagoByPrecioCondicion: function(id) { | 40 | getPlazoPagoByPrecioCondicion: function(id) { |
41 | return $http.get(route + '/plazo-pago/precio-condicion/'+ id); | 41 | return $http.get(route + '/plazo-pago/precio-condicion/'+ id); |
42 | }, | 42 | }, |
43 | crearFlete: function(flete) { | 43 | crearFlete: function(flete) { |
44 | return $http.post(route + '/flete', {flete : flete}); | 44 | return $http.post(route + '/flete', {flete : flete}); |
45 | }, | 45 | }, |
46 | crearPlazosParaNotaPedido: function(plazos) { | 46 | crearPlazosParaNotaPedido: function(plazos) { |
47 | return $http.post(route + '/plazo-pago/nota-pedido', {plazos: plazos}); | 47 | return $http.post(route + '/plazo-pago/nota-pedido', {plazos: plazos}); |
48 | }, | 48 | }, |
49 | getCotizacionByIdMoneda: function(id) { | 49 | getCotizacionByIdMoneda: function(id) { |
50 | return $http.get(route + '/moneda/' + id); | 50 | return $http.get(route + '/moneda/' + id); |
51 | }, | 51 | }, |
52 | crearEstadoParaNotaPedido: function(estado) { | 52 | crearEstadoParaNotaPedido: function(estado) { |
53 | return $http.post(route + '/estado', {estado: estado}); | 53 | return $http.post(route + '/estado', {estado: estado}); |
54 | }, | 54 | }, |
55 | getNumeroNotaPedido: function() { | 55 | getNumeroNotaPedido: function() { |
56 | return $http.get(route + '/nota-pedido/numero-siguiente'); | 56 | return $http.get(route + '/nota-pedido/numero-siguiente'); |
57 | }, | 57 | }, |
58 | getBotonera: function(vendedor) { | 58 | getBotonera: function(vendedor) { |
59 | var result = [ | 59 | var result = [ |
60 | { | 60 | { |
61 | label: 'Cliente', | 61 | label: 'Cliente', |
62 | image: 'cliente.png' | 62 | image: 'cliente.png' |
63 | }, | 63 | }, |
64 | { | 64 | { |
65 | label: 'Proveedor', | 65 | label: 'Proveedor', |
66 | image: 'proveedor.png' | 66 | image: 'proveedor.png' |
67 | }, | 67 | }, |
68 | { | 68 | { |
69 | label: 'Moneda', | 69 | label: 'Moneda', |
70 | image: 'moneda.png' | 70 | image: 'moneda.png' |
71 | }, | 71 | }, |
72 | { | 72 | { |
73 | label: 'Precios y condiciones', | 73 | label: 'Precios y condiciones', |
74 | image: 'precios-condiciones.png' | 74 | image: 'precios-condiciones.png' |
75 | }, | 75 | }, |
76 | { | 76 | { |
77 | label: 'Flete', | 77 | label: 'Flete', |
78 | image: 'flete.png' | 78 | image: 'flete.png' |
79 | }, | 79 | }, |
80 | { | 80 | { |
81 | label: 'Productos', | 81 | label: 'Productos', |
82 | image: 'productos.png' | 82 | image: 'productos.png' |
83 | } | 83 | } |
84 | ]; | 84 | ]; |
85 | |||
85 | if(!vendedor) { | 86 | if(!vendedor) { |
86 | var botonVendedor = { | 87 | var botonVendedor = { |
87 | label: 'Vendedor', | 88 | label: 'Vendedor', |
88 | image: 'vendedor.png' | 89 | image: 'vendedor.png' |
89 | } | 90 | }; |
90 | result.unshift(botonVendedor) | 91 | |
92 | result.unshift(botonVendedor); | ||
91 | } | 93 | } |
94 | |||
92 | return result; | 95 | return result; |
93 | }, | 96 | }, |
94 | crearPuntosDescarga: function(puntosDescarga) { | 97 | crearPuntosDescarga: function(puntosDescarga) { |
95 | return $http.post(route + '/puntos-descarga/nota-pedido', | 98 | return $http.post(route + '/puntos-descarga/nota-pedido', |
96 | {puntosDescarga: puntosDescarga}); | 99 | {puntosDescarga: puntosDescarga}); |
97 | }, | 100 | }, |
98 | getPuntosDescargaByClienDom: function(idDomicilio, idCliente) { | 101 | getPuntosDescargaByClienDom: function(idDomicilio, idCliente) { |
99 | return $http.get(API_ENDPOINT.URL + '/punto-descarga/' + | 102 | return $http.get(API_ENDPOINT.URL + '/punto-descarga/' + |
100 | idDomicilio + '/' + idCliente); | 103 | idDomicilio + '/' + idCliente); |
101 | }, | 104 | }, |
102 | getVendedorById: function(id) { | 105 | getVendedorById: function(id) { |
103 | return $http.get(API_ENDPOINT.URL + '/vendedor-cobrador/' + id); | 106 | return $http.get(API_ENDPOINT.URL + '/vendedor-cobrador/' + id); |
104 | } | 107 | } |
105 | }; | 108 | }; |
106 | }]); | 109 | }]); |
107 | 110 |