Commit cd5efe0953c01ff8deb6a5f546443ef324fc797e
1 parent
ee34395a29
Exists in
ultimos_despachos
and in
1 other branch
Agregada validacion para busqueda de productos.
Showing
1 changed file
with
8 additions
and
5 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', 'APP', 'focaLoginService', | 4 | '$localStorage', 'APP', 'focaLoginService', | 
| 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, APP, loginServ) | 7 | crearRemitoService, $rootScope, focaBotoneraLateralService, $localStorage, APP, loginServ) { | 
| 8 | { | ||
| 9 | 8 | ||
| 10 | config(); | 9 | config(); | 
| 11 | 10 | ||
| 12 | function config() { | 11 | function config() { | 
| 13 | $scope.tmpCantidad = Number; | 12 | $scope.tmpCantidad = Number; | 
| 14 | $scope.tmpPrecio = Number; | 13 | $scope.tmpPrecio = Number; | 
| 15 | $scope.botonera = crearFacturaService.getBotonera(); | 14 | $scope.botonera = crearFacturaService.getBotonera(); | 
| 16 | $scope.botoneraProductos = []; | 15 | $scope.botoneraProductos = []; | 
| 17 | $scope.isNumber = angular.isNumber; | 16 | $scope.isNumber = angular.isNumber; | 
| 18 | $scope.datepickerAbierto = false; | 17 | $scope.datepickerAbierto = false; | 
| 19 | $scope.show = false; | 18 | $scope.show = false; | 
| 20 | $scope.cargando = true; | 19 | $scope.cargando = true; | 
| 21 | $scope.now = new Date(); | 20 | $scope.now = new Date(); | 
| 22 | $scope.puntoVenta = rellenar(0, 4); | 21 | $scope.puntoVenta = rellenar(0, 4); | 
| 23 | $scope.comprobante = rellenar(0, 8); | 22 | $scope.comprobante = rellenar(0, 8); | 
| 24 | $scope.dateOptions = { | 23 | $scope.dateOptions = { | 
| 25 | maxDate: new Date(), | 24 | maxDate: new Date(), | 
| 26 | minDate: new Date(2010, 0, 1) | 25 | minDate: new Date(2010, 0, 1) | 
| 27 | }; | 26 | }; | 
| 28 | $scope.cabeceras = []; | 27 | $scope.cabeceras = []; | 
| 29 | crearFacturaService.getParametros().then(function (res) { | 28 | crearFacturaService.getParametros().then(function (res) { | 
| 30 | 29 | ||
| 31 | var parametros = JSON.parse(res.data[0].jsonText); | 30 | var parametros = JSON.parse(res.data[0].jsonText); | 
| 32 | 31 | ||
| 33 | if ($localStorage.factura) { | 32 | if ($localStorage.factura) { | 
| 34 | 33 | ||
| 35 | $timeout(function () { getLSFactura(); }); | 34 | $timeout(function () { getLSFactura(); }); | 
| 36 | } else { | 35 | } else { | 
| 37 | 36 | ||
| 38 | for (var property in parametros) { | 37 | for (var property in parametros) { | 
| 39 | $scope.factura[property] = parametros[property]; | 38 | $scope.factura[property] = parametros[property]; | 
| 40 | $scope.inicial[property] = parametros[property]; | 39 | $scope.inicial[property] = parametros[property]; | 
| 41 | } | 40 | } | 
| 42 | 41 | ||
| 43 | setearFactura($scope.factura); | 42 | setearFactura($scope.factura); | 
| 44 | } | 43 | } | 
| 45 | 44 | ||
| 46 | }); | 45 | }); | 
| 47 | 46 | ||
| 48 | //SETEO BOTONERA LATERAL | 47 | //SETEO BOTONERA LATERAL | 
| 49 | $timeout(function () { | 48 | $timeout(function () { | 
| 50 | focaBotoneraLateralService.showSalir(false); | 49 | focaBotoneraLateralService.showSalir(false); | 
| 51 | focaBotoneraLateralService.showPausar(true); | 50 | focaBotoneraLateralService.showPausar(true); | 
| 52 | focaBotoneraLateralService.showGuardar(true, $scope.seleccionarFormaDePago); | 51 | focaBotoneraLateralService.showGuardar(true, $scope.seleccionarFormaDePago); | 
| 53 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 52 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 
| 54 | }); | 53 | }); | 
| 55 | 54 | ||
| 56 | init(); | 55 | init(); | 
| 57 | 56 | ||
| 58 | } | 57 | } | 
| 59 | 58 | ||
| 60 | function init() { | 59 | function init() { | 
| 61 | 60 | ||
| 62 | $scope.$broadcast('cleanCabecera'); | 61 | $scope.$broadcast('cleanCabecera'); | 
| 63 | 62 | ||
| 64 | $scope.factura = { | 63 | $scope.factura = { | 
| 65 | id: 0, | 64 | id: 0, | 
| 66 | estado: 0, | 65 | estado: 0, | 
| 67 | vendedor: {}, | 66 | vendedor: {}, | 
| 68 | cliente: {}, | 67 | cliente: {}, | 
| 69 | proveedor: {}, | 68 | proveedor: {}, | 
| 70 | domicilio: { dom: '' }, | 69 | domicilio: { dom: '' }, | 
| 71 | moneda: {}, | 70 | moneda: {}, | 
| 72 | cotizacion: $scope.cotizacionPorDefecto || {}, | 71 | cotizacion: $scope.cotizacionPorDefecto || {}, | 
| 73 | articulosFactura: [], | 72 | articulosFactura: [], | 
| 74 | despachos: [] | 73 | despachos: [] | 
| 75 | }; | 74 | }; | 
| 76 | 75 | ||
| 77 | $scope.factura.articulosFactura = []; | 76 | $scope.factura.articulosFactura = []; | 
| 78 | $scope.idLista = undefined; | 77 | $scope.idLista = undefined; | 
| 79 | 78 | ||
| 80 | crearRemitoService.getNumeroRemito().then( | 79 | crearRemitoService.getNumeroRemito().then( | 
| 81 | function (res) { | 80 | function (res) { | 
| 82 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); | 81 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); | 
| 83 | $scope.comprobante = rellenar(res.data.numeroRemito, 8); | 82 | $scope.comprobante = rellenar(res.data.numeroRemito, 8); | 
| 84 | }, | 83 | }, | 
| 85 | function (err) { | 84 | function (err) { | 
| 86 | focaModalService.alert('La terminal no esta configurada correctamente'); | 85 | focaModalService.alert('La terminal no esta configurada correctamente'); | 
| 87 | console.info(err); | 86 | console.info(err); | 
| 88 | } | 87 | } | 
| 89 | ); | 88 | ); | 
| 90 | 89 | ||
| 91 | $scope.inicial = angular.copy($scope.factura); | 90 | $scope.inicial = angular.copy($scope.factura); | 
| 92 | 91 | ||
| 93 | if (APP == 'facturador') { | 92 | if (APP == 'facturador') { | 
| 94 | crearFacturaService | 93 | crearFacturaService | 
| 95 | .getVendedorPlayaById(loginServ.getLoginData().vendedorPlaya) | 94 | .getVendedorPlayaById(loginServ.getLoginData().vendedorPlaya) | 
| 96 | .then(function (res) { | 95 | .then(function (res) { | 
| 97 | 96 | ||
| 98 | validarPlanillaVendedor(res.data) | 97 | validarPlanillaVendedor(res.data) | 
| 99 | .then(function () { | 98 | .then(function () { | 
| 100 | 99 | ||
| 101 | $scope.$broadcast('addCabecera', { | 100 | $scope.$broadcast('addCabecera', { | 
| 102 | label: 'Vendedor:', | 101 | label: 'Vendedor:', | 
| 103 | valor: $filter('rellenarDigitos')(res.data.CodVen, 3) + | 102 | valor: $filter('rellenarDigitos')(res.data.CodVen, 3) + | 
| 104 | ' - ' + | 103 | ' - ' + | 
| 105 | res.data.NomVen | 104 | res.data.NomVen | 
| 106 | }); | 105 | }); | 
| 107 | 106 | ||
| 108 | $scope.factura.vendedor = res.data; | 107 | $scope.factura.vendedor = res.data; | 
| 109 | $scope.inicial.vendedor = res.data; | 108 | $scope.inicial.vendedor = res.data; | 
| 110 | 109 | ||
| 111 | getProductosByPlanilla(res.data.NplVen); | 110 | getProductosByPlanilla(res.data.NplVen); | 
| 112 | }) | 111 | }) | 
| 113 | .catch(function (err) { | 112 | .catch(function (err) { | 
| 114 | console.log(err); | 113 | console.log(err); | 
| 115 | focaModalService.alert('Ocurrió un error al intentar recuperar' + | 114 | focaModalService.alert('Ocurrió un error al intentar recuperar' + | 
| 116 | 'el vendedor logeado'); | 115 | 'el vendedor logeado'); | 
| 117 | }); | 116 | }); | 
| 118 | }) | 117 | }) | 
| 119 | } | 118 | } | 
| 120 | } | 119 | } | 
| 121 | 120 | ||
| 122 | $scope.$watch('factura', function (newValue) { | 121 | $scope.$watch('factura', function (newValue) { | 
| 123 | focaBotoneraLateralService.setPausarData({ | 122 | focaBotoneraLateralService.setPausarData({ | 
| 124 | label: 'factura', | 123 | label: 'factura', | 
| 125 | val: newValue | 124 | val: newValue | 
| 126 | }); | 125 | }); | 
| 127 | }, true); | 126 | }, true); | 
| 128 | 127 | ||
| 129 | $scope.seleccionarFormaDePago = function () { | 128 | $scope.seleccionarFormaDePago = function () { | 
| 130 | if (!validarGuardar()) return; | 129 | if (!validarGuardar()) return; | 
| 131 | var modalInstance = $uibModal.open( | 130 | var modalInstance = $uibModal.open( | 
| 132 | { | 131 | { | 
| 133 | templateUrl: 'modal-forma-pago.html', | 132 | templateUrl: 'modal-forma-pago.html', | 
| 134 | controller: 'focaModalFormaPagoController', | 133 | controller: 'focaModalFormaPagoController', | 
| 135 | resolve: { | 134 | resolve: { | 
| 136 | parametros: function () { | 135 | parametros: function () { | 
| 137 | return { | 136 | return { | 
| 138 | importe: $scope.getTotal() | 137 | importe: $scope.getTotal() | 
| 139 | }; | 138 | }; | 
| 140 | }, | 139 | }, | 
| 141 | }, | 140 | }, | 
| 142 | size: 'lg', | 141 | size: 'lg', | 
| 143 | } | 142 | } | 
| 144 | ); | 143 | ); | 
| 145 | modalInstance.result | 144 | modalInstance.result | 
| 146 | .then(function (data) { | 145 | .then(function (data) { | 
| 147 | 146 | ||
| 148 | $scope.crearFactura(data); | 147 | $scope.crearFactura(data); | 
| 149 | }) | 148 | }) | 
| 150 | .catch(function (e) { console.error(e); }); | 149 | .catch(function (e) { console.error(e); }); | 
| 151 | }; | 150 | }; | 
| 152 | 151 | ||
| 153 | $scope.crearFactura = function (formaPago) { | 152 | $scope.crearFactura = function (formaPago) { | 
| 154 | 153 | ||
| 155 | var save = { | 154 | var save = { | 
| 156 | factura: { | 155 | factura: { | 
| 157 | 156 | ||
| 158 | BONIF: 0, | 157 | BONIF: 0, | 
| 159 | CLI: $scope.factura.cliente.cod, | 158 | CLI: $scope.factura.cliente.cod, | 
| 160 | CUI: $scope.factura.cliente.cuit, | 159 | CUI: $scope.factura.cliente.cuit, | 
| 161 | CTA: $scope.factura.cliente.cod, | 160 | CTA: $scope.factura.cliente.cod, | 
| 162 | DC1: '', | 161 | DC1: '', | 
| 163 | DC2: '', | 162 | DC2: '', | 
| 164 | DE1: '', | 163 | DE1: '', | 
| 165 | DOM: $scope.factura.cliente.DOM, | 164 | DOM: $scope.factura.cliente.DOM, | 
| 166 | FACAUT: 0, | 165 | FACAUT: 0, | 
| 167 | DTO: 0, | 166 | DTO: 0, | 
| 168 | FEC: $filter('date')($scope.now, 'yyyy-MM-dd HH:mm:ss'), | 167 | FEC: $filter('date')($scope.now, 'yyyy-MM-dd HH:mm:ss'), | 
| 169 | FEC_ANT: '19000101', | 168 | FEC_ANT: '19000101', | 
| 170 | FPA: 0, // 0 <- Múltiple formas de pago, 2 cta corriente | 169 | FPA: 0, // 0 <- Múltiple formas de pago, 2 cta corriente | 
| 171 | IDEXCEPCION: 0, | 170 | IDEXCEPCION: 0, | 
| 172 | IDLP: $scope.factura.cliente.mod.trim() || 0, | 171 | IDLP: $scope.factura.cliente.mod.trim() || 0, | 
| 173 | IDPERSONERIA: 0, | 172 | IDPERSONERIA: 0, | 
| 174 | IMI: 0, // TODO | 173 | IMI: 0, // TODO | 
| 175 | IMI2: 0, // TODO | 174 | IMI2: 0, // TODO | 
| 176 | IMI3: 0, // TODO | 175 | IMI3: 0, // TODO | 
| 177 | IMP_LEY: 0, | 176 | IMP_LEY: 0, | 
| 178 | IRI: 0, // TODO | 177 | IRI: 0, // TODO | 
| 179 | IRS: 0, | 178 | IRS: 0, | 
| 180 | LEG: '', | 179 | LEG: '', | 
| 181 | LUG: $scope.factura.vendedor.LugVen, | 180 | LUG: $scope.factura.vendedor.LugVen, | 
| 182 | MK_M: 0, | 181 | MK_M: 0, | 
| 183 | NEE: 0, // TODO | 182 | NEE: 0, // TODO | 
| 184 | NET: 0, // TODO | 183 | NET: 0, // TODO | 
| 185 | NFI: '', | 184 | NFI: '', | 
| 186 | NNP: 0, | 185 | NNP: 0, | 
| 187 | NOM: $scope.factura.cliente.nom, | 186 | NOM: $scope.factura.cliente.nom, | 
| 188 | OPE: $scope.factura.vendedor.CodVen, | 187 | OPE: $scope.factura.vendedor.CodVen, | 
| 189 | PAG: $scope.getTotal(), | 188 | PAG: $scope.getTotal(), | 
| 190 | PER: 0, | 189 | PER: 0, | 
| 191 | PER_IVA: 0, | 190 | PER_IVA: 0, | 
| 192 | PLA: $scope.factura.vendedor.NplVen, | 191 | PLA: $scope.factura.vendedor.NplVen, | 
| 193 | PRO: '', | 192 | PRO: '', | 
| 194 | REC_ANT: 0, | 193 | REC_ANT: 0, | 
| 195 | SUC: parseInt($scope.puntoVenta), | 194 | SUC: parseInt($scope.puntoVenta), | 
| 196 | TCA: 1, | 195 | TCA: 1, | 
| 197 | TCO: 'FT', | 196 | TCO: 'FT', | 
| 198 | TFI: '', | 197 | TFI: '', | 
| 199 | TIP: $scope.factura.cliente.tipoFactura, | 198 | TIP: $scope.factura.cliente.tipoFactura, | 
| 200 | TIV: 0, // TODO | 199 | TIV: 0, // TODO | 
| 201 | TOT: $scope.getTotal(), | 200 | TOT: $scope.getTotal(), | 
| 202 | TUR: 0, // TODO | 201 | TUR: 0, // TODO | 
| 203 | VEN: $scope.factura.vendedor.CodVen, | 202 | VEN: $scope.factura.vendedor.CodVen, | 
| 204 | VTO_CLI: '', | 203 | VTO_CLI: '', | 
| 205 | ZON: 1, // TODO | 204 | ZON: 1, // TODO | 
| 206 | OBSERVACIONES: $scope.factura.observaciones | 205 | OBSERVACIONES: $scope.factura.observaciones | 
| 207 | }, | 206 | }, | 
| 208 | cuerpo: $scope.articulosFiltro(), | 207 | cuerpo: $scope.articulosFiltro(), | 
| 209 | despachos: $scope.factura.despachos, | 208 | despachos: $scope.factura.despachos, | 
| 210 | formaPago: formaPago | 209 | formaPago: formaPago | 
| 211 | }; | 210 | }; | 
| 212 | 211 | ||
| 213 | crearFacturaService.guardarFactura(save).then(function (res) { | 212 | crearFacturaService.guardarFactura(save).then(function (res) { | 
| 214 | 213 | ||
| 215 | focaBotoneraLateralService.endGuardar(true); | 214 | focaBotoneraLateralService.endGuardar(true); | 
| 216 | 215 | ||
| 217 | focaModalService.alert('Comprobante guardado con éxito'); | 216 | focaModalService.alert('Comprobante guardado con éxito'); | 
| 218 | 217 | ||
| 219 | config(); | 218 | config(); | 
| 220 | 219 | ||
| 221 | }).catch(function (err) { | 220 | }).catch(function (err) { | 
| 222 | focaModalService.alert('Hubo un error al guardar la factura'); | 221 | focaModalService.alert('Hubo un error al guardar la factura'); | 
| 223 | console.error(err); | 222 | console.error(err); | 
| 224 | }); | 223 | }); | 
| 225 | 224 | ||
| 226 | }; | 225 | }; | 
| 227 | 226 | ||
| 228 | $scope.seleccionarCliente = function () { | 227 | $scope.seleccionarCliente = function () { | 
| 229 | 228 | ||
| 230 | var modalInstance = $uibModal.open( | 229 | var modalInstance = $uibModal.open( | 
| 231 | { | 230 | { | 
| 232 | ariaLabelledBy: 'Busqueda de Cliente', | 231 | ariaLabelledBy: 'Busqueda de Cliente', | 
| 233 | templateUrl: 'foca-busqueda-cliente-modal.html', | 232 | templateUrl: 'foca-busqueda-cliente-modal.html', | 
| 234 | controller: 'focaBusquedaClienteModalController', | 233 | controller: 'focaBusquedaClienteModalController', | 
| 235 | resolve: { | 234 | resolve: { | 
| 236 | vendedor: function () { return null; }, | 235 | vendedor: function () { return null; }, | 
| 237 | cobrador: function () { return null; } | 236 | cobrador: function () { return null; } | 
| 238 | }, | 237 | }, | 
| 239 | size: 'lg' | 238 | size: 'lg' | 
| 240 | } | 239 | } | 
| 241 | ); | 240 | ); | 
| 242 | modalInstance.result.then( | 241 | modalInstance.result.then( | 
| 243 | function (cliente) { | 242 | function (cliente) { | 
| 244 | var modalInstance = $uibModal.open( | 243 | var modalInstance = $uibModal.open( | 
| 245 | { | 244 | { | 
| 246 | templateUrl: 'modal-estado-cuenta.html', | 245 | templateUrl: 'modal-estado-cuenta.html', | 
| 247 | controller: 'focaModalEstadoCuentaController', | 246 | controller: 'focaModalEstadoCuentaController', | 
| 248 | size: 'lg', | 247 | size: 'lg', | 
| 249 | resolve: { | 248 | resolve: { | 
| 250 | parametros: function () { return { idCliente: cliente.cod }; }, | 249 | parametros: function () { return { idCliente: cliente.cod }; }, | 
| 251 | } | 250 | } | 
| 252 | } | 251 | } | 
| 253 | ); | 252 | ); | 
| 254 | modalInstance.result | 253 | modalInstance.result | 
| 255 | .then(function (data) { | 254 | .then(function (data) { | 
| 256 | 255 | ||
| 257 | $scope.factura.cliente = cliente; | 256 | $scope.factura.cliente = cliente; | 
| 258 | 257 | ||
| 259 | $scope.$broadcast('addCabecera', { | 258 | $scope.$broadcast('addCabecera', { | 
| 260 | label: 'Cliente:', | 259 | label: 'Cliente:', | 
| 261 | valor: $filter('rellenarDigitos')(cliente.cod, 3) + | 260 | valor: $filter('rellenarDigitos')(cliente.cod, 3) + | 
| 262 | ' - ' + cliente.nom | 261 | ' - ' + cliente.nom | 
| 263 | }); | 262 | }); | 
| 264 | 263 | ||
| 265 | $filter('filter')($scope.botonera, | 264 | $filter('filter')($scope.botonera, | 
| 266 | { label: 'Cliente' })[0].checked = true; | 265 | { label: 'Cliente' })[0].checked = true; | 
| 267 | 266 | ||
| 268 | $scope.$broadcast('addCabecera', { | 267 | $scope.$broadcast('addCabecera', { | 
| 269 | label: 'Tipo de pago: ', | 268 | label: 'Tipo de pago: ', | 
| 270 | valor: data | 269 | valor: data | 
| 271 | }); | 270 | }); | 
| 272 | }) | 271 | }) | 
| 273 | .catch(function () { | 272 | .catch(function () { | 
| 274 | 273 | ||
| 275 | $scope.seleccionarCliente(); | 274 | $scope.seleccionarCliente(); | 
| 276 | }); | 275 | }); | 
| 277 | 276 | ||
| 278 | }, function () { | 277 | }, function () { | 
| 279 | } | 278 | } | 
| 280 | ); | 279 | ); | 
| 281 | 280 | ||
| 282 | }; | 281 | }; | 
| 283 | 282 | ||
| 284 | $scope.seleccionarVendedor = function () { | 283 | $scope.seleccionarVendedor = function () { | 
| 285 | var parametrosModal = { | 284 | var parametrosModal = { | 
| 286 | titulo: 'Búsqueda vendedores', | 285 | titulo: 'Búsqueda vendedores', | 
| 287 | query: '/vendedor-playa', | 286 | query: '/vendedor-playa', | 
| 288 | columnas: [ | 287 | columnas: [ | 
| 289 | { | 288 | { | 
| 290 | propiedad: 'CodVen', | 289 | propiedad: 'CodVen', | 
| 291 | nombre: 'Código', | 290 | nombre: 'Código', | 
| 292 | filtro: { | 291 | filtro: { | 
| 293 | nombre: 'rellenarDigitos', | 292 | nombre: 'rellenarDigitos', | 
| 294 | parametro: 3 | 293 | parametro: 3 | 
| 295 | } | 294 | } | 
| 296 | }, | 295 | }, | 
| 297 | { | 296 | { | 
| 298 | propiedad: 'NomVen', | 297 | propiedad: 'NomVen', | 
| 299 | nombre: 'Nombre' | 298 | nombre: 'Nombre' | 
| 300 | } | 299 | } | 
| 301 | ], | 300 | ], | 
| 302 | size: 'md' | 301 | size: 'md' | 
| 303 | }; | 302 | }; | 
| 304 | focaModalService.modal(parametrosModal).then( | 303 | focaModalService.modal(parametrosModal).then( | 
| 305 | function (vendedor) { | 304 | function (vendedor) { | 
| 306 | 305 | ||
| 307 | indicarPassword(vendedor) | 306 | indicarPassword(vendedor) | 
| 308 | .then(function () { | 307 | .then(function () { | 
| 309 | validarPlanillaVendedor(vendedor) | 308 | validarPlanillaVendedor(vendedor) | 
| 310 | .then(function () { | 309 | .then(function () { | 
| 311 | 310 | ||
| 312 | $filter('filter')($scope.botonera, { | 311 | $filter('filter')($scope.botonera, { | 
| 313 | label: 'Vendedor' | 312 | label: 'Vendedor' | 
| 314 | })[0].checked = true; | 313 | })[0].checked = true; | 
| 315 | 314 | ||
| 316 | $scope.$broadcast('addCabecera', { | 315 | $scope.$broadcast('addCabecera', { | 
| 317 | label: 'Vendedor:', | 316 | label: 'Vendedor:', | 
| 318 | valor: $filter('rellenarDigitos')(vendedor.CodVen, 3) + | 317 | valor: $filter('rellenarDigitos')(vendedor.CodVen, 3) + | 
| 319 | ' - ' + | 318 | ' - ' + | 
| 320 | vendedor.NomVen | 319 | vendedor.NomVen | 
| 321 | }); | 320 | }); | 
| 322 | 321 | ||
| 323 | $scope.factura.vendedor = vendedor; | 322 | $scope.factura.vendedor = vendedor; | 
| 324 | 323 | ||
| 325 | getProductosByPlanilla(vendedor.NplVen); | 324 | getProductosByPlanilla(vendedor.NplVen); | 
| 326 | }) | 325 | }) | 
| 327 | .catch($scope.seleccionarVendedor); | 326 | .catch($scope.seleccionarVendedor); | 
| 328 | }) | 327 | }) | 
| 329 | .catch(function (err) { | 328 | .catch(function (err) { | 
| 330 | console.error(err); | 329 | console.error(err); | 
| 331 | }); | 330 | }); | 
| 332 | 331 | ||
| 333 | }, function () { } | 332 | }, function () { } | 
| 334 | ); | 333 | ); | 
| 335 | }; | 334 | }; | 
| 336 | 335 | ||
| 337 | $scope.seleccionarMoneda = function () { | 336 | $scope.seleccionarMoneda = function () { | 
| 338 | 337 | ||
| 339 | var parametrosModal = { | 338 | var parametrosModal = { | 
| 340 | titulo: 'Búsqueda de monedas', | 339 | titulo: 'Búsqueda de monedas', | 
| 341 | query: '/moneda', | 340 | query: '/moneda', | 
| 342 | columnas: [ | 341 | columnas: [ | 
| 343 | { | 342 | { | 
| 344 | propiedad: 'DETALLE', | 343 | propiedad: 'DETALLE', | 
| 345 | nombre: 'Nombre' | 344 | nombre: 'Nombre' | 
| 346 | }, | 345 | }, | 
| 347 | { | 346 | { | 
| 348 | propiedad: 'SIMBOLO', | 347 | propiedad: 'SIMBOLO', | 
| 349 | nombre: 'Símbolo' | 348 | nombre: 'Símbolo' | 
| 350 | } | 349 | } | 
| 351 | ], | 350 | ], | 
| 352 | size: 'md' | 351 | size: 'md' | 
| 353 | }; | 352 | }; | 
| 354 | focaModalService.modal(parametrosModal).then( | 353 | focaModalService.modal(parametrosModal).then( | 
| 355 | function (moneda) { | 354 | function (moneda) { | 
| 356 | 355 | ||
| 357 | if (moneda.ID !== 1) { | 356 | if (moneda.ID !== 1) { | 
| 358 | $scope.abrirModalCotizacion(moneda); | 357 | $scope.abrirModalCotizacion(moneda); | 
| 359 | return; | 358 | return; | 
| 360 | } | 359 | } | 
| 361 | 360 | ||
| 362 | crearRemitoService.getCotizacionByIdMoneda(1) | 361 | crearRemitoService.getCotizacionByIdMoneda(1) | 
| 363 | .then(function (res) { | 362 | .then(function (res) { | 
| 364 | 363 | ||
| 365 | var cotizacionPArgentino = res.data[0].cotizaciones[0]; | 364 | var cotizacionPArgentino = res.data[0].cotizaciones[0]; | 
| 366 | cotizacionPArgentino.moneda = moneda; | 365 | cotizacionPArgentino.moneda = moneda; | 
| 367 | 366 | ||
| 368 | actualizarCabeceraMoneda(cotizacionPArgentino); | 367 | actualizarCabeceraMoneda(cotizacionPArgentino); | 
| 369 | 368 | ||
| 370 | $scope.remito.cotizacion = cotizacionPArgentino; | 369 | $scope.remito.cotizacion = cotizacionPArgentino; | 
| 371 | }); | 370 | }); | 
| 372 | }, function () { | 371 | }, function () { | 
| 373 | 372 | ||
| 374 | } | 373 | } | 
| 375 | ); | 374 | ); | 
| 376 | }; | 375 | }; | 
| 377 | 376 | ||
| 378 | $scope.abrirModalCotizacion = function (moneda) { | 377 | $scope.abrirModalCotizacion = function (moneda) { | 
| 379 | var modalInstance = $uibModal.open( | 378 | var modalInstance = $uibModal.open( | 
| 380 | { | 379 | { | 
| 381 | ariaLabelledBy: 'Busqueda de Cotización', | 380 | ariaLabelledBy: 'Busqueda de Cotización', | 
| 382 | templateUrl: 'modal-cotizacion.html', | 381 | templateUrl: 'modal-cotizacion.html', | 
| 383 | controller: 'focaModalCotizacionController', | 382 | controller: 'focaModalCotizacionController', | 
| 384 | size: 'lg', | 383 | size: 'lg', | 
| 385 | resolve: { idMoneda: function () { return moneda.ID; } } | 384 | resolve: { idMoneda: function () { return moneda.ID; } } | 
| 386 | } | 385 | } | 
| 387 | ); | 386 | ); | 
| 388 | modalInstance.result.then( | 387 | modalInstance.result.then( | 
| 389 | function (cotizacion) { | 388 | function (cotizacion) { | 
| 390 | 389 | ||
| 391 | cotizacion.moneda = moneda; | 390 | cotizacion.moneda = moneda; | 
| 392 | actualizarCabeceraMoneda(cotizacion); | 391 | actualizarCabeceraMoneda(cotizacion); | 
| 393 | $scope.factura.cotizacion = cotizacion; | 392 | $scope.factura.cotizacion = cotizacion; | 
| 394 | 393 | ||
| 395 | }, function () { | 394 | }, function () { | 
| 396 | 395 | ||
| 397 | } | 396 | } | 
| 398 | ); | 397 | ); | 
| 399 | }; | 398 | }; | 
| 400 | 399 | ||
| 401 | $scope.seleccionarObservaciones = function () { | 400 | $scope.seleccionarObservaciones = function () { | 
| 402 | var observacion = { | 401 | var observacion = { | 
| 403 | titulo: 'Ingrese Observaciones', | 402 | titulo: 'Ingrese Observaciones', | 
| 404 | value: $scope.factura.observaciones, | 403 | value: $scope.factura.observaciones, | 
| 405 | maxlength: 155, | 404 | maxlength: 155, | 
| 406 | textarea: true | 405 | textarea: true | 
| 407 | }; | 406 | }; | 
| 408 | 407 | ||
| 409 | focaModalService | 408 | focaModalService | 
| 410 | .prompt(observacion) | 409 | .prompt(observacion) | 
| 411 | .then(function (observaciones) { | 410 | .then(function (observaciones) { | 
| 412 | $scope.factura.observaciones = observaciones; | 411 | $scope.factura.observaciones = observaciones; | 
| 413 | }); | 412 | }); | 
| 414 | }; | 413 | }; | 
| 415 | 414 | ||
| 416 | $scope.articulosFiltro = function () { | 415 | $scope.articulosFiltro = function () { | 
| 417 | return $scope.factura.articulosFactura.filter(function (articulo) { | 416 | return $scope.factura.articulosFactura.filter(function (articulo) { | 
| 418 | return !articulo.desactivado; | 417 | return !articulo.desactivado; | 
| 419 | }); | 418 | }); | 
| 420 | }; | 419 | }; | 
| 421 | 420 | ||
| 422 | $scope.getTotal = function () { | 421 | $scope.getTotal = function () { | 
| 423 | 422 | ||
| 424 | var total = 0; | 423 | var total = 0; | 
| 425 | 424 | ||
| 426 | $scope.articulosFiltro().forEach(function (articulo) { | 425 | $scope.articulosFiltro().forEach(function (articulo) { | 
| 427 | total += articulo.PUN * articulo.CAN; | 426 | total += articulo.PUN * articulo.CAN; | 
| 428 | }); | 427 | }); | 
| 429 | 428 | ||
| 430 | return parseFloat(total.toFixed(2)); | 429 | return parseFloat(total.toFixed(2)); | 
| 431 | }; | 430 | }; | 
| 432 | 431 | ||
| 433 | $scope.quitarDespacho = function (articulo, index) { | 432 | $scope.quitarDespacho = function (articulo, index) { | 
| 434 | 433 | ||
| 435 | crearFacturaService | 434 | crearFacturaService | 
| 436 | .setearDespachoDesocupado({ | 435 | .setearDespachoDesocupado({ | 
| 437 | surtidor: $scope.factura.despachos[index].SUR, | 436 | surtidor: $scope.factura.despachos[index].SUR, | 
| 438 | producto: $scope.factura.despachos[index].PRO, | 437 | producto: $scope.factura.despachos[index].PRO, | 
| 439 | carga: $scope.factura.despachos[index].CAR, | 438 | carga: $scope.factura.despachos[index].CAR, | 
| 440 | planilla: $scope.factura.despachos[index].PLA | 439 | planilla: $scope.factura.despachos[index].PLA | 
| 441 | }) | 440 | }) | 
| 442 | .then(function () { | 441 | .then(function () { | 
| 443 | articulo.desactivado = true; | 442 | articulo.desactivado = true; | 
| 444 | $scope.factura.despachos.splice(index, 1); | 443 | $scope.factura.despachos.splice(index, 1); | 
| 445 | }) | 444 | }) | 
| 446 | .catch(function () { | 445 | .catch(function () { | 
| 447 | focaModalService.alert('Hubo un error al desasociar este despacho'); | 446 | focaModalService.alert('Hubo un error al desasociar este despacho'); | 
| 448 | }); | 447 | }); | 
| 449 | }; | 448 | }; | 
| 450 | 449 | ||
| 451 | function getProductosByPlanilla(numeroPlanilla) { | 450 | function getProductosByPlanilla(numeroPlanilla) { | 
| 452 | 451 | ||
| 453 | crearFacturaService.getProductosByPlanilla(numeroPlanilla).then(function (res) { | 452 | crearFacturaService.getProductosByPlanilla(numeroPlanilla).then(function (res) { | 
| 454 | 453 | ||
| 455 | if (!res.data.length) { | 454 | if (!res.data.length) { | 
| 456 | 455 | ||
| 457 | focaModalService.alert('No hay despachos disponibles por el momento'); | 456 | focaModalService.alert('No hay despachos disponibles por el momento'); | 
| 458 | return; | 457 | return; | 
| 459 | } | 458 | } | 
| 460 | 459 | ||
| 461 | $scope.botoneraProductos.length = 0; | 460 | $scope.botoneraProductos.length = 0; | 
| 462 | res.data.forEach(function (producto) { | 461 | res.data.forEach(function (producto) { | 
| 463 | 462 | ||
| 464 | $scope.botoneraProductos.push({ | 463 | $scope.botoneraProductos.push({ | 
| 465 | label: producto.DetArt, | 464 | label: producto.DetArt, | 
| 466 | image: producto.nombreImagen, | 465 | image: producto.nombreImagen, | 
| 467 | imageDefault: 'productoDefault.png' | 466 | imageDefault: 'productoDefault.png' | 
| 468 | }); | 467 | }); | 
| 469 | 468 | ||
| 470 | |||
| 471 | crearFuncionesProductos(producto); | 469 | crearFuncionesProductos(producto); | 
| 472 | |||
| 473 | }); | 470 | }); | 
| 474 | }); | 471 | }); | 
| 475 | } | 472 | } | 
| 476 | 473 | ||
| 477 | $scope.seleccionarBusquedaProductos = function () { | 474 | $scope.seleccionarBusquedaProductos = function () { | 
| 475 | |||
| 476 | if (angular.equals({}, $scope.factura.vendedor)) { | ||
| 477 | |||
| 478 | focaModalService.alert('Seleccione Vendedor'); | ||
| 479 | return false; | ||
| 480 | } | ||
| 478 | 481 | ||
| 479 | var modalInstance = $uibModal.open( | 482 | var modalInstance = $uibModal.open( | 
| 480 | { | 483 | { | 
| 481 | ariaLabelledBy: 'Busqueda de Productos', | 484 | ariaLabelledBy: 'Busqueda de Productos', | 
| 482 | templateUrl: 'modal-busqueda-productos.html', | 485 | templateUrl: 'modal-busqueda-productos.html', | 
| 483 | controller: 'modalBusquedaProductosCtrl', | 486 | controller: 'modalBusquedaProductosCtrl', | 
| 484 | resolve: { | 487 | resolve: { | 
| 485 | parametroProducto: { | 488 | parametroProducto: { | 
| 486 | idLista: null, | 489 | idLista: null, | 
| 487 | cotizacion: $scope.factura.cotizacion.VENDEDOR, | 490 | cotizacion: $scope.factura.cotizacion.VENDEDOR, | 
| 488 | simbolo: $scope.factura.cotizacion.moneda.SIMBOLO, | 491 | simbolo: $scope.factura.cotizacion.moneda.SIMBOLO, | 
| 489 | buscarTodos: true | 492 | buscarTodos: true | 
| 490 | } | 493 | } | 
| 491 | }, | 494 | }, | 
| 492 | size: 'lg' | 495 | size: 'lg' | 
| 493 | } | 496 | } | 
| 494 | ); | 497 | ); | 
| 495 | 498 | ||
| 496 | modalInstance.result | 499 | modalInstance.result | 
| 497 | .then(function (producto) { | 500 | .then(function (producto) { | 
| 498 | 501 | ||
| 499 | var articulo = { | 502 | var articulo = { | 
| 500 | TIP: $scope.factura.cliente.tipoFactura, | 503 | TIP: $scope.factura.cliente.tipoFactura, | 
| 501 | TCO: 'FT', | 504 | TCO: 'FT', | 
| 502 | SUC: parseInt($scope.puntoVenta), | 505 | SUC: parseInt($scope.puntoVenta), | 
| 503 | ORD: $scope.articulosFiltro().length + 1, | 506 | ORD: $scope.articulosFiltro().length + 1, | 
| 504 | SEC: producto.sector, | 507 | SEC: producto.sector, | 
| 505 | ART: producto.codigo, | 508 | ART: producto.codigo, | 
| 506 | RUB: producto.CodRub, | 509 | RUB: producto.CodRub, | 
| 507 | DES: producto.descripcionLarga, | 510 | DES: producto.descripcionLarga, | 
| 508 | PUN: producto.precio, // TODO | 511 | PUN: producto.precio, // TODO | 
| 509 | IVA: producto.IMPIVA, // TODO | 512 | IVA: producto.IMPIVA, // TODO | 
| 510 | NET: 0, // TODO | 513 | NET: 0, // TODO | 
| 511 | NEX: 0, // TODO | 514 | NEX: 0, // TODO | 
| 512 | IMI: producto.ImpInt, // TODO | 515 | IMI: producto.ImpInt, // TODO | 
| 513 | IMI2: producto.ImpInt2, // TODO | 516 | IMI2: producto.ImpInt2, // TODO | 
| 514 | IMI3: producto.ImpInt3, // TODO | 517 | IMI3: producto.ImpInt3, // TODO | 
| 515 | PUT: producto.PreNet, // TODO | 518 | PUT: producto.PreNet, // TODO | 
| 516 | SUR: 0, | 519 | SUR: 0, | 
| 517 | PLA: $scope.factura.vendedor.NplVen, | 520 | PLA: $scope.factura.vendedor.NplVen, | 
| 518 | LUG: $scope.factura.vendedor.LugVen, | 521 | LUG: $scope.factura.vendedor.LugVen, | 
| 519 | LEG: $scope.factura.vendedor.CodVen, | 522 | LEG: $scope.factura.vendedor.CodVen, | 
| 520 | TUR: $scope.factura.vendedor.TurVen, | 523 | TUR: $scope.factura.vendedor.TurVen, | 
| 521 | ORDEN_PRECOMPRA: '', | 524 | ORDEN_PRECOMPRA: '', | 
| 522 | ESC: producto.tipoFactura === 'L' ? 1 : 0, | 525 | ESC: producto.tipoFactura === 'L' ? 1 : 0, | 
| 523 | CMF: 0, | 526 | CMF: 0, | 
| 524 | PTA: 0, | 527 | PTA: 0, | 
| 525 | IVS: 0, | 528 | IVS: 0, | 
| 526 | TIVA: 0, | 529 | TIVA: 0, | 
| 527 | CON: 0, | 530 | CON: 0, | 
| 528 | SINO: '', | 531 | SINO: '', | 
| 529 | ORD_TRA: 0, | 532 | ORD_TRA: 0, | 
| 530 | IMP_DESP: 0, | 533 | IMP_DESP: 0, | 
| 531 | PCD: 0, | 534 | PCD: 0, | 
| 532 | RTO: '' | 535 | RTO: '' | 
| 533 | }; | 536 | }; | 
| 534 | // crearFacturaService.setearDespachoOcupado({ | 537 | // crearFacturaService.setearDespachoOcupado({ | 
| 535 | // surtidor: articulo.SUR, | 538 | // surtidor: articulo.SUR, | 
| 536 | // producto: articulo.PRO, | 539 | // producto: articulo.PRO, | 
| 537 | // carga: articulo.CAR | 540 | // carga: articulo.CAR | 
| 538 | // }) | 541 | // }) | 
| 539 | // .then(function () { | 542 | // .then(function () { | 
| 540 | $scope.factura.articulosFactura.push(articulo); | 543 | $scope.factura.articulosFactura.push(articulo); | 
| 541 | $scope.cambioEdit(articulo, 'cantidad'); | 544 | $scope.cambioEdit(articulo, 'cantidad'); | 
| 542 | // }) | 545 | // }) | 
| 543 | // .catch(function (err) { | 546 | // .catch(function (err) { | 
| 544 | 547 | ||
| 545 | // focaModalService.alert('El despacho esta en uso'); | 548 | // focaModalService.alert('El despacho esta en uso'); | 
| 546 | // }); | 549 | // }); | 
| 547 | }) | 550 | }) | 
| 548 | .catch(function (e) { console.error(e); }); | 551 | .catch(function (e) { console.error(e); }); | 
| 549 | }; | 552 | }; | 
| 550 | 553 | ||
| 551 | function crearFuncionesProductos(producto) { | 554 | function crearFuncionesProductos(producto) { | 
| 552 | 555 | ||
| 553 | $scope[nombreFuncion(producto.DetArt)] = function () { | 556 | $scope[nombreFuncion(producto.DetArt)] = function () { | 
| 554 | 557 | ||
| 555 | if (angular.equals($scope.factura.cliente, {})) { | 558 | if (angular.equals($scope.factura.cliente, {})) { | 
| 556 | focaModalService.alert('Seleccione cliente'); | 559 | focaModalService.alert('Seleccione cliente'); | 
| 557 | return; | 560 | return; | 
| 558 | } | 561 | } | 
| 559 | 562 | ||
| 560 | var modalInstance = $uibModal.open( | 563 | var modalInstance = $uibModal.open( | 
| 561 | { | 564 | { | 
| 562 | templateUrl: 'modal-combustibles.html', | 565 | templateUrl: 'modal-combustibles.html', | 
| 563 | controller: 'focaModalCombustiblesController', | 566 | controller: 'focaModalCombustiblesController', | 
| 564 | resolve: { | 567 | resolve: { | 
| 565 | parametros: function () { | 568 | parametros: function () { | 
| 566 | return { | 569 | return { | 
| 567 | despachos: producto.despachos, | 570 | despachos: producto.despachos, | 
| 568 | nombreProducto: producto.DetArt | 571 | nombreProducto: producto.DetArt | 
| 569 | }; | 572 | }; | 
| 570 | } | 573 | } | 
| 571 | }, | 574 | }, | 
| 572 | size: 'md' | 575 | size: 'md' | 
| 573 | } | 576 | } | 
| 574 | ); | 577 | ); | 
| 575 | 578 | ||
| 576 | modalInstance.result.then(function (despacho) { | 579 | modalInstance.result.then(function (despacho) { | 
| 577 | 580 | ||
| 578 | var articulo = { | 581 | var articulo = { | 
| 579 | TIP: $scope.factura.cliente.tipoFactura, | 582 | TIP: $scope.factura.cliente.tipoFactura, | 
| 580 | TCO: 'FT', | 583 | TCO: 'FT', | 
| 581 | SUC: parseInt($scope.puntoVenta), | 584 | SUC: parseInt($scope.puntoVenta), | 
| 582 | ORD: $scope.articulosFiltro().length + 1, | 585 | ORD: $scope.articulosFiltro().length + 1, | 
| 583 | SEC: despacho.SEC, | 586 | SEC: despacho.SEC, | 
| 584 | ART: despacho.PRO, | 587 | ART: despacho.PRO, | 
| 585 | RUB: producto.CodRub, | 588 | RUB: producto.CodRub, | 
| 586 | DES: producto.DetArt, | 589 | DES: producto.DetArt, | 
| 587 | CAN: despacho.LTS, | 590 | CAN: despacho.LTS, | 
| 588 | PUN: producto.PreVen, // TODO | 591 | PUN: producto.PreVen, // TODO | 
| 589 | IVA: producto.IMPIVA, // TODO | 592 | IVA: producto.IMPIVA, // TODO | 
| 590 | NET: 0, // TODO | 593 | NET: 0, // TODO | 
| 591 | NEX: 0, // TODO | 594 | NEX: 0, // TODO | 
| 592 | IMI: producto.ImpInt, // TODO | 595 | IMI: producto.ImpInt, // TODO | 
| 593 | IMI2: producto.ImpInt2, // TODO | 596 | IMI2: producto.ImpInt2, // TODO | 
| 594 | IMI3: producto.ImpInt3, // TODO | 597 | IMI3: producto.ImpInt3, // TODO | 
| 595 | PUT: producto.PreNet, // TODO | 598 | PUT: producto.PreNet, // TODO | 
| 596 | SUR: despacho.SUR, | 599 | SUR: despacho.SUR, | 
| 597 | PLA: despacho.PLA, | 600 | PLA: despacho.PLA, | 
| 598 | LUG: despacho.LUG, | 601 | LUG: despacho.LUG, | 
| 599 | LEG: $scope.factura.vendedor.CodVen, | 602 | LEG: $scope.factura.vendedor.CodVen, | 
| 600 | TUR: $scope.factura.vendedor.TurVen, | 603 | TUR: $scope.factura.vendedor.TurVen, | 
| 601 | ORDEN_PRECOMPRA: '', | 604 | ORDEN_PRECOMPRA: '', | 
| 602 | ESC: producto.tipoFactura === 'L' ? 1 : 0, | 605 | ESC: producto.tipoFactura === 'L' ? 1 : 0, | 
| 603 | CMF: 0, | 606 | CMF: 0, | 
| 604 | PTA: 0, | 607 | PTA: 0, | 
| 605 | IVS: 0, | 608 | IVS: 0, | 
| 606 | TIVA: 0, | 609 | TIVA: 0, | 
| 607 | CON: 0, | 610 | CON: 0, | 
| 608 | SINO: '', | 611 | SINO: '', | 
| 609 | ORD_TRA: 0, | 612 | ORD_TRA: 0, | 
| 610 | IMP_DESP: 0, | 613 | IMP_DESP: 0, | 
| 611 | PCD: 0, | 614 | PCD: 0, | 
| 612 | RTO: '' | 615 | RTO: '' | 
| 613 | }; | 616 | }; | 
| 614 | 617 | ||
| 615 | crearFacturaService.setearDespachoOcupado({ | 618 | crearFacturaService.setearDespachoOcupado({ | 
| 616 | surtidor: despacho.SUR, | 619 | surtidor: despacho.SUR, | 
| 617 | producto: despacho.PRO, | 620 | producto: despacho.PRO, | 
| 618 | carga: despacho.CAR | 621 | carga: despacho.CAR | 
| 619 | }) | 622 | }) | 
| 620 | .then(function () { | 623 | .then(function () { | 
| 621 | $scope.factura.articulosFactura.push(articulo); | 624 | $scope.factura.articulosFactura.push(articulo); | 
| 622 | $scope.factura.despachos.push(despacho); | 625 | $scope.factura.despachos.push(despacho); | 
| 623 | }) | 626 | }) | 
| 624 | .catch(function (err) { | 627 | .catch(function (err) { | 
| 625 | 628 | ||
| 626 | console.error(err); | 629 | console.error(err); | 
| 627 | focaModalService.alert('El despacho esta en uso'); | 630 | focaModalService.alert('El despacho esta en uso'); | 
| 628 | }); | 631 | }); | 
| 629 | 632 | ||
| 630 | }) | 633 | }) | 
| 631 | .catch(function (err) { | 634 | .catch(function (err) { | 
| 632 | console.error(err); | 635 | console.error(err); | 
| 633 | }); | 636 | }); | 
| 634 | 637 | ||
| 635 | }; | 638 | }; | 
| 636 | } | 639 | } | 
| 637 | 640 | ||
| 638 | function nombreFuncion(string) { | 641 | function nombreFuncion(string) { | 
| 639 | var texto = 'seleccionar'; | 642 | var texto = 'seleccionar'; | 
| 640 | var arr = string.split(' '); | 643 | var arr = string.split(' '); | 
| 641 | arr.forEach(function (palabra) { | 644 | arr.forEach(function (palabra) { | 
| 642 | palabra = palabra.charAt(0).toUpperCase() + palabra.slice(1); | 645 | palabra = palabra.charAt(0).toUpperCase() + palabra.slice(1); | 
| 643 | texto += palabra; | 646 | texto += palabra; | 
| 644 | }); | 647 | }); | 
| 645 | return texto; | 648 | return texto; | 
| 646 | } | 649 | } | 
| 647 | 650 | ||
| 648 | function indicarPassword(vendedor) { | 651 | function indicarPassword(vendedor) { | 
| 649 | 652 | ||
| 650 | return new Promise(function (resolve, reject) { | 653 | return new Promise(function (resolve, reject) { | 
| 651 | 654 | ||
| 652 | function openPrompt() { | 655 | function openPrompt() { | 
| 653 | return focaModalService | 656 | return focaModalService | 
| 654 | .prompt({ | 657 | .prompt({ | 
| 655 | titulo: 'Indique Contraseña', | 658 | titulo: 'Indique Contraseña', | 
| 656 | value: '' | 659 | value: '' | 
| 657 | }) | 660 | }) | 
| 658 | .then(function (contraseña) { | 661 | .then(function (contraseña) { | 
| 659 | 662 | ||
| 660 | if (contraseña !== vendedor.ClaVen.trim()) { | 663 | if (contraseña !== vendedor.ClaVen.trim()) { | 
| 661 | 664 | ||
| 662 | focaModalService.alert('Clave incorrecta').then(function () { | 665 | focaModalService.alert('Clave incorrecta').then(function () { | 
| 663 | openPrompt(vendedor); | 666 | openPrompt(vendedor); | 
| 664 | }); | 667 | }); | 
| 665 | } else { | 668 | } else { | 
| 666 | resolve(); | 669 | resolve(); | 
| 667 | } | 670 | } | 
| 668 | }) | 671 | }) | 
| 669 | .catch(reject);; | 672 | .catch(reject);; | 
| 670 | } | 673 | } | 
| 671 | 674 | ||
| 672 | openPrompt() | 675 | openPrompt() | 
| 673 | }); | 676 | }); | 
| 674 | } | 677 | } | 
| 675 | 678 | ||
| 676 | function validarPlanillaVendedor(vendedor) { | 679 | function validarPlanillaVendedor(vendedor) { | 
| 677 | 680 | ||
| 678 | return new Promise(function (resolve, reject) { | 681 | return new Promise(function (resolve, reject) { | 
| 679 | 682 | ||
| 680 | crearFacturaService | 683 | crearFacturaService | 
| 681 | .validarPlanillaVendedor(vendedor.CodVen.toString().trim()) | 684 | .validarPlanillaVendedor(vendedor.CodVen.toString().trim()) | 
| 682 | .then(function (res) { | 685 | .then(function (res) { | 
| 683 | 686 | ||
| 684 | if (!res.data.length) { | 687 | if (!res.data.length) { | 
| 685 | 688 | ||
| 686 | focaModalService | 689 | focaModalService | 
| 687 | .alert('No se encontró planilla abierta para el vendedor') | 690 | .alert('No se encontró planilla abierta para el vendedor') | 
| 688 | .then(reject); | 691 | .then(reject); | 
| 689 | 692 | ||
| 690 | } else { | 693 | } else { | 
| 691 | resolve(); | 694 | resolve(); | 
| 692 | } | 695 | } | 
| 693 | 696 | ||
| 694 | }) | 697 | }) | 
| 695 | .catch(function (err) { | 698 | .catch(function (err) { | 
| 696 | console.log(err) | 699 | console.log(err) | 
| 697 | reject(); | 700 | reject(); | 
| 698 | }); | 701 | }); | 
| 699 | }); | 702 | }); | 
| 700 | } | 703 | } | 
| 701 | 704 | ||
| 702 | function rellenar(relleno, longitud) { | 705 | function rellenar(relleno, longitud) { | 
| 703 | relleno = '' + relleno; | 706 | relleno = '' + relleno; | 
| 704 | while (relleno.length < longitud) { | 707 | while (relleno.length < longitud) { | 
| 705 | relleno = '0' + relleno; | 708 | relleno = '0' + relleno; | 
| 706 | } | 709 | } | 
| 707 | return relleno; | 710 | return relleno; | 
| 708 | } | 711 | } | 
| 709 | 712 | ||
| 710 | function salir() { | 713 | function salir() { | 
| 711 | var confirmacion = false; | 714 | var confirmacion = false; | 
| 712 | 715 | ||
| 713 | if (!angular.equals($scope.factura, $scope.inicial)) { | 716 | if (!angular.equals($scope.factura, $scope.inicial)) { | 
| 714 | confirmacion = true; | 717 | confirmacion = true; | 
| 715 | } | 718 | } | 
| 716 | 719 | ||
| 717 | if (confirmacion) { | 720 | if (confirmacion) { | 
| 718 | focaModalService.confirm( | 721 | focaModalService.confirm( | 
| 719 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 722 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 
| 720 | ).then(function (data) { | 723 | ).then(function (data) { | 
| 721 | if (data) { | 724 | if (data) { | 
| 722 | $location.path('/'); | 725 | $location.path('/'); | 
| 723 | } | 726 | } | 
| 724 | }); | 727 | }); | 
| 725 | } else { | 728 | } else { | 
| 726 | $location.path('/'); | 729 | $location.path('/'); | 
| 727 | } | 730 | } | 
| 728 | } | 731 | } | 
| 729 | 732 | ||
| 730 | function setearFactura(factura) { | 733 | function setearFactura(factura) { | 
| 731 | 734 | ||
| 732 | $scope.$broadcast('cleanCabecera'); | 735 | $scope.$broadcast('cleanCabecera'); | 
| 733 | 736 | ||
| 734 | $scope.cabeceras = []; | 737 | $scope.cabeceras = []; | 
| 735 | 738 | ||
| 736 | if (factura.cotizacion && factura.cotizacion.moneda.CODIGO_AFIP !== 'PES') { | 739 | if (factura.cotizacion && factura.cotizacion.moneda.CODIGO_AFIP !== 'PES') { | 
| 737 | $scope.cabeceras.push({ | 740 | $scope.cabeceras.push({ | 
| 738 | label: 'Moneda:', | 741 | label: 'Moneda:', | 
| 739 | valor: factura.cotizacion.moneda.DETALLE | 742 | valor: factura.cotizacion.moneda.DETALLE | 
| 740 | }); | 743 | }); | 
| 741 | $scope.cabeceras.push({ | 744 | $scope.cabeceras.push({ | 
| 742 | label: 'Fecha cotizacion:', | 745 | label: 'Fecha cotizacion:', | 
| 743 | valor: $filter('date')(factura.cotizacion.FECHA, | 746 | valor: $filter('date')(factura.cotizacion.FECHA, | 
| 744 | 'dd/MM/yyyy') | 747 | 'dd/MM/yyyy') | 
| 745 | }); | 748 | }); | 
| 746 | $scope.cabeceras.push({ | 749 | $scope.cabeceras.push({ | 
| 747 | label: 'Cotizacion:', | 750 | label: 'Cotizacion:', | 
| 748 | valor: $filter('number')(factura.cotizacion.VENDEDOR, | 751 | valor: $filter('number')(factura.cotizacion.VENDEDOR, | 
| 749 | '2') | 752 | '2') | 
| 750 | }); | 753 | }); | 
| 751 | } | 754 | } | 
| 752 | 755 | ||
| 753 | if (factura.cotizacion && factura.cotizacion.moneda) { | 756 | if (factura.cotizacion && factura.cotizacion.moneda) { | 
| 754 | // $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; | 757 | // $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; | 
| 755 | } | 758 | } | 
| 756 | 759 | ||
| 757 | if (factura.cliente && factura.cliente.cod) { | 760 | if (factura.cliente && factura.cliente.cod) { | 
| 758 | $scope.cabeceras.push({ | 761 | $scope.cabeceras.push({ | 
| 759 | label: 'Cliente:', | 762 | label: 'Cliente:', | 
| 760 | valor: $filter('rellenarDigitos')(factura.cliente.cod, 3) + ' - ' + | 763 | valor: $filter('rellenarDigitos')(factura.cliente.cod, 3) + ' - ' + | 
| 761 | factura.cliente.nom | 764 | factura.cliente.nom | 
| 762 | }); | 765 | }); | 
| 763 | 766 | ||
| 764 | $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; | 767 | $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; | 
| 765 | } | 768 | } | 
| 766 | 769 | ||
| 767 | $scope.puntoVenta = rellenar(factura.sucursal, 4); | 770 | $scope.puntoVenta = rellenar(factura.sucursal, 4); | 
| 768 | $scope.comprobante = rellenar(factura.numerofactura, 8); | 771 | $scope.comprobante = rellenar(factura.numerofactura, 8); | 
| 769 | $scope.factura = factura; | 772 | $scope.factura = factura; | 
| 770 | 773 | ||
| 771 | addArrayCabecera($scope.cabeceras); | 774 | addArrayCabecera($scope.cabeceras); | 
| 772 | } | 775 | } | 
| 773 | 776 | ||
| 774 | function getLSFactura() { | 777 | function getLSFactura() { | 
| 775 | var factura = JSON.parse($localStorage.factura || null); | 778 | var factura = JSON.parse($localStorage.factura || null); | 
| 776 | if (factura) { | 779 | if (factura) { | 
| 777 | setearFactura(factura); | 780 | setearFactura(factura); | 
| 778 | delete $localStorage.factura; | 781 | delete $localStorage.factura; | 
| 779 | } | 782 | } | 
| 780 | } | 783 | } | 
| 781 | 784 | ||
| 782 | function addArrayCabecera(array) { | 785 | function addArrayCabecera(array) { | 
| 783 | for (var i = 0; i < array.length; i++) { | 786 | for (var i = 0; i < array.length; i++) { | 
| 784 | $scope.$broadcast('addCabecera', { | 787 | $scope.$broadcast('addCabecera', { | 
| 785 | label: array[i].label, | 788 | label: array[i].label, | 
| 786 | valor: array[i].valor | 789 | valor: array[i].valor | 
| 787 | }); | 790 | }); | 
| 788 | } | 791 | } | 
| 789 | } | 792 | } | 
| 790 | 793 | ||
| 791 | $scope.cambioEdit = function (articulo, propiedad) { | 794 | $scope.cambioEdit = function (articulo, propiedad) { | 
| 792 | if (propiedad === 'cantidad') { | 795 | if (propiedad === 'cantidad') { | 
| 793 | articulo.editCantidad = true; | 796 | articulo.editCantidad = true; | 
| 794 | } | 797 | } | 
| 795 | }; | 798 | }; | 
| 796 | 799 | ||
| 797 | $scope.editarArticulo = function (key, articulo, tmpCantidad) { | 800 | $scope.editarArticulo = function (key, articulo, tmpCantidad) { | 
| 798 | if (key === 13) { | 801 | if (key === 13) { | 
| 799 | if (!articulo.cantidad && !tmpCantidad) { | 802 | if (!articulo.cantidad && !tmpCantidad) { | 
| 800 | focaModalService.alert('Los valores deben ser al menos 1'); | 803 | focaModalService.alert('Los valores deben ser al menos 1'); | 
| 801 | return; | 804 | return; | 
| 802 | } else if (tmpCantidad === '0') { | 805 | } else if (tmpCantidad === '0') { | 
| 803 | focaModalService.alert('Esta ingresando un producto con valor 0'); | 806 | focaModalService.alert('Esta ingresando un producto con valor 0'); | 
| 804 | } else if (articulo.cantidad < 0) { | 807 | } else if (articulo.cantidad < 0) { | 
| 805 | focaModalService.alert('Los valores no pueden ser negativos'); | 808 | focaModalService.alert('Los valores no pueden ser negativos'); | 
| 806 | return; | 809 | return; | 
| 807 | } | 810 | } | 
| 808 | articulo.CAN = parseInt(tmpCantidad); | 811 | articulo.CAN = parseInt(tmpCantidad); | 
| 809 | $scope.getTotal(); | 812 | $scope.getTotal(); | 
| 810 | articulo.editCantidad = false; | 813 | articulo.editCantidad = false; | 
| 811 | } | 814 | } | 
| 812 | }; | 815 | }; | 
| 813 | 816 | ||
| 814 | $scope.cancelarEditar = function (articulo) { | 817 | $scope.cancelarEditar = function (articulo) { | 
| 815 | $scope.tmpCantidad = articulo.CAN; | 818 | $scope.tmpCantidad = articulo.CAN; | 
| 816 | articulo.editCantidad = false; | 819 | articulo.editCantidad = false; | 
| 817 | }; | 820 | }; | 
| 818 | 821 | ||
| 819 | function actualizarCabeceraMoneda(cotizacion) { | 822 | function actualizarCabeceraMoneda(cotizacion) { | 
| 820 | 823 | ||
| 821 | $scope.factura.articulosFactura.forEach(function (art) { | 824 | $scope.factura.articulosFactura.forEach(function (art) { | 
| 822 | art.PUN = (art.PUN * $scope.factura.cotizacion.VENDEDOR).toFixed(4); | 825 | art.PUN = (art.PUN * $scope.factura.cotizacion.VENDEDOR).toFixed(4); | 
| 823 | art.PUN = (art.PUN / cotizacion.VENDEDOR).toFixed(4); | 826 | art.PUN = (art.PUN / cotizacion.VENDEDOR).toFixed(4); | 
| 824 | }); | 827 | }); | 
| 825 | 828 | ||
| 826 | if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { | 829 | if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { | 
| 827 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 830 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 
| 828 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 831 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 
| 829 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 832 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 
| 830 | } else { | 833 | } else { | 
| 831 | $scope.$broadcast('addCabecera', { | 834 | $scope.$broadcast('addCabecera', { | 
| 832 | label: 'Moneda:', | 835 | label: 'Moneda:', | 
| 833 | valor: cotizacion.moneda.DETALLE | 836 | valor: cotizacion.moneda.DETALLE | 
| 834 | }); | 837 | }); | 
| 835 | $scope.$broadcast('addCabecera', { | 838 | $scope.$broadcast('addCabecera', { | 
| 836 | label: 'Fecha cotizacion:', | 839 | label: 'Fecha cotizacion:', | 
| 837 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 840 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 
| 838 | }); | 841 | }); | 
| 839 | $scope.$broadcast('addCabecera', { | 842 | $scope.$broadcast('addCabecera', { | 
| 840 | label: 'Cotizacion:', | 843 | label: 'Cotizacion:', | 
| 841 | valor: $filter('number')(cotizacion.VENDEDOR, '2') | 844 | valor: $filter('number')(cotizacion.VENDEDOR, '2') | 
| 842 | }); | 845 | }); | 
| 843 | } | 846 | } | 
| 844 | } | 847 | } | 
| 845 | 848 | ||
| 846 | function validarGuardar() { | 849 | function validarGuardar() { | 
| 847 | 850 | ||
| 848 | if (angular.equals({}, $scope.factura.vendedor)) { | 851 | if (angular.equals({}, $scope.factura.vendedor)) { | 
| 849 | 852 | ||
| 850 | focaModalService.alert('Seleccione Vendedor'); | 853 | focaModalService.alert('Seleccione Vendedor'); | 
| 851 | return false; | 854 | return false; | 
| 852 | } else if (angular.equals({}, $scope.factura.cliente)) { | 855 | } else if (angular.equals({}, $scope.factura.cliente)) { | 
| 853 | 856 | ||
| 854 | focaModalService.alert('Seleccione Cliente'); | 857 | focaModalService.alert('Seleccione Cliente'); | 
| 855 | return false; | 858 | return false; | 
| 856 | } else if (!$scope.articulosFiltro().length) { | 859 | } else if (!$scope.articulosFiltro().length) { | 
| 857 | 860 | ||
| 858 | focaModalService.alert('Seleccione al menos un Articulo'); | 861 | focaModalService.alert('Seleccione al menos un Articulo'); | 
| 859 | return false; | 862 | return false; | 
| 860 | } | 863 | } | 
| 861 | 864 | ||
| 862 | return true; | 865 | return true; | 
| 863 | } | 866 | } |