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