ledger_sync 1.0.10 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +36 -20
  3. data/README.md +105 -66
  4. data/ledger_sync.gemspec +1 -0
  5. data/lib/ledger_sync.rb +23 -4
  6. data/lib/ledger_sync/adaptors/operation.rb +28 -28
  7. data/lib/ledger_sync/adaptors/quickbooks_online/account/mapping.rb +325 -0
  8. data/lib/ledger_sync/adaptors/quickbooks_online/account/operations/create.rb +54 -0
  9. data/lib/ledger_sync/adaptors/quickbooks_online/account/operations/find.rb +38 -0
  10. data/lib/ledger_sync/adaptors/quickbooks_online/account/operations/update.rb +61 -0
  11. data/lib/ledger_sync/adaptors/quickbooks_online/account/searcher.rb +67 -0
  12. data/lib/ledger_sync/adaptors/quickbooks_online/adaptor.rb +18 -16
  13. data/lib/ledger_sync/adaptors/quickbooks_online/bill/operations/create.rb +65 -0
  14. data/lib/ledger_sync/adaptors/quickbooks_online/bill/operations/find.rb +37 -0
  15. data/lib/ledger_sync/adaptors/quickbooks_online/bill/operations/update.rb +69 -0
  16. data/lib/ledger_sync/adaptors/quickbooks_online/bill/searcher.rb +28 -0
  17. data/lib/ledger_sync/adaptors/quickbooks_online/customer/operations/create.rb +6 -6
  18. data/lib/ledger_sync/adaptors/quickbooks_online/customer/operations/find.rb +1 -3
  19. data/lib/ledger_sync/adaptors/quickbooks_online/customer/operations/update.rb +6 -9
  20. data/lib/ledger_sync/adaptors/quickbooks_online/customer/searcher.rb +2 -38
  21. data/lib/ledger_sync/adaptors/quickbooks_online/deposit/operations/create.rb +61 -0
  22. data/lib/ledger_sync/adaptors/quickbooks_online/deposit/operations/find.rb +36 -0
  23. data/lib/ledger_sync/adaptors/quickbooks_online/deposit/operations/update.rb +65 -0
  24. data/lib/ledger_sync/adaptors/quickbooks_online/deposit/searcher.rb +28 -0
  25. data/lib/ledger_sync/adaptors/quickbooks_online/expense/mapping.rb +15 -0
  26. data/lib/ledger_sync/adaptors/quickbooks_online/expense/operations/create.rb +68 -0
  27. data/lib/ledger_sync/adaptors/quickbooks_online/expense/operations/find.rb +39 -0
  28. data/lib/ledger_sync/adaptors/quickbooks_online/expense/operations/update.rb +72 -0
  29. data/lib/ledger_sync/adaptors/quickbooks_online/expense/searcher.rb +28 -0
  30. data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry/mapping.rb +14 -0
  31. data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry/operations/create.rb +56 -0
  32. data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry/operations/find.rb +34 -0
  33. data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry/operations/update.rb +60 -0
  34. data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry/searcher.rb +28 -0
  35. data/lib/ledger_sync/adaptors/quickbooks_online/operation.rb +30 -0
  36. data/lib/ledger_sync/adaptors/quickbooks_online/payment/operations/create.rb +8 -22
  37. data/lib/ledger_sync/adaptors/quickbooks_online/payment/operations/find.rb +0 -2
  38. data/lib/ledger_sync/adaptors/quickbooks_online/payment/operations/update.rb +6 -22
  39. data/lib/ledger_sync/adaptors/quickbooks_online/searcher.rb +45 -0
  40. data/lib/ledger_sync/adaptors/quickbooks_online/transfer/operations/create.rb +52 -0
  41. data/lib/ledger_sync/adaptors/quickbooks_online/transfer/operations/find.rb +36 -0
  42. data/lib/ledger_sync/adaptors/quickbooks_online/transfer/operations/update.rb +57 -0
  43. data/lib/ledger_sync/adaptors/quickbooks_online/vendor/operations/create.rb +46 -0
  44. data/lib/ledger_sync/adaptors/quickbooks_online/vendor/operations/find.rb +36 -0
  45. data/lib/ledger_sync/adaptors/quickbooks_online/vendor/operations/update.rb +51 -0
  46. data/lib/ledger_sync/adaptors/quickbooks_online/vendor/searcher.rb +64 -0
  47. data/lib/ledger_sync/adaptors/searcher.rb +3 -1
  48. data/lib/ledger_sync/adaptors/test/account/operations/create.rb +53 -0
  49. data/lib/ledger_sync/adaptors/test/account/operations/find.rb +38 -0
  50. data/lib/ledger_sync/adaptors/test/account/operations/invalid.rb +25 -0
  51. data/lib/ledger_sync/adaptors/test/account/operations/update.rb +50 -0
  52. data/lib/ledger_sync/adaptors/test/account/operations/valid.rb +31 -0
  53. data/lib/ledger_sync/adaptors/test/account/searcher.rb +40 -0
  54. data/lib/ledger_sync/adaptors/test/adaptor.rb +4 -4
  55. data/lib/ledger_sync/adaptors/test/customer/operations/create.rb +4 -6
  56. data/lib/ledger_sync/adaptors/test/customer/operations/find.rb +0 -2
  57. data/lib/ledger_sync/adaptors/test/customer/operations/update.rb +4 -6
  58. data/lib/ledger_sync/adaptors/test/customer/searcher.rb +2 -2
  59. data/lib/ledger_sync/adaptors/test/expense/operations/create.rb +54 -0
  60. data/lib/ledger_sync/adaptors/test/expense/operations/find.rb +39 -0
  61. data/lib/ledger_sync/adaptors/test/expense/operations/update.rb +57 -0
  62. data/lib/ledger_sync/adaptors/test/payment/operations/create.rb +4 -20
  63. data/lib/ledger_sync/adaptors/test/payment/operations/find.rb +0 -2
  64. data/lib/ledger_sync/adaptors/test/payment/operations/update.rb +4 -20
  65. data/lib/ledger_sync/adaptors/test/transfer/operations/create.rb +45 -0
  66. data/lib/ledger_sync/adaptors/test/transfer/operations/find.rb +36 -0
  67. data/lib/ledger_sync/adaptors/test/transfer/operations/update.rb +48 -0
  68. data/lib/ledger_sync/adaptors/test/vendor/operations/create.rb +47 -0
  69. data/lib/ledger_sync/adaptors/test/vendor/operations/find.rb +34 -0
  70. data/lib/ledger_sync/adaptors/test/vendor/operations/invalid.rb +21 -0
  71. data/lib/ledger_sync/adaptors/test/vendor/operations/update.rb +44 -0
  72. data/lib/ledger_sync/adaptors/test/vendor/operations/valid.rb +27 -0
  73. data/lib/ledger_sync/adaptors/test/vendor/searcher.rb +41 -0
  74. data/lib/ledger_sync/error/resource_errors.rb +24 -0
  75. data/lib/ledger_sync/resource.rb +24 -64
  76. data/lib/ledger_sync/resource_attribute.rb +50 -0
  77. data/lib/ledger_sync/resource_attribute/dirty_mixin.rb +49 -0
  78. data/lib/ledger_sync/resource_attribute/mixin.rb +90 -0
  79. data/lib/ledger_sync/resource_attribute/reference.rb +9 -0
  80. data/lib/ledger_sync/resource_attribute/reference/many.rb +34 -0
  81. data/lib/ledger_sync/resource_attribute/reference/one.rb +33 -0
  82. data/lib/ledger_sync/resource_attribute_set.rb +58 -0
  83. data/lib/ledger_sync/resources/account.rb +14 -0
  84. data/lib/ledger_sync/resources/bill.rb +17 -0
  85. data/lib/ledger_sync/resources/bill_line_item.rb +11 -0
  86. data/lib/ledger_sync/resources/customer.rb +5 -4
  87. data/lib/ledger_sync/resources/deposit.rb +16 -0
  88. data/lib/ledger_sync/resources/deposit_line_item.rb +11 -0
  89. data/lib/ledger_sync/resources/expense.rb +19 -0
  90. data/lib/ledger_sync/resources/expense_line_item.rb +11 -0
  91. data/lib/ledger_sync/resources/journal_entry.rb +13 -0
  92. data/lib/ledger_sync/resources/journal_entry_line_item.rb +12 -0
  93. data/lib/ledger_sync/resources/payment.rb +5 -3
  94. data/lib/ledger_sync/resources/transfer.rb +15 -0
  95. data/lib/ledger_sync/resources/vendor.rb +12 -0
  96. data/lib/ledger_sync/result.rb +0 -24
  97. data/lib/ledger_sync/type/boolean.rb +17 -0
  98. data/lib/ledger_sync/type/date.rb +17 -0
  99. data/lib/ledger_sync/type/float.rb +17 -0
  100. data/lib/ledger_sync/type/integer.rb +17 -0
  101. data/lib/ledger_sync/type/reference_many.rb +27 -0
  102. data/lib/ledger_sync/type/reference_one.rb +26 -0
  103. data/lib/ledger_sync/type/string.rb +17 -0
  104. data/lib/ledger_sync/type/value.rb +12 -0
  105. data/lib/ledger_sync/type/value_mixin.rb +19 -0
  106. data/lib/ledger_sync/util/hash_helpers.rb +16 -1
  107. data/lib/ledger_sync/util/resources_builder.rb +36 -9
  108. data/lib/ledger_sync/version.rb +1 -1
  109. metadata +92 -7
  110. data/lib/ledger_sync/adaptors/quickbooks_online/customer/operations/upsert.rb +0 -42
  111. data/lib/ledger_sync/adaptors/quickbooks_online/payment/operations/upsert.rb +0 -53
  112. data/lib/ledger_sync/adaptors/test/customer/operations/upsert.rb +0 -42
  113. data/lib/ledger_sync/adaptors/test/payment/operations/upsert.rb +0 -53
  114. data/lib/ledger_sync/sync.rb +0 -108
  115. data/lib/ledger_sync/util/coordinator.rb +0 -72
