Mass invoicing
Kevin Buckley
kevin.m.buckley at gmail.com
Thu Oct 9 20:45:26 EDT 2008
Here's some info about the underlying XML that might
be useful to you (I thought I had posted this before
but can't find the post - apologies for duplicating)
I had a little perl program that took a list of Customer
GUIDs and a set of Income Account GUIDs from which
they would be billed in the A/R account, and set up
Invoice and Entry entities for a list of dates
For reference, I was bulk creating Service Charge invoices
for folk in a block of flats that only got posted at the start
of each month.
The "trick" is to either have a GUID generator create
any you need on the fly, or, as i did it, decide on a format
for your GUIDS in advance and fill in bits of it with
sequential data. OF course, you need to ensure the
GUIDs are unique but I can be done.
For example, a GUID representing something to do with
Flat 2, might have the string
f1ac02
in it and furthermore might have the year and month
coded in
200701f1ac02
This is not to say that you should rely on the info
encapsulated in the GUID but it does make external
generation easier
loop over 01 02 03 .. 12
printf "<randomchars>2007%2df1ac02<randomchars>"
will give you twelve monthly GUIDs for some purpose.
Anyroad, enough of the specific to my needs info,here's
the relevant parts of the notes I made at the time:
Basically, the following fields link the various objects
gnc:GncInvoice gnc:GncEntry
<invoice:guid type="guid"> <entry:invoice type="guid">
gnc:GncInvoice gnc:GncCustomer
<owner:id type="guid"> <cust:guid type="guid">
gnc:GncEntry gnc:account
<entry:i-acct type="guid"> <act:id type="guid">
Here an the XML for an invoice that has not been posted yet
<gnc:GncInvoice version="2.0.0">
<invoice:guid type="guid">eb6db4dcc3eb0ce4548c54e0e0353c83</invoice:guid>
<invoice:id>000038</invoice:id>
<invoice:owner version="2.0.0">
<owner:type>gncCustomer</owner:type>
<owner:id type="guid">7f1e2c88490d8c2d10d2ad706fc36574</owner:id>
</invoice:owner>
<invoice:opened>
<ts:date>2007-02-01 00:00:00 +0000</ts:date>
</invoice:opened>
<invoice:active>1</invoice:active>
<invoice:currency>
<cmdty:space>ISO4217</cmdty:space>
<cmdty:id>GBP</cmdty:id>
</invoice:currency>
</gnc:GncInvoice>
The owner:id 7f1e2c88490d8c2d10d2ad706fc36574 references
<gnc:GncCustomer version="2.0.0">
<cust:guid type="guid">7f1e2c88490d8c2d10d2ad706fc36574</cust:guid>
<cust:name>Mr & Mrs Smith</cust:name>
<cust:id>20070201</cust:id>
<cust:addr version="2.0.0">
<addr:addr1>Flat 2</addr:addr1>
<addr:addr2>The Block</addr:addr2>
<addr:addr3>SOMETOWN</addr:addr3>
<addr:addr4>PO5 TCD</addr:addr4>
</cust:addr>
<cust:shipaddr version="2.0.0"/>
<cust:taxincluded>USEGLOBAL</cust:taxincluded>
<cust:active>1</cust:active>
<cust:discount>0/1</cust:discount>
<cust:credit>0/1</cust:credit>
<cust:currency>
<cmdty:space>ISO4217</cmdty:space>
<cmdty:id>GBP</cmdty:id>
</cust:currency>
<cust:use-tt>0</cust:use-tt>
</gnc:GncCustomer>
The invoice:guid eb6db4dcc3eb0ce4548c54e0e0353c83 references
<gnc:GncEntry version="2.0.0">
<entry:guid type="guid">59ea0cc10e5206bb4be6f8907276b264</entry:guid>
<entry:date>
<ts:date>2007-05-04 12:00:00 +0100</ts:date>
</entry:date>
<entry:entered>
<ts:date>2007-05-04 22:50:25 +0100</ts:date>
</entry:entered>
<entry:qty>1000000/1000000</entry:qty>
<entry:i-acct type="guid">26e7f4952452057644618418a842026a</entry:i-acct>
<entry:i-price>50000000/1000000</entry:i-price>
<entry:invoice type="guid">eb6db4dcc3eb0ce4548c54e0e0353c83</entry:invoice>
<entry:i-disc-type>PERCENT</entry:i-disc-type>
<entry:i-disc-how>PRETAX</entry:i-disc-how>
<entry:i-taxable>1</entry:i-taxable>
<entry:i-taxincluded>0</entry:i-taxincluded>
</gnc:GncEntry>
The entry:i-acct guid 26e7f4952452057644618418a842026a references
<gnc:account version="2.0.0">
<act:name>Flat 2</act:name>
<act:id type="guid">26e7f4952452057644618418a842026a</act:id>
<act:type>INCOME</act:type>
<act:commodity>
<cmdty:space>ISO4217</cmdty:space>
<cmdty:id>GBP</cmdty:id>
</act:commodity>
<act:commodity-scu>100</act:commodity-scu>
<act:parent type="guid">d52d6bbec058219379d0d3fd96c62bae</act:parent>
</gnc:account>
so let's try adding another one by changing the
invoice:guid to end in 84 not 83
<gnc:GncInvoice version="2.0.0">
<invoice:guid type="guid">eb6db4dcc3eb0ce4548c54e0e0353c84</invoice:guid>
<invoice:id>003002</invoice:id>
<invoice:owner version="2.0.0">
<owner:type>gncCustomer</owner:type>
<owner:id type="guid">7f1e2c88490d8c2d10d2ad706fc36574</owner:id>
</invoice:owner>
<invoice:opened>
<ts:date>2007-03-01 00:00:00 +0000</ts:date>
</invoice:opened>
<invoice:active>1</invoice:active>
<invoice:currency>
<cmdty:space>ISO4217</cmdty:space>
<cmdty:id>GBP</cmdty:id>
</invoice:currency>
</gnc:GncInvoice>
and creating a similar entry with the entry:invoice altered similarly
and by incrementing the entry:guid by one
<gnc:GncEntry version="2.0.0">
<entry:guid type="guid">59ea0cc10e5206bb4be6f8907276b265</entry:guid>
<entry:invoice type="guid">eb6db4dcc3eb0ce4548c54e0e0353c84</entry:invoice>
<entry:date>
<ts:date>2007-03-01 12:00:00 +0100</ts:date>
</entry:date>
<entry:entered>
<ts:date>2007-05-04 22:50:25 +0100</ts:date>
</entry:entered>
<entry:qty>1000000/1000000</entry:qty>
<entry:i-acct type="guid">26e7f4952452057644618418a842026a</entry:i-acct>
<entry:i-price>50000000/1000000</entry:i-price>
<entry:i-disc-type>PERCENT</entry:i-disc-type>
<entry:i-disc-how>PRETAX</entry:i-disc-how>
<entry:i-taxable>1</entry:i-taxable>
<entry:i-taxincluded>0</entry:i-taxincluded>
</gnc:GncEntry>
Seems to work
Note tha the Invoice number appears 3 times
In the List of Lots
<slot:value type="string">Invoice 000002</slot:value>
In the transaction
<trn:num>000002</trn:num>
And in an Invoice
<invoice:id>000002</invoice:id>
Posting an Invoice seems to
Add a gnc:lot to act:lots
<gnc:lot version="2.0.0">
<lot:id type="guid">af2613d28a4cac2e4d3e677739b4d78a</lot:id>
<lot:slots>
<slot>
<slot:key>title</slot:key>
<slot:value type="string">Invoice 002002</slot:value>
</slot>
<slot>
<slot:key>gncInvoice</slot:key>
<slot:value type="frame">
<slot>
<slot:key>invoice-guid</slot:key>
<slot:value type="guid">eb6db4dcc3eb0ce4548c54e0e0353c83</slot:val
ue>
</slot>
</slot:value>
</slot>
</lot:slots>
</gnc:lot>
but also adds a whopping great transaction with a pair of splits
and all that jazz
Not sure that posting is something you want to do by hand in XML-land
More information about the gnucash-user
mailing list