Invoice create

Method invoice_create is used for creating new invoices.

Return value

This method returns an InvoiceStatus struct.

Arguments

  1. api_keys (required)
  2. InvoiceParamsIn (required)

Example code in Ruby

 1 require 'soap/wsdlDriver'
 2 require 'soap/attachment'
 3 
 4 server = SOAP::WSDLDriverFactory.new("https://testing.maventa.com/apis/bravo/wsdl").create_rpc_driver
 5 
 6 #Set up API keys
 7 api_keys = Hash.new
 8 api_keys[:vendor_api_key] = "" # Partner software API key
 9 api_keys[:user_api_key] = "" # User API key
10 api_keys[:company_uuid] = "" # UUID of current company
11 
12 #Set up customer information
13 customer = Hash.new
14 customer[:customer_nr] = "1001" 
15 customer[:name] = "Test Customer" 
16 customer[:address1] = "Post Address" 
17 customer[:post_code] = "00100" 
18 customer[:post_office] = "TEST" 
19 customer[:country] = "FI" 
20 customer[:lang] = "FI" 
21 customer[:contact_p] = "John Doe" 
22 customer[:email] = "customer@maventa.com" 
23 customer[:bid] = "FI1234567" 
24 customer[:ovt] = "00371111111" 
25 
26 #Set up invoice items
27 items_out = Array.new
28 inv_item = Hash.new
29 inv_item[:subject]    = "Test item" 
30 inv_item[:unit_type]  = "pcs" 
31 inv_item[:amount]     = "1" 
32 inv_item[:price]      = "200" 
33 inv_item[:discount]   = "50" 
34 inv_item[:definition] = "" 
35 inv_item[:tax]        = "22" 
36 inv_item[:sum]        = "100" 
37 inv_item[:sum_tax]    = "122" 
38 items_out.push(inv_item)
39 
40 #Set up attachments
41 attachments_out = Array.new
42 fa = Hash.new
43 fa[:filename] = "invoice_1001.pdf" 
44 fa[:file] = SOAP::Attachment.new(File.new("invoice_1001.pdf"))
45 fa[:attachment_type] = "INVOICE_IMAGE" 
46 attachments_out.push(fa)
47 
48 fa = Hash.new
49 fa[:filename] = "attachment_1001.doc" 
50 fa[:file] = SOAP::Attachment.new(File.new("attachment_1001.doc"))
51 fa[:attachment_type] = "ATTACHMENT" 
52 attachments_out.push(fa)
53 
54 #Set up invoice information
55 invoice = Hash.new
56 invoice[:invoice_nr] = 1001
57 invoice[:date] = "20090915" 
58 invoice[:date_due] = "20090930" 
59 invoice[:currency] = "EUR" 
60 invoice[:notes] = "TEST INVOICE / DO NOT PAY" 
61 invoice[:sum] = "100" 
62 invoice[:sum_tax] = "122" 
63 invoice[:customer] = customer
64 invoice[:items] = items_out
65 invoice[:attachments] = attachments_out
66 
67 #Create the invoice
68 result = server.invoice_create(api_keys, invoice)
69 
70 puts result.status

Example code in C#

 1 //WSDL at https://testing.maventa.com/apis/bravo/wsdl needs to be added as web reference for the example to work
 2 
 3 using System;
 4 using System.IO;
 5 using System.Collections.Generic;
 6 using System.Drawing;
 7 using System.Windows.Forms;
 8 using MaventaAPI;
 9 
10 namespace MaventaDemo
11 {
12     public partial class MainForm : Form
13     {
14         public MainForm()
15         {
16             InitializeComponent();
17             MaventaService m_server = new MaventaService();
18 
19             ApiKeys apiKeys = new ApiKeys();
20             apiKeys.user_api_key = ""; //User API key
21             apiKeys.company_uuid = ""; //UUID of current company
22 
23             //Create invoice
24             InvoiceParamsIn invoiceOut = new InvoiceParamsIn();
25             invoiceOut.invoice_nr = "1001";
26             invoiceOut.reference_nr = "10016";
27             invoiceOut.date = "20090918";
28             invoiceOut.date_due = "20090925";
29             invoiceOut.sum = "200";
30             invoiceOut.sum_tax = "244";
31             invoiceOut.currency = "EUR";
32             invoiceOut.lang = "FI";
33 
34             //Customer information
35             CustomerParamsIn customerOut = new CustomerParamsIn();
36             customerOut.name = "Test Customer";
37             customerOut.bid = "FI1234567";
38                         customerOut.ovt = "0037111111";
39             customerOut.email = "customer@maventa.com";
40             customerOut.country = "FI";
41             invoiceOut.customer = customerOut;
42 
43             //Invoice items
44             ItemsIn[] itemArray = new ItemsIn[2];
45 
46             ItemsIn itemOut1 = new ItemsIn();
47             itemOut1.item_code = "TST001";
48             itemOut1.subject = "Test item 1";
49             itemOut1.definition = "blue";
50             itemOut1.amount = 1;
51             itemOut1.price = "100";
52             itemOut1.tax = 22;
53             itemOut1.sum = "100";
54             itemOut1.sum_tax = "122";
55             itemOut1.position = 1;
56 
57             ItemsIn itemOut2 = new ItemsIn();
58             itemOut2.item_code = "TST002";
59             itemOut2.subject = "Test item 2";
60             itemOut2.definition = "red";
61             itemOut2.amount = 1;
62             itemOut2.price = "100";
63             itemOut2.tax = 22;
64             itemOut2.sum = "100";
65             itemOut2.sum_tax = "122";
66             itemOut2.position = 2;
67 
68             itemArray[0] = itemOut1;
69             itemArray[1] = itemOut2;
70             invoiceOut.items = itemArray;
71 
72             //File attachments
73             FileAttachment[] fileArray = new FileAttachment[1];
74 
75             FileAttachment attachmentFile1 = new FileAttachment();
76             attachmentFile1.filename = "attachment1.doc";
77             attachmentFile1.file = File.ReadAllBytes("C:\\attachment1.doc");
78             attachmentFile1.attachment_type = "ATTACHMENT";
79 
80             fileArray[0] = attachmentFile1;
81             invoiceOut.attachments = fileArray;
82 
83             //Send invoice
84             InvoiceStatus invoiceResponse = new InvoiceStatus();
85             invoiceResponse = m_server.invoice_create(apiKeys, invoiceOut);
86             MessageBox.Show(invoiceResponse.status);
87         }
88     }
89 }
90 

