-
Notifications
You must be signed in to change notification settings - Fork 151
/
Copy pathinvoice.service.ts
104 lines (94 loc) · 2.91 KB
/
invoice.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { Injectable } from '@angular/core';
import { map } from 'rxjs/operators/map';
import { Constants } from '../config';
import { HttpService } from '../services/http.service';
@Injectable({
providedIn: 'root'
})
export class InvoiceService {
_invoiceList;
invoiceArray = [];
sheetParams = {
action: 'read',
sheet_name: 'this._config.customerDetailsPage',
page: 'this._config.paymentDetailsPage'
};
constructor(private _http: HttpService, private _confignew: Constants) {
this.getInvoiceList();
}
get invoiceList() {
console.log(JSON.parse(localStorage.invoiceList));
return JSON.parse(localStorage.invoiceList) || this._invoiceList;
}
getInvoiceList() {
this.invoiceArray = [];
return this._http.apiGet(`${this._confignew.INVOICE}get_invoice`).pipe(
map(invoice => {
this._invoiceList = invoice;
this.invoiceArray = this.createInvoiceArray(this._invoiceList);
this.saveLocalStroage(this._invoiceList);
return this.invoiceArray;
})
);
}
getInvoiceArray() {
return this.invoiceArray;
}
saveLocalStroage(data) {
this._invoiceList = data;
localStorage.invoiceList = JSON.stringify(this._invoiceList);
}
createInvoiceArray(invoiceObj) {
for (const key in invoiceObj) {
if (key) {
this.invoiceArray.push(invoiceObj[key]);
}
}
this.invoiceArray = this.invoiceArray.sort((a, b) => {
if (a.supplier === b.supplier) {
// Price is only important when cities are the same
return a.order > b.order ? 1 : b.order > a.order ? -1 : 0;
}
return a.supplier > b.supplier ? 1 : b.supplier > a.supplier ? -1 : 0;
});
console.log(this.invoiceArray);
return this.invoiceArray;
}
editInvoice(updateData) {
this.sheetParams['action'] = 'update';
console.log('update data', { ...updateData, ...this.sheetParams });
return this._http.apiGet({ ...updateData, ...updateData });
}
supplierList(supplier) {
return ['all', ...new Set(this.invoiceArray.map(item => item.supplier))];
}
getLinesDependOnSupplier(supplier) {
const supplierList = this.invoiceArray.filter(
invoice => invoice.supplier === supplier
);
return ['all', , ...new Set(supplierList.map(item => item.line_number))];
}
getFilterData(supplier, lineNumber) {
if (supplier === 'all') {
return this.invoiceArray;
} else {
const supplierDependInvocieArray = this.invoiceArray.filter(
item => item.supplier === supplier
);
if (lineNumber === 'all') {
return supplierDependInvocieArray;
} else {
return supplierDependInvocieArray.filter(
item => item.line_number === lineNumber
);
}
}
}
// udpate invoice of the cus
updateInvoice(customerInvoice) {
return this._http.apiPost(
`${this._confignew.INVOICE}${this._confignew.UPDATEINVOICE}`,
customerInvoice
);
}
}