#encoding: utf-8 module C4LabelPrintProvider # # # def self.included(klass) klass.extend ClassMethods # klass.logger.debug "*** extending Class #{klass.class_name} with say_c4_label" klass.class_eval do include InstanceMethods end end # # # module ClassMethods end # # # module InstanceMethods # # # def say_c4_label nbr_labels=2, label_printer="" kvast_strings = [] product_label = [] stock_or_customer_sign = provide_customer_or_stock_label ft_profil = "" if self.product.name =~ /FT Profil \D*/ # profil_nr ="FT Profil %s" % self.product.name.gsub(/^.* FT Profil (\d*).*$/, "\\1") # ft_profil = " # T :text2;8,135,0,3,pt25;#{profil_nr}" end props=self.product.name.split(" ") props=props[0..props.size-2] if props.at(-1) =~ /\d*\/\d/ if props.size > 6 product_label[0] = props[0..6].join(" ") product_label[1] = props[7..props.size].join(" ") #[ltw..self.product.name.size] else product_label[0] = props.join(" ") product_label[1] = "" end if self.stock_items.size > 0 kvasts = self.stock_items.collect { |si| "%i/%0.2f" % [si.quantity.to_i,si.product.length.to_f] } kvast_strings << kvasts[0..6].join(" :: ").gsub(/\./,",") kvast_strings << ((kvasts.size > 6) ? kvasts[7..kvasts.size].join(" :: ").gsub(/\./,",") : "") product_label[0] = product_label[0].gsub(/KVAST .*/, "") product_label[1] = product_label[1].gsub(/KVAST .*/, "KVAST") else kvast_strings = [] kvast_strings << "" kvast_strings << "" end supplier_colli_barcode_number = self.supplier_barcode_number ||= "" if (width==0.0 or width.blank?) thick_height = "ø#{self.product.height.to_i}" else thick_height = "#{self.product.height.to_i} x #{self.product.width.to_i}" end # old barcode: B 11.51,125.12,90,e,14.25,0.25;#{self.barcode_number.to_s} # B 5, 5,0,CODE128, 12,.3;ABC123 cmd="J H175,+0 O R I :image1;8,55,90;LOGOGREY S l1;0,0,145,149,104;label G 4.13,6.88,0;R:95.09,131.13,1.00,1.00[F:100%] B 18,125.12,90,CODE128,25,0.5;#{self.barcode_number.to_s} T :bc_label;15,125,90,5,pt36;#{self.barcode_number.to_s} #{stock_or_customer_sign} T :text0;64,125,90,3,pt10;#{product_label[0]} T :text1;68,125,90,3,pt10;#{product_label[1]}#{ft_profil} T :thick_height;60,125,90,5,pt46;#{thick_height} T :quantity_length;80,125,90,5,pt36;#{self.quantity.to_i.to_s} stk/ #{self.product.length.to_s.gsub(/\./,",")}m T :pieces0;83,125,90,5,pt8;#{kvast_strings[0]} T :pieces1;87,125,90,5,pt8;#{kvast_strings[1]} T :supplier_colli_barcode_number;96,135.12,90,3,pt8;#{supplier_colli_barcode_number} T :cubic;96,30,90,3,pt8;#{self.cubic.to_s}m3 T :label_print_dato;96,8,180,3,pt10;#{ Time.now.strftime('%d-%m-%Y')} A #{nbr_labels} " # CHANGED 2009-01-15 use quantity from self - #{self.product.casing.split(" ")[0].to_s} stk/ #{self.product.length.to_s}m return cmd if label_printer=="" upload_logo label_printer File.open("#{RAILS_ROOT}/public/documents/label", "w") do |f| f.write(cmd) end %x(lp -d #{label_printer} -o raw #{RAILS_ROOT}public/documents) rescue "" end # # provide the sign for labels - either a customer or a stock sign (two-digit year) def provide_customer_or_stock_label # does this stock_item task belong to any particular customer order? unless (self.purchase_task.blank? or self.purchase_task.customer_partner.blank?) return " T :customer_name;31,70,90,5,pt12;#{ self.purchase_task.customer_partner.name.strip[0..25] } T :customer_zip;39,70,90,5,pt12;#{ zipcode_and_order_nr self.purchase_task }" else # perhaps the entire pick_list is a customer order?! unless self.purchase_picklist.blank? customer = self.purchase_picklist.customer_partner unless customer.blank? return " T :customer_name;31,70,90,5,pt12;#{ customer.name.strip[0..25] } T :customer_zip;39,70,90,5,pt12;#{ zipcode_and_order_nr self.purchase_picklist }" end end # this is most definately a stock order - tell them! return "T :year_big;40,58,90,5,pt66;#{ Time.now.strftime('%y') }" end end # # build zipcode and order number def zipcode_and_order_nr element "box: #{element.customer_partner.zipcode.strip[0..8]} ordrenr.: #{element.customer_project_number.strip[0..6]}" end # # # # # # def upload_logo printer unless File.exist?("#{RAILS_ROOT}/tmp/lbl_logo.dat") esc_byte = "\e" buff = "" buff << "e GIF;* d GIF;LOGOGREY " + esc_byte + "." File.open("#{RAILS_ROOT}/public/forms/labels/logogrey.gif", "r") do |f| f.each_byte {|b| b==27 ? buff<< b << b : buff << b} end buff << esc_byte + "." File.open("#{RAILS_ROOT}/tmp/lbl_logo.dat", "w") do |f| f.write(buff) end end value = `lp -d #{printer} -o raw #{RAILS_ROOT}/tmp/lbl_logo.dat` true rescue false end def label_test kvast_strings = [] product_label = [] # if self.stock_items.size > 0 # kvasts = self.stock_items.collect { |si| "#{si.quantity} / #{si.product.length}" } # kvast_strings << kvasts[0..6].join(" :: ") # kvast_strings << ((kvasts.size > 6) ? kvasts[7..kvasts.size].join(" :: ") : "") # product_label[0] = self.product.name.gsub(/KVAST .*/, "") # product_label[1] = self.product.name.gsub(/.* KVAST/, "KVAST") # else kvast_strings = [] kvast_strings << "" kvast_strings << "" product_label[0] = "16x100 fyr ru tørret 12-15% æøåÆØÅ" product_label[1] = "KVAST 201/3.454" # end supplier_colli_barcode_number = "" # TODO 2008-09-09 add supplier barcode number to picklist input # old barcode: B 11.51,125.12,90,e,14.25,0.25;#{self.barcode_number.to_s} # B 5, 5,0,CODE128, 12,.3;ABC123 # CHANGED 2008-09-12: from # S l1;0,0,144,149,103;label # B 11.51,125.12,90,CODE128,14.25,0.25;9201123123 # T :bc_label;35.51,125.25,90,5,pt36;9201123123 cmd = "J H175,+0,D O R, T S l1;0,0,145,149,104;label G 4.13,6.88,0;R:95.09,131.13,1.00,1.00[F:100%] B 18,125.12,90,CODE128,25,0.5;9201123123 T :bc_label;15,125,90,5,pt36;123123 T :text0;64,125,90,3,pt10;#{product_label[0]} T :text1;68,125,90,3,pt10;#{product_label[1]} T :thick_height;60,125,90,5,pt46;16 x 100 T :quantity_length;80,125,90,5,pt36;201 stk/ 3.454m T :pieces0;83,125,90,5,pt8;#{kvast_strings[0]} T :pieces1;87,125,90,5,pt8;#{kvast_strings[1]} T :supplier_colli_barcode_number;96,135.12,90,3,pt8;#{supplier_colli_barcode_number} T :cubic;96,30,90,3,pt8;1.456m3 T :label_print_dato;96,8,180,3,pt10;#{ Time.now.strftime('%d-%m-%Y')} A 1 " File.open("#{RAILS_ROOT}/tmp/label", "w") do |f| f.write(cmd) end %x(lp -d label -o raw #{RAILS_ROOT}/tmp/label) end end end