Class: Merge::Accounting::ExpenseRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/merge_ruby_client/accounting/types/expense_request.rb

Overview

# The Expense Object

### Description
The `Expense` object is used to represent a direct purchase by a business,
typically made with a check, credit card, or cash. Each `Expense` object is
dedicated to a grouping of expenses, with each expense recorded in the lines
object.
The `Expense` object is used also used to represent refunds to direct purchases.
Refunds can be distinguished from purchases by the amount sign of the records.
Expense objects with a negative amount are purchases and `Expense` objects with
a positive amount are refunds to those purchases.
### Usage Example
Fetch from the `GET Expense` endpoint and view a company's expense.

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transaction_date: OMIT, account: OMIT, contact: OMIT, total_amount: OMIT, sub_total: OMIT, total_tax_amount: OMIT, currency: OMIT, exchange_rate: OMIT, inclusive_of_tax: OMIT, company: OMIT, employee: OMIT, memo: OMIT, lines: OMIT, tracking_categories: OMIT, accounting_period: OMIT, integration_params: OMIT, linked_account_params: OMIT, remote_fields: OMIT, additional_properties: nil) ⇒ Merge::Accounting::ExpenseRequest



709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
# File 'lib/merge_ruby_client/accounting/types/expense_request.rb', line 709

def initialize(transaction_date: OMIT, account: OMIT, contact: OMIT, total_amount: OMIT, sub_total: OMIT,
               total_tax_amount: OMIT, currency: OMIT, exchange_rate: OMIT, inclusive_of_tax: OMIT, company: OMIT, employee: OMIT, memo: OMIT, lines: OMIT, tracking_categories: OMIT, accounting_period: OMIT, integration_params: OMIT, linked_account_params: OMIT, remote_fields: OMIT, additional_properties: nil)
  @transaction_date = transaction_date if transaction_date != OMIT
  @account =  if  != OMIT
  @contact = contact if contact != OMIT
  @total_amount = total_amount if total_amount != OMIT
  @sub_total = sub_total if sub_total != OMIT
  @total_tax_amount = total_tax_amount if total_tax_amount != OMIT
  @currency = currency if currency != OMIT
  @exchange_rate = exchange_rate if exchange_rate != OMIT
  @inclusive_of_tax = inclusive_of_tax if inclusive_of_tax != OMIT
  @company = company if company != OMIT
  @employee = employee if employee != OMIT
  @memo = memo if memo != OMIT
  @lines = lines if lines != OMIT
  @tracking_categories = tracking_categories if tracking_categories != OMIT
  @accounting_period = accounting_period if accounting_period != OMIT
  @integration_params = integration_params if integration_params != OMIT
  @linked_account_params =  if  != OMIT
  @remote_fields = remote_fields if remote_fields != OMIT
  @additional_properties = additional_properties
  @_field_set = {
    "transaction_date": transaction_date,
    "account": ,
    "contact": contact,
    "total_amount": total_amount,
    "sub_total": sub_total,
    "total_tax_amount": total_tax_amount,
    "currency": currency,
    "exchange_rate": exchange_rate,
    "inclusive_of_tax": inclusive_of_tax,
    "company": company,
    "employee": employee,
    "memo": memo,
    "lines": lines,
    "tracking_categories": tracking_categories,
    "accounting_period": accounting_period,
    "integration_params": integration_params,
    "linked_account_params": ,
    "remote_fields": remote_fields
  }.reject do |_k, v|
    v == OMIT
  end
end

Instance Attribute Details

#accountMerge::Accounting::ExpenseRequestAccount (readonly)



34
35
36
# File 'lib/merge_ruby_client/accounting/types/expense_request.rb', line 34

def 
  @account
end

#accounting_periodMerge::Accounting::ExpenseRequestAccountingPeriod (readonly)



367
368
369
# File 'lib/merge_ruby_client/accounting/types/expense_request.rb', line 367

def accounting_period
  @accounting_period
end

#additional_propertiesOpenStruct (readonly)



375
376
377
# File 'lib/merge_ruby_client/accounting/types/expense_request.rb', line 375

def additional_properties
  @additional_properties
end

#companyMerge::Accounting::ExpenseRequestCompany (readonly)



357
358
359
# File 'lib/merge_ruby_client/accounting/types/expense_request.rb', line 357

def company
  @company
end

#contactMerge::Accounting::ExpenseRequestContact (readonly)



