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