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