在 Zoho Invoice 中创建记录

 概述

可执行 Zoho.invoice.create() 任务以便将记录添加到 Zoho Invoice 的任何受支持模块。通过将它放入 Zoho Creator 中所需的表单动作块,在 Zoho Invoice 中创建记录的过程可以根据需求轻松地实现自动化。假设我们有一个 Zoho Creator 表单,用户使用它来订购某些产品。若要同时在 Zoho Invoice 的“联系人”模块中创建客户(用户),您可以执行“成功时”表单动作块中的 zoho.invoice.create() 任务。这样,每当提交带有客户详细信息的 Zoho Creator 表单时,将在 Zoho Invoice 中创建记录。有关如何执行此任务的更多详情在下面说明。

 支持的模块

  • 发货单
  • 客户付款
  • 产品
  • 联系人
  • 费用
  • 报价单
  • 费用类别

 语法

response =zoho.invoice.create(module_name, organisation_id, {data_map})

其中,
<response> - 是作为响应由 Zoho Invoice 返回的映射变量。
<moduleName> - Zoho Invoice 中的模块名称,记录将添加到此模块。(必填)
<organisation_id> - 添加记录时必需的机构编号。(必填)
<dataMap> - 保存键值对的映射变量。映射键是 Zoho Invoice 模块中指定的标签名,映射值是在 ZC 表单中提交的字段值。例如,"First Name" : input.First_Name。在这里,"First Name” 是在 Zoho Invoice 模块中指定的标签名,input.First_Name 指的是在 Zoho Creator 表单的 First_Name 字段中指定的值。(必填)

 示例

1) 假设我们有一个 Creator 表单,用于订购某些产品。此表单包含字段,

  • 联系人姓名
  • 公司名称
  • 地址
  • 城市
  • 省/直辖市/自治区
  • 邮编
  • 国家/地区
  • 传真

您可以将以下脚本添加到 Creator 表单的添加时 -> 成功时块,以便每当提交此表单时,在 Zoho Invoice 的指定模块中创建带有指定详细信息的记录。在本例中,模块是“联系人”。

values = map();
values.put("contact_name" , input.Contact_Name);
values.put("company_name" , input.Company_Name);
            
addressDetails = map();
addressDetails.put("address", input.Address);
addressDetails.put("city", input.City);
addressDetails.put("state", input.State);
addressDetails.put("zip" , input.Zip);
addressDetails.put("country", input.Country);
addressDetails.put("fax", input.Fax);
 
values.put("billing_address" , addressDetails);

 

response = zoho.invoice.create("Contacts", "10982991", values );

其中,
response - 是作为响应由 Zoho Invoice 返回的映射变量。
Contacts - Zoho Invoice 中的模块名称,记录将添加到该模块中。
10982991 - 示例机构编号,记录将添加到其中。
映射值包含 Invoice 报价字段的键名,后面是它的值(表单字段输入)。

2) 让我们以在 Zoho Invoice 中创建发货单来做例子。假设我们有一个 Creator 表单用于存储发货单详情。表单包含以下字段:

  • 发货单编号
  • 客户姓名
  • 日期
  • 包含项名称、费率和数量的产品子表单

我们将先提取要将发货单与之链接在一起的客户编号。这可以使用以下代码来实现:

resp = zoho.invoice.getRecords("contacts", "10982991", "", input.Customer_Name);
detail = (resp.get("contacts").toJSONList().get(0)).toMap();
customer_id = detail.get("contact_id");

若要在提交表单时在 Zoho Invoice 中创建发货单,将以下脚本添加到表单的添加时 > 成功时块:

itemsList = list();
for each record in Products
{
item = map();
item.put("name", record.Item_Name );
item.put("rate", record.Rate);
item.put("quantity", record.Quantity);
itemsList.add(item);
}

values = map();
values.put("customer_id" , customer_id); 
values.put("invoice_number", input.Inv_number);
values.put("date" , input.Date);
values.put("line_items", itemsList);

response = zoho.invoice.create("Invoices", "10982991" , values);

其中,
response - 是作为响应由 Zoho Invoice 返回的映射变量。
Invoice - Zoho Invoice 中的发货单名称,记录将添加到其中。
10982991 - 示例机构编号,记录将添加到其中。
映射值包含 Invoice 报价字段的键名,后面是它的值(表单字段输入)

 响应

Zoho Invoice 作为映射为示例 1 返回的响应:

