[seti transaction_record]
[tag flag write]transactions orderline userdb[/tag]
[if !session logged_in]
	[set auto_create]1[/set]
	[if type=explicit compare=|
		[userdb
			function=new_account
				assign_username=1
					password='[value zip]'
						verify='[value zip]'
		]
		|]
	[comment][perl] Log("User create succeeded."); [/perl][/comment]
	[else]
	[comment][perl] Log("Failed user create."); [/perl][/comment]
	[/else]
	[/if]
[/if]
[comment][perl] Log("Starting report."); [/perl][/comment]

[try]
[comment][perl] Log("Past ACL create log."); [/perl][/comment]
Add main order[data
	table=userdb
	column=order_numbers
	key="[data session username]"
	value=" [value mv_order_number]"
	append="1"
	] to transactions: [import table=transactions type=LINE continue=NOTES]
code: [value mv_order_number]
store_id: __STORE_ID__
order_number: [value mv_order_number]
session: [data session id]
username: [data session username]
shipmode: [value mv_shipmode] ([shipping-desc])
shipping: [shipping noformat=1]
nitems: [nitems]
subtotal: [subtotal noformat=1]
handling: [handling noformat=1]
salestax: [salestax noformat=1]
total_cost: [total-cost noformat=1]
fname: [value filter=strip name=fname]
lname: [value filter=strip name=lname]
company: [value filter=strip name=company]
address1: [value filter=strip name=address1]
address2: [value filter=strip name=address2]
city: [value filter=strip name=city]
state: [value name=state filter="strip uc"]
zip: [value name=zip filter=digits]
country: [value country]
phone_day: [value filter=strip name=phone_day]
phone_night: [value filter=strip name=phone_night]
b_fname: [value filter=strip name=b_fname]
b_lname: [value filter=strip name=b_lname]
b_address1: [value filter=strip name=b_address1]
b_address2: [value filter=strip name=b_address2]
b_city: [value filter=strip name=b_city]
b_state: [value filter=strip name=b_state]
b_zip: [value filter=strip name=b_zip]
b_country: [value filter=strip name=b_country]
b_phone: [value filter=strip name=b_phone]
payment_method: [value mv_payment]
order_date: [value name=order_date set="[tag time]%Y%m%d %H:%M:%S[/tag]"]
status: pending
parent: __PARENT__
[/import]
[comment][perl] Log("Past transactions entry."); [/perl][/comment][item-list]Added [item-code] to orderline: [import table=orderline type=LINE continue=NOTES]
code: [value mv_order_number]-[item-increment]
store_id: __STORE_ID__
order_number: [value mv_order_number]
session: [data session id]
username: [data session username]
shipmode: [item-modifier mv_shipmode]
sku: [item-code]
quantity: [item-quantity]
price: [item-price noformat]
subtotal: [item-subtotal noformat]
size: [item-modifier size]
color: [item-modifier color]
order_date: [value order_date]
status: pending
[/import]
[/item-list][/try]
[catch] There was an error adding to the transaction log. [/catch]
[if scratch auto_create]
	[userdb logout]
	[value name=mv_username set=""]
[/if]
[comment][perl] Log("Past add data entry."); [/perl][/comment]

[comment][perl] Log("Past all transaction log."); [/perl][/comment]
[/seti][perl]
	my $out = $Scratch->{transaction_record};
	$out =~ s/^\s+//;
	$out =~ s/\s+$//;
	return $out;
[/perl]
