erp_txns_and_accts 4.0.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/app/controllers/api/v1/biz_txn_acct_roots_controller.rb +124 -0
 - data/app/controllers/api/v1/biz_txn_acct_types_controller.rb +130 -0
 - data/app/controllers/api/v1/biz_txn_events_controller.rb +53 -0
 - data/app/controllers/api/v1/biz_txn_types_controller.rb +131 -0
 - data/app/controllers/api/v1/financial_txns_controller.rb +53 -0
 - data/app/models/biz_txn_acct_pty_rtype.rb +1 -0
 - data/app/models/biz_txn_acct_root.rb +130 -6
 - data/app/models/biz_txn_acct_type.rb +2 -0
 - data/app/models/biz_txn_event.rb +229 -49
 - data/app/models/biz_txn_party_role_type.rb +6 -0
 - data/app/models/biz_txn_type.rb +23 -0
 - data/app/models/extensions/party.rb +4 -2
 - data/app/models/financial_txn.rb +108 -19
 - data/config/routes.rb +13 -0
 - data/db/data_migrations/20151216210147_add_default_gl_accounts.rb +33 -0
 - data/db/migrate/20080805000030_base_txns_and_accts.rb +129 -127
 - data/db/migrate/20151216202856_add_nested_set_to_biz_txn_acct_roots.rb +31 -0
 - data/db/migrate/20151231185337_add_billable_to_finanical_txn.rb +13 -0
 - data/db/migrate/20160310163051_add_created_by_updated_by_to_erp_txns_and_accts.rb +35 -0
 - data/db/migrate/20160628145626_upgrade_biz_txn_events_entered_date_data_type.rb +21 -0
 - data/lib/erp_txns_and_accts/extensions/active_record/acts_as_biz_txn_event.rb +29 -15
 - data/lib/erp_txns_and_accts/version.rb +1 -1
 - metadata +17 -10
 - data/db/data_migrations/20101014142230_financial_txn_types.rb +0 -15
 - data/db/migrate/20130408195119_add_biz_txn_acct_type_id_to_biz_txn_acct_root.rb +0 -5
 - data/db/migrate/20140523095709_add_custom_fields_to_biz_txn_events.rb +0 -10
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: ffd7bf7f798a95542011d353cc0edb33d57cd342
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 89145255844014ea63bf763f95b9179141b366d4
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: fbe1f69f358256a7e6e2ff1ebc1bf969f92bdc9a1493dd374488295ea91e73b09e432a1381d22a6ce285a666b8b8dc91d80643850dcad2a574626862158eb3d4
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 533ea3141db9f80eac766529560d0476a22c4a6f66de9fecc71968d8c260ce826fd7dcc218b61ac51549404b57a8bb1338ffb5d9c02b95cf2f76b1e74899affe
         
     | 
| 
         @@ -0,0 +1,124 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Api
         
     | 
| 
      
 2 
     | 
    
         
            +
              module V1
         
     | 
| 
      
 3 
     | 
    
         
            +
                class BizTxnAcctRootsController < BaseController
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
                  def index
         
     | 
| 
      
 6 
     | 
    
         
            +
                    sort = nil
         
     | 
| 
      
 7 
     | 
    
         
            +
                    dir = nil
         
     | 
| 
      
 8 
     | 
    
         
            +
                    limit = nil
         
     | 
| 
      
 9 
     | 
    
         
            +
                    start = nil
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                    unless params[:sort].blank?
         
     | 
| 
      
 12 
     | 
    
         
            +
                      sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
         
     | 
| 
      
 13 
     | 
    
         
            +
                      sort = sort_hash[:property] || 'description'
         
     | 
| 
      
 14 
     | 
    
         
            +
                      dir = sort_hash[:direction] || 'ASC'
         
     | 
| 
      
 15 
     | 
    
         
            +
                      limit = params[:limit] || 25
         
     | 
| 
      
 16 
     | 
    
         
            +
                      start = params[:start] || 0
         
     | 
| 
      
 17 
     | 
    
         
            +
                    end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                    query_filter = params[:query_filter].blank? ? {} : JSON.parse(params[:query_filter]).symbolize_keys
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                    # hook method to apply any scopes passed via parameters to this api
         
     | 
| 
      
 22 
     | 
    
         
            +
                    biz_txn_acct_roots = BizTxnAcctRoot.apply_filters(query_filter)
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                    # scope by dba_organizations if there are no parties passed as filters
         
     | 
| 
      
 25 
     | 
    
         
            +
                    dba_organizations = [current_user.party.dba_organization]
         
     | 