{
"code": 0,
"message": "The contact has been added.",
"contact": {
"contact_id": "219715000000070001",
"contact_name": "sample",
"company_name": "",
"website": "",
"language_code": "",
"language_code_formatted": "",
"contact_salutation": "",
"is_client_review_asked": false,
"has_transaction": false,
"contact_type": "customer",
"owner_id": "",
"owner_name": "",
"source": "api",
"is_crm_customer": false,
"is_linked_with_zohocrm": false,
"primary_contact_id": "",
"zcrm_account_id": "",
"zcrm_contact_id": "",
"payment_terms": 0,
"payment_terms_label": "Due On Receipt",
"currency_id": "219715000000000099",
"currency_code": "INR",
"currency_symbol": "Rs.",
"price_precision": 2,
"outstanding_receivable_amount": 0,
"outstanding_receivable_amount_bcy": 0,
"unused_credits_receivable_amount": 0,
"unused_credits_receivable_amount_bcy": 0,
"status": "active",
"payment_reminder_enabled": true,
"is_client_review_settings_enabled": false,
"average_client_rating": "-0.0",
"custom_fields": [],
"billing_address": {
"address": "",
"city": "",
"state": "",
"zip": "",
"country": "",
"fax": ""
},
"shipping_address": {
"address": "",
"city": "",
"state": "",
"zip": "",
"country": "",
"fax": ""
},
"contact_persons": [],
"pricebook_id": "",
"pricebook_name": "",
"default_templates": {
"invoice_template_id": "",
"invoice_template_name": "",
"estimate_template_id": "",
"estimate_template_name": "",
"creditnote_template_id": "",
"creditnote_template_name": "",
"paymentthankyou_template_id": "",
"paymentthankyou_template_name": "",
"invoice_email_template_id": "",
"invoice_email_template_name": "",
"estimate_email_template_id": "",
"estimate_email_template_name": "",
"creditnote_email_template_id": "",
"creditnote_email_template_name": "",
"paymentthankyou_email_template_id": "",
"paymentthankyou_email_template_name": ""
},
"associated_with_square": false,
"cards": [],
"checks": [],
"bank_accounts": [],
"notes": "",
"created_time": "2016-02-08T13:21:54+0530",
"last_modified_time": "2016-02-08T13:21:54+0530"
}
}

Zoho Invoice 作为映射为示例 2 返回的响应:

{
"code": 0,
"message": "The invoice has been created.",
"invoice": {
"invoice_id": "219715000000070007",
"invoice_number": "INV-000017",
"zcrm_potential_id": "",
"zcrm_potential_name": "",
"date": "2016-02-08",
"status": "draft",
"payment_terms": 0,
"payment_terms_label": "Due On Receipt",
"due_date": "2016-02-08",
"payment_expected_date": "",
"stop_reminder_until_payment_expected_date": false,
"last_payment_date": "",
"reference_number": "",
"customer_id": "219715000000070001",
"estimate_id": "",
"is_client_review_settings_enabled": false,
"customer_name": "sunil",
"contact_persons": [],
"currency_id": "219715000000000099",
"currency_code": "INR",
"currency_symbol": "Rs.",
"exchange_rate": 1,
"discount": 0,
"discount_applied_on_amount": 0,
"is_discount_before_tax": true,
"discount_type": "item_level",
"recurring_invoice_id": "",
"documents": [],
"is_viewed_by_client": false,
"client_viewed_time": "",
"is_inclusive_tax": false,
"line_items": [
{
"line_item_id": "219715000000070015",
"item_id": "",
"salesorder_item_id": "",
"project_id": "",
"time_entry_ids": "",
"expense_id": "",
"expense_receipt_name": "",
"name": "Hard Drive",
"description": "500GB, USB 2.0 interface 1400 rpm, protective hard case.",
"item_order": 1,
"bcy_rate": 120,
"rate": 120,
"quantity": 1,
"unit": "",
"discount_amount": 0,
"discount": 0,
"tax_id": "",
"tax_name": "",
"tax_type": "tax",
"tax_percentage": 0,
"item_total": 120,
"documents": []
}
],
"shipping_charge": 0,
"adjustment": 0,
"adjustment_description": "",
"late_fee": {
"name": "",
"type": "percentage",
"rate": 0,
"amount": 0,
"frequency_type": "month"
},
"sub_total": 120,
"tax_total": 0,
"total": 120,
"taxes": [],
"payment_reminder_enabled": true,
"payment_made": 0,
"credits_applied": 0,
"tax_amount_withheld": 0,
"balance": 120,
"write_off_amount": 0,
"allow_partial_payments": false,
"price_precision": 2,
"payment_options": {
"payment_gateways": []
},
"is_emailed": false,
"reminders_sent": 0,
"last_reminder_sent_date": "",
"billing_address": {
"address": "",
"city": "",
"state": "",
"zip": "",
"country": "",
"fax": ""
},
"shipping_address": {
"address": "",
"city": "",
"state": "",
"zip": "",
"country": "",
"fax": ""
},
"notes": "Thanks for your business.",
"terms": "",
"custom_fields": [],
"template_id": "219715000000043021",
"template_name": "Grand",
"template_type": "grand",
"created_time": "2016-02-08T13:26:53+0530",
"last_modified_time": "2016-02-08T13:26:53+0530",
"created_by_id": "219715000000043001",
"attachment_name": "",
"can_send_in_mail": false,
"salesperson_id": "",
"salesperson_name": "",
"is_autobill_enabled": false,
"invoice_url": "https://invoice.zoho.com/portal/sampletest/secure?CInvoiceID=2-576e0c8724661463e3ad3e00ecf1cf09a0fd32de6df1ccd4e6cddd11545a3935460d2a05eb636b8d30214a816848de1cc28700b0dfd6eff4" }
}

失败响应:

{"message":"Invalid value passed for contact_name","code":4}