diff --git a/Gemfile.lock b/Gemfile.lock index affb7b95..ba8f6a0c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,39 +1,39 @@ GEM remote: https://rubygems.org/ specs: - actioncable (5.1.1) - actionpack (= 5.1.1) + actioncable (5.1.3) + actionpack (= 5.1.3) nio4r (~> 2.0) websocket-driver (~> 0.6.1) - actionmailer (5.1.1) - actionpack (= 5.1.1) - actionview (= 5.1.1) - activejob (= 5.1.1) + actionmailer (5.1.3) + actionpack (= 5.1.3) + actionview (= 5.1.3) + activejob (= 5.1.3) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.1.1) - actionview (= 5.1.1) - activesupport (= 5.1.1) + actionpack (5.1.3) + actionview (= 5.1.3) + activesupport (= 5.1.3) rack (~> 2.0) rack-test (~> 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.1.1) - activesupport (= 5.1.1) + actionview (5.1.3) + activesupport (= 5.1.3) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.1.1) - activesupport (= 5.1.1) + activejob (5.1.3) + activesupport (= 5.1.3) globalid (>= 0.3.6) - activemodel (5.1.1) - activesupport (= 5.1.1) - activerecord (5.1.1) - activemodel (= 5.1.1) - activesupport (= 5.1.1) + activemodel (5.1.3) + activesupport (= 5.1.3) + activerecord (5.1.3) + activemodel (= 5.1.3) + activesupport (= 5.1.3) arel (~> 8.0) - activesupport (5.1.1) + activesupport (5.1.3) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (~> 0.7) minitest (~> 5.1) @@ -64,7 +64,7 @@ GEM cups (0.0.7) database_cleaner (1.6.1) diff-lcs (1.3) - erubi (1.6.0) + erubi (1.6.1) execjs (2.7.0) factory_girl (4.8.0) activesupport (>= 3.0.0) @@ -81,7 +81,7 @@ GEM activesupport (>= 4.2.0) httparty (0.15.5) multi_xml (>= 0.5.2) - i18n (0.8.4) + i18n (0.8.6) jbuilder (2.7.0) activesupport (>= 4.2.0) multi_json (>= 1.2) @@ -115,7 +115,7 @@ GEM mime-types-data (~> 3.2015) mime-types-data (3.2016.0521) mini_portile2 (2.2.0) - minitest (5.10.2) + minitest (5.10.3) multi_json (1.12.1) multi_xml (0.6.0) mysql2 (0.4.6) @@ -136,26 +136,26 @@ GEM rack rack-test (0.6.3) rack (>= 1.0) - rails (5.1.1) - actioncable (= 5.1.1) - actionmailer (= 5.1.1) - actionpack (= 5.1.1) - actionview (= 5.1.1) - activejob (= 5.1.1) - activemodel (= 5.1.1) - activerecord (= 5.1.1) - activesupport (= 5.1.1) - bundler (>= 1.3.0, < 2.0) - railties (= 5.1.1) + rails (5.1.3) + actioncable (= 5.1.3) + actionmailer (= 5.1.3) + actionpack (= 5.1.3) + actionview (= 5.1.3) + activejob (= 5.1.3) + activemodel (= 5.1.3) + activerecord (= 5.1.3) + activesupport (= 5.1.3) + bundler (>= 1.3.0) + railties (= 5.1.3) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) rails-html-sanitizer (1.0.3) loofah (~> 2.0) - railties (5.1.1) - actionpack (= 5.1.1) - activesupport (= 5.1.1) + railties (5.1.3) + actionpack (= 5.1.3) + activesupport (= 5.1.3) method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) @@ -288,4 +288,4 @@ DEPENDENCIES whenever BUNDLED WITH - 1.15.1 + 1.15.3 diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 49c64e52..180901ad 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -17,6 +17,8 @@ class Crm::CustomersController < BaseCrmController @crm_customer = Customer.new @count_customer = Customer.count_customer + @taxes = TaxProfile.all.order("order_by asc") + # if flash["errors"] # @crm_customer.valid? # end @@ -67,11 +69,16 @@ class Crm::CustomersController < BaseCrmController # POST /crm/customers # POST /crm/customers.json - def create + def create + # Remove "" default first + params[:customer][:tax_profiles].delete_at(0) @crm_customers = Customer.new(customer_params) respond_to do |format| if @crm_customers.save + # update tax profile + customer = Customer.find(@crm_customers.customer_id) + customer.update_attributes(tax_profiles: params[:customer][:tax_profiles].to_json) name = customer_params[:name] phone = customer_params[:contact_no] email = customer_params[:email] @@ -346,7 +353,7 @@ end # Never trust parameters from the scary internet, only allow the white list through. def customer_params - params.require(:customer).permit(:name, :company, :contact_no, :email, - :date_of_birth,:salutation,:gender,:nrc_no,:address,:card_no, :paypar_account_no) + params.require(:customer).permit(:id, :name, :company, :contact_no, :email, + :date_of_birth,:salutation,:gender,:nrc_no,:address,:card_no, :paypar_account_no, :customer_type) end end diff --git a/app/models/sale.rb b/app/models/sale.rb index b06dc54f..c7ffec34 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -279,12 +279,15 @@ class Sale < ApplicationRecord sale_tax = SaleTax.new(:sale => sale) sale_tax.tax_name = tax.name sale_tax.tax_rate = tax.rate - #include or execulive - # sale_tax.tax_payable_amount = total_taxable * tax.rate # substract , to give after discount total_tax = total_taxable - total_discount - sale_tax.tax_payable_amount = total_tax * tax.rate / 100 + #include or execulive + if tax.inclusive + sale_tax.tax_payable_amount = total_tax / 21 + else + sale_tax.tax_payable_amount = total_tax * tax.rate / 100 + end #new taxable amount is standard rule for step by step # total_taxable = total_taxable + sale_tax.tax_payable_amount @@ -299,12 +302,6 @@ class Sale < ApplicationRecord # Tax Calculate def apply_tax(total_taxable) - #if tax is not apply create new record - # self.sale_taxes.each do |existing_tax| - # #delete existing and create new - # existing_tax.delete - # end - #if tax is not apply create new record SaleTax.where("sale_id='#{self.sale_id}'").find_each do |existing_tax| #delete existing and create new @@ -320,10 +317,16 @@ class Sale < ApplicationRecord sale_tax = SaleTax.new(:sale => self) sale_tax.tax_name = tax.name sale_tax.tax_rate = tax.rate - #include or execulive - # sale_tax.tax_payable_amount = total_taxable * tax.rate + + # substract , to give after discount total_tax = total_taxable - self.total_discount - sale_tax.tax_payable_amount = total_tax * tax.rate / 100 + #include or execulive + if tax.inclusive + sale_tax.tax_payable_amount = total_tax / 21 + else + sale_tax.tax_payable_amount = total_tax * tax.rate / 100 + end + #new taxable amount is standard rule for step by step # total_taxable = total_taxable + sale_tax.tax_payable_amount diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index a2b726c9..2dca6d16 100644 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -3,7 +3,7 @@ class ReceiptBillPdf < Prawn::Document attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width, :description_width, :price_num_width def initialize(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount = nil,shop_details, printed_status) self.page_width = 210 - self.page_height = 7000 + self.page_height = 1450 self.margin = 5 self.price_width = 40 self.qty_width = 20 diff --git a/app/views/crm/customers/_new_form.html.erb b/app/views/crm/customers/_new_form.html.erb index 1eda0bec..5f1d1b46 100644 --- a/app/views/crm/customers/_new_form.html.erb +++ b/app/views/crm/customers/_new_form.html.erb @@ -1,25 +1,7 @@
<%= simple_form_for @crm_customer,:url => crm_customers_path, :method => :post do |f| %> - <%= f.hidden_field :id, :class => "form-control col-md-6 " %> - -
"> - <%= f.input :card_no, :class => "form-control col-md-6 card_no"%> - <% flash.each do |name, msg| %> - <% str="[\"#{msg['card_no']}\"]" - str.gsub!('["', '') - str.gsub!('"]', '') %> - <%= str %> - <% end %> -
- -
- -
- -
-
-
+ <%= f.hidden_field :id, :class => "form-control col-md-6 " %>

@@ -102,6 +84,37 @@ <%= f.text_field :date_of_birth,:value=>"01-01-1990",:class=>"form-control datepicker"%>
+
"> + <%= f.input :card_no, :class => "form-control col-md-6 card_no"%> + <% flash.each do |name, msg| %> + <% str="[\"#{msg['card_no']}\"]" + str.gsub!('["', '') + str.gsub!('"]', '') %> + <%= str %> + <% end %> +
+ +
+ + +
+
+ <%= f.input :tax_profiles, :collection => @taxes, :input_html => { :multiple => true }, :class => "form-control col-md-6 tax_profiles" %> +
+ +
+ +
+ +
+
+
+
- +
@@ -138,6 +150,11 @@ },100); } }); + + // $("#customer_card_no").click(function(){ + // var ab=$("#customer_tax_profiles").val(); + // console.log(JSON.stringify(ab)); + // }); }); diff --git a/app/views/crm/customers/index.html.erb b/app/views/crm/customers/index.html.erb index 6f336158..b1b1272b 100644 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -76,7 +76,7 @@
- <%= render 'new_form', crm_customer: @crm_customer %> + <%= render 'new_form', crm_customer: @crm_customer, taxes: @taxes %>

