lib/kashflow_api/models/receipt.rb in kashflow_api-0.0.3 vs lib/kashflow_api/models/receipt.rb in kashflow_api-0.1.0
- old
+ new
@@ -1,43 +1,41 @@
module KashflowApi
- class Receipt < KashflowApi::SoapObject
- def self.find(search)
- result = KashflowApi.api.get_receipt(search)
- self.build_from_soap(result.hash[:envelope][:body][:get_receipt_response][:get_receipt_result])
- end
+ class Receipt < KashflowApi::SoapObject
+ Keys = KashflowApi::Invoice::Keys
+
+ Finds = KashflowApi::Invoice::Finds
+
+ KFObject = { singular: "receipt", plural: "receipts" }
+
+ XMLKey = "InvoiceDBID"
+
+ def self.build_arguments(action, object, field, argument)
+ if action == "get"
+ expects argument, String
+ return "<ReceiptNumber>#{argument}</ReceiptNumber>" if object == "receipt"
+ elsif action == "update" || action == "insert"
+ expects argument, KashflowApi::Receipt
+ return "<ReceiptID>#{argument.receiptid}</ReceiptID><InvLine>#{argument.to_xml}</InvLine>" if field == "Line"
+ return "<ReceiptNumber>#{argument.invoicenumber}</ReceiptNumber><InvLine>#{argument.to_xml}</InvLine>" if field == "Number"
+ return "<Inv>#{argument.to_xml}</Inv>" if object == "receipt"
+ end
+ end
+
+ def save
+ if @hash["InvoiceDBID"] == "0"
+ insert_receipt
+ else
+ update_receipt
+ end
+ end
- def save
- if @hash["InvoiceDBID"] == "0"
- insert_receipt
- else
- update_receipt
- end
- end
-
- def to_xml
- xml = []
- id_line = ""
- @hash.keys.each do |key|
- if key == "InvoiceDBID"
- id_line = "<#{key}>#{@hash[key]}</#{key}>" unless @hash[key] == "0"
- else
- xml.push("<#{key}>#{@hash[key]}</#{key}>")
- end
- end
- [id_line, xml.join].join
- end
-
- private
-
- def blank_object_hash
- { "InvoiceNumber" => "", "InvoiceDate" => "", "DueDate" => "", "CustomerID" => "", "CustomerReference" => "", "InvoiceDBID" => "0" }
- end
+ private
- def update_receipt
- KashflowApi.api.update_receipt(self)
- end
+ def update_receipt
+ KashflowApi.api.update_receipt(self)
+ end
- def insert_receipt
- KashflowApi.api.insert_receipt(self)
- end
+ def insert_receipt
+ KashflowApi.api.insert_receipt(self)
end
+ end
end
\ No newline at end of file