2021-10-12 22:29:57 +00:00
|
|
|
import {
|
2021-11-01 20:44:29 +00:00
|
|
|
QueryCustomer,
|
2021-10-12 22:29:57 +00:00
|
|
|
Paginacion,
|
|
|
|
paginacionToSearchParams,
|
|
|
|
Paging,
|
2021-11-01 20:44:29 +00:00
|
|
|
queryCustomerToSearchParams,
|
|
|
|
TipoDeDocumento,
|
2021-10-12 22:29:57 +00:00
|
|
|
} from "./common.js";
|
|
|
|
|
|
|
|
export interface CustomerQuery {
|
|
|
|
paginacion?: Paginacion;
|
2021-11-01 20:44:29 +00:00
|
|
|
customer?: QueryCustomer;
|
2021-10-12 22:29:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface Customer {
|
|
|
|
Code: string;
|
|
|
|
BusinessName: string;
|
|
|
|
TradeName: string;
|
|
|
|
Address: string;
|
|
|
|
PostalCode: string;
|
|
|
|
City: string;
|
|
|
|
ProvinceCode: string;
|
|
|
|
TradeAddress: string;
|
|
|
|
PhoneNumbers: string;
|
|
|
|
Email: string;
|
|
|
|
MobilePhoneNumber: string;
|
|
|
|
WebPage: string;
|
|
|
|
IvaCategoryCode: string;
|
2021-11-01 20:44:29 +00:00
|
|
|
DocumentType: TipoDeDocumento;
|
2021-10-12 22:29:57 +00:00
|
|
|
DocumentNumber: string;
|
|
|
|
PriceListNumber: number;
|
|
|
|
Discount: number;
|
|
|
|
Observations: string;
|
|
|
|
DisabledDate: string;
|
|
|
|
SellerCode: string;
|
|
|
|
CreditQuota: number;
|
|
|
|
LocalAccountBalance: number;
|
|
|
|
ForeignAccountBalance: number;
|
|
|
|
ForeignCurrencyClause: boolean;
|
|
|
|
CreditQuotaCurrencyCode: string;
|
|
|
|
UpdateDatetime?: null;
|
|
|
|
LastUpdateUtc?: string;
|
|
|
|
ShippingAddresses: ShippingAddress[];
|
|
|
|
CustomerComments: CustomerComment[];
|
|
|
|
SaleConditionCode: number;
|
|
|
|
TransportCode: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface CustomerComment {
|
|
|
|
Line: number;
|
|
|
|
Text: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface ShippingAddress {
|
|
|
|
Code: string;
|
|
|
|
Address: string;
|
|
|
|
ProvinceCode: string;
|
|
|
|
City: string;
|
|
|
|
PostalCode: string;
|
|
|
|
PhoneNumber1: string;
|
|
|
|
PhoneNumber2: string;
|
|
|
|
DefaultAddress: string;
|
|
|
|
Enabled: string;
|
|
|
|
DeliveryHours: string;
|
|
|
|
DeliversMonday: string;
|
|
|
|
DeliversTuesday: string;
|
|
|
|
DeliversWednesday: string;
|
|
|
|
DeliversThursday: string;
|
|
|
|
DeliversFriday: string;
|
|
|
|
DeliversSaturday: string;
|
|
|
|
DeliversSunday: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface CustomerResponse {
|
|
|
|
Paging: Paging;
|
|
|
|
Data: Customer[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getCustomers(
|
2021-11-15 21:57:36 +00:00
|
|
|
host: string,
|
2022-11-01 17:21:52 +00:00
|
|
|
headers: HeadersInit,
|
2021-10-12 22:29:57 +00:00
|
|
|
options: CustomerQuery
|
|
|
|
): Promise<CustomerResponse> {
|
|
|
|
let searchParams = new URLSearchParams();
|
|
|
|
paginacionToSearchParams(options.paginacion, searchParams);
|
2021-11-01 20:44:29 +00:00
|
|
|
if (options.customer) {
|
|
|
|
queryCustomerToSearchParams(options.customer, searchParams);
|
|
|
|
}
|
2021-10-12 22:29:57 +00:00
|
|
|
const res = await fetch(
|
2021-11-15 21:57:36 +00:00
|
|
|
`${host}/api/Aperture/Customer?${searchParams.toString()}`,
|
2022-11-01 17:21:52 +00:00
|
|
|
{ headers }
|
2021-10-12 22:29:57 +00:00
|
|
|
);
|
|
|
|
const json = await res.json();
|
|
|
|
console.debug(json);
|
|
|
|
if (json.Message) {
|
|
|
|
throw new Error(`Tango: ${json.Message}`);
|
|
|
|
}
|
|
|
|
return json;
|
|
|
|
}
|