erp_dekont_olustur
Create new document headers in the ERP system for orders, quotes, invoices, and returns with required fields like document type, date, number, and customer ID.
Instructions
ERP sisteminde yeni dekont başlığı oluşturur (Sipariş, Teklif, Fatura vb.). Görüntülemek için: https://erp.aaro.com.tr/Fatura/Kalem?id={DekontID}
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| TipID | Yes | Dekont tipi (10013: Alınan Sipariş, 10014: Verilen Sipariş, 10015: Alınan Teklif, 10016: Verilen Teklif, 10005: Satış Faturası, 10006: Alış Faturası, 10007: Satış İade Faturası, 10008: Alış İade Faturası) | |
| Tarih | Yes | Dekont tarihi (YYYY-MM-DD) | |
| BelgeNo | Yes | Belge numarası aynı tipte bulunan id ye göre en son eklenen dekontu bul ve onun belgenosuna +1 ekle | |
| Vade | No | Vade tarihi (YYYY-MM-DD) | |
| SirketID | No | Şirket ID (varsayılan: 1) | |
| SubeID | No | Şube ID (varsayılan: 1) | |
| RefDepoID | No | Referans depo ID (varsayılan: 1) | |
| CariID | Yes | Cari ID (zorunlu) | |
| DovizID | No | Döviz ID (varsayılan: 1) | |
| Aciklama | No | Açıklama |
Implementation Reference
- src/index.ts:459-490 (handler)The handler function 'createDekont' that executes the core logic for creating a new Dekont (accounting voucher/invoice). This is likely the implementation for the 'erp_dekont_olustur' tool, as it matches the Turkish naming ('olustur' = create) and makes a POST request to /api/Dekont/Baslik to create the dekont header with a single cari (customer) item.private async createDekont(args: any) { const { TipID, Tarih, BelgeNo, Vade, SirketID, SubeID, RefDepoID, CariID, DovizID, Aciklama } = args; if (!TipID || !Tarih || !BelgeNo || !CariID) { throw new Error('TipID, Tarih, BelgeNo ve CariID gerekli'); } const dekontData = { Baslik: { Tarih, BelgeNo, Vade: Vade || Tarih, TipID: parseInt(TipID), SirketID: parseInt(SirketID || '1'), SubeID: parseInt(SubeID || '1'), RefDepoID: parseInt(RefDepoID || '1') }, KalemTek: { KalemTipi: 4, // Cari olduğunu gösterir KartID: parseInt(CariID), DovizID: parseInt(DovizID || '1'), Aciklama: Aciklama || '' } }; this.log('Dekont oluşturuluyor', 'info', dekontData); return await this.callErpApi('/api/Dekont/Baslik', 'POST', { KayitTipi: '1', body: dekontData }); }
- src/index.ts:241-242 (registration)The switch case in callSpecialHandler that registers and routes calls to the 'createDekont' handler when a tool configured with handler: 'createDekont' is invoked. The tool name 'erp_dekont_olustur' is likely defined in config/tools.json mapping to this handler.case 'createDekont': return await this.createDekont(args);
- src/index.ts:692-800 (helper)Supporting utility function used by createDekont to make the actual ERP API call to /api/Dekont/Baslik. Manages authentication token (cached or fresh), constructs request, sends via axios, and formats response.private async callErpApi(endpoint: string, method: 'GET' | 'POST', args: any) { try { // Token'ı otomatik olarak al (cache'den veya yeni) let token = this.getCachedToken(); if (!token) { this.log('Token bulunamadı, yeni token alınıyor...'); token = await this.getErpToken(); } // URL'nin harici olup olmadığını kontrol et const isExternalUrl = endpoint.startsWith('http://') || endpoint.startsWith('https://'); const finalUrl = isExternalUrl ? endpoint : `${this.settings.erp.baseUrl}${endpoint}`; const config: any = { method, url: finalUrl, headers: { 'Authorization': `Bearer ${encodeURIComponent(token)}`, ...this.settings.api.defaultHeaders, }, timeout: this.settings.api.timeout, }; // Harici URL için ek header'lar ekle if (isExternalUrl) { config.headers['X-Original-ERP-URL'] = `${this.settings.erp.baseUrl}${endpoint.replace(/^https?:\/\/[^\/]+/, '')}`; config.headers['X-ERP-Token'] = encodeURIComponent(token); } if (method === 'GET') { // Tüm parametreleri query string olarak ekle const queryParams = { ...args }; delete queryParams.endpoint; delete queryParams.method; delete queryParams.body; if (Object.keys(queryParams).length > 0) { config.params = queryParams; } } else if (method === 'POST') { if (args.body) { config.data = args.body; } // POST için query parametreleri de ekle const queryParams = { ...args }; delete queryParams.endpoint; delete queryParams.method; delete queryParams.body; if (Object.keys(queryParams).length > 0) { config.params = queryParams; } } this.log(`API çağrısı: ${method} ${endpoint}`, 'info', { url: config.url, method: config.method, params: config.params, isExternal: isExternalUrl }); const response = await axios(config); this.log(`API başarılı: ${method} ${endpoint}`, 'info', { status: response.status, dataLength: JSON.stringify(response.data).length, isExternal: isExternalUrl }); return { content: [ { type: 'text', text: JSON.stringify(response.data, null, 2), }, ], }; } catch (error) { let errorMessage = 'Bilinmeyen hata'; if (axios.isAxiosError(error)) { if (error.response) { errorMessage = `HTTP ${error.response.status}: ${error.response.statusText}`; if (error.response.data) { errorMessage += `\n${JSON.stringify(error.response.data, null, 2)}`; } } else if (error.request) { errorMessage = 'İstek gönderildi ancak yanıt alınamadı'; } else { errorMessage = error.message; } } else if (error instanceof Error) { errorMessage = error.message; } this.log(`API hatası: ${method} ${endpoint}`, 'error', { error: errorMessage }); return { content: [ { type: 'text', text: `API Hatası: ${errorMessage}`, }, ], isError: true, }; } }