You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在C#的Tally Connector Library中查看凭证的金额及明细项详情

使用Tally Connector Library获取特定凭证详情(C#)

核心思路

你获取的凭证集合中,每个Voucher对象本身就包含了金额、明细项等完整数据,无需额外调用接口,只需筛选出目标凭证后直接访问对应属性即可。

具体实现步骤

1. 筛选目标凭证

通过凭证号、日期或类型等条件,从已获取的凭证列表中定位特定凭证。示例(按凭证号筛选):

// 假设allVouchers是你已获取的全量凭证列表(List<Voucher>类型)
var targetVoucher = allVouchers.FirstOrDefault(v => v.VoucherNumber == "INV-001");

注:字段名需匹配你使用的Tally Connector版本,若VoucherNumber不生效,可调试查看Voucher对象的实际属性名(比如部分版本可能叫Number)。

2. 读取凭证金额信息

直接访问Voucher对象的金额相关属性:

if (targetVoucher != null)
{
    decimal totalAmount = targetVoucher.TotalAmount; // 凭证总金额
    decimal debitTotal = targetVoucher.DebitTotal;   // 借方合计
    decimal creditTotal = targetVoucher.CreditTotal; // 贷方合计

    Console.WriteLine($"总金额: {totalAmount:C}");
    Console.WriteLine($"借方合计: {debitTotal:C} | 贷方合计: {creditTotal:C}");
}

3. 获取凭证明细项

凭证的分录明细通常存储在VoucherEntries(或Entries)集合中,遍历即可获取每条明细的科目、金额、借贷方向;库存类凭证还包含InventoryEntries属性存储商品数量、单价等信息:

if (targetVoucher != null && targetVoucher.VoucherEntries != null)
{
    Console.WriteLine("\n凭证明细:");
    foreach (var entry in targetVoucher.VoucherEntries)
    {
        string ledger = entry.LedgerName;
        decimal amount = entry.Amount;
        string direction = entry.IsDebit ? "借方" : "贷方";

        Console.WriteLine($"{direction} | 科目: {ledger} | 金额: {amount:C}");

        // 若为库存凭证,读取商品明细
        if (entry.InventoryEntries != null && entry.InventoryEntries.Any())
        {
            Console.WriteLine("  库存明细:");
            foreach (var invItem in entry.InventoryEntries)
            {
                Console.WriteLine($"    商品: {invItem.ItemName} | 数量: {invItem.Quantity} | 单价: {invItem.Rate:C}");
            }
        }
    }
}

额外提示

  • 若属性名不匹配,可通过Visual Studio的调试功能查看Voucher对象的所有属性,找到对应字段。
  • 除了凭证号,还可组合多个条件筛选,比如按日期+凭证类型:
var targetVoucher = allVouchers.FirstOrDefault(v => 
    v.VoucherDate.Date == new DateTime(2024, 5, 1) 
    && v.VoucherType == "Sales");

内容的提问来源于stack exchange,提问作者Dhiraj Dewani

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 09:12:21