lib/pack_material/services/complete_purchase_invoice.rb
# rubocop:disable Metrics/ClassLength
# Complete a purchase invoice and send XML representation to accounting system.
# - use the `just_show_xml` flag to check the XML output without modifying the db.
#
# @param user_name [string] the user who initiated this task.
# @param opts [Hash] { delivery_id [integer], mr_goods_returned_note_id [integer] }
# @param just_show_xml [bool] set to true to just return XML from the call without updating the db.
disable Metrics/ClassLength
Complete a purchase invoice and send XML representation to accounting system.
use the `just_show_xml` flag to check the XML output without modifying the db.
disable Metrics / ClassLength Complete a purchase invoice and send XML representation to accounting system . use the ` just_show_xml ` flag to check the XML output without modifying the db .
def build_grn_xml 
      supplier_invoice_number = @delivery.supplier_invoice_ref_number
      supplier_invoice_date = @delivery.supplier_invoice_date.to_s
      supplier_code = @repo.get_supplier_erp_number(@id)
      po_account_code = @repo.po_account_code_for_delivery(@id)
      cn_number = @goods_returned_note.credit_note_number
      products = @purchase_invoice_repo.products_for_goods_returned_note(@grn_id)
      cn_totals = @purchase_invoice_repo.cn_sub_totals(@grn_id, delimiter: '', no_decimals: 5)
      request_xml = Nokogiri::XML::Builder.new do |xml|
        xml.purchase_invoice do
          xml.supplier_invoice_number supplier_invoice_number
          xml.supplier_invoice_date supplier_invoice_date
          xml.internal_invoice_number cn_number
          xml.supplier_code supplier_code
          xml.account_code po_account_code
          xml.invoice_total cn_totals[:total]
          xml.subtotal cn_totals[:subtotal]
          xml.vat cn_totals[:vat]
          xml.pay_term 'CN'
          xml.line_items do
            products.each do |line_item|
              xml.line_item do
                xml.product_number line_item[:product_number]
                xml.product_description line_item[:product_description]
                xml.unit_price UtilityFunctions.delimited_number(line_item[:unit_price], delimiter: '', no_decimals: 5)
                xml.quantity UtilityFunctions.delimited_number(line_item[:quantity], delimiter: '', no_decimals: 2)
                xml.purchase_order_number line_item[:purchase_order_number]
              end
            end
          end
        end
      end
      request_xml.to_xml
    end
def build_grn_xml supplier_invoice_number = @delivery . supplier_invoice_ref_number supplier_invoice_date = @delivery . supplier_invoice_date . to_s supplier_code = @repo . get_supplier_erp_number ( @id ) po_account_code = @repo . po_account_code_for_delivery ( @id ) cn_number = @goods_returned_note . credit_note_number products = @purchase_invoice_repo . products_for_goods_returned_note ( @grn_id ) cn_totals = @purchase_invoice_repo . cn_sub_totals ( @grn_id , delimiter : '' , no_decimals : 5 ) request_xml = Nokogiri :: XML :: Builder . new do | xml | xml . purchase_invoice do xml . supplier_invoice_number supplier_invoice_number xml . supplier_invoice_date supplier_invoice_date xml . internal_invoice_number cn_number xml . supplier_code supplier_code xml . account_code po_account_code xml . invoice_total cn_totals [ :total ] xml . subtotal cn_totals [ :subtotal ] xml . vat cn_totals [ :vat ] xml . pay_term 'CN' xml . line_items do products . each do | line_item | xml . line_item do xml . product_number line_item [ :product_number ] xml . product_description line_item [ :product_description ] xml . unit_price UtilityFunctions . delimited_number ( line_item [ :unit_price ] , delimiter : '' , no_decimals : 5 ) xml . quantity UtilityFunctions . delimited_number ( line_item [ :quantity ] , delimiter : '' , no_decimals : 2 ) xml . purchase_order_number line_item [ :purchase_order_number ] end end end end end request_xml . to_xml end
rubocop:disable Metrics/ClassLength
Complete a purchase invoice and send XML representation to accounting system.
rubocop : disable Metrics / ClassLength Complete a purchase invoice and send XML representation to accounting system .
# rubocop:disable Metrics/AbcSize # Deliveries are limited to single suppliers # delivery_number = @delivery.delivery_number # xml.internal_invoice_number delivery_number # xml.credit_note_number cn_number
user_name
<not_specific>
the user who initiated this task.
the user who initiated this task .
opts
<not_specific>
{ delivery_id [integer], mr_goods_returned_note_id [integer] }
{ delivery_id [ integer ] mr_goods_returned_note_id [ integer ] }
just_show_xml
<not_specific>
set to true to just return XML from the call without updating the db.
set to true to just return XML from the call without updating the db .