@@ -3,7 +3,7 @@
3
3
  module LedgerSync
4
4
  module Adaptors
5
5
  module Operation
6
- TYPES = %i[create find update upsert].freeze
6
+ TYPES = %i[create find update].freeze
7
7
 
8
8
  module Mixin
9
9
  module ClassMethods
@@ -30,16 +30,16 @@ module LedgerSync
30
30
 
31
31
  base.class_eval do
32
32
  serialize only: %i[
33
- adaptor
34
- after_operations
35
- before_operations
36
- operations
37
- resource
38
- root_operation
39
- result
40
- response
41
- original
42
- ]
33
+ adaptor
34
+ after_operations
35
+ before_operations
36
+ operations
37
+ resource
38
+ root_operation
39
+ result
40
+ response
41
+ original
42
+ ]
43
43
  end
44
44
  end
45
45
 
@@ -90,7 +90,7 @@ module LedgerSync
90
90
  operate
91
91
  rescue LedgerSync::Error => e
92
92
  failure(e)
93
- rescue => e
93
+ rescue StandardError => e
94
94
  parsed_error = adaptor.parse_operation_error(error: e, operation: self)
95
95
  raise e unless parsed_error
96
96
 
@@ -104,10 +104,6 @@ module LedgerSync
104
104
  @performed == true
