view · edit · sidebar · attach · print · history

20101230-update-vat_rate-ydim

<< Masa.20101231-update-vat_rate-ydim | 2010 | Masa.20101229-update-ydim >>


  1. Commit and Reboot ydim
  2. Commit bbmb.ch
  3. Update vat_rate suspend
  4. Check PDF format
  5. Update vat_rate again Done

Goal
  • Update vat_rate ydim / 100%
Milestones
  1. Commit and Reboot ydim 8:15
  2. Commit bbmb.ch 8:45
  3. Update vat_rate
    • BraSt 9:30
    • Replace the display from 8.0% (new) to 7.6% (old) with new 'state' and 'view' classes
    • Find how to switch the 'state' or 'view' classes suspend 17:00
  4. Check the difference between online and local regarding PDF format 15:00
Summary
Commits
ToDo Tomorrow
Keep in Mind
  1. swissmedic_followers debug
  2. export_fachinfo test locally (weekend)
  3. backup script (weekend)
  4. On Ice
  5. emerge --sync

Commit and Reboot ydim

Commit

Reboot (ydimd, ydim-htmld server)

~/git/ydim $ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   bin/ydim-edit
#       deleted:    set_initial_ydim_db.sql
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       doc/
#       lib/ydim/debitors.rb
#       lib/ydim/drbwrapper.rb
#       test/flexmock.rb
#       test/test_debitors.rb
#       test/test_drbwrapper.rb
~/git/ydim $ git checkout -f
~/git/ydim $ git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       doc/
#       lib/ydim/debitors.rb
#       lib/ydim/drbwrapper.rb
#       test/flexmock.rb
#       test/test_debitors.rb
#       test/test_drbwrapper.rb
nothing added to commit but untracked files present (use "git add" to track)

/var/www/ydim.ywesee.com $ git pull
remote: Counting objects: 13, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 7 (delta 3), reused 0 (delta 0)
Unpacking objects: 100% (7/7), done.
From /home/ywesee/cogito/ydim-html/
   cec7536..de0e512  master     -> origin
Updating cec7536..de0e512
Fast-forward
 lib/ydim/html/util/lookandfeel.rb |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

~/git/ydim $ su
# svstat /service/ydim
/service/ydim: up (pid 26521) 23558995 seconds
# svc -d /service/ydim
# svstat /service/ydim
/service/ydim: down 1 seconds, normally up
# svc -u /service/ydim
# svstat /service/ydim
/service/ydim: up (pid 13104) 2 seconds
# svstat /service/ydim
/service/ydim: up (pid 13104) 6 seconds

# svstat /service/ydim-html
/service/ydim-html: up (pid 21018) 21854055 seconds
# svc -d /service/ydim-html
# svstat /service/ydim-html
/service/ydim-html: down 8 seconds, normally up
# svc -u /service/ydim-html
# svstat /service/ydim-html
/service/ydim-html: up (pid 13187) 4 seconds
# svstat /service/ydim-html
/service/ydim-html: up (pid 13187) 7 seconds

Commit bbmb.ch

Reference (New company information)

Commit

Update vat_rate

BraSt

  • 'InvoiceView' class is loaded and associated with AjaxInvoice class when system boots
  • I guess it is possible to change the View class by using 'remove_const'
  • But first I should do as follows, since I should know about the mechanism of HtmlGrid
    1. Make new 'State' and 'View' class for the display of MwSt about old saved data
    2. Replace the new 'State' and 'View' for all the data
    3. Find how to switch 'View' ('State') class

Confirm default

saved data

new data

Make new 'state' and 'view' classes

lib/ydim/html/util/lookandfeel.rb

            :vat                                                =>  'MwSt. (8.0%)',
            :vat_2010                                               =>  'MwSt. (7.6%)',

Create new View classes for saved data

lib/ydim/html/view/invoice.rb

