Add machine livesearch lookup
This commit is contained in:
@@ -14,6 +14,7 @@ import type {
|
||||
AgrarmonitorRegistrierungStatus,
|
||||
EingangsrechnungLivesearchResult,
|
||||
Logger,
|
||||
Maschine,
|
||||
MaschinenKategorie,
|
||||
Rechnungsdaten,
|
||||
} from './types';
|
||||
@@ -373,6 +374,34 @@ export class AgrarmonitorConnector implements AgrarmonitorConnectorResult {
|
||||
});
|
||||
}
|
||||
|
||||
async getMaschinen(gruppenId: number, suchstring = ''): Promise<Maschine[]> {
|
||||
const response = await this.http.get('/module/maschinen/livesearch.php', {
|
||||
params: {
|
||||
suchstring,
|
||||
maschinen_aktiv: 1,
|
||||
maschinengruppe: gruppenId,
|
||||
seite: 1,
|
||||
},
|
||||
});
|
||||
|
||||
await this.saveSession();
|
||||
|
||||
const document = this.parseHtmlDocument(response.data);
|
||||
const rows = Array.from(document.querySelectorAll<HTMLTableRowElement>('table.maschinen_table tbody tr'));
|
||||
|
||||
return rows.map(row => {
|
||||
const cells = Array.from(row.querySelectorAll<HTMLTableCellElement>('td'));
|
||||
|
||||
return {
|
||||
id: this.parseNumber(row.getAttribute('data-id') ?? row.id),
|
||||
nummer: cells[0]?.textContent?.trim() ?? '',
|
||||
name: cells[1]?.textContent?.trim() ?? '',
|
||||
kennzeichen: cells[2]?.textContent?.trim() ?? '',
|
||||
aktiv: Boolean(cells[4]?.querySelector('.fa-check, .text-green')),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private createHttpClient(): AxiosInstance {
|
||||
const client = wrapper(
|
||||
axios.create({
|
||||
|
||||
@@ -54,6 +54,7 @@ export interface AgrarmonitorConnectorResult {
|
||||
setEingangsdatum(rechnungId: number, datum: Date): Promise<boolean>;
|
||||
getCustomerById(id: number): Promise<AgrarmonitorApiCustomer>;
|
||||
getMaschinenKategorien(): Promise<MaschinenKategorie[]>;
|
||||
getMaschinen(gruppenId: number, suchstring?: string): Promise<Maschine[]>;
|
||||
}
|
||||
|
||||
export interface AgrarmonitorFreischaltungStatus {
|
||||
@@ -137,3 +138,11 @@ export interface MaschinenKategorie {
|
||||
zugmaschine: boolean;
|
||||
mobilSichtbar: boolean;
|
||||
}
|
||||
|
||||
export interface Maschine {
|
||||
id: number;
|
||||
nummer: string;
|
||||
name: string;
|
||||
kennzeichen: string;
|
||||
aktiv: boolean;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user