| 
      
 26 
     | 
    
         
            +
                    dba_organizations = dba_organizations.concat(current_user.party.dba_organization.child_dba_organizations)
         
     | 
| 
      
 27 
     | 
    
         
            +
                    biz_txn_acct_roots = biz_txn_acct_roots.scope_by_dba_organization(dba_organizations)
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                    respond_to do |format|
         
     | 
| 
      
 30 
     | 
    
         
            +
                      format.json do
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                        if sort and dir
         
     | 
| 
      
 33 
     | 
    
         
            +
                          biz_txn_acct_roots = biz_txn_acct_roots.order("#{sort} #{dir}")
         
     | 
| 
      
 34 
     | 
    
         
            +
                        end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                        total_count = biz_txn_acct_roots.count
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                        if start and limit
         
     | 
| 
      
 39 
     | 
    
         
            +
                          biz_txn_acct_roots = biz_txn_acct_roots.offset(start).limit(limit)
         
     | 
| 
      
 40 
     | 
    
         
            +
                        end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                        render :json => {success: true,
         
     | 
| 
      
 43 
     | 
    
         
            +
                                         total_count: total_count,
         
     | 
| 
      
 44 
     | 
    
         
            +
                                         biz_txn_acct_roots: biz_txn_acct_roots.collect { |item| item.to_data_hash }}
         
     | 
| 
      
 45 
     | 
    
         
            +
                      end
         
     | 
| 
      
 46 
     | 
    
         
            +
                      format.tree do
         
     | 
| 
      
 47 
     | 
    
         
            +
                        if params[:parent_id]
         
     | 
| 
      
 48 
     | 
    
         
            +
                          render :json => {success: true,
         
     | 
| 
      
 49 
     | 
    
         
            +
                                           biz_txn_acct_roots: BizTxnAcctRoot.find(params[:parent_id]).children_to_tree_hash}
         
     | 
| 
      
 50 
     | 
    
         
            +
                        else
         
     | 
| 
      
 51 
     | 
    
         
            +
                          nodes = [].tap do |nodes|
         
     | 
| 
      
 52 
     | 
    
         
            +
                            biz_txn_acct_roots.roots.each do |root|
         
     | 
| 
      
 53 
     | 
    
         
            +
                              nodes.push(root.to_tree_hash)
         
     | 
| 
      
 54 
     | 
    
         
            +
                            end
         
     | 
| 
      
 55 
     | 
    
         
            +
                          end
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
                          render :json => {success: true,
         
     | 
| 
      
 58 
     | 
    
         
            +
                                           biz_txn_acct_roots: nodes}
         
     | 
| 
      
 59 
     | 
    
         
            +
                        end
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
                      end
         
     | 
| 
      
 62 
     | 
    
         
            +
                      format.all_representation do
         
     | 
| 
      
 63 
     | 
    
         
            +
                        if params[:parent_id].present?
         
     | 
| 
      
 64 
     | 
    
         
            +
                          render :json => {success: true,
         
     | 
| 
      
 65 
     | 
    
         
            +
                                           biz_txn_acct_roots: BizTxnAcctRoot.to_all_representation(BizTxnAcctRoot.find(params[:parent_id]))}
         
     | 
| 
      
 66 
     | 
    
         
            +
                        else
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                          render :json => {success: true,
         
     | 
| 
      
 70 
     | 
    
         
            +
                                           biz_txn_acct_roots: BizTxnAcctRoot.to_all_representation(nil, [], 0, biz_txn_acct_roots.roots)}
         
     | 
| 
      
 71 
     | 
    
         
            +
                        end
         
     | 
| 
      
 72 
     | 
    
         
            +
                      end
         
     | 
| 
      
 73 
     | 
    
         
            +
                    end
         
     | 
| 
      
 74 
     | 
    
         
            +
                  end
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                  def create
         
     | 
| 
      
 77 
     | 
    
         
            +
                    description = params[:description].strip
         
     | 
| 
      
 78 
     | 
    
         
            +
                    external_identifier = params[:external_identifier].strip
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 81 
     | 
    
         
            +
                      ActiveRecord::Base.transaction do
         
     | 
| 
      
 82 
     | 
    
         
            +
                        biz_txn_acct_root = BizTxnAcctRoot.create(description: description,
         
     | 
| 
      
 83 
     | 
    
         
            +
                                                                  internal_identifier: description.to_iid,
         
     | 
| 
      
 84 
     | 
    
         
            +
                                                                  external_identifier: external_identifier)
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
                        if !params[:parent].blank? and params[:parent] != 'No Parent'
         
     | 
