Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ekylibre/ekylibre into us…
Browse files Browse the repository at this point in the history
…er_preference_mask_literate_element
  • Loading branch information
Charles Duporge committed Mar 30, 2017
2 parents af24f0e + 555d481 commit d62c01c
Show file tree
Hide file tree
Showing 190 changed files with 10,000 additions and 582 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
2.36.8
2.39.1
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Expand Up @@ -50,6 +50,7 @@
//= require form/dependents
//= require form/toggle
//= require form/dates
//= require form/links
//= require cocoon
//= require jquery/ext
//= require selector
Expand Down
25 changes: 21 additions & 4 deletions app/assets/javascripts/backend/loans.js.coffee
Expand Up @@ -12,10 +12,27 @@
form.find("input[name='loan[repayment_duration]'], input[name='loan[shift_duration]']").each ->
duration = $(this)
x = duration.val()
# Back to month
x *= 12 if period == "year"
# Back to wanted duration
x /= 12 if input.val() == "year"

if period == "month"
x /= 12 if input.val() == "year"
x /= 6 if input.val() == "semester"
x /= 3 if input.val() == "trimester"

if period == "year"
x *= 12 if input.val() == "month"
x *= 2 if input.val() == "semester"
x *= 4 if input.val() == "trimester"

if period == "semester"
x *= 6 if input.val() == "month"
x /= 2 if input.val() == "year"
x *= 2 if input.val() == "trimester"

if period == "trimester"
x *= 3 if input.val() == "month"
x /= 4 if input.val() == "year"
x /= 2 if input.val() == "semester"

duration.val(x.toFixed(0))
form.prop("lastRepaymentPeriod", input.val())

Expand Down
84 changes: 84 additions & 0 deletions app/assets/javascripts/form/links.js.coffee
@@ -0,0 +1,84 @@
(($) ->

setUpdateTriggers = ->
links = $(this)
links.each ->
link = $(this)
triggerSelector = link.data('update-link-with')
$(triggerSelector).change ->
url = link.attr('href')
triggeredInput = $(this)
id = triggeredInput.attr 'id'
value = triggeredInput.val()
regExp = new RegExp "(\\?|\\&)(#{id})\\=([^&]+)"

if url.match(regExp)
url = url.replace(regExp, "$1$2=#{value}")
else
if url.indexOf('?') < 0 then url += '?' else url += '&'
url += "#{id}=#{value}"

link.attr('href', url)


$(document).behave 'load', 'a[data-update-link-with]', setUpdateTriggers

completeUrlWithIds = ->
links = $(this)
links.each ->
link = $(this)
paramName = $(link).attr('data-complete-link-with-ids')
checkboxes = $('.list td input[type="checkbox"]')

$(checkboxes).change ->
ids = []
id = parseInt($(this).closest('tr').attr('id').substring(1))
url = link.attr('href')
lastUrlParams = ""

if url.indexOf(paramName) > 0
idsArray = url.split(paramName)[1]

if idsArray.indexOf('&') > 0
index = idsArray.indexOf('&')
lastUrlParams = idsArray.substring(index)
idsArray = idsArray.split('&')[0]

idsLength = idsArray.length
idsInLink = idsArray.substring(idsLength - 1, 2)
ids = JSON.parse("[" + idsInLink + "]")

paramToSplit = ""

if url.indexOf("?#{paramName}") > 0 then paramToSplit = '?' else paramToSplit += '&'

paramToSplit += paramName
url = url.split("#{paramToSplit}")[0]

if $(this).is(':checked')
ids.push(id)
else
index = ids.indexOf(id)
ids.splice(index, 1)

if url.indexOf('?') < 0 then url += '?' else url += '&'

url += "#{paramName}=[#{ids.join(', ')}]"
url += lastUrlParams

link.attr('href', url)

if link.attr('data-display-class-on-click')
elementDisplayOnClick = '.' + link.attr('data-display-class-on-click')

if ids.length == 0
$(elementDisplayOnClick).hide()

if ids.length == 1
$(elementDisplayOnClick).show()


$(document).behave 'load', 'a.js-complete-links-with-ids', completeUrlWithIds

return
) jQuery
Expand Up @@ -2,9 +2,8 @@ module Backend
module Cells
class AccountancyBalanceCellsController < Backend::Cells::BaseController
def show
f = FinancialYear.current
f = current_user.current_financial_year
if f
f.compute_balances!
@financial_year = f
@started_on = f.started_on
@stopped_on = f.stopped_on
Expand Down
14 changes: 14 additions & 0 deletions app/controllers/backend/cells/profit_and_loss_cells_controller.rb
@@ -0,0 +1,14 @@
module Backend
module Cells
class ProfitAndLossCellsController < Backend::Cells::BaseController
def show
f = current_user.current_financial_year
if f
@financial_year = f
@started_on = f.started_on
@stopped_on = f.stopped_on
end
end
end
end
end
10 changes: 4 additions & 6 deletions app/controllers/backend/entities_controller.rb
Expand Up @@ -98,7 +98,6 @@ def self.entities_conditions
code.c
end


