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