| 
      
 87 
     | 
    
         
            +
                          parent = BizTxnAcctRoot.iid(params[:parent])
         
     | 
| 
      
 88 
     | 
    
         
            +
                          biz_txn_acct_root.move_to_child_of(parent)
         
     | 
| 
      
 89 
     | 
    
         
            +
                        elsif !params[:default_parent].blank?
         
     | 
| 
      
 90 
     | 
    
         
            +
                          parent = BizTxnAcctRoot.iid(params[:default_parent])
         
     | 
| 
      
 91 
     | 
    
         
            +
                          biz_txn_acct_root.move_to_child_of(parent)
         
     | 
| 
      
 92 
     | 
    
         
            +
                        end
         
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
      
 94 
     | 
    
         
            +
                        if params[:biz_txn_acct_type_iid]
         
     | 
| 
      
 95 
     | 
    
         
            +
                          biz_txn_acct_root.biz_txn_acct_type = BizTxnAcctType.iid(params[:biz_txn_acct_type_iid])
         
     | 
| 
      
 96 
     | 
    
         
            +
                        end
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
                        BizTxnAcctPartyRole.create(biz_txn_acct_root: biz_txn_acct_root,
         
     | 
| 
      
 99 
     | 
    
         
            +
                                                   party: current_user.party.dba_organization,
         
     | 
| 
      
 100 
     | 
    
         
            +
                                                   biz_txn_acct_pty_rtype: BizTxnAcctPtyRtype.find_or_create('dba_org', 'DBA Organization'))
         
     | 
| 
      
 101 
     | 
    
         
            +
             
     | 
| 
      
 102 
     | 
    
         
            +
                        biz_txn_acct_root.created_by_party = current_user.party
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
                        biz_txn_acct_root.save!
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
      
 106 
     | 
    
         
            +
                        render :json => {success: true, biz_txn_type: biz_txn_acct_root.to_data_hash}
         
     | 
| 
      
 107 
     | 
    
         
            +
                      end
         
     | 
| 
      
 108 
     | 
    
         
            +
                    rescue ActiveRecord::RecordInvalid => invalid
         
     | 
| 
      
 109 
     | 
    
         
            +
                      Rails.logger.error invalid.record.errors.full_messages
         
     | 
| 
      
 110 
     | 
    
         
            +
             
     | 
| 
      
 111 
     | 
    
         
            +
                      render json: {:success => false, :message => invalid.record.errors.full_messages.join('</br>')}
         
     | 
| 
      
 112 
     | 
    
         
            +
                    rescue => ex
         
     | 
| 
      
 113 
     | 
    
         
            +
                      Rails.logger.error ex.message
         
     | 
| 
      
 114 
     | 
    
         
            +
                      Rails.logger.error ex.backtrace.join("\n")
         
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
      
 116 
     | 
    
         
            +
                      ExceptionNotifier.notify_exception(ex) if defined? ExceptionNotifier
         
     | 
| 
      
 117 
     | 
    
         
            +
             
     | 
| 
      
 118 
     | 
    
         
            +
                      render json: {:success => false, :message => "Error creating record"}
         
     | 
| 
      
 119 
     | 
    
         
            +
                    end
         
     | 
| 
      
 120 
     | 
    
         
            +
                  end
         
     | 
| 
      
 121 
     | 
    
         
            +
             
     | 
| 
      
 122 
     | 
    
         
            +
                end # BizTxnAcctRootsController
         
     | 
| 
      
 123 
     | 
    
         
            +
              end # V1
         
     | 
| 
      
 124 
     | 
    
         
            +
            end # Api
         
     | 
| 
         @@ -0,0 +1,130 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Api
         
     | 
| 
      
 2 
     | 
    
         
            +
              module V1
         
     | 
| 
      
 3 
     | 
    
         
            +
                class BizTxnAcctTypesController < BaseController
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
                  def index
         
     | 
| 
      
 6 
     | 
    
         
            +
                    if !params[:parent].blank?
         
     | 
| 
      
 7 
     | 
    
         
            +
                      parent = nil
         
     | 
| 
      
 8 
     | 
    
         
            +
                      # create parent if it doesn't exist
         
     | 
| 
      
 9 
     | 
    
         
            +
                      # if the parent param is a comma separated string then
         
     | 
| 
      
 10 
     | 
    
         
            +
                      # the parent is nested from left to right
         
     | 
| 
      
 11 
     | 
    
         
            +
                      params[:parent].split(',').each do |parent_iid|
         
     | 
