Module: Invoicexpress::Client::PurchaseOrders

Included in:
Invoicexpress::Client
Defined in:
lib/invoicexpress/client/purchase_orders.rb

Instance Method Summary collapse

Instance Method Details

#create_purchase_order(purchase_order, options = {}) ⇒ Object

Creates a new purchase order. Creates a new purchase order. Also allows to create a new supplier and/or new items in the same request. If the supplier name does not exist a new one is created. If items do not exist with the given names, new ones will be created. If item name already exists, the item is updated with the new values. Regarding item taxes, if the tax name is not found, no tax is applyed to that item.

Parameters:

Returns:

  • Invoicexpress::Models::PurchaseOrder The PurchaseOrder

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

  • Invoicexpress::UnprocessableEntity When there are errors on the submission



28
29
30
31
32
33
# File 'lib/invoicexpress/client/purchase_orders.rb', line 28

def create_purchase_order(purchase_order, options={})
  raise(ArgumentError, "purchase order has the wrong type") unless purchase_order.is_a?(Invoicexpress::Models::PurchaseOrder)

  params = { :klass => Invoicexpress::Models::PurchaseOrder, :body => purchase_order }
  post("purchase_orders.xml", params.merge(options))
end

#purchase_order(purchase_order, options = {}) ⇒ Object

Returns a specific purchase order.

Parameters:

Returns:

  • Invoicexpress::Models::PurchaseOrder The PurchaseOrder

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

  • Invoicexpress::NotFound When the purchase_order doesn’t exist



41
42
43
44
45
# File 'lib/invoicexpress/client/purchase_orders.rb', line 41

def purchase_order(purchase_order, options={})
  params = { :klass => Invoicexpress::Models::PurchaseOrder }

  get("purchase_orders/#{id_from_purchase_order(purchase_order)}.xml", params.merge(options))
end

#purchase_order_mail(purchase_order_id, message, options = {}) ⇒ Object

Sends the purchase order by email

Parameters:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

  • Invoicexpress::UnprocessableEntity When there are errors on the submission

  • Invoicexpress::NotFound When the credit note doesn’t exist



105
106
107
108
109
110
# File 'lib/invoicexpress/client/purchase_orders.rb', line 105

def purchase_order_mail(purchase_order_id, message, options={})
  raise(ArgumentError, "message has the wrong type") unless message.is_a?(Invoicexpress::Models::Message)

  params = { :body => message, :klass => Invoicexpress::Models::PurchaseOrder }
  put("purchase_orders/#{purchase_order_id}/email-document.xml", params.merge(options))
end

#purchase_orders(options = {}) ⇒ Array<Invoicexpress::Models::PurchaseOrder>

Returns all your purchase orders.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • page (Integer) — default: 1

    You can ask a specific page of PurchaseOrders

Returns:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized



11
12
13
14
15
# File 'lib/invoicexpress/client/purchase_orders.rb', line 11

def purchase_orders(options = {})
  params = { :page => 1, :klass => Invoicexpress::Models::PurchaseOrder }

  get("purchase_orders.xml", params.merge(options))
end

#update_purchase_order(purchase_order, options = {}) ⇒ Object

Updates a purchase order Updates a purchase order. Also allows to create a new supplier and/or new items in the same request. If the supplier name does not exist a new one is created. If items do not exist with the given names, new ones will be created. If item name already exists, the item is updated with the new values. Regarding item taxes, if the tax name is not found, no tax is applyed to that item. Be careful when updating the invoice items, any missing items from the original invoice will be deleted.

Parameters:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

  • Invoicexpress::UnprocessableEntity When there are errors on the submission

  • Invoicexpress::NotFound When the credit note doesn’t exist



59
60
61
62
63
64
65
66
67
# File 'lib/invoicexpress/client/purchase_orders.rb', line 59

def update_purchase_order(purchase_order, options={})
  raise(ArgumentError, "purchase order has the wrong type") unless purchase_order.is_a?(Invoicexpress::Models::PurchaseOrder)

  if !purchase_order.id
    raise ArgumentError, "Purchase Order ID is required"
  end
  params = { :klass => Invoicexpress::Models::PurchaseOrder, :body => purchase_order.to_core_purchase_order }
  put("purchase_orders/#{purchase_order.id}.xml", params.merge(options))
end

#update_purchase_order_state(purchase_order_id, purchase_order_state, options = {}) ⇒ Invoicexpress::Models::PurchaseOrder

Changes the state of a purchase order. Possible state transitions:

  • draft to final – finalized

  • draft to deleted – deleted

  • final to second_copy – second_copy

  • final to accepted – accepted

  • final to refused – refused

  • final to canceled – canceled

  • second_copy to canceled – canceled

  • accepted to refused – refused

  • accepted to completed – completed

  • refused to canceled – canceled

  • refused to accepted – accepted

Any other transitions will fail. When canceling an purchase order you must specify a reason.

Parameters:

Returns:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

  • Invoicexpress::UnprocessableEntity When there are errors on the submission

  • Invoicexpress::NotFound When the credit note doesn’t exist



91
92
93
94
95
96
# File 'lib/invoicexpress/client/purchase_orders.rb', line 91

def update_purchase_order_state(purchase_order_id, purchase_order_state, options={})
  raise(ArgumentError, "purchase_order_state has the wrong type") unless purchase_order_state.is_a?(Invoicexpress::Models::InvoiceState)

  params = { :klass => Invoicexpress::Models::PurchaseOrder, :body => purchase_order_state }
  put("purchase_orders/#{purchase_order_id}/change-state.xml", params.merge(options))
end