# Copyright 2002-2007 Interchange Development Group and others
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.  See the LICENSE file for details.

UserTag write-shipping Order      file
UserTag write-shipping PosNumber  1
UserTag write-shipping addAttr
UserTag write-shipping Version    1.6
UserTag write-shipping Routine    <<EOR
sub {
	my ($file, $opt) = @_;
	if(! $file) {
		unless($file = $Vend::Cfg->{Special}{'shipping.asc'}) {
			my $dir = $Vend::Cfg->{Shipping}{dir} || $Vend::Cfg->{ProductDir};
			$file = Vend::Util::catfile($dir,'shipping.asc');
	}
	}

	## This is set so the UI knows where to check for changes
	$::Scratch->{ui_shipping_asc} = $file;

	my $lines = $Vend::Cfg->{Shipping_line};
	my @outlines;
	for (@$lines) {
		#    0      1      2      3     4     5       6      7
		# ($mode, $desc, $crit, $min, $max, $cost, $query, $opt) 
		my @line = @$_;
		my $opt = '';
		if (ref($line[7]) =~ /HASH/) {
			$line[7] = uneval_it($line[7]);
		}
		push @outlines, \@line;
	}

	# Back the file up
	$Tag->backup_file($file);

	open(SHIPOUT, ">$file")
		or die errmsg("Can't write shipping to %s: %s", $file, $!);
	for(@outlines) {
		print SHIPOUT join "\t", @$_;
		print SHIPOUT "\n";
	}
	close SHIPOUT;
}
EOR