105
105
  end
106
106
 
107
- def prepare
108
- build
109
- end
110
-
111
107
  # Results
112
108
 
113
109
  def failure(error)
@@ -134,20 +130,28 @@ module LedgerSync
134
130
  result.success?
135
131
  end
136
132
 
133
+ def valid?
134
+ validate.success?
135
+ end
136
+
137
137
  def validate
138
138
  raise "#{self.class.name}::Contract must be defined to validate." unless self.class.const_defined?('Contract')
139
139
 
140
- serializer = resource.serializer
141
- serialized_resource = serializer.serialize[:objects][serializer.id][:data]
142
-
143
140
  Util::Validator.new(
144
141
  contract: self.class::Contract,
145
- data: serialized_resource
142
+ data: validation_data
146
143
  ).validate
147
144
  end
148
145
 
149
- def valid?
150
- validate.success?
146
+ def validation_data
147
+ serializer = resource.serializer(
148
+ do_not_serialize_if_class_is: Resource::PRIMITIVES
149
+ )
150
+ serializer.serialize[:objects][serializer.id][:data]
151
+ end
152
+
153
+ def errors
154
+ validate.validator.errors
151
155
  end
152
156
 
153
157
  # Comparison
@@ -174,17 +178,13 @@ module LedgerSync
174
178
 
175
179
  def merge_into(from:, to:)
176
180
  case to
177
- when String, Integer, Array then from
178
- else to.merge!(from) { |_key, old_value, new_value| merge_into(from: old_value, to: new_value) } if to && from
181
+ when *(Resource::PRIMITIVES | [Array]) then from
182
+ else to.merge!(from) { |_key, new_value, old_value| merge_into(from: old_value, to: new_value) } if to && from
179
183
  end
180
184
  end
181
185
 
182
186
  private
183
187
 
184
- def build
185
- add_root_operation self
186
- end
187
-
188
188
  def operate
189
189
  raise NotImplementedError, self.class.name
190
190
  end
