Created
April 30, 2012 12:42
-
-
Save kohgpat/2557994 to your computer and use it in GitHub Desktop.
Duplicates P023
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: UTF-8 | |
require 'builder' | |
require 'spreadsheet' | |
Spreadsheet.client_encoding = 'UTF-8' | |
class Person | |
attr_accessor :fam, :im, :ot, :w, :dr | |
attr_accessor :s_pol, :n_pol, :enp, :dp | |
attr_accessor :sn_pasp | |
def initialize(fam, im, ot, w, dr, s_pol, n_pol, enp, dp, sn_pasp) | |
@fam, @im, @ot, @w, @dr, @s_pol, @n_pol, @enp, @dp, @sn_pasp = fam, im, ot, w, dr, s_pol, n_pol, enp, dp, sn_pasp | |
end | |
def sex | |
w.to_i | |
end | |
def birthday | |
Date.parse(dr) | |
end | |
def docdate | |
Date.parse(dp) | |
end | |
def doctype | |
if sn_pasp[0] == 'I' | |
return 3 | |
elsif sn_pasp[0] == 'III' | |
return 3 | |
elsif sn_pasp[0] == 'V' | |
return 3 | |
else | |
return 14 | |
end | |
end | |
def docser | |
doc_arr = sn_pasp.split(" ") | |
doc_arr[0..doc_arr.length-2].join(" ") | |
end | |
def docnum | |
sn_pasp.split(" ").last | |
end | |
def vpolis | |
if s_pol == "РГС" | |
return 1 | |
elsif n_pol.start_with?("013") | |
return 2 | |
else | |
return 3 | |
end | |
end | |
end | |
class App | |
attr_accessor :workbook | |
attr_accessor :people | |
def initialize(workbook) | |
@workbook = Spreadsheet.open workbook | |
end | |
def run | |
puts "[Processing data]" | |
create_people | |
export_people | |
puts "[Complete]" | |
end | |
def create_people | |
@people = [] | |
get_data.each do |r| | |
@people << Person.new(r[0].gsub(' ', ''), r[1].gsub(' ', ''), r[2].gsub(' ', ''), r[3], r[4], r[16].gsub(' ', ''), r[17].gsub(' ', ''), r[18], r[20], r[26]) | |
end | |
end | |
def export_people | |
xml = Builder::XmlMarkup.new(indent: 2) | |
xml.instruct! :xml, :version=>"1.0", :encoding=>"Windows-1251" | |
xml.OPLIST(VERS: "2.0", FILENAME: "I03102_231_041271", SMOCOD: "03102", PRZCOD: "231", NRECORDS: @people.count) { | |
@people.each_with_index do |person, idx| | |
xml.OP(N_REC: idx+1, ID: "", TIP_OP: "П023") { | |
xml.PERSON(FAM: person.fam, IM: person.im, OT: person.ot, W: person.sex, DR: person.birthday, TRUE_DR: "1", C_OKSM: "RUS", SS: "", PHONE: "", EMAIL: "", FIOPR: "", CONTACT: "", DDEATH: "") | |
xml.DOC(DOCTYPE: person.doctype, DOCSER: person.docser, DOCNUM: person.docnum, DOCDATE: "", NAME_VP: "", MR: "") | |
xml.OLD_PERSON(FAM: "", IM: "", OT: "", W: "", DR: "", OLD_ENP: "") | |
xml.OLD_DOC(DOCTYPE: "", DOCSER: "", DOCNUM: "", DOCDATE: "", NAME_VP: "", MR: "") | |
xml.ADDRES_G(BOMG: "", SUBJ: "", INDX: "", OKATO: "", RNNAME: "", NPNAME: "", UL: "", DOM: "", KORP: "", KV: "", DREG: "") | |
xml.ADDRES_P(SUBJ: "", INDX: "", OKATO: "", RNNAME: "", NPNAME: "", UL: "", DOM: "", KORP: "", KV: "", DREG: "") | |
xml.VIZIT(DVIZIT: person.docdate, METHOD: "", PETITION: "", RSMO: "0", RPOLIS: "0", FPOLIS: "0") | |
xml.INSURANCE(TER_ST: "81000", ENP: person.enp, OGRNSMO: "1027806865481", ERP: "") { | |
xml.POLIS(VPOLIS: person.vpolis, NPOLIS: person.n_pol, SPOLIS: person.s_pol, DBEG: person.docdate, DEND: "", DSTOP: Date.today) | |
} | |
} | |
end | |
} | |
file = File.new("I03102_231_041271.XML", "w") | |
file.write(xml.target!) | |
file.close | |
end | |
def get_data | |
sheet = @workbook.worksheet 0 | |
sheet.select { |row| row if row[30] == 'погасить' } | |
end | |
end | |
App.new("pasport_R21.xls").run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment