2 package SGN
::Controller
::StockBarcode
;
7 use Bio
::Chado
::Schema
::Result
::Stock
::Stock
;
8 use CXGN
::Stock
::StockBarcode
;
11 use SGN
::Model
::Cvterm
;
12 use CXGN
::Stock
::Order
;
13 use CXGN
::TrackingActivity
::ActivityProject
;
15 BEGIN { extends
"Catalyst::Controller"; }
19 # sub download_zpl_barcodes : Path('/barcode/stock/download/zpl') :Args(0) {
23 # my $stock_names = $c->req->param("stock_names");
24 # my $stock_names_file = $c->req->upload("stock_names_file");
26 # my $complete_list = $stock_names ."\n".$stock_names_file;
28 # $complete_list =~ s/\r//g;
30 # my @names = split /\n/, $complete_list;
36 # my $schema = $c->dbic_schema('Bio::Chado::Schema');
38 # foreach my $name (@names) {
46 # my $stock = $schema->resultset("Stock::Stock")->find( { name=>$name });
49 # push @not_found, $name;
53 # my $stock_id = $stock->stock_id();
57 # # generate new zdl label
59 # my $label = CXGN::ZPL->new();
60 # $label->start_format();
61 # $label->barcode_code128($c->config->{identifier_prefix}.$stock_id);
62 # $label->end_format();
63 # push @labels, $label;
67 # my $dir = $c->tempfiles_subdir('zpl');
68 # my ($FH, $filename) = $c->tempfile(TEMPLATE=>"zpl/zpl-XXXXX", UNLINK=>0);
70 # foreach my $label (@labels) {
71 # print $FH $label->render();
75 # $c->stash->{not_found} = \@not_found;
76 # $c->stash->{found} = \@found;
77 # $c->stash->{file} = $filename;
78 # $c->stash->{filetype} = "ZPL";
79 # $c->stash->{template} = '/barcode/stock_download_result.mas';
84 sub download_pdf_labels
:Path
('/barcode/stock/download/pdf') :Args
(0) {
87 my $stock_names = $c->req->param("stock_names");
88 my $stock_names_file = $c->req->upload("stock_names_file");
89 my $labels_per_page = $c->req->param("label_rows") || 10;
90 my $labels_per_row = $c->req->param("label_cols") || 1;
91 my $page_format = $c->req->param("page_format") || "letter";
92 my $top_margin_mm = $c->req->param("tops_margin");
93 my $left_margin_mm = $c->req->param("left_margin");
94 my $bottom_margin_mm = $c->req->param("bottom_margin");
95 my $right_margin_mm = $c->req->param("right_margin");
96 my $nursery = $c->req->param("nursery");
97 my $added_text = $c->req->param("text_margin");
98 my $barcode_type = $c->req->param("select_barcode_type");
99 my $fieldbook_barcode = $c->req->param("enable_fieldbook_2d_barcode");
100 my $cass_print_format = $c->req->param("select_print_format");
103 my $sp_person_id = $c->user() ?
$c->user->get_object()->get_sp_person_id() : undef;
104 my $schema = $c->dbic_schema('Bio::Chado::Schema', undef, $sp_person_id);
105 my $plot_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'plot', 'stock_type' )->cvterm_id();
106 my $plot_number_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'plot number', 'stock_property' )->cvterm_id();
107 my $accession_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'accession', 'stock_type' )->cvterm_id();
108 my $plant_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'plant', 'stock_type' )->cvterm_id();
109 my $tissue_sample_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'tissue_sample', 'stock_type')->cvterm_id;
110 my $cross_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'cross', 'stock_type' )->cvterm_id();
111 my $cross_combination_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'cross_combination', 'stock_property' )->cvterm_id();
112 my $xlabel_margin = 8;
113 # convert mm into pixels
114 print STDERR
"MY TOP MARGIN: $top_margin_mm\n";
115 if ($cass_print_format eq 'NCSU') {$left_margin_mm = 10, $top_margin_mm = 12, $bottom_margin_mm = 12, $right_margin_mm = 10, $labels_per_page = 10, $labels_per_row = 3, $barcode_type = "2D", $page_format = "letter"; }
116 if ($cass_print_format eq 'CASS') {$left_margin_mm = 112, $top_margin_mm = 10, $bottom_margin_mm = 13, $right_margin_mm = 10, $barcode_type = "2D", $labels_per_row = 2; }
117 if ($cass_print_format eq 'IITA-3') {$left_margin_mm = 130, $top_margin_mm = 13, $bottom_margin_mm = 11, $right_margin_mm = 10, $labels_per_row = 3, $barcode_type = "2D"; }
118 if ($cass_print_format eq 'IITA-2') {$left_margin_mm = 130, $top_margin_mm = 13, $bottom_margin_mm = 11, $right_margin_mm = 10, $labels_per_row = 2, $barcode_type = "2D"; }
119 if ($cass_print_format eq 'MUSA') {$left_margin_mm = 112, $top_margin_mm = 10, $bottom_margin_mm = 13, $barcode_type = "2D", $labels_per_row = 2; }
120 if ($cass_print_format eq '32A4') {$left_margin_mm = 17, $top_margin_mm = 12, $bottom_margin_mm = 12, $right_margin_mm = 10, $labels_per_page = 8, $labels_per_row = 4, $barcode_type = "2D", $page_format = "letter"; }
121 if ($cass_print_format eq '32_unique') {$left_margin_mm = 17, $top_margin_mm = 12, $bottom_margin_mm = 12, $right_margin_mm = 10, $labels_per_page = 8, $labels_per_row = 4, $barcode_type = "2D", $page_format = "letter"; }
122 if ($cass_print_format eq '20A4') {$left_margin_mm = 10, $top_margin_mm = 12, $bottom_margin_mm = 12, $right_margin_mm = 10, $labels_per_page = 10, $labels_per_row = 2, $barcode_type = "2D", $page_format = "letter"; }
123 if ($cass_print_format eq 'crossing') {$left_margin_mm = 2, $top_margin_mm = 5, $bottom_margin_mm = 0, $right_margin_mm = 0, $labels_per_row = 1, $labels_per_page = 1, $barcode_type = "2D"; }
124 my ($top_margin, $left_margin, $bottom_margin, $right_margin) = map { $_ * 2.846 } (
131 # read file if upload
133 if ($stock_names_file) {
134 my $stock_file_contents = read_file
($stock_names_file->{tempname
});
135 $stock_names = $stock_names ."\n".$stock_file_contents;
138 $stock_names =~ s/\r//g;
139 my @names = split /\n/, $stock_names;
144 my ($row, $stockprop_name, $value, $fdata_block, $fdata_rep, $fdata_plot, $fdata, $accession_id, $accession_name, $parents, $tract_type_id, $label_text_5, $plot_name, $label_text_6, $musa_row_col_number, $label_text_7, $row_col_number, $label_text_8, $fdata_plot_20A4, $fdata_rep_block);
145 my $stock_precheck = $schema->resultset("Stock::Stock")->find( { uniquename
=>$names[0] });
146 my $type_id_precheck = $stock_precheck->type_id();
150 if ($type_id_precheck == $tissue_sample_cvterm_id){
152 my $stock_rs = $schema->resultset("Stock::Stock")->search(
154 uniquename
=> {'-in' => \
@names},
155 'stockprops.type_id' => $plot_number_cvterm_id
158 join => {'stockprops'},
159 '+select' => ['stockprops.value'],
160 '+as' => ['plot_number'],
161 'order_by' => { '-asc' => 'stockprops.value::INT' }
164 while ( my $r = $stock_rs->next()){
165 my $stock_name = $r->uniquename;
166 my $stock_id = $r->stock_id;
167 my $stock_type_id = $r->type_id;
168 my $plot_number = $r->get_column('plot_number');
169 push @stocks_sorted, $stock_name
173 if (scalar(@stocks_sorted) > 0){
174 @names = @stocks_sorted;
177 foreach my $name (@names) {
185 my $stock = $schema->resultset("Stock::Stock")->find( { uniquename
=>$name });
188 push @not_found, $name;
192 my $stock_id = $stock->stock_id();
193 $type_id = $stock->type_id();
195 if ($type_id == $tissue_sample_cvterm_id){
196 $type_id = $accession_cvterm_id;
199 if ($plant_cvterm_id == $type_id){
200 my $dbh = $c->dbc->dbh();
201 my $h = $dbh->prepare("select stock_relationship.subject_id, stock.name from stock join stock_relationship on stock.stock_id=stock_relationship.subject_id where object_id=?;");
203 $h->execute($stock_id);
204 while (my($plot_of_plant_id, $plant_plot_name) = $h->fetchrow_array) {
205 $plot_name = $plant_plot_name;
207 my $dbh = $c->dbc->dbh();
208 my $h = $dbh->prepare("select name, value from cvterm inner join stockprop on cvterm.cvterm_id = stockprop.type_id where stockprop.stock_id=?;");
210 $h->execute($plot_of_plant_id);
213 while (($stockprop_name, $value) = $h->fetchrow_array) {
214 $stockprop_hash{$stock_id}->{$stockprop_name} = $value;
217 $row = $stockprop_hash{$stock_id}->{'replicate'};
218 $fdata = "rep:".$stockprop_hash{$stock_id}->{'replicate'}.' '."blk:".$stockprop_hash{$stock_id}->{'block'}.' '."plot:".$stockprop_hash{$stock_id}->{'plot number'};
219 $fdata_block = "blk:".$stockprop_hash{$stock_id}->{'block'};
220 $fdata_rep = "rep:".$stockprop_hash{$stock_id}->{'replicate'};
221 $fdata_rep_block = "block number:".$stockprop_hash{$stock_id}->{'block'}.', '."rep number:".$stockprop_hash{$stock_id}->{'replicate'};
222 $fdata_plot = "plot:".$stockprop_hash{$stock_id}->{'plot number'};
223 $fdata_plot_20A4 = "plot number:".$stockprop_hash{$stock_id}->{'plot number'};
224 $musa_row_col_number = "row number:".$stockprop_hash{$stock_id}->{'row_number'}.', '."column number:".$stockprop_hash{$stock_id}->{'col_number'};
226 my $h_acc = $dbh->prepare("select stock.uniquename, stock.stock_id FROM stock join stock_relationship on (stock.stock_id = stock_relationship.object_id) where stock_relationship.subject_id =?;");
228 $h_acc->execute($stock_id);
229 ($accession_name, $accession_id) = $h_acc->fetchrow_array;
233 if ($plot_cvterm_id == $type_id){
234 my $dbh = $c->dbc->dbh();
235 my $h = $dbh->prepare("select name, value from cvterm inner join stockprop on cvterm.cvterm_id = stockprop.type_id where stockprop.stock_id=?;");
237 $h->execute($stock_id);
240 while (($stockprop_name, $value) = $h->fetchrow_array) {
241 $stockprop_hash{$stock_id}->{$stockprop_name} = $value;
243 $row = $stockprop_hash{$stock_id}->{'replicate'};
244 $fdata = "rep:".$stockprop_hash{$stock_id}->{'replicate'}.' '."blk:".$stockprop_hash{$stock_id}->{'block'}.' '."plot:".$stockprop_hash{$stock_id}->{'plot number'};
245 $fdata_block = "blk:".$stockprop_hash{$stock_id}->{'block'};
246 $fdata_rep = "rep:".$stockprop_hash{$stock_id}->{'replicate'};
247 $fdata_plot = "plot:".$stockprop_hash{$stock_id}->{'plot number'};
248 $fdata_rep_block = "block number:".$stockprop_hash{$stock_id}->{'block'}.', '."rep number:".$stockprop_hash{$stock_id}->{'replicate'};
249 $fdata_plot_20A4 = "plot number:".$stockprop_hash{$stock_id}->{'plot number'};
250 $musa_row_col_number = "row number:".$stockprop_hash{$stock_id}->{'row_number'}.', '."column number:".$stockprop_hash{$stock_id}->{'col_number'};
251 $row_col_number = "rw/cl:".$stockprop_hash{$stock_id}->{'row_number'}."/".$stockprop_hash{$stock_id}->{'col_number'};
252 my $h_acc = $dbh->prepare("select stock.uniquename, stock.stock_id FROM stock join stock_relationship on (stock.stock_id = stock_relationship.object_id) where stock_relationship.subject_id =? and stock.type_id=?;");
254 $h_acc->execute($stock_id,$accession_cvterm_id);
255 ($accession_name, $accession_id) = $h_acc->fetchrow_array;
256 print STDERR
"Accession name for this plot is $accession_name and id is $accession_id\n";
259 if ($plot_cvterm_id == $type_id) {
260 $tract_type_id = 'plot';
261 $parents = CXGN
::Stock
->new ( schema
=> $schema, stock_id
=> $accession_id )->get_pedigree_string('Parents');
263 elsif ($accession_cvterm_id == $type_id){
264 $tract_type_id = 'accession';
265 $parents = CXGN
::Stock
->new ( schema
=> $schema, stock_id
=> $stock_id )->get_pedigree_string('Parents');
266 my $stock_synonyms = CXGN
::Stock
::Accession
->new({ schema
=> $schema, stock_id
=> $stock_id })->synonyms();
267 $synonym_string = join ',', @
$stock_synonyms;
269 elsif ($plant_cvterm_id == $type_id) {
270 $tract_type_id = 'plant';
271 $parents = CXGN
::Stock
->new ( schema
=> $schema, stock_id
=> $accession_id )->get_pedigree_string('Parents');
273 elsif ($cross_cvterm_id == $type_id){
274 my $dbh = $c->dbc->dbh();
275 $tract_type_id = 'cross';
276 my $h = $dbh->prepare("select value from stockprop where stockprop.stock_id = ? and stockprop.type_id = ? ;");
277 $h->execute($stock_id, $cross_combination_cvterm_id);
278 my @result = $h->fetchrow_array;
279 $synonym_string = $result[0];
282 if ($cass_print_format eq 'crossing'){
283 push @found, [ $stock_id, $name, $accession_name, $fdata, $parents, $tract_type_id, $plot_name, $synonym_string, $musa_row_col_number, $fdata_block, $fdata_rep, $fdata_plot, $row_col_number, $fdata_plot_20A4, $fdata_rep_block];
285 push @found, [ $c->config->{identifier_prefix
}.$stock_id, $name, $accession_name, $fdata, $parents, $tract_type_id, $plot_name, $synonym_string, $musa_row_col_number, $fdata_block, $fdata_rep, $fdata_plot, $row_col_number, $fdata_plot_20A4, $fdata_rep_block];
289 my $dir = $c->tempfiles_subdir('pdfs');
290 my ($FH, $filename) = $c->tempfile(TEMPLATE
=>"pdfs/pdf-XXXXX", SUFFIX
=>".pdf", UNLINK
=>0);
291 print STDERR
"FILENAME: $filename \n\n\n";
292 my $pdf = PDF
::Create
->new(filename
=>$c->path_to($filename),
293 Author
=>$c->config->{project_name
},
295 CreationDate
=> [ localtime ],
299 if (!$page_format) { $page_format = "Letter"; }
300 if (!$labels_per_page) { $labels_per_page = 8; }
302 my $base_page = $pdf->new_page(MediaBox
=>$pdf->get_page_size($page_format));
304 my ($page_width, $page_height) = @
{$pdf->get_page_size($page_format)}[2,3];
306 ## for 10 labels per page
308 if ($cass_print_format eq '32A4'){
310 print STDERR
"LABEL HEIGHT: $label_height\n";
312 elsif ($cass_print_format eq '32_unique'){
314 $labels_per_page = 32;
317 if ($labels_per_page == '10'){
318 $label_height = int( (($page_height - $top_margin - $bottom_margin) / $labels_per_page) + 0.5 );
320 ## for 20 labels per page
321 elsif ($labels_per_page == '20'){
322 $label_height = int( (($page_height - $top_margin - $bottom_margin) / $labels_per_page) - 0.05 );
325 ## for 20 labels per page
326 $label_height = int( ($page_height - $top_margin - $bottom_margin) / $labels_per_page);
331 foreach my $page (1..$self->label_to_page($labels_per_page, scalar(@found))) {
332 print STDERR
"Generating page $page...\n";
333 push @pages, $base_page->new_page();
336 print STDERR
$cass_print_format."\n";
337 my $row_y_label_count = 1;
338 my $labels_on_page = 0;
341 for (my $i=0; $i<@found; $i++) {
342 my $label_count = $i + 1;
343 my $page_nr = $self->label_to_page($labels_per_page, $label_count);
344 my $label_on_page = ($label_count -1) % $labels_per_page;
350 my $plot_text = "accession: ".$found[$i]->[2]." ".$found[$i]->[3];
351 if ($barcode_type eq "1D"){
352 if ($found[$i]->[5] eq 'plot'){
353 #$tempfile = $c->forward('/barcode/barcode_tempfile_jpg', [ $found[$i]->[0], $found[$i]->[2]." ".$found[$i]->[3], 'large', 20 ]);
354 $tempfile = $c->forward('/barcode/barcode_tempfile_jpg', [ $found[$i]->[1], $plot_text, 'large', 20 ]);
356 elsif ($found[$i]->[5] eq 'accession'){
357 $tempfile = $c->forward('/barcode/barcode_tempfile_jpg', [ $found[$i]->[1], $found[$i]->[4], 'large', 20 ]);
359 elsif ($found[$i]->[5] eq 'plant'){
360 $tempfile = $c->forward('/barcode/barcode_tempfile_jpg', [ $found[$i]->[1], $plot_text, 'large', 20 ]);
362 elsif ($found[$i]->[5] eq 'cross'){
363 $tempfile = $c->forward('/barcode/barcode_tempfile_jpg', [ $found[$i]->[1], $found[$i]->[7], 'large', 20 ]);
366 $tempfile = $c->forward('/barcode/barcode_tempfile_jpg', [ $found[$i]->[0], $found[$i]->[1], 'large', 20 ]);
369 elsif ($barcode_type eq "2D") {
371 if ($found[$i]->[5] eq 'plot'){
372 $parents = $found[$i]->[4];
373 if ($cass_print_format eq 'crossing'){
374 $tempfile = $c->forward('/barcode/barcode_qrcode_jpg', [ $found[$i]->[0], $found[$i]->[1], " Accession Name: ".$found[$i]->[2]."\n".$found[$i]->[3]."\n".$found[$i]->[4]."\n".$found[$i]->[8]."\n".$added_text, $fieldbook_barcode, $cass_print_format ]);
377 $tempfile = $c->forward('/barcode/barcode_qrcode_jpg', [ $found[$i]->[0], $found[$i]->[1], $found[$i]->[2]."\n".$found[$i]->[3]."\n".$found[$i]->[4]."\n".$found[$i]->[8]."\n".$added_text, $fieldbook_barcode ]);
380 elsif ($found[$i]->[5] eq 'accession'){
381 if ($found[$i]->[7] eq ''){
382 $found[$i]->[7] = "No synonym(s) available";
384 $found[$i]->[7] = "synonym(s): ".$found[$i]->[7];
386 $parents = $found[$i]->[4];
387 $tempfile = $c->forward('/barcode/barcode_qrcode_jpg', [ $found[$i]->[0], $found[$i]->[1], $found[$i]->[4]."\n".$added_text."\n".$found[$i]->[7], $fieldbook_barcode]);
389 elsif ($found[$i]->[5] eq 'plant'){
390 $parents = $found[$i]->[4];
391 $tempfile = $c->forward('/barcode/barcode_qrcode_jpg', [ $found[$i]->[0], $found[$i]->[1], $found[$i]->[2]."\nplot:".$found[$i]->[6]."\n".$found[$i]->[3]."\n".$found[$i]->[4]."\n".$found[$i]->[8]."\n".$added_text, $fieldbook_barcode ]);
393 elsif ($found[$i]->[5] eq 'cross'){
394 if (defined $found[$i]->[7]){
395 $found[$i]->[7] = "Combination: ".$found[$i]->[7];
397 $tempfile = $c->forward('/barcode/barcode_qrcode_jpg', [ $found[$i]->[0], $found[$i]->[1], $found[$i]->[7], $fieldbook_barcode]);
400 $tempfile = $c->forward('/barcode/barcode_qrcode_jpg', [ $found[$i]->[0], $found[$i]->[1], $added_text, $fieldbook_barcode ]);
405 print STDERR
"$tempfile\n";
406 my $image = $pdf->image($tempfile);
407 #print STDERR "IMAGE: ".Data::Dumper::Dumper($image);
409 # note: pdf coord system zero is lower left corner
411 print "PAGE WIDTH: $page_width\n";
412 my $final_barcode_width = ($page_width - $right_margin - $left_margin) / $labels_per_row;
413 my $scalex = $final_barcode_width / $image->{width
};
414 my $scaley = $label_height / $image->{height
};
416 if ($scalex < $scaley) { $scaley = $scalex; }
417 else { $scalex = $scaley; }
419 my ($year_text, $location_text, $label_boundary);
420 if ($cass_print_format eq 'NCSU'){
421 ($year_text,$location_text) = split ',', $added_text;
422 my $xlabel_margin = 18;
423 $label_boundary = $page_height - ($label_on_page * $label_height) - $top_margin;
424 $ypos = $label_boundary - int( ($label_height - $image->{height
} * $scaley) /2);
425 $final_barcode_width = ($page_width - $right_margin - $left_margin + (2 * $xlabel_margin)) / $labels_per_row;
427 elsif ($cass_print_format eq '32A4'){
428 my $label_height_8_per_page = 90;
429 $label_boundary = $page_height - ($label_on_page * $label_height_8_per_page) - $top_margin;
430 $ypos = $label_boundary - int( ($label_height_8_per_page - $image->{height
} * $scaley) /2);
431 $final_barcode_width = ($page_width - $right_margin - $left_margin + (3 * $xlabel_margin)) / $labels_per_row;
433 elsif ($cass_print_format eq '32_unique'){
434 my $label_height_8_per_page = 90;
435 if ($labels_on_page == 32){
439 if ($row_y_label_count == 1 || $row_y_label_count > $labels_per_row){
440 $label_boundary = $page_height - ($row_count * $label_height_8_per_page) - $top_margin;
441 $ypos = $label_boundary - int( ($label_height_8_per_page - $image->{height
} * $scaley) /2);
444 if ($row_y_label_count > $labels_per_row){
445 $row_y_label_count = 1;
447 print STDERR
$row_y_label_count." ".$row_count." ".$ypos." ".$labels_on_page."\n";
448 $row_y_label_count++;
450 $final_barcode_width = ($page_width - $right_margin - $left_margin + (3 * $xlabel_margin)) / $labels_per_row;
452 elsif ($cass_print_format eq '20A4'){
453 $label_boundary = $page_height - ($label_on_page * $label_height) - $top_margin;
454 $ypos = $label_boundary - int( ($label_height - $image->{height
} * $scaley) /2);
455 $final_barcode_width = ($page_width - $right_margin - $left_margin + (4 * $xlabel_margin)) / $labels_per_row;
457 elsif ($cass_print_format eq 'IITA-3'){
458 $label_boundary = $page_height - ($label_on_page * $label_height) - $top_margin;
459 $ypos = $label_boundary - int( ($label_height - $image->{height
} * $scaley) /2);
460 $final_barcode_width = ($page_width - $right_margin - $left_margin) / ($labels_per_row + 1);
462 elsif ($cass_print_format eq 'IITA-2'){
463 $label_boundary = $page_height - ($label_on_page * $label_height) - $top_margin;
464 $ypos = $label_boundary - int( ($label_height - $image->{height
} * $scaley) /2);
465 $final_barcode_width = ($page_width - $right_margin - $left_margin) / ($labels_per_row + 1.5);
468 $label_boundary = $page_height - ($label_on_page * $label_height) - $top_margin;
469 $ypos = $label_boundary - int( ($label_height - $image->{height
} * $scaley) /2);
472 if ($cass_print_format eq '32A4' || $cass_print_format eq '32_unique' || $cass_print_format eq 'NCSU' || $cass_print_format eq '20A4' || $cass_print_format eq 'crossing'){
475 $pages[$page_nr-1]->line($page_width -100, $label_boundary, $page_width, $label_boundary);
479 # my $lebel_number = scalar($#{$found[$i]});
480 my $font = $pdf->font('BaseFont' => 'Courier-Bold');
481 if ($barcode_type eq "2D" && !$cass_print_format) {
482 foreach my $label_count (1..$labels_per_row) {
483 my $xposition = $left_margin + ($label_count -1) * $final_barcode_width + 20;
484 my $yposition = $ypos -7;
485 my $label_text = $found[$i]->[1];
487 $pages[$page_nr-1]->image(image
=>$image, xpos
=>$left_margin + ($label_count -1) * $final_barcode_width, ypos
=>$ypos, xalign
=>0, yalign
=>2, xscale
=>$scalex, yscale
=>$scaley);
489 if ($labels_per_row == '1' ){
490 my $label_count_15_xter_plot_name = 1-1;
491 my $xposition = $left_margin + ($label_count_15_xter_plot_name) * $final_barcode_width + 80.63;
492 my ($yposition_2, $yposition_3, $yposition_4, $yposition_5);
493 if ($labels_per_page > 15){
494 $yposition_2 = $ypos - 10;
495 $yposition_3 = $ypos - 20;
496 $yposition_4 = $ypos - 30;
497 $yposition_5 = $ypos - 40;
499 $yposition_2 = $ypos - 20;
500 $yposition_3 = $ypos - 30;
501 $yposition_4 = $ypos - 40;
502 $yposition_5 = $ypos - 50;
504 my $plot_pedigree_text;
506 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_2, $label_text);
507 if ($found[$i]->[5] eq 'plot'){
508 $label_text_5 = "accession:".$found[$i]->[2]." ".$found[$i]->[3];
510 $label_text_4 = "No pedigree for ".$found[$i]->[2];
512 $label_text_4 = "pedigree: ".$parents;
515 elsif ($found[$i]->[5] eq 'accession'){
517 $label_text_4 = "No pedigree for ".$found[$i]->[1];
519 $label_text_4 = "pedigree: ".$parents;
521 $label_text_5 = $found[$i]->[7];
523 elsif ($found[$i]->[5] eq 'plant'){
524 $label_text_6 = "plot:".$found[$i]->[6];
525 $label_text_5 = "accession:".$found[$i]->[2]." ".$found[$i]->[3];
527 $label_text_4 = "No pedigree for ".$found[$i]->[2];
529 $label_text_4 = "pedigree: ".$parents;
532 elsif ($found[$i]->[5] eq 'cross'){
533 $label_text_5 = $found[$i]->[7];
539 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $label_text_4);
540 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $label_text_6);
541 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $label_text_5);
543 elsif ($labels_per_row > '1'){
544 if (length($label_text) <= 15){
545 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition, $label_text);
550 if ($labels_per_row > '1'){
551 my $label_text = $found[$i]->[1];
552 if (length($label_text) > 15) {
553 my $label_count_15_xter_plot_name = 1-1;
554 my $xposition = $left_margin + ($label_count_15_xter_plot_name) * $final_barcode_width + 20;
555 my $yposition = $ypos -7;
557 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition, $label_text);
562 elsif ($cass_print_format eq 'CASS' && $barcode_type eq "2D") {
564 foreach my $label_count (1..$labels_per_row) {
565 my $label_text = $found[$i]->[1];
567 my $xpos = ($left_margin + ($label_count -1) * $final_barcode_width) + 85;
568 my $label_count_15_xter_plot_name = 1-1;
569 my $xposition = $left_margin + ($label_count_15_xter_plot_name) * $final_barcode_width - 95.63;
570 my ($yposition_2, $yposition_3, $yposition_4, $yposition_5);
571 if ($labels_per_page > 15){
572 $yposition_2 = $ypos - 10;
573 $yposition_3 = $ypos - 20;
574 $yposition_4 = $ypos - 30;
575 $yposition_5 = $ypos - 40;
577 $yposition_2 = $ypos - 20;
578 $yposition_3 = $ypos - 30;
579 $yposition_4 = $ypos - 40;
580 $yposition_5 = $ypos - 50;
582 my $plot_pedigree_text;
584 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_2, $label_text);
585 if ($found[$i]->[5] eq 'plot'){
586 $label_text_5 = "stock:".$found[$i]->[2]." ".$found[$i]->[3];
588 $label_text_4 = "No pedigree for ".$found[$i]->[2];
590 $label_text_4 = "pedigree: ".$parents;
593 elsif ($found[$i]->[5] eq 'accession'){
595 $label_text_4 = "No pedigree for ".$found[$i]->[1];
597 $label_text_4 = "pedigree: ".$parents;
599 $label_text_5 = $found[$i]->[7];
601 elsif ($found[$i]->[5] eq 'plant'){
602 $label_text_6 = "plot:".$found[$i]->[6];
603 $label_text_5 = "accession:".$found[$i]->[2]." ".$found[$i]->[3];
605 $label_text_4 = "No pedigree for ".$found[$i]->[2];
607 $label_text_4 = "pedigree: ".$parents;
610 elsif ($found[$i]->[5] eq 'cross'){
611 $label_text_5 = $found[$i]->[7];
616 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $label_text_4);
617 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $label_text_5);
618 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $label_text_6);
619 $pages[$page_nr-1]->image(image
=>$image, xpos
=>$xpos, ypos
=>$ypos, xalign
=>0, yalign
=>2, xscale
=>$scalex, yscale
=>$scaley);
623 elsif ($cass_print_format eq 'IITA-3' && $barcode_type eq "2D") {
625 foreach my $label_count (1..$labels_per_row) {
626 my $label_text = $found[$i]->[1];
628 my $xpos = ($left_margin + ($label_count -1) * $final_barcode_width) + 80;
629 my $label_count_15_xter_plot_name = 1-1;
630 my $xposition = $left_margin + ($label_count_15_xter_plot_name) * $final_barcode_width - 95.63;
631 my ($yposition_2, $yposition_3, $yposition_4, $yposition_5);
632 if ($labels_per_page > 15){
633 $yposition_2 = $ypos - 10;
634 $yposition_3 = $ypos - 20;
635 $yposition_4 = $ypos - 30;
636 $yposition_5 = $ypos - 40;
638 $yposition_2 = $ypos - 20;
639 $yposition_3 = $ypos - 30;
640 $yposition_4 = $ypos - 40;
641 $yposition_5 = $ypos - 50;
643 my $plot_pedigree_text;
645 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_2, $label_text);
646 if ($found[$i]->[5] eq 'plot'){
647 $label_text_5 = "stock:".$found[$i]->[2]." ".$found[$i]->[3];
649 $label_text_4 = "No pedigree for ".$found[$i]->[2];
651 $label_text_4 = $parents;
654 elsif ($found[$i]->[5] eq 'accession'){
656 $label_text_4 = "No pedigree for ".$found[$i]->[1];
658 $label_text_4 = $parents;
660 $label_text_5 = $found[$i]->[7];
662 elsif ($found[$i]->[5] eq 'plant'){
663 $label_text_6 = "plot:".$found[$i]->[6];
664 $label_text_5 = "accession:".$found[$i]->[2]." ".$found[$i]->[3];
666 $label_text_4 = "No pedigree for ".$found[$i]->[2];
668 $label_text_4 = $parents;
671 elsif ($found[$i]->[5] eq 'cross'){
672 $label_text_5 = $found[$i]->[7];
677 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $label_text_4);
678 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $label_text_5);
679 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $label_text_6);
680 $pages[$page_nr-1]->image(image
=>$image, xpos
=>$xpos, ypos
=>$ypos, xalign
=>0, yalign
=>2, xscale
=>$scalex, yscale
=>$scaley);
684 elsif ($cass_print_format eq 'IITA-2' && $barcode_type eq "2D") {
686 foreach my $label_count (1..$labels_per_row) {
687 my $label_text = $found[$i]->[1];
689 my $xpos = ($left_margin + ($label_count -1) * $final_barcode_width) + 80;
690 my $label_count_15_xter_plot_name = 1-1;
691 my $xposition = $left_margin + ($label_count_15_xter_plot_name) * $final_barcode_width - 95.63;
692 my ($yposition_2, $yposition_3, $yposition_4, $yposition_5);
693 if ($labels_per_page > 15){
694 $yposition_2 = $ypos - 10;
695 $yposition_3 = $ypos - 20;
696 $yposition_4 = $ypos - 30;
697 $yposition_5 = $ypos - 40;
699 $yposition_2 = $ypos - 20;
700 $yposition_3 = $ypos - 30;
701 $yposition_4 = $ypos - 40;
702 $yposition_5 = $ypos - 50;
704 my $plot_pedigree_text;
706 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_2, $label_text);
707 if ($found[$i]->[5] eq 'plot'){
708 $label_text_5 = "stock:".$found[$i]->[2]." ".$found[$i]->[3];
710 $label_text_4 = "No pedigree for ".$found[$i]->[2];
712 $label_text_4 = $parents;
715 elsif ($found[$i]->[5] eq 'accession'){
717 $label_text_4 = "No pedigree for ".$found[$i]->[1];
719 $label_text_4 = $parents;
721 $label_text_5 = $found[$i]->[7];
723 elsif ($found[$i]->[5] eq 'plant'){
724 $label_text_6 = "plot:".$found[$i]->[6];
725 $label_text_5 = "accession:".$found[$i]->[2]." ".$found[$i]->[3];
727 $label_text_4 = "No pedigree for ".$found[$i]->[2];
729 $label_text_4 = $parents;
732 elsif ($found[$i]->[5] eq 'cross'){
733 $label_text_5 = $found[$i]->[7];
738 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $label_text_4);
739 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $label_text_5);
740 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $label_text_6);
741 $pages[$page_nr-1]->image(image
=>$image, xpos
=>$xpos + 60, ypos
=>$ypos, xalign
=>0, yalign
=>2, xscale
=>$scalex, yscale
=>$scaley);
745 elsif ($cass_print_format eq 'NCSU' && $barcode_type eq "2D") {
746 foreach my $label_count (1..$labels_per_row) {
747 my $xposition = $left_margin + ($label_count -1) * $final_barcode_width;
748 my $yposition = $ypos -7;
749 my $label_text = $found[$i]->[1];
751 my $label_size_stock = 12;
752 my $yposition_8 = $ypos + 2;
753 my $yposition_2 = $ypos - 10;
754 my $yposition_3 = $ypos - 20;
755 my $yposition_4 = $ypos - 30;
756 my $yposition_5 = $ypos - 40;
757 my $yposition_6 = $ypos - 50;
758 my $yposition_7 = $ypos - 60;
759 if ($found[$i]->[5] eq 'accession'){
760 $label_text_6 = $found[$i]->[1];
761 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $parents);
762 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $year_text);
763 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $location_text);
765 $label_text_6 = $found[$i]->[2];
766 $label_text_5 = $found[$i]->[11];
767 $label_text_4 = $found[$i]->[10];
768 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $year_text);
769 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $label_text_4);
770 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $label_text_5);
771 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_6, $location_text);
772 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_7, $parents);
774 $pages[$page_nr-1]->string($font, $label_size_stock, $xposition, $yposition_2, $label_text_6);
775 $pages[$page_nr-1]->image(image
=>$image, xpos
=>$left_margin + 90 + ($label_count -1) * $final_barcode_width, ypos
=>$ypos, xalign
=>0, yalign
=>2, xscale
=>$scalex, yscale
=>$scaley);
779 elsif ($cass_print_format eq '32A4' && $barcode_type eq "2D") {
780 foreach my $label_count (1..$labels_per_row) {
781 my $xposition = $left_margin + ($label_count -1) * $final_barcode_width;
782 my $yposition = $ypos -7;
783 my $label_text = $found[$i]->[1];
784 if ($found[$i]->[5] eq 'plot'){
785 $label_text = $found[$i]->[2];
788 my $label_size_stock = 10;
789 my $yposition_8 = $ypos + 2;
790 my $yposition_2 = $ypos - 10;
791 my $yposition_3 = $ypos - 20;
792 my $yposition_4 = $ypos - 30;
793 my $yposition_5 = $ypos - 40;
794 my $yposition_6 = $ypos - 50;
795 my $yposition_7 = $ypos - 60;
796 $label_text_6 = $found[$i]->[2];
797 $label_text_5 = $found[$i]->[11];
798 $label_text_4 = $found[$i]->[12];
799 $label_text_8 = $found[$i]->[10];
800 $pages[$page_nr-1]->string($font, $label_size_stock, $xposition, $yposition_8, $label_text);
801 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $label_text_8);
802 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $label_text_4);
803 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_2, $label_text_5);
804 if ($found[$i]->[5] eq 'accession'){
805 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_6, $parents);
807 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_6, $parents);
808 #$pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_7, $parents);
809 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $added_text);
812 if ($found[$i]->[5] eq 'accession'){
813 $pages[$page_nr-1]->image(image
=>$image, xpos
=>$left_margin + 20 + ($label_count -1) * $final_barcode_width, ypos
=>$ypos, xalign
=>0, yalign
=>2, xscale
=>$scalex, yscale
=>$scaley);
815 $pages[$page_nr-1]->image(image
=>$image, xpos
=>$left_margin + 50 + ($label_count -1) * $final_barcode_width, ypos
=>$ypos, xalign
=>0, yalign
=>2, xscale
=>$scalex, yscale
=>$scaley);
821 elsif ($cass_print_format eq '32_unique' && $barcode_type eq "2D") {
822 my $xposition = $left_margin + ($row_y_label_count -2) * $final_barcode_width;
823 my $yposition = $ypos -7;
824 my $label_text = $found[$i]->[1];
825 if ($found[$i]->[5] eq 'plot'){
826 $label_text = $found[$i]->[2];
829 my $label_size_stock = 10;
830 my $yposition_8 = $ypos + 2;
831 my $yposition_2 = $ypos - 10;
832 my $yposition_3 = $ypos - 20;
833 my $yposition_4 = $ypos - 30;
834 my $yposition_5 = $ypos - 40;
835 my $yposition_6 = $ypos - 50;
836 my $yposition_7 = $ypos - 60;
837 $label_text_6 = $found[$i]->[2];
838 $label_text_5 = $found[$i]->[11];
839 $label_text_4 = $found[$i]->[12];
840 $label_text_8 = $found[$i]->[10];
841 $pages[$page_nr-1]->string($font, $label_size_stock, $xposition, $yposition_8, $label_text);
842 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $label_text_8);
843 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $label_text_4);
844 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_2, $label_text_5);
845 if ($found[$i]->[5] eq 'accession'){
846 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_6, $parents);
848 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_6, $parents);
849 #$pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_7, $parents);
850 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $added_text);
853 if ($found[$i]->[5] eq 'accession'){
854 $pages[$page_nr-1]->image(image
=>$image, xpos
=>$left_margin + 20 + ($row_y_label_count -2) * $final_barcode_width, ypos
=>$ypos, xalign
=>0, yalign
=>2, xscale
=>$scalex, yscale
=>$scaley);
856 $pages[$page_nr-1]->image(image
=>$image, xpos
=>$left_margin + 50 + ($row_y_label_count -2) * $final_barcode_width, ypos
=>$ypos, xalign
=>0, yalign
=>2, xscale
=>$scalex, yscale
=>$scaley);
860 elsif ($cass_print_format eq '20A4' && $barcode_type eq "2D") {
861 foreach my $label_count (1..$labels_per_row) {
862 my $xposition = $left_margin + ($label_count -1) * $final_barcode_width;
863 my $yposition = $ypos -7;
864 my $label_text = $found[$i]->[1];
866 my $label_size_stock = 10;
867 my $yposition_2 = $ypos - 10;
868 my $yposition_3 = $ypos - 20;
869 my $yposition_4 = $ypos - 30;
870 my $yposition_5 = $ypos - 40;
871 my $yposition_6 = $ypos - 50;
872 my $yposition_7 = $ypos - 60;
873 my $yposition_8 = $ypos - 70;
874 if ($found[$i]->[5] eq 'accession'){}
876 $label_text_6 = "accession: ".$found[$i]->[2];
878 my $parents_20A4 = "pedigree: ".$parents;
879 $label_text_5 = $found[$i]->[14];
880 $label_text_4 = $found[$i]->[8];
881 $label_text_8 = $found[$i]->[13];
882 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_2, $label_text);
883 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $label_text_6);
884 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $label_text_5);
885 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $label_text_4);
886 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_6, $label_text_8);
887 if ($found[$i]->[5] eq 'accession'){
888 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $parents_20A4);
889 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $added_text);
891 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_7, $parents_20A4);
892 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_8, $added_text);
894 $pages[$page_nr-1]->image(image
=>$image, xpos
=>$left_margin + 200 + ($label_count -1) * $final_barcode_width, ypos
=>$ypos, xalign
=>0, yalign
=>2, xscale
=>$scalex, yscale
=>$scaley);
898 elsif ($cass_print_format eq 'crossing' && $barcode_type eq "2D") {
899 foreach my $label_count (1..$labels_per_row) {
900 my $xposition = $left_margin + ($label_count -1) * $final_barcode_width + 20;
901 my $yposition = $ypos -7;
902 my $label_text = $found[$i]->[1];
904 $pages[$page_nr-1]->image(image
=>$image, xpos
=>$left_margin + ($label_count -1) * $final_barcode_width, ypos
=>$ypos, xalign
=>0, yalign
=>2, xscale
=>$scalex, yscale
=>$scaley);
905 $pages[$page_nr-1]->string($font, $label_size, $xposition + 30, $yposition - 595, $label_text);
910 elsif ($cass_print_format eq 'MUSA' && $barcode_type eq "2D") {
912 foreach my $label_count (1..$labels_per_row) {
913 my $label_text = $found[$i]->[1];
915 my $xpos = ($left_margin + ($label_count -1) * $final_barcode_width) + 85;
916 my $label_count_15_xter_plot_name = 1-1;
917 my $xposition = $left_margin + ($label_count_15_xter_plot_name) * $final_barcode_width - 95.63;
918 my ($yposition_2, $yposition_3, $yposition_4, $yposition_5, $yposition_6);
919 if ($labels_per_page > 15){
920 $yposition_2 = $ypos - 10;
921 $yposition_3 = $ypos - 20;
922 $yposition_4 = $ypos - 30;
923 $yposition_5 = $ypos - 40;
924 $yposition_6 = $ypos - 50;
926 $yposition_2 = $ypos - 20;
927 $yposition_3 = $ypos - 30;
928 $yposition_4 = $ypos - 40;
929 $yposition_5 = $ypos - 50;
930 $yposition_6 = $ypos - 60;
932 my $plot_pedigree_text;
934 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_2, $label_text);
935 if ($found[$i]->[5] eq 'plot'){
936 $label_text_5 = "stock:".$found[$i]->[2]." ".$found[$i]->[3];
937 $label_text_6 = $found[$i]->[8];
939 $label_text_4 = "No pedigree for ".$found[$i]->[2];
941 $label_text_4 = "pedigree: ".$parents;
944 elsif ($found[$i]->[5] eq 'accession'){
946 $label_text_4 = "No pedigree for ".$found[$i]->[1];
948 $label_text_4 = "pedigree: ".$parents;
950 $label_text_5 = $found[$i]->[7];
952 elsif ($found[$i]->[5] eq 'plant'){
953 print "I HAVE ROW AND COL: $found[$i]->[8]\n";
954 $label_text_6 = "plot:".$found[$i]->[6];
955 $label_text_5 = "accession:".$found[$i]->[2]." ".$found[$i]->[3];
956 $label_text_7 = $found[$i]->[8];
958 $label_text_4 = "No pedigree for ".$found[$i]->[2];
960 $label_text_4 = "pedigree: ".$parents;
963 elsif ($found[$i]->[5] eq 'cross'){
964 $label_text_5 = $found[$i]->[7];
969 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $label_text_4);
970 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $label_text_5);
971 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $label_text_6);
972 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_6, $label_text_7);
973 $pages[$page_nr-1]->image(image
=>$image, xpos
=>$xpos, ypos
=>$ypos, xalign
=>0, yalign
=>2, xscale
=>$scalex, yscale
=>$scaley);
977 elsif ($barcode_type eq "1D") {
979 foreach my $label_count (1..$labels_per_row) {
981 $pages[$page_nr-1]->image(image
=>$image, xpos
=>$left_margin + ($label_count -1) * $final_barcode_width, ypos
=>$ypos, xalign
=>0, yalign
=>2, xscale
=>$scalex, yscale
=>$scaley);
988 $c->stash->{not_found
} = \
@not_found;
989 $c->stash->{found
} = \
@found;
990 $c->stash->{file
} = $filename;
991 $c->stash->{filetype
} = 'PDF';
992 $c->stash->{template
} = '/barcode/stock_download_result.mas';
995 # plot phenotyping barcode
996 sub download_qrcode
: Path
('/barcode/stock/download/plot_QRcode') : Args
(0) {
1000 my $stock_names = $c->req->param("stock_names_2");
1001 my $stock_names_file = $c->req->upload("stock_names_file_2");
1002 my $added_text = $c->req->param("select_barcode_text");
1003 my $labels_per_page = 7;
1004 my $page_format = "letter";
1005 my $labels_per_row = 1;
1006 my $top_margin_mm = 12;
1007 my $left_margin_mm = 70;
1008 my $bottom_margin_mm = 12;
1009 my $right_margin_mm = 20;
1010 my $sp_person_id = $c->user() ?
$c->user->get_object()->get_sp_person_id() : undef;
1011 my $schema = $c->dbic_schema('Bio::Chado::Schema', undef, $sp_person_id);
1012 my $accession_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'accession', 'stock_type' )->cvterm_id();
1013 my $plot_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'plot', 'stock_type' )->cvterm_id();
1014 # convert mm into pixels
1016 my ($top_margin, $left_margin, $bottom_margin, $right_margin) = map { $_ * 2.846 } ($top_margin_mm,
1021 # read file if upload
1023 if ($stock_names_file) {
1024 my $stock_file_contents = read_file
($stock_names_file->{tempname
});
1025 $stock_names = $stock_names ."\n".$stock_file_contents;
1028 $stock_names =~ s/\r//g;
1029 my @names = split /\n/, $stock_names;
1034 my ($row, $stockprop_name, $value, $fdata, $accession_id, $accession_name, $parents);
1036 foreach my $name (@names) {
1044 my $stock = $schema->resultset("Stock::Stock")->find( { name
=>$name });
1047 push @not_found, $name;
1051 my $stock_id = $stock->stock_id();
1052 my $type_id = $stock->type_id();
1053 if ($type_id == $accession_cvterm_id) {
1054 print "You are using accessions\n";
1055 my $error = "used only for downloading Plot barcodes.";
1056 $c->stash->{error
} = $error;
1057 $c->stash->{template
} = '/barcode/stock_download_result.mas';
1061 my $dbh = $c->dbc->dbh();
1062 my $h = $dbh->prepare("select name, value from cvterm inner join stockprop on cvterm.cvterm_id = stockprop.type_id where stockprop.stock_id=?;");
1063 $h->execute($stock_id);
1065 while (($stockprop_name, $value) = $h->fetchrow_array) {
1066 $stockprop_hash{$stock_id}->{$stockprop_name} = $value;
1068 $row = $stockprop_hash{$stock_id}->{'replicate'};
1069 $fdata = "rep:".$stockprop_hash{$stock_id}->{'replicate'}.' '."block:".$stockprop_hash{$stock_id}->{'block'}.' '."plot:".$stockprop_hash{$stock_id}->{'plot number'};
1071 my $h_acc = $dbh->prepare("select stock.uniquename, stock.stock_id FROM stock join stock_relationship on (stock.stock_id = stock_relationship.object_id) where stock.type_id=? and stock_relationship.subject_id =?;");
1073 $h_acc->execute($accession_cvterm_id,$stock_id);
1074 ($accession_name, $accession_id) = $h_acc->fetchrow_array;
1076 $parents = CXGN
::Stock
->new ( schema
=> $schema, stock_id
=> $accession_id )->get_pedigree_string('Parents');
1078 push @found, [ $stock_id, $name, $accession_name, $fdata, $parents];
1081 my $dir = $c->tempfiles_subdir('pdfs');
1082 my ($FH, $filename) = $c->tempfile(TEMPLATE
=>"pdfs/pdf-XXXXX", SUFFIX
=>".pdf", UNLINK
=>0);
1083 print STDERR
"FILENAME: $filename \n\n\n";
1084 my $pdf = PDF
::Create
->new(filename
=>$c->path_to($filename),
1085 Author
=>$c->config->{project_name
},
1087 CreationDate
=> [ localtime ],
1091 my $base_page = $pdf->new_page(MediaBox
=>$pdf->get_page_size($page_format));
1093 my ($page_width, $page_height) = @
{$pdf->get_page_size($page_format)}[2,3];
1095 my $label_height = int( ($page_height - $top_margin - $bottom_margin) / $labels_per_page);
1098 foreach my $page (1..$self->label_to_page($labels_per_page, scalar(@found))) {
1099 print STDERR
"Generating page $page...\n";
1100 push @pages, $base_page->new_page();
1103 for (my $i=0; $i<@found; $i++) {
1104 my $label_count = $i + 1;
1105 my $page_nr = $self->label_to_page($labels_per_page, $label_count);
1106 my $label_on_page = ($label_count -1) % $labels_per_page;
1111 if ($parents =~ /NA\/NA
/) {
1112 $tempfile = $c->forward('/barcode/phenotyping_qrcode_jpg', [ $found[$i]->[0], $found[$i]->[1], $found[$i]->[2]." ".$found[$i]->[3]." ".$added_text ]);
1115 $tempfile = $c->forward('/barcode/phenotyping_qrcode_jpg', [ $found[$i]->[0], $found[$i]->[1], $found[$i]->[2]." ".$found[$i]->[3]." ".$found[$i]->[4]." ".$added_text]);
1118 print STDERR
"$tempfile\n";
1119 my $image = $pdf->image($tempfile);
1120 print STDERR
"IMAGE: ".Data
::Dumper
::Dumper
($image);
1122 # note: pdf coord system zero is lower left corner
1124 my $final_barcode_width = ($page_width - $right_margin - $left_margin) / $labels_per_row;
1126 my $scalex = $final_barcode_width / $image->{width
};
1127 my $scaley = $label_height / $image->{height
};
1129 if ($scalex < $scaley) { $scaley = $scalex; }
1130 else { $scalex = $scaley; }
1132 my $label_boundary = $page_height - ($label_on_page * $label_height) - $top_margin;
1134 my $ypos = $label_boundary - int( ($label_height - $image->{height
} * $scaley) /2);
1136 $pages[$page_nr-1]->line($page_width -100, $label_boundary, $page_width, $label_boundary);
1138 my $font = $pdf->font('BaseFont' => 'Times-Roman');
1139 foreach my $label_count (1..$labels_per_row) {
1140 $pages[$page_nr-1]->image(image
=>$image, xpos
=>$left_margin + ($label_count -1) * $final_barcode_width, ypos
=>$ypos, xalign
=>0, yalign
=>2, xscale
=>$scalex, yscale
=>$scaley);
1143 my $label_text = $found[$i]->[1];
1144 my $label_text_2 = "Accession: ".$found[$i]->[2];
1145 my $label_text_3 = $found[$i]->[3];
1146 my $label_text_4 = "Pedigree: ".$found[$i]->[4];
1148 my $label_count_15_xter_plot_name = 1-1;
1149 my $xposition = $left_margin + ($label_count_15_xter_plot_name) * $final_barcode_width + 118.63;
1150 my $yposition = $ypos - 30;
1151 my $yposition_2 = $ypos - 40;
1152 my $yposition_3 = $ypos - 50;
1153 my $yposition_4 = $ypos - 60;
1154 my $yposition_5 = $ypos - 70;
1155 print "My X Position: $xposition and Y Position: $ypos\n";
1156 my $label_size = 11;
1157 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition, $label_text);
1158 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_2, $label_text_2);
1159 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $label_text_3);
1160 if ($found[$i]->[4] =~ m/^\//){
1161 $label_text_4 = "Pedigree: No pedigree available for ".$found[$i]->[2];
1163 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $label_text_4);
1164 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $added_text);
1169 $c->stash->{not_found
} = \
@not_found;
1170 $c->stash->{found
} = \
@found;
1171 $c->stash->{file
} = $filename;
1172 $c->stash->{filetype
} = 'PDF';
1173 $c->stash->{template
} = '/barcode/stock_download_result.mas';
1178 =head2 download_trial_qrcode
1180 URL: mapped to URL /barcode/trial/download/trial_QRcode
1181 Params: project_name or project_name_file: trial names to generate barcodes for
1182 Desc: creates the barcode image, create a pdf file, returns the created
1183 barcodes on a downloadable pdf file.
1190 # Generate Trial barcode
1191 sub download_trial_qrcode
: Path
('/barcode/trial/download/trial_QRcode') : Args
(0) {
1194 my $project_names = $c->req->param("trial_names_2");
1195 my $project_names_file = $c->req->upload("trial_names_file_2");
1196 my $labels_per_page = 64;
1197 my $page_format = "letter";
1198 my $labels_per_row = 4;
1199 my $top_margin_mm = 12;
1200 my $left_margin_mm = 10;
1201 my $bottom_margin_mm = 12;
1202 my $right_margin_mm = 10;
1203 my $barcode_type = "trial";
1204 my $sp_person_id = $c->user() ?
$c->user->get_object()->get_sp_person_id() : undef;
1205 my $schema = $c->dbic_schema('Bio::Chado::Schema', undef, $sp_person_id);
1207 # convert mm into pixels
1209 my ($top_margin, $left_margin, $bottom_margin, $right_margin) = map { $_ * 2.846 } ($top_margin_mm,
1214 # read file if upload
1216 if ($project_names_file) {
1217 my $project_file_contents = read_file
($project_names_file->{tempname
});
1218 $project_names = $project_names ."\n".$project_file_contents;
1221 $project_names =~ s/\r//g;
1222 my @names = split /\n/, $project_names;
1228 foreach my $name (@names) {
1236 my $project = $schema->resultset("Project::Project")->find( { name
=>$name });
1239 push @not_found, $name;
1242 my $project_id = $project->project_id();
1243 push @found, [ $project_id, $name];
1246 my $dir = $c->tempfiles_subdir('pdfs');
1247 my ($FH, $filename) = $c->tempfile(TEMPLATE
=>"pdfs/pdf-XXXXX", SUFFIX
=>".pdf", UNLINK
=>0);
1248 print STDERR
"FILENAME: $filename \n\n\n";
1249 my $pdf = PDF
::Create
->new(filename
=>$c->path_to($filename),
1250 Author
=>$c->config->{project_name
},
1252 CreationDate
=> [ localtime ],
1256 my $base_page = $pdf->new_page(MediaBox
=>$pdf->get_page_size($page_format));
1258 my ($page_width, $page_height) = @
{$pdf->get_page_size($page_format)}[2,3];
1259 my $label_height = 40;
1262 foreach my $page (1..$self->label_to_page($labels_per_page, scalar(@found))) {
1263 print STDERR
"Generating page $page...\n";
1264 push @pages, $base_page->new_page();
1267 my $row_y_label_count = 1;
1268 my $labels_on_page = 0;
1271 for (my $i=0; $i<@found; $i++) {
1272 my $label_count = $i + 1;
1273 my $page_nr = $self->label_to_page($labels_per_page, $label_count);
1274 my $label_on_page = ($label_count -1) % $labels_per_page;
1279 $tempfile = $c->forward('/barcode/phenotyping_qrcode_jpg', [ $found[$i]->[0], $found[$i]->[1], $barcode_type] );
1281 print STDERR
"$tempfile\n";
1282 my $image = $pdf->image($tempfile);
1283 print STDERR
"IMAGE: ".Data
::Dumper
::Dumper
($image);
1285 # note: pdf coord system zero is lower left corner
1287 my $xlabel_margin = 3.5;
1288 my $final_barcode_width = ($page_width - $right_margin - $left_margin + (3 * $xlabel_margin)) / $labels_per_row;
1290 my $scalex = $final_barcode_width / $image->{width
};
1291 my $scaley = $label_height / $image->{height
};
1293 if ($scalex < $scaley) { $scaley = $scalex; }
1294 else { $scalex = $scaley; }
1297 my $label_height_16_per_page = 45;
1298 my $custom_label_height = 90;
1299 if ($labels_on_page == 64){
1301 $labels_on_page = 0;
1303 if ($row_y_label_count == 1 || $row_y_label_count > $labels_per_row){
1304 $label_boundary = $page_height - ($row_count * $label_height_16_per_page) - $top_margin;
1305 $ypos = $label_boundary - int( ($custom_label_height - $image->{height
} * $scaley) /2);
1308 if ($row_y_label_count > $labels_per_row){
1309 $row_y_label_count = 1;
1311 print STDERR
$row_y_label_count." ".$row_count." ".$ypos." ".$labels_on_page."\n";
1312 $row_y_label_count++;
1315 my $font = $pdf->font('BaseFont' => 'Times-Roman');
1316 my $label_text = $found[$i]->[1];
1317 my $label_size = 10;
1318 my $xposition = $left_margin + 5 + ($row_y_label_count -2) * $final_barcode_width;
1319 my $yposition = $ypos;
1321 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition, $label_text);
1322 $pages[$page_nr-1]->image(image
=>$image, xpos
=>$left_margin + 89 + ($row_y_label_count -2) * $final_barcode_width, ypos
=>$ypos + 20.5, xalign
=>0, yalign
=>2, xscale
=>$scalex, yscale
=>$scaley);
1327 $c->stash->{not_found
} = \
@not_found;
1328 $c->stash->{found
} = \
@found;
1329 $c->stash->{file
} = $filename;
1330 $c->stash->{filetype
} = 'PDF';
1331 $c->stash->{template
} = '/barcode/stock_download_result.mas';
1335 # maps the label number to a page number
1338 my $labels_per_page = shift;
1339 my $label_count = shift;
1341 my $page_count = int( ($label_count -1) / $labels_per_page) +1;
1345 sub upload_barcode_output
: Path
('/breeders/phenotype/upload') :Args
(0) {
1346 my ($self, $c) = @_;
1347 my $upload = $c->req->upload('phenotype_file');
1348 my @contents = split /\n/, $upload->slurp;
1349 my $basename = $upload->basename;
1350 my $tempfile = $upload->tempname; #create a tempfile with the uploaded file
1351 if (! -e
$tempfile) {
1352 die "The file does not exist!\n\n";
1354 print STDERR
"***Basename= $basename, tempfile = $tempfile \n\n"; ##OK
1355 my $archive_path = $c->config->{archive_path
};
1357 $tempfile = $archive_path . "/" . $basename ;
1358 print STDERR
"**tempfile = $tempfile \n\n"; ##OK
1359 #chack for write permissions in $archive_path !
1360 my $upload_success = $upload->copy_to($archive_path . "/" . $basename); #returns false for failure, true for success
1361 if (!$upload_success) { die "Could not upload!\n $upload_success" ; }
1362 my $sp_person_id = $c->user() ?
$c->user->get_object()->get_sp_person_id() : undef;
1363 my $sb = CXGN
::Stock
::StockBarcode
->new( { schema
=> $c->dbic_schema("Bio::Chado::Schema", 'sgn_chado', $sp_person_id) });
1364 my $identifier_prefix = $c->config->{identifier_prefix
};
1365 my $db_name = $c->config->{trait_ontology_db_name
};
1367 $sb->parse(\
@contents, $identifier_prefix, $db_name);
1368 my $parse_errors = $sb->parse_errors;
1369 $sb->verify; #calling the verify function
1370 my $verify_errors = $sb->verify_errors;
1371 my @errors = (@
$parse_errors, @
$verify_errors);
1372 my $warnings = $sb->warnings;
1373 $c->stash->{tempfile
} = $tempfile;
1375 template
=> '/stock/barcode/upload_confirm.mas',
1376 tempfile
=> $tempfile,
1378 warnings
=> $warnings,
1379 feedback_email
=> $c->config->{feedback_email
},
1384 sub store_barcode_output
: Path
('/barcode/stock/store') :Args
(0) {
1385 my ($self, $c) = @_;
1386 my $filename = $c->req->param('tempfile');
1388 my @contents = read_file
($filename);
1390 my $sp_person_id = $c->user() ?
$c->user->get_object()->get_sp_person_id() : undef;
1391 my $sb = CXGN
::Stock
::StockBarcode
->new( { schema
=> $c->dbic_schema("Bio::Chado::Schema", 'sgn_chado', $sp_person_id) });
1392 my $identifier_prefix = $c->config->{identifier_prefix
};
1393 my $db_name = $c->config->{trait_ontology_db_name
};
1394 $sb->parse(\
@contents, $identifier_prefix, $db_name);
1396 my $error = $sb->store_error;
1397 my $message = $sb->store_message;
1399 template
=> '/stock/barcode/confirm_store.mas',
1401 message
=> $message,
1406 sub download_identifier_labels
:Path
('/barcode/identifier/download/pdf') :Args
(0) {
1407 my ($self, $c) = @_;
1409 my $item_names = $c->req->param("identifier_names");
1410 my $order_id = $c->req->param("order_id");
1411 my $trial_id = $c->req->param("trial_id");
1412 my $user_id = $c->req->param("user_id");
1413 my $labels_per_page = $c->req->param("label_rows") || 10;
1414 my $labels_per_row = $c->req->param("label_cols") || 1;
1415 my $page_format = $c->req->param("page_format") || "letter";
1416 my $top_margin_mm = $c->req->param("tops_margin");
1417 my $left_margin_mm = $c->req->param("left_margin");
1418 my $bottom_margin_mm = $c->req->param("bottom_margin");
1419 my $right_margin_mm = $c->req->param("right_margin");
1420 my $nursery = $c->req->param("nursery");
1421 my $added_text = $c->req->param("text_margin");
1422 my $barcode_type = $c->req->param("select_barcode_type");
1423 my $fieldbook_barcode = $c->req->param("enable_fieldbook_2d_barcode");
1424 my $cass_print_format = $c->req->param("select_print_format");
1433 my $schema = $c->dbic_schema('Bio::Chado::Schema');
1434 my $people_schema = $c->dbic_schema('CXGN::People::Schema');
1435 my $dbh = $c->dbc->dbh;
1436 my $plot_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'plot', 'stock_type' )->cvterm_id();
1437 my $plot_number_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'plot number', 'stock_property' )->cvterm_id();
1438 my $accession_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'accession', 'stock_type' )->cvterm_id();
1439 my $xlabel_margin = 8;
1440 # convert mm into pixels
1441 print STDERR
"MY TOP MARGIN: $top_margin_mm\n";
1442 if ($cass_print_format eq 'NCSU') {$left_margin_mm = 10, $top_margin_mm = 12, $bottom_margin_mm = 12, $right_margin_mm = 10, $labels_per_page = 10, $labels_per_row = 3, $barcode_type = "2D", $page_format = "letter"; }
1443 if ($cass_print_format eq 'CASS') {$left_margin_mm = 112, $top_margin_mm = 10, $bottom_margin_mm = 13, $right_margin_mm = 10, $barcode_type = "2D", $labels_per_row = 2; }
1444 if ($cass_print_format eq 'IITA-3') {$left_margin_mm = 130, $top_margin_mm = 13, $bottom_margin_mm = 11, $right_margin_mm = 10, $labels_per_row = 3, $barcode_type = "2D"; }
1445 if ($cass_print_format eq 'IITA-2') {$left_margin_mm = 130, $top_margin_mm = 13, $bottom_margin_mm = 11, $right_margin_mm = 10, $labels_per_row = 2, $barcode_type = "2D"; }
1446 if ($cass_print_format eq 'MUSA') {$left_margin_mm = 112, $top_margin_mm = 10, $bottom_margin_mm = 13, $barcode_type = "2D", $labels_per_row = 2; }
1447 if ($cass_print_format eq '32A4') {$left_margin_mm = 17, $top_margin_mm = 12, $bottom_margin_mm = 12, $right_margin_mm = 10, $labels_per_page = 8, $labels_per_row = 4, $barcode_type = "2D", $page_format = "letter"; }
1448 if ($cass_print_format eq '32_unique') {$left_margin_mm = 17, $top_margin_mm = 12, $bottom_margin_mm = 12, $right_margin_mm = 10, $labels_per_page = 8, $labels_per_row = 4, $barcode_type = "2D", $page_format = "letter"; }
1449 if ($cass_print_format eq '20A4') {$left_margin_mm = 10, $top_margin_mm = 12, $bottom_margin_mm = 12, $right_margin_mm = 10, $labels_per_page = 10, $labels_per_row = 2, $barcode_type = "2D", $page_format = "letter"; }
1450 if ($cass_print_format eq 'crossing') {$left_margin_mm = 2, $top_margin_mm = 5, $bottom_margin_mm = 0, $right_margin_mm = 0, $labels_per_row = 1, $labels_per_page = 1, $barcode_type = "2D"; }
1451 my ($top_margin, $left_margin, $bottom_margin, $right_margin) = map { $_ * 2.846 } (
1458 $item_names =~ s/\r//g;
1459 my @names = split /\n/, $item_names;
1466 if ($order_id || $order_id ne '') {
1467 my $order_obj = CXGN
::Stock
::Order
->new({ bcs_schema
=> $schema, dbh
=> $dbh, people_schema
=> $people_schema, sp_order_id
=> $order_id});
1468 $tracking_info = $order_obj->get_tracking_info();
1469 @tracking_list = @
$tracking_info;
1470 foreach my $item_info (@tracking_list) {
1471 push @id_list, $item_info->[0];
1473 } elsif ($trial_id || $trial_id ne '') {
1474 my $activity_project = CXGN
::TrackingActivity
::ActivityProject
->new(bcs_schema
=> $schema, trial_id
=> $trial_id);
1475 $tracking_info = $activity_project->get_project_active_identifiers();
1476 @tracking_list = @
$tracking_info;
1477 foreach my $item_info (@tracking_list) {
1478 push @id_list, $item_info->[1];
1481 my $orders = CXGN
::Stock
::Order
->new({ dbh
=> $dbh, people_schema
=> $people_schema, order_to_id
=> $user_id, bcs_schema
=> $schema});
1482 $tracking_info = $orders->get_active_item_tracking_info();
1483 @tracking_list = @
$tracking_info;
1484 foreach my $item_info (@tracking_list) {
1485 push @id_list, $item_info->[0];
1489 foreach my $name (@names) {
1490 if ($name ~~ @id_list) {
1491 push @found, [$name, $name];
1493 push @not_found, $name;
1497 my $dir = $c->tempfiles_subdir('pdfs');
1498 my ($FH, $filename) = $c->tempfile(TEMPLATE
=>"pdfs/pdf-XXXXX", SUFFIX
=>".pdf", UNLINK
=>0);
1499 print STDERR
"FILENAME: $filename \n\n\n";
1500 my $pdf = PDF
::Create
->new(filename
=>$c->path_to($filename),
1501 Author
=>$c->config->{project_name
},
1503 CreationDate
=> [ localtime ],
1507 if (!$page_format) { $page_format = "Letter"; }
1508 if (!$labels_per_page) { $labels_per_page = 8; }
1510 my $base_page = $pdf->new_page(MediaBox
=>$pdf->get_page_size($page_format));
1512 my ($page_width, $page_height) = @
{$pdf->get_page_size($page_format)}[2,3];
1514 ## for 10 labels per page
1516 if ($cass_print_format eq '32A4'){
1518 print STDERR
"LABEL HEIGHT: $label_height\n";
1520 elsif ($cass_print_format eq '32_unique'){
1522 $labels_per_page = 32;
1525 if ($labels_per_page == '10'){
1526 $label_height = int( (($page_height - $top_margin - $bottom_margin) / $labels_per_page) + 0.5 );
1528 ## for 20 labels per page
1529 elsif ($labels_per_page == '20'){
1530 $label_height = int( (($page_height - $top_margin - $bottom_margin) / $labels_per_page) - 0.05 );
1533 ## for 20 labels per page
1534 $label_height = int( ($page_height - $top_margin - $bottom_margin) / $labels_per_page);
1539 foreach my $page (1..$self->label_to_page($labels_per_page, scalar(@found))) {
1540 print STDERR
"Generating page $page...\n";
1541 push @pages, $base_page->new_page();
1544 print STDERR
$cass_print_format."\n";
1545 my $row_y_label_count = 1;
1546 my $labels_on_page = 0;
1549 for (my $i=0; $i<@found; $i++) {
1550 my $label_count = $i + 1;
1551 my $page_nr = $self->label_to_page($labels_per_page, $label_count);
1552 my $label_on_page = ($label_count -1) % $labels_per_page;
1556 my $plot_text = "accession: ".$found[$i]->[2]." ".$found[$i]->[3];
1557 if ($barcode_type eq "1D"){
1558 $tempfile = $c->forward('/barcode/barcode_tempfile_jpg', [ $found[$i]->[0], $found[$i]->[1], 'large', 20 ]);
1560 elsif ($barcode_type eq "2D") {
1561 $tempfile = $c->forward('/barcode/barcode_qrcode_jpg', [ $found[$i]->[0], $found[$i]->[1], $added_text, $fieldbook_barcode ]);
1564 print STDERR
"$tempfile\n";
1565 my $image = $pdf->image($tempfile);
1566 #print STDERR "IMAGE: ".Data::Dumper::Dumper($image);
1568 # note: pdf coord system zero is lower left corner
1570 print "PAGE WIDTH: $page_width\n";
1571 my $final_barcode_width = ($page_width - $right_margin - $left_margin) / $labels_per_row;
1572 my $scalex = $final_barcode_width / $image->{width
};
1573 my $scaley = $label_height / $image->{height
};
1575 if ($scalex < $scaley) { $scaley = $scalex; }
1576 else { $scalex = $scaley; }
1578 my ($year_text, $location_text, $label_boundary);
1579 if ($cass_print_format eq 'NCSU'){
1580 ($year_text,$location_text) = split ',', $added_text;
1581 my $xlabel_margin = 18;
1582 $label_boundary = $page_height - ($label_on_page * $label_height) - $top_margin;
1583 $ypos = $label_boundary - int( ($label_height - $image->{height
} * $scaley) /2);
1584 $final_barcode_width = ($page_width - $right_margin - $left_margin + (2 * $xlabel_margin)) / $labels_per_row;
1586 elsif ($cass_print_format eq '32A4'){
1587 my $label_height_8_per_page = 90;
1588 $label_boundary = $page_height - ($label_on_page * $label_height_8_per_page) - $top_margin;
1589 $ypos = $label_boundary - int( ($label_height_8_per_page - $image->{height
} * $scaley) /2);
1590 $final_barcode_width = ($page_width - $right_margin - $left_margin + (3 * $xlabel_margin)) / $labels_per_row;
1592 elsif ($cass_print_format eq '32_unique'){
1593 my $label_height_8_per_page = 90;
1594 if ($labels_on_page == 32){
1596 $labels_on_page = 0;
1598 if ($row_y_label_count == 1 || $row_y_label_count > $labels_per_row){
1599 $label_boundary = $page_height - ($row_count * $label_height_8_per_page) - $top_margin;
1600 $ypos = $label_boundary - int( ($label_height_8_per_page - $image->{height
} * $scaley) /2);
1603 if ($row_y_label_count > $labels_per_row){
1604 $row_y_label_count = 1;
1606 print STDERR
$row_y_label_count." ".$row_count." ".$ypos." ".$labels_on_page."\n";
1607 $row_y_label_count++;
1609 $final_barcode_width = ($page_width - $right_margin - $left_margin + (3 * $xlabel_margin)) / $labels_per_row;
1611 elsif ($cass_print_format eq '20A4'){
1612 $label_boundary = $page_height - ($label_on_page * $label_height) - $top_margin;
1613 $ypos = $label_boundary - int( ($label_height - $image->{height
} * $scaley) /2);
1614 $final_barcode_width = ($page_width - $right_margin - $left_margin + (4 * $xlabel_margin)) / $labels_per_row;
1616 elsif ($cass_print_format eq 'IITA-3'){
1617 $label_boundary = $page_height - ($label_on_page * $label_height) - $top_margin;
1618 $ypos = $label_boundary - int( ($label_height - $image->{height
} * $scaley) /2);
1619 $final_barcode_width = ($page_width - $right_margin - $left_margin) / ($labels_per_row + 1);
1621 elsif ($cass_print_format eq 'IITA-2'){
1622 $label_boundary = $page_height - ($label_on_page * $label_height) - $top_margin;
1623 $ypos = $label_boundary - int( ($label_height - $image->{height
} * $scaley) /2);
1624 $final_barcode_width = ($page_width - $right_margin - $left_margin) / ($labels_per_row + 1.5);
1627 $label_boundary = $page_height - ($label_on_page * $label_height) - $top_margin;
1628 $ypos = $label_boundary - int( ($label_height - $image->{height
} * $scaley) /2);
1631 if ($cass_print_format eq '32A4' || $cass_print_format eq '32_unique' || $cass_print_format eq 'NCSU' || $cass_print_format eq '20A4' || $cass_print_format eq 'crossing'){
1633 $pages[$page_nr-1]->line($page_width -100, $label_boundary, $page_width, $label_boundary);
1636 # my $lebel_number = scalar($#{$found[$i]});
1637 my $font = $pdf->font('BaseFont' => 'Courier-Bold');
1638 if ($barcode_type eq "2D" && !$cass_print_format) {
1639 foreach my $label_count (1..$labels_per_row) {
1640 my $xposition = $left_margin + ($label_count -1) * $final_barcode_width + 20;
1641 my $yposition = $ypos -7;
1642 my $label_text = $found[$i]->[1];
1644 $pages[$page_nr-1]->image(image
=>$image, xpos
=>$left_margin + ($label_count -1) * $final_barcode_width, ypos
=>$ypos, xalign
=>0, yalign
=>2, xscale
=>$scalex, yscale
=>$scaley);
1646 if ($labels_per_row == '1' ){
1647 my $label_count_15_xter_plot_name = 1-1;
1648 my $xposition = $left_margin + ($label_count_15_xter_plot_name) * $final_barcode_width + 80.63;
1649 my ($yposition_2, $yposition_3, $yposition_4, $yposition_5);
1650 if ($labels_per_page > 15){
1651 $yposition_2 = $ypos - 10;
1652 $yposition_3 = $ypos - 20;
1653 $yposition_4 = $ypos - 30;
1654 $yposition_5 = $ypos - 40;
1656 $yposition_2 = $ypos - 20;
1657 $yposition_3 = $ypos - 30;
1658 $yposition_4 = $ypos - 40;
1659 $yposition_5 = $ypos - 50;
1661 my $plot_pedigree_text;
1663 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_2, $label_text);
1666 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $label_text_4);
1667 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $label_text_6);
1668 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $label_text_5);
1670 } elsif ($labels_per_row > '1'){
1671 if (length($label_text) <= 15){
1672 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition, $label_text);
1677 if ($labels_per_row > '1'){
1678 my $label_text = $found[$i]->[1];
1679 if (length($label_text) > 15) {
1680 my $label_count_15_xter_plot_name = 1-1;
1681 my $xposition = $left_margin + ($label_count_15_xter_plot_name) * $final_barcode_width + 20;
1682 my $yposition = $ypos -7;
1684 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition, $label_text);
1687 } elsif ($cass_print_format eq 'CASS' && $barcode_type eq "2D") {
1689 foreach my $label_count (1..$labels_per_row) {
1690 my $label_text = $found[$i]->[1];
1692 my $xpos = ($left_margin + ($label_count -1) * $final_barcode_width) + 85;
1693 my $label_count_15_xter_plot_name = 1-1;
1694 my $xposition = $left_margin + ($label_count_15_xter_plot_name) * $final_barcode_width - 95.63;
1695 my ($yposition_2, $yposition_3, $yposition_4, $yposition_5);
1696 if ($labels_per_page > 15){
1697 $yposition_2 = $ypos - 10;
1698 $yposition_3 = $ypos - 20;
1699 $yposition_4 = $ypos - 30;
1700 $yposition_5 = $ypos - 40;
1702 $yposition_2 = $ypos - 20;
1703 $yposition_3 = $ypos - 30;
1704 $yposition_4 = $ypos - 40;
1705 $yposition_5 = $ypos - 50;
1707 my $plot_pedigree_text;
1709 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_2, $label_text);
1711 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $label_text_4);
1712 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $label_text_5);
1713 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $label_text_6);
1714 $pages[$page_nr-1]->image(image
=>$image, xpos
=>$xpos, ypos
=>$ypos, xalign
=>0, yalign
=>2, xscale
=>$scalex, yscale
=>$scaley);
1716 } elsif ($cass_print_format eq 'IITA-3' && $barcode_type eq "2D") {
1718 foreach my $label_count (1..$labels_per_row) {
1719 my $label_text = $found[$i]->[1];
1721 my $xpos = ($left_margin + ($label_count -1) * $final_barcode_width) + 80;
1722 my $label_count_15_xter_plot_name = 1-1;
1723 my $xposition = $left_margin + ($label_count_15_xter_plot_name) * $final_barcode_width - 95.63;
1724 my ($yposition_2, $yposition_3, $yposition_4, $yposition_5);
1725 if ($labels_per_page > 15){
1726 $yposition_2 = $ypos - 10;
1727 $yposition_3 = $ypos - 20;
1728 $yposition_4 = $ypos - 30;
1729 $yposition_5 = $ypos - 40;
1731 $yposition_2 = $ypos - 20;
1732 $yposition_3 = $ypos - 30;
1733 $yposition_4 = $ypos - 40;
1734 $yposition_5 = $ypos - 50;
1736 my $plot_pedigree_text;
1738 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_2, $label_text);
1741 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $label_text_4);
1742 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $label_text_5);
1743 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $label_text_6);
1744 $pages[$page_nr-1]->image(image
=>$image, xpos
=>$xpos, ypos
=>$ypos, xalign
=>0, yalign
=>2, xscale
=>$scalex, yscale
=>$scaley);
1746 } elsif ($cass_print_format eq 'IITA-2' && $barcode_type eq "2D") {
1748 foreach my $label_count (1..$labels_per_row) {
1749 my $label_text = $found[$i]->[1];
1751 my $xpos = ($left_margin + ($label_count -1) * $final_barcode_width) + 80;
1752 my $label_count_15_xter_plot_name = 1-1;
1753 my $xposition = $left_margin + ($label_count_15_xter_plot_name) * $final_barcode_width - 95.63;
1754 my ($yposition_2, $yposition_3, $yposition_4, $yposition_5);
1755 if ($labels_per_page > 15){
1756 $yposition_2 = $ypos - 10;
1757 $yposition_3 = $ypos - 20;
1758 $yposition_4 = $ypos - 30;
1759 $yposition_5 = $ypos - 40;
1761 $yposition_2 = $ypos - 20;
1762 $yposition_3 = $ypos - 30;
1763 $yposition_4 = $ypos - 40;
1764 $yposition_5 = $ypos - 50;
1766 my $plot_pedigree_text;
1768 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_2, $label_text);
1770 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $label_text_4);
1771 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $label_text_5);
1772 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $label_text_6);
1773 $pages[$page_nr-1]->image(image
=>$image, xpos
=>$xpos + 60, ypos
=>$ypos, xalign
=>0, yalign
=>2, xscale
=>$scalex, yscale
=>$scaley);
1776 } elsif ($cass_print_format eq 'NCSU' && $barcode_type eq "2D") {
1777 foreach my $label_count (1..$labels_per_row) {
1778 my $xposition = $left_margin + ($label_count -1) * $final_barcode_width;
1779 my $yposition = $ypos -7;
1780 my $label_text = $found[$i]->[1];
1782 my $label_size_stock = 12;
1783 my $yposition_8 = $ypos + 2;
1784 my $yposition_2 = $ypos - 10;
1785 my $yposition_3 = $ypos - 20;
1786 my $yposition_4 = $ypos - 30;
1787 my $yposition_5 = $ypos - 40;
1788 my $yposition_6 = $ypos - 50;
1789 my $yposition_7 = $ypos - 60;
1790 $label_text_6 = $found[$i]->[2];
1791 $label_text_5 = $found[$i]->[11];
1792 $label_text_4 = $found[$i]->[10];
1793 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $year_text);
1794 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $label_text_4);
1795 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $label_text_5);
1796 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_6, $location_text);
1797 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_7, my $parents);
1799 $pages[$page_nr-1]->string($font, $label_size_stock, $xposition, $yposition_2, $label_text_6);
1800 $pages[$page_nr-1]->image(image
=>$image, xpos
=>$left_margin + 90 + ($label_count -1) * $final_barcode_width, ypos
=>$ypos, xalign
=>0, yalign
=>2, xscale
=>$scalex, yscale
=>$scaley);
1802 } elsif ($cass_print_format eq '32A4' && $barcode_type eq "2D") {
1803 foreach my $label_count (1..$labels_per_row) {
1804 my $xposition = $left_margin + ($label_count -1) * $final_barcode_width;
1805 my $yposition = $ypos -7;
1806 my $label_text = $found[$i]->[1];
1808 my $label_size_stock = 10;
1809 my $yposition_8 = $ypos + 2;
1810 my $yposition_2 = $ypos - 10;
1811 my $yposition_3 = $ypos - 20;
1812 my $yposition_4 = $ypos - 30;
1813 my $yposition_5 = $ypos - 40;
1814 my $yposition_6 = $ypos - 50;
1815 my $yposition_7 = $ypos - 60;
1816 $label_text_6 = $found[$i]->[2];
1817 $label_text_5 = $found[$i]->[11];
1818 $label_text_4 = $found[$i]->[12];
1819 $label_text_8 = $found[$i]->[10];
1820 $pages[$page_nr-1]->string($font, $label_size_stock, $xposition, $yposition_8, $label_text);
1821 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $label_text_8);
1822 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $label_text_4);
1823 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_2, $label_text_5);
1824 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_6, $parents);
1825 #$pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_7, $parents);
1826 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $added_text);
1828 $pages[$page_nr-1]->image(image
=>$image, xpos
=>$left_margin + 50 + ($label_count -1) * $final_barcode_width, ypos
=>$ypos, xalign
=>0, yalign
=>2, xscale
=>$scalex, yscale
=>$scaley);
1831 } elsif ($cass_print_format eq '32_unique' && $barcode_type eq "2D") {
1832 my $xposition = $left_margin + ($row_y_label_count -2) * $final_barcode_width;
1833 my $yposition = $ypos -7;
1834 my $label_text = $found[$i]->[1];
1836 my $label_size_stock = 10;
1837 my $yposition_8 = $ypos + 2;
1838 my $yposition_2 = $ypos - 10;
1839 my $yposition_3 = $ypos - 20;
1840 my $yposition_4 = $ypos - 30;
1841 my $yposition_5 = $ypos - 40;
1842 my $yposition_6 = $ypos - 50;
1843 my $yposition_7 = $ypos - 60;
1844 $label_text_6 = $found[$i]->[2];
1845 $label_text_5 = $found[$i]->[11];
1846 $label_text_4 = $found[$i]->[12];
1847 $label_text_8 = $found[$i]->[10];
1848 $pages[$page_nr-1]->string($font, $label_size_stock, $xposition, $yposition_8, $label_text);
1849 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $label_text_8);
1850 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $label_text_4);
1851 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_2, $label_text_5);
1852 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_6, $parents);
1853 #$pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_7, $parents);
1854 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $added_text);
1855 $pages[$page_nr-1]->image(image
=>$image, xpos
=>$left_margin + 50 + ($row_y_label_count -2) * $final_barcode_width, ypos
=>$ypos, xalign
=>0, yalign
=>2, xscale
=>$scalex, yscale
=>$scaley);
1857 } elsif ($cass_print_format eq '20A4' && $barcode_type eq "2D") {
1858 foreach my $label_count (1..$labels_per_row) {
1859 my $xposition = $left_margin + ($label_count -1) * $final_barcode_width;
1860 my $yposition = $ypos -7;
1861 my $label_text = $found[$i]->[1];
1863 my $label_size_stock = 10;
1864 my $yposition_2 = $ypos - 10;
1865 my $yposition_3 = $ypos - 20;
1866 my $yposition_4 = $ypos - 30;
1867 my $yposition_5 = $ypos - 40;
1868 my $yposition_6 = $ypos - 50;
1869 my $yposition_7 = $ypos - 60;
1870 my $yposition_8 = $ypos - 70;
1871 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_2, $label_text);
1872 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $label_text_6);
1873 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $label_text_5);
1874 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $label_text_4);
1875 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_6, $label_text_8);
1876 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_7, $parents_20A4);
1877 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_8, $added_text);
1878 $pages[$page_nr-1]->image(image
=>$image, xpos
=>$left_margin + 200 + ($label_count -1) * $final_barcode_width, ypos
=>$ypos, xalign
=>0, yalign
=>2, xscale
=>$scalex, yscale
=>$scaley);
1880 } elsif ($cass_print_format eq 'MUSA' && $barcode_type eq "2D") {
1882 foreach my $label_count (1..$labels_per_row) {
1883 my $label_text = $found[$i]->[1];
1885 my $xpos = ($left_margin + ($label_count -1) * $final_barcode_width) + 85;
1886 my $label_count_15_xter_plot_name = 1-1;
1887 my $xposition = $left_margin + ($label_count_15_xter_plot_name) * $final_barcode_width - 95.63;
1888 my ($yposition_2, $yposition_3, $yposition_4, $yposition_5, $yposition_6);
1889 if ($labels_per_page > 15){
1890 $yposition_2 = $ypos - 10;
1891 $yposition_3 = $ypos - 20;
1892 $yposition_4 = $ypos - 30;
1893 $yposition_5 = $ypos - 40;
1894 $yposition_6 = $ypos - 50;
1896 $yposition_2 = $ypos - 20;
1897 $yposition_3 = $ypos - 30;
1898 $yposition_4 = $ypos - 40;
1899 $yposition_5 = $ypos - 50;
1900 $yposition_6 = $ypos - 60;
1902 my $plot_pedigree_text;
1904 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_2, $label_text);
1906 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_3, $label_text_4);
1907 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_4, $label_text_5);
1908 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_5, $label_text_6);
1909 $pages[$page_nr-1]->string($font, $label_size, $xposition, $yposition_6, $label_text_7);
1910 $pages[$page_nr-1]->image(image
=>$image, xpos
=>$xpos, ypos
=>$ypos, xalign
=>0, yalign
=>2, xscale
=>$scalex, yscale
=>$scaley);
1912 } elsif ($barcode_type eq "1D") {
1914 foreach my $label_count (1..$labels_per_row) {
1915 $pages[$page_nr-1]->image(image
=>$image, xpos
=>$left_margin + ($label_count -1) * $final_barcode_width, ypos
=>$ypos, xalign
=>0, yalign
=>2, xscale
=>$scalex, yscale
=>$scaley);
1921 print STDERR
"BARCODE FILE NAME =".Dumper
($filename)."\n";
1922 $c->stash->{not_found
} = \
@not_found;
1923 $c->stash->{found
} = \
@found;
1924 $c->stash->{file
} = $filename;
1925 $c->stash->{filetype
} = 'PDF';
1926 $c->stash->{template
} = '/barcode/stock_download_result.mas';