Class: Sap::Invoice

Inherits:
SapAnywhereInterface show all
Defined in:
lib/resource/sap/invoice.rb

Instance Method Summary collapse

Methods inherited from SapAnywhereInterface

#check_access_token, #check_function_and_shop, #convert_payment_type, #convert_price_unit, #delete, #get, #get_access_token, #get_access_token_url, #handle_response, #patch, #post

Constructor Details

#initialize(source) ⇒ Invoice

Note:

对象初始化方法(初始化来源)

对象初始化方法(初始化来源)

Parameters:

  • source (string)


9
10
11
# File 'lib/resource/sap/invoice.rb', line 9

def initialize(source)
  @source = source
end

Instance Method Details

#convert_to_sap_invoice(order) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/resource/sap/invoice.rb', line 64

def convert_to_sap_invoice(order)
  sap_invoice = yhash

  # 汇率
  sap_invoice.exchangeRate = 1

  # 过账时间
  sap_invoice.postingTime = order.try(:orderTime)

  # 到期时间
  sap_invoice.dueTime = order.try(:orderTime)

  # 备注
  sap_invoice.remark = "来源订单编号[#{order.try(:docNumber)}]"

  # 联系人
  # sap_invoice.contactPerson = yhash
  # sap_invoice.contactPerson.id = ''

  # 账单地址
  sap_invoice.billingAddress = yhash
  sap_invoice.billingAddress.state = order.try(:billingAddress).try(:state)
  sap_invoice.billingAddress.cityName = order.try(:billingAddress).try(:cityName)
  sap_invoice.billingAddress.street1 = order.try(:billingAddress).try(:street1)
  sap_invoice.billingAddress.street2 = order.try(:billingAddress).try(:street2)
  sap_invoice.billingAddress.zipCode = order.try(:billingAddress).try(:zipCode)
  sap_invoice.billingAddress.mobile = order.try(:billingAddress).try(:mobile)
  sap_invoice.billingAddress.telephone = order.try(:billingAddress).try(:telephone)
  sap_invoice.billingAddress.recipientName = order.try(:billingAddress).try(:recipientName)
  sap_invoice.billingAddress.displayName = order.try(:billingAddress).try(:displayName)

  # 发票行
  sap_invoice.invoiceLines = []
  order.try(:productLines).try(:each) do |child_product_lines|
    child_invoice_lines = yhash
    child_invoice_lines.baseDocument = yhash
    child_invoice_lines.baseDocument.baseId = order.try(:id)
    child_invoice_lines.baseDocument.baseNumber = nil
    child_invoice_lines.baseDocument.baseType = nil
    child_invoice_lines.baseDocument.baseLineId = child_product_lines.try(:id)
    child_invoice_lines.baseDocument.baseLineNumber = nil
    child_invoice_lines.remark = nil

    sap_invoice.invoiceLines << child_invoice_lines
  end

  # 物流行
  sap_invoice.shippingLines = [
      {
          baseDocument: {
              baseId: order.try(:id),
              baseNumber: nil,
              baseType: nil,
              baseLineId: order.try(:shippingLines).try(:first).try(:id),
              baseLineNumber: nil
          },
          remark: nil
      }
  ]

  # # 付款信息
  sap_invoice.paymentTerm = yhash
  sap_invoice.paymentTerm.id = order.try(:paymentTerm).try(:id)
  sap_invoice.paymentTerm.name = order.try(:paymentTerm).try(:name)

  sap_invoice

end

#find(id) ⇒ Object

Note:

通过接口获得单个数据

通过接口获得单个数据

Parameters:

  • id (Integer)

    数据id



24
25
26
# File 'lib/resource/sap/invoice.rb', line 24

def find(id)
  get(query(id))
end

#listObject

Note:

通过接口获得一堆数据

通过接口获得一堆数据

Parameters:

  • source (string)

    来源

  • request_name (string)

    请求资源名



17
18
19
# File 'lib/resource/sap/invoice.rb', line 17

def list
  get(query)
end

#query(params = {}, id = {}) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/resource/sap/invoice.rb', line 40

def  query(params = {}, id = {})
  # Rails.logger.info params[:user_id]
  request_names = if params.class == Fixnum || params.class == String
                    "#{request_name}/#{params}?expand=*&"
                  elsif id.class == Fixnum
                    "#{request_name}/#{id}?expand=*&"
                  else
                    "#{request_name}?expand=*&"
                  end
  post_params = {
      source: @source,
      request_name: request_names
  }
  p "params是#{params}"
  p "id是#{id}"
  if params.class != Fixnum && params.class != String && params.present?
    post_params.merge!(invoice: convert_to_sap_invoice(params))
    p "post_params#{post_params}"
  end
  post_params.merge(id: id) if id.class == Fixnum
  # p "当前参数#{post_params}"
  post_params
end

#request_nameObject

Note:

获取请求路径的请求名

获取请求路径的请求名



36
37
38
# File 'lib/resource/sap/invoice.rb', line 36

def request_name
  'SalesInvoices'
end

#upload(invoice_order) ⇒ Object

将收付款单数据从云店家上传到sap

Parameters:

  • invoice_order (string)


30
31
32
# File 'lib/resource/sap/invoice.rb', line 30

def upload(invoice_order)
  invoice_id = post(query(invoice_order))
end