36
37
38
# File 'lib/merge_ruby_client/accounting/types/expense_request.rb', line 36

def contact
  @contact
end

#currencyMerge::Accounting::TransactionCurrencyEnum (readonly)



350
351
352
# File 'lib/merge_ruby_client/accounting/types/expense_request.rb', line 350

def currency
  @currency
end

#employeeMerge::Accounting::ExpenseRequestEmployee (readonly)



359
360
361
# File 'lib/merge_ruby_client/accounting/types/expense_request.rb', line 359

def employee
  @employee
end

#exchange_rateString (readonly)



352
353
354
# File 'lib/merge_ruby_client/accounting/types/expense_request.rb', line 352

def exchange_rate
  @exchange_rate
end

#inclusive_of_taxBoolean (readonly)



355
356
357
# File 'lib/merge_ruby_client/accounting/types/expense_request.rb', line 355

def inclusive_of_tax
  @inclusive_of_tax
end

#integration_paramsHash{String => Object} (readonly)



369
370
371
# File 'lib/merge_ruby_client/accounting/types/expense_request.rb', line 369

def integration_params
  @integration_params
end

#linesArray<Merge::Accounting::ExpenseLineRequest> (readonly)



363
364
365
# File 'lib/merge_ruby_client/accounting/types/expense_request.rb', line 363

def lines
  @lines
end

#linked_account_paramsHash{String => Object} (readonly)



371
372
373
# File 'lib/merge_ruby_client/accounting/types/expense_request.rb', line 371

def 
  @linked_account_params
end

#memoString (readonly)



361
362
363
# File 'lib/merge_ruby_client/accounting/types/expense_request.rb', line 361

def memo
  @memo
end

#remote_fieldsArray<Merge::Accounting::RemoteFieldRequest> (readonly)



373
374
375
# File 'lib/merge_ruby_client/accounting/types/expense_request.rb', line 373

def remote_fields
  @remote_fields
end

#sub_totalFloat (readonly)



40
41
42
# File 'lib/merge_ruby_client/accounting/types/expense_request.rb', line 40

def sub_total
  @sub_total
end

#total_amountFloat (readonly)



38
39
40
# File 'lib/merge_ruby_client/accounting/types/expense_request.rb', line 38

def total_amount
  @total_amount
end

#total_tax_amountFloat (readonly)



42
43
44
# File 'lib/merge_ruby_client/accounting/types/expense_request.rb', line 42

def total_tax_amount
  @total_tax_amount
end

#tracking_categoriesArray<Merge::Accounting::ExpenseRequestTrackingCategoriesItem> (readonly)



365
366
367
# File 'lib/merge_ruby_client/accounting/types/expense_request.rb', line 365

def tracking_categories
  @tracking_categories
end

#transaction_dateDateTime (readonly)



32
33
34
# File 'lib/merge_ruby_client/accounting/types/expense_request.rb', line 32

def transaction_date
  @transaction_date
end

Class Method Details

.from_json(json_object:) ⇒ Merge::Accounting::ExpenseRequest

Deserialize a JSON object to an instance of ExpenseRequest