class InvoiceTotalComposite_2010 < InvoiceTotalComposite
    COMPONENTS = {
        [0,0]   =>  :total_netto,
        [0,1]   =>  :vat_2010,
        [0,2]   =>  :total_brutto,
    }
end
...
class InvoiceComposite_2010 < InvoiceComposite
    COMPONENTS = {
        [0,0]   =>  InvoiceInnerComposite,
        [0,1]   =>  :items,
        [0,2]   =>  InvoiceTotalComposite_2010,
        [0,3]   =>  :submit,
        [1,3]   =>  :pdf,
        [2,3]   =>  :send_invoice,
    }

end
..
class Invoice_2010 < Invoice
  CONTENT = InvoiceComposite_2010
end     

Note

  • We do not have to 'remove_const:' of the super class's constant

grep View::Invoice

masa@masa ~/ywesee/ydim $ grep -r View::Invoice *
lib/ydim/html/state/invoice.rb: VIEW = Html::View::Invoice
lib/ydim/html/state/invoice.rb: VIEW = Html::View::Invoice

Note

  • Keep in mind: There is 2 parts, read and create

Check Invoice_2010 working

lib/ydim/html/state/invoice.rb

    #VIEW = Html::View::Invoice
    VIEW = Html::View::Invoice_2010

Note

  • Probably @model variable is the invoice instance which has @vat_rate instance variable
  • Probably I can switch View classes by using this instance variables

Result

  • It works
  • But the actual value is not shown

lib/ydim/item.rb

        def vat_2010
            total_netto * (@vat_rate.to_f / 100.0)
        end

lib/ydim/invoice.rb

        sum :vat
        sum :vat_2010

Result

  • The actual MwSt value is shown with the current @vat_rate (8.0)
  • (MwSt display is '7.6%')

Create new State classes for saved data

lib/ydim/html/state/invoice.rb

class Invoice_2010 < Invoice
    VIEW = Html::View::Invoice_2010
end

Question

  • How do I use Invoice_2010 State class?

grep

masa@masa ~/ywesee/ydim $ grep -r State::Invoice *
lib/ydim/html/state/invoice.rb:# Html::State::Invoice -- ydim -- 16.01.2006 -- hwyss@ywesee.com
lib/ydim/html/state/invoices.rb:# Html::State::Invoices -- ydim -- 13.01.2006 -- hwyss@ywesee.com
masa@masa ~/ywesee/ydim $ 

Hypothesis

  • The State class name may be associated with the Model class name
  • Because there is no description 'State::Invoice' in source code

Experiment

lib/ydim/invoice_2010.rb

#!/usr/bin/env ruby
# Invoice -- ydim -- 11.01.2006 -- hwyss@ywesee.com

require 'pdfinvoice/config'
require 'pdfinvoice/invoice'
require 'ydim/item'
require 'ydim/server'

module YDIM
    class Invoice_2010 < Invoice
    end
  end
end

lib/ydim/html/state/global.rb#invoice

    def invoice
        if(id = @session.user_input(:unique_id))
            #Invoice.new(@session, @session.invoice(id.to_i))
            Invoice_2010.new(@session, @session.invoice(id.to_i))
        end
    end

Result

  • MwSt is shown as '7.6%'
  • Good

Experiment (switch)

lib/ydim/html/state/global.rb#invoice

    def invoice
      ret = nil
        if(id = @session.user_input(:unique_id))
            #Invoice.new(@session, @session.invoice(id.to_i))
            #Invoice_2010.new(@session, @session.invoice(id.to_i))
          ret = Invoice.new(@session, @session.invoice(id.to_i))
          if (ret.model.items[0].vat_rate - YDIM::Server.config.vat_rate).abs > 0.1
            ret = Invoice_2010.new(@session, @session.invoice(id.to_i))
          end
        end
        return ret
    end

Result

  • In this case, the 'MwSt' is switched and looks good, but the other case may be not
  • Because item[0] value is used here
  • If there is no 'items' this code will be an error