| 
      
 12 
     | 
    
         
            +
                        if parent
         
     | 
| 
      
 13 
     | 
    
         
            +
                          parent = BizTxnAcctType.find_or_create(parent_iid, parent_iid.humanize, parent)
         
     | 
| 
      
 14 
     | 
    
         
            +
                        else
         
     | 
| 
      
 15 
     | 
    
         
            +
                          parent = BizTxnAcctType.find_or_create(parent_iid, parent_iid.humanize)
         
     | 
| 
      
 16 
     | 
    
         
            +
                        end
         
     | 
| 
      
 17 
     | 
    
         
            +
                      end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                      respond_to do |format|
         
     | 
| 
      
 20 
     | 
    
         
            +
                        format.tree do
         
     | 
| 
      
 21 
     | 
    
         
            +
                          render :json => {success: true, biz_txn_acct_types: parent.children_to_tree_hash}
         
     | 
| 
      
 22 
     | 
    
         
            +
                        end
         
     | 
| 
      
 23 
     | 
    
         
            +
                        format.json do
         
     | 
| 
      
 24 
     | 
    
         
            +
                          render :json => {success: true, biz_txn_acct_types: BizTxnAcctType.to_all_representation(parent)}
         
     | 
| 
      
 25 
     | 
    
         
            +
                        end
         
     | 
| 
      
 26 
     | 
    
         
            +
                      end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                      # if ids are passed look up on the txn types with the ids passed
         
     | 
| 
      
 29 
     | 
    
         
            +
                    elsif params[:ids]
         
     | 
| 
      
 30 
     | 
    
         
            +
                      ids = params[:ids].split(',').compact
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                      biz_txn_acct_types = []
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                      ids.each do |id|
         
     | 
| 
      
 35 
     | 
    
         
            +
                        # check if id is a integer if so fine by id
         
     | 
| 
      
 36 
     | 
    
         
            +
                        if id.is_integer?
         
     | 
| 
      
 37 
     | 
    
         
            +
                          biz_txn_acct_type = BizTxnAcctType.find(id)
         
     | 
| 
      
 38 
     | 
    
         
            +
                        else
         
     | 
| 
      
 39 
     | 
    
         
            +
                          biz_txn_acct_type = BizTxnAcctType.iid(id)
         
     | 
| 
      
 40 
     | 
    
         
            +
                        end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                        respond_to do |format|
         
     | 
| 
      
 43 
     | 
    
         
            +
                          format.tree do
         
     | 
| 
      
 44 
     | 
    
         
            +
                            data = biz_txn_acct_type.to_hash({
         
     | 
| 
      
 45 
     | 
    
         
            +
                                                            only: [:id, :parent_id, :internal_identifier, :description],
         
     | 
| 
      
 46 
     | 
    
         
            +
                                                            leaf: biz_txn_acct_type.leaf?,
         
     | 
| 
      
 47 
     | 
    
         
            +
                                                            text: biz_txn_acct_type.to_label,
         
     | 
| 
      
 48 
     | 
    
         
            +
                                                            children: []
         
     | 
| 
      
 49 
     | 
    
         
            +
                                                        })
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                            parent = nil
         
     | 
| 
      
 52 
     | 
    
         
            +
                            biz_txn_acct_types.each do |biz_txn_acct_type_hash|
         
     | 
| 
      
 53 
     | 
    
         
            +
                              if biz_txn_acct_type_hash[:id] == data[:parent_id]
         
     | 
| 
      
 54 
     | 
    
         
            +
                                parent = biz_txn_acct_type_hash
         
     | 
| 
      
 55 
     | 
    
         
            +
                              end
         
     | 
| 
      
 56 
     | 
    
         
            +
                            end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                            if parent
         
     | 
| 
      
 59 
     | 
    
         
            +
                              parent[:children].push(data)
         
     | 
| 
      
 60 
     | 
    
         
            +
                            else
         
     | 
| 
      
 61 
     | 
    
         
            +
                              biz_txn_acct_types.push(data)
         
     | 
| 
      
 62 
     | 
    
         
            +
                            end
         
     | 
| 
      
 63 
     | 
    
         
            +
                          end
         
     | 
| 
      
 64 
     | 
    
         
            +
                          format.json do
         
     | 
| 
      
 65 
     | 
    
         
            +
                            biz_txn_acct_types.push(biz_txn_acct_type.to_hash(only: [:id, :description, :internal_identifier]))
         
     | 
| 
      
 66 
     | 
    
         
            +
                          end
         
     | 
