module SKApi module Resources class Invoice < SKApi::Resources::Base def save save_with_validation end def open self.put(:open, :id => self.id) # PUT /invoices/:id/open end # rethink def print(template_id) self.get(:print, :template_id => template_id) # GET /invoices.pdf?template_id=:ids end def mail(template_id, cc, bcc) self.get(:print, :template_id => template_id) # GET /invoices.pdf?template_id=:ids end ########################################################################## # Class methods ########################################################################## def self.schema { "type" => "object", "properties" => SKApi::Resources::Invoice.schema_props} end def self.schema_props { "id" => {"type" => "string", "identity" => true, "optional" => true, "readonly" => true}, "number" => {"type" => "string", "optional" => true}, "date" => {"type" => "string", "format" =>"date", "optional" => true}, "due_days" => {"type" => "integer", "optional" => true}, "title" => {"type" => "string", "optional" => true}, "status" => {"type" => "string", "enum" => ["draft", "open", "closed"], "default" =>"draft", "optional" => true}, "payment_method" => {"type" => "string", "enum" => ["cash", "bank_transfer", "credit_card", "paypal", "direct_debit", "cheque"], "optional" => true}, "due_date" => {"type" => "string", "format" =>"date", "optional" => true}, "notes_before" => {"type" => "string", "optional" => true}, "notes_after" => {"type" => "string", "optional" => true}, "price_total" => {"type" => "number", "optional" => true, "readonly" => true}, "price_tax" => {"type" => "number", "optional" => true, "readonly" => true}, "created_at" => {"type" => "string", "format" =>"date-time", "optional" => true, "readonly"=> true}, "updated_at" => {"type" => "string", "format" =>"date-time", "optional" => true, "readonly"=> true}, "address_field" => {"type" => "string", "optional" => true}, "lock_version" => {"type" => "integer", "optional" => true, "readonly" => true}, "client_id" => {"type" => "string"}, "client" => {"type" => "object", "properties" => SKApi::Resources::Client.schema_props, "optional" => true, "readonly" => true}, "line_items" => {"type" => "array","properties" => SKApi::Resources::LineItem.schema_props, "optional" => true} } end def self.api_links #internal links on fields=> id => salesking.eu/clients/4567.json [:edit, :destroy, :copy, :print, :show, :payments, :payment_new] # [ :edit, # :destroy, # { :copy =>"invoices/new?source=#{self.id}" }, # :open => "PUT invoices/#{self.id}/open", # :print, # :show, ] end end end end