@@ -129,7 +129,14 @@ $(document).on('click',".customer_tr",function(){ url: url, data: {}, dataType: "json", - success: function(data) { + success: function(data) { + // Selected for Taxes + //var taxes = JSON.stringify(data.tax_profiles); + var parse_taxes = JSON.parse(data.tax_profiles); + $.each(parse_taxes, function(i, value){ + $("#customer_tax_profiles option[value='" + value + "']").attr("selected","selected"); + }); + $('#customer_id').val(data.id); $('#customer_name').val(data.name); $('#customer_company').val(data.company); @@ -138,6 +145,7 @@ $(document).on('click',".customer_tr",function(){ $('#customer_salutation').val(data.salutation); $('#customer_nrc_no').val(data.nrc_no); $('#customer_card_no').val(data.card_no); + $('#customer_type').val(data.customer_type); $('#paypar_account_no').val(data.paypar_account_no); $('#customer_address').val(data.address); $('#customer_date_of_birth').val(data.date_of_birth); diff --git a/app/views/crm/customers/show.json.jbuilder b/app/views/crm/customers/show.json.jbuilder index 5fd0410a..ffc312a2 100644 --- a/app/views/crm/customers/show.json.jbuilder +++ b/app/views/crm/customers/show.json.jbuilder @@ -1,4 +1,4 @@ json.extract! @crm_customer, :id, :name, :company, :contact_no, :email, :date_of_birth, :membership_id, :membership_type, :membership_authentication_code, - :salutation, :gender,:nrc_no,:address,:card_no, :paypar_account_no + :salutation, :gender,:nrc_no,:address,:card_no, :paypar_account_no, :customer_type, :tax_profiles json.url crm_customer_url(@crm_customer, format: :json) diff --git a/db/migrate/20170622050926_create_customers.rb b/db/migrate/20170622050926_create_customers.rb index 20ced7b0..cb370bc1 100644 --- a/db/migrate/20170622050926_create_customers.rb +++ b/db/migrate/20170622050926_create_customers.rb @@ -16,6 +16,8 @@ class CreateCustomers < ActiveRecord::Migration[5.1] t.string :membership_id t.string :membership_type t.string :membership_authentication_code + t.string :customer_type, :default => "Dinein" + t.json :tax_profiles end end end diff --git a/db/seeds.rb b/db/seeds.rb index 065b447c..1b63bcb0 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -87,11 +87,16 @@ void_reason = Lookup.create([{lookup_type:'void_reason', name: 'Approve By Manag {lookup_type:'void_reason', name: 'Cashier Mistake', value: 'Cashier Mistake'}, {lookup_type:'void_reason', name: 'Waiter Mistake', value: 'Waiter Mistake'}]) - # sale void reason - float_value = Lookup.create([{lookup_type:'float_value', name: '500', value: '500'}, - {lookup_type:'float_value', name: '1000', value: '1000'}, - {lookup_type:'float_value', name: '5000', value: '5000'}, - {lookup_type:'float_value', name: '10000', value: '10000'}]) +# sale void reason +float_value = Lookup.create([{lookup_type:'float_value', name: '500', value: '500'}, + {lookup_type:'float_value', name: '1000', value: '1000'}, + {lookup_type:'float_value', name: '5000', value: '5000'}, + {lookup_type:'float_value', name: '10000', value: '10000'}]) + +# customer type +customer_type = Lookup.create([{lookup_type:'customer_type', name: 'Dinein', value: 'Dinein'}, + {lookup_type:'customer_type', name: 'Takeaway', value: 'Takeaway'}, + {lookup_type:'customer_type', name: 'Delivery', value: 'Delivery'}]) #WALK CUSTOMER - Default CUSTOMER (take key 1) customer = Customer.create({name:"WALK-IN", email: "cus1@customer.com", contact_no:"000000000",card_no:"000"})