2021-10-28 20:34:48 +00:00
|
|
|
import { Inject, Component, OnInit, OnDestroy, ViewEncapsulation } from '@angular/core';
|
|
|
|
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
2022-03-07 19:46:00 +00:00
|
|
|
import { MatSlideToggleChange } from '@angular/material/slide-toggle';
|
2022-07-13 12:20:47 +00:00
|
|
|
import { UntypedFormBuilder, Validators, UntypedFormGroup, FormControl } from '@angular/forms';
|
2022-08-10 19:12:28 +00:00
|
|
|
import { Observable } from 'rxjs';
|
2022-07-18 23:41:31 +00:00
|
|
|
import { Owner } from '../owner.model';
|
2022-08-10 19:12:28 +00:00
|
|
|
import { XeroService } from '../xero.service';
|
2022-08-09 22:23:58 +00:00
|
|
|
|
2022-08-31 20:50:53 +00:00
|
|
|
import { NotifierService } from '../notifier.service';
|
|
|
|
import { faCopy } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
|
|
|
|
|
2021-10-28 20:34:48 +00:00
|
|
|
@Component({
|
|
|
|
selector: 'app-settings',
|
|
|
|
templateUrl: './settings.component.html',
|
|
|
|
styleUrls: ['/settings.component.css']
|
|
|
|
})
|
|
|
|
|
|
|
|
export class SettingsComponent implements OnInit {
|
|
|
|
|
2022-08-31 20:50:53 +00:00
|
|
|
// ------------------------------------
|
|
|
|
//
|
|
|
|
faCopy = faCopy;
|
|
|
|
// ------------------------------------
|
2022-07-13 12:20:47 +00:00
|
|
|
settingsForm: UntypedFormGroup;
|
2022-09-07 02:44:36 +00:00
|
|
|
accCodForm: UntypedFormGroup;
|
2021-10-28 20:34:48 +00:00
|
|
|
owner: Owner;
|
2022-03-07 19:46:00 +00:00
|
|
|
useZats: boolean;
|
2022-08-23 21:22:34 +00:00
|
|
|
proVersion: boolean = false;
|
2022-07-20 01:48:52 +00:00
|
|
|
useVKey: boolean = false;
|
2022-09-06 20:44:01 +00:00
|
|
|
linkMsg: string = 'Link to Xero';
|
|
|
|
xeroAccCod: string = '';
|
2022-09-02 11:33:24 +00:00
|
|
|
saveAccOk: boolean = false;
|
2022-08-31 20:50:53 +00:00
|
|
|
|
2021-11-22 20:37:45 +00:00
|
|
|
coins = [
|
|
|
|
{
|
|
|
|
label: 'US Dollar',
|
|
|
|
symbol: 'usd'
|
|
|
|
},{
|
|
|
|
label: 'Euro',
|
|
|
|
symbol: 'eur'
|
|
|
|
},{
|
|
|
|
label: 'British Pound',
|
|
|
|
symbol: 'gbp'
|
|
|
|
},{
|
|
|
|
label: 'Canadian Dollar',
|
|
|
|
symbol: 'cad'
|
|
|
|
},{
|
|
|
|
label: 'Australian Dollar',
|
|
|
|
symbol: 'aud'
|
2022-09-06 15:06:22 +00:00
|
|
|
},{
|
|
|
|
label: 'New Zealand Dollar',
|
|
|
|
symbol: 'nzd'
|
2021-11-22 20:37:45 +00:00
|
|
|
}
|
|
|
|
];
|
2022-08-09 22:23:58 +00:00
|
|
|
xeroLink: string = '';
|
|
|
|
localToken: string = '';
|
2022-08-10 19:12:28 +00:00
|
|
|
clientId: string = '';
|
|
|
|
clientIdUpdate: Observable<string>;
|
2022-09-06 20:44:01 +00:00
|
|
|
accCodeUpdate: Observable<string>;
|
2022-08-31 20:50:53 +00:00
|
|
|
linked2Xero : boolean = false;
|
|
|
|
pmtServiceURL : string = '';
|
2021-10-28 20:34:48 +00:00
|
|
|
|
|
|
|
constructor(
|
2022-08-31 20:50:53 +00:00
|
|
|
private notifierService : NotifierService,
|
2022-07-13 12:20:47 +00:00
|
|
|
private fb: UntypedFormBuilder,
|
2022-08-10 19:12:28 +00:00
|
|
|
public xeroService: XeroService,
|
2021-10-28 20:34:48 +00:00
|
|
|
private dialogRef: MatDialogRef<SettingsComponent>,
|
2022-07-22 04:06:23 +00:00
|
|
|
@Inject(MAT_DIALOG_DATA) public data: Owner) {
|
|
|
|
this.useZats = data.zats;
|
|
|
|
this.useVKey = data.payconf;
|
|
|
|
this.settingsForm = fb.group({
|
2022-09-07 02:44:36 +00:00
|
|
|
name: [data.name, Validators.required],
|
|
|
|
currency: [data.currency, Validators.required],
|
|
|
|
useZats: [data.zats, Validators.required],
|
|
|
|
useVKey: [data.payconf, Validators.required],
|
|
|
|
// proVersion: [data.invoices, Validators.required],
|
|
|
|
vKey: [data.viewkey]
|
|
|
|
});
|
|
|
|
this.accCodForm = fb.group ({
|
|
|
|
xAcc: [this.xeroAccCod]
|
|
|
|
});
|
|
|
|
|
2022-07-22 04:06:23 +00:00
|
|
|
if (data.payconf) {
|
|
|
|
this.settingsForm.get('vKey')!.enable();
|
|
|
|
}
|
|
|
|
this.owner = data;
|
2022-08-27 00:16:00 +00:00
|
|
|
this.proVersion = this.owner.invoices;
|
2022-08-31 20:50:53 +00:00
|
|
|
if ( this.owner.crmToken !== '' ) {
|
|
|
|
this.linked2Xero = true;
|
|
|
|
}
|
2022-08-10 19:12:28 +00:00
|
|
|
this.clientIdUpdate = xeroService.clientIdUpdate;
|
|
|
|
xeroService.getXeroConfig();
|
|
|
|
this.clientIdUpdate.subscribe(clientId => {
|
|
|
|
this.clientId = clientId;
|
2022-09-07 22:00:01 +00:00
|
|
|
this.xeroLink = `https://login.xero.com/identity/connect/authorize?response_type=code&client_id=${this.clientId}&redirect_uri=http%3A%2F%2Flocalhost%3A4200%2Fxeroauth&scope=accounting.transactions offline_access&state=${this.owner.address.substring(0, 6)}`
|
2022-08-10 19:12:28 +00:00
|
|
|
});
|
2022-09-06 20:44:01 +00:00
|
|
|
this.accCodeUpdate = xeroService.accCodeUpdate;
|
|
|
|
xeroService.getXeroAccountCode(this.owner.address);
|
|
|
|
this.accCodeUpdate.subscribe(accData => {
|
|
|
|
this.xeroAccCod = accData;
|
2022-09-07 02:44:36 +00:00
|
|
|
console.log("xeroAccCod -> [" + this.xeroAccCod + "]");
|
|
|
|
this.accCodForm.get('xAcc')!.setValue(this.xeroAccCod);
|
2022-09-06 20:44:01 +00:00
|
|
|
});
|
2021-10-28 20:34:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2022-08-12 20:31:01 +00:00
|
|
|
this.settingsForm.get('vKey')!.disable();
|
2022-08-31 20:50:53 +00:00
|
|
|
this.linkMsg = 'Link to Xero';
|
|
|
|
this.pmtServiceURL + '';
|
|
|
|
if ( this.linked2Xero ) {
|
|
|
|
this.linkMsg = 'Relink to Xero';
|
|
|
|
this.pmtServiceURL = 'https://zgo.cash/pmtservice?owner=' +
|
|
|
|
this.owner._id +
|
|
|
|
'&invoiceNo=[INVOICENUMBER]¤cy=[CURRENCY]&amount=[AMOUNTDUE]&shortCode=[SHORTCODE]';
|
|
|
|
}
|
2022-08-09 22:23:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
safeURL(s: string){
|
|
|
|
return s.replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
|
2021-10-28 20:34:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
close() {
|
2022-09-02 11:33:24 +00:00
|
|
|
|
|
|
|
this.dialogRef.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
closeIntegration() {
|
2022-09-08 16:35:55 +00:00
|
|
|
if ( (this.xeroAccCod == '') && (this.linked2Xero) )
|
2022-09-02 11:33:24 +00:00
|
|
|
this.notifierService
|
2022-09-06 21:03:38 +00:00
|
|
|
.showNotification("Payment confirmation disabled!!","Close",'warning');
|
2021-10-28 20:34:48 +00:00
|
|
|
this.dialogRef.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
save() {
|
|
|
|
this.owner.name = this.settingsForm.value.name;
|
2021-11-22 20:37:45 +00:00
|
|
|
this.owner.currency = this.settingsForm.value.currency;
|
2022-07-20 01:48:52 +00:00
|
|
|
this.owner.zats = this.settingsForm.value.useZats;
|
2022-07-20 16:10:24 +00:00
|
|
|
this.owner.payconf = this.settingsForm.value.useVKey;
|
|
|
|
this.owner.viewkey = this.settingsForm.value.vKey;
|
2022-08-23 21:22:34 +00:00
|
|
|
this.owner.invoices = this.settingsForm.value.proVersion
|
2021-10-28 20:34:48 +00:00
|
|
|
this.dialogRef.close(this.owner);
|
|
|
|
}
|
2022-03-07 19:46:00 +00:00
|
|
|
|
|
|
|
onChange(ob: MatSlideToggleChange) {
|
|
|
|
this.useZats = ob.checked;
|
|
|
|
}
|
2022-07-18 23:41:31 +00:00
|
|
|
|
2022-08-23 21:22:34 +00:00
|
|
|
onChangeProVersion(ob: MatSlideToggleChange) {
|
|
|
|
this.proVersion = ob.checked;
|
|
|
|
}
|
|
|
|
|
2022-07-18 23:41:31 +00:00
|
|
|
onChangeVKeyOn(ob: MatSlideToggleChange) {
|
2022-07-26 00:21:15 +00:00
|
|
|
// console.log("Viewing key switch is " +
|
|
|
|
// ( ob.checked ? "[ON]." : "[OFF]." ) );
|
2022-07-20 01:48:52 +00:00
|
|
|
|
|
|
|
this.useVKey = ob.checked;
|
|
|
|
|
|
|
|
if ( ob.checked )
|
2022-07-20 15:31:23 +00:00
|
|
|
this.settingsForm.get('vKey')!.enable();
|
2022-07-20 01:48:52 +00:00
|
|
|
else
|
2022-07-20 15:31:23 +00:00
|
|
|
this.settingsForm.get('vKey')!.disable();
|
2022-07-20 01:48:52 +00:00
|
|
|
|
2022-07-18 23:41:31 +00:00
|
|
|
}
|
2022-08-31 20:50:53 +00:00
|
|
|
|
|
|
|
copyUrl() {
|
|
|
|
// console.log("Inside copyUrl()");
|
|
|
|
if (navigator.clipboard) {
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
navigator.clipboard.writeText(this.pmtServiceURL);
|
|
|
|
this.notifierService
|
|
|
|
.showNotification("ZGo URL copied to Clipboard!!","Close",'success');
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
// console.error("Error", err);
|
|
|
|
this.notifierService
|
|
|
|
.showNotification("Functionality not available for your browser. Use send button instead.","Close",'error');
|
|
|
|
}
|
|
|
|
}
|
2022-09-02 11:33:24 +00:00
|
|
|
|
2022-09-07 02:44:36 +00:00
|
|
|
saveAccCod() {
|
2022-09-07 22:04:07 +00:00
|
|
|
|
2022-09-07 02:44:36 +00:00
|
|
|
this.xeroAccCod = this.accCodForm.value.xAcc;
|
|
|
|
console.log(">>> " + this.xeroAccCod);
|
|
|
|
if ( this.xeroAccCod.length <= 10 ) {
|
2022-09-08 03:00:43 +00:00
|
|
|
const obs = this.xeroService
|
|
|
|
.setXeroAccountCode(this.owner.address,
|
|
|
|
this.xeroAccCod);
|
|
|
|
obs.subscribe(responseData => {
|
|
|
|
if (responseData.status == 202) {
|
|
|
|
console.log('Account saved');
|
|
|
|
this.notifierService
|
|
|
|
.showNotification("Account Code saved!!","Close",'success');
|
|
|
|
} else {
|
|
|
|
console.log('Account not saved -> status[' + responseData.status + ']');
|
|
|
|
this.notifierService
|
|
|
|
.showNotification("Account Code not saved","Close",'error');
|
|
|
|
}
|
|
|
|
|
|
|
|
}, error => {
|
|
|
|
console.log('Error saving Account Code -> ' + error.msg)
|
|
|
|
});
|
2022-09-07 02:44:36 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
this.notifierService
|
|
|
|
.showNotification("Invalid Account code (10 chars max.)","Close",'error');
|
2022-09-07 22:04:07 +00:00
|
|
|
};
|
2022-09-07 02:44:36 +00:00
|
|
|
}
|
2022-09-09 00:57:11 +00:00
|
|
|
/*
|
2022-09-02 11:33:24 +00:00
|
|
|
xeroAccCodChanged( arg: any ) {
|
2022-09-09 00:57:11 +00:00
|
|
|
console.log("Account Code changed: " + arg.target.value);
|
2022-09-02 11:33:24 +00:00
|
|
|
// console.log(arg);
|
2022-09-07 02:44:36 +00:00
|
|
|
this.saveAccOk = (arg.target.value != this.xeroAccCod );
|
2022-09-02 11:33:24 +00:00
|
|
|
}
|
2022-09-09 00:57:11 +00:00
|
|
|
*/
|
|
|
|
checkStatus( arg : any ) {
|
|
|
|
console.log('onChange - checkStatus');
|
|
|
|
console.log(arg.target.value);
|
|
|
|
this.saveAccOk = (arg.target.value != this.xeroAccCod );
|
|
|
|
}
|
2021-10-28 20:34:48 +00:00
|
|
|
}
|