Module: C4LabelPrintProvider::InstanceMethods
- Defined in:
- lib/c4_label_print_provider.rb
Instance Method Summary collapse
- #label_test ⇒ Object
-
#provide_customer_or_stock_label ⇒ Object
provide the sign for labels - either a customer or a stock sign (two-digit year).
- #say_c4_label(nbr_labels = 2, label_printer = "") ⇒ Object
- #upload_logo(printer) ⇒ Object
-
#zipcode_and_order_nr(element) ⇒ Object
build zipcode and order number.
Instance Method Details
#label_test ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/c4_label_print_provider.rb', line 164 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 = "" # 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 |
#provide_customer_or_stock_label ⇒ Object
provide the sign for labels - either a customer or a stock sign (two-digit year)
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/c4_label_print_provider.rb', line 105 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 |
#say_c4_label(nbr_labels = 2, label_printer = "") ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 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 |
# File 'lib/c4_label_print_provider.rb', line 32 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 = self. ||= "" 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 |
#upload_logo(printer) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/c4_label_print_provider.rb', line 141 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 |
#zipcode_and_order_nr(element) ⇒ Object
build zipcode and order number
130 131 132 |
# File 'lib/c4_label_print_provider.rb', line 130 def zipcode_and_order_nr element "box: #{element.customer_partner.zipcode.strip[0..8]} ordrenr.: #{element.customer_project_number.strip[0..6]}" end |