list(conditions: entities_conditions, order: 'entities.last_name, entities.first_name') do |t|
t.action :edit
t.action :destroy, if: :destroyable?
Expand Down Expand Up @@ -294,12 +293,12 @@ def self.entities_moves_client_conditions(params)
code = ''
code << search_conditions({ journal_entry_item: [:name, :debit, :credit, :real_debit, :real_credit], journal_entry: [:number] }, conditions: 'c', variable: 'params[:b]'.c) + "\n"
code << "c[0] << ' AND #{JournalEntryItem.table_name}.account_id = ?'\n"
code << "c << Entity.find(params[:id]).client_account_id\n"
code << "c << Entity.find(#{params[:id]}).client_account_id\n"
code << "c\n"
eval code
end

list(:client_journal_entry_items, model: :journal_entry_items, conditions: { account_id: 'Entity.find(params[:id]).client_account_id'.c },line_class: "( RECORD.letter.to_s.empty? ? '' : 'unmark')".c, joins: :entry, order: "entry_id DESC, #{JournalEntryItem.table_name}.position") do |t|
list(:client_journal_entry_items, model: :journal_entry_items, conditions: { account_id: 'Entity.find(params[:id]).client_account_id'.c }, line_class: "( RECORD.letter.to_s.empty? ? '' : 'unmark')".c, joins: :entry, order: "entry_id DESC, #{JournalEntryItem.table_name}.position") do |t|
t.column :journal, url: true
t.column :entry_number, url: true
t.column :printed_on, datatype: :date, label: :column
Expand All @@ -314,17 +313,16 @@ def self.entities_moves_client_conditions(params)
t.column :absolute_credit, currency: :absolute_currency
end


def self.entities_moves_supplier_conditions(params)
code = ''
code << search_conditions({ journal_entry_item: [:name, :debit, :credit, :real_debit, :real_credit], journal_entry: [:number] }, conditions: 'c', variable: 'params[:b]'.c) + "\n"
code << "c[0] << ' AND #{JournalEntryItem.table_name}.account_id = ?'\n"
code << "c << Entity.find(params[:id]).supplier_account_id\n"
code << "c << Entity.find(#{params[:id]}).supplier_account_id\n"
code << "c\n"
eval code
end

list(:supplier_journal_entry_items, model: :journal_entry_items, conditions: { account_id: 'Entity.find(params[:id]).supplier_account_id'.c },line_class: "( RECORD.letter.to_s.empty? ? '' : 'unmark')".c, joins: :entry, order: "entry_id DESC, #{JournalEntryItem.table_name}.position") do |t|
list(:supplier_journal_entry_items, model: :journal_entry_items, conditions: { account_id: 'Entity.find(params[:id]).supplier_account_id'.c }, line_class: "( RECORD.letter.to_s.empty? ? '' : 'unmark')".c, joins: :entry, order: "entry_id DESC, #{JournalEntryItem.table_name}.position") do |t|
t.column :journal, url: true
t.column :entry_number, url: true
t.column :printed_on, datatype: :date, label: :column
Expand Down
26 changes: 26 additions & 0 deletions app/controllers/backend/fixed_asset_depreciations_controller.rb
@@ -0,0 +1,26 @@
# == License
# Ekylibre - Simple agricultural ERP
# Copyright (C) 2008-2012 Brice Texier
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

module Backend
class FixedAssetDepreciationsController < Backend::BaseController
def show
depreciation = FixedAssetDepreciation.find(params[:id])
redirect_to action: :show, controller: 'backend/fixed_assets', id: depreciation.fixed_asset_id
end
end
end
137 changes: 128 additions & 9 deletions app/controllers/backend/fixed_assets_controller.rb
Expand Up @@ -22,18 +22,58 @@ class FixedAssetsController < Backend::BaseController

unroll

list do |t|
respond_to :pdf, :odt, :docx, :xml, :json, :html, :csv