758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
# File 'lib/merge_ruby_client/accounting/types/expense_request.rb', line 758

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  transaction_date = (DateTime.parse(parsed_json["transaction_date"]) unless parsed_json["transaction_date"].nil?)
  if parsed_json["account"].nil?
     = nil
  else
     = parsed_json["account"].to_json
     = Merge::Accounting::ExpenseRequestAccount.from_json(json_object: )
  end
  if parsed_json["contact"].nil?
    contact = nil
  else
    contact = parsed_json["contact"].to_json
    contact = Merge::Accounting::ExpenseRequestContact.from_json(json_object: contact)
  end
  total_amount = parsed_json["total_amount"]
  sub_total = parsed_json["sub_total"]
  total_tax_amount = parsed_json["total_tax_amount"]
  currency = parsed_json["currency"]
  exchange_rate = parsed_json["exchange_rate"]
  inclusive_of_tax = parsed_json["inclusive_of_tax"]
  if parsed_json["company"].nil?
    company = nil
  else
    company = parsed_json["company"].to_json
    company = Merge::Accounting::ExpenseRequestCompany.from_json(json_object: company)
  end
  if parsed_json["employee"].nil?
    employee = nil
  else
    employee = parsed_json["employee"].to_json
    employee = Merge::Accounting::ExpenseRequestEmployee.from_json(json_object: employee)
  end
  memo = parsed_json["memo"]
  lines = parsed_json["lines"]&.map do |item|
    item = item.to_json
    Merge::Accounting::ExpenseLineRequest.from_json(json_object: item)
  end
  tracking_categories = parsed_json["tracking_categories"]&.map do |item|
    item = item.to_json
    Merge::Accounting::ExpenseRequestTrackingCategoriesItem.from_json(json_object: item)
  end
  if parsed_json["accounting_period"].nil?
    accounting_period = nil
  else
    accounting_period = parsed_json["accounting_period"].to_json
    accounting_period = Merge::Accounting::ExpenseRequestAccountingPeriod.from_json(json_object: accounting_period)
  end
  integration_params = parsed_json["integration_params"]
   = parsed_json["linked_account_params"]
  remote_fields = parsed_json["remote_fields"]&.map do |item|
    item = item.to_json
    Merge::Accounting::RemoteFieldRequest.from_json(json_object: item)
  end
  new(
    transaction_date: transaction_date,
    account: ,
    contact: contact,
    total_amount: total_amount,
    sub_total: sub_total,
    total_tax_amount: total_tax_amount,
    currency: currency,
    exchange_rate: exchange_rate,
    inclusive_of_tax: inclusive_of_tax,
    company: company,
    employee: employee,
    memo: memo,
    lines: lines,
    tracking_categories: tracking_categories,
    accounting_period: accounting_period,
    integration_params: integration_params,
    linked_account_params: ,
    remote_fields: remote_fields,
    additional_properties: struct
  )
end

.validate_raw(obj:) ⇒ Void

Leveraged for Union-type generation, validate_raw attempts to parse the given

hash and check each fields type against the current object's property
definitions.


849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
# File 'lib/merge_ruby_client/accounting/types/expense_request.rb', line 849

def self.validate_raw(obj:)
  obj.transaction_date&.is_a?(DateTime) != false || raise("Passed value for field obj.transaction_date is not the expected type, validation failed.")
  obj..nil? || Merge::Accounting::ExpenseRequestAccount.validate_raw(obj: obj.)
  obj.contact.nil? || Merge::Accounting::ExpenseRequestContact.validate_raw(obj: obj.contact)
  obj.total_amount&.is_a?(Float) != false || raise("Passed value for field obj.total_amount is not the expected type, validation failed.")
  obj.sub_total&.is_a?(Float) != false || raise("Passed value for field obj.sub_total is not the expected type, validation failed.")
  obj.total_tax_amount&.is_a?(Float) != false || raise("Passed value for field obj.total_tax_amount is not the expected type, validation failed.")
  obj.currency&.is_a?(Merge::Accounting::TransactionCurrencyEnum) != false || raise("Passed value for field obj.currency is not the expected type, validation failed.")
  obj.exchange_rate&.is_a?(String) != false || raise("Passed value for field obj.exchange_rate is not the expected type, validation failed.")
  obj.inclusive_of_tax&.is_a?(Boolean) != false || raise("Passed value for field obj.inclusive_of_tax is not the expected type, validation failed.")
  obj.company.nil? || Merge::Accounting::ExpenseRequestCompany.validate_raw(obj: obj.company)
  obj.employee.nil? || Merge::Accounting::ExpenseRequestEmployee.validate_raw(obj: obj.employee)
  obj.memo&.is_a?(String) != false || raise("Passed value for field obj.memo is not the expected type, validation failed.")
  obj.lines&.is_a?(Array) != false || raise("Passed value for field obj.lines is not the expected type, validation failed.")
  obj.tracking_categories&.is_a?(Array) != false || raise("Passed value for field obj.tracking_categories is not the expected type, validation failed.")
  obj.accounting_period.nil? || Merge::Accounting::ExpenseRequestAccountingPeriod.validate_raw(obj: obj.accounting_period)
  obj.integration_params&.is_a?(Hash) != false || raise("Passed value for field obj.integration_params is not the expected type, validation failed.")
  obj.&.is_a?(Hash) != false || raise("Passed value for field obj.linked_account_params is not the expected type, validation failed.")
  obj.remote_fields&.is_a?(Array) != false || raise("Passed value for field obj.remote_fields is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of ExpenseRequest to a JSON object



839
840
841
# File 'lib/merge_ruby_client/accounting/types/expense_request.rb', line 839

def to_json(*_args)
  @_field_set&.to_json
end