repo
stringlengths
5
92
file_url
stringlengths
80
287
file_path
stringlengths
5
197
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:37:27
2026-01-04 17:58:21
truncated
bool
2 classes
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/controllers/loan_ledger_ins_controller.rb
app/controllers/loan_ledger_ins_controller.rb
class LoanLedgerInsController < ApplicationController before_action :ledger_form before_action :check_loan_give, only: [:new_give, :give] before_action :check_loan_receive, only: [:new_receive, :receive] # GET def new_give end # PATCH def give @ledger_form = Loans::LedgerInForm.new(loan_params) ...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/controllers/units_controller.rb
app/controllers/units_controller.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class UnitsController < ApplicationController respond_to :html, :json # GET /units def index @units = Unit.all end # GET /units/1 def show @unit = Unit.find(params[:id]) respond_with @unit end # GET /units/new def n...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/controllers/organisations_controller.rb
app/controllers/organisations_controller.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class OrganisationsController < ApplicationController before_action :check_tenant_creation, :check_user_master_account skip_before_action :set_tenant, :check_authorization! # GET /organisations/new def new end # POST /organisations ...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/controllers/helper.rb
app/controllers/helper.rb
class Helper include Singleton include ActionView::Helpers::TagHelper include ActionView::Helpers::UrlHelper include ActionView::Helpers::NumberHelper #include ActionView::Partials end
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/controllers/errors_controller.rb
app/controllers/errors_controller.rb
class ErrorsController < ActionController::Base def page_not_found # render status: 404 #render text: 'Page was not found' end end
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/controllers/attachments_controller.rb
app/controllers/attachments_controller.rb
class AttachmentsController < ApplicationController before_action :set_attachment, only: [:show, :update, :destroy] # POST /attachments def create @attachment = Attachment.new(create_params) @attachment.save_attachment render json: @attachment end # PATCH /attachments/:id def update case ...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/controllers/registrations_controller.rb
app/controllers/registrations_controller.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class RegistrationsController < ApplicationController skip_before_filter :set_tenant, :check_authorization! #before_filter :check_allow_registration before_filter :check_registration_tenant, only: ['show'] layout 'sessions' # GET /regis...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/controllers/reports_controller.rb
app/controllers/reports_controller.rb
# author: Boris Barroso # email: boriscyber@gmail.com class ReportsController < ApplicationController include Controllers::DateRange before_filter :set_date_range, :set_tag_ids def index @report = Report.new(@date_range, tag_ids: @tag_ids) end def inventory @report = InventoryReportService.new(inve...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/controllers/download_controller.rb
app/controllers/download_controller.rb
class DownloadController < ApplicationController layout false # GET /download/file/name def download_pdf send_file "#{download_file}.pdf", filename: "#{params[:name]}.pdf" end private def download_file if File.exists?("/tmp/#{params[:file]}.pdf") "/tmp/#{params[:file]}" else ...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/controllers/devolutions_controller.rb
app/controllers/devolutions_controller.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class DevolutionsController < ApplicationController # GET /devolutions/:id/new_income def new_income @devolution = Incomes::Devolution.new(account_id: params[:id], date: Date.today) check_income end # POST /devolutions/:id/income ...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/controllers/movement_details_history_controller.rb
app/controllers/movement_details_history_controller.rb
class MovementDetailsHistoryController < ApplicationController # GET /movement_details_history def show @history = present History.find(params[:id]), MovementHistoryDetailsPresenter end end
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/controllers/sessions_controller.rb
app/controllers/sessions_controller.rb
# author: Boris Barroso # email: boriscyber@gmail.com class SessionsController < ApplicationController #before_action :redirect_www skip_before_action :set_tenant, :check_authorization! before_action :check_logged_in, only: %i(new create) layout "sessions" def new @session = Session.new end def crea...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/controllers/incomes_inventory_ins_controller.rb
app/controllers/incomes_inventory_ins_controller.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com # Devolutions of inventory for Income class IncomesInventoryInsController < ApplicationController before_filter :set_store_and_income # GET # /incomes_inventory_ins/new?store_id=:store_id&income_id=:income_id def new @inv = Incomes::In...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/controllers/application_controller.rb
app/controllers/application_controller.rb
# author: Boris Barroso # email: boriscyber@gmail.com class ApplicationController < ActionController::Base layout lambda { |c| case when (c.request.xhr? or params[:xhr]) then false when params[:print].present? then 'print' else 'application' end } include Controllers::Authentica...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/controllers/cashes_controller.rb
app/controllers/cashes_controller.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class CashesController < ApplicationController before_filter :set_cash, only: [:show, :edit, :update, :destroy] include Controllers::Money # GET /cashs def index @cashes = present Cash.order('name asc'), MoneyAccountPresenter end ...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/controllers/taxes_controller.rb
app/controllers/taxes_controller.rb
class TaxesController < ApplicationController def index end # GET /taxes/new def new @tax = Tax.new end # POST /taxes def create @tax = Tax.new tax_params if @tax.save if request.xhr? render json: { id: @tax.id, to_s: @tax.to_s, percentage: @tax.percentage, name: @tax.name } ...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/controllers/banks_controller.rb
app/controllers/banks_controller.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class BanksController < ApplicationController before_filter :find_bank, only: [:show, :edit, :update, :destroy] # GET /banks def index @banks = present Bank.order('name asc'), MoneyAccountPresenter end # GET /banks/1 def show en...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/controllers/api/v1/contacts_controller.rb
app/controllers/api/v1/contacts_controller.rb
class Api::V1::ContactsController < Api::V1::BaseController # GET /api/v1/contacts def index render json: Contact.page(page).per(per).to_json end # POST /api/v1/contacts # JSON must be # {contact: {matchcode: 'Nmame', first_name: 'First'}} def create contact = Contact.new(contact_params) if ...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/controllers/api/v1/tags_controller.rb
app/controllers/api/v1/tags_controller.rb
class Api::V1::TagsController < Api::V1::BaseController # GET /api/v1/tags def index render json: Tag.page(page).per(per) end # GET /api/v1/tags/count def count render json: { count: Tag.count } end end
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/controllers/api/v1/items_controller.rb
app/controllers/api/v1/items_controller.rb
class Api::V1::ItemsController < Api::V1::BaseController # GET /api/v1/items def index render json: Item.page(page).per(per).to_json end # GET /api/v1/items/count def show item = Item.find(params[:id]) render json: item.to_json end # GET /api/v1/items/count def count render json: { c...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/controllers/api/v1/tag_groups_controller.rb
app/controllers/api/v1/tag_groups_controller.rb
class Api::V1::TagGroupsController < Api::V1::BaseController # GET /api/v1/tag_groups def index render json: TagGroup.page(page).per(per).to_json end # GET /api/v1/tag_groups/count def count render json: { count: TagGroup.count } end end
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/controllers/api/v1/incomes_controller.rb
app/controllers/api/v1/incomes_controller.rb
class Api::V1::IncomesController < Api::V1::BaseController # GET /api/v1/incomes def index render json: Income.page(page).per(per).to_json end # GET /api/v1/incomes/:id def show render json: Income.find(params[:id]) end # POST /api/v1/incomes def create inc = Incomes::Form.new_income(inco...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/controllers/api/v1/base_controller.rb
app/controllers/api/v1/base_controller.rb
class Api::V1::BaseController < ActionController::Base before_action :authenticate_user, :set_tenant, :set_user_session private def authenticate_user if user_link.blank? || current_user.blank? render(text: 'Invalid token', status: 401) and return end end def current_user use...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/controllers/api/v1/attachments_controller.rb
app/controllers/api/v1/attachments_controller.rb
class Api::V1::AttachmentsController < Api::V1::BaseController # GET /api/v1/attachments def index render json: Attachment.page(page).per(per).map(&:to_api).to_json end # GET /api/v1/attachments/:id def show attachment = Attachment.find(params[:id]) render json: attachment.to_api.to_json end ...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/tag.rb
app/models/tag.rb
# author: Boris Barroso # email: boriscyber@gmail.com class Tag < ActiveRecord::Base validates :name, presence: true, uniqueness: true, format: { with: /\A[\w\s\ñ]+\z/ }, length: { in: 3..20 } validates :bgcolor, presence: {message: I18n.t('errors.messages.taken')}, format: {wit...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/income_detail.rb
app/models/income_detail.rb
# encoding: utf-8 class IncomeDetail < MovementDetail # Relationships belongs_to :income, -> { where(type: 'Income') }, foreign_key: :account_id, inverse_of: :income_details belongs_to :item, inverse_of: :income_details # Validations validates_presence_of :item validate :valid_income_item, if: :item_id_ch...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/report.rb
app/models/report.rb
# encoding: utf-8 class Report attr_reader :date_range, :attrs def initialize(drange, attrs = {}) @date_range = drange @attrs = attrs end def expenses_by_item conn.select_rows(sum_movement_details_sql(params(type: 'Expense') ) ) .map {|v| ItemTransReport.new(*v)} end def incomes_by_item ...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/organisation_session.rb
app/models/organisation_session.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com # Used to access the organisation_id in the models class OrganisationSession class << self attr_reader :organisation delegate :id, :name, :currency, :tenant, :emamil, :address, :inventory_active?, :inventory?, to: :organisation, all...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/unit.rb
app/models/unit.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Unit < ActiveRecord::Base # callbacks before_save :strip_attributes before_update :update_item_units before_destroy :check_items_destroy # Relationships has_many :items # Validations validates_presence_of :name, :symbo...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/session.rb
app/models/session.rb
# encoding: utf-8 class Session < BaseService attr_reader :tenant, :status, :active, :logged attribute :email, String attribute :password, String delegate :id, to: :user, prefix: true, allow_nil: true validates_presence_of :email, :password def authenticate? return false unless validated? user....
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/project.rb
app/models/project.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Project < ActiveRecord::Base # associations has_many :accounts has_many :account_ledgers # validations validates_presence_of :name validates_lengths_from_database scope :active, -> { where(active: true) } def to_s name...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/contact_account.rb
app/models/contact_account.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class ContactAccount < Account belongs_to :account, -> { where(staff: false) } end
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/stock.rb
app/models/stock.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Stock < ActiveRecord::Base belongs_to :store belongs_to :item belongs_to :user #validations validates_presence_of :store, :store_id, :item, :item_id validates_numericality_of :minimum, greater_than_or_equal_to: 0, allow_nil: tru...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/movement.rb
app/models/movement.rb
# author: Boris Barroso # email: boriscyber@gmail.com # Base class for Income and Expense class Movement < Account # module for setters and getters extend Models::AccountCode STATES = %w(draft approved paid nulled) =begin jsonb_accessor(:extras, {delivered: :boolean, discounted: :boolean, devoluti...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/expense_detail.rb
app/models/expense_detail.rb
# encoding: utf-8 # Class to store the details of a expense class ExpenseDetail < MovementDetail # Relationships belongs_to :expense, -> { where(type: 'Expense') }, foreign_key: :account_id, inverse_of: :expense_details belongs_to :item, inverse_of: :expense_details delegate :for_sale?, :to_s, :n...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/item.rb
app/models/item.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Item < ActiveRecord::Base include ::Models::Tag include ::Models::Updater include ::Models::History ########################################## # Callbacks before_save :trim_code before_save :set_unit before_destroy :check_it...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/account.rb
app/models/account.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Account < ActiveRecord::Base include ActionView::Helpers::NumberHelper include ::Models::Tag include ::Models::Updater ######################################## # Relationships belongs_to :contact has_many :account_ledgers, -> ...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/tax.rb
app/models/tax.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Tax < ActiveRecord::Base has_many :accounts before_destroy :check_related_accounts # Validations validates :name, length: { in: 1..20 }, uniqueness: true validates :percentage, numericality: { greater_than_or_equal_to: 0, less_tha...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/income.rb
app/models/income.rb
# author: Boris Barroso # email: boriscyber@gmail.com # Class that creates incomes "Sales" class Income < Movement include Models::History has_history_details Movements::History, :income_details self.code_name = 'I' jsonb_accessor(:extras, {delivered: :boolean, discounted: :boolean, devolution: :...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/account_ledger.rb
app/models/account_ledger.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class AccountLedger < ActiveRecord::Base include ::Models::Updater extend Models::AccountCode self.code_name = 'T' ######################################## # Constants OPERATIONS = ['trans', # trans = Transfer from one account to ...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/country.rb
app/models/country.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Country < Struct.new(:code, :name) def to_s "#{name} #{code}" end class << self def find(cod) c = COUNTRIES[cod] Country.new(c.try(:fetch, :code), c.try(:fetch, :name)) end def options all.map do |c|...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/currency.rb
app/models/currency.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Currency < OpenStruct FILTER = %w(USD EUR ARS BOB CLP COP MXN PYG PEN UYU VEB GBP JPY) def to_s "#{code} #{name}" end def self.find(cur) if CURRENCIES[cur] Currency.new(CURRENCIES[cur]) else nil end en...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/store.rb
app/models/store.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Store < ActiveRecord::Base #include Models::Account::Base before_destroy :check_store_for_delete has_many :stocks, -> { where(active: true) }, autosave: true has_many :inventories validates_presence_of :name validates_uniquene...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/tag_group.rb
app/models/tag_group.rb
class TagGroup < ActiveRecord::Base validates :name, presence: true, length: { within: 3..100 }, uniqueness: true scope :api, -> { select('id, name, tag_ids') } def tags(reload = false) @tags = nil if reload @tags ||= Tag.where(id: tag_ids) end def tag_ids=(ids) @tags = nil write_attribut...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/date_range.rb
app/models/date_range.rb
# encoding: utf-8 # Creates date ranges for search class DateRange < Struct.new(:date_start, :date_end) def range date_start..date_end end def self.default last end def self.last(days = 30) d = Time.zone.now.to_date new(d - days.days, d) end def self.range(s, e) s, e = (s.is_a?(Stri...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/bank.rb
app/models/bank.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Bank < Account # Store accessors extend Models::HstoreMap EXTRA_COLUMNS = [:email, :address, :phone, :website].freeze store_accessor(:extras, *EXTRA_COLUMNS) # can't use Bank.stored_attributes methods[:extras] alias_method :old_...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/link.rb
app/models/link.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Link < ActiveRecord::Base self.table_name = "common.links" belongs_to :organisation, inverse_of: :links belongs_to :user, inverse_of: :active_links validates_presence_of :role, :organisation_id validates_inclusion_of :role, in: U...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/cash.rb
app/models/cash.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Cash < Account # Store accessors EXTRA_COLUMNS = [:email, :address, :phone].freeze store_accessor(:extras, *EXTRA_COLUMNS) # Validations validates :name, length: { minimum: 3 } # Related methods for money accounts include Mod...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/movement_detail.rb
app/models/movement_detail.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class MovementDetail < ActiveRecord::Base # Validations validates_presence_of :item_id validates_numericality_of :quantity, greater_than: 0 validate :balance_is_correct validate :change_of_item_id, unless: :new_record? validate :quanti...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/attachment.rb
app/models/attachment.rb
class Attachment < ActiveRecord::Base belongs_to :attachable, polymorphic: true belongs_to :user dragonfly_accessor :attachment do copy_to(:small_attachment) { |a| a.thumb('200x200') if a.image? } copy_to(:medium_attachment) { |a| a.thumb('500x500') if a.image? } end dragonfly_accessor :small_atta...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/user_session.rb
app/models/user_session.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com # Used to access the authenticated user in the models class UserSession class << self attr_reader :user delegate :id, :email, to: :user # Stores using de application_controller the current_user for devise def user=(usr) rais...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/organisation.rb
app/models/organisation.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Organisation < ActiveRecord::Base DATA_PATH = "db/defaults" self.table_name = 'common.organisations' HEADER_CSS = %w(bonsai-header red-header blue-header white-header violet-header orange-header dark-header) #######################...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/expense.rb
app/models/expense.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Expense < Movement include Models::History has_history_details Movements::History, :expense_details self.code_name = 'E' jsonb_accessor(:extras, {delivered: :boolean, discounted: :boolean, devolution: :boolean, gros...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/null_ledger.rb
app/models/null_ledger.rb
# NullLedger class class NullLedger attr_accessor :operation, :account_id def save_ledger true end def errors {} end end
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/loan.rb
app/models/loan.rb
# author: Boris Barroso # email: boriscyber@gmail.com class Loan < Account # module for setters and getters extend SettersGetters extend Models::AccountCode include Models::History STATES = %w(approved paid nulled).freeze LOAN_TYPES = %w(Loans::Receive Loans::Give).freeze # Store extend Models::Hstor...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/inventory_detail.rb
app/models/inventory_detail.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class InventoryDetail < ActiveRecord::Base belongs_to :inventory belongs_to :item validates_presence_of :item, :item_id, :quantity validates_numericality_of :quantity, greater_than: 0 attr_accessor :available end
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/currency_exchange.rb
app/models/currency_exchange.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com # Makes the exchange and can check validation for conversion in # account_ledgers, the accounts passed should be valid class CurrencyExchange attr_accessor :account, :account_to, :exchange_rate delegate :currency, to: :current_organisation ...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/inventory.rb
app/models/inventory.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Inventory < ActiveRecord::Base include ::Models::Updater before_create { self.creator_id = UserSession.id } OPERATIONS = %w(in out inc_in inc_out exp_in exp_out trans).freeze belongs_to :store belongs_to :store_to, class_name: "...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/contact.rb
app/models/contact.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Contact < ActiveRecord::Base include Models::Tag before_destroy :check_relations ######################################## # Relationships has_many :contact_accounts, -> { where(type: 'ContactAccount') }, foreign_key: :...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/user_with_role.rb
app/models/user_with_role.rb
class UserWithRole attr_reader :user, :organisation delegate :role, :master_account?, to: :link delegate :email, :id, to: :user def initialize(user, organisation) @user = user raise StandardError, 'The user must be type User' unless @user.is_a?(User) @organisation = organisation raise Standar...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/history.rb
app/models/history.rb
class History < ActiveRecord::Base # Relationships belongs_to :historiable, polymorphic: true belongs_to :user store_accessor :extras, :klass_to_s, :operation_type def history_attributes @history_attributes ||= history_data.keys end def history @hist_data ||= get_typecasted end private ...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/staff_account.rb
app/models/staff_account.rb
class StaffAccount < Account # Store accessors EXTRA_COLUMNS = [:email, :address, :phone, :mobile].freeze store_accessor(:extras, *EXTRA_COLUMNS) # Validations validates :name, length: { minimum: 3 } # Related methods for money accounts include Models::Money def to_s "#{name} #{currency}" end ...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/user.rb
app/models/user.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class User < ActiveRecord::Base self.table_name = 'common.users' # Includes include Models::User::Authentication ROLES = %w(admin group other demo).freeze # Callbacks before_update :store_old_emails, if: :email_changed? ##########...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/account_ledgers/query.rb
app/models/account_ledgers/query.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class AccountLedgers::Query def initialize(rel = AccountLedger) @rel = rel end def money(id) @rel.where(t[:account_id].eq(id).or(t[:account_to_id].eq(id))) .order('account_ledgers.date desc, account_ledgers.id desc') .include...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/inventories/details.rb
app/models/inventories/details.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com # Class that helps manage details for Inventory class Inventories::Details < Struct.new(:inventory) delegate :details, :store_id, :store_to_id, to: :inventory def item_ids #@item_ids ||= details.select{|v| v.quantity > 0 }.map(&:item_id).u...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/inventories/transference.rb
app/models/inventories/transference.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Inventories::Transference < Inventories::Form attribute :store_to_id, Integer validates_presence_of :store_to def create inventory.store_to_id = store_to_id save do inventory.save update_stocks update_stocks_...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/inventories/in.rb
app/models/inventories/in.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Inventories::In < Inventories::Form def create save { update_stocks && inventory.save } end def details_form_name 'inventories_in[inventory_details_attributes]' end private def operation 'in' end def u...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/inventories/errors.rb
app/models/inventories/errors.rb
class Inventories::Errors < Struct.new(:inventory, :stocks) attr_reader :errors delegate :details, to: :inventory def set_errors @has_error = false @errors = {quantity: [], item_ids: []} stock_errors inventory.has_error = @has_error inventory.error_messages = get_errors end def stock_er...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/inventories/form.rb
app/models/inventories/form.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Inventories::Form < BaseForm attribute :store_id, Integer attribute :date, Date attribute :ref_number, String attribute :description, String attribute :inventory_details_attributes attr_writer :inventory delegate :inventory_de...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/inventories/out.rb
app/models/inventories/out.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Inventories::Out < Inventories::Form def create res = true save do res = update_stocks Inventories::Errors.new(inventory, stocks).set_errors res && inventory.save end end def details_form_name 'invent...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/expenses/export.rb
app/models/expenses/export.rb
class Expenses::Export < Movements::Export def export(col_sep: ",") super Expense, col_sep end private def movement_name 'Egreso' end end
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/expenses/devolution.rb
app/models/expenses/devolution.rb
# encoding: utf-8 # Creates a devolution that updates the Income#total and creates an # instance of AccountLedger with the devolution data class Expenses::Devolution < Devolution # Validations validates_presence_of :expense # Delegations delegate :total, :balance, :currency, to: :expense, prefix: true, allow_...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/expenses/errors.rb
app/models/expenses/errors.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Expenses::Errors < Struct.new(:expense) attr_reader :errors delegate :balance, :total, :expense_details, to: :expense def set_errors expense.has_error = false @errors = {} balance_errors expense_details_errors expe...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/expenses/form.rb
app/models/expenses/form.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Expenses::Form < Movements::Form alias_method :expense, :movement attribute :expense_details_attributes validate :expense_is_valid, if: :direct_payment? validate :valid_account_to, if: :direct_payment? delegate :contact, :is_app...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/expenses/query.rb
app/models/expenses/query.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Expenses::Query < Movements::Query def initialize super Expense end def inc rel.includes(payments: [:account_to], expense_details: [:item]) end def to_pay(contact_id) @rel.active.where{(state.eq 'approved') & (amount.g...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/expenses/batch_payment.rb
app/models/expenses/batch_payment.rb
# Makes a complete payment for multiple expenses class Expenses::BatchPayment attr_reader :errors, :account_to_id, :ids def initialize(data) @ids = data[:ids] @account_to_id = data[:account_to_id] @errors = [] end def make_payments valid? expenses.each do |expense| make_payment(expe...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/expenses/inventory_out.rb
app/models/expenses/inventory_out.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Expenses::InventoryOut < Inventories::Out attribute :expense_id, Integer validates_presence_of :expense validate :valid_quantities validate :valid_item_ids delegate :expense_details, to: :expense delegate :balance_inventory, :in...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/expenses/payment.rb
app/models/expenses/payment.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Expenses::Payment < PaymentService # Validations validates_presence_of :expense validate :valid_expense_balance validate :valid_account_to_balance, if: :account_to_is_income? validate :valid_account_to_state, if: :account_to_is_inc...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/expenses/inventory_in.rb
app/models/expenses/inventory_in.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Expenses::InventoryIn < Inventories::In attribute :expense_id, Integer validates_presence_of :expense validate :valid_quantities #validate :valid_item_ids delegate :expense_details, to: :expense delegate :balance_inventory, :inv...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/expenses/service.rb
app/models/expenses/service.rb
# Class that stores all requried methods for form save # 1 Saves common data Cotact details etc # 2 Set the balance # 3 Create ledger if direct_payment # 4 Set item balance # 5 Set errors for expense class Expenses::Service < Movements::Service alias_method :expense, :movement def ledger @ledger ||= direct_pay...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/accounts/query.rb
app/models/accounts/query.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Accounts::Query def initialize(rel = Account) @rel = rel end def money @rel.active.where(type: %w(Bank Cash StaffAccount)).order(:type, :name) end def bank_cash @rel.active.where(type: %w(Bank Cash)).order(:type, :name...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/incomes/export.rb
app/models/incomes/export.rb
# Object used for exporting data class Incomes::Export < Movements::Export def export(col_sep: ",") super Income, col_sep end private def movement_name 'Ingreso' end end
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/incomes/devolution.rb
app/models/incomes/devolution.rb
# encoding: utf-8 # Creates a devolution that updates the Income#total and creates an # instance of AccountLedger with the devolution data class Incomes::Devolution < Devolution # Validations validates_presence_of :income # Delegations delegate :total, :balance, :currency, to: :income, prefix: true, allow_nil...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/incomes/errors.rb
app/models/incomes/errors.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Incomes::Errors < Struct.new(:income) attr_reader :errors delegate :balance, :total, :income_details, to: :income def set_errors income.has_error = false @errors = {} balance_errors income_details_errors income.err...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/incomes/form.rb
app/models/incomes/form.rb
# author: Boris Barroso # email: boriscyber@gmail.com class Incomes::Form < Movements::Form alias_method :income, :movement attribute :income_details_attributes validate :income_is_valid, if: :direct_payment? validate :valid_account_to, if: :direct_payment? delegate :contact, :is_approved?, :is_draft?, :t...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/incomes/query.rb
app/models/incomes/query.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Incomes::Query < Movements::Query def initialize super Income end def inc rel.includes(payments: [:account_to], income_details: [:item]) end def to_pay(contact_id) rel.active.where{amount.gt 0}.where(contact_id: contac...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/incomes/batch_payment.rb
app/models/incomes/batch_payment.rb
# Makes a complete payment for multiple incomes class Incomes::BatchPayment attr_reader :errors, :account_to_id, :ids def initialize(data) @ids = data[:ids] @account_to_id = data[:account_to_id] @errors = [] end def make_payments valid? incomes.each do |income| make_payment(income) ...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/incomes/inventory_out.rb
app/models/incomes/inventory_out.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Incomes::InventoryOut < Inventories::Out attribute :income_id, Integer validates_presence_of :income validate :valid_quantities validate :valid_item_ids delegate :income_details, to: :income delegate :balance_inventory, :invento...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/incomes/clone.rb
app/models/incomes/clone.rb
# Creates or new instance with the parameters form an income or # creates a new one in case that no id is given class Incomes::Clone attr_reader :income CLONE_ATTRS = [:contact_id, :currency, :date, :due_date, :project_id, :description, :total, :exchange_rate] delegate(*CLONE_ATTRS, to: :income...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/incomes/payment.rb
app/models/incomes/payment.rb
# encoding: utf-8 class Incomes::Payment < PaymentService # Validations validates_presence_of :income validate :valid_account_to_balance, if: :account_to_is_expense? validate :valid_account_to_state, if: :account_to_is_expense? validate :valid_amount # Delegations delegate :total, :balance, :currency, t...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/incomes/inventory_in.rb
app/models/incomes/inventory_in.rb
# author: Boris Barroso # email: boriscyber@gmail.com # Class that creates a inventory in "Devolution of items" for an Income # this class inherits from Iventories::In < Inventories::Form # inventory_details defined on Inventories::Form class Incomes::InventoryIn < Inventories::In attribute :income_id, Integer attr...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/incomes/service.rb
app/models/incomes/service.rb
# Class that stores all requried methods for form save # 1 Saves common data Cotact details etc # 2 Set the balance # 3 Create ledger if direct_payment # 4 Set item balance # 5 Set errors for income class Incomes::Service < Movements::Service alias_method :income, :movement def ledger @ledger ||= direct_paymen...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/contacts/calculation.rb
app/models/contacts/calculation.rb
class Contacts::Calculation < Struct.new(:contact) delegate :operations, :accounts, to: :contact def total_in @total_in ||= accounts.in.approved.sum('amount * exchange_rate') end def total_out @total_out ||= accounts.out.approved.sum('amount * exchange_rate') end end
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/contacts/query.rb
app/models/contacts/query.rb
class Contacts::Query < SimpleDelegator def initialize(rel = Contact) super(rel) end def index __getobj__ .select("contacts.*, tot_in, tot_out") .joins("LEFT JOIN (#{tots_sql}) AS res ON (res.contact_id=contacts.id)") end private def tots_sql <<-SQL SELECT contact_id, SUM(tot_in) ...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/loans/give_form.rb
app/models/loans/give_form.rb
class Loans::GiveForm < Loans::Form def create res = valid? commit_or_rollback do res = loan.save ledger.account_id = loan.id res = res && ledger.save_ledger end set_errors(loan, ledger) unless res res end def loan @loan ||= Loans::Give.new( contact_id: contact_i...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/loans/ledger_in_form.rb
app/models/loans/ledger_in_form.rb
class Loans::LedgerInForm < BaseForm attribute :loan_id, Integer attribute :account_to_id, Integer attribute :amount, BigDecimal attribute :reference, String attribute :date, Date attribute :exchange_rate, Decimal, default: 1 attribute :verification, Boolean, default: false # Validations validates :a...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/loans/payment_form.rb
app/models/loans/payment_form.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com class Loans::PaymentForm < BaseForm attribute :account_id, Integer attribute :account_to_id, Integer attribute :exchange_rate, Decimal, default: 1 attribute :amount, Decimal, default: 0 attribute :date, Date attribute :reference, String...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/loans/receive_form.rb
app/models/loans/receive_form.rb
class Loans::ReceiveForm < Loans::Form def create res = valid? commit_or_rollback do res = loan.save ledger.account_id = loan.id res = res && ledger.save_ledger end set_errors(loan, ledger) unless res res end def loan @loan ||= Loans::Receive.new( contact_id: con...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/loans/give_payment_form.rb
app/models/loans/give_payment_form.rb
# encoding: utf-8 # class for to make payments for Loans received the money goes out # author: Boris Barroso # email: boriscyber@gmail.com class Loans::GivePaymentForm < Loans::PaymentForm validate :valid_expense_amount, if: :account_to_is_expense? def create_payment return false unless valid? res = true ...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false
bonsaiERP/bonsaiERP
https://github.com/bonsaiERP/bonsaiERP/blob/0edb91af594f81e7534dbc90525a406c645ad164/app/models/loans/receive.rb
app/models/loans/receive.rb
# encoding: utf-8 # author: Boris Barroso # email: boriscyber@gmail.com # Class for receiving loans class Loans::Receive < Loan self.code_name = 'PR' # Relationships has_many :ledger_ins, -> { where(operation: 'lrcre') }, class_name: 'AccountLedger', foreign_key: :account_id has_many :payments, -> { where(op...
ruby
MIT
0edb91af594f81e7534dbc90525a406c645ad164
2026-01-04T17:40:51.865869Z
false