| 
      
 67 
     | 
    
         
            +
                        end
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                      end
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
                      render :json => {success: true, biz_txn_acct_types: biz_txn_acct_types}
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
                      # get all txn types
         
     | 
| 
      
 74 
     | 
    
         
            +
                    else
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                      respond_to do |format|
         
     | 
| 
      
 77 
     | 
    
         
            +
                        format.tree do
         
     | 
| 
      
 78 
     | 
    
         
            +
                          nodes = [].tap do |nodes|
         
     | 
| 
      
 79 
     | 
    
         
            +
                            BizTxnAcctType.roots.each do |root|
         
     | 
| 
      
 80 
     | 
    
         
            +
                              nodes.push(root.to_tree_hash)
         
     | 
| 
      
 81 
     | 
    
         
            +
                            end
         
     | 
| 
      
 82 
     | 
    
         
            +
                          end
         
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
      
 84 
     | 
    
         
            +
                          render :json => {success: true, biz_txn_acct_types: nodes}
         
     | 
| 
      
 85 
     | 
    
         
            +
                        end
         
     | 
| 
      
 86 
     | 
    
         
            +
                        format.json do
         
     | 
| 
      
 87 
     | 
    
         
            +
                          render :json => {success: true, biz_txn_acct_types: BizTxnAcctType.to_all_representation}
         
     | 
| 
      
 88 
     | 
    
         
            +
                        end
         
     | 
| 
      
 89 
     | 
    
         
            +
                      end
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
                    end
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
                  end
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
                  def create
         
     | 
| 
      
 96 
     | 
    
         
            +
                    description = params[:description].strip
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
                      ActiveRecord::Base.transaction do
         
     | 
| 
      
 101 
     | 
    
         
            +
                        biz_txn_acct_type = BizTxnAcctType.create(description: description, internal_identifier: description.to_iid)
         
     | 
| 
      
 102 
     | 
    
         
            +
             
     | 
| 
      
 103 
     | 
    
         
            +
                        if !params[:parent].blank? and params[:parent] != 'No Parent'
         
     | 
| 
      
 104 
     | 
    
         
            +
                          parent = BizTxnAcctType.iid(params[:parent])
         
     | 
| 
      
 105 
     | 
    
         
            +
                          biz_txn_acct_type.move_to_child_of(parent)
         
     | 
| 
      
 106 
     | 
    
         
            +
                        elsif !params[:default_parent].blank?
         
     | 
| 
      
 107 
     | 
    
         
            +
                          parent = BizTxnAcctType.iid(params[:default_parent])
         
     | 
| 
      
 108 
     | 
    
         
            +
                          biz_txn_acct_type.move_to_child_of(parent)
         
     | 
| 
      
 109 
     | 
    
         
            +
                        end
         
     | 
| 
      
 110 
     | 
    
         
            +
             
     | 
| 
      
 111 
     | 
    
         
            +
                        render :json => {success: true, biz_txn_acct_type: biz_txn_acct_type.to_hash(only: [:id, :description, :internal_identifier])}
         
     | 
| 
      
 112 
     | 
    
         
            +
                      end
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
                    rescue ActiveRecord::RecordInvalid => invalid
         
     | 
| 
      
 115 
     | 
    
         
            +
                      Rails.logger.error invalid.record.errors.full_messages
         
     | 
| 
      
 116 
     | 
    
         
            +
             
     | 
| 
      
 117 
     | 
    
         
            +
                      {:success => false, :message => invalid.record.errors.full_messages.join('</br>')}
         
     | 
| 
      
 118 
     | 
    
         
            +
                    rescue => ex
         
     | 
| 
      
 119 
     | 
    
         
            +
                      Rails.logger.error ex.message
         
     | 
| 
      
 120 
     | 
    
         
            +
                      Rails.logger.error ex.backtrace.join("\n")
         
     | 
| 
      
 121 
     | 
    
         
            +
             
     | 
| 
      
 122 
     | 
    
         
            +
                      ExceptionNotifier.notify_exception(ex) if defined? ExceptionNotifier
         
     | 
| 
      
 123 
     | 
    
         
            +
             
     | 
| 
      
 124 
     | 
    
         
            +
                      {:success => false, :message => "Error creating record"}
         
     | 
| 
      
 125 
     | 
    
         
            +
                    end
         
     | 
| 
      
 126 
     | 
    
         
            +
                  end
         
     | 
| 
      
 127 
     | 
    
         
            +
             
     | 
| 
      
 128 
     | 
    
         
            +
                end # BizTxnAcctTypesController
         
     | 
