Apple Script Samples for Invoice 3



Invoce 3 is Apple Scriptable for your automations. Here you can find some sample codes how to use Invoice 3 in your automations.
  • Creating New Store

    tell
    application "Invoice3"

    set myStore to store named "My Great Store"
    if not (myStore exists) then
    set myStore to make new store
    set name of myStore to "My Great Store"
    set owner of myStore to system attribute "USER"
    end if

    end tell
  • Creating Category

    tell
    application "Invoice3"
    tell default store
    set theCategory to category named "Apple Hardware"
    if not (theCategory exists) then
    set theCategory to make new category with properties {name:"Apple Hardware"}
    end if
    end tell
    end tell
  • Creating Item

    tell application "Invoice3"
    tell default store

    -- Get the category named 'Apple Hardware' or create the category

    set theCategory to category named "Apple Hardware"
    if not (theCategory exists) then
    set theCategory to make new category with properties {name:"Apple Hardware"}
    end if

    set theProduct to make new product with properties {name:"Macbook Pro 15\"", price:1999.9, cost price:1600.0, unit:"pc"}


    -- Setting a color will help us to find the product easier
    -- You could of course set this property also in the 'with properties' record

    set color of theProduct to red

    -- You can add a product to as many categories as you want

    add product theProduct to theCategory

    -- You can use 'remove product' to remove a product from a category
    -- This will not delete the product. Just removes from the category

    -- remove product theProduct from theCategory

    -- Customize product by setting a custom field.
    -- Just to demonstrate the 'customize' command

    set systemUser to system attribute "USER"
    customize theProduct by name "created by" value systemUser

    end tell
    end tell
  • Creating Project

    tell application "Invoice3"
    tell default store

    -- First project

    set firstProject to make new project with properties {name:"Invoice 3", website:"http://www.invoice3.com", description:"Created using 'with properties'"}

    -- Second project

    set secondProject to make new project
    tell secondProject
    set name to "Refactoring Code"
    -- nr is optional. Keep in mind that 'make new project' has
    -- increased the counter for project numbers if you set a nr again
    set nr to "ABC-123"
    end tell

    -- Set a customer. Note that at least one customer must exist
    -- See also "make_entry.scpt" for searching for customers

    set customer of secondProject to the first customer

    -- Customize project by setting a custom field.
    -- Just to demonstrate the 'customize' command

    set systemUser to system attribute "USER"
    customize secondProject by name "created by" value systemUser

    end tell
    end tell
  • Creating Customer

    tell application "Invoice3"
    tell default store
    set aCustomer to make new customer
    tell aCustomer
    set first name to "John"
    set last name to "Wesley"
    set company name to "eSell E-Commerce"
    set is company flag to true
    set street nr of primary address to "133 Stemmons Freeway, Suite 114"
    set zip of primary address to "75207"
    set city of primary address to "Dallas"
    set state of primary address to "Texas"
    set country of primary address to "United States"
    end tell

    set anotherAddress to add address to aCustomer
    tell anotherAddress
    set street nr to "133 Stemmons Freeway, Suite 117"
    set zip to "75207"
    set city to "Dallas"
    set state to "Texas"
    set country to "United States"
    set recipient name to "Finance department"
    end tell

    -- Customize customer by setting a custom field.
    -- Just to demonstrate the 'customize' command

    set systemUser to system attribute "USER"
    customize aCustomer by name "created by" value systemUser

    end tell
    end tell
  • Creating invoice

    tell application "Invoice3"
    tell default store
    set theInvoice to make new invoice

    -- Get customer whose nr is 'ABC123'. If not exist create the customer
    -- See also make_customer for more information about creating customers

    set foundCustomers to every customer whose nr is "ABC123"
    if ((count of foundCustomers) is 0) then
    set aCustomer to make new customer with properties {first name:"John", last name:"Wesley", nr:"ABC123"}
    tell primary address of aCustomer
    set street nr to "133 Freeway, Suite 114"
    set zip to "75207"
    set city to "Dallas"
    set state to "Texas"
    set country to "United States"
    end tell
    else
    set aCustomer to first item in foundCustomers
    end if

    set customer of theInvoice to aCustomer
    set recipient name of theInvoice to the primary address of aCustomer

    -- Assign a project
    set theProject to the project named "Invoice3"
    if theProject is missing value then
    set theProject to make new project with properties {name:"Invoice3"}
    set customer of theProject to aCustomer
    end if

    set project of theInvoice to theProject

    -- This is optional. The default is false and will treat
    -- given line item prices as non tax added values

    set tax added flag of theInvoice to true

    -- Add some line items. Only 'with title' is mandatory
    -- Further parameters are rebate, cost price, nr and unit

    add line item to theInvoice with title "Hello World!" price 100 quantity 1 tax 19
    add line item to theInvoice with title "Hello World!" price 100 quantity 4 tax 19
    add line item to theInvoice with title "Hello World!" price 100 quantity 1 tax 19

    -- Customize entry by setting a custom field.
    -- Just to demonstrate the 'customize' command

    set systemUser to system attribute "USER"
    customize theInvoice by name "created by" value systemUser

    -- This is required to make an invoice from a draft
    -- Additionally this command will generate a PDF file

    process invoice theInvoice using layout "Summer"

    -- You can also create a PDF file without making an invoice
    -- draft. Just comment out the following line and set the pdf path

    -- create pdf from theInvoice to path "~/Desktop/Export" using layout "Summer"

    -- Display the generated PDF file using "Finder"

    set pdfPath to pdf path of theInvoice
    tell application "Finder" to open pdfPath as POSIX file
    end tell
    end tell
  • List Projects

    tell application "TextEdit"
    activate
    make new document at the beginning of documents
    set the name of window 1 to "projects.txt"

    tell application "Invoice3"
    tell default store
    repeat with aProject in every project
    set projectName to name of aProject
    set entryCount to count of every invoice of aProject
    set projectNr to nr of aProject
    tell application "TextEdit" to set lastText to text of the front document
    set lastText to lastText & projectName & " [" & projectNr & "] (" & (count of every invoice of aProject) & ")
    "
    tell application "TextEdit" to set the text of front document to lastText as text

    end repeat
    end tell
    end tell
    end tell