Commit 558186a93fc1c31c6bbed20132f6acb23300494d
1 parent
844727754c
Exists in
master
Agregado modal de estado de cuenta.
Showing
5 changed files
with
261 additions
and
89 deletions
 
Show diff stats
src/js/controller.js
| 1 | angular.module('focaCrearFactura').controller('facturaController', [ | 1 | angular.module('focaCrearFactura').controller('facturaController', [ | 
| 2 | '$scope', '$uibModal', '$location', '$filter', 'crearFacturaService', '$timeout', | 2 | '$scope', '$uibModal', '$location', '$filter', 'crearFacturaService', '$timeout', | 
| 3 | 'focaModalService', 'crearRemitoService', '$rootScope', 'focaBotoneraLateralService', | 3 | 'focaModalService', 'crearRemitoService', '$rootScope', 'focaBotoneraLateralService', | 
| 4 | '$localStorage', | 4 | '$localStorage', 'APP', | 
| 5 | function ( | 5 | function ( | 
| 6 | $scope, $uibModal, $location, $filter, crearFacturaService, $timeout, focaModalService, | 6 | $scope, $uibModal, $location, $filter, crearFacturaService, $timeout, focaModalService, | 
| 7 | crearRemitoService, $rootScope, focaBotoneraLateralService, $localStorage) { | 7 | crearRemitoService, $rootScope, focaBotoneraLateralService, $localStorage, APP) { | 
| 8 | 8 | ||
| 9 | config(); | 9 | config(); | 
| 10 | 10 | ||
| 11 | function config() { | 11 | function config() { | 
| 12 | $scope.tmpCantidad = Number; | 12 | $scope.tmpCantidad = Number; | 
| 13 | $scope.tmpPrecio = Number; | 13 | $scope.tmpPrecio = Number; | 
| 14 | $scope.botonera = crearFacturaService.getBotonera(); | 14 | $scope.botonera = crearFacturaService.getBotonera(); | 
| 15 | $scope.isNumber = angular.isNumber; | 15 | $scope.isNumber = angular.isNumber; | 
| 16 | $scope.datepickerAbierto = false; | 16 | $scope.datepickerAbierto = false; | 
| 17 | $scope.show = false; | 17 | $scope.show = false; | 
| 18 | $scope.cargando = true; | 18 | $scope.cargando = true; | 
| 19 | $scope.now = new Date(); | 19 | $scope.now = new Date(); | 
| 20 | $scope.puntoVenta = rellenar(0, 4); | 20 | $scope.puntoVenta = rellenar(0, 4); | 
| 21 | $scope.comprobante = rellenar(0, 8); | 21 | $scope.comprobante = rellenar(0, 8); | 
| 22 | $scope.dateOptions = { | 22 | $scope.dateOptions = { | 
| 23 | maxDate: new Date(), | 23 | maxDate: new Date(), | 
| 24 | minDate: new Date(2010, 0, 1) | 24 | minDate: new Date(2010, 0, 1) | 
| 25 | }; | 25 | }; | 
| 26 | $scope.cabeceras = []; | 26 | $scope.cabeceras = []; | 
| 27 | crearFacturaService.getParametros().then(function (res) { | 27 | crearFacturaService.getParametros().then(function (res) { | 
| 28 | 28 | ||
| 29 | var parametros = JSON.parse(res.data[0].jsonText); | 29 | var parametros = JSON.parse(res.data[0].jsonText); | 
| 30 | 30 | ||
| 31 | if ($localStorage.factura) { | 31 | if ($localStorage.factura) { | 
| 32 | 32 | ||
| 33 | $timeout(function () { getLSFactura(); }); | 33 | $timeout(function () { getLSFactura(); }); | 
| 34 | } else { | 34 | } else { | 
| 35 | 35 | ||
| 36 | for (var property in parametros) { | 36 | for (var property in parametros) { | 
| 37 | $scope.factura[property] = parametros[property]; | 37 | $scope.factura[property] = parametros[property]; | 
| 38 | $scope.inicial[property] = parametros[property]; | 38 | $scope.inicial[property] = parametros[property]; | 
| 39 | } | 39 | } | 
| 40 | 40 | ||
| 41 | setearFactura($scope.factura); | 41 | setearFactura($scope.factura); | 
| 42 | } | 42 | } | 
| 43 | 43 | ||
| 44 | }); | 44 | }); | 
| 45 | 45 | ||
| 46 | //SETEO BOTONERA LATERAL | 46 | //SETEO BOTONERA LATERAL | 
| 47 | $timeout(function () { | 47 | $timeout(function () { | 
| 48 | focaBotoneraLateralService.showSalir(false); | 48 | focaBotoneraLateralService.showSalir(false); | 
| 49 | focaBotoneraLateralService.showPausar(true); | 49 | focaBotoneraLateralService.showPausar(true); | 
| 50 | focaBotoneraLateralService.showGuardar(true, $scope.seleccionarFormaDePago); | 50 | focaBotoneraLateralService.showGuardar(true, $scope.seleccionarFormaDePago); | 
| 51 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 51 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 
| 52 | }); | 52 | }); | 
| 53 | 53 | ||
| 54 | init(); | 54 | init(); | 
| 55 | 55 | ||
| 56 | } | 56 | } | 
| 57 | 57 | ||
| 58 | function init() { | 58 | function init() { | 
| 59 | 59 | ||
| 60 | $scope.$broadcast('cleanCabecera'); | 60 | $scope.$broadcast('cleanCabecera'); | 
| 61 | 61 | ||
| 62 | $scope.factura = { | 62 | $scope.factura = { | 
| 63 | id: 0, | 63 | id: 0, | 
| 64 | estado: 0, | 64 | estado: 0, | 
| 65 | vendedor: {}, | 65 | vendedor: {}, | 
| 66 | cliente: {}, | 66 | cliente: {}, | 
| 67 | proveedor: {}, | 67 | proveedor: {}, | 
| 68 | domicilio: { dom: '' }, | 68 | domicilio: { dom: '' }, | 
| 69 | moneda: {}, | 69 | moneda: {}, | 
| 70 | cotizacion: $scope.cotizacionPorDefecto || {}, | 70 | cotizacion: $scope.cotizacionPorDefecto || {}, | 
| 71 | articulosFactura: [], | 71 | articulosFactura: [], | 
| 72 | despachos: [] | 72 | despachos: [] | 
| 73 | }; | 73 | }; | 
| 74 | 74 | ||
| 75 | $scope.factura.articulosFactura = []; | 75 | $scope.factura.articulosFactura = []; | 
| 76 | $scope.idLista = undefined; | 76 | $scope.idLista = undefined; | 
| 77 | 77 | ||
| 78 | crearRemitoService.getNumeroRemito().then( | 78 | crearRemitoService.getNumeroRemito().then( | 
| 79 | function (res) { | 79 | function (res) { | 
| 80 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); | 80 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); | 
| 81 | $scope.comprobante = rellenar(res.data.numeroRemito, 8); | 81 | $scope.comprobante = rellenar(res.data.numeroRemito, 8); | 
| 82 | }, | 82 | }, | 
| 83 | function (err) { | 83 | function (err) { | 
| 84 | focaModalService.alert('La terminal no esta configurada correctamente'); | 84 | focaModalService.alert('La terminal no esta configurada correctamente'); | 
| 85 | console.info(err); | 85 | console.info(err); | 
| 86 | } | 86 | } | 
| 87 | ); | 87 | ); | 
| 88 | 88 | ||
| 89 | $scope.inicial = angular.copy($scope.factura); | 89 | $scope.inicial = angular.copy($scope.factura); | 
| 90 | if (APP === 'facturador') { | ||
| 91 | var modalInstance = $uibModal.open( | ||
| 92 | { | ||
| 93 | templateUrl: 'modal-estado-cuenta.html', | ||
| 94 | controller: 'focaModalEstadoCuentaController', | ||
| 95 | size: 'lg' | ||
| 96 | } | ||
| 97 | ); | ||
| 98 | modalInstance.result | ||
| 99 | .then(function (data) { | ||
| 100 | $scope.$broadcast('addCabecera', { | ||
| 101 | label: 'Tipo de pago: ', | ||
| 102 | valor: data | ||
| 103 | }); | ||
| 104 | }) | ||
| 105 | .catch(function (e) { console.error(e); }); | ||
| 106 | } | ||
| 90 | } | 107 | } | 
| 91 | 108 | ||
| 92 | $scope.$watch('factura', function (newValue) { | 109 | $scope.$watch('factura', function (newValue) { | 
| 93 | focaBotoneraLateralService.setPausarData({ | 110 | focaBotoneraLateralService.setPausarData({ | 
| 94 | label: 'factura', | 111 | label: 'factura', | 
| 95 | val: newValue | 112 | val: newValue | 
| 96 | }); | 113 | }); | 
| 97 | }, true); | 114 | }, true); | 
| 98 | 115 | ||
| 99 | $scope.seleccionarFormaDePago = function () { | 116 | $scope.seleccionarFormaDePago = function () { | 
| 100 | if (!validarGuardar()) return; | 117 | if (!validarGuardar()) return; | 
| 101 | var modalInstance = $uibModal.open( | 118 | var modalInstance = $uibModal.open( | 
| 102 | { | 119 | { | 
| 103 | templateUrl: 'modal-forma-pago.html', | 120 | templateUrl: 'modal-forma-pago.html', | 
| 104 | controller: 'focaModalFormaPagoController', | 121 | controller: 'focaModalFormaPagoController', | 
| 105 | resolve: { | 122 | resolve: { | 
| 106 | filters: function () { return null; }, | 123 | filters: function () { return null; }, | 
| 107 | }, | 124 | }, | 
| 108 | size: 'lg', | 125 | size: 'lg', | 
| 109 | } | 126 | } | 
| 110 | ); | 127 | ); | 
| 111 | modalInstance.result | 128 | modalInstance.result | 
| 112 | .then(function (data) { | 129 | .then(function (data) { | 
| 113 | console.log(data); | 130 | console.log(data); | 
| 114 | $scope.crearFactura(); | 131 | $scope.crearFactura(); | 
| 115 | }) | 132 | }) | 
| 116 | .catch(function (e) { console.error(e); }); | 133 | .catch(function (e) { console.error(e); }); | 
| 117 | }; | 134 | }; | 
| 118 | 135 | ||
| 119 | $scope.crearFactura = function () { | 136 | $scope.crearFactura = function () { | 
| 120 | 137 | ||
| 121 | var save = { | 138 | var save = { | 
| 122 | factura: { | 139 | factura: { | 
| 123 | 140 | ||
| 124 | BONIF: 0, | 141 | BONIF: 0, | 
| 125 | CLI: $scope.factura.cliente.cod, | 142 | CLI: $scope.factura.cliente.cod, | 
| 126 | CUI: $scope.factura.cliente.cuit, | 143 | CUI: $scope.factura.cliente.cuit, | 
| 127 | CTA: $scope.factura.cliente.cod, | 144 | CTA: $scope.factura.cliente.cod, | 
| 128 | DC1: '', | 145 | DC1: '', | 
| 129 | DC2: '', | 146 | DC2: '', | 
| 130 | DE1: '', | 147 | DE1: '', | 
| 131 | DOM: $scope.factura.cliente.DOM, | 148 | DOM: $scope.factura.cliente.DOM, | 
| 132 | FACAUT: 0, | 149 | FACAUT: 0, | 
| 133 | DTO: 0, | 150 | DTO: 0, | 
| 134 | FEC: $filter('date')($scope.now, 'yyyy-MM-dd HH:mm:ss'), | 151 | FEC: $filter('date')($scope.now, 'yyyy-MM-dd HH:mm:ss'), | 
| 135 | FEC_ANT: '19000101', | 152 | FEC_ANT: '19000101', | 
| 136 | FPA: 0, // 0 <- Múltiple formas de pago, 2 cta corriente | 153 | FPA: 0, // 0 <- Múltiple formas de pago, 2 cta corriente | 
| 137 | IDEXCEPCION: 0, | 154 | IDEXCEPCION: 0, | 
| 138 | IDLP: $scope.factura.cliente.mod.trim() || 0, | 155 | IDLP: $scope.factura.cliente.mod.trim() || 0, | 
| 139 | IDPERSONERIA: 0, | 156 | IDPERSONERIA: 0, | 
| 140 | IMI: 0, // TODO | 157 | IMI: 0, // TODO | 
| 141 | IMI2: 0, // TODO | 158 | IMI2: 0, // TODO | 
| 142 | IMI3: 0, // TODO | 159 | IMI3: 0, // TODO | 
| 143 | IMP_LEY: 0, | 160 | IMP_LEY: 0, | 
| 144 | IRI: 0, // TODO | 161 | IRI: 0, // TODO | 
| 145 | IRS: 0, | 162 | IRS: 0, | 
| 146 | LEG: '', | 163 | LEG: '', | 
| 147 | LUG: $scope.factura.vendedor.LugVen, | 164 | LUG: $scope.factura.vendedor.LugVen, | 
| 148 | MK_M: 0, | 165 | MK_M: 0, | 
| 149 | NEE: 0, // TODO | 166 | NEE: 0, // TODO | 
| 150 | NET: 0, // TODO | 167 | NET: 0, // TODO | 
| 151 | NFI: '', | 168 | NFI: '', | 
| 152 | NNP: 0, | 169 | NNP: 0, | 
| 153 | NOM: $scope.factura.cliente.nom, | 170 | NOM: $scope.factura.cliente.nom, | 
| 154 | OPE: $scope.factura.vendedor.CodVen, | 171 | OPE: $scope.factura.vendedor.CodVen, | 
| 155 | PAG: $scope.getTotal(), | 172 | PAG: $scope.getTotal(), | 
| 156 | PER: 0, | 173 | PER: 0, | 
| 157 | PER_IVA: 0, | 174 | PER_IVA: 0, | 
| 158 | PLA: $scope.factura.vendedor.NplVen, | 175 | PLA: $scope.factura.vendedor.NplVen, | 
| 159 | PRO: '', | 176 | PRO: '', | 
| 160 | REC_ANT: 0, | 177 | REC_ANT: 0, | 
| 161 | SUC: parseInt($scope.puntoVenta), | 178 | SUC: parseInt($scope.puntoVenta), | 
| 162 | TCA: 1, | 179 | TCA: 1, | 
| 163 | TCO: 'FT', | 180 | TCO: 'FT', | 
| 164 | TFI: '', | 181 | TFI: '', | 
| 165 | TIP: $scope.factura.cliente.tipoFactura, | 182 | TIP: $scope.factura.cliente.tipoFactura, | 
| 166 | TIV: 0, // TODO | 183 | TIV: 0, // TODO | 
| 167 | TOT: $scope.getTotal(), | 184 | TOT: $scope.getTotal(), | 
| 168 | TUR: 0, // TODO | 185 | TUR: 0, // TODO | 
| 169 | VEN: $scope.factura.vendedor.CodVen, | 186 | VEN: $scope.factura.vendedor.CodVen, | 
| 170 | VTO_CLI: '', | 187 | VTO_CLI: '', | 
| 171 | ZON: 1, // TODO | 188 | ZON: 1, // TODO | 
| 172 | OBSERVACIONES: $scope.factura.observaciones | 189 | OBSERVACIONES: $scope.factura.observaciones | 
| 173 | }, | 190 | }, | 
| 174 | cuerpo: $scope.articulosFiltro(), | 191 | cuerpo: $scope.articulosFiltro(), | 
| 175 | despachos: $scope.factura.despachos | 192 | despachos: $scope.factura.despachos | 
| 176 | }; | 193 | }; | 
| 177 | 194 | ||
| 178 | crearFacturaService.guardarFactura(save).then(function(res) { | 195 | crearFacturaService.guardarFactura(save).then(function (res) { | 
| 179 | 196 | ||
| 180 | focaBotoneraLateralService.endGuardar(true); | 197 | focaBotoneraLateralService.endGuardar(true); | 
| 181 | 198 | ||
| 182 | focaModalService.alert('Comprobante guardado con éxito'); | 199 | focaModalService.alert('Comprobante guardado con éxito'); | 
| 183 | 200 | ||
| 184 | config(); | 201 | config(); | 
| 185 | 202 | ||
| 186 | }).catch(function(err) { | 203 | }).catch(function (err) { | 
| 187 | focaModalService.alert('Hubo un error al guardar la factura'); | 204 | focaModalService.alert('Hubo un error al guardar la factura'); | 
| 188 | console.log(err); | 205 | console.log(err); | 
| 189 | }); | 206 | }); | 
| 190 | 207 | ||
| 191 | }; | 208 | }; | 
| 192 | 209 | ||
| 193 | $scope.seleccionarCliente = function () { | 210 | $scope.seleccionarCliente = function () { | 
| 194 | 211 | ||
| 195 | var modalInstance = $uibModal.open( | 212 | var modalInstance = $uibModal.open( | 
| 196 | { | 213 | { | 
| 197 | ariaLabelledBy: 'Busqueda de Cliente', | 214 | ariaLabelledBy: 'Busqueda de Cliente', | 
| 198 | templateUrl: 'foca-busqueda-cliente-modal.html', | 215 | templateUrl: 'foca-busqueda-cliente-modal.html', | 
| 199 | controller: 'focaBusquedaClienteModalController', | 216 | controller: 'focaBusquedaClienteModalController', | 
| 200 | resolve: { | 217 | resolve: { | 
| 201 | vendedor: function () { return null; }, | 218 | vendedor: function () { return null; }, | 
| 202 | cobrador: function () { return null; } | 219 | cobrador: function () { return null; } | 
| 203 | }, | 220 | }, | 
| 204 | size: 'lg' | 221 | size: 'lg' | 
| 205 | } | 222 | } | 
| 206 | ); | 223 | ); | 
| 207 | modalInstance.result.then( | 224 | modalInstance.result.then( | 
| 208 | function (cliente) { | 225 | function (cliente) { | 
| 209 | $scope.factura.cliente = cliente; | 226 | var modalInstance = $uibModal.open( | 
| 227 | { | ||
| 228 | templateUrl: 'modal-estado-cuenta.html', | ||
| 229 | controller: 'focaModalEstadoCuentaController', | ||
| 230 | size: 'lg', | ||
| 231 | resolve: { | ||
| 232 | parametros: function () { return { idCliente: cliente.cod }; }, | ||
| 233 | } | ||
| 234 | } | ||
| 235 | ); | ||
| 236 | modalInstance.result | ||
| 237 | .then(function (data) { | ||
| 210 | 238 | ||
| 211 | $scope.$broadcast('addCabecera', { | 239 | $scope.factura.cliente = cliente; | 
| 212 | label: 'Cliente:', | 240 | |
| 213 | valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + cliente.nom | 241 | $scope.$broadcast('addCabecera', { | 
| 214 | }); | 242 | label: 'Cliente:', | 
| 243 | valor: $filter('rellenarDigitos')(cliente.cod, 3) + | ||
| 244 | ' - ' + cliente.nom | ||
| 245 | }); | ||
| 246 | |||
| 247 | $filter('filter')($scope.botonera, | ||
| 248 | { label: 'Cliente' })[0].checked = true; | ||
| 249 | |||
| 250 | $scope.$broadcast('addCabecera', { | ||
| 251 | label: 'Tipo de pago: ', | ||
| 252 | valor: data | ||
| 253 | }); | ||
| 254 | }) | ||
| 255 | .catch(function () { | ||
| 215 | 256 | ||
| 216 | $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; | 257 | $scope.seleccionarCliente(); | 
| 258 | }); | ||
| 217 | 259 | ||
| 218 | }, function () { | 260 | }, function () { | 
| 219 | } | 261 | } | 
| 220 | ); | 262 | ); | 
| 221 | 263 | ||
| 222 | }; | 264 | }; | 
| 223 | 265 | ||
| 224 | $scope.seleccionarVendedor = function() { | 266 | $scope.seleccionarVendedor = function () { | 
| 225 | var parametrosModal = { | 267 | var parametrosModal = { | 
| 226 | titulo: 'Búsqueda vendedores', | 268 | titulo: 'Búsqueda vendedores', | 
| 227 | query: '/vendedor-playa', | 269 | query: '/vendedor-playa', | 
| 228 | columnas: [ | 270 | columnas: [ | 
| 229 | { | 271 | { | 
| 230 | propiedad: 'CodVen', | 272 | propiedad: 'CodVen', | 
| 231 | nombre: 'Código', | 273 | nombre: 'Código', | 
| 232 | filtro: { | 274 | filtro: { | 
| 233 | nombre: 'rellenarDigitos', | 275 | nombre: 'rellenarDigitos', | 
| 234 | parametro: 3 | 276 | parametro: 3 | 
| 235 | } | 277 | } | 
| 236 | }, | 278 | }, | 
| 237 | { | 279 | { | 
| 238 | propiedad: 'NomVen', | 280 | propiedad: 'NomVen', | 
| 239 | nombre: 'Nombre' | 281 | nombre: 'Nombre' | 
| 240 | } | 282 | } | 
| 241 | ], | 283 | ], | 
| 242 | size: 'md' | 284 | size: 'md' | 
| 243 | }; | 285 | }; | 
| 244 | focaModalService.modal(parametrosModal).then( | 286 | focaModalService.modal(parametrosModal).then( | 
| 245 | function (vendedor) { | 287 | function (vendedor) { | 
| 246 | 288 | ||
| 247 | indicarPassword(vendedor) | 289 | indicarPassword(vendedor) | 
| 248 | .then(function() { | 290 | .then(function () { | 
| 249 | validarPlanillaVendedor(vendedor) | 291 | validarPlanillaVendedor(vendedor) | 
| 250 | .then(function() { | 292 | .then(function () { | 
| 251 | 293 | ||
| 252 | $filter('filter')($scope.botonera, { | 294 | $filter('filter')($scope.botonera, { | 
| 253 | label: 'Vendedor' | 295 | label: 'Vendedor' | 
| 254 | })[0].checked = true; | 296 | })[0].checked = true; | 
| 255 | 297 | ||
| 256 | $scope.$broadcast('addCabecera', { | 298 | $scope.$broadcast('addCabecera', { | 
| 257 | label: 'Vendedor:', | 299 | label: 'Vendedor:', | 
| 258 | valor: $filter('rellenarDigitos')(vendedor.CodVen, 3) + | 300 | valor: $filter('rellenarDigitos')(vendedor.CodVen, 3) + | 
| 259 | ' - ' + | 301 | ' - ' + | 
| 260 | vendedor.NomVen | 302 | vendedor.NomVen | 
| 261 | }); | 303 | }); | 
| 262 | 304 | ||
| 263 | $scope.factura.vendedor = vendedor; | 305 | $scope.factura.vendedor = vendedor; | 
| 264 | 306 | ||
| 265 | getProductosByPlanilla(vendedor.NplVen); | 307 | getProductosByPlanilla(vendedor.NplVen); | 
| 266 | }) | 308 | }) | 
| 267 | .catch($scope.seleccionarVendedor); | 309 | .catch($scope.seleccionarVendedor); | 
| 268 | }) | 310 | }) | 
| 269 | .catch(function(err) { | 311 | .catch(function (err) { | 
| 270 | console.log(err) | 312 | console.log(err) | 
| 271 | }); | 313 | }); | 
| 272 | 314 | ||
| 273 | }, function () { } | 315 | }, function () { } | 
| 274 | ); | 316 | ); | 
| 275 | }; | 317 | }; | 
| 276 | 318 | ||
| 277 | $scope.seleccionarMoneda = function () { | 319 | $scope.seleccionarMoneda = function () { | 
| 278 | 320 | ||
| 279 | var parametrosModal = { | 321 | var parametrosModal = { | 
| 280 | titulo: 'Búsqueda de monedas', | 322 | titulo: 'Búsqueda de monedas', | 
| 281 | query: '/moneda', | 323 | query: '/moneda', | 
| 282 | columnas: [ | 324 | columnas: [ | 
| 283 | { | 325 | { | 
| 284 | propiedad: 'DETALLE', | 326 | propiedad: 'DETALLE', | 
| 285 | nombre: 'Nombre' | 327 | nombre: 'Nombre' | 
| 286 | }, | 328 | }, | 
| 287 | { | 329 | { | 
| 288 | propiedad: 'SIMBOLO', | 330 | propiedad: 'SIMBOLO', | 
| 289 | nombre: 'Símbolo' | 331 | nombre: 'Símbolo' | 
| 290 | } | 332 | } | 
| 291 | ], | 333 | ], | 
| 292 | size: 'md' | 334 | size: 'md' | 
| 293 | }; | 335 | }; | 
| 294 | focaModalService.modal(parametrosModal).then( | 336 | focaModalService.modal(parametrosModal).then( | 
| 295 | function (moneda) { | 337 | function (moneda) { | 
| 296 | 338 | ||
| 297 | if (moneda.ID !== 1) { | 339 | if (moneda.ID !== 1) { | 
| 298 | $scope.abrirModalCotizacion(moneda); | 340 | $scope.abrirModalCotizacion(moneda); | 
| 299 | return; | 341 | return; | 
| 300 | } | 342 | } | 
| 301 | 343 | ||
| 302 | crearRemitoService.getCotizacionByIdMoneda(1) | 344 | crearRemitoService.getCotizacionByIdMoneda(1) | 
| 303 | .then(function (res) { | 345 | .then(function (res) { | 
| 304 | 346 | ||
| 305 | cotizacionPArgentino = res.data[0].cotizaciones[0]; | 347 | cotizacionPArgentino = res.data[0].cotizaciones[0]; | 
| 306 | cotizacionPArgentino.moneda = moneda; | 348 | cotizacionPArgentino.moneda = moneda; | 
| 307 | 349 | ||
| 308 | actualizarCabeceraMoneda(cotizacionPArgentino); | 350 | actualizarCabeceraMoneda(cotizacionPArgentino); | 
| 309 | 351 | ||
| 310 | $scope.remito.cotizacion = cotizacionPArgentino; | 352 | $scope.remito.cotizacion = cotizacionPArgentino; | 
| 311 | }); | 353 | }); | 
| 312 | }, function () { | 354 | }, function () { | 
| 313 | 355 | ||
| 314 | } | 356 | } | 
| 315 | ); | 357 | ); | 
| 316 | }; | 358 | }; | 
| 317 | 359 | ||
| 318 | $scope.abrirModalCotizacion = function (moneda) { | 360 | $scope.abrirModalCotizacion = function (moneda) { | 
| 319 | var modalInstance = $uibModal.open( | 361 | var modalInstance = $uibModal.open( | 
| 320 | { | 362 | { | 
| 321 | ariaLabelledBy: 'Busqueda de Cotización', | 363 | ariaLabelledBy: 'Busqueda de Cotización', | 
| 322 | templateUrl: 'modal-cotizacion.html', | 364 | templateUrl: 'modal-cotizacion.html', | 
| 323 | controller: 'focaModalCotizacionController', | 365 | controller: 'focaModalCotizacionController', | 
| 324 | size: 'lg', | 366 | size: 'lg', | 
| 325 | resolve: { idMoneda: function () { return moneda.ID; } } | 367 | resolve: { idMoneda: function () { return moneda.ID; } } | 
| 326 | } | 368 | } | 
| 327 | ); | 369 | ); | 
| 328 | modalInstance.result.then( | 370 | modalInstance.result.then( | 
| 329 | function (cotizacion) { | 371 | function (cotizacion) { | 
| 330 | 372 | ||
| 331 | cotizacion.moneda = moneda; | 373 | cotizacion.moneda = moneda; | 
| 332 | actualizarCabeceraMoneda(cotizacion); | 374 | actualizarCabeceraMoneda(cotizacion); | 
| 333 | $scope.factura.cotizacion = cotizacion; | 375 | $scope.factura.cotizacion = cotizacion; | 
| 334 | 376 | ||
| 335 | }, function () { | 377 | }, function () { | 
| 336 | 378 | ||
| 337 | } | 379 | } | 
| 338 | ); | 380 | ); | 
| 339 | }; | 381 | }; | 
| 340 | 382 | ||
| 341 | $scope.seleccionarObservaciones = function () { | 383 | $scope.seleccionarObservaciones = function () { | 
| 342 | var observacion = { | 384 | var observacion = { | 
| 343 | titulo: 'Ingrese Observaciones', | 385 | titulo: 'Ingrese Observaciones', | 
| 344 | value: $scope.factura.observaciones, | 386 | value: $scope.factura.observaciones, | 
| 345 | maxlength: 155, | 387 | maxlength: 155, | 
| 346 | textarea: true | 388 | textarea: true | 
| 347 | }; | 389 | }; | 
| 348 | 390 | ||
| 349 | focaModalService | 391 | focaModalService | 
| 350 | .prompt(observacion) | 392 | .prompt(observacion) | 
| 351 | .then(function (observaciones) { | 393 | .then(function (observaciones) { | 
| 352 | $scope.factura.observaciones = observaciones; | 394 | $scope.factura.observaciones = observaciones; | 
| 353 | }); | 395 | }); | 
| 354 | }; | 396 | }; | 
| 355 | 397 | ||
| 356 | $scope.articulosFiltro = function () { | 398 | $scope.articulosFiltro = function () { | 
| 357 | return $scope.factura.articulosFactura.filter(function (articulo) { | 399 | return $scope.factura.articulosFactura.filter(function (articulo) { | 
| 358 | return !articulo.desactivado; | 400 | return !articulo.desactivado; | 
| 359 | }); | 401 | }); | 
| 360 | }; | 402 | }; | 
| 361 | 403 | ||
| 362 | $scope.getTotal = function () { | 404 | $scope.getTotal = function () { | 
| 363 | 405 | ||
| 364 | var total = 0; | 406 | var total = 0; | 
| 365 | 407 | ||
| 366 | $scope.articulosFiltro().forEach(function (articulo) { | 408 | $scope.articulosFiltro().forEach(function (articulo) { | 
| 367 | total += articulo.PUN * articulo.CAN; | 409 | total += articulo.PUN * articulo.CAN; | 
| 368 | }); | 410 | }); | 
| 369 | 411 | ||
| 370 | return parseFloat(total.toFixed(2)); | 412 | return parseFloat(total.toFixed(2)); | 
| 371 | }; | 413 | }; | 
| 372 | 414 | ||
| 373 | $scope.quitarDespacho = function (articulo, index) { | 415 | $scope.quitarDespacho = function (articulo, index) { | 
| 374 | 416 | ||
| 375 | crearFacturaService | 417 | crearFacturaService | 
| 376 | .setearDespachoDesocupado({ | 418 | .setearDespachoDesocupado({ | 
| 377 | surtidor: $scope.factura.despachos[index].SUR, | 419 | surtidor: $scope.factura.despachos[index].SUR, | 
| 378 | producto: $scope.factura.despachos[index].PRO, | 420 | producto: $scope.factura.despachos[index].PRO, | 
| 379 | carga: $scope.factura.despachos[index].CAR, | 421 | carga: $scope.factura.despachos[index].CAR, | 
| 380 | planilla: $scope.factura.despachos[index].PLA | 422 | planilla: $scope.factura.despachos[index].PLA | 
| 381 | }) | 423 | }) | 
| 382 | .then(function () { | 424 | .then(function () { | 
| 383 | articulo.desactivado = true; | 425 | articulo.desactivado = true; | 
| 384 | $scope.factura.despachos.splice(index, 1); | 426 | $scope.factura.despachos.splice(index, 1); | 
| 385 | }) | 427 | }) | 
| 386 | .catch(function() { | 428 | .catch(function () { | 
| 387 | focaModalService.alert('Hubo un error al desasociar este despacho'); | 429 | focaModalService.alert('Hubo un error al desasociar este despacho'); | 
| 388 | }); | 430 | }); | 
| 389 | }; | 431 | }; | 
| 390 | 432 | ||
| 391 | function getProductosByPlanilla(numeroPlanilla) { | 433 | function getProductosByPlanilla(numeroPlanilla) { | 
| 392 | 434 | ||
| 393 | crearFacturaService.getProductosByPlanilla(numeroPlanilla).then(function(res) { | 435 | crearFacturaService.getProductosByPlanilla(numeroPlanilla).then(function (res) { | 
| 394 | 436 | ||
| 395 | res.data.forEach(function (producto) { | 437 | res.data.forEach(function (producto) { | 
| 396 | 438 | ||
| 397 | $scope.botonera.push({ | 439 | $scope.botonera.push({ | 
| 398 | label: producto.DetArt, | 440 | label: producto.DetArt, | 
| 399 | image: 'productos.png' | 441 | image: 'productos.png' | 
| 400 | }); | 442 | }); | 
| 401 | 443 | ||
| 402 | 444 | ||
| 403 | crearFuncionesProductos(producto); | 445 | crearFuncionesProductos(producto); | 
| 404 | 446 | ||
| 405 | }); | 447 | }); | 
| 406 | }); | 448 | }); | 
| 407 | } | 449 | } | 
| 408 | 450 | ||
| 409 | function crearFuncionesProductos(producto) { | 451 | function crearFuncionesProductos(producto) { | 
| 410 | 452 | ||
| 411 | $scope[nombreFuncion(producto.DetArt)] = function() { | 453 | $scope[nombreFuncion(producto.DetArt)] = function () { | 
| 412 | 454 | ||
| 413 | if (angular.equals($scope.factura.cliente, {})) { | 455 | if (angular.equals($scope.factura.cliente, {})) { | 
| 414 | focaModalService.alert('Seleccione cliente'); | 456 | focaModalService.alert('Seleccione cliente'); | 
| 415 | return; | 457 | return; | 
| 416 | } | 458 | } | 
| 417 | 459 | ||
| 418 | var modalInstance = $uibModal.open( | 460 | var modalInstance = $uibModal.open( | 
| 419 | { | 461 | { | 
| 420 | templateUrl: 'modal-combustibles.html', | 462 | templateUrl: 'modal-combustibles.html', | 
| 421 | controller: 'focaModalCombustiblesController', | 463 | controller: 'focaModalCombustiblesController', | 
| 422 | resolve: { | 464 | resolve: { | 
| 423 | parametros: function() { | 465 | parametros: function () { | 
| 424 | return { | 466 | return { | 
| 425 | despachos: producto.despachos, | 467 | despachos: producto.despachos, | 
| 426 | nombreProducto: producto.DetArt | 468 | nombreProducto: producto.DetArt | 
| 427 | } | 469 | } | 
| 428 | } | 470 | } | 
| 429 | }, | 471 | }, | 
| 430 | size: 'md' | 472 | size: 'md' | 
| 431 | } | 473 | } | 
| 432 | ); | 474 | ); | 
| 433 | 475 | ||
| 434 | modalInstance.result.then(function(despacho) { | 476 | modalInstance.result.then(function (despacho) { | 
| 435 | 477 | ||
| 436 | var articulo = { | 478 | var articulo = { | 
| 437 | TIP: $scope.factura.cliente.tipoFactura, | 479 | TIP: $scope.factura.cliente.tipoFactura, | 
| 438 | TCO: 'FT', | 480 | TCO: 'FT', | 
| 439 | SUC: parseInt($scope.puntoVenta), | 481 | SUC: parseInt($scope.puntoVenta), | 
| 440 | ORD: $scope.articulosFiltro().length + 1, | 482 | ORD: $scope.articulosFiltro().length + 1, | 
| 441 | SEC: despacho.SEC, | 483 | SEC: despacho.SEC, | 
| 442 | ART: despacho.PRO, | 484 | ART: despacho.PRO, | 
| 443 | RUB: producto.CodRub, | 485 | RUB: producto.CodRub, | 
| 444 | DES: producto.DetArt, | 486 | DES: producto.DetArt, | 
| 445 | CAN: despacho.LTS, | 487 | CAN: despacho.LTS, | 
| 446 | PUN: producto.PreVen, // TODO | 488 | PUN: producto.PreVen, // TODO | 
| 447 | IVA: producto.IMPIVA, // TODO | 489 | IVA: producto.IMPIVA, // TODO | 
| 448 | NET: 0, // TODO | 490 | NET: 0, // TODO | 
| 449 | NEX: 0, // TODO | 491 | NEX: 0, // TODO | 
| 450 | IMI: producto.ImpInt, // TODO | 492 | IMI: producto.ImpInt, // TODO | 
| 451 | IMI2: producto.ImpInt2, // TODO | 493 | IMI2: producto.ImpInt2, // TODO | 
| 452 | IMI3: producto.ImpInt3, // TODO | 494 | IMI3: producto.ImpInt3, // TODO | 
| 453 | PUT: producto.PreNet, // TODO | 495 | PUT: producto.PreNet, // TODO | 
| 454 | SUR: despacho.SUR, | 496 | SUR: despacho.SUR, | 
| 455 | PLA: despacho.PLA, | 497 | PLA: despacho.PLA, | 
| 456 | LUG: despacho.LUG, | 498 | LUG: despacho.LUG, | 
| 457 | LEG: $scope.factura.vendedor.CodVen, | 499 | LEG: $scope.factura.vendedor.CodVen, | 
| 458 | TUR: $scope.factura.vendedor.TurVen, | 500 | TUR: $scope.factura.vendedor.TurVen, | 
| 459 | ORDEN_PRECOMPRA: '', | 501 | ORDEN_PRECOMPRA: '', | 
| 460 | ESC: producto.tipoFactura == 'L' ? 1 : 0, | 502 | ESC: producto.tipoFactura == 'L' ? 1 : 0, | 
| 461 | CMF: 0, | 503 | CMF: 0, | 
| 462 | PTA: 0, | 504 | PTA: 0, | 
| 463 | IVS: 0, | 505 | IVS: 0, | 
| 464 | TIVA: 0, | 506 | TIVA: 0, | 
| 465 | CON: 0, | 507 | CON: 0, | 
| 466 | SINO: '', | 508 | SINO: '', | 
| 467 | ORD_TRA: 0, | 509 | ORD_TRA: 0, | 
| 468 | IMP_DESP: 0, | 510 | IMP_DESP: 0, | 
| 469 | PCD: 0, | 511 | PCD: 0, | 
| 470 | RTO: '' | 512 | RTO: '' | 
| 471 | }; | 513 | }; | 
| 472 | 514 | ||
| 473 | crearFacturaService.setearDespachoOcupado({ | 515 | crearFacturaService.setearDespachoOcupado({ | 
| 474 | surtidor: despacho.SUR, | 516 | surtidor: despacho.SUR, | 
| 475 | producto: despacho.PRO, | 517 | producto: despacho.PRO, | 
| 476 | carga: despacho.CAR | 518 | carga: despacho.CAR | 
| 477 | }) | 519 | }) | 
| 478 | .then(function () { | 520 | .then(function () { | 
| 479 | $scope.factura.articulosFactura.push(articulo); | 521 | $scope.factura.articulosFactura.push(articulo); | 
| 480 | $scope.factura.despachos.push(despacho); | 522 | $scope.factura.despachos.push(despacho); | 
| 481 | }) | 523 | }) | 
| 482 | .catch(function (err) { | 524 | .catch(function (err) { | 
| 483 | 525 | ||
| 484 | focaModalService.alert('El despacho esta en uso'); | 526 | focaModalService.alert('El despacho esta en uso'); | 
| 485 | }); | 527 | }); | 
| 486 | 528 | ||
| 487 | }) | 529 | }) | 
| 488 | .catch(function (err) { | 530 | .catch(function (err) { | 
| 489 | console.log(err); | 531 | console.log(err); | 
| 490 | }); | 532 | }); | 
| 491 | 533 | ||
| 492 | }; | 534 | }; | 
| 493 | } | 535 | } | 
| 494 | 536 | ||
| 495 | function nombreFuncion(string) { | 537 | function nombreFuncion(string) { | 
| 496 | var texto = 'seleccionar'; | 538 | var texto = 'seleccionar'; | 
| 497 | var arr = string.split(' '); | 539 | var arr = string.split(' '); | 
| 498 | arr.forEach(function(palabra) { | 540 | arr.forEach(function (palabra) { | 
| 499 | palabra = palabra.charAt(0).toUpperCase() + palabra.slice(1); | 541 | palabra = palabra.charAt(0).toUpperCase() + palabra.slice(1); | 
| 500 | texto += palabra; | 542 | texto += palabra; | 
| 501 | }); | 543 | }); | 
| 502 | return texto; | 544 | return texto; | 
| 503 | } | 545 | } | 
| 504 | 546 | ||
| 505 | function indicarPassword(vendedor) { | 547 | function indicarPassword(vendedor) { | 
| 506 | 548 | ||
| 507 | return new Promise(function(resolve, reject) { | 549 | return new Promise(function (resolve, reject) { | 
| 508 | 550 | ||
| 509 | focaModalService | 551 | focaModalService | 
| 510 | .prompt({ | 552 | .prompt({ | 
| 511 | titulo: 'Indique Contraseña', | 553 | titulo: 'Indique Contraseña', | 
| 512 | value: '' | 554 | value: '' | 
| 513 | }) | 555 | }) | 
| 514 | .then(function (contraseña) { | 556 | .then(function (contraseña) { | 
| 515 | 557 | ||
| 516 | if (contraseña != vendedor.ClaVen.trim()) { | 558 | if (contraseña != vendedor.ClaVen.trim()) { | 
| 517 | 559 | ||
| 518 | focaModalService.alert('Clave incorrecta').then(function() { | 560 | focaModalService.alert('Clave incorrecta').then(function () { | 
| 519 | indicarPassword(vendedor); | 561 | indicarPassword(vendedor); | 
| 520 | }); | 562 | }); | 
| 521 | } else { | 563 | } else { | 
| 522 | resolve(); | 564 | resolve(); | 
| 523 | } | 565 | } | 
| 524 | }) | 566 | }) | 
| 525 | .catch(reject); | 567 | .catch(reject); | 
| 526 | }); | 568 | }); | 
| 527 | } | 569 | } | 
| 528 | 570 | ||
| 529 | function validarPlanillaVendedor(vendedor) { | 571 | function validarPlanillaVendedor(vendedor) { | 
| 530 | 572 | ||
| 531 | return new Promise(function(resolve, reject) { | 573 | return new Promise(function (resolve, reject) { | 
| 532 | 574 | ||
| 533 | crearFacturaService | 575 | crearFacturaService | 
| 534 | .validarPlanillaVendedor(vendedor.CodVen.trim()) | 576 | .validarPlanillaVendedor(vendedor.CodVen.trim()) | 
| 535 | .then(function (res) { | 577 | .then(function (res) { | 
| 536 | 578 | ||
| 537 | if (!res.data.length) { | 579 | if (!res.data.length) { | 
| 538 | 580 | ||
| 539 | focaModalService | 581 | focaModalService | 
| 540 | .alert('No se encontró planilla abierta para el vendedor') | 582 | .alert('No se encontró planilla abierta para el vendedor') | 
| 541 | .then(reject); | 583 | .then(reject); | 
| 542 | 584 | ||
| 543 | } else { | 585 | } else { | 
| 544 | resolve(); | 586 | resolve(); | 
| 545 | } | 587 | } | 
| 546 | 588 | ||
| 547 | }) | 589 | }) | 
| 548 | .catch(reject); | 590 | .catch(reject); | 
| 549 | }); | 591 | }); | 
| 550 | } | 592 | } | 
| 551 | 593 | ||
| 552 | function rellenar(relleno, longitud) { | 594 | function rellenar(relleno, longitud) { | 
| 553 | relleno = '' + relleno; | 595 | relleno = '' + relleno; | 
| 554 | while (relleno.length < longitud) { | 596 | while (relleno.length < longitud) { | 
| 555 | relleno = '0' + relleno; | 597 | relleno = '0' + relleno; | 
| 556 | } | 598 | } | 
| 557 | return relleno; | 599 | return relleno; | 
| 558 | } | 600 | } | 
| 559 | 601 | ||
| 560 | function salir() { | 602 | function salir() { | 
| 561 | var confirmacion = false; | 603 | var confirmacion = false; | 
| 562 | 604 | ||
| 563 | if (!angular.equals($scope.factura, $scope.inicial)) { | 605 | if (!angular.equals($scope.factura, $scope.inicial)) { | 
| 564 | confirmacion = true; | 606 | confirmacion = true; | 
| 565 | } | 607 | } | 
| 566 | 608 | ||
| 567 | if (confirmacion) { | 609 | if (confirmacion) { | 
| 568 | focaModalService.confirm( | 610 | focaModalService.confirm( | 
| 569 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 611 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 
| 570 | ).then(function (data) { | 612 | ).then(function (data) { | 
| 571 | if (data) { | 613 | if (data) { | 
| 572 | $location.path('/'); | 614 | $location.path('/'); | 
| 573 | } | 615 | } | 
| 574 | }); | 616 | }); | 
| 575 | } else { | 617 | } else { | 
| 576 | $location.path('/'); | 618 | $location.path('/'); | 
| 577 | } | 619 | } | 
| 578 | } | 620 | } | 
| 579 | 621 | ||
| 580 | function setearFactura(factura) { | 622 | function setearFactura(factura) { | 
| 581 | 623 | ||
| 582 | $scope.$broadcast('cleanCabecera'); | 624 | $scope.$broadcast('cleanCabecera'); | 
| 583 | 625 | ||
| 584 | $scope.cabeceras = []; | 626 | $scope.cabeceras = []; | 
| 585 | 627 | ||
| 586 | if (factura.cotizacion && factura.cotizacion.moneda.CODIGO_AFIP !== 'PES') { | 628 | if (factura.cotizacion && factura.cotizacion.moneda.CODIGO_AFIP !== 'PES') { | 
| 587 | $scope.cabeceras.push({ | 629 | $scope.cabeceras.push({ | 
| 588 | label: 'Moneda:', | 630 | label: 'Moneda:', | 
| 589 | valor: factura.cotizacion.moneda.DETALLE | 631 | valor: factura.cotizacion.moneda.DETALLE | 
| 590 | }); | 632 | }); | 
| 591 | $scope.cabeceras.push({ | 633 | $scope.cabeceras.push({ | 
| 592 | label: 'Fecha cotizacion:', | 634 | label: 'Fecha cotizacion:', | 
| 593 | valor: $filter('date')(factura.cotizacion.FECHA, | 635 | valor: $filter('date')(factura.cotizacion.FECHA, | 
| 594 | 'dd/MM/yyyy') | 636 | 'dd/MM/yyyy') | 
| 595 | }); | 637 | }); | 
| 596 | $scope.cabeceras.push({ | 638 | $scope.cabeceras.push({ | 
| 597 | label: 'Cotizacion:', | 639 | label: 'Cotizacion:', | 
| 598 | valor: $filter('number')(factura.cotizacion.VENDEDOR, | 640 | valor: $filter('number')(factura.cotizacion.VENDEDOR, | 
| 599 | '2') | 641 | '2') | 
| 600 | }); | 642 | }); | 
| 601 | } | 643 | } | 
| 602 | 644 | ||
| 603 | if (factura.cotizacion && factura.cotizacion.moneda) { | 645 | if (factura.cotizacion && factura.cotizacion.moneda) { | 
| 604 | $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; | 646 | $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; | 
| 605 | } | 647 | } | 
| 606 | 648 | ||
| 607 | if (factura.cliente && factura.cliente.cod) { | 649 | if (factura.cliente && factura.cliente.cod) { | 
| 608 | $scope.cabeceras.push({ | 650 | $scope.cabeceras.push({ | 
| 609 | label: 'Cliente:', | 651 | label: 'Cliente:', | 
| 610 | valor: $filter('rellenarDigitos')(factura.cliente.cod, 3) + ' - ' + | 652 | valor: $filter('rellenarDigitos')(factura.cliente.cod, 3) + ' - ' + | 
| 611 | factura.cliente.nom | 653 | factura.cliente.nom | 
| 612 | }); | 654 | }); | 
| 613 | 655 | ||
| 614 | $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; | 656 | $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; | 
| 615 | } | 657 | } | 
| 616 | 658 | ||
| 617 | $scope.puntoVenta = rellenar(factura.sucursal, 4); | 659 | $scope.puntoVenta = rellenar(factura.sucursal, 4); | 
| 618 | $scope.comprobante = rellenar(factura.numerofactura, 8); | 660 | $scope.comprobante = rellenar(factura.numerofactura, 8); | 
| 619 | $scope.factura = factura; | 661 | $scope.factura = factura; | 
| 620 | 662 | ||
| 621 | addArrayCabecera($scope.cabeceras); | 663 | addArrayCabecera($scope.cabeceras); | 
| 622 | } | 664 | } | 
| 623 | 665 | ||
| 624 | function getLSFactura() { | 666 | function getLSFactura() { | 
| 625 | var factura = JSON.parse($localStorage.factura || null); | 667 | var factura = JSON.parse($localStorage.factura || null); | 
| 626 | if (factura) { | 668 | if (factura) { | 
| 627 | setearFactura(factura); | 669 | setearFactura(factura); | 
| 628 | delete $localStorage.factura; | 670 | delete $localStorage.factura; | 
| 629 | } | 671 | } | 
| 630 | } | 672 | } | 
| 631 | 673 | ||
| 632 | function addArrayCabecera(array) { | 674 | function addArrayCabecera(array) { | 
| 633 | for (var i = 0; i < array.length; i++) { | 675 | for (var i = 0; i < array.length; i++) { | 
| 634 | $scope.$broadcast('addCabecera', { | 676 | $scope.$broadcast('addCabecera', { | 
| 635 | label: array[i].label, | 677 | label: array[i].label, | 
| 636 | valor: array[i].valor | 678 | valor: array[i].valor | 
| 637 | }); | 679 | }); | 
| 638 | } | 680 | } | 
| 639 | } | 681 | } | 
| 640 | 682 | ||
| 641 | function actualizarCabeceraMoneda(cotizacion) { | 683 | function actualizarCabeceraMoneda(cotizacion) { | 
| 642 | 684 | ||
| 643 | $scope.factura.articulosFactura.forEach(function (art) { | 685 | $scope.factura.articulosFactura.forEach(function (art) { | 
| 644 | art.PUN = (art.PUN * $scope.factura.cotizacion.VENDEDOR).toFixed(4); | 686 | art.PUN = (art.PUN * $scope.factura.cotizacion.VENDEDOR).toFixed(4); | 
| 645 | art.PUN = (art.PUN / cotizacion.VENDEDOR).toFixed(4); | 687 | art.PUN = (art.PUN / cotizacion.VENDEDOR).toFixed(4); | 
| 646 | }); | 688 | }); | 
| 647 | 689 | ||
| 648 | if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { | 690 | if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { | 
| 649 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 691 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 
| 650 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 692 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 
| 651 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 693 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 
| 652 | } else { | 694 | } else { | 
| 653 | $scope.$broadcast('addCabecera', { | 695 | $scope.$broadcast('addCabecera', { | 
| 654 | label: 'Moneda:', | 696 | label: 'Moneda:', | 
| 655 | valor: cotizacion.moneda.DETALLE | 697 | valor: cotizacion.moneda.DETALLE | 
| 656 | }); | 698 | }); | 
| 657 | $scope.$broadcast('addCabecera', { | 699 | $scope.$broadcast('addCabecera', { | 
| 658 | label: 'Fecha cotizacion:', | 700 | label: 'Fecha cotizacion:', | 
| 659 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 701 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 
| 660 | }); | 702 | }); | 
| 661 | $scope.$broadcast('addCabecera', { | 703 | $scope.$broadcast('addCabecera', { | 
| 662 | label: 'Cotizacion:', | 704 | label: 'Cotizacion:', | 
| 663 | valor: $filter('number')(cotizacion.VENDEDOR, '2') | 705 | valor: $filter('number')(cotizacion.VENDEDOR, '2') | 
| 664 | }); | 706 | }); | 
| 665 | } | 707 | } | 
| 666 | } | 708 | } | 
| 667 | 709 | ||
| 668 | function validarGuardar() { | 710 | function validarGuardar() { | 
| 669 | 711 | ||
| 670 | if (angular.equals({}, $scope.factura.vendedor)) { | 712 | if (angular.equals({}, $scope.factura.vendedor)) { | 
| 671 | 713 | ||
| 672 | focaModalService.alert('Seleccione Vendedor'); | 714 | focaModalService.alert('Seleccione Vendedor'); | 
| 673 | return false; | 715 | return false; | 
| 674 | } else if (angular.equals({}, $scope.factura.cliente)) { | 716 | } else if (angular.equals({}, $scope.factura.cliente)) { | 
| 675 | 717 | ||
| 676 | focaModalService.alert('Seleccione Cliente') | 718 | focaModalService.alert('Seleccione Cliente') | 
| 677 | return false; | 719 | return false; | 
| 678 | } else if (!$scope.articulosFiltro().length) { | 720 | } else if (!$scope.articulosFiltro().length) { | 
| 679 | 721 | ||
| 680 | focaModalService.alert('Seleccione al menos un Articulo'); | 722 | focaModalService.alert('Seleccione al menos un Articulo'); | 
| 681 | return false; | 723 | return false; | 
| 682 | } | 724 | } | 
| 683 | 725 | ||
| 684 | return true; | 726 | return true; | 
| 685 | } | 727 | } | 
| 686 | } | 728 | } | 
| 687 | ]); | 729 | ]); | 
| 688 | 730 | 
src/js/controllerEstadoCuenta.js
| File was created | 1 | angular.module('focaCrearFactura') | |
| 2 | .controller('focaModalEstadoCuentaController', [ | ||
| 3 | '$scope', '$uibModalInstance', 'crearFacturaService', 'parametros', | ||
| 4 | function ($scope, $uibModalInstance, crearFacturaService, parametros) { | ||
| 5 | |||
| 6 | $scope.estadoCuenta = { | ||
| 7 | autorizado: 0.0, | ||
| 8 | extracciones: 0.0, | ||
| 9 | saldo: 0.0, | ||
| 10 | situacion: false, | ||
| 11 | facturasVencidas: 0.0 | ||
| 12 | }; | ||
| 13 | |||
| 14 | init(); | ||
| 15 | |||
| 16 | function init() { | ||
| 17 | crearFacturaService.getResumenCuenta(parametros.idCliente) | ||
| 18 | .then(function (res) { | ||
| 19 | console.log(res); | ||
| 20 | $scope.estadoCuenta = res.data; | ||
| 21 | }) | ||
| 22 | .catch(function (e) { console.error(e); }); | ||
| 23 | } | ||
| 24 | |||
| 25 | $scope.elegirTipoDePago = function (tipoDePago) { | ||
| 26 | $uibModalInstance.close(tipoDePago); | ||
| 27 | }; | ||
| 28 | |||
| 29 | $scope.cancel = function () { | ||
| 30 | $uibModalInstance.dismiss('cancel'); | ||
| 31 | }; | ||
| 32 | } | ||
| 33 | ]); | ||
| 34 | 
src/js/service.js
| 1 | angular.module('focaCrearFactura') | 1 | angular.module('focaCrearFactura') | 
| 2 | .service('crearFacturaService', ['$http', 'API_ENDPOINT', | 2 | .service('crearFacturaService', ['$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 | guardarFactura: function (factura) { | 6 | guardarFactura: function (factura) { | 
| 7 | return $http.post(route + '/factura/guardar', factura) | 7 | return $http.post(route + '/factura/guardar', factura); | 
| 8 | }, | 8 | }, | 
| 9 | getParametros: function() { | 9 | getParametros: function () { | 
| 10 | return $http.get(API_ENDPOINT.URL + '/parametros/factura'); | 10 | return $http.get(API_ENDPOINT.URL + '/parametros/factura'); | 
| 11 | }, | 11 | }, | 
| 12 | validarPlanillaVendedor: function(idVendedor) { | 12 | validarPlanillaVendedor: function (idVendedor) { | 
| 13 | return $http.get(route + '/turnos/validar-planilla/' + idVendedor); | 13 | return $http.get(route + '/turnos/validar-planilla/' + idVendedor); | 
| 14 | }, | 14 | }, | 
| 15 | getProductosByPlanilla: function (numeroPlanilla) { | 15 | getProductosByPlanilla: function (numeroPlanilla) { | 
| 16 | return $http.get(route + '/turnos/productos/' + numeroPlanilla); | 16 | return $http.get(route + '/turnos/productos/' + numeroPlanilla); | 
| 17 | }, | 17 | }, | 
| 18 | setearDespachoOcupado: function (parametros) { | 18 | setearDespachoOcupado: function (parametros) { | 
| 19 | return $http.post(route + '/turnos/despacho-en-uso', parametros); | 19 | return $http.post(route + '/turnos/despacho-en-uso', parametros); | 
| 20 | }, | 20 | }, | 
| 21 | setearDespachoDesocupado: function (parametros) { | 21 | setearDespachoDesocupado: function (parametros) { | 
| 22 | return $http.post(route + '/turnos/depacho-sin-uso', parametros); | 22 | return $http.post(route + '/turnos/depacho-sin-uso', parametros); | 
| 23 | }, | 23 | }, | 
| 24 | getBotonera: function() { | 24 | getResumenCuenta: function (idCliente) { | 
| 25 | return [ | 25 | return $http.get('http://10.231.45.194:9900' + '/cliente/resumen-cuenta/' + idCliente); | 
| 26 | { | 26 | }, | 
| 27 | label: 'Vendedor', | 27 | getBotonera: function () { | 
| 28 | image: 'vendedor.png' | 28 | return [ | 
| 29 | }, | 29 | { | 
| 30 | { | 30 | label: 'Vendedor', | 
| 31 | label: 'Cliente', | 31 | image: 'vendedor.png' | 
| 32 | image: 'cliente.png' | 32 | }, | 
| 33 | }, | 33 | { | 
| 34 | { | 34 | label: 'Cliente', | 
| 35 | label: 'Moneda', | 35 | image: 'cliente.png' | 
| 36 | image: 'moneda.png' | 36 | }, | 
| 37 | }, | 37 | { | 
| 38 | { | 38 | label: 'Moneda', | 
| 39 | label: 'Observaciones', | 39 | image: 'moneda.png' | 
| 40 | image: 'botonObservaciones.png' | 40 | }, | 
| 41 | } | 41 | { | 
| 42 | ]; | 42 | label: 'Observaciones', | 
| 43 | } | 43 | image: 'botonObservaciones.png' | 
| 44 | }; | 44 | } | 
| 45 | }]); | 45 | ]; | 
| 46 | } | ||
| 47 | }; | ||
| 48 | } | ||
| 49 | ]); | ||
| 46 | 50 | 
src/views/modal-estado-cuenta.html
| File was created | 1 | <div class="modal-header py-1"> | |
| 2 | <div class="row w-100"> | ||
| 3 | <div class="col-lg-6"> | ||
| 4 | <h5 class="modal-title text-center my-1">Estado cuenta corriente</h5> | ||
| 5 | </div> | ||
| 6 | </div> | ||
| 7 | </div> | ||
| 8 | <div class="modal-body" id="modal-body"> | ||
| 9 | <div class="row m-3"> | ||
| 10 | <div class="col"> | ||
| 11 | <div class="row mb-2"> | ||
| 12 | <div class="col text-center"> | ||
| 13 | <p class="m-0">Autorizado</p> | ||
| 14 | <p class="h5 m-0" ng-bind="estadoCuenta.autorizado | currency"></p> | ||
| 15 | </div> | ||
| 16 | </div> | ||
| 17 | <div class="row border-top mb-2"> | ||
| 18 | <div class="col text-center"> | ||
| 19 | <p class="m-0">Extracciones</p> | ||
| 20 | <p class="h5 m-0" ng-bind="estadoCuenta.extracciones | currency"></p> | ||
| 21 | </div> | ||
| 22 | </div> | ||
| 23 | <div class="row border-top mb-2"> | ||
| 24 | <div class="col text-center"> | ||
| 25 | <p class="m-0">Saldo</p> | ||
| 26 | <p class="h5 m-0" ng-bind="estadoCuenta.saldo | currency"></p> | ||
| 27 | </div> | ||
| 28 | </div> | ||
| 29 | <div class="row border-top"> | ||
| 30 | <div class="col text-center"> | ||
| 31 | <p class="m-0">Situacion</p> | ||
| 32 | <h4> | ||
| 33 | <p | ||
| 34 | ng-show="estadoCuenta.situacion" | ||
| 35 | class="badge badge-success m-0 px-3">Permitido | ||
| 36 | </p> | ||
| 37 | <p | ||
| 38 | ng-show="!estadoCuenta.situacion" | ||
| 39 | class="badge badge-danger m-0 px-3">No permitido | ||
| 40 | </p> | ||
| 41 | </h4> | ||
| 42 | </div> | ||
| 43 | </div> | ||
| 44 | <div class="row border-top mb-2"> | ||
| 45 | <div class="col text-center"> | ||
| 46 | <p class="m-0">Facturas Vencidas</p> | ||
| 47 | <p class="h5 m-0" ng-bind="estadoCuenta.facturasVencidas | currency"></p> | ||
| 48 | </div> | ||
| 49 | </div> | ||
| 50 | </div> | ||
| 51 | </div> | ||
| 52 | <div class="row h-25 align-items-center mx-0 botonera-secundaria"> | ||
| 53 | <div class="col-6 col-sm-4 offset-sm-2"> | ||
| 54 | <button | ||
| 55 | type="button" | ||
| 56 | class="btn btn-sm btn-block btn-tarjeta rounded border p-1" | ||
| 57 | ng-disabled="!estadoCuenta.situacion" | ||
| 58 | ng-click="elegirTipoDePago('Contado')" | ||
| 59 | > | ||
| 60 | <img ng-src="./img/contado.png" alt=""> | ||
| 61 | <p class="m-0">Contado</p> | ||
| 62 | </button> | ||
| 63 | </div> | ||
| 64 | <div class="col-6 col-sm-4"> | ||
| 65 | <button | ||
| 66 | type="button" | ||
| 67 | class="btn btn-sm btn-block btn-tarjeta rounded border p-1" | ||
| 68 | ng-disabled="!estadoCuenta.situacion" | ||
| 69 | foca-focus="true" | ||
| 70 | ng-click="elegirTipoDePago('Cuenta Corriente')" | ||
| 71 | > | ||
| 72 | <img ng-src="./img/cuentaCorriente.png" alt=""> | ||
| 73 | <p class="m-0">Cta. Corriente</p> | ||
| 74 | </button> | ||
| 75 | </div> | ||
| 76 | </div> | ||
| 77 | </div> | ||
| 78 | <div class="modal-footer py-2"> | ||
| 79 | <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button> | ||
| 80 | </div> | 
src/views/modal-seleccionar-cliente.html
| File was created | 1 | <div class="modal-header py-1"> | |
| 2 | <div class="row w-100"> | ||
| 3 | <div class="col-lg-6"> | ||
| 4 | <h5 class="modal-title my-1">Seleccione Cliente</h5> | ||
| 5 | </div> | ||
| 6 | </div> | ||
| 7 | </div> | ||
| 8 | <div class="modal-body" id="modal-body"> | ||
| 9 | |||
| 10 | </div> | ||
| 11 | <div class="modal-footer py-1"> | ||
| 12 | <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button> | ||
| 13 | </div> |