2021-10-25 20:01:06 +00:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2021-10-27 20:21:55 +00:00
|
|
|
import { MatDialog, MatDialogConfig} from '@angular/material/dialog';
|
2021-10-25 20:01:06 +00:00
|
|
|
import { Observable } from 'rxjs';
|
2022-07-17 01:49:58 +00:00
|
|
|
import { LineItem } from '../items/lineitem.model';
|
2022-07-18 00:46:56 +00:00
|
|
|
import { newLineItem } from '../items/newlineitem.model';
|
2021-10-25 20:01:06 +00:00
|
|
|
import { Order } from './order.model';
|
|
|
|
import { FullnodeService } from '../fullnode.service';
|
|
|
|
import { OrderService } from './order.service';
|
2021-10-27 20:21:55 +00:00
|
|
|
import { CancelComponent } from '../cancel/cancel.component';
|
2021-10-28 18:22:54 +00:00
|
|
|
import { CheckoutComponent} from '../checkout/checkout.component';
|
2022-05-23 20:52:55 +00:00
|
|
|
import { PromptInvoiceComponent } from '../prompt-invoice/prompt-invoice.component';
|
2022-04-08 23:23:13 +00:00
|
|
|
import { ReceiptQRComponent} from '../receipt-qr/receipt-qr.component';
|
2022-05-23 20:52:55 +00:00
|
|
|
import { faFileInvoiceDollar } from '@fortawesome/free-solid-svg-icons';
|
2021-10-25 20:01:06 +00:00
|
|
|
|
2022-07-17 01:49:58 +00:00
|
|
|
import { faTrash } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
import { faTrashAlt } from '@fortawesome/free-solid-svg-icons';
|
2022-07-18 00:46:56 +00:00
|
|
|
import { faChevronRight } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
import { faSignOut } from '@fortawesome/free-solid-svg-icons';
|
2022-07-17 01:49:58 +00:00
|
|
|
|
2022-07-31 22:54:50 +00:00
|
|
|
import { NotifierService } from '../notifier.service';
|
2022-07-17 01:49:58 +00:00
|
|
|
|
2023-02-01 03:36:53 +00:00
|
|
|
import { LanguageService } from '../language.service';
|
|
|
|
import { LanguageData } from '../language.model';
|
|
|
|
|
2021-10-25 20:01:06 +00:00
|
|
|
@Component({
|
|
|
|
selector: 'app-order',
|
|
|
|
templateUrl: './order.component.html',
|
|
|
|
styleUrls: ['./order.component.css']
|
|
|
|
})
|
|
|
|
|
|
|
|
export class OrderComponent implements OnInit{
|
2022-07-18 00:46:56 +00:00
|
|
|
|
|
|
|
public oLines : newLineItem[] = [];
|
|
|
|
public myLines : LineItem[] = [];
|
|
|
|
|
2022-05-23 20:52:55 +00:00
|
|
|
faInvoice = faFileInvoiceDollar;
|
2021-11-22 20:37:45 +00:00
|
|
|
public order: Order = {
|
2022-08-25 00:57:44 +00:00
|
|
|
_id: '',
|
2021-11-22 20:37:45 +00:00
|
|
|
address: '',
|
|
|
|
session: '',
|
|
|
|
timestamp: '',
|
|
|
|
closed: false,
|
|
|
|
currency: '',
|
|
|
|
price:0,
|
|
|
|
total:0,
|
|
|
|
totalZec: 0,
|
2022-05-24 18:18:46 +00:00
|
|
|
paid: false,
|
2022-08-10 19:12:28 +00:00
|
|
|
externalInvoice: '',
|
|
|
|
shortCode: '',
|
2021-11-22 20:37:45 +00:00
|
|
|
lines: [
|
|
|
|
{
|
|
|
|
qty: 1,
|
|
|
|
name: '',
|
|
|
|
cost: 0
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
2021-10-25 20:01:06 +00:00
|
|
|
public price: number = 1;
|
2021-10-27 20:21:55 +00:00
|
|
|
public total: number = 0;
|
2021-10-25 20:01:06 +00:00
|
|
|
public orderUpdate: Observable<Order>;
|
|
|
|
public priceUpdate: Observable<number>;
|
2021-10-27 20:21:55 +00:00
|
|
|
public totalUpdate: Observable<number>;
|
2021-10-25 20:01:06 +00:00
|
|
|
|
2022-07-17 01:49:58 +00:00
|
|
|
// ------------------------------------
|
|
|
|
//
|
|
|
|
faTrash = faTrash;
|
|
|
|
faTrashAlt = faTrashAlt;
|
2022-07-18 00:46:56 +00:00
|
|
|
faChevronRight = faChevronRight;
|
|
|
|
faSignOut = faSignOut;
|
2022-07-17 01:49:58 +00:00
|
|
|
// -------------------------------------
|
2023-02-01 03:36:53 +00:00
|
|
|
//
|
|
|
|
// Language Support
|
|
|
|
//
|
|
|
|
vE = {
|
|
|
|
orderNoOpenorder : ''
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// ------------------------------------------------------------
|
2021-10-25 20:01:06 +00:00
|
|
|
constructor(
|
2023-02-01 03:36:53 +00:00
|
|
|
private languageService : LanguageService,
|
2021-10-25 20:01:06 +00:00
|
|
|
public fullnodeService: FullnodeService,
|
2021-10-27 20:21:55 +00:00
|
|
|
public orderService: OrderService,
|
2022-07-31 22:54:50 +00:00
|
|
|
private dialog: MatDialog,
|
|
|
|
private notifierService: NotifierService )
|
|
|
|
{
|
2021-10-25 20:01:06 +00:00
|
|
|
this.priceUpdate = fullnodeService.priceUpdate;
|
2021-10-27 20:21:55 +00:00
|
|
|
this.priceUpdate.subscribe((price) => {
|
|
|
|
this.price = price;
|
|
|
|
});
|
2021-10-25 20:01:06 +00:00
|
|
|
this.orderUpdate = orderService.orderUpdate;
|
2021-10-27 12:59:43 +00:00
|
|
|
this.orderUpdate.subscribe((order) => {
|
|
|
|
this.order = order;
|
2022-08-25 00:57:44 +00:00
|
|
|
|
|
|
|
console.log('this.order > ' + JSON.stringify(this.order));
|
2022-07-18 00:46:56 +00:00
|
|
|
// ------------------------------------------------
|
|
|
|
this.oLines = [];
|
|
|
|
this.myLines = this.order.lines;
|
|
|
|
var nl = {} as newLineItem;
|
|
|
|
|
|
|
|
for ( let i = 0; i < this.myLines.length; i++ )
|
|
|
|
{
|
|
|
|
// console.log("Loop : " + i + " - name : " + this.myLines[i].name);
|
|
|
|
nl = this.fillLineData(i,this.myLines[i].name,
|
|
|
|
this.myLines[i].qty,
|
|
|
|
this.myLines[i].cost) ;
|
|
|
|
// console.log(">> line_id: " + nl.line_id +
|
|
|
|
// " name: " + nl.name +
|
|
|
|
// " qty: " + nl.qty +
|
|
|
|
// " cost: " + nl.cost + " <<"
|
|
|
|
// )
|
|
|
|
this.oLines.push(nl);
|
|
|
|
// this.oLines[i].cost = this.myLines[i].cost;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------
|
2021-10-27 12:59:43 +00:00
|
|
|
});
|
2021-10-27 20:21:55 +00:00
|
|
|
this.totalUpdate = orderService.totalUpdate;
|
|
|
|
this.totalUpdate.subscribe((total) => {
|
|
|
|
this.total = total;
|
|
|
|
});
|
2022-07-18 00:46:56 +00:00
|
|
|
|
2021-10-25 20:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2023-02-01 03:36:53 +00:00
|
|
|
this.chgUILanguage();
|
2021-10-25 20:01:06 +00:00
|
|
|
}
|
2021-10-27 20:21:55 +00:00
|
|
|
|
|
|
|
cancelOrder() {
|
|
|
|
const dialogConfig = new MatDialogConfig();
|
|
|
|
|
|
|
|
dialogConfig.disableClose = true;
|
|
|
|
dialogConfig.autoFocus = true;
|
2022-02-01 18:56:02 +00:00
|
|
|
dialogConfig.data = {title: 'Cancel Order?', msg: 'Are you sure you want to cancel the order?'};
|
2021-10-27 20:21:55 +00:00
|
|
|
|
|
|
|
const dialogRef = this.dialog.open(CancelComponent, dialogConfig);
|
|
|
|
dialogRef.afterClosed().subscribe((val) => {
|
|
|
|
if (val) {
|
|
|
|
console.log('Canceling');
|
|
|
|
this.orderService.cancelOrder(this.order._id!).subscribe((response) => {
|
|
|
|
this.orderService.getOrder();
|
2022-07-31 22:54:50 +00:00
|
|
|
this.notifierService
|
|
|
|
.showNotification("Order successfully cancelled!",
|
|
|
|
"Close","success");
|
2022-08-02 00:41:47 +00:00
|
|
|
});
|
2021-10-27 20:21:55 +00:00
|
|
|
} else {
|
|
|
|
console.log('Returning to page');
|
|
|
|
}
|
|
|
|
this.orderService.getOrder();
|
2022-07-18 00:46:56 +00:00
|
|
|
this.oLines = [];
|
2021-10-27 20:21:55 +00:00
|
|
|
});
|
|
|
|
}
|
2021-10-28 18:22:54 +00:00
|
|
|
|
|
|
|
checkout() {
|
2021-11-05 14:30:35 +00:00
|
|
|
var zec = this.total/this.price;
|
2022-05-23 20:52:55 +00:00
|
|
|
this.order.totalZec = parseFloat(zec.toFixed(8));
|
2021-10-28 18:22:54 +00:00
|
|
|
const dialogConfig = new MatDialogConfig();
|
|
|
|
|
|
|
|
dialogConfig.disableClose = true;
|
|
|
|
dialogConfig.autoFocus = true;
|
|
|
|
dialogConfig.data = {
|
2021-11-05 14:30:35 +00:00
|
|
|
totalZec: this.order.totalZec,
|
2021-10-28 18:22:54 +00:00
|
|
|
addr: this.order.address,
|
|
|
|
orderId: this.order._id
|
|
|
|
};
|
|
|
|
|
|
|
|
const dialogRef = this.dialog.open(CheckoutComponent, dialogConfig);
|
|
|
|
dialogRef.afterClosed().subscribe((val) => {
|
|
|
|
if (val) {
|
2022-04-08 23:23:13 +00:00
|
|
|
const dialogConfig2 = new MatDialogConfig();
|
|
|
|
dialogConfig2.disableClose = true;
|
|
|
|
dialogConfig2.autoFocus = true;
|
|
|
|
dialogConfig2.data = {
|
|
|
|
order: this.order._id
|
|
|
|
};
|
2021-10-28 18:22:54 +00:00
|
|
|
console.log('Payment confirmed!');
|
2022-05-24 18:18:46 +00:00
|
|
|
this.orderService.closeOrder(true);
|
2022-04-08 23:23:13 +00:00
|
|
|
const dialogRef2 = this.dialog.open(ReceiptQRComponent, dialogConfig2);
|
|
|
|
dialogRef2.afterClosed().subscribe( val => {
|
|
|
|
if (val) {
|
|
|
|
console.log('Receipt closed.');
|
2022-07-18 00:46:56 +00:00
|
|
|
this.oLines = [];
|
2022-04-08 23:23:13 +00:00
|
|
|
}
|
|
|
|
});
|
2021-10-28 18:22:54 +00:00
|
|
|
} else {
|
|
|
|
console.log('Returning to order');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-11-22 20:37:45 +00:00
|
|
|
|
2022-05-23 20:52:55 +00:00
|
|
|
invoice() {
|
|
|
|
var zec = this.total/this.price;
|
|
|
|
this.order.totalZec = parseFloat(zec.toFixed(8));
|
|
|
|
const dialogConfig = new MatDialogConfig();
|
|
|
|
|
|
|
|
dialogConfig.disableClose = true;
|
|
|
|
dialogConfig.autoFocus = true;
|
|
|
|
dialogConfig.data = {
|
|
|
|
orderId: this.order._id
|
|
|
|
};
|
|
|
|
|
2022-08-25 00:57:44 +00:00
|
|
|
console.log ('order_id : ' + this.order._id);
|
|
|
|
|
2022-05-23 20:52:55 +00:00
|
|
|
const dialogRef = this.dialog.open(PromptInvoiceComponent, dialogConfig);
|
|
|
|
dialogRef.afterClosed().subscribe((val) => {
|
|
|
|
if (val) {
|
2022-05-24 18:18:46 +00:00
|
|
|
this.orderService.closeOrder(false);
|
2022-07-18 00:46:56 +00:00
|
|
|
this.oLines = [];
|
2022-05-23 20:52:55 +00:00
|
|
|
} else {
|
|
|
|
console.log('Returning to order');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-11-22 20:37:45 +00:00
|
|
|
getCurrency(){
|
|
|
|
return this.order.currency.toUpperCase();
|
|
|
|
}
|
2022-07-17 01:49:58 +00:00
|
|
|
|
2022-07-18 00:46:56 +00:00
|
|
|
|
|
|
|
fillLineData(i: number,
|
|
|
|
iname: string,
|
|
|
|
iqty: number,
|
|
|
|
icost: number) : newLineItem {
|
|
|
|
|
|
|
|
const a = { line_id: i,
|
|
|
|
name: iname,
|
|
|
|
qty: iqty,
|
|
|
|
cost: icost } as newLineItem;
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
trashCanClicked(item : newLineItem, lines: newLineItem[]) {
|
|
|
|
|
|
|
|
const dialogConfig = new MatDialogConfig();
|
|
|
|
|
|
|
|
dialogConfig.disableClose = true;
|
|
|
|
dialogConfig.autoFocus = true;
|
|
|
|
dialogConfig.data = {title: 'Remove Item?',
|
|
|
|
msg: 'Are you sure you want to remove <<' +
|
|
|
|
item.name + ' x ' + item.qty +
|
|
|
|
'>> from this order?'};
|
|
|
|
const dialogRef = this.dialog.open(CancelComponent, dialogConfig);
|
|
|
|
dialogRef.afterClosed().subscribe((val) => {
|
|
|
|
if (val) {
|
|
|
|
// console.log('Deleting item at line: '
|
|
|
|
// + (item.line_id +1)
|
|
|
|
// + " => (" + item.name +")");
|
|
|
|
this.orderService.updateOrder(item.line_id,lines);
|
|
|
|
this.orderService.getOrder();
|
2022-08-02 00:41:47 +00:00
|
|
|
if ( this.order.lines.length == 0 ) {
|
|
|
|
this.orderService.cancelOrder(this.order._id!)
|
|
|
|
.subscribe((response) => {
|
|
|
|
this.orderService.getOrder();
|
|
|
|
});
|
|
|
|
}
|
2022-07-18 00:46:56 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
console.log('Returning to order');
|
|
|
|
}
|
|
|
|
});
|
2023-02-01 03:36:53 +00:00
|
|
|
}
|
2022-07-18 00:46:56 +00:00
|
|
|
|
2023-02-01 03:36:53 +00:00
|
|
|
chgUILanguage(){
|
|
|
|
console.log('ORDER.chgUILanguage Called ');
|
|
|
|
this.languageService.getViewElements('order').subscribe(
|
|
|
|
response => {
|
|
|
|
console.log('Received >> ', response );
|
|
|
|
console.log('Language Code : ', response.language);
|
|
|
|
console.log('Component Name : ',response.component);
|
|
|
|
console.log('Language data : ',response.data);
|
2022-07-18 00:46:56 +00:00
|
|
|
|
2023-02-01 03:36:53 +00:00
|
|
|
this.vE.orderNoOpenorder = response.data.order_no_openorder;
|
|
|
|
},
|
|
|
|
error => { console.log('Error >> ',error); }
|
|
|
|
);
|
2022-07-17 01:49:58 +00:00
|
|
|
}
|
2023-02-01 03:36:53 +00:00
|
|
|
|
2021-10-25 20:01:06 +00:00
|
|
|
}
|