Example code in PHP

 1 <?php
 2   require 'SOAP/Client.php';
 3   # NOTE! In PHP when using the 'SOAP/Client.php', all WSDL properties need to be present for request to work, use 'null' for values not used.
 4 
 5   $client = new SoapClient('https://testing.maventa.com/apis/bravo/wsdl');
 6 
 7   $api_keys = array();
 8   $api_keys["vendor_api_key"] = null;
 9   $api_keys["user_api_key"] = null;
10   $api_keys["company_uuid"] = null;
11 
12   # Gather needed data for invoice customer
13   $customer = array();
14   $customer["customer_nr"] = "1001";
15   $customer["name"] = "Test Customer";
16   $customer["email"] = "test.customer@maventa.com";
17   $customer["bid"] = "FI12345678";
18   $customer["address1"] = "Customer address";
19   $customer["address2"] = "";
20   $customer["post_code"] = "00100";
21   $customer["post_office"] = "Helsinki";
22   $customer["country"] = "FI";
23   $customer["contact_p"] = "Customer Test";
24   $customer["lang"] = "FI";
25   $customer["customer_type"] = "COMPANY";
26   $customer["state"] = null;
27   $customer["phone"] = null;
28   $customer["gsm"] = null;
29   $customer["ovt"] = null;
30 
31   # Gather invoice items into array
32   # NOTE! Items are an array of arrays
33   $items_out = array();
34 
35   $inv_items = array();
36   $inv_items["position"]   = 1;
37   $inv_items["item_code"]  = "itm0001";
38   $inv_items["subject"]    = "Test item";
39   $inv_items["unit_type"]  = "pcs";
40   $inv_items["amount"]     = 10;
41   $inv_items["price"]      = "10";
42   $inv_items["discount"]   = 0;
43   $inv_items["definition"] = "red";
44   $inv_items["tax"]        = 22;
45   $inv_items["sum"]        = "100";
46   $inv_items["sum_tax"]    = "122";
47 
48   array_push($items_out, $inv_items);
49 
50   # Gather invoice data
51   $invoice = array();
52   $invoice["invoice_nr"] = "1001";
53   $invoice["reference_nr"] = "10012";
54   $invoice["date"] = "20091028";
55   $invoice["date_due"] = "20091104";
56   $invoice["currency"] = "EUR";
57   $invoice["sum"] = "100.00";
58   $invoice["sum_tax"] = "122.00";
59   $invoice["lang"] = "FI";
60   $invoice["order_nr"] = null;
61   $invoice["company_comment"] = null;
62   $invoice["notes"] = null;
63   $invoice["customer_maventa_id"] = null;
64   $invoice["delivery_date"] = null;
65   $invoice["delivery_type"] = null;
66   $invoice["customer_reference"] = null;
67   $invoice["company_reference"] = null;
68   $invoice["company_paper_fee"] = null;
69   $invoice["company_interest"] = null;
70   $invoice["company_reminder"] = null;
71   $invoice["company_website"] = null;
72   $invoice["require_sign"] = null;
73   $invoice["disabled_routes"] = null;
74   $invoice["attachments"] = null;
75   $invoice["bank_accounts"] = null;
76   $invoice["company_postal"] = null;
77 
78   # Assign customer and item info to invoice
79   $invoice["customer"] = $customer;
80   $invoice["items"] = $items_out;
81 
82   $result = $client->invoice_create($api_keys, $invoice);
83   print $result->status;
84 ?>

Also available in: HTML TXT