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