Commit c93664d299b0cef8be76c16a15e2eb48abfe1995
Exists in
master
Merge branch 'master' into 'develop'
Master See merge request !96
Showing
2 changed files
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: 'Precios y condiciones:', | 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.vendedor.NUM, | 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.idLista, | 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 | crearRemitoService.crearRemito(save).then( | 360 | crearRemitoService.crearRemito(save).then( |
361 | function (data) { | 361 | function (data) { |
362 | 362 | ||
363 | focaBotoneraLateralService.endGuardar(true); | 363 | focaBotoneraLateralService.endGuardar(true); |
364 | $scope.saveLoading = false; | 364 | $scope.saveLoading = false; |
365 | 365 | ||
366 | $scope.remito.numeroRemito = data.data.numero; | 366 | $scope.remito.numeroRemito = data.data.numero; |
367 | 367 | ||
368 | if ($scope.remito.remitoPuntoDescarga.length > 0) { | 368 | if ($scope.remito.remitoPuntoDescarga.length > 0) { |
369 | remitoBusinessService.addPuntosDescarga(data.data.id, | 369 | remitoBusinessService.addPuntosDescarga(data.data.id, |
370 | $scope.remito.remitoPuntoDescarga); | 370 | $scope.remito.remitoPuntoDescarga); |
371 | } | 371 | } |
372 | 372 | ||
373 | if (data.status === 500) { | 373 | if (data.status === 500) { |
374 | focaModalService.alert(data.data); | 374 | focaModalService.alert(data.data); |
375 | return; | 375 | return; |
376 | } | 376 | } |
377 | 377 | ||
378 | // TODO: updatear plazos | 378 | // TODO: updatear plazos |
379 | if ($scope.remito.id == 0) { | 379 | if ($scope.remito.id == 0) { |
380 | 380 | ||
381 | remitoBusinessService.addArticulos($scope.remito.articulosRemito, | 381 | remitoBusinessService.addArticulos($scope.remito.articulosRemito, |
382 | data.data.id, $scope.remito.cotizacion.VENDEDOR); | 382 | data.data.id, $scope.remito.cotizacion.VENDEDOR); |
383 | 383 | ||
384 | var plazos = $scope.remito.remitoPlazo; | 384 | var plazos = $scope.remito.remitoPlazo; |
385 | 385 | ||
386 | for (var j = 0; j < plazos.length; j++) { | 386 | for (var j = 0; j < plazos.length; j++) { |
387 | var json = { | 387 | var json = { |
388 | idRemito: data.data.id, | 388 | idRemito: data.data.id, |
389 | dias: plazos[j].dias | 389 | dias: plazos[j].dias |
390 | }; | 390 | }; |
391 | crearRemitoService.crearPlazosParaRemito(json); | 391 | crearRemitoService.crearPlazosParaRemito(json); |
392 | } | 392 | } |
393 | } | 393 | } |
394 | 394 | ||
395 | abrirModalMail(data.data.id, | 395 | abrirModalMail(data.data.id, |
396 | $scope.remito.cliente, | 396 | $scope.remito.cliente, |
397 | $filter('comprobante')([ | 397 | $filter('comprobante')([ |
398 | $scope.puntoVenta, | 398 | $scope.puntoVenta, |
399 | $scope.remito.numeroRemito | 399 | $scope.remito.numeroRemito |
400 | ]) | 400 | ]) |
401 | ); | 401 | ); |
402 | 402 | ||
403 | config(); | 403 | config(); |
404 | 404 | ||
405 | }, function (error) { | 405 | }, function (error) { |
406 | focaModalService.alert(error.data || 'Hubo un error al crear el remito'); | 406 | focaModalService.alert(error.data || 'Hubo un error al crear el remito'); |
407 | focaBotoneraLateralService.endGuardar(); | 407 | focaBotoneraLateralService.endGuardar(); |
408 | $scope.saveLoading = false; | 408 | $scope.saveLoading = false; |
409 | console.info(error); | 409 | console.info(error); |
410 | } | 410 | } |
411 | ); | 411 | ); |
412 | }; | 412 | }; |
413 | $scope.seleccionarProductos = function () { | 413 | $scope.seleccionarProductos = function () { |
414 | if ($scope.idLista === undefined) { | 414 | if ($scope.idLista === undefined) { |
415 | focaModalService.alert( | 415 | focaModalService.alert( |
416 | 'Primero seleccione una lista de precio y condicion'); | 416 | 'Primero seleccione una lista de precio y condicion'); |
417 | return; | 417 | return; |
418 | } | 418 | } |
419 | var modalInstance = $uibModal.open( | 419 | var modalInstance = $uibModal.open( |
420 | { | 420 | { |
421 | ariaLabelledBy: 'Busqueda de Productos', | 421 | ariaLabelledBy: 'Busqueda de Productos', |
422 | templateUrl: 'modal-busqueda-productos.html', | 422 | templateUrl: 'modal-busqueda-productos.html', |
423 | controller: 'modalBusquedaProductosCtrl', | 423 | controller: 'modalBusquedaProductosCtrl', |
424 | resolve: { | 424 | resolve: { |
425 | parametroProducto: { | 425 | parametroProducto: { |
426 | idLista: $scope.idLista, | 426 | idLista: $scope.idLista, |
427 | cotizacion: $scope.remito.cotizacion.VENDEDOR, | 427 | cotizacion: $scope.remito.cotizacion.VENDEDOR, |
428 | simbolo: $scope.remito.cotizacion.moneda.SIMBOLO | 428 | simbolo: $scope.remito.cotizacion.moneda.SIMBOLO |
429 | } | 429 | } |
430 | }, | 430 | }, |
431 | size: 'lg' | 431 | size: 'lg' |
432 | } | 432 | } |
433 | ); | 433 | ); |
434 | modalInstance.result.then( | 434 | modalInstance.result.then( |
435 | function (producto) { | 435 | function (producto) { |
436 | var newArt = | 436 | var newArt = |
437 | { | 437 | { |
438 | id: 0, | 438 | id: 0, |
439 | idRemito: 0, | 439 | idRemito: 0, |
440 | codigo: producto.codigo, | 440 | codigo: producto.codigo, |
441 | sector: producto.sector, | 441 | sector: producto.sector, |
442 | sectorCodigo: producto.sector + '-' + producto.codigo, | 442 | sectorCodigo: producto.sector + '-' + producto.codigo, |
443 | descripcion: producto.descripcion, | 443 | descripcion: producto.descripcion, |
444 | item: $scope.remito.articulosRemito.length + 1, | 444 | item: $scope.remito.articulosRemito.length + 1, |
445 | nombre: producto.descripcion, | 445 | nombre: producto.descripcion, |
446 | precio: parseFloat(producto.precio.toFixed(4)), | 446 | precio: parseFloat(producto.precio.toFixed(4)), |
447 | costoUnitario: producto.costo, | 447 | costoUnitario: producto.costo, |
448 | editCantidad: false, | 448 | editCantidad: false, |
449 | editPrecio: false, | 449 | editPrecio: false, |
450 | rubro: producto.CodRub, | 450 | rubro: producto.CodRub, |
451 | ivaUnitario: producto.IMPIVA, | 451 | ivaUnitario: producto.IMPIVA, |
452 | impuestoInternoUnitario: producto.ImpInt, | 452 | impuestoInternoUnitario: producto.ImpInt, |
453 | impuestoInterno1Unitario: producto.ImpInt2, | 453 | impuestoInterno1Unitario: producto.ImpInt2, |
454 | impuestoInterno2Unitario: producto.ImpInt3, | 454 | impuestoInterno2Unitario: producto.ImpInt3, |
455 | precioLista: producto.precio, | 455 | precioLista: producto.precio, |
456 | combustible: 1, | 456 | combustible: 1, |
457 | facturado: 0, | 457 | facturado: 0, |
458 | idArticulo: producto.id, | 458 | idArticulo: producto.id, |
459 | tasaIva: producto.tasaIVA | 459 | tasaIva: producto.tasaIVA |
460 | }; | 460 | }; |
461 | 461 | ||
462 | newArt.exentoUnitario = newArt.ivaUnitario ? 0 : producto.neto; | 462 | newArt.exentoUnitario = newArt.ivaUnitario ? 0 : producto.neto; |
463 | newArt.netoUnitario = newArt.ivaUnitario ? producto.neto : 0; | 463 | newArt.netoUnitario = newArt.ivaUnitario ? producto.neto : 0; |
464 | 464 | ||
465 | $scope.articuloACargar = newArt; | 465 | $scope.articuloACargar = newArt; |
466 | $scope.cargando = false; | 466 | $scope.cargando = false; |
467 | }, function () { | 467 | }, function () { |
468 | // funcion ejecutada cuando se cancela el modal | 468 | // funcion ejecutada cuando se cancela el modal |
469 | } | 469 | } |
470 | ); | 470 | ); |
471 | }; | 471 | }; |
472 | $scope.seleccionarPuntosDeDescarga = function () { | 472 | $scope.seleccionarPuntosDeDescarga = function () { |
473 | if (!$scope.remito.cliente.COD || !$scope.remito.domicilio.id) { | 473 | if (!$scope.remito.cliente.COD || !$scope.remito.domicilio.id) { |
474 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); | 474 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); |
475 | return; | 475 | return; |
476 | } else { | 476 | } else { |
477 | var modalInstance = $uibModal.open( | 477 | var modalInstance = $uibModal.open( |
478 | { | 478 | { |
479 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', | 479 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', |
480 | templateUrl: 'modal-punto-descarga.html', | 480 | templateUrl: 'modal-punto-descarga.html', |
481 | controller: 'focaModalPuntoDescargaController', | 481 | controller: 'focaModalPuntoDescargaController', |
482 | size: 'lg', | 482 | size: 'lg', |
483 | resolve: { | 483 | resolve: { |
484 | filters: { | 484 | filters: { |
485 | idDomicilio: $scope.remito.domicilio.id, | 485 | idDomicilio: $scope.remito.domicilio.id, |
486 | idCliente: $scope.remito.cliente.COD, | 486 | idCliente: $scope.remito.cliente.COD, |
487 | articulos: $scope.remito.articulosRemito, | 487 | articulos: $scope.remito.articulosRemito, |
488 | puntosDescarga: $scope.remito.remitoPuntoDescarga, | 488 | puntosDescarga: $scope.remito.remitoPuntoDescarga, |
489 | domicilio: $scope.remito.domicilio | 489 | domicilio: $scope.remito.domicilio |
490 | } | 490 | } |
491 | } | 491 | } |
492 | } | 492 | } |
493 | ); | 493 | ); |
494 | modalInstance.result.then( | 494 | modalInstance.result.then( |
495 | function (puntosDescarga) { | 495 | function (puntosDescarga) { |
496 | 496 | ||
497 | puntosDescarga.forEach(function (punto) { | 497 | puntosDescarga.forEach(function (punto) { |
498 | $scope.remito.remitoPuntoDescarga.push( | 498 | $scope.remito.remitoPuntoDescarga.push( |
499 | { | 499 | { |
500 | puntoDescarga: punto | 500 | puntoDescarga: punto |
501 | } | 501 | } |
502 | ); | 502 | ); |
503 | }); | 503 | }); |
504 | 504 | ||
505 | $scope.$broadcast('addCabecera', { | 505 | $scope.$broadcast('addCabecera', { |
506 | label: 'Puntos de descarga:', | 506 | label: 'Puntos de descarga:', |
507 | valor: getCabeceraPuntoDescarga(puntosDescarga) | 507 | valor: getCabeceraPuntoDescarga(puntosDescarga) |
508 | }); | 508 | }); |
509 | }, function () { | 509 | }, function () { |
510 | $scope.abrirModalDomicilios($scope.cliente); | 510 | $scope.abrirModalDomicilios($scope.cliente); |
511 | } | 511 | } |
512 | ); | 512 | ); |
513 | } | 513 | } |
514 | }; | 514 | }; |
515 | $scope.seleccionarCliente = function () { | 515 | $scope.seleccionarCliente = function () { |
516 | if (varlidarRemitoFacturado()) { | 516 | if (varlidarRemitoFacturado()) { |
517 | var modalInstance = $uibModal.open( | 517 | var modalInstance = $uibModal.open( |
518 | { | 518 | { |
519 | ariaLabelledBy: 'Busqueda de Cliente', | 519 | ariaLabelledBy: 'Busqueda de Cliente', |
520 | templateUrl: 'foca-busqueda-cliente-modal.html', | 520 | templateUrl: 'foca-busqueda-cliente-modal.html', |
521 | controller: 'focaBusquedaClienteModalController', | 521 | controller: 'focaBusquedaClienteModalController', |
522 | resolve: { | 522 | resolve: { |
523 | vendedor: function () { return null; }, | 523 | vendedor: function () { return null; }, |
524 | cobrador: function () { return null; } | 524 | cobrador: function () { return null; } |
525 | }, | 525 | }, |
526 | size: 'lg' | 526 | size: 'lg' |
527 | } | 527 | } |
528 | ); | 528 | ); |
529 | modalInstance.result.then( | 529 | modalInstance.result.then( |
530 | function (cliente) { | 530 | function (cliente) { |
531 | $scope.abrirModalDomicilios(cliente); | 531 | $scope.abrirModalDomicilios(cliente); |
532 | $scope.cliente = cliente; | 532 | $scope.cliente = cliente; |
533 | }, function () { | 533 | }, function () { |
534 | } | 534 | } |
535 | ); | 535 | ); |
536 | } | 536 | } |
537 | }; | 537 | }; |
538 | 538 | ||
539 | $scope.seleccionarProveedor = function () { | 539 | $scope.seleccionarEliminarRemito = function () { |
540 | if (varlidarRemitoFacturado()) { | 540 | focaModalService.confirm('¿Desea eliminar este remito?').then(function (data) { |
541 | if (data) { | ||
542 | $scope.remito.anulado = true; | ||
543 | delete $scope.remito.remitoPlazo; | ||
544 | delete $scope.remito.vendedor; | ||
545 | delete $scope.remito.proveedor; | ||
546 | delete $scope.remito.cliente; | ||
547 | delete $scope.remito.cotizacion; | ||
548 | delete $scope.remito.remitoPuntoDescarga; | ||
549 | delete $scope.remito.articulosRemito; | ||
550 | delete $scope.remito.fechaRemito; | ||
551 | crearRemitoService.eliminarRemito($scope.remito); | ||
552 | } | ||
553 | config(); | ||
554 | }); | ||
555 | }; | ||
556 | |||
557 | $scope.seleccionarProveedor = function () { | ||
558 | if (varlidarRemitoFacturado()) { | ||
541 | var parametrosModal = { | 559 | var parametrosModal = { |
542 | titulo: 'Búsqueda de Proveedor', | 560 | titulo: 'Búsqueda de Proveedor', |
543 | query: '/proveedor', | 561 | query: '/proveedor', |
544 | columnas: [ | 562 | columnas: [ |
545 | { | 563 | { |
546 | nombre: 'Código', | 564 | nombre: 'Código', |
547 | propiedad: 'COD', | 565 | propiedad: 'COD', |
548 | filtro: { | 566 | filtro: { |
549 | nombre: 'rellenarDigitos', | 567 | nombre: 'rellenarDigitos', |
550 | parametro: 5 | 568 | parametro: 5 |
551 | } | 569 | } |
552 | }, | 570 | }, |
553 | { | 571 | { |
554 | nombre: 'Nombre', | 572 | nombre: 'Nombre', |
555 | propiedad: 'NOM' | 573 | propiedad: 'NOM' |
556 | }, | 574 | }, |
557 | { | 575 | { |
558 | nombre: 'CUIT', | 576 | nombre: 'CUIT', |
559 | propiedad: 'CUIT' | 577 | propiedad: 'CUIT' |
560 | } | 578 | } |
561 | ], | 579 | ], |
562 | tipo: 'POST', | 580 | tipo: 'POST', |
563 | json: { razonCuitCod: '' } | 581 | json: { razonCuitCod: '' } |
564 | }; | 582 | }; |
565 | focaModalService.modal(parametrosModal).then( | 583 | focaModalService.modal(parametrosModal).then( |
566 | function (proveedor) { | 584 | function (proveedor) { |
567 | $scope.seleccionarFlete(proveedor); | 585 | $scope.seleccionarFlete(proveedor); |
568 | }, function () { } | 586 | }, function () { } |
569 | ); | 587 | ); |
570 | } | 588 | } |
571 | }; | 589 | }; |
572 | 590 | ||
573 | $scope.abrirModalDomicilios = function (cliente) { | 591 | $scope.abrirModalDomicilios = function (cliente) { |
574 | var modalInstanceDomicilio = $uibModal.open( | 592 | var modalInstanceDomicilio = $uibModal.open( |
575 | { | 593 | { |
576 | ariaLabelledBy: 'Busqueda de Domicilios', | 594 | ariaLabelledBy: 'Busqueda de Domicilios', |
577 | templateUrl: 'modal-domicilio.html', | 595 | templateUrl: 'modal-domicilio.html', |
578 | controller: 'focaModalDomicilioController', | 596 | controller: 'focaModalDomicilioController', |
579 | size: 'lg', | 597 | size: 'lg', |
580 | resolve: { | 598 | resolve: { |
581 | idCliente: function () { return cliente.cod; }, | 599 | idCliente: function () { return cliente.cod; }, |
582 | esNuevo: function () { return cliente.esNuevo; } | 600 | esNuevo: function () { return cliente.esNuevo; } |
583 | } | 601 | } |
584 | } | 602 | } |
585 | ); | 603 | ); |
586 | modalInstanceDomicilio.result.then( | 604 | modalInstanceDomicilio.result.then( |
587 | function (domicilio) { | 605 | function (domicilio) { |
588 | $scope.remito.domicilio = domicilio; | 606 | $scope.remito.domicilio = domicilio; |
589 | $scope.remito.cliente = { | 607 | $scope.remito.cliente = { |
590 | COD: cliente.cod, | 608 | COD: cliente.cod, |
591 | CUIT: cliente.cuit, | 609 | CUIT: cliente.cuit, |
592 | NOM: cliente.nom, | 610 | NOM: cliente.nom, |
593 | MAIL: cliente.mail, | 611 | MAIL: cliente.mail, |
594 | MOD: cliente.mod, | 612 | MOD: cliente.mod, |
595 | IVA: cliente.iva, | 613 | IVA: cliente.iva, |
596 | VEN: cliente.ven | 614 | VEN: cliente.ven |
597 | }; | 615 | }; |
598 | crearRemitoService.getVendedorById($scope.remito.cliente.VEN) | 616 | crearRemitoService.getVendedorById($scope.remito.cliente.VEN) |
599 | .then(function (res) { | 617 | .then(function (res) { |
600 | if (res.data !== '') { | 618 | if (res.data !== '') { |
601 | $scope.remito.vendedor = res.data; | 619 | $scope.remito.vendedor = res.data; |
602 | $scope.$broadcast('addCabecera', { | 620 | $scope.$broadcast('addCabecera', { |
603 | label: 'Vendedor:', | 621 | label: 'Vendedor:', |
604 | valor: $filter('rellenarDigitos')($scope.remito.vendedor | 622 | valor: $filter('rellenarDigitos')($scope.remito.vendedor |
605 | .NUM, 3) + ' - ' + $scope.remito.vendedor.NOM | 623 | .NUM, 3) + ' - ' + $scope.remito.vendedor.NOM |
606 | }); | 624 | }); |
607 | } | 625 | } |
608 | var domicilioStamp = | 626 | var domicilioStamp = |
609 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + | 627 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + |
610 | domicilio.Localidad + ', ' + domicilio.Provincia; | 628 | domicilio.Localidad + ', ' + domicilio.Provincia; |
611 | $scope.remito.domicilioStamp = domicilioStamp; | 629 | $scope.remito.domicilioStamp = domicilioStamp; |
612 | $scope.$broadcast('addCabecera', { | 630 | $scope.$broadcast('addCabecera', { |
613 | label: 'Cliente:', | 631 | label: 'Cliente:', |
614 | valor: $filter('rellenarDigitos')(cliente.cod, 3) + | 632 | valor: $filter('rellenarDigitos')(cliente.cod, 3) + |
615 | ' - ' + cliente.nom | 633 | ' - ' + cliente.nom |
616 | }); | 634 | }); |
617 | $scope.$broadcast('addCabecera', { | 635 | $scope.$broadcast('addCabecera', { |
618 | label: 'Domicilio:', | 636 | label: 'Domicilio:', |
619 | valor: domicilioStamp | 637 | valor: domicilioStamp |
620 | }); | 638 | }); |
621 | 639 | ||
622 | if (domicilio.verPuntos) { | 640 | if (domicilio.verPuntos) { |
623 | delete $scope.remito.domicilio.verPuntos; | 641 | delete $scope.remito.domicilio.verPuntos; |
624 | $scope.seleccionarPuntosDeDescarga(); | 642 | $scope.seleccionarPuntosDeDescarga(); |
625 | } else { | 643 | } else { |
626 | crearRemitoService | 644 | crearRemitoService |
627 | .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) | 645 | .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) |
628 | .then(function (res) { | 646 | .then(function (res) { |
629 | if (res.data.length) { | 647 | if (res.data.length) { |
630 | $scope.seleccionarPuntosDeDescarga(); | 648 | $scope.seleccionarPuntosDeDescarga(); |
631 | } | 649 | } |
632 | }); | 650 | }); |
633 | } | 651 | } |
634 | 652 | ||
635 | $filter('filter')($scope.botonera, | 653 | $filter('filter')($scope.botonera, |
636 | { label: 'Cliente' })[0].checked = true; | 654 | { label: 'Cliente' })[0].checked = true; |
637 | }) | 655 | }) |
638 | .catch(function (e) { console.log(e); }); | 656 | .catch(function (e) { console.log(e); }); |
639 | }, function () { | 657 | }, function () { |
640 | $scope.seleccionarCliente(true); | 658 | $scope.seleccionarCliente(true); |
641 | return; | 659 | return; |
642 | } | 660 | } |
643 | ); | 661 | ); |
644 | }; | 662 | }; |
645 | 663 | ||
646 | $scope.getTotal = function () { | 664 | $scope.getTotal = function () { |
647 | var total = 0; | 665 | var total = 0; |
648 | var arrayTempArticulos = $scope.articulosFiltro(); | 666 | var arrayTempArticulos = $scope.articulosFiltro(); |
649 | for (var i = 0; i < arrayTempArticulos.length; i++) { | 667 | for (var i = 0; i < arrayTempArticulos.length; i++) { |
650 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | 668 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; |
651 | } | 669 | } |
652 | return parseFloat(total.toFixed(2)); | 670 | return parseFloat(total.toFixed(2)); |
653 | }; | 671 | }; |
654 | 672 | ||
655 | $scope.getSubTotal = function () { | 673 | $scope.getSubTotal = function () { |
656 | if ($scope.articuloACargar) { | 674 | if ($scope.articuloACargar) { |
657 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; | 675 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
658 | } | 676 | } |
659 | }; | 677 | }; |
660 | 678 | ||
661 | $scope.seleccionarPreciosYCondiciones = function () { | 679 | $scope.seleccionarPreciosYCondiciones = function () { |
662 | if (!$scope.remito.cliente.COD) { | 680 | if (!$scope.remito.cliente.COD) { |
663 | focaModalService.alert('Primero seleccione un cliente'); | 681 | focaModalService.alert('Primero seleccione un cliente'); |
664 | return; | 682 | return; |
665 | } | 683 | } |
666 | 684 | ||
667 | if ($scope.remito.articulosRemito.length !== 0) { | 685 | if ($scope.remito.articulosRemito.length !== 0) { |
668 | focaModalService.confirm('Se perderan los productos ingresados') | 686 | focaModalService.confirm('Se perderan los productos ingresados') |
669 | .then(function (data) { | 687 | .then(function (data) { |
670 | if (data && varlidarRemitoFacturado()) { | 688 | if (data && varlidarRemitoFacturado()) { |
671 | abrirModal(); | 689 | abrirModal(); |
672 | } | 690 | } |
673 | }); | 691 | }); |
674 | } else { | 692 | } else { |
675 | abrirModal(); | 693 | abrirModal(); |
676 | } | 694 | } |
677 | 695 | ||
678 | function abrirModal() { | 696 | function abrirModal() { |
679 | var modalInstance = $uibModal.open( | 697 | var modalInstance = $uibModal.open( |
680 | { | 698 | { |
681 | ariaLabelledBy: 'Busqueda de Precio Condición', | 699 | ariaLabelledBy: 'Busqueda de Precio Condición', |
682 | templateUrl: 'modal-precio-condicion.html', | 700 | templateUrl: 'modal-precio-condicion.html', |
683 | controller: 'focaModalPrecioCondicionController', | 701 | controller: 'focaModalPrecioCondicionController', |
684 | size: 'lg', | 702 | size: 'lg', |
685 | resolve: { | 703 | resolve: { |
686 | idListaPrecio: function () { return $scope.remito.cliente.MOD || null; }, | 704 | idListaPrecio: function () { return $scope.remito.cliente.MOD || null; }, |
687 | idCliente: function () { return $scope.remito.cliente.COD; } | 705 | idCliente: function () { return $scope.remito.cliente.COD; } |
688 | } | 706 | } |
689 | } | 707 | } |
690 | ); | 708 | ); |
691 | modalInstance.result.then( | 709 | modalInstance.result.then( |
692 | function (precioCondicion) { | 710 | function (precioCondicion) { |
693 | var cabecera = ''; | 711 | var cabecera = ''; |
694 | var plazosConcat = ''; | 712 | var plazosConcat = ''; |
695 | if (!Array.isArray(precioCondicion)) { | 713 | if (!Array.isArray(precioCondicion)) { |
696 | $scope.remito.idPrecioCondicion = precioCondicion.listaPrecio.ID; | 714 | $scope.remito.idPrecioCondicion = precioCondicion.listaPrecio.ID; |
697 | $scope.remito.remitoPlazo = precioCondicion.plazoPago; | 715 | $scope.remito.remitoPlazo = precioCondicion.plazoPago; |
698 | $scope.idLista = parseInt(precioCondicion.listaPrecio.ID) ? | 716 | $scope.idLista = parseInt(precioCondicion.listaPrecio.ID) ? |
699 | parseInt(precioCondicion.listaPrecio.ID) : -1; | 717 | parseInt(precioCondicion.listaPrecio.ID) : -1; |
700 | for (var i = 0; i < precioCondicion.plazoPago.length; i++) { | 718 | for (var i = 0; i < precioCondicion.plazoPago.length; i++) { |
701 | plazosConcat += precioCondicion.plazoPago[i].dias + ', '; | 719 | plazosConcat += precioCondicion.plazoPago[i].dias + ', '; |
702 | } | 720 | } |
703 | plazosConcat = plazosConcat.substring(0, plazosConcat.length - 2); | 721 | plazosConcat = plazosConcat.substring(0, plazosConcat.length - 2); |
704 | cabecera = $filter('rellenarDigitos')(parseInt(precioCondicion.listaPrecio.ID), 4) + | 722 | cabecera = $filter('rellenarDigitos')(parseInt(precioCondicion.listaPrecio.ID), 4) + |
705 | ' - ' + precioCondicion.listaPrecio.DES + ' ' + plazosConcat.trim(); | 723 | ' - ' + precioCondicion.listaPrecio.DES + ' ' + plazosConcat.trim(); |
706 | } else { //Cuando se ingresan los plazos manualmente | 724 | } else { //Cuando se ingresan los plazos manualmente |
707 | $scope.remito.idPrecioCondicion = 0; | 725 | $scope.remito.idPrecioCondicion = 0; |
708 | //-1, el modal productos busca todos los productos | 726 | //-1, el modal productos busca todos los productos |
709 | $scope.idLista = -1; | 727 | $scope.idLista = -1; |
710 | $scope.remito.remitoPlazo = precioCondicion; | 728 | $scope.remito.remitoPlazo = precioCondicion; |
711 | for (var j = 0; j < precioCondicion.length; j++) { | 729 | for (var j = 0; j < precioCondicion.length; j++) { |
712 | plazosConcat += precioCondicion[j].dias + ' '; | 730 | plazosConcat += precioCondicion[j].dias + ' '; |
713 | } | 731 | } |
714 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); | 732 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); |
715 | } | 733 | } |
716 | $scope.remito.articulosRemito = []; | 734 | $scope.remito.articulosRemito = []; |
717 | $scope.$broadcast('addCabecera', { | 735 | $scope.$broadcast('addCabecera', { |
718 | label: 'Precios y condiciones:', | 736 | label: 'Precios y condiciones:', |
719 | valor: cabecera | 737 | valor: cabecera |
720 | }); | 738 | }); |
721 | $scope.remito.precioCondicion = precioCondicion; | 739 | $scope.remito.precioCondicion = precioCondicion; |
722 | 740 | ||
723 | $filter('filter')($scope.botonera, | 741 | $filter('filter')($scope.botonera, |
724 | { label: 'Precios y Condiciones' })[0].checked = true; | 742 | { label: 'Precios y Condiciones' })[0].checked = true; |
725 | }, function () { | 743 | }, function () { |
726 | 744 | ||
727 | } | 745 | } |
728 | ); | 746 | ); |
729 | } | 747 | } |
730 | }; | 748 | }; |
731 | 749 | ||
732 | $scope.seleccionarFlete = function (proveedor) { | 750 | $scope.seleccionarFlete = function (proveedor) { |
733 | if (varlidarRemitoFacturado()) { | 751 | if (varlidarRemitoFacturado()) { |
734 | var modalInstance = $uibModal.open( | 752 | var modalInstance = $uibModal.open( |
735 | { | 753 | { |
736 | ariaLabelledBy: 'Busqueda de Flete', | 754 | ariaLabelledBy: 'Busqueda de Flete', |
737 | templateUrl: 'modal-flete.html', | 755 | templateUrl: 'modal-flete.html', |
738 | controller: 'focaModalFleteController', | 756 | controller: 'focaModalFleteController', |
739 | size: 'lg', | 757 | size: 'lg', |
740 | resolve: { | 758 | resolve: { |
741 | parametrosFlete: | 759 | parametrosFlete: |
742 | function () { | 760 | function () { |
743 | return { | 761 | return { |
744 | flete: $scope.remito.flete ? '1' : | 762 | flete: $scope.remito.flete ? '1' : |
745 | ($scope.remito.fob ? 'FOB' : | 763 | ($scope.remito.fob ? 'FOB' : |
746 | ($scope.remito.flete === undefined ? | 764 | ($scope.remito.flete === undefined ? |
747 | null : '0')), | 765 | null : '0')), |
748 | bomba: $scope.remito.bomba ? '1' : | 766 | bomba: $scope.remito.bomba ? '1' : |
749 | ($scope.remito.bomba === undefined ? | 767 | ($scope.remito.bomba === undefined ? |
750 | null : '0'), | 768 | null : '0'), |
751 | kilometros: $scope.remito.kilometros | 769 | kilometros: $scope.remito.kilometros |
752 | }; | 770 | }; |
753 | } | 771 | } |
754 | } | 772 | } |
755 | } | 773 | } |
756 | ); | 774 | ); |
757 | modalInstance.result.then( | 775 | modalInstance.result.then( |
758 | function (datos) { | 776 | function (datos) { |
759 | $scope.remitoIsDirty = true; | 777 | $scope.remitoIsDirty = true; |
760 | $scope.remito.proveedor = proveedor; | 778 | $scope.remito.proveedor = proveedor; |
761 | $scope.remito.idProveedor = proveedor.COD; | 779 | $scope.remito.idProveedor = proveedor.COD; |
762 | $scope.$broadcast('addCabecera', { | 780 | $scope.$broadcast('addCabecera', { |
763 | label: 'Proveedor:', | 781 | label: 'Proveedor:', |
764 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + | 782 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + |
765 | proveedor.NOM | 783 | proveedor.NOM |
766 | }); | 784 | }); |
767 | 785 | ||
768 | $scope.remito.flete = datos.flete; | 786 | $scope.remito.flete = datos.flete; |
769 | $scope.remito.fob = datos.FOB; | 787 | $scope.remito.fob = datos.FOB; |
770 | $scope.remito.bomba = datos.bomba; | 788 | $scope.remito.bomba = datos.bomba; |
771 | $scope.remito.kilometros = datos.kilometros; | 789 | $scope.remito.kilometros = datos.kilometros; |
772 | 790 | ||
773 | $scope.$broadcast('addCabecera', { | 791 | $scope.$broadcast('addCabecera', { |
774 | label: 'Flete:', | 792 | label: 'Flete:', |
775 | valor: datos.flete ? 'Si' : ($scope.remito.fob ? 'FOB' : 'No') | 793 | valor: datos.flete ? 'Si' : ($scope.remito.fob ? 'FOB' : 'No') |
776 | }); | 794 | }); |
777 | if (datos.flete) { | 795 | if (datos.flete) { |
778 | $scope.$broadcast('addCabecera', { | 796 | $scope.$broadcast('addCabecera', { |
779 | label: 'Bomba:', | 797 | label: 'Bomba:', |
780 | valor: datos.bomba ? 'Si' : 'No' | 798 | valor: datos.bomba ? 'Si' : 'No' |
781 | }); | 799 | }); |
782 | $scope.$broadcast('addCabecera', { | 800 | $scope.$broadcast('addCabecera', { |
783 | label: 'Kilometros:', | 801 | label: 'Kilometros:', |
784 | valor: datos.kilometros | 802 | valor: datos.kilometros |
785 | }); | 803 | }); |
786 | } else { | 804 | } else { |
787 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 805 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
788 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 806 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
789 | $scope.remito.bomba = false; | 807 | $scope.remito.bomba = false; |
790 | $scope.remito.kilometros = null; | 808 | $scope.remito.kilometros = null; |
791 | } | 809 | } |
792 | 810 | ||
793 | $filter('filter')($scope.botonera, | 811 | $filter('filter')($scope.botonera, |
794 | { label: 'Proveedor' })[0].checked = true; | 812 | { label: 'Proveedor' })[0].checked = true; |
795 | }, function () { | 813 | }, function () { |
796 | $scope.seleccionarTransportista(); | 814 | $scope.seleccionarTransportista(); |
797 | } | 815 | } |
798 | ); | 816 | ); |
799 | } | 817 | } |
800 | }; | 818 | }; |
801 | 819 | ||
802 | $scope.seleccionarMoneda = function () { | 820 | $scope.seleccionarMoneda = function () { |
803 | if (varlidarRemitoFacturado()) { | 821 | if (varlidarRemitoFacturado()) { |
804 | var parametrosModal = { | 822 | var parametrosModal = { |
805 | titulo: 'Búsqueda de monedas', | 823 | titulo: 'Búsqueda de monedas', |
806 | query: '/moneda', | 824 | query: '/moneda', |
807 | columnas: [ | 825 | columnas: [ |
808 | { | 826 | { |
809 | propiedad: 'DETALLE', | 827 | propiedad: 'DETALLE', |
810 | nombre: 'Nombre' | 828 | nombre: 'Nombre' |
811 | }, | 829 | }, |
812 | { | 830 | { |
813 | propiedad: 'SIMBOLO', | 831 | propiedad: 'SIMBOLO', |
814 | nombre: 'Símbolo' | 832 | nombre: 'Símbolo' |
815 | } | 833 | } |
816 | ], | 834 | ], |
817 | size: 'md' | 835 | size: 'md' |
818 | }; | 836 | }; |
819 | focaModalService.modal(parametrosModal).then( | 837 | focaModalService.modal(parametrosModal).then( |
820 | function (moneda) { | 838 | function (moneda) { |
821 | 839 | ||
822 | if (moneda.ID !== 1) { | 840 | if (moneda.ID !== 1) { |
823 | $scope.abrirModalCotizacion(moneda); | 841 | $scope.abrirModalCotizacion(moneda); |
824 | return; | 842 | return; |
825 | } | 843 | } |
826 | 844 | ||
827 | crearRemitoService.getCotizacionByIdMoneda(1) | 845 | crearRemitoService.getCotizacionByIdMoneda(1) |
828 | .then(function (res) { | 846 | .then(function (res) { |
829 | 847 | ||
830 | cotizacionPArgentino = res.data[0].cotizaciones[0]; | 848 | cotizacionPArgentino = res.data[0].cotizaciones[0]; |
831 | cotizacionPArgentino.moneda = moneda; | 849 | cotizacionPArgentino.moneda = moneda; |
832 | 850 | ||
833 | actualizarCabeceraMoneda(cotizacionPArgentino); | 851 | actualizarCabeceraMoneda(cotizacionPArgentino); |
834 | 852 | ||
835 | $scope.remito.cotizacion = cotizacionPArgentino; | 853 | $scope.remito.cotizacion = cotizacionPArgentino; |
836 | }); | 854 | }); |
837 | }, function () { | 855 | }, function () { |
838 | 856 | ||
839 | } | 857 | } |
840 | ); | 858 | ); |
841 | } | 859 | } |
842 | }; | 860 | }; |
843 | 861 | ||
844 | $scope.seleccionarObservaciones = function () { | 862 | $scope.seleccionarObservaciones = function () { |
845 | focaModalService | 863 | focaModalService |
846 | .prompt({ | 864 | .prompt({ |
847 | titulo: 'Observaciones', | 865 | titulo: 'Observaciones', |
848 | value: $scope.remito.observaciones, | 866 | value: $scope.remito.observaciones, |
849 | textarea: true, | 867 | textarea: true, |
850 | readonly: true | 868 | readonly: true |
851 | }) | 869 | }) |
852 | .then(function (observaciones) { | 870 | .then(function (observaciones) { |
853 | $scope.remito.observaciones = observaciones; | 871 | $scope.remito.observaciones = observaciones; |
854 | }); | 872 | }); |
855 | }; | 873 | }; |
856 | 874 | ||
857 | $scope.abrirModalCotizacion = function (moneda) { | 875 | $scope.abrirModalCotizacion = function (moneda) { |
858 | var modalInstance = $uibModal.open( | 876 | var modalInstance = $uibModal.open( |
859 | { | 877 | { |
860 | ariaLabelledBy: 'Busqueda de Cotización', | 878 | ariaLabelledBy: 'Busqueda de Cotización', |
861 | templateUrl: 'modal-cotizacion.html', | 879 | templateUrl: 'modal-cotizacion.html', |
862 | controller: 'focaModalCotizacionController', | 880 | controller: 'focaModalCotizacionController', |
863 | size: 'lg', | 881 | size: 'lg', |
864 | resolve: { idMoneda: function () { return moneda.ID; } } | 882 | resolve: { idMoneda: function () { return moneda.ID; } } |
865 | } | 883 | } |
866 | ); | 884 | ); |
867 | modalInstance.result.then( | 885 | modalInstance.result.then( |
868 | function (cotizacion) { | 886 | function (cotizacion) { |
869 | cotizacion.moneda = moneda; | 887 | cotizacion.moneda = moneda; |
870 | $scope.remitoIsDirty = true; | 888 | $scope.remitoIsDirty = true; |
871 | actualizarCabeceraMoneda(cotizacion); | 889 | actualizarCabeceraMoneda(cotizacion); |
872 | $scope.remito.cotizacion = cotizacion; | 890 | $scope.remito.cotizacion = cotizacion; |
873 | }, function () { | 891 | }, function () { |
874 | 892 | ||
875 | } | 893 | } |
876 | ); | 894 | ); |
877 | }; | 895 | }; |
878 | 896 | ||
879 | function actualizarCabeceraMoneda(cotizacion) { | 897 | function actualizarCabeceraMoneda(cotizacion) { |
880 | 898 | ||
881 | $scope.remito.articulosRemito.forEach(function (art) { | 899 | $scope.remito.articulosRemito.forEach(function (art) { |
882 | art.precio = (art.precio * $scope.remito.cotizacion.VENDEDOR).toFixed(4); | 900 | art.precio = (art.precio * $scope.remito.cotizacion.VENDEDOR).toFixed(4); |
883 | art.precio = (art.precio / cotizacion.VENDEDOR).toFixed(4); | 901 | art.precio = (art.precio / cotizacion.VENDEDOR).toFixed(4); |
884 | }); | 902 | }); |
885 | 903 | ||
886 | if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { | 904 | if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { |
887 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 905 | $scope.$broadcast('removeCabecera', 'Moneda:'); |
888 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 906 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); |
889 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 907 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); |
890 | } else { | 908 | } else { |
891 | $scope.$broadcast('addCabecera', { | 909 | $scope.$broadcast('addCabecera', { |
892 | label: 'Moneda:', | 910 | label: 'Moneda:', |
893 | valor: cotizacion.moneda.DETALLE | 911 | valor: cotizacion.moneda.DETALLE |
894 | }); | 912 | }); |
895 | $scope.$broadcast('addCabecera', { | 913 | $scope.$broadcast('addCabecera', { |
896 | label: 'Fecha cotizacion:', | 914 | label: 'Fecha cotizacion:', |
897 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 915 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') |
898 | }); | 916 | }); |
899 | $scope.$broadcast('addCabecera', { | 917 | $scope.$broadcast('addCabecera', { |
900 | label: 'Cotizacion:', | 918 | label: 'Cotizacion:', |
901 | valor: $filter('number')(cotizacion.VENDEDOR, '2') | 919 | valor: $filter('number')(cotizacion.VENDEDOR, '2') |
902 | }); | 920 | }); |
903 | } | 921 | } |
904 | } | 922 | } |
905 | 923 | ||
906 | $scope.agregarATabla = function (key) { | 924 | $scope.agregarATabla = function (key) { |
907 | if (key === 13) { | 925 | if (key === 13) { |
908 | if (!$scope.articuloACargar.cantidad || !$scope.articuloACargar.precio) { | 926 | if (!$scope.articuloACargar.cantidad || !$scope.articuloACargar.precio) { |
909 | focaModalService.alert('El valor debe ser al menos 1'); | 927 | focaModalService.alert('El valor debe ser al menos 1'); |
910 | return; | 928 | return; |
911 | } | 929 | } |
912 | delete $scope.articuloACargar.sectorCodigo; | 930 | delete $scope.articuloACargar.sectorCodigo; |
913 | $scope.remito.articulosRemito.push($scope.articuloACargar); | 931 | $scope.remito.articulosRemito.push($scope.articuloACargar); |
914 | $scope.cargando = true; | 932 | $scope.cargando = true; |
915 | } | 933 | } |
916 | }; | 934 | }; |
917 | 935 | ||
918 | $scope.quitarArticulo = function (articulo) { | 936 | $scope.quitarArticulo = function (articulo) { |
919 | articulo.idRemito = -1; | 937 | articulo.idRemito = -1; |
920 | }; | 938 | }; |
921 | 939 | ||
922 | $scope.articulosFiltro = function () { | 940 | $scope.articulosFiltro = function () { |
923 | 941 | ||
924 | var result = $scope.remito.articulosRemito.filter(function (articulo) { | 942 | var result = $scope.remito.articulosRemito.filter(function (articulo) { |
925 | return articulo.idRemito >= 0; | 943 | return articulo.idRemito >= 0; |
926 | }); | 944 | }); |
927 | 945 | ||
928 | // Agrego checked en cabecera si hay datos | 946 | // Agrego checked en cabecera si hay datos |
929 | if (result.length) { | 947 | if (result.length) { |
930 | $filter('filter')($scope.botonera, { label: 'Productos' })[0].checked = true; | 948 | $filter('filter')($scope.botonera, { label: 'Productos' })[0].checked = true; |
931 | } else { | 949 | } else { |
932 | $filter('filter')($scope.botonera, { label: 'Productos' })[0].checked = false; | 950 | $filter('filter')($scope.botonera, { label: 'Productos' })[0].checked = false; |
933 | } | 951 | } |
934 | return result; | 952 | return result; |
935 | }; | 953 | }; |
936 | 954 | ||
937 | $scope.editarArticulo = function (key, articulo, tmpCantidad, tmpPrecio) { | 955 | $scope.editarArticulo = function (key, articulo, tmpCantidad, tmpPrecio) { |
938 | if (key === 13) { | 956 | if (key === 13) { |
939 | if (!articulo.cantidad || !articulo.precio || !tmpCantidad || !tmpPrecio) { | 957 | if (!articulo.cantidad || !articulo.precio || !tmpCantidad || !tmpPrecio) { |
940 | focaModalService.alert('Los valores deben ser al menos 1'); | 958 | focaModalService.alert('Los valores deben ser al menos 1'); |
941 | return; | 959 | return; |
942 | } else if (articulo.cantidad < 0 || articulo.precio < 0) { | 960 | } else if (articulo.cantidad < 0 || articulo.precio < 0) { |
943 | focaModalService.alert('Los valores no pueden ser negativos'); | 961 | focaModalService.alert('Los valores no pueden ser negativos'); |
944 | return; | 962 | return; |
945 | } | 963 | } |
946 | articulo.cantidad = tmpCantidad; | 964 | articulo.cantidad = tmpCantidad; |
947 | articulo.precio = tmpPrecio; | 965 | articulo.precio = tmpPrecio; |
948 | $scope.getTotal(); | 966 | $scope.getTotal(); |
949 | articulo.editCantidad = articulo.editPrecio = false; | 967 | articulo.editCantidad = articulo.editPrecio = false; |
950 | } | 968 | } |
951 | }; | 969 | }; |
952 | 970 | ||
953 | $scope.cancelarEditar = function (articulo) { | 971 | $scope.cancelarEditar = function (articulo) { |
954 | $scope.tmpCantidad = articulo.cantidad; | 972 | $scope.tmpCantidad = articulo.cantidad; |
955 | $scope.tmpPrecio = articulo.precio; | 973 | $scope.tmpPrecio = articulo.precio; |
956 | articulo.editCantidad = articulo.editPrecio = false; | 974 | articulo.editCantidad = articulo.editPrecio = false; |
957 | }; | 975 | }; |
958 | 976 | ||
959 | $scope.cambioEdit = function (articulo, propiedad) { | 977 | $scope.cambioEdit = function (articulo, propiedad) { |
960 | if (propiedad === 'cantidad') { | 978 | if (propiedad === 'cantidad') { |
961 | articulo.editCantidad = true; | 979 | articulo.editCantidad = true; |
962 | } else if (propiedad === 'precio') { | 980 | } else if (propiedad === 'precio') { |
963 | articulo.editPrecio = true; | 981 | articulo.editPrecio = true; |
964 | } | 982 | } |
965 | }; | 983 | }; |
966 | 984 | ||
967 | $scope.resetFilter = function () { | 985 | $scope.resetFilter = function () { |
968 | $scope.articuloACargar = {}; | 986 | $scope.articuloACargar = {}; |
969 | $scope.cargando = true; | 987 | $scope.cargando = true; |
970 | }; | 988 | }; |
971 | //Recibe aviso si el teclado está en uso | 989 | //Recibe aviso si el teclado está en uso |
972 | $rootScope.$on('usarTeclado', function (event, data) { | 990 | $rootScope.$on('usarTeclado', function (event, data) { |
973 | if (data) { | 991 | if (data) { |
974 | $scope.mostrarTeclado = true; | 992 | $scope.mostrarTeclado = true; |
975 | return; | 993 | return; |
976 | } | 994 | } |
977 | $scope.mostrarTeclado = false; | 995 | $scope.mostrarTeclado = false; |
978 | }); | 996 | }); |
979 | 997 | ||
980 | $scope.selectFocus = function ($event) { | 998 | $scope.selectFocus = function ($event) { |
981 | // Si el teclado esta en uso no selecciona el valor | 999 | // Si el teclado esta en uso no selecciona el valor |
982 | if ($scope.mostrarTeclado) { | 1000 | if ($scope.mostrarTeclado) { |
983 | return; | 1001 | return; |
984 | } | 1002 | } |
985 | $event.target.select(); | 1003 | $event.target.select(); |
986 | }; | 1004 | }; |
987 | 1005 | ||
988 | function addArrayCabecera(array) { | 1006 | function addArrayCabecera(array) { |
989 | for (var i = 0; i < array.length; i++) { | 1007 | for (var i = 0; i < array.length; i++) { |
990 | $scope.$broadcast('addCabecera', { | 1008 | $scope.$broadcast('addCabecera', { |
991 | label: array[i].label, | 1009 | label: array[i].label, |
992 | valor: array[i].valor | 1010 | valor: array[i].valor |
993 | }); | 1011 | }); |
994 | } | 1012 | } |
995 | } | 1013 | } |
996 | 1014 | ||
997 | function rellenar(relleno, longitud) { | 1015 | function rellenar(relleno, longitud) { |
998 | relleno = '' + relleno; | 1016 | relleno = '' + relleno; |
999 | while (relleno.length < longitud) { | 1017 | while (relleno.length < longitud) { |
1000 | relleno = '0' + relleno; | 1018 | relleno = '0' + relleno; |
1001 | } | 1019 | } |
1002 | return relleno; | 1020 | return relleno; |
1003 | } | 1021 | } |
1004 | 1022 | ||
1005 | function varlidarRemitoFacturado() { | 1023 | function varlidarRemitoFacturado() { |
1006 | if ($scope.remito.estado !== 5) { | 1024 | if ($scope.remito.estado !== 5) { |
1007 | return true; | 1025 | return true; |
1008 | } else { | 1026 | } else { |
1009 | focaModalService.alert('No se puede editar un remito facturado'); | 1027 | focaModalService.alert('No se puede editar un remito facturado'); |
1010 | return false(); | 1028 | return false(); |
1011 | } | 1029 | } |
1012 | } | 1030 | } |
1013 | 1031 | ||
1014 | function salir() { | 1032 | function salir() { |
1015 | var confirmacion = false; | 1033 | var confirmacion = false; |
1016 | 1034 | ||
1017 | if (!angular.equals($scope.remito, $scope.inicial)) { | 1035 | if (!angular.equals($scope.remito, $scope.inicial)) { |
1018 | confirmacion = true; | 1036 | confirmacion = true; |
1019 | } | 1037 | } |
1020 | 1038 | ||
1021 | if (confirmacion) { | 1039 | if (confirmacion) { |
1022 | focaModalService.confirm( | 1040 | focaModalService.confirm( |
1023 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 1041 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
1024 | ).then(function (data) { | 1042 | ).then(function (data) { |
1025 | if (data) { | 1043 | if (data) { |
1026 | $location.path('/'); | 1044 | $location.path('/'); |
1027 | } | 1045 | } |
1028 | }); | 1046 | }); |
1029 | } else { | 1047 | } else { |
1030 | $location.path('/'); | 1048 | $location.path('/'); |
1031 | } | 1049 | } |
1032 | } | 1050 | } |
1033 | 1051 | ||
1034 | function enableObservaciones(val) { | 1052 | function enableObservaciones(val) { |
1035 | var boton = $scope.botonera.filter(function (botonObs) { | 1053 | var boton = $scope.botonera.filter(function (botonObs) { |
1036 | return botonObs.label === 'Observaciones'; | 1054 | return botonObs.label === 'Observaciones'; |
1037 | }); | 1055 | }); |
1038 | boton[0].disable = !val; | 1056 | boton[0].disable = !val; |
1039 | } | 1057 | } |
1040 | 1058 | ||
1041 | function setearRemito(remito) { | 1059 | function setearRemito(remito) { |
1042 | //añado cabeceras | 1060 | //añado cabeceras |
1043 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 1061 | if (remito.estado !== 5 && remito.id) { |
1062 | |||
1063 | $scope.botonera.forEach(function(boton) { | ||
1064 | |||
1065 | if (boton.label === 'Eliminar Remito') { | ||
1066 | boton.disable = false; | ||
1067 | } | ||
1068 | }); | ||
1069 | } | ||
1070 | $scope.$broadcast('removeCabecera', 'Moneda:'); | ||
1044 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 1071 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); |
1045 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 1072 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); |
1046 | $scope.$broadcast('removeCabecera', 'Vendedor:'); | 1073 | $scope.$broadcast('removeCabecera', 'Vendedor:'); |
1047 | 1074 | ||
1048 | var cabeceras = []; | 1075 | var cabeceras = []; |
1049 | 1076 | ||
1050 | if (remito.cotizacion && remito.cotizacion.moneda.CODIGO_AFIP !== 'PES') { | 1077 | if (remito.cotizacion && remito.cotizacion.moneda.CODIGO_AFIP !== 'PES') { |
1051 | cabeceras.push({ | 1078 | cabeceras.push({ |
1052 | label: 'Moneda:', | 1079 | label: 'Moneda:', |
1053 | valor: remito.cotizacion.moneda.DETALLE | 1080 | valor: remito.cotizacion.moneda.DETALLE |
1054 | }); | 1081 | }); |
1055 | cabeceras.push({ | 1082 | cabeceras.push({ |
1056 | label: 'Fecha cotizacion:', | 1083 | label: 'Fecha cotizacion:', |
1057 | valor: $filter('date')(remito.cotizacion.FECHA, | 1084 | valor: $filter('date')(remito.cotizacion.FECHA, |
1058 | 'dd/MM/yyyy') | 1085 | 'dd/MM/yyyy') |
1059 | }); | 1086 | }); |
1060 | cabeceras.push({ | 1087 | cabeceras.push({ |
1061 | label: 'Cotizacion:', | 1088 | label: 'Cotizacion:', |
1062 | valor: $filter('number')(remito.cotizacion.VENDEDOR, | 1089 | valor: $filter('number')(remito.cotizacion.VENDEDOR, |
1063 | '2') | 1090 | '2') |
1064 | }); | 1091 | }); |
1065 | } | 1092 | } |
1066 | 1093 | ||
1067 | if (remito.cotizacion && remito.cotizacion.moneda) { | 1094 | if (remito.cotizacion && remito.cotizacion.moneda) { |
1068 | $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; | 1095 | $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; |
1069 | } | 1096 | } |
1070 | 1097 | ||
1071 | if (remito.cliente && remito.cliente.COD) { | 1098 | if (remito.cliente && remito.cliente.COD) { |
1072 | cabeceras.push({ | 1099 | cabeceras.push({ |
1073 | label: 'Cliente:', | 1100 | label: 'Cliente:', |
1074 | valor: $filter('rellenarDigitos')(remito.cliente.COD, 3) + ' - ' + | 1101 | valor: $filter('rellenarDigitos')(remito.cliente.COD, 3) + ' - ' + |
1075 | remito.cliente.NOM | 1102 | remito.cliente.NOM |
1076 | }); | 1103 | }); |
1077 | cabeceras.push({ | 1104 | cabeceras.push({ |
1078 | label: 'Domicilio:', | 1105 | label: 'Domicilio:', |
1079 | valor: remito.domicilioStamp | 1106 | valor: remito.domicilioStamp |
1080 | }); | 1107 | }); |
1081 | 1108 | ||
1082 | $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; | 1109 | $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; |
1083 | } | 1110 | } |
1084 | if (remito.vendedor && remito.vendedor.NUM) { | 1111 | if (remito.vendedor && remito.vendedor.NUM) { |
1085 | cabeceras.push({ | 1112 | cabeceras.push({ |
1086 | label: 'Vendedor:', | 1113 | label: 'Vendedor:', |
1087 | valor: $filter('rellenarDigitos')(remito.vendedor.NUM, 3) + | 1114 | valor: $filter('rellenarDigitos')(remito.vendedor.NUM, 3) + |
1088 | ' - ' + remito.vendedor.NOM | 1115 | ' - ' + remito.vendedor.NOM |
1089 | }); | 1116 | }); |
1090 | } | 1117 | } |
1091 | if (remito.proveedor && remito.proveedor.COD) { | 1118 | if (remito.proveedor && remito.proveedor.COD) { |
1092 | cabeceras.push({ | 1119 | cabeceras.push({ |
1093 | label: 'Proveedor:', | 1120 | label: 'Proveedor:', |
1094 | valor: $filter('rellenarDigitos')(remito.proveedor.COD, 5) + | 1121 | valor: $filter('rellenarDigitos')(remito.proveedor.COD, 5) + |
1095 | ' - ' + remito.proveedor.NOM | 1122 | ' - ' + remito.proveedor.NOM |
1096 | }); | 1123 | }); |
1097 | 1124 | ||
1098 | $filter('filter')($scope.botonera, { label: 'Proveedor' })[0].checked = true; | 1125 | $filter('filter')($scope.botonera, { label: 'Proveedor' })[0].checked = true; |
1099 | } | 1126 | } |
1100 | if (remito.flete !== undefined && remito.fob !== undefined) { | 1127 | if (remito.flete !== undefined && remito.fob !== undefined) { |
1101 | cabeceras.push({ | 1128 | cabeceras.push({ |
1102 | label: 'Flete:', | 1129 | label: 'Flete:', |
1103 | valor: remito.fob ? 'FOB' : ( | 1130 | valor: remito.fob ? 'FOB' : ( |
1104 | remito.flete ? 'Si' : 'No') | 1131 | remito.flete ? 'Si' : 'No') |
1105 | }); | 1132 | }); |
1106 | } | 1133 | } |
1107 | if (remito.remitoPlazo) { | 1134 | if (remito.remitoPlazo) { |
1108 | cabeceras.push({ | 1135 | cabeceras.push({ |
1109 | label: 'Precio condicion:', | 1136 | label: 'Precio condicion:', |
1110 | valor: valorPrecioCondicion() + ' ' + | 1137 | valor: valorPrecioCondicion() + ' ' + |
1111 | remitoBusinessService.plazoToString(remito.remitoPlazo) | 1138 | remitoBusinessService.plazoToString(remito.remitoPlazo) |
1112 | }); | 1139 | }); |
1113 | 1140 | ||
1114 | $filter('filter')($scope.botonera, | 1141 | $filter('filter')($scope.botonera, |
1115 | { label: 'Precios y condiciones' })[0].checked = true; | 1142 | { label: 'Precios y condiciones' })[0].checked = true; |
1116 | } | 1143 | } |
1117 | function valorPrecioCondicion() { | 1144 | function valorPrecioCondicion() { |
1118 | if (remito.idPrecioCondicion > 0) { | 1145 | if (remito.idPrecioCondicion > 0) { |
1119 | return remito.precioCondicion.nombre; | 1146 | return remito.precioCondicion.nombre; |
1120 | } else { | 1147 | } else { |
1121 | return 'Ingreso Manual'; | 1148 | return 'Ingreso Manual'; |
1122 | } | 1149 | } |
1123 | } | 1150 | } |
1124 | if (remito.flete === 1) { | 1151 | if (remito.flete === 1) { |
1125 | var cabeceraBomba = { | 1152 | var cabeceraBomba = { |
1126 | label: 'Bomba', | 1153 | label: 'Bomba', |
1127 | valor: remito.bomba === 1 ? 'Si' : 'No' | 1154 | valor: remito.bomba === 1 ? 'Si' : 'No' |
1128 | }; | 1155 | }; |
1129 | if (remito.kilometros) { | 1156 | if (remito.kilometros) { |
1130 | var cabeceraKilometros = { | 1157 | var cabeceraKilometros = { |
1131 | label: 'Kilometros', | 1158 | label: 'Kilometros', |
1132 | valor: remito.kilometros | 1159 | valor: remito.kilometros |
1133 | }; | 1160 | }; |
1134 | cabeceras.push(cabeceraKilometros); | 1161 | cabeceras.push(cabeceraKilometros); |
1135 | } | 1162 | } |
1136 | cabeceras.push(cabeceraBomba); | 1163 | cabeceras.push(cabeceraBomba); |
1137 | } | 1164 | } |
1138 | 1165 | ||
1139 | if (remito.idPrecioCondicion > 0) { | 1166 | if (remito.idPrecioCondicion > 0) { |
1140 | $scope.idLista = remito.precioCondicion.idListaPrecio; | 1167 | $scope.idLista = remito.precioCondicion.idListaPrecio; |
1141 | } else if (remito.idPrecioCondicion) { | 1168 | } else if (remito.idPrecioCondicion) { |
1142 | $scope.idLista = -1; | 1169 | $scope.idLista = -1; |
1143 | } | 1170 | } |
1144 | $scope.puntoVenta = rellenar(remito.sucursal, 4); | 1171 | $scope.puntoVenta = rellenar(remito.sucursal, 4); |
1145 | $scope.comprobante = rellenar(remito.numeroRemito, 8); | 1172 | $scope.comprobante = rellenar(remito.numeroRemito, 8); |
1146 | $scope.remito = remito; | 1173 | $scope.remito = remito; |
1147 | if ($scope.remito.remitoPuntoDescarga.length) { | 1174 | if ($scope.remito.remitoPuntoDescarga.length) { |
1148 | var puntoDescarga = []; | 1175 | var puntoDescarga = []; |
1149 | 1176 | ||
1150 | $scope.remito.remitoPuntoDescarga.forEach(function (remitoPuntoDescarga) { | 1177 | $scope.remito.remitoPuntoDescarga.forEach(function (remitoPuntoDescarga) { |
1151 | puntoDescarga.push(remitoPuntoDescarga.puntoDescarga); | 1178 | puntoDescarga.push(remitoPuntoDescarga.puntoDescarga); |
1152 | }); | 1179 | }); |
1153 | 1180 | ||
1154 | cabeceras.push({ | 1181 | cabeceras.push({ |
1155 | label: 'Puntos de descarga: ', | 1182 | label: 'Puntos de descarga: ', |
1156 | valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntoDescarga)) | 1183 | valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntoDescarga)) |
1157 | }); | 1184 | }); |
1158 | } | 1185 | } |
1159 | $scope.remitoIsDirty = false; | 1186 | $scope.remitoIsDirty = false; |
1160 | 1187 | ||
1161 | if (remito.articulosRemito && $scope.remito.articulosRemito.length) { | 1188 | if (remito.articulosRemito && $scope.remito.articulosRemito.length) { |
1162 | $scope.remito.articulosRemito.forEach(function (articulo) { | 1189 | $scope.remito.articulosRemito.forEach(function (articulo) { |
1163 | articulo.precio = | 1190 | articulo.precio = |
1164 | (articulo.precio / $scope.remito.cotizacion.VENDEDOR).toFixed(4); | 1191 | (articulo.precio / $scope.remito.cotizacion.VENDEDOR).toFixed(4); |
1165 | }); | 1192 | }); |
1166 | } | 1193 | } |
1167 | 1194 | ||
1168 | addArrayCabecera(cabeceras); | 1195 | addArrayCabecera(cabeceras); |
1169 | } | 1196 | } |
1170 | 1197 | ||
1171 | function getLSRemito() { | 1198 | function getLSRemito() { |
1172 | var remito = JSON.parse($localStorage.remito || null); | 1199 | var remito = JSON.parse($localStorage.remito || null); |
1173 | if (remito) { | 1200 | if (remito) { |
1174 | setearRemito(remito); | 1201 | setearRemito(remito); |
1175 | delete $localStorage.remito; | 1202 | delete $localStorage.remito; |
1176 | } | 1203 | } |
1177 | } | 1204 | } |
1178 | 1205 | ||
1179 | function getCabeceraPuntoDescarga(puntosDescarga) { | 1206 | function getCabeceraPuntoDescarga(puntosDescarga) { |
1180 | var puntosStamp = ''; | 1207 | var puntosStamp = ''; |
1181 | puntosDescarga.forEach(function (punto, idx, arr) { | 1208 | puntosDescarga.forEach(function (punto, idx, arr) { |
1182 | puntosStamp += punto.descripcion; | 1209 | puntosStamp += punto.descripcion; |
1183 | if ((idx + 1) !== arr.length) puntosStamp += ', '; | 1210 | if ((idx + 1) !== arr.length) puntosStamp += ', '; |
1184 | }); | 1211 | }); |
1185 | return puntosStamp; | 1212 | return puntosStamp; |
1186 | } | 1213 | } |
1187 | 1214 | ||
1188 | function abrirModalMail(id, cliente, numeroRemito) { | 1215 | function abrirModalMail(id, cliente, numeroRemito) { |
1189 | focaModalService.mail( | 1216 | focaModalService.mail( |
1190 | { | 1217 | { |
1191 | titulo: 'Comprobante de remito Nº ' + numeroRemito, | 1218 | titulo: 'Comprobante de remito Nº ' + numeroRemito, |
1192 | descarga: { | 1219 | descarga: { |
1193 | nombre: numeroRemito + '.pdf', | 1220 | nombre: numeroRemito + '.pdf', |
1194 | url: '/remito/comprobante', | 1221 | url: '/remito/comprobante', |
1195 | }, | 1222 | }, |
1196 | envio: { | 1223 | envio: { |
1197 | mailCliente: cliente.MAIL, | 1224 | mailCliente: cliente.MAIL, |
1198 | url: '/remito/mail', | 1225 | url: '/remito/mail', |
1199 | }, | 1226 | }, |
1200 | options: { | 1227 | options: { |
1201 | idRemito: id | 1228 | idRemito: id |
1202 | } | 1229 | } |
1203 | } | 1230 | } |
1204 | ) | 1231 | ) |
1205 | .then(function (res) { | 1232 | .then(function (res) { |
1206 | if (res === false) { | 1233 | if (res === false) { |
1207 | abrirModalMail(id); | 1234 | abrirModalMail(id); |
1208 | focaModalService.alert('Descarga o envíe su remito ' + | 1235 | focaModalService.alert('Descarga o envíe su remito ' + |
1209 | 'antes de cerrar esta ventana'); | 1236 | 'antes de cerrar esta ventana'); |
1210 | } | 1237 | } |
1211 | }); | 1238 | }); |
1212 | } | 1239 | } |
1213 | //recibo la propiedad por la cual quiero obtener el valor | 1240 | //recibo la propiedad por la cual quiero obtener el valor |
1214 | function getImporte(propiedad) { | 1241 | function getImporte(propiedad) { |
1215 | var importe = 0; | 1242 | var importe = 0; |
1216 | 1243 | ||
1217 | $scope.articulosFiltro().forEach(function (articulo) { | 1244 | $scope.articulosFiltro().forEach(function (articulo) { |
1218 | 1245 | ||
1219 | if (articulo[propiedad]) { | 1246 | if (articulo[propiedad]) { |
1220 | importe += articulo[propiedad] * articulo.cantidad; | 1247 | importe += articulo[propiedad] * articulo.cantidad; |
1221 | } | 1248 | } |
1222 | return; | 1249 | return; |
1223 | 1250 | ||
1224 | }); | 1251 | }); |
1225 | 1252 | ||
1226 | return importe; | 1253 | return importe; |
1227 | } | 1254 | } |
1228 | } | 1255 | } |
1229 | ]); | 1256 | ]); |
1230 | 1257 |
src/js/service.js
1 | angular.module('focaCrearRemito') | 1 | angular.module('focaCrearRemito') |
2 | .service('crearRemitoService', ['$http', 'API_ENDPOINT', | 2 | .service('crearRemitoService', ['$http', 'API_ENDPOINT', |
3 | function($http, API_ENDPOINT) { | 3 | function($http, API_ENDPOINT) { |
4 | var route = API_ENDPOINT.URL; | 4 | var route = API_ENDPOINT.URL; |
5 | return { | 5 | return { |
6 | getVendedorById: function (idVendedor) { | 6 | getVendedorById: function (idVendedor) { |
7 | return $http.get(route + '/vendedor-cobrador/' + idVendedor); | 7 | return $http.get(route + '/vendedor-cobrador/' + idVendedor); |
8 | }, | 8 | }, |
9 | crearRemito: function(remito) { | 9 | crearRemito: function(remito) { |
10 | // TODO: Cambiar para usar el servicio /remito | 10 | // TODO: Cambiar para usar el servicio /remito |
11 | return $http.post(route + '/remito', remito); | 11 | return $http.post(route + '/remito', remito); |
12 | }, | 12 | }, |
13 | getRemitoById: function(id) { | 13 | getRemitoById: function(id) { |
14 | return $http.get(route + '/remito/obtener/' + id); | 14 | return $http.get(route + '/remito/obtener/' + id); |
15 | }, | 15 | }, |
16 | obtenerRemito: function() { | 16 | obtenerRemito: function() { |
17 | return $http.get(route +'/nota-pedido'); | 17 | return $http.get(route +'/nota-pedido'); |
18 | }, | 18 | }, |
19 | setRemito: function(remito) { | 19 | setRemito: function(remito) { |
20 | this.remito = remito; | 20 | this.remito = remito; |
21 | }, | 21 | }, |
22 | clearRemito: function() { | 22 | clearRemito: function() { |
23 | this.remito = undefined; | 23 | this.remito = undefined; |
24 | }, | 24 | }, |
25 | getRemito: function() { | 25 | getRemito: function() { |
26 | return this.remito; | 26 | return this.remito; |
27 | }, | 27 | }, |
28 | getArticulosByIdRemito: function(id) { | 28 | getArticulosByIdRemito: function(id) { |
29 | return $http.get(route+'/articulos/nota-pedido/'+id); | 29 | return $http.get(route+'/articulos/nota-pedido/'+id); |
30 | }, | 30 | }, |
31 | crearArticulosParaRemito: function(articuloRemito) { | 31 | crearArticulosParaRemito: function(articuloRemito) { |
32 | return $http.post(route + '/articulos/remito', | 32 | return $http.post(route + '/articulos/remito', |
33 | {articuloRemito: articuloRemito}); | 33 | {articuloRemito: articuloRemito}); |
34 | }, | 34 | }, |
35 | getProveedorById: function(id) { | 35 | getProveedorById: function(id) { |
36 | return $http.get(API_ENDPOINT.URL + '/proveedor/' + id); | 36 | return $http.get(API_ENDPOINT.URL + '/proveedor/' + id); |
37 | }, | 37 | }, |
38 | getDomiciliosByIdRemito: function(id) { | 38 | getDomiciliosByIdRemito: function(id) { |
39 | return $http.get(route +'/nota-pedido/'+id+'/domicilios'); | 39 | return $http.get(route +'/nota-pedido/'+id+'/domicilios'); |
40 | }, | 40 | }, |
41 | getDomiciliosByIdCliente: function(id) { | 41 | getDomiciliosByIdCliente: function(id) { |
42 | var idTipoEntrega = 2;//Solo traigo los domicilios que tienen tipo 2 (tipo entrega) | 42 | var idTipoEntrega = 2;//Solo traigo los domicilios que tienen tipo 2 (tipo entrega) |
43 | return $http.get(route + '/domicilio/tipo/' + idTipoEntrega + '/cliente/' + id ); | 43 | return $http.get(route + '/domicilio/tipo/' + idTipoEntrega + '/cliente/' + id ); |
44 | }, | 44 | }, |
45 | getPrecioCondicion: function() { | 45 | getPrecioCondicion: function() { |
46 | return $http.get(route + '/precio-condicion'); | 46 | return $http.get(route + '/precio-condicion'); |
47 | }, | 47 | }, |
48 | getPrecioCondicionById: function(id) { | 48 | getPrecioCondicionById: function(id) { |
49 | return $http.get(route + '/precio-condicion/' + id); | 49 | return $http.get(route + '/precio-condicion/' + id); |
50 | }, | 50 | }, |
51 | getPlazoPagoByPrecioCondicion: function(id) { | 51 | getPlazoPagoByPrecioCondicion: function(id) { |
52 | return $http.get(route + '/plazo-pago/precio-condicion/'+ id); | 52 | return $http.get(route + '/plazo-pago/precio-condicion/'+ id); |
53 | }, | 53 | }, |
54 | crearFlete: function(flete) { | 54 | crearFlete: function(flete) { |
55 | return $http.post(route + '/flete', {flete : flete}); | 55 | return $http.post(route + '/flete', {flete : flete}); |
56 | }, | 56 | }, |
57 | crearPlazosParaRemito: function(plazos) { | 57 | crearPlazosParaRemito: function(plazos) { |
58 | return $http.post(route + '/plazo-pago/remito', plazos); | 58 | return $http.post(route + '/plazo-pago/remito', plazos); |
59 | }, | 59 | }, |
60 | getCotizacionByIdMoneda: function(id) { | 60 | getCotizacionByIdMoneda: function(id) { |
61 | return $http.get(route + '/moneda/' + id); | 61 | return $http.get(route + '/moneda/' + id); |
62 | }, | 62 | }, |
63 | crearEstadoParaRemito: function(estado) { | 63 | crearEstadoParaRemito: function(estado) { |
64 | return $http.post(route + '/estado', {estado: estado}); | 64 | return $http.post(route + '/estado', {estado: estado}); |
65 | }, | 65 | }, |
66 | getNumeroRemito: function() { | 66 | getNumeroRemito: function() { |
67 | return $http.get(route + '/remito/numero-siguiente'); | 67 | return $http.get(route + '/remito/numero-siguiente'); |
68 | }, | 68 | }, |
69 | imprimirRemitoByIdRemito: function(idRemito) { | 69 | imprimirRemitoByIdRemito: function(idRemito) { |
70 | return $http.get(route + '/remito/comprobante/' + idRemito , { | 70 | return $http.get(route + '/remito/comprobante/' + idRemito , { |
71 | responseType: 'arraybuffer' | 71 | responseType: 'arraybuffer' |
72 | }); | 72 | }); |
73 | }, | 73 | }, |
74 | getPuntosDescargaByClienDom: function(idDomicilio, idCliente) { | 74 | getPuntosDescargaByClienDom: function(idDomicilio, idCliente) { |
75 | return $http.get(API_ENDPOINT.URL + '/punto-descarga/' + | 75 | return $http.get(API_ENDPOINT.URL + '/punto-descarga/' + |
76 | idDomicilio + '/' + idCliente); | 76 | idDomicilio + '/' + idCliente); |
77 | }, | 77 | }, |
78 | enviarCorreo: function(options) { | 78 | enviarCorreo: function(options) { |
79 | return $http.post(API_ENDPOINT.URL + '/remito/mail', options); | 79 | return $http.post(API_ENDPOINT.URL + '/remito/mail', options); |
80 | }, | 80 | }, |
81 | getParametros: function() { | 81 | getParametros: function() { |
82 | return $http.get(API_ENDPOINT.URL + '/parametros/remito'); | 82 | return $http.get(API_ENDPOINT.URL + '/parametros/remito'); |
83 | }, | 83 | }, |
84 | crearPuntosDescarga: function(puntosDescarga) { | 84 | crearPuntosDescarga: function(puntosDescarga) { |
85 | return $http.post(route + '/puntos-descarga/remito', | 85 | return $http.post(route + '/puntos-descarga/remito', |
86 | {puntosDescarga: puntosDescarga}); | 86 | {puntosDescarga: puntosDescarga}); |
87 | }, | 87 | }, |
88 | getBotonera: function() { | 88 | getBotonera: function() { |
89 | return [ | 89 | return [ |
90 | { | 90 | { |
91 | label: 'Nota pedido', | 91 | label: 'Nota pedido', |
92 | image: 'notaDePedido.png' | 92 | image: 'notaDePedido.png' |
93 | }, | 93 | }, |
94 | { | 94 | { |
95 | label: 'Cliente', | 95 | label: 'Cliente', |
96 | image: 'cliente.png' | 96 | image: 'cliente.png' |
97 | }, | 97 | }, |
98 | { | 98 | { |
99 | label: 'Proveedor', | 99 | label: 'Proveedor', |
100 | image: 'proveedor.png' | 100 | image: 'proveedor.png' |
101 | }, | 101 | }, |
102 | { | 102 | { |
103 | label: 'Moneda', | 103 | label: 'Moneda', |
104 | image: 'moneda.png' | 104 | image: 'moneda.png' |
105 | }, | 105 | }, |
106 | { | 106 | { |
107 | label: 'Precios y condiciones', | 107 | label: 'Precios y condiciones', |
108 | image: 'precios-condiciones.png' | 108 | image: 'precios-condiciones.png' |
109 | }, | 109 | }, |
110 | { | 110 | { |
111 | label: 'Productos', | 111 | label: 'Productos', |
112 | image: 'productos.png' | 112 | image: 'productos.png' |
113 | }, | 113 | }, |
114 | { | 114 | { |
115 | label: 'Observaciones', | 115 | label: 'Observaciones', |
116 | image: 'botonObservaciones.png', | 116 | image: 'botonObservaciones.png', |
117 | disable: true | 117 | disable: true |
118 | }, | ||
119 | { | ||
120 | label: 'Eliminar Remito', | ||
121 | image: 'eliminarRemito.png', | ||
122 | disable: true | ||
118 | } | 123 | } |
119 | ]; | 124 | ]; |
125 | }, | ||
126 | eliminarRemito: function (remito) { | ||
127 | return $http.post(API_ENDPOINT.URL + '/remito/update', {remito: remito}); | ||
120 | } | 128 | } |
121 | }; | 129 | }; |
122 | }]); | 130 | }]); |
123 | 131 |