Browse Source

測試銷售單

ANX 4 years ago
parent
commit
4d7b2661b2

+ 3 - 2
Gemfile

@@ -31,8 +31,9 @@ gem 'jbuilder', '~> 2.5'
 # gem 'redis', '~> 3.0'
 # Use ActiveModel has_secure_password
 # gem 'bcrypt', '~> 3.1.7'
-gem 'tiny_tds'
-gem 'activerecord-sqlserver-adapter'
+gem 'tiny_tds', '~> 1.0.4'
+gem 'activerecord-sqlserver-adapter', '~> 5.0.1'
+gem 'bootstrap-sass', '~> 3.3.6'
 # Use Capistrano for deployment
 # gem 'capistrano-rails', group: :development
 

+ 10 - 3
Gemfile.lock

@@ -33,13 +33,19 @@ GEM
       activemodel (= 5.0.1)
       activesupport (= 5.0.1)
       arel (~> 7.0)
-    activerecord-sqlserver-adapter (2.3.8)
+    activerecord-sqlserver-adapter (5.0.1)
+      activerecord (~> 5.0.0)
     activesupport (5.0.1)
       concurrent-ruby (~> 1.0, >= 1.0.2)
       i18n (~> 0.7)
       minitest (~> 5.1)
       tzinfo (~> 1.1)
     arel (7.1.4)
+    autoprefixer-rails (6.6.1)
+      execjs
+    bootstrap-sass (3.3.7)
+      autoprefixer-rails (>= 5.2.1)
+      sass (>= 3.3.4)
     builder (3.2.3)
     byebug (9.0.6)
     coffee-rails (4.2.1)
@@ -157,7 +163,8 @@ PLATFORMS
   ruby
 
 DEPENDENCIES
-  activerecord-sqlserver-adapter
+  activerecord-sqlserver-adapter (~> 5.0.1)
+  bootstrap-sass (~> 3.3.6)
   byebug
   coffee-rails (~> 4.2)
   jbuilder (~> 2.5)
@@ -169,7 +176,7 @@ DEPENDENCIES
   spring
   spring-watcher-listen (~> 2.0.0)
   sqlite3
-  tiny_tds
+  tiny_tds (~> 1.0.4)
   turbolinks (~> 5)
   tzinfo-data
   uglifier (>= 1.3.0)

+ 1 - 0
app/assets/javascripts/application.js

@@ -11,6 +11,7 @@
 // about supported directives.
 //
 //= require jquery
+//= require bootstrap-sprockets
 //= require jquery_ujs
 //= require turbolinks
 //= require_tree .

+ 3 - 0
app/assets/javascripts/pages.coffee

@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://coffeescript.org/

+ 3 - 0
app/assets/stylesheets/application.css

@@ -13,3 +13,6 @@
  *= require_tree .
  *= require_self
  */
+
+ @import "bootstrap-sprockets";
+ @import "bootstrap";

+ 3 - 0
app/assets/stylesheets/pages.scss

@@ -0,0 +1,3 @@
+// Place all the styles related to the pages controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/

+ 5 - 0
app/controllers/pages_controller.rb

@@ -0,0 +1,5 @@
+class PagesController < ApplicationController
+  def index
+    @orders = SoSalesOrder.all
+  end
+end

+ 2 - 0
app/helpers/pages_helper.rb

@@ -0,0 +1,2 @@
+module PagesHelper
+end

+ 1 - 1
app/models/inflow_server.rb

@@ -1,3 +1,3 @@
-class InflowServer < ApplicationRecord
+class InflowServer < ActiveRecord::Base
   establish_connection :inflow_server
 end

+ 2 - 1
app/models/so_sales_order.rb

@@ -1,5 +1,6 @@
 class SoSalesOrder < InflowServer
   self.table_name = 'So_SalesOrder'
   self.primary_key = 'SalesOrderId'
-  has_many :so_sales_order_lines
+
+  has_many :lines, class_name: "SoSalesOrderLine", foreign_key: "SalesOrderId", primary_key: "SalesOrderId"
 end

+ 3 - 2
app/models/so_sales_order_line.rb

@@ -1,5 +1,6 @@
 class SoSalesOrderLine < InflowServer
-  self.table_name = 'So_SalesOrder_Lines'
+  self.table_name = 'So_SalesOrder_Line'
   self.primary_key = 'SalesOrderLineId'
-  belongs_to :so_sales_order
+
+  belongs_to :order, class_name: "SoSalesOrder", foreign_key: "SalesOrderId", primary_key: "SalesOrderId"
 end

+ 38 - 0
app/views/pages/index.html.erb

@@ -0,0 +1,38 @@
+<h1>Pages#index</h1>
+<p>Find me in app/views/pages/index.html.erb</p>
+
+<table class="table table-bordered table-striped table-hover">
+  <tr>
+    <th>#</th>
+    <th>訂單</th>
+    <th>明細</th>
+  </tr>
+  <% @orders.each.with_index(1) do |order,index| %>
+  <tr>
+    <td><%= index %></td>
+    <td><%= order.OrderNumber %></td>
+    <td>
+      <table class="table table-striped table-hover">
+        <tr>
+          <th>#</th>
+          <th>型號</th>
+          <th>單價</th>
+          <th>數量</th>
+          <th>折扣</th>
+          <th>小計</th>
+        </tr>
+        <% order.lines.each do |line| %>
+        <tr>
+          <td><%= line.LineNum %></td>
+          <td><%= line.ProdId %></td>
+          <td><%= line.UnitPrice %></td>
+          <td><%= line.Quantity %></td>
+          <td><%= line.Discount %>%</td>
+          <td><%= line.SubTotal %></td>
+        </tr>
+        <% end %>
+      </table>
+    </td>
+  </tr>
+  <% end %>
+</table>

+ 5 - 5
config/database.yml

@@ -14,11 +14,11 @@ development:
   database: db/development.sqlite3
 
 inflow_server:
-    adapter: sqlserver
-    host: 192.168.2.104
-    database: InFlow
-    username: sa
-    password: 123
+  adapter: sqlserver
+  host: 192.168.1.66
+  database: InFlow
+  username: sa
+  password: 123
 # Warning: The database defined as "test" will be erased and
 # re-generated from your development database when you run "rake".
 # Do not set this db to the same as development or production.

+ 2 - 0
config/routes.rb

@@ -1,3 +1,5 @@
 Rails.application.routes.draw do
+  get 'pages/index'
+  root 'pages#index'
   # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
 end