erp_dekont_kalem_ekle
Add stock items to a receipt in the AARO ERP system by specifying details like item ID, quantity, amount, and currency using this integration tool.
Instructions
Dekonta stok kalemi ekler
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| BA | No | Borç/Alacak (varsayılan: A) | |
| DekontID | Yes | Dekont ID (zorunlu) | |
| DepoID | No | Depo ID (varsayılan: 1) | |
| DovizID | No | Döviz ID (varsayılan: 1) | |
| Miktar | Yes | Miktar (zorunlu) | |
| StokID | Yes | Stok ID (zorunlu) | |
| TeslimTarihi | No | Teslim tarihi (YYYY-MM-DD) | |
| Tutar | Yes | Tutar (zorunlu) | |
| TutarDvz | No | Dövizli tutar (varsayılan: 0) | |
| VergiID | No | Vergi ID (varsayılan: 1) | |
| VergiOrani | No | Vergi oranı (varsayılan: 18) |
Implementation Reference
- src/index.ts:492-544 (handler)The main handler function for the 'erp_dekont_kalem_ekle' tool. It prepares the kalem data with required fields like DekontID, StokID, Miktar, Tutar, etc., constructs the payload for the ERP API endpoint '/api/Dekont/Kalem', and calls the API to add the line item to the dekont.private async addDekontKalem(args: any) { const { DekontID, StokID, Miktar, Tutar, DovizID, TutarDvz, BA, DepoID, TeslimTarihi, VergiID, VergiOrani } = args; if (!DekontID || !StokID || !Miktar || !Tutar) { throw new Error('DekontID, StokID, Miktar ve Tutar gerekli'); } const kalemData = { KalemTipi: 7, // Sabit değer DekontID: parseInt(DekontID), KartID: parseInt(StokID), Miktar: parseFloat(Miktar), Tutar: parseFloat(Tutar), DovizID: parseInt(DovizID || '1'), TutarDvz: parseFloat(TutarDvz || '0'), BA: BA || 'A', SiparisStok: { DepoID: parseInt(DepoID || '1'), TeslimTarihi: TeslimTarihi || new Date().toISOString().split('T')[0], VergiDetaylari: [ { VergiID: parseInt(VergiID || '1'), Oran: parseFloat(VergiOrani || '20'), Tutar: parseFloat(Tutar) * (parseFloat(VergiOrani || '20') / 100), TutarDvz: 0, DovizID: parseInt(DovizID || '1'), Matrah: parseFloat(Tutar), MatrahDvz: 0, BA: BA || 'A' } ] } }; this.log('Dekont kalemi ekleniyor', 'info', kalemData); return await this.callErpApi('/api/Dekont/Kalem', 'POST', { KayitTipi: '1', body: kalemData }); }
- src/index.ts:244-245 (registration)Registration/dispatch point in the callSpecialHandler switch statement that routes calls to the addDekontKalem handler function when the tool config specifies handler: 'addDekontKalem'. The actual tool name 'erp_dekont_kalem_ekle' is likely defined in config/tools.json mapping to this handler.case 'addDekontKalem': return await this.addDekontKalem(args);
- src/index.ts:692-799 (helper)Helper function used by addDekontKalem to make the actual POST request to the ERP API. Handles token retrieval from cache or login, constructs axios config, sends request to /api/Dekont/Kalem, and formats response or error.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, }; }