class VendorDocument < Sequel::Model(:'vendor documents') set_primary_key [:'kid - user', :'kid - mult', :'kid - comm', :'kid - date', :'kid - time'] unrestrict_primary_key # helper accessors for creating vendor document # filename_prefix helps set up the path to the document attr_accessor :doc_type_value, :file_name_prefix, :doc_type, :file_name ###### helper aliases for crewres to submit new vendor documents ######### column_alias :trip_number, :number, :type => :integer column_alias :description, :name # Code associations code_association :type, :document_type, :aircraft_document def validate validates_presence [:document_type, :image_name, :number, :doc_date, :document_type] end def after_initialize if new? set_kids set_other_vars end end def set_kids self.kid_date=Date.today.to_fos_days self.kid_time=Time.now.as_minutes self.kid_comm=0 self.kid_mult=next_kid_mult self.kid_user="ADMN" end def next_kid_mult vd = VendorDocument.filter(:kid_date=>kid_date,:kid_time=>kid_time).order(:kid_mult).last (vd and vd.kid_mult < 255) ? vd.kid_mult+1 : 0 end def set_other_vars self.doc_date = case doc_date when String then Date.parse(doc_date).to_fos_days when Date then doc_date.to_fos_days else Date.today.to_fos_days end self.renew_days= 0 self.category= 0 self.cost= 0 self.status_code= 0 self.acct_number= "" self.paid_date= 0 self.paid= 0 self.billed_date= 0 self.image_name= File.join(file_name_prefix, file_name) if file_name self.document_type= doc_type_value if Code.valid_value_for_group?(doc_type_value, :aircraft_document) end #### BEGIN GENERATED SECTION #### column_alias :acct_number, :'acct number' column_alias :billed, :'billed' column_alias :billed_date, :'billed date' column_alias :category, :'category' column_alias :cost, :'cost' column_alias :doc_date, :'doc date' column_alias :document_type, :'document type' column_alias :exp_date, :'exp date' column_alias :image_name, :'image name' column_alias :inactive, :'inactive' column_alias :internal0, :'internal0' column_alias :internal01, :'internal01' column_alias :internal02, :'internal02' column_alias :internal03, :'internal03' column_alias :internal04, :'internal04' column_alias :internal2, :'internal2' column_alias :kid_comm, :'kid - comm' column_alias :kid_date, :'kid - date' column_alias :kid_mult, :'kid - mult' column_alias :kid_time, :'kid - time' column_alias :kid_user, :'kid - user' column_alias :name, :'name' column_alias :number, :'number' column_alias :paid, :'paid' column_alias :paid_date, :'paid date' column_alias :renew_days, :'renew days' column_alias :status_code, :'status code' column_alias :vendor_id, :'vendor id' column_alias :vendor_kid_comm, :'vendor kid - comm' column_alias :vendor_kid_date, :'vendor kid - date' column_alias :vendor_kid_mult, :'vendor kid - mult' column_alias :vendor_kid_time, :'vendor kid - time' column_alias :vendor_kid_user, :'vendor kid - user' column_alias :key0, :'key0' column_alias :key1, :'key1' column_alias :key2, :'key2' column_alias :key3, :'key3' column_alias :key4, :'key4' #### END GENERATED SECTION #### end