Taxes, tips and bugfixes #10
3 changed files with 66 additions and 9 deletions
|
@ -75,6 +75,18 @@
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="newOrdertbdetail" style="text-align: right;">Sales Tax</td>
|
||||||
|
<td class="newOrdertbdetail" style="text-align: right;">{{ tax / 100 | percent:'1.2-4'}}</td>
|
||||||
|
<td class="newOrdertbdetail" style="text-align: right;">{{ total * tax / 100 | currency: getCurrency() }}</td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="newOrdertbdetail" style="text-align: right;">Value-Added Tax</td>
|
||||||
|
<td class="newOrdertbdetail" style="text-align: right;">{{ vat / 100 | percent:'1.2-4' }}</td>
|
||||||
|
<td class="newOrdertbdetail" style="text-align: right;">{{ total * vat / 100 | currency: getCurrency() }}</td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -48,6 +48,9 @@ export class OrderComponent implements OnInit{
|
||||||
externalInvoice: '',
|
externalInvoice: '',
|
||||||
shortCode: '',
|
shortCode: '',
|
||||||
token: '',
|
token: '',
|
||||||
|
taxAmount: 0,
|
||||||
|
vatAmount: 0,
|
||||||
|
tipAmount: 0,
|
||||||
lines: [
|
lines: [
|
||||||
{
|
{
|
||||||
qty: 1,
|
qty: 1,
|
||||||
|
@ -58,9 +61,13 @@ export class OrderComponent implements OnInit{
|
||||||
};
|
};
|
||||||
public price: number = 1;
|
public price: number = 1;
|
||||||
public total: number = 0;
|
public total: number = 0;
|
||||||
|
public tax: number = 0;
|
||||||
|
public vat: number = 0;
|
||||||
public orderUpdate: Observable<Order>;
|
public orderUpdate: Observable<Order>;
|
||||||
public priceUpdate: Observable<number>;
|
public priceUpdate: Observable<number>;
|
||||||
public totalUpdate: Observable<number>;
|
public totalUpdate: Observable<number>;
|
||||||
|
public taxUpdate: Observable<number>;
|
||||||
|
public vatUpdate: Observable<number>;
|
||||||
|
|
||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
//
|
//
|
||||||
|
@ -106,9 +113,6 @@ export class OrderComponent implements OnInit{
|
||||||
this.orderUpdate = orderService.orderUpdate;
|
this.orderUpdate = orderService.orderUpdate;
|
||||||
this.orderUpdate.subscribe((order) => {
|
this.orderUpdate.subscribe((order) => {
|
||||||
this.order = order;
|
this.order = order;
|
||||||
|
|
||||||
//console.log('this.order > ' + JSON.stringify(this.order));
|
|
||||||
// ------------------------------------------------
|
|
||||||
this.oLines = [];
|
this.oLines = [];
|
||||||
this.myLines = this.order.lines;
|
this.myLines = this.order.lines;
|
||||||
var nl = {} as newLineItem;
|
var nl = {} as newLineItem;
|
||||||
|
@ -134,6 +138,14 @@ export class OrderComponent implements OnInit{
|
||||||
this.total = total;
|
this.total = total;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.taxUpdate = orderService.taxUpdate;
|
||||||
|
this.taxUpdate.subscribe((tax) => {
|
||||||
|
this.tax = tax;
|
||||||
|
});
|
||||||
|
this.vatUpdate = orderService.vatUpdate;
|
||||||
|
this.vatUpdate.subscribe((vat) => {
|
||||||
|
this.vat = vat;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
|
|
@ -57,6 +57,9 @@ export class OrderService {
|
||||||
externalInvoice: '',
|
externalInvoice: '',
|
||||||
shortCode: '',
|
shortCode: '',
|
||||||
token: '',
|
token: '',
|
||||||
|
taxAmount: 0,
|
||||||
|
vatAmount: 0,
|
||||||
|
tipAmount: 0,
|
||||||
lines: [
|
lines: [
|
||||||
{
|
{
|
||||||
qty: 1,
|
qty: 1,
|
||||||
|
@ -72,6 +75,10 @@ export class OrderService {
|
||||||
public readonly totalUpdate: Observable<number> = this._totalUpdated.asObservable();
|
public readonly totalUpdate: Observable<number> = this._totalUpdated.asObservable();
|
||||||
private _allOrdersUpdated: BehaviorSubject<Order[]> = new BehaviorSubject(this.dataStore.allOrders);
|
private _allOrdersUpdated: BehaviorSubject<Order[]> = new BehaviorSubject(this.dataStore.allOrders);
|
||||||
public readonly allOrdersUpdate: Observable<Order[]> = this._allOrdersUpdated.asObservable();
|
public readonly allOrdersUpdate: Observable<Order[]> = this._allOrdersUpdated.asObservable();
|
||||||
|
private _taxUpdated: BehaviorSubject<number> = new BehaviorSubject(this.dataStore.owner.taxValue);
|
||||||
|
public readonly taxUpdate: Observable<number> = this._taxUpdated.asObservable();
|
||||||
|
private _vatUpdated: BehaviorSubject<number> = new BehaviorSubject(this.dataStore.owner.vatValue);
|
||||||
|
public readonly vatUpdate: Observable<number> = this._vatUpdated.asObservable();
|
||||||
public userUpdate: Observable<User>;
|
public userUpdate: Observable<User>;
|
||||||
public ownerUpdate: Observable<Owner>;
|
public ownerUpdate: Observable<Owner>;
|
||||||
private reqHeaders: HttpHeaders;
|
private reqHeaders: HttpHeaders;
|
||||||
|
@ -95,6 +102,16 @@ export class OrderService {
|
||||||
});
|
});
|
||||||
this.ownerUpdate.subscribe((owner) => {
|
this.ownerUpdate.subscribe((owner) => {
|
||||||
this.dataStore.owner = owner;
|
this.dataStore.owner = owner;
|
||||||
|
if (this.dataStore.owner.tax) {
|
||||||
|
this._taxUpdated.next(Object.assign({}, this.dataStore).owner.taxValue);
|
||||||
|
} else {
|
||||||
|
this._taxUpdated.next(0);
|
||||||
|
}
|
||||||
|
if (this.dataStore.owner.vat) {
|
||||||
|
this._vatUpdated.next(Object.assign({}, this.dataStore).owner.vatValue);
|
||||||
|
} else {
|
||||||
|
this._vatUpdated.next(0);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,10 +122,10 @@ export class OrderService {
|
||||||
if (OrderDataResponse.status == 200) {
|
if (OrderDataResponse.status == 200) {
|
||||||
this.dataStore.order = OrderDataResponse.body!.order;
|
this.dataStore.order = OrderDataResponse.body!.order;
|
||||||
this._orderUpdated.next(Object.assign({}, this.dataStore).order);
|
this._orderUpdated.next(Object.assign({}, this.dataStore).order);
|
||||||
this.dataStore.order.total = 0;
|
//this.dataStore.order.total = 0;
|
||||||
for(var line of this.dataStore.order.lines) {
|
//for(var line of this.dataStore.order.lines) {
|
||||||
this.dataStore.order.total += line.qty * line.cost;
|
//this.dataStore.order.total += line.qty * line.cost;
|
||||||
}
|
//}
|
||||||
this._totalUpdated.next(Object.assign({}, this.dataStore).order.total);
|
this._totalUpdated.next(Object.assign({}, this.dataStore).order.total);
|
||||||
} else {
|
} else {
|
||||||
console.log('No order found');
|
console.log('No order found');
|
||||||
|
@ -148,6 +165,14 @@ export class OrderService {
|
||||||
}
|
}
|
||||||
|
|
||||||
createOrder(lineItem: LineItem) {
|
createOrder(lineItem: LineItem) {
|
||||||
|
let localTax = 0;
|
||||||
|
let localVat = 0;
|
||||||
|
if (this.dataStore.owner.tax) {
|
||||||
|
localTax = lineItem.cost * lineItem.qty * this.dataStore.owner.taxValue / 100;
|
||||||
|
}
|
||||||
|
if (this.dataStore.owner.vat) {
|
||||||
|
localVat = lineItem.cost * lineItem.qty * this.dataStore.owner.vatValue / 100;
|
||||||
|
}
|
||||||
var order:Order = {
|
var order:Order = {
|
||||||
_id: '',
|
_id: '',
|
||||||
address: this.dataStore.user.address,
|
address: this.dataStore.user.address,
|
||||||
|
@ -162,11 +187,13 @@ export class OrderService {
|
||||||
externalInvoice: '',
|
externalInvoice: '',
|
||||||
shortCode: '',
|
shortCode: '',
|
||||||
token: '',
|
token: '',
|
||||||
|
taxAmount: localTax,
|
||||||
|
vatAmount: localVat,
|
||||||
|
tipAmount: 0,
|
||||||
lines: [lineItem]
|
lines: [lineItem]
|
||||||
};
|
};
|
||||||
let obs = this.http.post<{message: string, order: Order}>(this.beUrl+'api/order', {payload: order}, { headers: this.reqHeaders, params: this.reqParams });
|
let obs = this.http.post<{message: string, order: Order}>(this.beUrl+'api/order', {payload: order}, { headers: this.reqHeaders, params: this.reqParams });
|
||||||
obs.subscribe((orderData) => {
|
obs.subscribe((orderData) => {
|
||||||
console.log('Created order');
|
|
||||||
this.getOrder()
|
this.getOrder()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -192,6 +219,9 @@ export class OrderService {
|
||||||
externalInvoice: '',
|
externalInvoice: '',
|
||||||
shortCode: '',
|
shortCode: '',
|
||||||
token: '',
|
token: '',
|
||||||
|
taxAmount: 0,
|
||||||
|
vatAmount: 0,
|
||||||
|
tipAmount: 0,
|
||||||
lines: [
|
lines: [
|
||||||
{
|
{
|
||||||
qty: 1,
|
qty: 1,
|
||||||
|
@ -214,7 +244,7 @@ export class OrderService {
|
||||||
this.dataStore.order.paid = paid;
|
this.dataStore.order.paid = paid;
|
||||||
let obs = this.http.post(this.beUrl+'api/order', {payload: this.dataStore.order}, { headers: this.reqHeaders, params: this.reqParams });
|
let obs = this.http.post(this.beUrl+'api/order', {payload: this.dataStore.order}, { headers: this.reqHeaders, params: this.reqParams });
|
||||||
obs.subscribe((orderData) => {
|
obs.subscribe((orderData) => {
|
||||||
console.log('Closed order', orderData);
|
//console.log('Closed order', orderData);
|
||||||
this.dataStore.order = {
|
this.dataStore.order = {
|
||||||
address: '',
|
address: '',
|
||||||
session: '',
|
session: '',
|
||||||
|
@ -228,6 +258,9 @@ export class OrderService {
|
||||||
externalInvoice: '',
|
externalInvoice: '',
|
||||||
shortCode: '',
|
shortCode: '',
|
||||||
token: '',
|
token: '',
|
||||||
|
taxAmount: 0,
|
||||||
|
vatAmount: 0,
|
||||||
|
tipAmount: 0,
|
||||||
lines: [
|
lines: [
|
||||||
{
|
{
|
||||||
qty: 1,
|
qty: 1,
|
||||||
|
|
Loading…
Reference in a new issue