# params:
# :q Text search
# :s State search
# :period Two Dates with _ separator
# :variant_id
# :activity_id
def self.fixed_assets_conditions
code = ''
code = search_conditions(fixed_assets: [:name, :number, :description]) + " ||= []\n"
code << "if params[:period].present? && params[:period].to_s != 'all'\n"
code << " c[0] << ' AND #{FixedAsset.table_name}.started_on BETWEEN ? AND ?'\n"
code << " if params[:period].to_s == 'interval'\n"
code << " c << params[:started_on]\n"
code << " c << params[:stopped_on]\n"
code << " else\n"
code << " interval = params[:period].to_s.split('_')\n"
code << " c << interval.first\n"
code << " c << interval.second\n"
code << " end\n"
code << "end\n"
code << "if params[:fixed_asset_id].to_i > 0\n"
code << " c[0] += ' AND #{FixedAsset.table_name}.id = ?'\n"
code << " c << params[:fixed_asset_id]\n"
code << "end\n"
code << "if params[:product_id].to_i > 0\n"
code << " c[0] += ' AND #{FixedAsset.table_name}.product_id = ?'\n"
code << " c << params[:product_id]\n"
code << "end\n"
code << "c\n"
code.c
end

list(conditions: fixed_assets_conditions) do |t|
t.action :edit
t.action :destroy
t.column :number, url: true
t.column :name, url: true
t.column :asset_account, url: true
t.status
t.column :product, url: true
t.column :depreciable_amount, currency: true
t.column :started_on
t.column :stopped_on
end

list(:depreciations, model: :fixed_asset_depreciations, conditions: { fixed_asset_id: 'params[:id]'.c }, order: :position) do |t|
# t.action :edit, if: "RECORD.journal_entry.nil?".c
t.column :position
t.column :accountable
t.column :locked
t.column :amount, currency: true
t.column :depreciable_amount, currency: true
t.column :depreciated_amount, currency: true
Expand All @@ -43,9 +83,64 @@ class FixedAssetsController < Backend::BaseController
t.column :journal_entry, label_method: :number, url: true
end

list(:products, model: :products, conditions: { fixed_asset_id: 'params[:id]'.c }, order: :initial_born_at) do |t|
t.column :name, url: true
t.column :initial_born_at
# Show a list of fixed_assets
def index
@fixed_assets = FixedAsset.all.reorder(:started_on)
# passing a parameter to Jasper for company full name and id
@entity_of_company_full_name = Entity.of_company.full_name
@entity_of_company_id = Entity.of_company.id

respond_with @fixed_assets, methods: [:net_book_value], include: [:asset_account, :expenses_account, :allocation_account, :product]
end

def show
# passing a parameter to Jasper for company full name and id
@entity_of_company_full_name = Entity.of_company.full_name
@entity_of_company_id = Entity.of_company.id

return unless @fixed_asset = find_and_check
t3e @fixed_asset
respond_with(@fixed_asset, methods: [:net_book_value, :duration],
include: [
{
depreciations: {
methods: [],
include: { journal_entry: {} }
},
purchase_items: {},
asset_account: {},
expenses_account: {},
allocation_account: {},
product: {}

}
],
procs: proc { |options| options[:builder].tag!(:url, backend_fixed_asset_url(@fixed_asset)) })
end

def depreciate_up_to
begin
date = Date.parse(params[:'depreciation-date'])
rescue
notify_error(:error_while_depreciating)
return redirect_to(params[:redirect] || { action: :index })
end

depreciations = FixedAssetDepreciation.with_active_asset.up_to(date)
success = true

ActiveRecord::Base.transaction do
# trusting the bookkeep to take care of the accounting
depreciations.find_each { |dep| success &&= dep.update(accountable: true) }
raise ActiveRecord::Rollback unless success
end

if success
notify_success(:depreciation_successful)
else
notify_error(:depreciation_failed)
end
redirect_to(params[:redirect] || { action: :index })
end

# def cede
Expand All @@ -56,10 +151,34 @@ class FixedAssetsController < Backend::BaseController
# return unless @fixed_asset = find_and_check
# end

# def depreciate
# return unless @fixed_asset = find_and_check
# @fixed_asset.depreciate!
# redirect_to fixed_asset_path(@fixed_asset)
# end
FixedAsset.state_machine.events.each do |event|
define_method event.name do
fire_event(event.name)
end
end

def depreciate
fixed_assets = find_fixed_assets
return unless fixed_assets

unless fixed_assets.all?(&:depreciable?)
notify_error(:all_fixed_assets_must_be_depreciable)
redirect_to(params[:redirect] || { action: :index })
return
end
end

protected

def find_fixed_assets
fixed_asset_ids = params[:id].split(',')
fixed_assets = fixed_asset_ids.map { |id| FixedAsset.find_by(id: id) }.compact
unless fixed_assets.any?
notify_error :no_fixed_assets_given
redirect_to(params[:redirect] || { action: :index })
return nil
end
fixed_assets
end
end
end

0 comments on commit d62c01c

Please sign in to comment.