Check PDF format

Email

Problem

  • Local system outputs a PDF with 'Tax' but
  • Online system outputs with 'MwSt. 7.6%'
  • I cannot find the configuration in the source code of ydim or ydim-html.

Hypothesis

  • It is probably in different place from ydim directory

Check invoice.rb

lib/ydim/invoice.rb

require 'pdfinvoice/config'
require 'pdfinvoice/invoice'
...
    def pdf_invoice(sort_args={})
      config = PdfInvoice.config.dup
...

Note

  • This is it!
  • 'pdfinvoice' library is required here.

Correct MwSt in the config file of pdfinvoice

/etc/pdfinvoice $ ls
config.yml  logo.png
/etc/pdfinvoice $ cat config.yml
...
 tax: MwSt 7.6%
...

(correct)

/etc/pdfinvoice $ cat config.yml
...
 tax: MwSt 8.0%
...

Result

  • It works

Resume the updating of vat_rate

Check the differences among Invoice, Invoices, Item classes

Note

  • The number of items (items.length) is the number of 'Position'
  • There is a case where 'Invoice' instance has no 'item' instance (items.length==0)
  • In one 'Invoice' instance the 'vat_rate is same even if there are some items

Improvement

lib/ydim/item.rb

        alias :vat_2010 :vat

lib/ydim/html/state/global.rb#invoice

    def invoice
      inv = nil
      if(id = @session.user_input(:unique_id))
        #   Invoice.new(@session, @session.invoice(id.to_i))
        inv = Invoice.new(@session, @session.invoice(id.to_i))
        rate = YDIM::Server.config.vat_rate
        if(item = inv.model.items[0] and (item.vat_rate - rate).abs > 0.1)
          inv = Invoice_2010.new(@session, @session.invoice(id.to_i))
        end
      end
      return inv
    end

Result

  • Good (the same as before)

Summary

New View classes

lib/ydim/html/view/invoice.rb

class InvoiceTotalComposite_2010 < InvoiceTotalComposite
    COMPONENTS = {
        [0,0]   =>  :total_netto,
        [0,1]   =>  :vat_2010,
        [0,2]   =>  :total_brutto,
    }
end
class InvoiceComposite_2010 < InvoiceComposite
    COMPONENTS = {
        [0,0]   =>  InvoiceInnerComposite,
        [0,1]   =>  :items,
        [0,2]   =>  InvoiceTotalComposite_2010,
        [0,3]   =>  :submit,
        [1,3]   =>  :pdf,
        [2,3]   =>  :send_invoice,
    }
end
class Invoice_2010 < Invoice
  CONTENT = InvoiceComposite_2010
end

New State class

lib/ydim/html/state/invoice.rb

class Invoice_2010 < Invoice
    VIEW = Html::View::Invoice_2010
end

The other modifications

lib/ydim/invoice.rb

        sum :vat_2010
...
  class Invoice_2010 < Invoice
  end

lib/ydim/html/util/lookandfeel.rb

            :vat_2010                                               =>  'MwSt. (7.6%)',

lib/ydim/item.rb

        alias :vat_2010 :vat

lib/ydim/html/state/global.rb#invoice

    def invoice
      inv = nil
      if(id = @session.user_input(:unique_id))
        #   Invoice.new(@session, @session.invoice(id.to_i))
        inv = Invoice.new(@session, @session.invoice(id.to_i))
        rate = YDIM::Server.config.vat_rate
        if(item = inv.model.items[0] and (item.vat_rate - rate).abs > 0.1)
          inv = Invoice_2010.new(@session, @session.invoice(id.to_i))
        end
      end
      return inv
    end

Result

  • 'MwSt' percentage can switch automatically depending on the value of 'vat_rate'
view · edit · sidebar · attach · print · history
Page last modified on July 13, 2011, at 12:04 PM