From 5f78c52db40e07da994a2ad7a48c1dd582f42553 Mon Sep 17 00:00:00 2001 From: Nulo Date: Thu, 16 Jun 2022 21:59:47 +0000 Subject: [PATCH] Agregar Stock --- demo/demo.ts | 7 +++++++ demo/index.html | 7 +++++++ index.ts | 1 + stock.ts | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 stock.ts diff --git a/demo/demo.ts b/demo/demo.ts index a11f3bd..0ac21b7 100644 --- a/demo/demo.ts +++ b/demo/demo.ts @@ -3,6 +3,7 @@ import { getProductos, getPrices, getPricesByCustomer, + getStocks, getCustomers, order, OrderDto, @@ -98,6 +99,12 @@ setupForm("#price", (event) => filter: (event.target! as any).filter.value, }) ); +setupForm("#stock", (event) => + getStocks(HOST, token(), { + filter: (event.target! as any).filter.value, + warehouseCode: (event.target! as any).warehouseCode.value, + }) +); setupForm("#price-by-customer", (event) => getPricesByCustomer(HOST, token(), { filter: (event.target! as any).filter.value, diff --git a/demo/index.html b/demo/index.html index 111431f..0295284 100644 --- a/demo/index.html +++ b/demo/index.html @@ -72,6 +72,13 @@

+
+ + + +

+
+

diff --git a/index.ts b/index.ts index 869ed60..5cbe13f 100644 --- a/index.ts +++ b/index.ts @@ -5,6 +5,7 @@ export * from "./product.js"; export * from "./price.js"; export * from "./priceByCustomer.js"; export * from "./priceList.js"; +export * from "./stock.js"; export * from "./customer.js"; export * from "./order.js"; export * from "./publications.js"; diff --git a/stock.ts b/stock.ts new file mode 100644 index 0000000..32e87fa --- /dev/null +++ b/stock.ts @@ -0,0 +1,51 @@ +import { Paginacion, paginacionToSearchParams, Paging } from "./common.js"; + +export interface StockQuery { + paginacion?: Paginacion; + warehouseCode?: string; + filter?: string; +} + +export interface Stock { + StoreNumber: number; + WarehouseCode: string; + SKUCode: string; + Quantity: number; + EngagedQuantity: number; + PendingQuantity: number; +} + +export interface StockResponse { + Paging: Paging; + Data: Stock[]; +} + +// https://github.com/TangoSoftware/ApiTiendas#saldos-de-stock +export async function getStocks( + host: string, + token: string, + options: StockQuery +): Promise { + let searchParams = new URLSearchParams(); + paginacionToSearchParams(options.paginacion, searchParams); + if (options.filter) { + searchParams.set("filter", options.filter); + } + if (options.warehouseCode) { + searchParams.set("warehouseCode", options.warehouseCode); + } + const res = await fetch( + `${host}/api/Aperture/Stock?${searchParams.toString()}`, + { + headers: { + accesstoken: token, + }, + } + ); + const json = await res.json(); + console.debug(json); + if (json.Message) { + throw new Error(`Tango: ${json.Message}`); + } + return json; +}