@@ -0,0 +1,325 @@
1
+ module LedgerSync
2
+ module Adaptors
3
+ module QuickBooksOnline
4
+ module Account
5
+ module Mapping
6
+ ACCOUNT_CLASSIFICATIONS = {
7
+ 'asset' => 'Asset',
8
+ 'equity' => 'Equity',
9
+ 'expense' => 'Expense',
10
+ 'liability' => 'Liability',
11
+ 'revenue' => 'Revenue'
12
+ }
13
+
14
+ ACCOUNT_TYPES = {
15
+ 'bank' => 'Bank',
16
+ 'other_current_assets' => 'Other Current Asset',
17
+ 'fixed_asset' => 'Fixed Asset',
18
+ 'other_asset' => 'Other Asset',
19
+ 'accounts_receivable' => 'Accounts Receivable',
20
+ 'equity' => 'Equity',
21
+ 'expense' => 'Expense',
22
+ 'other_expense' => 'Other Expense',
23
+ 'cost_of_goods_sold' => 'Cost of Goods Sold',
24
+ 'accounts_payable' => 'Accounts Payable',
25
+ 'credit_card' => 'Credit Card',
26
+ 'long_term_liability' => 'Long Term Liability',
27
+ 'other_current_liability' => 'Other Current Liability',
28
+ 'income' => 'Income',
29
+ 'other_income' => 'Other Income'
30
+ }
31
+
32
+ ACCOUNT_SUB_TYPES = {
33
+ # Bank
34
+ 'cash_on_hand' => 'CashOnHand',
35
+ 'checking' => 'Checking',
36
+ 'money_market' => 'MoneyMarket',
37
+ 'rents_held_in_trust' => 'RentsHeldInTrust',
38
+ 'savings' => 'Savings',
39
+ 'trust_accounts' => 'TrustAccounts',
40
+ 'cash_and_cash_equivalents' => 'CashAndCashEquivalents',
41
+ 'other_ear_marked_bank_accounts' => 'OtherEarMarkedBankAccounts',
42
+ # Other Current Asset
43
+ 'allowance_for_bad_debts' => 'AllowanceForBadDebts',
44
+ 'development_costs' => 'DevelopmentCosts',
45
+ 'employee_cash_advances' => 'EmployeeCashAdvances',
46
+ 'other_current_assets' => 'OtherCurrentAssets',
47
+ 'inventory' => 'Inventory',
48
+ 'investment_mortgage_real_estate_loans' => 'Investment_MortgageRealEstateLoans',
49
+ 'investment_other' => 'Investment_Other',
50
+ 'investment_tax_exempt_securities' => 'Investment_TaxExemptSecurities',
51
+ 'investment_us_government_obligations' => 'Investment_USGovernmentObligations',
52
+ 'loans_to_officers' => 'LoansToOfficers',
53
+ 'loans_to_others' => 'LoansToOthers',
54
+ 'loans_to_stockholders' => 'LoansToStockholders',
55
+ 'prepaid_expenses' => 'PrepaidExpenses',
56
+ 'retainage' => 'Retainage',
57
+ 'undeposited_funds' => 'UndepositedFunds',
58
+ 'assets_available_for_sale' => 'AssetsAvailableForSale',
59
+ 'bal_with_govt_authorities' => 'BalWithGovtAuthorities',
60
+ 'called_up_share_capital_not_paid' => 'CalledUpShareCapitalNotPaid',
61
+ 'expenditure_authorisations_and_letters_of_credit' => 'ExpenditureAuthorisationsAndLettersOfCredit',
62
+ 'global_tax_deferred' => 'GlobalTaxDeferred',
63
+ 'global_tax_refund' => 'GlobalTaxRefund',
64
+ 'internal_transfers' => 'InternalTransfers',
65
+ 'other_consumables' => 'OtherConsumables',
66
+ 'provisions_current_assets' => 'ProvisionsCurrentAssets',
67
+ 'short_term_investments_in_related_parties' => 'ShortTermInvestmentsInRelatedParties',
68
+ 'short_term_loans_and_advances_to_related_parties' => 'ShortTermLoansAndAdvancesToRelatedParties',
69
+ 'trade_and_other_receivables' => 'TradeAndOtherReceivables',
70
+ # Fixed Asset
71
+ 'accumulated_depletion' => 'AccumulatedDepletion',
72
+ 'accumulated_depreciation' => 'AccumulatedDepreciation',
73
+ 'depletable_assets' => 'DepletableAssets',
74
+ 'fixed_asset_computers' => 'FixedAssetComputers',
75
+ 'fixed_asset_copiers' => 'FixedAssetCopiers',
76
+ 'fixed_asset_furniture' => 'FixedAssetFurniture',
77
+ 'fixed_asset_phone' => 'FixedAssetPhone',
78
+ 'fixed_asset_photo_video' => 'FixedAssetPhotoVideo',
79
+ 'fixed_asset_software' => 'FixedAssetSoftware',
80
+ 'fixed_asset_other_tools_equipment' => 'FixedAssetOtherToolsEquipment',
81
+ 'furniture_and_fixtures' => 'FurnitureAndFixtures',
82
+ 'land' => 'Land',
83
+ 'leasehold_improvements' => 'LeaseholdImprovements',
84
+ 'other_fixed_assets' => 'OtherFixedAssets',
85
+ 'accumulated_amortization' => 'AccumulatedAmortization',
86
+ 'buildings' => 'Buildings',
87
+ 'intangible_assets' => 'IntangibleAssets',
88
+ 'machinery_and_equipment' => 'MachineryAndEquipment',
89
+ 'vehicles' => 'Vehicles',
90
+ 'assets_in_course_of_construction' => 'AssetsInCourseOfConstruction',
91
+ 'capital_wip' => 'CapitalWip',
92
+ 'cumulative_depreciation_on_intangible_assets' => 'CumulativeDepreciationOnIntangibleAssets',
93
+ 'intangible_assets_under_development' => 'IntangibleAssetsUnderDevelopment',
94
+ 'land_asset' => 'LandAsset',
95
+ 'non_current_assets' => 'NonCurrentAssets',
96
+ 'participating_interests' => 'ParticipatingInterests',
97
+ 'provisions_fixed_assets' => 'ProvisionsFixedAssets',
98
+ # Other Asset
99
+ 'lease_buyout' => 'LeaseBuyout',
100
+ 'other_long_term_assets' => 'OtherLongTermAssets',
101
+ 'security_deposits' => 'SecurityDeposits',
102
+ 'accumulated_amortization_of_other_assets' => 'AccumulatedAmortizationOfOtherAssets',
103
+ 'goodwill' => 'Goodwill',
104
+ 'licenses' => 'Licenses',
105
+ 'organizational_costs' => 'OrganizationalCosts',
106
+ 'assets_held_for_sale' => 'AssetsHeldForSale',
107
+ 'available_for_sale_financial_assets' => 'AvailableForSaleFinancialAssets',
108
+ 'deferred_tax' => 'DeferredTax',
109
+ 'investments' => 'Investments',
110
+ 'long_term_investments' => 'LongTermInvestments',
111
+ 'long_term_loans_and_advances_to_related_parties' => 'LongTermLoansAndAdvancesToRelatedParties',
112
+ 'other_intangible_assets' => 'OtherIntangibleAssets',
113
+ 'other_long_term_investments' => 'OtherLongTermInvestments',
114
+ 'other_long_term_loans_and_advances' => 'OtherLongTermLoansAndAdvances',
115
+ 'prepayments_and_accrued_income' => 'PrepaymentsAndAccruedIncome',
116
+ 'provisions_non_current_assets' => 'ProvisionsNonCurrentAssets',
117
+ 'accounts_receivable' => 'AccountsReceivable',
118
+ # Equity
119
+ 'opening_balance_equity' => 'OpeningBalanceEquity',
120
+ 'partners_equity' => 'PartnersEquity',
121
+ 'retained_earnings' => 'RetainedEarnings',
122
+ 'accumulated_adjustment' => 'AccumulatedAdjustment',
123
+ 'owners_equity' => 'OwnersEquity',
124
+ 'paid_in_capital_or_surplus' => 'PaidInCapitalOrSurplus',
125
+ 'partner_contributions' => 'PartnerContributions',
126
+ 'partner_distributions' => 'PartnerDistributions',
127
+ 'preferred_stock' => 'PreferredStock',
128
+ 'common_stock' => 'CommonStock',
129
+ 'treasury_stock' => 'TreasuryStock',
130
+ 'estimated_taxes' => 'EstimatedTaxes',
131
+ 'healthcare' => 'Healthcare',
132
+ 'personal_income' => 'PersonalIncome',
133
+ 'personal_expense' => 'PersonalExpense',
134
+ 'accumulated_other_comprehensive_income' => 'AccumulatedOtherComprehensiveIncome',
135
+ 'called_up_share_capital' => 'CalledUpShareCapital',
136
+ 'capital_reserves' => 'CapitalReserves',
137
+ 'dividend_disbursed' => 'DividendDisbursed',
138
+ 'equity_in_earnings_of_subsiduaries' => 'EquityInEarningsOfSubsiduaries',
139
+ 'investment_grants' => 'InvestmentGrants',
140
+ 'money_received_against_share_warrants' => 'MoneyReceivedAgainstShareWarrants',
141
+ 'other_free_reserves' => 'OtherFreeReserves',
142
+ 'share_application_money_pending_allotment' => 'ShareApplicationMoneyPendingAllotment',
143
+ 'share_capital' => 'ShareCapital',
144
+ 'funds' => 'Funds',
145
+ # Expense
146
+ 'advertising_promotional' => 'AdvertisingPromotional',
147
+ 'bad_debts' => 'BadDebts',
148
+ 'bank_charges' => 'BankCharges',
149
+ 'charitable_contributions' => 'CharitableContributions',
150
+ 'entertainment' => 'Entertainment',
151
+ 'entertainment_meals' => 'EntertainmentMeals',
152
+ 'equipment_rental' => 'EquipmentRental',
153
+ 'finance_costs' => 'FinanceCosts',
154
+ 'global_tax_expense' => 'GlobalTaxExpense',
155
+ 'insurance' => 'Insurance',
156
+ 'interest_paid' => 'InterestPaid',
157
+ 'legal_professional_fees' => 'LegalProfessionalFees',
158
+ 'office_expenses' => 'OfficeExpenses',
159
+ 'office_general_administrative_expenses' => 'OfficeGeneralAdministrativeExpenses',
160
+ 'other_business_expenses' => 'OtherBusinessExpenses',
161
+ 'other_miscellaneous_service_cost' => 'OtherMiscellaneousServiceCost',
162
+ 'promotional_meals' => 'PromotionalMeals',
163
+ 'rent_or_lease_of_buildings' => 'RentOrLeaseOfBuildings',
164
+ 'repair_maintenance' => 'RepairMaintenance',
165
+ 'shipping_freight_delivery' => 'ShippingFreightDelivery',
166
+ 'supplies_materials' => 'SuppliesMaterials',
167
+ 'travel' => 'Travel',
168
+ 'travel_meals' => 'TravelMeals',
169
+ 'auto' => 'Auto',
170
+ 'cost_of_labor' => 'CostOfLabor',
171
+ 'dues_subscriptions' => 'DuesSubscriptions',
172
+ 'payroll_expenses' => 'PayrollExpenses',
173
+ 'taxes_paid' => 'TaxesPaid',
174
+ 'unapplied_cash_bill_payment_expense' => 'UnappliedCashBillPaymentExpense',
175
+ 'amortization_expense' => 'AmortizationExpense',
176
+ 'appropriations_to_depreciation' => 'AppropriationsToDepreciation',
177
+ 'borrowing_cost' => 'BorrowingCost',
178
+ 'commissions_and_fees' => 'CommissionsAndFees',
179
+ 'distribution_costs' => 'DistributionCosts',
180
+ 'external_services' => 'ExternalServices',
181
+ 'extraordinary_charges' => 'ExtraordinaryCharges',
182
+ 'income_tax_expense' => 'IncomeTaxExpense',
183
+ 'loss_on_discontinued_operations_net_of_tax' => 'LossOnDiscontinuedOperationsNetOfTax',
184
+ 'management_compensation' => 'ManagementCompensation',
185
+ 'other_current_operating_charges' => 'OtherCurrentOperatingCharges',
186
+ 'other_external_services' => 'OtherExternalServices',
187
+ 'other_rental_costs' => 'OtherRentalCosts',
188
+ 'other_selling_expenses' => 'OtherSellingExpenses',
189
+ 'project_studies_surveys_assessments' => 'ProjectStudiesSurveysAssessments',
190
+ 'purchases_rebates' => 'PurchasesRebates',
191
+ 'shipping_and_delivery_expense' => 'ShippingAndDeliveryExpense',
192
+ 'staff_costs' => 'StaffCosts',
193
+ 'sundry' => 'Sundry',
194
+ 'travel_expenses_general_and_admin_expenses' => 'TravelExpensesGeneralAndAdminExpenses',
195
+ 'travel_expenses_selling_expense' => 'TravelExpensesSellingExpense',
196
+ # Other Expense
197
+ 'depreciation' => 'Depreciation',
198
+ 'exchange_gain_or_loss' => 'ExchangeGainOrLoss',
199
+ 'other_miscellaneous_expense' => 'OtherMiscellaneousExpense',
200
+ 'penalties_settlements' => 'PenaltiesSettlements',
201
+ 'amortization' => 'Amortization',
202
+ 'gas_and_fuel' => 'GasAndFuel',
203
+ 'home_office' => 'HomeOffice',
204
+ 'home_owner_rental_insurance' => 'HomeOwnerRentalInsurance',
205
+ 'other_home_office_expenses' => 'OtherHomeOfficeExpenses',
206
+ 'mortgage_interest' => 'MortgageInterest',
207
+ 'rent_and_lease' => 'RentAndLease',
208
+ 'repairs_and_maintenance' => 'RepairsAndMaintenance',
209
+ 'parking_and_tolls' => 'ParkingAndTolls',
210
+ 'vehicle' => 'Vehicle',
211
+ 'vehicle_insurance' => 'VehicleInsurance',
212
+ 'vehicle_lease' => 'VehicleLease',
213
+ 'vehicle_loan_interest' => 'VehicleLoanInterest',
214
+ 'vehicle_loan' => 'VehicleLoan',
215
+ 'vehicle_registration' => 'VehicleRegistration',
216
+ 'vehicle_repairs' => 'VehicleRepairs',
217
+ 'other_vehicle_expenses' => 'OtherVehicleExpenses',
218
+ 'utilities' => 'Utilities',
219
+ 'wash_and_road_services' => 'WashAndRoadServices',
220
+ 'deferred_tax_expense' => 'DeferredTaxExpense',
221
+ 'depletion' => 'Depletion',
222
+ 'exceptional_items' => 'ExceptionalItems',
223
+ 'extraordinary_items' => 'ExtraordinaryItems',
224
+ 'income_tax_other_expense' => 'IncomeTaxOtherExpense',
225
+ 'mat_credit' => 'MatCredit',
226
+ 'prior_period_items' => 'PriorPeriodItems',
227
+ 'tax_roundoff_gain_or_loss' => 'TaxRoundoffGainOrLoss',
228
+ # Cost of Goods Sold
229
+ 'equipment_rental_cos' => 'EquipmentRentalCos',
230
+ 'other_costs_of_service_cos' => 'OtherCostsOfServiceCos',
231
+ 'shipping_freight_delivery_cos' => 'ShippingFreightDeliveryCos',
232
+ 'supplies_materials_cogs' => 'SuppliesMaterialsCogs',
233
+ 'cost_of_labor_cos' => 'CostOfLaborCos',
234
+ 'cost_of_sales' => 'CostOfSales',
235
+ 'freight_and_delivery_cost' => 'FreightAndDeliveryCost',
236
+ # Accounts Payable
237
+ 'accounts_payable' => 'AccountsPayable',
238
+ 'outstanding_dues_micro_small_enterprise' => 'OutstandingDuesMicroSmallEnterprise',
239
+ 'outstanding_dues_other_than_micro_small_enterprise' => 'OutstandingDuesOtherThanMicroSmallEnterprise',
240
+ # Credit Card
241
+ 'credit_card' => 'CreditCard',
242
+ # Long Term Liability
243
+ 'notes_payable' => 'NotesPayable',
244
+ 'other_long_term_liabilities' => 'OtherLongTermLiabilities',
245
+ 'shareholder_notes_payable' => 'ShareholderNotesPayable',
246
+ 'accruals_and_deferred_income' => 'AccrualsAndDeferredIncome',
247
+ 'accrued_long_lerm_liabilities' => 'AccruedLongLermLiabilities',
248
+ 'accrued_vacation_payable' => 'AccruedVacationPayable',
249
+ 'bank_loans' => 'BankLoans',
250
+ 'debts_related_to_participating_interests' => 'DebtsRelatedToParticipatingInterests',
251
+ 'deferred_tax_liabilities' => 'DeferredTaxLiabilities',
252
+ 'government_and_other_public_authorities' => 'GovernmentAndOtherPublicAuthorities',
253
+ 'group_and_associates' => 'GroupAndAssociates',
254
+ 'liabilities_related_to_assets_held_for_sale' => 'LiabilitiesRelatedToAssetsHeldForSale',
255
+ 'long_term_borrowings' => 'LongTermBorrowings',
256
+ 'long_term_debit' => 'LongTermDebit',
257
+ 'long_term_employee_benefit_obligations' => 'LongTermEmployeeBenefitObligations',
258
+ 'obligations_under_finance_leases' => 'ObligationsUnderFinanceLeases',
259
+ 'other_long_term_provisions' => 'OtherLongTermProvisions',
260
+ 'provision_for_liabilities' => 'ProvisionForLiabilities',
261
+ 'provisions_non_current_liabilities' => 'ProvisionsNonCurrentLiabilities',
262
+ 'staff_and_related_long_term_liability_accounts' => 'StaffAndRelatedLongTermLiabilityAccounts',
263
+ # Other Current Liability
264
+ 'direct_deposit_payable' => 'DirectDepositPayable',
265
+ 'line_of_credit' => 'LineOfCredit',
266
+ 'loan_payable' => 'LoanPayable',
267
+ 'global_tax_payable' => 'GlobalTaxPayable',
268
+ 'global_tax_suspense' => 'GlobalTaxSuspense',
269
+ 'other_current_liabilities' => 'OtherCurrentLiabilities',
270
+ 'payroll_clearing' => 'PayrollClearing',
271
+ 'payroll_tax_payable' => 'PayrollTaxPayable',
272
+ 'prepaid_expenses_payable' => 'PrepaidExpensesPayable',
273
+ 'rents_in_trust_liability' => 'RentsInTrustLiability',
274
+ 'trust_accounts_liabilities' => 'TrustAccountsLiabilities',
275
+ 'federal_income_tax_payable' => 'FederalIncomeTaxPayable',
276
+ 'insurance_payable' => 'InsurancePayable',
277
+ 'sales_tax_payable' => 'SalesTaxPayable',
278
+ 'state_local_income_tax_payable' => 'StateLocalIncomeTaxPayable',
279
+ 'accrued_liabilities' => 'AccruedLiabilities',
280
+ 'current_liabilities' => 'CurrentLiabilities',
281
+ 'current_portion_employee_benefits_obligations' => 'CurrentPortionEmployeeBenefitsObligations',
282
+ 'current_portion_of_obligations_under_finance_leases' => 'CurrentPortionOfObligationsUnderFinanceLeases',
283
+ 'current_tax_liability' => 'CurrentTaxLiability',
284
+ 'dividends_payable' => 'DividendsPayable',
285
+ 'duties_and_taxes' => 'DutiesAndTaxes',
286
+ 'interest_payables' => 'InterestPayables',
287
+ 'provision_for_warranty_obligations' => 'ProvisionForWarrantyObligations',
288
+ 'provisions_current_liabilities' => 'ProvisionsCurrentLiabilities',
289
+ 'short_term_borrowings' => 'ShortTermBorrowings',
290
+ 'social_security_agencies' => 'SocialSecurityAgencies',
291
+ 'staff_and_related_liability_accounts' => 'StaffAndRelatedLiabilityAccounts',
292
+ 'sundry_debtors_and_creditors' => 'SundryDebtorsAndCreditors',
293
+ 'trade_and_other_payables' => 'TradeAndOtherPayables',
294
+ # Income
295
+ 'non_profit_income' => 'NonProfitIncome',
296
+ 'other_primary_income' => 'OtherPrimaryIncome',
297
+ 'sales_of_product_income' => 'SalesOfProductIncome',
298
+ 'service_fee_income' => 'ServiceFeeIncome',
299
+ 'discounts_refunds_given' => 'DiscountsRefundsGiven',
300
+ 'unapplied_cash_payment_income' => 'UnappliedCashPaymentIncome',
301
+ 'cash_receipt_income' => 'CashReceiptIncome',
302
+ 'operating_grants' => 'OperatingGrants',
303
+ 'other_current_operating_income' => 'OtherCurrentOperatingIncome',
304
+ 'own_work_capitalized' => 'OwnWorkCapitalized',
305
+ 'revenue_general' => 'RevenueGeneral',
306
+ 'sales_retail' => 'SalesRetail',
307
+ 'sales_wholesale' => 'SalesWholesale',
308
+ 'savings_by_tax_scheme' => 'SavingsByTaxScheme',
309
+ # Other Income
310
+ 'dividend_income' => 'DividendIncome',
311
+ 'interest_earned' => 'InterestEarned',
312
+ 'other_investment_income' => 'OtherInvestmentIncome',
313
+ 'other_miscellaneous_income' => 'OtherMiscellaneousIncome',
314
+ 'tax_exempt_interest' => 'TaxExemptInterest',
315
+ 'gain_loss_on_sale_of_fixed_assets' => 'GainLossOnSaleOfFixedAssets',
316
+ 'gain_loss_on_sale_of_investments' => 'GainLossOnSaleOfInvestments',
317
+ 'loss_on_disposal_of_assets' => 'LossOnDisposalOfAssets',
318
+ 'other_operating_income' => 'OtherOperatingIncome',
319
+ 'unrealised_loss_on_securities_net_of_tax' => 'UnrealisedLossOnSecuritiesNetOfTax',
320
+ }
321
+ end
322
+ end
323
+ end
324
+ end
325
+ end
@@ -0,0 +1,54 @@
1
+ require 'ledger_sync/adaptors/quickbooks_online/account/mapping'
2
+
3
+ module LedgerSync
4
+ module Adaptors
5
+ module QuickBooksOnline
6
+ module Account
7
+ module Operations
8
+ class Create < Operation::Create
9
+ class Contract < LedgerSync::Adaptors::Contract
10
+ params do
11
+ required(:ledger_id).value(:nil)
12
+ required(:name).filled(:string)
13
+ required(:classification).filled(:string)
14
+ required(:account_type).filled(:string)
15
+ required(:account_sub_type).filled(:string)
16
+ required(:number).maybe(:integer)
17
+ required(:currency).maybe(:string)
18
+ required(:description).maybe(:string)
19
+ required(:active).maybe(:bool)
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def operate
26
+ response = adaptor.post(
27
+ resource: 'account',
28
+ payload: local_resource_data
29
+ )
30
+
31
+ resource.ledger_id = response.dig('Id')
32
+ success(response: response)
33
+ end
34
+
35
+ def local_resource_data
36
+ {
37
+ 'Name' => resource.name,
38
+ 'Classification' => Mapping::ACCOUNT_CLASSIFICATIONS[resource.classification],
39
+ 'AccountType' => Mapping::ACCOUNT_TYPES[resource.account_type],
40
+ 'AccountSubType' => Mapping::ACCOUNT_SUB_TYPES[resource.account_sub_type],
41
+ 'AcctNum' => resource.number,
42
+ 'CurrencyRef' => {
43
+ 'value' => resource.currency,
44
+ },
45
+ 'Description' => resource.description,
46
+ 'Active' => resource.active
47
+ }
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end