| 
      
 129 
     | 
    
         
            +
              end # V1
         
     | 
| 
      
 130 
     | 
    
         
            +
            end # Api
         
     | 
| 
         @@ -0,0 +1,53 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Api
         
     | 
| 
      
 2 
     | 
    
         
            +
              module V1
         
     | 
| 
      
 3 
     | 
    
         
            +
                class BizTxnEventsController < BaseController
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
                  def index
         
     | 
| 
      
 6 
     | 
    
         
            +
                    sort = nil
         
     | 
| 
      
 7 
     | 
    
         
            +
                    dir = nil
         
     | 
| 
      
 8 
     | 
    
         
            +
                    limit = nil
         
     | 
| 
      
 9 
     | 
    
         
            +
                    start = nil
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                    unless params[:sort].blank?
         
     | 
| 
      
 12 
     | 
    
         
            +
                      sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
         
     | 
| 
      
 13 
     | 
    
         
            +
                      sort = sort_hash[:property] || 'description'
         
     | 
| 
      
 14 
     | 
    
         
            +
                      dir = sort_hash[:direction] || 'ASC'
         
     | 
| 
      
 15 
     | 
    
         
            +
                      limit = params[:limit] || 25
         
     | 
| 
      
 16 
     | 
    
         
            +
                      start = params[:start] || 0
         
     | 
| 
      
 17 
     | 
    
         
            +
                    end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                    query_filter = params[:query_filter].blank? ? {} : JSON.parse(params[:query_filter]).symbolize_keys
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                    # hook method to apply any scopes passed via parameters to this api
         
     | 
| 
      
 22 
     | 
    
         
            +
                    biz_txn_events = BizTxnEvent.apply_filters(query_filter)
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                    # scope by dba_organizations if there are no parties passed as filters
         
     | 
| 
      
 25 
     | 
    
         
            +
                    unless query_filter[:parties]
         
     | 
| 
      
 26 
     | 
    
         
            +
                      dba_organizations = [current_user.party.dba_organization]
         
     | 
| 
      
 27 
     | 
    
         
            +
                      dba_organizations = dba_organizations.concat(current_user.party.dba_organization.child_dba_organizations)
         
     | 
| 
      
 28 
     | 
    
         
            +
                      biz_txn_events = biz_txn_events.scope_by_dba_organization(dba_organizations)
         
     | 
| 
      
 29 
     | 
    
         
            +
                    end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                    if sort and dir
         
     | 
| 
      
 32 
     | 
    
         
            +
                      biz_txn_events = biz_txn_events.order("#{sort} #{dir}")
         
     | 
| 
      
 33 
     | 
    
         
            +
                    end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                    total_count = biz_txn_events.count
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                    if start and limit
         
     | 
| 
      
 38 
     | 
    
         
            +
                      biz_txn_events = biz_txn_events.offset(start).limit(limit)
         
     | 
| 
      
 39 
     | 
    
         
            +
                    end
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                    render :json => {total_count: total_count, biz_txn_events: biz_txn_events.collect(&:to_data_hash)}
         
     | 
| 
      
 42 
     | 
    
         
            +
                  end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                  def show
         
     | 
| 
      
 45 
     | 
    
         
            +
                    biz_txn_event = BizTxnEvent.find(params[:id])
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                    render :json => {biz_txn_event: biz_txn_event.to_data_hash}
         
     | 
| 
      
 48 
     | 
    
         
            +
                  end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                end # BizTxnEvents
         
     | 
| 
      
 52 
     | 
    
         
            +
              end # V1
         
     | 
| 
      
 53 
     | 
    
         
            +
            end # Api
         
     | 
| 
         @@ -0,0 +1,131 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Api
         
     | 
| 
      
 2 
     | 
    
         
            +
              module V1
         
     | 
| 
      
 3 
     | 
    
         
            +
                class BizTxnTypesController < BaseController
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
                  def index
         
     | 
| 
      
 6 
     | 
    
         
            +
                    if !params[:parent].blank?
         
     | 
| 
      
 7 
     | 
    
         
            +
                      parent = nil
         
     | 
| 
      
 8 
     | 
    
         
            +
                      # create parent if it doesn't exist
         
     | 
| 
      
 9 
     | 
    
         
            +
                      # if the parent param is a comma separated string then
         
     | 
| 
      
 10 
     | 
    
         
            +
                      # the parent is nested from left to right
         
     | 
| 
      
 11 
     | 
    
         
            +
                      params[:parent].split(',').each do |parent_iid|
         
     | 
| 
      
 12 
     | 
    
         
            +
                        if parent
         
     | 
