import { Component, OnInit } from '@angular/core'; import { DialogService, SelectItem } from 'primeng/api'; import { AddTaxOverridesComponent } from '../popups/add-tax-overrides/add-tax-overrides.component'; import { DefaultTaxRatesComponent } from '../popups/default-tax-rates/default-tax-rates.component'; import { CookieService } from 'ngx-cookie-service'; import { Router, ActivatedRoute } from '@angular/router'; import { TaxService } from '../../services/tax/tax.service'; import { ICountryTaxRate } from '../../core/tax/ICountryTaxRate'; import { IStateTaxRate } from '../../core/tax/IStateTaxRate'; @Component({ selector: 'app-tax-country', templateUrl: './tax-country.component.html', styleUrls: ['./tax-country.component.scss'] }) export class TaxCountryComponent implements OnInit { shippingProfileId:number; companyId:number; baseTax:ICountryTaxRate; taxType:SelectItem[]=[]; constructor(public dialogService: DialogService, private cookieService:CookieService,private route: ActivatedRoute, private taxService:TaxService, public router: Router) { } ngOnInit() { this.companyId = +this.cookieService.get('CompanyId') this.shippingProfileId = +this.route.snapshot.paramMap.get("id"); this.baseTax = {CountryId:0,ShippingProfileId:this.shippingProfileId,CountryName:'',StateTaxRates:[],TaxRate:0} this.getBaseTax(); } // get country tax getBaseTax(){ this.taxService.GetBaseTaxRates(this.companyId,this.shippingProfileId,'BYCOUNTRY').subscribe(data=>{ this.baseTax = data; // get state tax type this.taxType = [ {label:'Added to '+ this.baseTax.TaxRate + '% federal tax',value:1}, {label:'Instead of '+ this.baseTax.TaxRate + '% federal tax',value:2}, {label:'Compound on top of '+ this.baseTax.TaxRate + '% federal tax',value:3}, ] }) } // save country tax rate saveCountryTaxRate(){ this.taxService.SetCountryTaxRate(this.companyId,this.baseTax).subscribe(data=>{ // get state tax type this.taxType = [ {label:'Added to '+ this.baseTax.TaxRate + '% federal tax',value:1}, {label:'Instead of '+ this.baseTax.TaxRate + '% federal tax',value:2}, {label:'Compound on top of '+ this.baseTax.TaxRate + '% federal tax',value:3}, ] }) } saveStateTaxRate(stateTax:IStateTaxRate){ stateTax.ShippingProfileId = this.shippingProfileId; stateTax.CountryId = this.baseTax.CountryId; this.taxService.SetStateTaxRate(this.companyId,stateTax).subscribe(data=>{}); } resetBackTaxRates(){ const ref = this.dialogService.open(DefaultTaxRatesComponent, { header: 'Reset back to default tax rates', width: '35%', data:{companyId:this.companyId,shippingProfileId:this.shippingProfileId, countryName:this.baseTax.CountryName } }); ref.onClose.subscribe(data=>{ this.getBaseTax(); }); } backToTax() { this.router.navigate(['/taxes']); } }