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