| 
      
 13 
     | 
    
         
            +
                          parent = BizTxnType.find_or_create(parent_iid, parent_iid.humanize, parent)
         
     | 
| 
      
 14 
     | 
    
         
            +
                        else
         
     | 
| 
      
 15 
     | 
    
         
            +
                          parent = BizTxnType.find_or_create(parent_iid, parent_iid.humanize)
         
     | 
| 
      
 16 
     | 
    
         
            +
                        end
         
     | 
| 
      
 17 
     | 
    
         
            +
                      end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                      respond_to do |format|
         
     | 
| 
      
 20 
     | 
    
         
            +
                        format.tree do
         
     | 
| 
      
 21 
     | 
    
         
            +
                          render :json => {success: true, biz_txn_types: parent.children_to_tree_hash}
         
     | 
| 
      
 22 
     | 
    
         
            +
                        end
         
     | 
| 
      
 23 
     | 
    
         
            +
                        format.json do
         
     | 
| 
      
 24 
     | 
    
         
            +
                          render :json => {success: true, biz_txn_types: BizTxnType.to_all_representation(parent)}
         
     | 
| 
      
 25 
     | 
    
         
            +
                        end
         
     | 
| 
      
 26 
     | 
    
         
            +
                      end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                      # if ids are passed look up on the txn types with the ids passed
         
     | 
| 
      
 29 
     | 
    
         
            +
                    elsif params[:ids]
         
     | 
| 
      
 30 
     | 
    
         
            +
                      ids = params[:ids].split(',').compact
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                      biz_txn_types = []
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                      ids.each do |id|
         
     | 
| 
      
 35 
     | 
    
         
            +
                        # check if id is a integer if so fine by id
         
     | 
| 
      
 36 
     | 
    
         
            +
                        if id.is_integer?
         
     | 
| 
      
 37 
     | 
    
         
            +
                          biz_txn_type = BizTxnType.find(id)
         
     | 
| 
      
 38 
     | 
    
         
            +
                        else
         
     | 
| 
      
 39 
     | 
    
         
            +
                          biz_txn_type = BizTxnType.iid(id)
         
     | 
| 
      
 40 
     | 
    
         
            +
                        end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                        if biz_txn_type
         
     | 
| 
      
 43 
     | 
    
         
            +
                          respond_to do |format|
         
     | 
| 
      
 44 
     | 
    
         
            +
                            format.tree do
         
     | 
| 
      
 45 
     | 
    
         
            +
                              data = biz_txn_type.to_hash({
         
     | 
| 
      
 46 
     | 
    
         
            +
                                                            only: [:id, :parent_id, :internal_identifier, :description],
         
     | 
| 
      
 47 
     | 
    
         
            +
                                                            leaf: biz_txn_type.leaf?,
         
     | 
| 
      
 48 
     | 
    
         
            +
                                                            text: biz_txn_type.to_label,
         
     | 
| 
      
 49 
     | 
    
         
            +
                                                            children: []
         
     | 
| 
      
 50 
     | 
    
         
            +
                              })
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                              parent = nil
         
     | 
| 
      
 53 
     | 
    
         
            +
                              biz_txn_types.each do |biz_txn_type_hash|
         
     | 
| 
      
 54 
     | 
    
         
            +
                                if biz_txn_type_hash[:id] == data[:parent_id]
         
     | 
| 
      
 55 
     | 
    
         
            +
                                  parent = biz_txn_type_hash
         
     | 
| 
      
 56 
     | 
    
         
            +
                                end
         
     | 
| 
      
 57 
     | 
    
         
            +
                              end
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                              if parent
         
     | 
| 
      
 60 
     | 
    
         
            +
                                parent[:children].push(data)
         
     | 
| 
      
 61 
     | 
    
         
            +
                              else
         
     | 
| 
      
 62 
     | 
    
         
            +
                                biz_txn_types.push(data)
         
     | 
| 
      
 63 
     | 
    
         
            +
                              end
         
     | 
| 
      
 64 
     | 
    
         
            +
                            end
         
     | 
| 
      
 65 
     | 
    
         
            +
                            format.json do
         
     | 
| 
      
 66 
     | 
    
         
            +
                              biz_txn_types.push(biz_txn_type.to_hash(only: [:id, :description, :internal_identifier]))
         
     | 
| 
      
 67 
     | 
    
         
            +
                            end
         
     | 
| 
      
 68 
     | 
    
         
            +
                          end
         
     | 
| 
      
 69 
     | 
    
         
            +
                        end
         
     | 
