From 6a47f38e80a9baa8c6633ac03bc0f003452c6b7b Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Thu, 9 Apr 2015 17:55:27 +0300 Subject: [PATCH] Improve invoice view --- app/assets/images/eis-logo-et.png | Bin 0 -> 1440 bytes app/assets/stylesheets/registrar.sass | 18 +++++- app/models/invoice.rb | 20 +++++++ app/models/invoice_item.rb | 4 ++ app/models/registrar.rb | 6 +- .../registrar/invoices/partials/_buyer.haml | 20 +++++++ .../registrar/invoices/partials/_details.haml | 17 ++++++ .../registrar/invoices/partials/_items.haml | 32 +++++++++++ .../registrar/invoices/partials/_seller.haml | 52 +++++++++--------- .../registrar/invoices/partials/_total.haml | 17 ++++++ app/views/registrar/invoices/show.haml | 10 ++-- config/locales/en.yml | 3 + .../20150408081917_create_invoice_items.rb | 6 +- db/schema.rb | 6 +- 14 files changed, 167 insertions(+), 44 deletions(-) create mode 100644 app/assets/images/eis-logo-et.png create mode 100644 app/views/registrar/invoices/partials/_details.haml create mode 100644 app/views/registrar/invoices/partials/_items.haml create mode 100644 app/views/registrar/invoices/partials/_total.haml diff --git a/app/assets/images/eis-logo-et.png b/app/assets/images/eis-logo-et.png new file mode 100644 index 0000000000000000000000000000000000000000..1bdf0a983198bcec12ed242278a6cb2df9e0d400 GIT binary patch literal 1440 zcmZ9MdpHw%7{`}eE)l0A8M&+y%5umxXKZdmF}E>=#W)+$LTDPfcBscRnsVp3|7+9uv#`wp^Fe&d&3AJm;MEdEWQ?d4JD)`|FpAaI}?{1WEz`0BJk8m5V@w z1RfwREQsXF6udwvi1TjN0tJw}_6+!?Kr9cfvSle>U)IECB^3qcGaK-tmvBjLp{h z=53ASMV`8oEB8Yall>5x-`w49Qt$M#ijBRbt;^8%^Y2K$VnYVKgfN+5ruIb7oC;9u zl_5_{;j)u@fkGPwqArouYH-l1yv>VvbX4eBX(rwAOnN6T?YBoeg`yT$ehntYO z8D*jD=JRYIr~-YlWFGsdlyWFszx^1l$Ud^JA@>{fdJMc^+@XncugY-g(ip=Sr{SAZ z(fQ=u2@KSsCu@SRAeQr1Yx=(P)aO29;Qpli3Ypfet~{LW^kR(qBI$|xfi-f-cd>Sr zv5Vr(vyx+|HgPi9$p<`*t5rBYc>&h{*bwab$J7K7wTL|1U`fVmeVe+F?Px5@Y!1gv z_7CON)H5ldwRIC%h|&$+^MrH@vx(_pF~YfYZyzT$wrR_-u`1o#jLqJB8SzUdI5QqP zIzJrgzcujVkYnX5Dm?&it(h4E2naP9xCRf;2=>$ue0}{4gx&>AL{YY$BJ;nfc=&t= zHdy9(Il3&^XN`Mg@QZRUix>Zf*rXJLuZ}G_g-B?B_?a+g(b?jfR9__A0XQO` z6>oY_Rsev66&ZjA~)DRMzPOxQpv^HMGQ?8!g7B;Kk6J-u*_f zO4w+SB;-MI=G>fSX}}yuf}bnl}SB&-)?++Fu*^9(|>X^l|fL}TKnk~I$PEL3pnuW=EzDv z@$0G%lwsv3%mHB|jvgIpjR(ncrD>!)M%*QXh%K^Iuqd|4Dz})IrQ*e<8IqI;2h-wv z)0~?CF}NBXqMKA_yo9?daL8Mp{OokAd!w+sPEo5~dAaSURIS^gYjm1cf(OF%nHP^E z(o)s<_O+sTEeE~XB+(I5CITj-)(I?vQBP8{*UR2L4Rb-19gX;cEB8^yX4RiRsTF z^Yx~SdN$N{k6Jk56X`>>3iWk_kCLD+#aNZOBFDixn7l7t?Ysi1d)Ob& zST(@WiOnyv{N|JE@8%VR{~1m2xHtMP${e!8U6N~=zsi#|DD)|VO#k!M+F3hVJ%OPU F{s#K9*PZ|X literal 0 HcmV?d00001 diff --git a/app/assets/stylesheets/registrar.sass b/app/assets/stylesheets/registrar.sass index 9441d99e6..2f2de0b32 100644 --- a/app/assets/stylesheets/registrar.sass +++ b/app/assets/stylesheets/registrar.sass @@ -13,16 +13,28 @@ html min-height: 100% body - padding-bottom: 60px + padding-bottom: 130px body > .container height: 100% background: #fff padding: 60px 30px 30px 30px +h1, h2, h3, h4 + margin-bottom: 0px !important + +hr + margin-top: 10px !important + margin-bottom: 10px !important + +.no-border + border: 0 !important + .footer position: absolute bottom: 0 width: 100% - height: 60px - background-color: black + height: 130px + background: image_url('bg.jpg') + color: white !important + background-size: 100% diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 612083710..693967f5b 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -7,4 +7,24 @@ class Invoice < ActiveRecord::Base def seller_address [seller_street, seller_city, seller_state, seller_zip].reject(&:blank?).compact.join(', ') end + + def buyer_address + [buyer_street, buyer_city, buyer_state, buyer_zip].reject(&:blank?).compact.join(', ') + end + + def items + invoice_items + end + + def total_without_vat + items.map(&:item_total_without_vat).sum + end + + def total_vat + total_without_vat * vat_prc + end + + def total + total_without_vat + total_vat + end end diff --git a/app/models/invoice_item.rb b/app/models/invoice_item.rb index 180f29522..0c7e6faf8 100644 --- a/app/models/invoice_item.rb +++ b/app/models/invoice_item.rb @@ -1,3 +1,7 @@ class InvoiceItem < ActiveRecord::Base belongs_to :invoice + + def item_total_without_vat + amount * price + end end diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 2728642b7..6243bf2d9 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -67,9 +67,9 @@ class Registrar < ActiveRecord::Base invoice_items_attributes: [ { description: 'prepayment', - item_unit: 'piece', - item_amount: 1, - item_price: amount + unit: 'piece', + amount: 1, + price: amount } ] ) diff --git a/app/views/registrar/invoices/partials/_buyer.haml b/app/views/registrar/invoices/partials/_buyer.haml index e69de29bb..2201e65ac 100644 --- a/app/views/registrar/invoices/partials/_buyer.haml +++ b/app/views/registrar/invoices/partials/_buyer.haml @@ -0,0 +1,20 @@ +%h4= t('buyer') +%hr +%dl.dl-horizontal + %dt= t('name') + %dd= @invoice.buyer_name + + %dt= t('reg_no') + %dd= @invoice.buyer_reg_no + + %dt= t('address') + %dd= @invoice.buyer_address + + %dt= t('phone') + %dd= @invoice.buyer_phone + + %dt= t('url') + %dd= @invoice.buyer_url + + %dt= t('email') + %dd= @invoice.buyer_email diff --git a/app/views/registrar/invoices/partials/_details.haml b/app/views/registrar/invoices/partials/_details.haml new file mode 100644 index 000000000..608dade76 --- /dev/null +++ b/app/views/registrar/invoices/partials/_details.haml @@ -0,0 +1,17 @@ +%h4= t('details') +%hr +%dl.dl-horizontal + / %dt= t('document_name') + / %dd= t(@invoice.document_name) + + %dt= t('issue_date') + %dd= l(@invoice.created_at) + + %dt= t('due_date') + %dd= l(@invoice.due_date) + + %dt= t('payment_term') + %dd= t(@invoice.payment_term) + + %dt= t('description') + %dd= @invoice.description diff --git a/app/views/registrar/invoices/partials/_items.haml b/app/views/registrar/invoices/partials/_items.haml new file mode 100644 index 000000000..a3c5613b4 --- /dev/null +++ b/app/views/registrar/invoices/partials/_items.haml @@ -0,0 +1,32 @@ +%h4= t('items') +%hr +.table-responsive + %table.table.table-hover.table-condensed + %thead + %tr + %th{class: 'col-xs-4'}= t('description') + %th{class: 'col-xs-2'}= t('unit') + %th{class: 'col-xs-2'}= t('amount') + %th{class: 'col-xs-2'}= t('price') + %th{class: 'col-xs-2'}= t('total') + %tbody + - @invoice.items.each do |x| + %tr + %td= t(x.description) + %td= x.unit + %td= x.amount + %td= x.price + %td= x.item_total_without_vat + %tfoot + %tr + %th{colspan: 3} + %th= t('total_without_vat') + %td= @invoice.total_without_vat + %tr + %th.no-border{colspan: 3} + %th= t('vat', vat_prc: (@invoice.vat_prc * 100).round) + %td= @invoice.total_vat + %tr + %th.no-border{colspan: 3} + %th= t('total') + %td= @invoice.total diff --git a/app/views/registrar/invoices/partials/_seller.haml b/app/views/registrar/invoices/partials/_seller.haml index ab1957f45..91c15b695 100644 --- a/app/views/registrar/invoices/partials/_seller.haml +++ b/app/views/registrar/invoices/partials/_seller.haml @@ -1,37 +1,35 @@ -.panel.panel-default - .panel-heading - %h3.panel-title= t('general') - .panel-body - %dl.dl-horizontal - %dt= t('name') - %dd= @invoice.seller_name +%h4= t('seller') +%hr +%dl.dl-horizontal + %dt= t('name') + %dd= @invoice.seller_name - %dt= t('reg_no') - %dd= @invoice.seller_reg_no + %dt= t('reg_no') + %dd= @invoice.seller_reg_no - %dt= t('iban') - %dd= @invoice.seller_iban + %dt= t('iban') + %dd= @invoice.seller_iban - %dt= t('bank') - %dd= @invoice.seller_bank + %dt= t('bank') + %dd= @invoice.seller_bank - %dt= t('swift') - %dd= @invoice.seller_swift + %dt= t('swift') + %dd= @invoice.seller_swift - %dt= t('vat_no') - %dd= @invoice.seller_vat_no + %dt= t('vat_no') + %dd= @invoice.seller_vat_no - %dt= t('address') - %dd= @invoice.seller_address + %dt= t('address') + %dd= @invoice.seller_address - %dt= t('phone') - %dd= @invoice.seller_phone + %dt= t('phone') + %dd= @invoice.seller_phone - %dt= t('url') - %dd= @invoice.seller_url + %dt= t('url') + %dd= @invoice.seller_url - %dt= t('email') - %dd= @invoice.seller_email + %dt= t('email') + %dd= @invoice.seller_email - %dt= t('issuer') - %dd= @invoice.seller_contact_name + %dt= t('issuer') + %dd= @invoice.seller_contact_name diff --git a/app/views/registrar/invoices/partials/_total.haml b/app/views/registrar/invoices/partials/_total.haml new file mode 100644 index 000000000..247f84b64 --- /dev/null +++ b/app/views/registrar/invoices/partials/_total.haml @@ -0,0 +1,17 @@ +%h4= t('total') +%hr +%dl.dl-horizontal + / %dt= t('document_name') + / %dd= t(@invoice.document_name) + + %dt= t('issue_date') + %dd= l(@invoice.created_at) + + %dt= t('due_date') + %dd= l(@invoice.due_date) + + %dt= t('payment_term') + %dd= t(@invoice.payment_term) + + %dt= t('description') + %dd= @invoice.description diff --git a/app/views/registrar/invoices/show.haml b/app/views/registrar/invoices/show.haml index ef87ac4be..41619084d 100644 --- a/app/views/registrar/invoices/show.haml +++ b/app/views/registrar/invoices/show.haml @@ -2,11 +2,11 @@ %hr .row .col-md-6= render 'registrar/invoices/partials/seller' - .col-md-6= render 'registrar/invoices/partials/buyer' -/ .row -/ .col-md-12= render 'admin/domains/partials/tech_contacts' -/ .row -/ .col-md-12= render 'admin/domains/partials/admin_contacts' + .col-md-6= render 'registrar/invoices/partials/details' +.row + .col-md-12= render 'registrar/invoices/partials/buyer' +.row + .col-md-12= render 'registrar/invoices/partials/items' / .row / .col-md-12= render 'admin/domains/partials/statuses' / .row diff --git a/config/locales/en.yml b/config/locales/en.yml index cb21caa33..5fc476487 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -647,3 +647,6 @@ en: amount: 'Amount' please_pay_the_following_invoice: 'Please pay the following invoice' invoice_no: 'Invoice no. %{no}' + seller: 'Seller' + prepayment: 'Prepayment' + vat: 'VAT (%{vat_prc}%)' diff --git a/db/migrate/20150408081917_create_invoice_items.rb b/db/migrate/20150408081917_create_invoice_items.rb index e4025a8fc..c884c3dda 100644 --- a/db/migrate/20150408081917_create_invoice_items.rb +++ b/db/migrate/20150408081917_create_invoice_items.rb @@ -4,9 +4,9 @@ class CreateInvoiceItems < ActiveRecord::Migration t.integer :invoice_id # t.string :product_code t.string :description, null: false - t.string :item_unit - t.integer :item_amount - t.decimal :item_price + t.string :unit + t.integer :amount + t.decimal :price t.timestamps end diff --git a/db/schema.rb b/db/schema.rb index 7db3923fe..6546ff70f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -209,9 +209,9 @@ ActiveRecord::Schema.define(version: 20150413140933) do create_table "invoice_items", force: :cascade do |t| t.integer "invoice_id" t.string "description", null: false - t.string "item_unit" - t.integer "item_amount" - t.decimal "item_price" + t.string "unit" + t.integer "amount" + t.decimal "price" t.datetime "created_at" t.datetime "updated_at" end