Commit f97fdee1d1239cdfd320c0ba137137e59aa8f601
1 parent
f214f3f429
Exists in
master
save remito
Showing
1 changed file
with
67 additions
and
67 deletions
Show diff stats
src/js/controller.js
1 | angular.module('focaCrearRemito') .controller('remitoController', | 1 | angular.module('focaCrearRemito') .controller('remitoController', |
2 | [ | 2 | [ |
3 | '$scope', '$uibModal', '$location', '$filter', 'crearRemitoService', '$timeout', | 3 | '$scope', '$uibModal', '$location', '$filter', 'crearRemitoService', '$timeout', |
4 | 'focaModalService', 'remitoBusinessService', '$rootScope', 'focaBotoneraLateralService', | 4 | 'focaModalService', 'remitoBusinessService', '$rootScope', 'focaBotoneraLateralService', |
5 | '$localStorage', | 5 | '$localStorage', |
6 | function( | 6 | function( |
7 | $scope, $uibModal, $location, $filter, crearRemitoService, $timeout, focaModalService, | 7 | $scope, $uibModal, $location, $filter, crearRemitoService, $timeout, focaModalService, |
8 | remitoBusinessService, $rootScope, focaBotoneraLateralService, $localStorage) | 8 | remitoBusinessService, $rootScope, focaBotoneraLateralService, $localStorage) |
9 | { | 9 | { |
10 | config(); | 10 | config(); |
11 | 11 | ||
12 | function config() { | 12 | function config() { |
13 | $scope.botonera = crearRemitoService.getBotonera(); | 13 | $scope.botonera = crearRemitoService.getBotonera(); |
14 | $scope.isNumber = angular.isNumber; | 14 | $scope.isNumber = angular.isNumber; |
15 | $scope.datepickerAbierto = false; | 15 | $scope.datepickerAbierto = false; |
16 | $scope.show = false; | 16 | $scope.show = false; |
17 | $scope.cargando = true; | 17 | $scope.cargando = true; |
18 | $scope.now = new Date(); | 18 | $scope.now = new Date(); |
19 | $scope.puntoVenta = rellenar(0, 4); | 19 | $scope.puntoVenta = rellenar(0, 4); |
20 | $scope.comprobante = rellenar(0, 8); | 20 | $scope.comprobante = rellenar(0, 8); |
21 | $scope.dateOptions = { | 21 | $scope.dateOptions = { |
22 | maxDate: new Date(), | 22 | maxDate: new Date(), |
23 | minDate: new Date(2010, 0, 1) | 23 | minDate: new Date(2010, 0, 1) |
24 | }; | 24 | }; |
25 | 25 | ||
26 | var monedaPorDefecto; | 26 | var monedaPorDefecto; |
27 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' | 27 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' |
28 | crearRemitoService.getCotizacionByIdMoneda(1).then(function(res) { | 28 | crearRemitoService.getCotizacionByIdMoneda(1).then(function(res) { |
29 | monedaPorDefecto = res.data[0]; | 29 | monedaPorDefecto = res.data[0]; |
30 | 30 | ||
31 | $scope.remito.cotizacion = Object.assign( | 31 | $scope.remito.cotizacion = Object.assign( |
32 | {moneda: monedaPorDefecto}, monedaPorDefecto.cotizaciones[0] | 32 | {moneda: monedaPorDefecto}, monedaPorDefecto.cotizaciones[0] |
33 | ); | 33 | ); |
34 | $scope.inicial.cotizacion = $scope.remito.cotizacion; | 34 | $scope.inicial.cotizacion = $scope.remito.cotizacion; |
35 | $scope.cotizacionPorDefecto = angular.copy($scope.remito.cotizacion); | 35 | $scope.cotizacionPorDefecto = angular.copy($scope.remito.cotizacion); |
36 | }); | 36 | }); |
37 | 37 | ||
38 | //SETEO BOTONERA LATERAL | 38 | //SETEO BOTONERA LATERAL |
39 | $timeout(function() { | 39 | $timeout(function() { |
40 | focaBotoneraLateralService.showSalir(false); | 40 | focaBotoneraLateralService.showSalir(false); |
41 | focaBotoneraLateralService.showPausar(true); | 41 | focaBotoneraLateralService.showPausar(true); |
42 | focaBotoneraLateralService.showGuardar(true, $scope.crearRemito); | 42 | focaBotoneraLateralService.showGuardar(true, $scope.crearRemito); |
43 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 43 | focaBotoneraLateralService.addCustomButton('Salir', salir); |
44 | }); | 44 | }); |
45 | 45 | ||
46 | init(); | 46 | init(); |
47 | $timeout(function() {getLSRemito();}); | 47 | $timeout(function() {getLSRemito();}); |
48 | } | 48 | } |
49 | 49 | ||
50 | function init() { | 50 | function init() { |
51 | $scope.$broadcast('cleanCabecera'); | 51 | $scope.$broadcast('cleanCabecera'); |
52 | 52 | ||
53 | $scope.remito = { | 53 | $scope.remito = { |
54 | id: 0, | 54 | id: 0, |
55 | estado: 0, | 55 | estado: 0, |
56 | vendedor: {}, | 56 | vendedor: {}, |
57 | cliente: {}, | 57 | cliente: {}, |
58 | proveedor: {}, | 58 | proveedor: {}, |
59 | domicilio: {dom: ''}, | 59 | domicilio: {dom: ''}, |
60 | moneda: {}, | 60 | moneda: {}, |
61 | cotizacion: $scope.cotizacionPorDefecto || {}, | 61 | cotizacion: $scope.cotizacionPorDefecto || {}, |
62 | articulosRemito: [] | 62 | articulosRemito: [] |
63 | }; | 63 | }; |
64 | 64 | ||
65 | $scope.notaPedido = { | 65 | $scope.notaPedido = { |
66 | id: 0 | 66 | id: 0 |
67 | }; | 67 | }; |
68 | 68 | ||
69 | $scope.remito.articulosRemito = []; | 69 | $scope.remito.articulosRemito = []; |
70 | $scope.idLista = undefined; | 70 | $scope.idLista = undefined; |
71 | 71 | ||
72 | crearRemitoService.getNumeroRemito().then( | 72 | crearRemitoService.getNumeroRemito().then( |
73 | function(res) { | 73 | function(res) { |
74 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); | 74 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); |
75 | $scope.comprobante = rellenar(res.data.numeroRemito, 8); | 75 | $scope.comprobante = rellenar(res.data.numeroRemito, 8); |
76 | }, | 76 | }, |
77 | function(err) { | 77 | function(err) { |
78 | focaModalService.alert('La terminal no esta configurada correctamente'); | 78 | focaModalService.alert('La terminal no esta configurada correctamente'); |
79 | console.info(err); | 79 | console.info(err); |
80 | } | 80 | } |
81 | ); | 81 | ); |
82 | 82 | ||
83 | $scope.inicial = angular.copy($scope.remito); | 83 | $scope.inicial = angular.copy($scope.remito); |
84 | } | 84 | } |
85 | 85 | ||
86 | $scope.$watch('remito', function(newValue) { | 86 | $scope.$watch('remito', function(newValue) { |
87 | focaBotoneraLateralService.setPausarData({ | 87 | focaBotoneraLateralService.setPausarData({ |
88 | label: 'remito', | 88 | label: 'remito', |
89 | val: newValue | 89 | val: newValue |
90 | }); | 90 | }); |
91 | }, true); | 91 | }, true); |
92 | 92 | ||
93 | $scope.seleccionarNotaPedido = function() { | 93 | $scope.seleccionarNotaPedido = function() { |
94 | if (varlidarRemitoFacturado()) { | 94 | if (varlidarRemitoFacturado()) { |
95 | var modalInstance = $uibModal.open( | 95 | var modalInstance = $uibModal.open( |
96 | { | 96 | { |
97 | ariaLabelledBy: 'Busqueda de Nota de Pedido', | 97 | ariaLabelledBy: 'Busqueda de Nota de Pedido', |
98 | templateUrl: 'foca-modal-nota-pedido.html', | 98 | templateUrl: 'foca-modal-nota-pedido.html', |
99 | controller: 'focaModalNotaPedidoController', | 99 | controller: 'focaModalNotaPedidoController', |
100 | size: 'lg', | 100 | size: 'lg', |
101 | resolve: { | 101 | resolve: { |
102 | usadoPor: function() { return 'remito'; }, | 102 | usadoPor: function() { return 'remito'; }, |
103 | idVendedor: function() { return null; } | 103 | idVendedor: function() { return null; } |
104 | } | 104 | } |
105 | } | 105 | } |
106 | ); | 106 | ); |
107 | modalInstance.result.then( | 107 | modalInstance.result.then( |
108 | function(notaPedido) { | 108 | function(notaPedido) { |
109 | //añado cabeceras | 109 | //añado cabeceras |
110 | $scope.notaPedido.id = notaPedido.id; | 110 | $scope.notaPedido.id = notaPedido.id; |
111 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 111 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
112 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 112 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
113 | var cabeceras = [ | 113 | var cabeceras = [ |
114 | { | 114 | { |
115 | label: 'Moneda:', | 115 | label: 'Moneda:', |
116 | valor: notaPedido.cotizacion.moneda.DETALLE | 116 | valor: notaPedido.cotizacion.moneda.DETALLE |
117 | }, | 117 | }, |
118 | { | 118 | { |
119 | label: 'Fecha cotizacion:', | 119 | label: 'Fecha cotizacion:', |
120 | valor: $filter('date')(notaPedido.cotizacion.FECHA, | 120 | valor: $filter('date')(notaPedido.cotizacion.FECHA, |
121 | 'dd/MM/yyyy') | 121 | 'dd/MM/yyyy') |
122 | }, | 122 | }, |
123 | { | 123 | { |
124 | label: 'Cotizacion:', | 124 | label: 'Cotizacion:', |
125 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, | 125 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, |
126 | '2') | 126 | '2') |
127 | }, | 127 | }, |
128 | { | 128 | { |
129 | label: 'Cliente:', | 129 | label: 'Cliente:', |
130 | valor: $filter('rellenarDigitos')(notaPedido.cliente.COD, 3) + | 130 | valor: $filter('rellenarDigitos')(notaPedido.cliente.COD, 3) + |
131 | ' - ' + notaPedido.cliente.NOM | 131 | ' - ' + notaPedido.cliente.NOM |
132 | }, | 132 | }, |
133 | { | 133 | { |
134 | label: 'Domicilio:', | 134 | label: 'Domicilio:', |
135 | valor: notaPedido.domicilioStamp | 135 | valor: notaPedido.domicilioStamp |
136 | }, | 136 | }, |
137 | { | 137 | { |
138 | label: 'Vendedor:', | 138 | label: 'Vendedor:', |
139 | valor: $filter('rellenarDigitos')( | 139 | valor: $filter('rellenarDigitos')( |
140 | notaPedido.vendedor.NUM, 3 | 140 | notaPedido.vendedor.NUM, 3 |
141 | ) + ' - ' + notaPedido.vendedor.NOM | 141 | ) + ' - ' + notaPedido.vendedor.NOM |
142 | }, | 142 | }, |
143 | { | 143 | { |
144 | label: 'Proveedor:', | 144 | label: 'Proveedor:', |
145 | valor: $filter('rellenarDigitos') | 145 | valor: $filter('rellenarDigitos') |
146 | (notaPedido.proveedor.COD, 5) + ' - ' + | 146 | (notaPedido.proveedor.COD, 5) + ' - ' + |
147 | notaPedido.proveedor.NOM | 147 | notaPedido.proveedor.NOM |
148 | }, | 148 | }, |
149 | { | 149 | { |
150 | label: 'Precio condicion:', | 150 | label: 'Precio condicion:', |
151 | valor: valorPrecioCondicion() + ' ' + | 151 | valor: valorPrecioCondicion() + ' ' + |
152 | remitoBusinessService | 152 | remitoBusinessService |
153 | .plazoToString(notaPedido.notaPedidoPlazo) | 153 | .plazoToString(notaPedido.notaPedidoPlazo) |
154 | }, | 154 | }, |
155 | { | 155 | { |
156 | label: 'Flete:', | 156 | label: 'Flete:', |
157 | valor: notaPedido.fob === 1 ? 'FOB' : ( | 157 | valor: notaPedido.fob === 1 ? 'FOB' : ( |
158 | notaPedido.flete === 1 ? 'Si' : 'No') | 158 | notaPedido.flete === 1 ? 'Si' : 'No') |
159 | } | 159 | } |
160 | ]; | 160 | ]; |
161 | 161 | ||
162 | function valorPrecioCondicion() { | 162 | function valorPrecioCondicion() { |
163 | if (notaPedido.idPrecioCondicion > 0) { | 163 | if (notaPedido.idPrecioCondicion > 0) { |
164 | return notaPedido.precioCondicion.nombre; | 164 | return notaPedido.precioCondicion.nombre; |
165 | } else { | 165 | } else { |
166 | return 'Ingreso Manual'; | 166 | return 'Ingreso Manual'; |
167 | } | 167 | } |
168 | } | 168 | } |
169 | 169 | ||
170 | if (notaPedido.flete === 1) { | 170 | if (notaPedido.flete === 1) { |
171 | var cabeceraBomba = { | 171 | var cabeceraBomba = { |
172 | label: 'Bomba:', | 172 | label: 'Bomba:', |
173 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' | 173 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' |
174 | }; | 174 | }; |
175 | if (notaPedido.kilometros) { | 175 | if (notaPedido.kilometros) { |
176 | var cabeceraKilometros = { | 176 | var cabeceraKilometros = { |
177 | label: 'Kilometros:', | 177 | label: 'Kilometros:', |
178 | valor: notaPedido.kilometros | 178 | valor: notaPedido.kilometros |
179 | }; | 179 | }; |
180 | cabeceras.push(cabeceraKilometros); | 180 | cabeceras.push(cabeceraKilometros); |
181 | } | 181 | } |
182 | cabeceras.push(cabeceraBomba); | 182 | cabeceras.push(cabeceraBomba); |
183 | } | 183 | } |
184 | 184 | ||
185 | delete notaPedido.id; | 185 | delete notaPedido.id; |
186 | $scope.remito = notaPedido; | 186 | $scope.remito = notaPedido; |
187 | $scope.remito.id = 0; | 187 | $scope.remito.id = 0; |
188 | $scope.remito.remitoPlazo = notaPedido.notaPedidoPlazo; | 188 | $scope.remito.remitoPlazo = notaPedido.notaPedidoPlazo; |
189 | 189 | ||
190 | for(var i = notaPedido.articulosNotaPedido.length - 1; i >= 0; i--) { | 190 | for(var i = notaPedido.articulosNotaPedido.length - 1; i >= 0; i--) { |
191 | notaPedido.articulosNotaPedido[i].id = 0; | 191 | notaPedido.articulosNotaPedido[i].id = 0; |
192 | notaPedido.articulosNotaPedido[i].idRemito = 0; | 192 | notaPedido.articulosNotaPedido[i].idRemito = 0; |
193 | } | 193 | } |
194 | 194 | ||
195 | $scope.remito.articulosRemito = notaPedido.articulosNotaPedido; | 195 | $scope.remito.articulosRemito = notaPedido.articulosNotaPedido; |
196 | 196 | ||
197 | if (notaPedido.idPrecioCondicion > 0) { | 197 | if (notaPedido.idPrecioCondicion > 0) { |
198 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; | 198 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; |
199 | } else { | 199 | } else { |
200 | $scope.idLista = -1; | 200 | $scope.idLista = -1; |
201 | } | 201 | } |
202 | 202 | ||
203 | enableObservaciones(notaPedido.observaciones ? true : false); | 203 | enableObservaciones(notaPedido.observaciones ? true : false); |
204 | addArrayCabecera(cabeceras); | 204 | addArrayCabecera(cabeceras); |
205 | 205 | ||
206 | }, function() { | 206 | }, function() { |
207 | // funcion ejecutada cuando se cancela el modal | 207 | // funcion ejecutada cuando se cancela el modal |
208 | } | 208 | } |
209 | ); | 209 | ); |
210 | } | 210 | } |
211 | }; | 211 | }; |
212 | 212 | ||
213 | $scope.seleccionarRemito = function() { | 213 | $scope.seleccionarRemito = function() { |
214 | var modalInstance = $uibModal.open( | 214 | var modalInstance = $uibModal.open( |
215 | { | 215 | { |
216 | ariaLabelledBy: 'Busqueda de Remito', | 216 | ariaLabelledBy: 'Busqueda de Remito', |
217 | templateUrl: 'foca-modal-remito.html', | 217 | templateUrl: 'foca-modal-remito.html', |
218 | controller: 'focaModalRemitoController', | 218 | controller: 'focaModalRemitoController', |
219 | size: 'lg', | 219 | size: 'lg', |
220 | resolve: {usadoPor: function() {return 'remito';}} | 220 | resolve: {usadoPor: function() {return 'remito';}} |
221 | } | 221 | } |
222 | ); | 222 | ); |
223 | modalInstance.result.then( | 223 | modalInstance.result.then( |
224 | setearRemito, function() { | 224 | setearRemito, function() { |
225 | // funcion ejecutada cuando se cancela el modal | 225 | // funcion ejecutada cuando se cancela el modal |
226 | } | 226 | } |
227 | ); | 227 | ); |
228 | }; | 228 | }; |
229 | 229 | ||
230 | //validacion por domicilio y por plazo pago | 230 | //validacion por domicilio y por plazo pago |
231 | $scope.crearRemito = function() { | 231 | $scope.crearRemito = function() { |
232 | if (!$scope.remito.vendedor.NUM) { | 232 | if (!$scope.remito.vendedor.NUM) { |
233 | focaModalService.alert('Ingrese Vendedor'); | 233 | focaModalService.alert('Ingrese Vendedor'); |
234 | return; | 234 | return; |
235 | } else if (!$scope.remito.cliente.COD) { | 235 | } else if (!$scope.remito.cliente.COD) { |
236 | focaModalService.alert('Ingrese Cliente'); | 236 | focaModalService.alert('Ingrese Cliente'); |
237 | return; | 237 | return; |
238 | } else if (!$scope.remito.proveedor) { | 238 | } else if (!$scope.remito.proveedor) { |
239 | focaModalService.alert('Ingrese Proveedor'); | 239 | focaModalService.alert('Ingrese Proveedor'); |
240 | return; | 240 | return; |
241 | } else if (!$scope.remito.cotizacion.moneda.id && | 241 | } else if (!$scope.remito.cotizacion.moneda.id && |
242 | !$scope.remito.cotizacion.moneda.ID){ | 242 | !$scope.remito.cotizacion.moneda.ID){ |
243 | focaModalService.alert('Ingrese Moneda'); | 243 | focaModalService.alert('Ingrese Moneda'); |
244 | return; | 244 | return; |
245 | } else if (!$scope.remito.cotizacion.ID) { | 245 | } else if (!$scope.remito.cotizacion.ID) { |
246 | focaModalService.alert('Ingrese Cotización'); | 246 | focaModalService.alert('Ingrese Cotización'); |
247 | return; | 247 | return; |
248 | } else if ($scope.remito.flete === undefined || $scope.remito.flete === null){ | 248 | } else if ($scope.remito.flete === undefined || $scope.remito.flete === null){ |
249 | focaModalService.alert('Ingrese Flete'); | 249 | focaModalService.alert('Ingrese Flete'); |
250 | return; | 250 | return; |
251 | } else if ($scope.articulosFiltro().length === 0) { | 251 | } else if ($scope.articulosFiltro().length === 0) { |
252 | focaModalService.alert('Debe cargar al menos un articulo'); | 252 | focaModalService.alert('Debe cargar al menos un articulo'); |
253 | return; | 253 | return; |
254 | } | 254 | } |
255 | focaBotoneraLateralService.startGuardar(); | 255 | focaBotoneraLateralService.startGuardar(); |
256 | $scope.saveLoading = true; | 256 | $scope.saveLoading = true; |
257 | var save = { | 257 | var save = { |
258 | remito: { | 258 | remito: { |
259 | id: $scope.remito.id, | 259 | id: $scope.remito.id, |
260 | fechaRemito: $scope.now.toISOString().slice(0, 19).replace('T', ' '), | 260 | fechaRemito: $scope.now.toISOString().slice(0, 19).replace('T', ' '), |
261 | idCliente: $scope.remito.cliente.COD, | 261 | idCliente: $scope.remito.cliente.COD, |
262 | nombreCliente: $scope.remito.cliente.NOM, | 262 | nombreCliente: $scope.remito.cliente.NOM, |
263 | cuitCliente: $scope.remito.cliente.CUIT, | 263 | cuitCliente: $scope.remito.cliente.CUIT, |
264 | responsabilidadIvaCliente: 0,//TODO, | 264 | responsabilidadIvaCliente: 0,//TODO, |
265 | descuento: 0,//TODO, | 265 | descuento: 0,//TODO, |
266 | importeNeto: 0,//TODO | 266 | importeNeto: 0,//TODO |
267 | importeExento: 0,//TODO | 267 | importeExento: 0,//TODO |
268 | importeIva: 0,//TODO | 268 | importeIva: 0,//TODO |
269 | importeIvaServicios: 0,//TODO | 269 | importeIvaServicios: 0,//TODO |
270 | importeImpuestoInterno: 0,//TODO | 270 | importeImpuestoInterno: 0,//TODO |
271 | importeImpuestoInterno1: 0,//TODO | 271 | importeImpuestoInterno1: 0,//TODO |
272 | importeImpuestoInterno2: 0,//TODO | 272 | importeImpuestoInterno2: 0,//TODO |
273 | percepcion: 0,//TODO | 273 | percepcion: 0,//TODO |
274 | percepcionIva: 0,//TODO | 274 | percepcionIva: 0,//TODO |
275 | redondeo: 0,//TODO | 275 | redondeo: 0,//TODO |
276 | total: $scope.getTotal() * $scope.remito.cotizacion.VENDEDOR, | 276 | total: $scope.getTotal() * $scope.remito.cotizacion.VENDEDOR, |
277 | numeroNotaPedido: $scope.remito.numeroNotaPedido, | 277 | numeroNotaPedido: $scope.remito.numeroNotaPedido, |
278 | anulado: false, | 278 | anulado: false, |
279 | planilla: 0,//TODO | 279 | planilla: 0,//TODO |
280 | lugar: 0,//TODO | 280 | lugar: 0,//TODO |
281 | cuentaMadre: 0,// | 281 | cuentaMadre: 0,// |
282 | cuentaContable: 0,//TODO | 282 | cuentaContable: 0,//TODO |
283 | asiento: 0,//TODO | 283 | asiento: 0,//TODO |
284 | e_hd: '',//TODO | 284 | e_hd: '',//TODO |
285 | c_hd: '', | 285 | c_hd: '', |
286 | numeroLiquidoProducto: 0,//TODO | 286 | numeroLiquidoProducto: 0,//TODO |
287 | idVendedor: $scope.remito.idVendedor, | 287 | idVendedor: $scope.remito.idVendedor, |
288 | idProveedor: $scope.remito.idProveedor, | 288 | idProveedor: $scope.remito.idProveedor, |
289 | idDomicilio: $scope.remito.idDomicilio, | 289 | idDomicilio: $scope.remito.idDomicilio, |
290 | idCotizacion: $scope.remito.cotizacion.ID, | 290 | idCotizacion: $scope.remito.cotizacion.ID, |
291 | idPrecioCondicion: $scope.remito.idPrecioCondicion, | 291 | idPrecioCondicion: $scope.remito.idPrecioCondicion, |
292 | flete: $scope.remito.flete, | 292 | flete: $scope.remito.flete, |
293 | fob: $scope.remito.fob, | 293 | fob: $scope.remito.fob, |
294 | bomba: $scope.remito.bomba, | 294 | bomba: $scope.remito.bomba, |
295 | kilometros: $scope.remito.kilometros, | 295 | kilometros: $scope.remito.kilometros, |
296 | domicilioStamp: $scope.remito.domicilioStamp, | 296 | domicilioStamp: $scope.remito.domicilioStamp, |
297 | estado: 0,//TODO | 297 | estado: 0,//TODO |
298 | destinoVenta: 0,//TODO | 298 | destinoVenta: 0,//TODO |
299 | operacionTipo: 0, //TODO | 299 | operacionTipo: 0, //TODO |
300 | observaciones: $scope.remito.observaciones, | 300 | observaciones: $scope.remito.observaciones, |
301 | numeroRemito: parseInt($scope.comprobante), | 301 | numeroRemito: parseInt($scope.comprobante), |
302 | sucursal: parseInt($scope.puntoVenta) | 302 | sucursal: parseInt($scope.puntoVenta) |
303 | }, | 303 | }, |
304 | notaPedido: $scope.notaPedido | 304 | notaPedido: $scope.notaPedido |
305 | }; | 305 | }; |
306 | 306 | ||
307 | crearRemitoService.crearRemito(save).then( | 307 | crearRemitoService.crearRemito(save).then( |
308 | function(data) { | 308 | function(data) { |
309 | 309 | ||
310 | focaBotoneraLateralService.endGuardar(true); | 310 | focaBotoneraLateralService.endGuardar(true); |
311 | $scope.saveLoading = false; | 311 | $scope.saveLoading = false; |
312 | 312 | ||
313 | $scope.remito.id = data.data.id; | ||
314 | $scope.remito.numeroRemito = data.data.numero; | ||
315 | |||
313 | remitoBusinessService.addArticulos($scope.remito.articulosRemito, | 316 | remitoBusinessService.addArticulos($scope.remito.articulosRemito, |
314 | $scope.remito.id, $scope.remito.cotizacion.VENDEDOR); | 317 | $scope.remito.id, $scope.remito.cotizacion.VENDEDOR); |
315 | 318 | ||
316 | if(data.status === 500) { | 319 | if(data.status === 500) { |
317 | focaModalService.alert(data.data); | 320 | focaModalService.alert(data.data); |
318 | return; | 321 | return; |
319 | } | 322 | } |
320 | 323 | ||
321 | // TODO: updatear plazos | 324 | // TODO: updatear plazos |
322 | if ($scope.remito.id === 0) { | 325 | if ($scope.remito.id === 0) { |
323 | |||
324 | $scope.remito.id = data.data.id; | ||
325 | $scope.remito.numeroRemito = data.data.numero; | ||
326 | var plazos = $scope.remito.remitoPlazo; | 326 | var plazos = $scope.remito.remitoPlazo; |
327 | 327 | ||
328 | for(var j = 0; j < plazos.length; j++) { | 328 | for(var j = 0; j < plazos.length; j++) { |
329 | var json = { | 329 | var json = { |
330 | idRemito: $scope.remito.id, | 330 | idRemito: $scope.remito.id, |
331 | dias: plazos[j].dias | 331 | dias: plazos[j].dias |
332 | }; | 332 | }; |
333 | crearRemitoService.crearPlazosParaRemito(json); | 333 | crearRemitoService.crearPlazosParaRemito(json); |
334 | } | 334 | } |
335 | } | 335 | } |
336 | 336 | ||
337 | abrirModalMail($scope.remito.id, | 337 | abrirModalMail($scope.remito.id, |
338 | $scope.remito.cliente, | 338 | $scope.remito.cliente, |
339 | $filter('comprobante')([ | 339 | $filter('comprobante')([ |
340 | $scope.puntoVenta, | 340 | $scope.puntoVenta, |
341 | $scope.remito.numeroRemito | 341 | $scope.remito.numeroRemito |
342 | ]) | 342 | ]) |
343 | ); | 343 | ); |
344 | 344 | ||
345 | init(); | 345 | init(); |
346 | 346 | ||
347 | }, function(error) { | 347 | }, function(error) { |
348 | focaModalService.alert('Hubo un error al crear el remito'); | 348 | focaModalService.alert(error.data || 'Hubo un error al crear el remito'); |
349 | focaBotoneraLateralService.endGuardar(); | 349 | focaBotoneraLateralService.endGuardar(); |
350 | $scope.saveLoading = false; | 350 | $scope.saveLoading = false; |
351 | console.info(error); | 351 | console.info(error); |
352 | } | 352 | } |
353 | ); | 353 | ); |
354 | }; | 354 | }; |
355 | 355 | ||
356 | $scope.seleccionarProductos = function() { | 356 | $scope.seleccionarProductos = function() { |
357 | if ($scope.idLista === undefined) { | 357 | if ($scope.idLista === undefined) { |
358 | focaModalService.alert( | 358 | focaModalService.alert( |
359 | 'Primero seleccione una lista de precio y condicion'); | 359 | 'Primero seleccione una lista de precio y condicion'); |
360 | return; | 360 | return; |
361 | } | 361 | } |
362 | var modalInstance = $uibModal.open( | 362 | var modalInstance = $uibModal.open( |
363 | { | 363 | { |
364 | ariaLabelledBy: 'Busqueda de Productos', | 364 | ariaLabelledBy: 'Busqueda de Productos', |
365 | templateUrl: 'modal-busqueda-productos.html', | 365 | templateUrl: 'modal-busqueda-productos.html', |
366 | controller: 'modalBusquedaProductosCtrl', | 366 | controller: 'modalBusquedaProductosCtrl', |
367 | resolve: { | 367 | resolve: { |
368 | parametroProducto: { | 368 | parametroProducto: { |
369 | idLista: $scope.idLista, | 369 | idLista: $scope.idLista, |
370 | cotizacion: $scope.remito.cotizacion.VENDEDOR, | 370 | cotizacion: $scope.remito.cotizacion.VENDEDOR, |
371 | simbolo: $scope.remito.cotizacion.moneda.SIMBOLO | 371 | simbolo: $scope.remito.cotizacion.moneda.SIMBOLO |
372 | } | 372 | } |
373 | }, | 373 | }, |
374 | size: 'lg' | 374 | size: 'lg' |
375 | } | 375 | } |
376 | ); | 376 | ); |
377 | modalInstance.result.then( | 377 | modalInstance.result.then( |
378 | function(producto) { | 378 | function(producto) { |
379 | var newArt = | 379 | var newArt = |
380 | { | 380 | { |
381 | id: 0, | 381 | id: 0, |
382 | idRemito: 0, | 382 | idRemito: 0, |
383 | codigo: producto.codigo, | 383 | codigo: producto.codigo, |
384 | sector: producto.sector, | 384 | sector: producto.sector, |
385 | sectorCodigo: producto.sector + '-' + producto.codigo, | 385 | sectorCodigo: producto.sector + '-' + producto.codigo, |
386 | descripcion: producto.descripcion, | 386 | descripcion: producto.descripcion, |
387 | item: $scope.remito.articulosRemito.length + 1, | 387 | item: $scope.remito.articulosRemito.length + 1, |
388 | nombre: producto.descripcion, | 388 | nombre: producto.descripcion, |
389 | precio: parseFloat(producto.precio.toFixed(4)), | 389 | precio: parseFloat(producto.precio.toFixed(4)), |
390 | costoUnitario: producto.costo, | 390 | costoUnitario: producto.costo, |
391 | editCantidad: false, | 391 | editCantidad: false, |
392 | editPrecio: false, | 392 | editPrecio: false, |
393 | rubro: producto.CodRub, | 393 | rubro: producto.CodRub, |
394 | exentoUnitario: producto.precio, | 394 | exentoUnitario: producto.precio, |
395 | ivaUnitario: producto.IMPIVA, | 395 | ivaUnitario: producto.IMPIVA, |
396 | impuestoInternoUnitario: producto.ImpInt, | 396 | impuestoInternoUnitario: producto.ImpInt, |
397 | impuestoInterno1Unitario: producto.ImpInt2, | 397 | impuestoInterno1Unitario: producto.ImpInt2, |
398 | impuestoInterno2Unitario: producto.ImpInt3, | 398 | impuestoInterno2Unitario: producto.ImpInt3, |
399 | precioLista: producto.precio, | 399 | precioLista: producto.precio, |
400 | combustible: 1, | 400 | combustible: 1, |
401 | facturado: 0 | 401 | facturado: 0 |
402 | }; | 402 | }; |
403 | $scope.articuloACargar = newArt; | 403 | $scope.articuloACargar = newArt; |
404 | $scope.cargando = false; | 404 | $scope.cargando = false; |
405 | }, function() { | 405 | }, function() { |
406 | // funcion ejecutada cuando se cancela el modal | 406 | // funcion ejecutada cuando se cancela el modal |
407 | } | 407 | } |
408 | ); | 408 | ); |
409 | }; | 409 | }; |
410 | 410 | ||
411 | $scope.seleccionarPuntosDeDescarga = function() { | 411 | $scope.seleccionarPuntosDeDescarga = function() { |
412 | if (!$scope.remito.cliente.COD || !$scope.remito.domicilio.id) { | 412 | if (!$scope.remito.cliente.COD || !$scope.remito.domicilio.id) { |
413 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); | 413 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); |
414 | return; | 414 | return; |
415 | } else { | 415 | } else { |
416 | var modalInstance = $uibModal.open( | 416 | var modalInstance = $uibModal.open( |
417 | { | 417 | { |
418 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', | 418 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', |
419 | templateUrl: 'modal-punto-descarga.html', | 419 | templateUrl: 'modal-punto-descarga.html', |
420 | controller: 'focaModalPuntoDescargaController', | 420 | controller: 'focaModalPuntoDescargaController', |
421 | size: 'lg', | 421 | size: 'lg', |
422 | resolve: { | 422 | resolve: { |
423 | filters: { | 423 | filters: { |
424 | idDomicilio: $scope.remito.domicilio.id, | 424 | idDomicilio: $scope.remito.domicilio.id, |
425 | idCliente: $scope.remito.cliente.COD, | 425 | idCliente: $scope.remito.cliente.COD, |
426 | articulos: $scope.remito.articulosRemito, | 426 | articulos: $scope.remito.articulosRemito, |
427 | puntosDescarga: $scope.remito.domicilio.puntosDescarga, | 427 | puntosDescarga: $scope.remito.domicilio.puntosDescarga, |
428 | domicilio: $scope.remito.domicilio | 428 | domicilio: $scope.remito.domicilio |
429 | } | 429 | } |
430 | } | 430 | } |
431 | } | 431 | } |
432 | ); | 432 | ); |
433 | modalInstance.result.then( | 433 | modalInstance.result.then( |
434 | function(puntosDescarga) { | 434 | function(puntosDescarga) { |
435 | $scope.remito.puntosDescarga = puntosDescarga; | 435 | $scope.remito.puntosDescarga = puntosDescarga; |
436 | 436 | ||
437 | //AGREGO PUNTOS DE DESCARGA A CABECERA | 437 | //AGREGO PUNTOS DE DESCARGA A CABECERA |
438 | var puntosStamp = ''; | 438 | var puntosStamp = ''; |
439 | puntosDescarga.forEach(function(punto, idx, arr) { | 439 | puntosDescarga.forEach(function(punto, idx, arr) { |
440 | puntosStamp += punto.descripcion; | 440 | puntosStamp += punto.descripcion; |
441 | if ((idx + 1) !== arr.length) puntosStamp += ', '; | 441 | if ((idx + 1) !== arr.length) puntosStamp += ', '; |
442 | }); | 442 | }); |
443 | 443 | ||
444 | $scope.$broadcast('addCabecera', { | 444 | $scope.$broadcast('addCabecera', { |
445 | label: 'Puntos de descarga:', | 445 | label: 'Puntos de descarga:', |
446 | valor: puntosStamp | 446 | valor: puntosStamp |
447 | }); | 447 | }); |
448 | }, function() { | 448 | }, function() { |
449 | $scope.abrirModalDomicilios($scope.cliente); | 449 | $scope.abrirModalDomicilios($scope.cliente); |
450 | } | 450 | } |
451 | ); | 451 | ); |
452 | } | 452 | } |
453 | }; | 453 | }; |
454 | 454 | ||
455 | $scope.seleccionarVendedor = function(callback, ocultarVendedor) { | 455 | $scope.seleccionarVendedor = function(callback, ocultarVendedor) { |
456 | if (ocultarVendedor) { | 456 | if (ocultarVendedor) { |
457 | callback(); | 457 | callback(); |
458 | return; | 458 | return; |
459 | } | 459 | } |
460 | 460 | ||
461 | if (varlidarRemitoFacturado()) { | 461 | if (varlidarRemitoFacturado()) { |
462 | var parametrosModal = { | 462 | var parametrosModal = { |
463 | titulo: 'Búsqueda vendedores', | 463 | titulo: 'Búsqueda vendedores', |
464 | query: '/vendedor', | 464 | query: '/vendedor', |
465 | columnas: [ | 465 | columnas: [ |
466 | { | 466 | { |
467 | propiedad: 'NUM', | 467 | propiedad: 'NUM', |
468 | nombre: 'Código', | 468 | nombre: 'Código', |
469 | filtro: { | 469 | filtro: { |
470 | nombre: 'rellenarDigitos', | 470 | nombre: 'rellenarDigitos', |
471 | parametro: 3 | 471 | parametro: 3 |
472 | } | 472 | } |
473 | }, | 473 | }, |
474 | { | 474 | { |
475 | propiedad: 'NOM', | 475 | propiedad: 'NOM', |
476 | nombre: 'Nombre' | 476 | nombre: 'Nombre' |
477 | } | 477 | } |
478 | ], | 478 | ], |
479 | size: 'md' | 479 | size: 'md' |
480 | }; | 480 | }; |
481 | focaModalService.modal(parametrosModal).then( | 481 | focaModalService.modal(parametrosModal).then( |
482 | function(vendedor) { | 482 | function(vendedor) { |
483 | $scope.$broadcast('addCabecera',{ | 483 | $scope.$broadcast('addCabecera',{ |
484 | label: 'Vendedor:', | 484 | label: 'Vendedor:', |
485 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + | 485 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + |
486 | vendedor.NOM | 486 | vendedor.NOM |
487 | }); | 487 | }); |
488 | $scope.remito.idVendedor = vendedor.id; | 488 | $scope.remito.idVendedor = vendedor.id; |
489 | $scope.remito.vendedor = vendedor; | 489 | $scope.remito.vendedor = vendedor; |
490 | deleteCliente(); | 490 | deleteCliente(); |
491 | callback(); | 491 | callback(); |
492 | }, function() { | 492 | }, function() { |
493 | 493 | ||
494 | } | 494 | } |
495 | ); | 495 | ); |
496 | } | 496 | } |
497 | }; | 497 | }; |
498 | 498 | ||
499 | $scope.seleccionarCliente = function(ocultarVendedor) { | 499 | $scope.seleccionarCliente = function(ocultarVendedor) { |
500 | 500 | ||
501 | $scope.seleccionarVendedor(function() { | 501 | $scope.seleccionarVendedor(function() { |
502 | if (varlidarRemitoFacturado()) { | 502 | if (varlidarRemitoFacturado()) { |
503 | var modalInstance = $uibModal.open( | 503 | var modalInstance = $uibModal.open( |
504 | { | 504 | { |
505 | ariaLabelledBy: 'Busqueda de Cliente', | 505 | ariaLabelledBy: 'Busqueda de Cliente', |
506 | templateUrl: 'foca-busqueda-cliente-modal.html', | 506 | templateUrl: 'foca-busqueda-cliente-modal.html', |
507 | controller: 'focaBusquedaClienteModalController', | 507 | controller: 'focaBusquedaClienteModalController', |
508 | resolve: { | 508 | resolve: { |
509 | vendedor: function() { return $scope.remito.vendedor; }, | 509 | vendedor: function() { return $scope.remito.vendedor; }, |
510 | cobrador: function() { return null; } | 510 | cobrador: function() { return null; } |
511 | }, | 511 | }, |
512 | size: 'lg' | 512 | size: 'lg' |
513 | } | 513 | } |
514 | ); | 514 | ); |
515 | modalInstance.result.then( | 515 | modalInstance.result.then( |
516 | function(cliente) { | 516 | function(cliente) { |
517 | $scope.abrirModalDomicilios(cliente); | 517 | $scope.abrirModalDomicilios(cliente); |
518 | $scope.cliente = cliente; | 518 | $scope.cliente = cliente; |
519 | }, function() { | 519 | }, function() { |
520 | $scope.seleccionarCliente(); | 520 | $scope.seleccionarCliente(); |
521 | } | 521 | } |
522 | ); | 522 | ); |
523 | } | 523 | } |
524 | }, ocultarVendedor); | 524 | }, ocultarVendedor); |
525 | }; | 525 | }; |
526 | 526 | ||
527 | $scope.seleccionarProveedor = function(callback) { | 527 | $scope.seleccionarProveedor = function() { |
528 | if (varlidarRemitoFacturado()) { | 528 | if (varlidarRemitoFacturado()) { |
529 | var parametrosModal = { | 529 | var parametrosModal = { |
530 | titulo: 'Búsqueda de Proveedor', | 530 | titulo: 'Búsqueda de Proveedor', |
531 | query: '/proveedor', | 531 | query: '/proveedor', |
532 | columnas: [ | 532 | columnas: [ |
533 | { | 533 | { |
534 | nombre: 'Código', | 534 | nombre: 'Código', |
535 | propiedad: 'COD', | 535 | propiedad: 'COD', |
536 | filtro: { | 536 | filtro: { |
537 | nombre: 'rellenarDigitos', | 537 | nombre: 'rellenarDigitos', |
538 | parametro: 5 | 538 | parametro: 5 |
539 | } | 539 | } |
540 | }, | 540 | }, |
541 | { | 541 | { |
542 | nombre: 'Nombre', | 542 | nombre: 'Nombre', |
543 | propiedad: 'NOM' | 543 | propiedad: 'NOM' |
544 | }, | 544 | }, |
545 | { | 545 | { |
546 | nombre: 'CUIT', | 546 | nombre: 'CUIT', |
547 | propiedad: 'CUIT' | 547 | propiedad: 'CUIT' |
548 | } | 548 | } |
549 | ], | 549 | ], |
550 | tipo: 'POST', | 550 | tipo: 'POST', |
551 | json: {razonCuitCod: ''} | 551 | json: {razonCuitCod: ''} |
552 | }; | 552 | }; |
553 | focaModalService.modal(parametrosModal).then( | 553 | focaModalService.modal(parametrosModal).then( |
554 | function(proveedor) { | 554 | function(proveedor) { |
555 | $scope.remito.proveedor = proveedor; | 555 | $scope.seleccionarFlete(proveedor); |
556 | $scope.remito.idProveedor = proveedor.COD; | ||
557 | $scope.$broadcast('addCabecera',{ | ||
558 | label: 'Proveedor:', | ||
559 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + | ||
560 | proveedor.NOM | ||
561 | }); | ||
562 | callback(); | ||
563 | }, function() { } | 556 | }, function() { } |
564 | ); | 557 | ); |
565 | } | 558 | } |
566 | }; | 559 | }; |
567 | 560 | ||
568 | $scope.abrirModalDomicilios = function(cliente) { | 561 | $scope.abrirModalDomicilios = function(cliente) { |
569 | var modalInstanceDomicilio = $uibModal.open( | 562 | var modalInstanceDomicilio = $uibModal.open( |
570 | { | 563 | { |
571 | ariaLabelledBy: 'Busqueda de Domicilios', | 564 | ariaLabelledBy: 'Busqueda de Domicilios', |
572 | templateUrl: 'modal-domicilio.html', | 565 | templateUrl: 'modal-domicilio.html', |
573 | controller: 'focaModalDomicilioController', | 566 | controller: 'focaModalDomicilioController', |
574 | size: 'lg', | 567 | size: 'lg', |
575 | resolve: { | 568 | resolve: { |
576 | idCliente: function() { return cliente.cod; }, | 569 | idCliente: function() { return cliente.cod; }, |
577 | esNuevo: function() { return cliente.esNuevo; } | 570 | esNuevo: function() { return cliente.esNuevo; } |
578 | } | 571 | } |
579 | } | 572 | } |
580 | ); | 573 | ); |
581 | modalInstanceDomicilio.result.then( | 574 | modalInstanceDomicilio.result.then( |
582 | function(domicilio) { | 575 | function(domicilio) { |
583 | $scope.remito.domicilio = domicilio; | 576 | $scope.remito.domicilio = domicilio; |
584 | $scope.remito.cliente = { | 577 | $scope.remito.cliente = { |
585 | COD: cliente.cod, | 578 | COD: cliente.cod, |
586 | CUIT: cliente.cuit, | 579 | CUIT: cliente.cuit, |
587 | NOM: cliente.nom, | 580 | NOM: cliente.nom, |
588 | MAIL: cliente.mail, | 581 | MAIL: cliente.mail, |
589 | MOD: cliente.mod | 582 | MOD: cliente.mod |
590 | }; | 583 | }; |
591 | 584 | ||
592 | var domicilioStamp = | 585 | var domicilioStamp = |
593 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + | 586 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + |
594 | domicilio.Localidad + ', ' + domicilio.Provincia; | 587 | domicilio.Localidad + ', ' + domicilio.Provincia; |
595 | $scope.remito.domicilioStamp = domicilioStamp; | 588 | $scope.remito.domicilioStamp = domicilioStamp; |
596 | $scope.$broadcast('addCabecera',{ | 589 | $scope.$broadcast('addCabecera',{ |
597 | label: 'Cliente:', | 590 | label: 'Cliente:', |
598 | valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + cliente.nom | 591 | valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + cliente.nom |
599 | }); | 592 | }); |
600 | $scope.$broadcast('addCabecera',{ | 593 | $scope.$broadcast('addCabecera',{ |
601 | label: 'Domicilio:', | 594 | label: 'Domicilio:', |
602 | valor: domicilioStamp | 595 | valor: domicilioStamp |
603 | }); | 596 | }); |
604 | 597 | ||
605 | if (domicilio.verPuntos) { | 598 | if (domicilio.verPuntos) { |
606 | delete $scope.remito.domicilio.verPuntos; | 599 | delete $scope.remito.domicilio.verPuntos; |
607 | $scope.seleccionarPuntosDeDescarga(); | 600 | $scope.seleccionarPuntosDeDescarga(); |
608 | } else { | 601 | } else { |
609 | crearRemitoService | 602 | crearRemitoService |
610 | .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) | 603 | .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) |
611 | .then(function(res) { | 604 | .then(function(res) { |
612 | if (res.data.length) $scope.seleccionarPuntosDeDescarga(); | 605 | if (res.data.length) $scope.seleccionarPuntosDeDescarga(); |
613 | }); | 606 | }); |
614 | } | 607 | } |
615 | }, function() { | 608 | }, function() { |
616 | $scope.seleccionarCliente(true); | 609 | $scope.seleccionarCliente(true); |
617 | return; | 610 | return; |
618 | } | 611 | } |
619 | ); | 612 | ); |
620 | }; | 613 | }; |
621 | 614 | ||
622 | $scope.getTotal = function() { | 615 | $scope.getTotal = function() { |
623 | var total = 0; | 616 | var total = 0; |
624 | var arrayTempArticulos = $scope.articulosFiltro(); | 617 | var arrayTempArticulos = $scope.articulosFiltro(); |
625 | for(var i = 0; i < arrayTempArticulos.length; i++) { | 618 | for(var i = 0; i < arrayTempArticulos.length; i++) { |
626 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | 619 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; |
627 | } | 620 | } |
628 | return parseFloat(total.toFixed(2)); | 621 | return parseFloat(total.toFixed(2)); |
629 | }; | 622 | }; |
630 | 623 | ||
631 | $scope.getSubTotal = function() { | 624 | $scope.getSubTotal = function() { |
632 | if ($scope.articuloACargar) { | 625 | if ($scope.articuloACargar) { |
633 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; | 626 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
634 | } | 627 | } |
635 | }; | 628 | }; |
636 | 629 | ||
637 | $scope.seleccionarPreciosYCondiciones = function() { | 630 | $scope.seleccionarPreciosYCondiciones = function() { |
638 | if (!$scope.remito.cliente.COD) { | 631 | if (!$scope.remito.cliente.COD) { |
639 | focaModalService.alert('Primero seleccione un cliente'); | 632 | focaModalService.alert('Primero seleccione un cliente'); |
640 | return; | 633 | return; |
641 | } | 634 | } |
642 | if (varlidarRemitoFacturado()) { | 635 | if (varlidarRemitoFacturado()) { |
643 | var modalInstance = $uibModal.open( | 636 | var modalInstance = $uibModal.open( |
644 | { | 637 | { |
645 | ariaLabelledBy: 'Busqueda de Precio Condición', | 638 | ariaLabelledBy: 'Busqueda de Precio Condición', |
646 | templateUrl: 'modal-precio-condicion.html', | 639 | templateUrl: 'modal-precio-condicion.html', |
647 | controller: 'focaModalPrecioCondicionController', | 640 | controller: 'focaModalPrecioCondicionController', |
648 | size: 'lg', | 641 | size: 'lg', |
649 | resolve: { | 642 | resolve: { |
650 | idListaPrecio: function() { | 643 | idListaPrecio: function() { |
651 | return $scope.remito.cliente.MOD || null; | 644 | return $scope.remito.cliente.MOD || null; |
652 | } | 645 | } |
653 | } | 646 | } |
654 | } | 647 | } |
655 | ); | 648 | ); |
656 | modalInstance.result.then( | 649 | modalInstance.result.then( |
657 | function(precioCondicion) { | 650 | function(precioCondicion) { |
658 | var cabecera = ''; | 651 | var cabecera = ''; |
659 | var plazosConcat = ''; | 652 | var plazosConcat = ''; |
660 | if (!Array.isArray(precioCondicion)) { | 653 | if (!Array.isArray(precioCondicion)) { |
661 | $scope.remito.idPrecioCondicion = precioCondicion.id; | 654 | $scope.remito.idPrecioCondicion = precioCondicion.id; |
662 | $scope.remito.remitoPlazo = precioCondicion.plazoPago; | 655 | $scope.remito.remitoPlazo = precioCondicion.plazoPago; |
663 | $scope.idLista = precioCondicion.idListaPrecio; | 656 | $scope.idLista = precioCondicion.idListaPrecio; |
664 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { | 657 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { |
665 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; | 658 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; |
666 | } | 659 | } |
667 | cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + | 660 | cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + |
668 | ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); | 661 | ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); |
669 | } else { //Cuando se ingresan los plazos manualmente | 662 | } else { //Cuando se ingresan los plazos manualmente |
670 | $scope.remito.idPrecioCondicion = 0; | 663 | $scope.remito.idPrecioCondicion = 0; |
671 | //-1, el modal productos busca todos los productos | 664 | //-1, el modal productos busca todos los productos |
672 | $scope.idLista = -1; | 665 | $scope.idLista = -1; |
673 | $scope.remito.remitoPlazo = precioCondicion; | 666 | $scope.remito.remitoPlazo = precioCondicion; |
674 | for(var j = 0; j < precioCondicion.length; j++) { | 667 | for(var j = 0; j < precioCondicion.length; j++) { |
675 | plazosConcat += precioCondicion[j].dias + ' '; | 668 | plazosConcat += precioCondicion[j].dias + ' '; |
676 | } | 669 | } |
677 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); | 670 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); |
678 | } | 671 | } |
679 | $scope.remito.articulosRemito = []; | 672 | $scope.remito.articulosRemito = []; |
680 | $scope.$broadcast('addCabecera',{ | 673 | $scope.$broadcast('addCabecera',{ |
681 | label: 'Precios y condiciones:', | 674 | label: 'Precios y condiciones:', |
682 | valor: cabecera | 675 | valor: cabecera |
683 | }); | 676 | }); |
684 | $scope.remito.precioCondicion = precioCondicion; | 677 | $scope.remito.precioCondicion = precioCondicion; |
685 | }, function() { | 678 | }, function() { |
686 | 679 | ||
687 | } | 680 | } |
688 | ); | 681 | ); |
689 | } | 682 | } |
690 | }; | 683 | }; |
691 | 684 | ||
692 | $scope.seleccionarTransportista = function() { | 685 | $scope.seleccionarFlete = function(proveedor) { |
693 | $scope.seleccionarProveedor(function() { | 686 | if (varlidarRemitoFacturado()) { |
694 | if (varlidarRemitoFacturado()) { | 687 | var modalInstance = $uibModal.open( |
695 | var modalInstance = $uibModal.open( | 688 | { |
696 | { | 689 | ariaLabelledBy: 'Busqueda de Flete', |
697 | ariaLabelledBy: 'Busqueda de Flete', | 690 | templateUrl: 'modal-flete.html', |
698 | templateUrl: 'modal-flete.html', | 691 | controller: 'focaModalFleteController', |
699 | controller: 'focaModalFleteController', | 692 | size: 'lg', |
700 | size: 'lg', | 693 | resolve: { |
701 | resolve: { | 694 | parametrosFlete: |
702 | parametrosFlete: | 695 | function() { |
703 | function() { | 696 | return { |
704 | return { | 697 | flete: $scope.remito.flete ? '1' : |
705 | flete: $scope.remito.flete ? '1' : | 698 | ($scope.remito.fob ? 'FOB' : |
706 | ($scope.remito.fob ? 'FOB' : | 699 | ($scope.remito.flete === undefined ? |
707 | ($scope.remito.flete === undefined ? | 700 | null : '0')), |
708 | null : '0')), | 701 | bomba: $scope.remito.bomba ? '1' : |
709 | bomba: $scope.remito.bomba ? '1' : | 702 | ($scope.remito.bomba === undefined ? |
710 | ($scope.remito.bomba === undefined ? | 703 | null : '0'), |
711 | null : '0'), | 704 | kilometros: $scope.remito.kilometros |
712 | kilometros: $scope.remito.kilometros | 705 | }; |
713 | }; | 706 | } |
714 | } | ||
715 | } | ||
716 | } | 707 | } |
717 | ); | 708 | } |
718 | modalInstance.result.then( | 709 | ); |
719 | function(datos) { | 710 | modalInstance.result.then( |
720 | $scope.remito.flete = datos.flete; | 711 | function(datos) { |
721 | $scope.remito.fob = datos.FOB; | 712 | |
722 | $scope.remito.bomba = datos.bomba; | 713 | $scope.remito.proveedor = proveedor; |
723 | $scope.remito.kilometros = datos.kilometros; | 714 | $scope.remito.idProveedor = proveedor.COD; |
724 | 715 | $scope.$broadcast('addCabecera',{ | |
716 | label: 'Proveedor:', | ||
717 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + | ||
718 | proveedor.NOM | ||
719 | }); | ||
720 | |||
721 | $scope.remito.flete = datos.flete; | ||
722 | $scope.remito.fob = datos.FOB; | ||
723 | $scope.remito.bomba = datos.bomba; | ||
724 | $scope.remito.kilometros = datos.kilometros; | ||
725 | |||
726 | $scope.$broadcast('addCabecera',{ | ||
727 | label: 'Flete:', | ||
728 | valor: datos.flete ? 'Si' : ($scope.remito.fob ? 'FOB' : 'No') | ||
729 | }); | ||
730 | if (datos.flete) { | ||
725 | $scope.$broadcast('addCabecera',{ | 731 | $scope.$broadcast('addCabecera',{ |
726 | label: 'Flete:', | 732 | label: 'Bomba:', |
727 | valor: datos.flete ? 'Si' : ($scope.remito.fob ? 'FOB' : 'No') | 733 | valor: datos.bomba ? 'Si' : 'No' |
728 | }); | 734 | }); |
729 | if (datos.flete) { | 735 | $scope.$broadcast('addCabecera',{ |
730 | $scope.$broadcast('addCabecera',{ | 736 | label: 'Kilometros:', |
731 | label: 'Bomba:', | 737 | valor: datos.kilometros |
732 | valor: datos.bomba ? 'Si' : 'No' | 738 | }); |
733 | }); | 739 | } else { |
734 | $scope.$broadcast('addCabecera',{ | 740 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
735 | label: 'Kilometros:', | 741 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
736 | valor: datos.kilometros | 742 | $scope.remito.bomba = false; |
737 | }); | 743 | $scope.remito.kilometros = null; |
738 | } else { | ||
739 | $scope.$broadcast('removeCabecera', 'Bomba:'); | ||
740 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | ||
741 | $scope.remito.bomba = false; | ||
742 | $scope.remito.kilometros = null; | ||
743 | } | ||
744 | }, function() { | ||
745 | $scope.seleccionarTransportista(); | ||
746 | } | 744 | } |
747 | ); | 745 | }, function() { |
748 | } | 746 | $scope.seleccionarTransportista(); |
749 | }); | 747 | } |
748 | ); | ||
749 | } | ||
750 | }; | 750 | }; |
751 | 751 | ||
752 | $scope.seleccionarMoneda = function() { | 752 | $scope.seleccionarMoneda = function() { |
753 | if (varlidarRemitoFacturado()) { | 753 | if (varlidarRemitoFacturado()) { |
754 | var parametrosModal = { | 754 | var parametrosModal = { |
755 | titulo: 'Búsqueda de monedas', | 755 | titulo: 'Búsqueda de monedas', |
756 | query: '/moneda', | 756 | query: '/moneda', |
757 | columnas: [ | 757 | columnas: [ |
758 | { | 758 | { |
759 | propiedad: 'DETALLE', | 759 | propiedad: 'DETALLE', |
760 | nombre: 'Nombre' | 760 | nombre: 'Nombre' |
761 | }, | 761 | }, |
762 | { | 762 | { |
763 | propiedad: 'SIMBOLO', | 763 | propiedad: 'SIMBOLO', |
764 | nombre: 'Símbolo' | 764 | nombre: 'Símbolo' |
765 | } | 765 | } |
766 | ], | 766 | ], |
767 | size: 'md' | 767 | size: 'md' |
768 | }; | 768 | }; |
769 | focaModalService.modal(parametrosModal).then( | 769 | focaModalService.modal(parametrosModal).then( |
770 | function(moneda) { | 770 | function(moneda) { |
771 | $scope.abrirModalCotizacion(moneda); | 771 | $scope.abrirModalCotizacion(moneda); |
772 | }, function() { | 772 | }, function() { |
773 | 773 | ||
774 | } | 774 | } |
775 | ); | 775 | ); |
776 | } | 776 | } |
777 | }; | 777 | }; |
778 | 778 | ||
779 | $scope.seleccionarObservaciones = function() { | 779 | $scope.seleccionarObservaciones = function() { |
780 | focaModalService | 780 | focaModalService |
781 | .prompt({ | 781 | .prompt({ |
782 | titulo: 'Observaciones', | 782 | titulo: 'Observaciones', |
783 | value: $scope.remito.observaciones, | 783 | value: $scope.remito.observaciones, |
784 | textarea: true, | 784 | textarea: true, |
785 | readonly: true | 785 | readonly: true |
786 | }) | 786 | }) |
787 | .then(function(observaciones) { | 787 | .then(function(observaciones) { |
788 | $scope.remito.observaciones = observaciones; | 788 | $scope.remito.observaciones = observaciones; |
789 | }); | 789 | }); |
790 | }; | 790 | }; |
791 | 791 | ||
792 | $scope.abrirModalCotizacion = function(moneda) { | 792 | $scope.abrirModalCotizacion = function(moneda) { |
793 | var modalInstance = $uibModal.open( | 793 | var modalInstance = $uibModal.open( |
794 | { | 794 | { |
795 | ariaLabelledBy: 'Busqueda de Cotización', | 795 | ariaLabelledBy: 'Busqueda de Cotización', |
796 | templateUrl: 'modal-cotizacion.html', | 796 | templateUrl: 'modal-cotizacion.html', |
797 | controller: 'focaModalCotizacionController', | 797 | controller: 'focaModalCotizacionController', |
798 | size: 'lg', | 798 | size: 'lg', |
799 | resolve: {idMoneda: function() {return moneda.ID;}} | 799 | resolve: {idMoneda: function() {return moneda.ID;}} |
800 | } | 800 | } |
801 | ); | 801 | ); |
802 | modalInstance.result.then( | 802 | modalInstance.result.then( |
803 | function(cotizacion) { | 803 | function(cotizacion) { |
804 | var articulosTablaTemp = $scope.remito.articulosRemito; | 804 | var articulosTablaTemp = $scope.remito.articulosRemito; |
805 | for(var i = 0; i < articulosTablaTemp.length; i++) { | 805 | for(var i = 0; i < articulosTablaTemp.length; i++) { |
806 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * | 806 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * |
807 | $scope.remito.cotizacion.VENDEDOR; | 807 | $scope.remito.cotizacion.VENDEDOR; |
808 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / | 808 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / |
809 | cotizacion.VENDEDOR; | 809 | cotizacion.VENDEDOR; |
810 | } | 810 | } |
811 | $scope.remito.articulosRemito = articulosTablaTemp; | 811 | $scope.remito.articulosRemito = articulosTablaTemp; |
812 | $scope.remito.cotizacion = cotizacion; | 812 | $scope.remito.cotizacion = cotizacion; |
813 | $scope.remito.cotizacion.moneda = moneda; | 813 | $scope.remito.cotizacion.moneda = moneda; |
814 | if (moneda.DETALLE === 'PESOS ARGENTINOS') { | 814 | if (moneda.DETALLE === 'PESOS ARGENTINOS') { |
815 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 815 | $scope.$broadcast('removeCabecera', 'Moneda:'); |
816 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 816 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); |
817 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 817 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); |
818 | } else { | 818 | } else { |
819 | $scope.$broadcast('addCabecera',{ | 819 | $scope.$broadcast('addCabecera',{ |
820 | label: 'Moneda:', | 820 | label: 'Moneda:', |
821 | valor: moneda.DETALLE | 821 | valor: moneda.DETALLE |
822 | }); | 822 | }); |
823 | $scope.$broadcast('addCabecera',{ | 823 | $scope.$broadcast('addCabecera',{ |
824 | label: 'Fecha cotizacion:', | 824 | label: 'Fecha cotizacion:', |
825 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 825 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') |
826 | }); | 826 | }); |
827 | $scope.$broadcast('addCabecera',{ | 827 | $scope.$broadcast('addCabecera',{ |
828 | label: 'Cotizacion:', | 828 | label: 'Cotizacion:', |
829 | valor: $filter('number')(cotizacion.VENDEDOR, '2') | 829 | valor: $filter('number')(cotizacion.VENDEDOR, '2') |
830 | }); | 830 | }); |
831 | } | 831 | } |
832 | }, function() { | 832 | }, function() { |
833 | 833 | ||
834 | } | 834 | } |
835 | ); | 835 | ); |
836 | }; | 836 | }; |
837 | 837 | ||
838 | $scope.agregarATabla = function(key) { | 838 | $scope.agregarATabla = function(key) { |
839 | if (key === 13) { | 839 | if (key === 13) { |
840 | if ($scope.articuloACargar.cantidad === undefined || | 840 | if ($scope.articuloACargar.cantidad === undefined || |
841 | $scope.articuloACargar.cantidad === 0 || | 841 | $scope.articuloACargar.cantidad === 0 || |
842 | $scope.articuloACargar.cantidad === null ) { | 842 | $scope.articuloACargar.cantidad === null ) { |
843 | focaModalService.alert('El valor debe ser al menos 1'); | 843 | focaModalService.alert('El valor debe ser al menos 1'); |
844 | return; | 844 | return; |
845 | } | 845 | } |
846 | delete $scope.articuloACargar.sectorCodigo; | 846 | delete $scope.articuloACargar.sectorCodigo; |
847 | $scope.remito.articulosRemito.push($scope.articuloACargar); | 847 | $scope.remito.articulosRemito.push($scope.articuloACargar); |
848 | $scope.cargando = true; | 848 | $scope.cargando = true; |
849 | } | 849 | } |
850 | }; | 850 | }; |
851 | 851 | ||
852 | $scope.quitarArticulo = function(articulo) { | 852 | $scope.quitarArticulo = function(articulo) { |
853 | articulo.idRemito = -1; | 853 | articulo.idRemito = -1; |
854 | }; | 854 | }; |
855 | 855 | ||
856 | $scope.articulosFiltro = function() { | 856 | $scope.articulosFiltro = function() { |
857 | 857 | ||
858 | var result = $scope.remito.articulosRemito.filter(function(articulo) { | 858 | var result = $scope.remito.articulosRemito.filter(function(articulo) { |
859 | return articulo.idRemito >= 0; | 859 | return articulo.idRemito >= 0; |
860 | }); | 860 | }); |
861 | return result; | 861 | return result; |
862 | }; | 862 | }; |
863 | 863 | ||
864 | $scope.editarArticulo = function(key, articulo) { | 864 | $scope.editarArticulo = function(key, articulo) { |
865 | if (key === 13) { | 865 | if (key === 13) { |
866 | if (!articulo.cantidad || !articulo.precio) { | 866 | if (!articulo.cantidad || !articulo.precio) { |
867 | focaModalService.alert('Los valores deben ser al menos 1'); | 867 | focaModalService.alert('Los valores deben ser al menos 1'); |
868 | return; | 868 | return; |
869 | } else if (articulo.cantidad < 0 || articulo.precio < 0) { | 869 | } else if (articulo.cantidad < 0 || articulo.precio < 0) { |
870 | focaModalService.alert('Los valores no pueden ser negativos'); | 870 | focaModalService.alert('Los valores no pueden ser negativos'); |
871 | return; | 871 | return; |
872 | } | 872 | } |
873 | articulo.editCantidad = articulo.editPrecio = false; | 873 | articulo.editCantidad = articulo.editPrecio = false; |
874 | } | 874 | } |
875 | }; | 875 | }; |
876 | 876 | ||
877 | $scope.cambioEdit = function(articulo, propiedad) { | 877 | $scope.cambioEdit = function(articulo, propiedad) { |
878 | if (propiedad === 'cantidad') { | 878 | if (propiedad === 'cantidad') { |
879 | articulo.editCantidad = true; | 879 | articulo.editCantidad = true; |
880 | } else if (propiedad === 'precio') { | 880 | } else if (propiedad === 'precio') { |
881 | articulo.editPrecio = true; | 881 | articulo.editPrecio = true; |
882 | } | 882 | } |
883 | }; | 883 | }; |
884 | 884 | ||
885 | $scope.resetFilter = function() { | 885 | $scope.resetFilter = function() { |
886 | $scope.articuloACargar = {}; | 886 | $scope.articuloACargar = {}; |
887 | $scope.cargando = true; | 887 | $scope.cargando = true; |
888 | }; | 888 | }; |
889 | //Recibe aviso si el teclado está en uso | 889 | //Recibe aviso si el teclado está en uso |
890 | $rootScope.$on('usarTeclado', function(event, data) { | 890 | $rootScope.$on('usarTeclado', function(event, data) { |
891 | if (data) { | 891 | if (data) { |
892 | $scope.mostrarTeclado = true; | 892 | $scope.mostrarTeclado = true; |
893 | return; | 893 | return; |
894 | } | 894 | } |
895 | $scope.mostrarTeclado = false; | 895 | $scope.mostrarTeclado = false; |
896 | }); | 896 | }); |
897 | 897 | ||
898 | $scope.selectFocus = function($event) { | 898 | $scope.selectFocus = function($event) { |
899 | // Si el teclado esta en uso no selecciona el valor | 899 | // Si el teclado esta en uso no selecciona el valor |
900 | if ($scope.mostrarTeclado) { | 900 | if ($scope.mostrarTeclado) { |
901 | return; | 901 | return; |
902 | } | 902 | } |
903 | $event.target.select(); | 903 | $event.target.select(); |
904 | }; | 904 | }; |
905 | 905 | ||
906 | function addArrayCabecera(array) { | 906 | function addArrayCabecera(array) { |
907 | for (var i = 0; i < array.length; i++) { | 907 | for (var i = 0; i < array.length; i++) { |
908 | $scope.$broadcast('addCabecera',{ | 908 | $scope.$broadcast('addCabecera',{ |
909 | label: array[i].label, | 909 | label: array[i].label, |
910 | valor: array[i].valor | 910 | valor: array[i].valor |
911 | }); | 911 | }); |
912 | } | 912 | } |
913 | } | 913 | } |
914 | 914 | ||
915 | function rellenar(relleno, longitud) { | 915 | function rellenar(relleno, longitud) { |
916 | relleno = '' + relleno; | 916 | relleno = '' + relleno; |
917 | while (relleno.length < longitud) { | 917 | while (relleno.length < longitud) { |
918 | relleno = '0' + relleno; | 918 | relleno = '0' + relleno; |
919 | } | 919 | } |
920 | return relleno; | 920 | return relleno; |
921 | } | 921 | } |
922 | 922 | ||
923 | function varlidarRemitoFacturado() { | 923 | function varlidarRemitoFacturado() { |
924 | if ($scope.remito.estado !== 5) { | 924 | if ($scope.remito.estado !== 5) { |
925 | return true; | 925 | return true; |
926 | } else { | 926 | } else { |
927 | focaModalService.alert('No se puede editar un remito facturado'); | 927 | focaModalService.alert('No se puede editar un remito facturado'); |
928 | return false(); | 928 | return false(); |
929 | } | 929 | } |
930 | } | 930 | } |
931 | 931 | ||
932 | function salir() { | 932 | function salir() { |
933 | var confirmacion = false; | 933 | var confirmacion = false; |
934 | 934 | ||
935 | if (!angular.equals($scope.remito, $scope.inicial)) { | 935 | if (!angular.equals($scope.remito, $scope.inicial)) { |
936 | confirmacion = true; | 936 | confirmacion = true; |
937 | } | 937 | } |
938 | 938 | ||
939 | if (confirmacion) { | 939 | if (confirmacion) { |
940 | focaModalService.confirm( | 940 | focaModalService.confirm( |
941 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 941 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
942 | ).then(function(data) { | 942 | ).then(function(data) { |
943 | if (data) { | 943 | if (data) { |
944 | $location.path('/'); | 944 | $location.path('/'); |
945 | } | 945 | } |
946 | }); | 946 | }); |
947 | } else { | 947 | } else { |
948 | $location.path('/'); | 948 | $location.path('/'); |
949 | } | 949 | } |
950 | } | 950 | } |
951 | 951 | ||
952 | function enableObservaciones(val) { | 952 | function enableObservaciones(val) { |
953 | var boton = $scope.botonera.filter(function(botonObs) { | 953 | var boton = $scope.botonera.filter(function(botonObs) { |
954 | return botonObs.label === 'Observaciones'; | 954 | return botonObs.label === 'Observaciones'; |
955 | }); | 955 | }); |
956 | boton[0].disable = !val; | 956 | boton[0].disable = !val; |
957 | } | 957 | } |
958 | 958 | ||
959 | function setearRemito(remito) { | 959 | function setearRemito(remito) { |
960 | //añado cabeceras | 960 | //añado cabeceras |
961 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 961 | $scope.$broadcast('removeCabecera', 'Moneda:'); |
962 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 962 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); |
963 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 963 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); |
964 | 964 | ||
965 | var cabeceras = []; | 965 | var cabeceras = []; |
966 | 966 | ||
967 | if (remito.cotizacion.moneda.CODIGO_AFIP !== 'PES') { | 967 | if (remito.cotizacion.moneda.CODIGO_AFIP !== 'PES') { |
968 | cabeceras.push({ | 968 | cabeceras.push({ |
969 | label: 'Moneda:', | 969 | label: 'Moneda:', |
970 | valor: remito.cotizacion.moneda.DETALLE | 970 | valor: remito.cotizacion.moneda.DETALLE |
971 | }); | 971 | }); |
972 | cabeceras.push({ | 972 | cabeceras.push({ |
973 | label: 'Fecha cotizacion:', | 973 | label: 'Fecha cotizacion:', |
974 | valor: $filter('date')(remito.cotizacion.FECHA, | 974 | valor: $filter('date')(remito.cotizacion.FECHA, |
975 | 'dd/MM/yyyy') | 975 | 'dd/MM/yyyy') |
976 | }); | 976 | }); |
977 | cabeceras.push({ | 977 | cabeceras.push({ |
978 | label: 'Cotizacion:', | 978 | label: 'Cotizacion:', |
979 | valor: $filter('number')(remito.cotizacion.VENDEDOR, | 979 | valor: $filter('number')(remito.cotizacion.VENDEDOR, |
980 | '2') | 980 | '2') |
981 | }); | 981 | }); |
982 | } | 982 | } |
983 | if (remito.cliente.COD) { | 983 | if (remito.cliente.COD) { |
984 | cabeceras.push({ | 984 | cabeceras.push({ |
985 | label: 'Cliente:', | 985 | label: 'Cliente:', |
986 | valor: $filter('rellenarDigitos')(remito.cliente.COD, 3) + ' - ' + | 986 | valor: $filter('rellenarDigitos')(remito.cliente.COD, 3) + ' - ' + |
987 | remito.cliente.NOM | 987 | remito.cliente.NOM |
988 | }); | 988 | }); |
989 | cabeceras.push({ | 989 | cabeceras.push({ |
990 | label: 'Domicilio:', | 990 | label: 'Domicilio:', |
991 | valor: remito.domicilioStamp | 991 | valor: remito.domicilioStamp |
992 | }); | 992 | }); |
993 | } | 993 | } |
994 | if (remito.vendedor.NUM) { | 994 | if (remito.vendedor.NUM) { |
995 | cabeceras.push({ | 995 | cabeceras.push({ |
996 | label: 'Vendedor:', | 996 | label: 'Vendedor:', |
997 | valor: $filter('rellenarDigitos')(remito.vendedor.NUM, 3) + | 997 | valor: $filter('rellenarDigitos')(remito.vendedor.NUM, 3) + |
998 | ' - ' + remito.vendedor.NOM | 998 | ' - ' + remito.vendedor.NOM |
999 | }); | 999 | }); |
1000 | } | 1000 | } |
1001 | if (remito.proveedor.COD) { | 1001 | if (remito.proveedor.COD) { |
1002 | cabeceras.push({ | 1002 | cabeceras.push({ |
1003 | label: 'Proveedor:', | 1003 | label: 'Proveedor:', |
1004 | valor: $filter('rellenarDigitos')(remito.proveedor.COD, 5) + | 1004 | valor: $filter('rellenarDigitos')(remito.proveedor.COD, 5) + |
1005 | ' - ' + remito.proveedor.NOM | 1005 | ' - ' + remito.proveedor.NOM |
1006 | }); | 1006 | }); |
1007 | } | 1007 | } |
1008 | if (remito.flete !== undefined && remito.fob !== undefined) { | 1008 | if (remito.flete !== undefined && remito.fob !== undefined) { |
1009 | cabeceras.push({ | 1009 | cabeceras.push({ |
1010 | label: 'Flete:', | 1010 | label: 'Flete:', |
1011 | valor: remito.fob ? 'FOB' : ( | 1011 | valor: remito.fob ? 'FOB' : ( |
1012 | remito.flete ? 'Si' : 'No') | 1012 | remito.flete ? 'Si' : 'No') |
1013 | }); | 1013 | }); |
1014 | } | 1014 | } |
1015 | if (remito.remitoPlazo) { | 1015 | if (remito.remitoPlazo) { |
1016 | cabeceras.push({ | 1016 | cabeceras.push({ |
1017 | label: 'Precio condicion:', | 1017 | label: 'Precio condicion:', |
1018 | valor: valorPrecioCondicion() + ' ' + | 1018 | valor: valorPrecioCondicion() + ' ' + |
1019 | remitoBusinessService.plazoToString(remito.remitoPlazo) | 1019 | remitoBusinessService.plazoToString(remito.remitoPlazo) |
1020 | }); | 1020 | }); |
1021 | } | 1021 | } |
1022 | function valorPrecioCondicion() { | 1022 | function valorPrecioCondicion() { |
1023 | if (remito.idPrecioCondicion > 0) { | 1023 | if (remito.idPrecioCondicion > 0) { |
1024 | return remito.precioCondicion.nombre; | 1024 | return remito.precioCondicion.nombre; |
1025 | } else { | 1025 | } else { |
1026 | return 'Ingreso Manual'; | 1026 | return 'Ingreso Manual'; |
1027 | } | 1027 | } |
1028 | } | 1028 | } |
1029 | if (remito.flete === 1) { | 1029 | if (remito.flete === 1) { |
1030 | var cabeceraBomba = { | 1030 | var cabeceraBomba = { |
1031 | label: 'Bomba', | 1031 | label: 'Bomba', |
1032 | valor: remito.bomba === 1 ? 'Si' : 'No' | 1032 | valor: remito.bomba === 1 ? 'Si' : 'No' |
1033 | }; | 1033 | }; |
1034 | if (remito.kilometros) { | 1034 | if (remito.kilometros) { |
1035 | var cabeceraKilometros = { | 1035 | var cabeceraKilometros = { |
1036 | label: 'Kilometros', | 1036 | label: 'Kilometros', |
1037 | valor: remito.kilometros | 1037 | valor: remito.kilometros |
1038 | }; | 1038 | }; |
1039 | cabeceras.push(cabeceraKilometros); | 1039 | cabeceras.push(cabeceraKilometros); |
1040 | } | 1040 | } |
1041 | cabeceras.push(cabeceraBomba); | 1041 | cabeceras.push(cabeceraBomba); |
1042 | } | 1042 | } |
1043 | 1043 | ||
1044 | if (remito.idPrecioCondicion > 0) { | 1044 | if (remito.idPrecioCondicion > 0) { |
1045 | $scope.idLista = remito.precioCondicion.idListaPrecio; | 1045 | $scope.idLista = remito.precioCondicion.idListaPrecio; |
1046 | } else { | 1046 | } else { |
1047 | $scope.idLista = -1; | 1047 | $scope.idLista = -1; |
1048 | } | 1048 | } |
1049 | $scope.puntoVenta = rellenar(remito.sucursal, 4); | 1049 | $scope.puntoVenta = rellenar(remito.sucursal, 4); |
1050 | $scope.comprobante = rellenar(remito.numeroRemito, 8); | 1050 | $scope.comprobante = rellenar(remito.numeroRemito, 8); |
1051 | $scope.remito = remito; | 1051 | $scope.remito = remito; |
1052 | addArrayCabecera(cabeceras); | 1052 | addArrayCabecera(cabeceras); |
1053 | } | 1053 | } |
1054 | 1054 | ||
1055 | function getLSRemito() { | 1055 | function getLSRemito() { |
1056 | var remito = JSON.parse($localStorage.remito || null); | 1056 | var remito = JSON.parse($localStorage.remito || null); |
1057 | if (remito) { | 1057 | if (remito) { |
1058 | setearRemito(remito); | 1058 | setearRemito(remito); |
1059 | delete $localStorage.remito; | 1059 | delete $localStorage.remito; |
1060 | } | 1060 | } |
1061 | } | 1061 | } |
1062 | 1062 | ||
1063 | function deleteCliente() { | 1063 | function deleteCliente() { |
1064 | delete $scope.remito.domicilioStamp; | 1064 | delete $scope.remito.domicilioStamp; |
1065 | delete $scope.remito.puntosDescarga; | 1065 | delete $scope.remito.puntosDescarga; |
1066 | $scope.remito.domicilio = {dom: ''}; | 1066 | $scope.remito.domicilio = {dom: ''}; |
1067 | $scope.remito.cliente = {}; | 1067 | $scope.remito.cliente = {}; |
1068 | $scope.$broadcast('removeCabecera', 'Cliente:'); | 1068 | $scope.$broadcast('removeCabecera', 'Cliente:'); |
1069 | $scope.$broadcast('removeCabecera', 'Domicilio:'); | 1069 | $scope.$broadcast('removeCabecera', 'Domicilio:'); |
1070 | $scope.$broadcast('removeCabecera', 'Puntos de descarga:'); | 1070 | $scope.$broadcast('removeCabecera', 'Puntos de descarga:'); |
1071 | } | 1071 | } |
1072 | 1072 | ||
1073 | function abrirModalMail(id, cliente, numeroRemito) { | 1073 | function abrirModalMail(id, cliente, numeroRemito) { |
1074 | focaModalService.mail( | 1074 | focaModalService.mail( |
1075 | { | 1075 | { |
1076 | titulo: 'Comprobante de remito Nº ' + numeroRemito, | 1076 | titulo: 'Comprobante de remito Nº ' + numeroRemito, |
1077 | descarga: { | 1077 | descarga: { |
1078 | nombre: numeroRemito + '.pdf', | 1078 | nombre: numeroRemito + '.pdf', |
1079 | url: '/remito/comprobante', | 1079 | url: '/remito/comprobante', |
1080 | }, | 1080 | }, |