| 
      
 70 
     | 
    
         
            +
                      end
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                      render :json => {success: true, biz_txn_types: biz_txn_types}
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
                      # get all txn types
         
     | 
| 
      
 75 
     | 
    
         
            +
                    else
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
                      respond_to do |format|
         
     | 
| 
      
 78 
     | 
    
         
            +
                        format.tree do
         
     | 
| 
      
 79 
     | 
    
         
            +
                          nodes = [].tap do |nodes|
         
     | 
| 
      
 80 
     | 
    
         
            +
                            BizTxnType.roots.each do |root|
         
     | 
| 
      
 81 
     | 
    
         
            +
                              nodes.push(root.to_tree_hash)
         
     | 
| 
      
 82 
     | 
    
         
            +
                            end
         
     | 
| 
      
 83 
     | 
    
         
            +
                          end
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                          render :json => {success: true, biz_txn_types: nodes}
         
     | 
| 
      
 86 
     | 
    
         
            +
                        end
         
     | 
| 
      
 87 
     | 
    
         
            +
                        format.json do
         
     | 
| 
      
 88 
     | 
    
         
            +
                          render :json => {success: true, biz_txn_types: BizTxnType.to_all_representation}
         
     | 
| 
      
 89 
     | 
    
         
            +
                        end
         
     | 
| 
      
 90 
     | 
    
         
            +
                      end
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
                    end
         
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
      
 94 
     | 
    
         
            +
                  end
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
      
 96 
     | 
    
         
            +
                  def create
         
     | 
| 
      
 97 
     | 
    
         
            +
                    description = params[:description].strip
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 100 
     | 
    
         
            +
             
     | 
| 
      
 101 
     | 
    
         
            +
                      ActiveRecord::Base.transaction do
         
     | 
| 
      
 102 
     | 
    
         
            +
                        biz_txn_type = BizTxnType.create(description: description, internal_identifier: description.to_iid)
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
                        if !params[:parent].blank? and params[:parent] != 'No Parent'
         
     | 
| 
      
 105 
     | 
    
         
            +
                          parent = BizTxnType.iid(params[:parent])
         
     | 
| 
      
 106 
     | 
    
         
            +
                          biz_txn_type.move_to_child_of(parent)
         
     | 
| 
      
 107 
     | 
    
         
            +
                        elsif !params[:default_parent].blank?
         
     | 
| 
      
 108 
     | 
    
         
            +
                          parent = BizTxnType.iid(params[:default_parent])
         
     | 
| 
      
 109 
     | 
    
         
            +
                          biz_txn_type.move_to_child_of(parent)
         
     | 
| 
      
 110 
     | 
    
         
            +
                        end
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
      
 112 
     | 
    
         
            +
                        render :json => {success: true, biz_txn_type: biz_txn_type.to_hash(only: [:id, :description, :internal_identifier])}
         
     | 
| 
      
 113 
     | 
    
         
            +
                      end
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
      
 115 
     | 
    
         
            +
                    rescue ActiveRecord::RecordInvalid => invalid
         
     | 
| 
      
 116 
     | 
    
         
            +
                      Rails.logger.error invalid.record.errors.full_messages
         
     | 
| 
      
 117 
     | 
    
         
            +
             
     | 
| 
      
 118 
     | 
    
         
            +
                      {:success => false, :message => invalid.record.errors.full_messages.join('</br>')}
         
     | 
| 
      
 119 
     | 
    
         
            +
                    rescue => ex
         
     | 
| 
      
 120 
     | 
    
         
            +
                      Rails.logger.error ex.message
         
     | 
| 
      
 121 
     | 
    
         
            +
                      Rails.logger.error ex.backtrace.join("\n")
         
     | 
| 
      
 122 
     | 
    
         
            +
             
     | 
| 
      
 123 
     | 
    
         
            +
                      ExceptionNotifier.notify_exception(ex) if defined? ExceptionNotifier
         
     | 
| 
      
 124 
     | 
    
         
            +
             
     | 
| 
      
 125 
     | 
    
         
            +
                      {:success => false, :message => "Error creating record"}
         
     | 
| 
      
 126 
     | 
    
         
            +
                    end
         
     | 
| 
      
 127 
     | 
    
         
            +
                  end
         
     | 
| 
      
 128 
     | 
    
         
            +
             
     | 
| 
      
 129 
     | 
    
         
            +
                end # BizTxnTypesController
         
     | 
| 
      
 130 
     | 
    
         
            +
              end # V1
         
     | 
| 
      
 131 
     | 
    
         
            +
            end # Api
         
     |