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