#### begin quickbooks for [value mv_order_number] #####
[tmp quickbooks_record]
[if type=explicit compare="[salestax noformat=1]"]
	[set NAMEISTAXABLE]Y[/set]
	[set ISTAXABLE]1[/set]
	[set NAME]Invoice[/set]
[else]
	[set NAMEISTAXABLE]N[/set]
	[set ISTAXABLE]0[/set]
	[set NAME]Invoice with Sales Tax[/set]
[/else]
[/if]
Setting salestax: ISTAXABLE=[scratch ISTAXABLE]

[if type=explicit compare="[shipping noformat=1]"]
	[set HASSHIPPING]1[/set]
[else]
	[set HASSHIPPING]0[/set]
[/else]
[/if]
Checking shipping: HASSHIPPING=[scratch HASSHIPPING]

[if value b_address1]
[then]
	[seti ADDR1][if value b_fname][value b_fname] [value b_lname][else][value fname] [value lname][/else][/if][/seti]
	[seti ADDR2][if value company][value company][/if][/seti]
	[seti ADDR3][value b_address1][if value b_address2], [value b_address2][/if][/seti]
	[seti ADDR4][value b_city], [value b_state] [value b_zip][/seti]
	[seti ADDR5][if value b_country][if !value country =~ /^US.*/]INTL: [data table=country col=name key="[value b_country]"][/if][/if][/seti]
	[seti SADDR1][value fname] [value lname][/seti]
	[seti SADDR2][if value company][value company][/if][/seti]
	[seti SADDR3][value address1][if value address2], [value address2][/if][/seti]
	[seti SADDR4][value city], [value state] [value zip][/seti]
	[seti SADDR5][if value country][if !value country =~ /^US.*/]INTL: [data table=country col=name key="[value country]"][/if][/if][/seti]
[/then]
[else]
	[seti ADDR1][value fname] [value lname][/seti]
	[seti ADDR2][if value company][value company][/if][/seti]
	[seti ADDR3][value address1][if value address2], [value address2][/if][/seti]
	[seti ADDR4][value city], [value state] [value zip][/seti]
	[seti ADDR5][if value country][if !value country =~ /^US.*/]INTL: [data table=country col=name key="[value country]"][/if][/if][/seti]
	[seti SADDR1][value fname] [value lname][/seti]
	[seti SADDR2][if value company][value company][/if][/seti]
	[seti SADDR3][value address1][if value address2], [value address2][/if][/seti]
	[seti SADDR4][value city], [value state] [value zip][/seti]
	[seti SADDR5][if value country][if !value country =~ /^US.*/]INTL: [data table=country col=name key="[value country]"][/if][/if][/seti]
[/else]
[/if]

[seti CUSTNAME][either][value company][or][value lname], [value fname][/either] ([either][scratch auto_username][or][data session username][/either])[/seti]
[set TRNSTYPE]INVOICE[/set]
[seti DATE][tag time]%m/%d/%y[/tag][/seti]
[seti FILEDATE][tag time]%Y%m%d[/tag][/seti]
Setting customer number: [if !value customer_number][value name=customer_number set="[fcounter etc/qbcust.number]"][userdb save][/if]
[seti qb_trans]!CUST	NAME	REFNUM	TIMESTAMP	EMAIL	BADDR1	BADDR2	BADDR3	BADDR4	BADDR5	SADDR1	SADDR2	SADDR3	SADDR4	SADDR5	PHONE1	PHONE2	FAXNUM	NOTE	CONT1	CONT2	CTYPE	TERMS	TAXABLE	LIMIT	RESALENUM	REP	TAXITEM	NOTEPAD	SALUTATION	COMPANYNAME	FIRSTNAME	MIDINIT	LASTNAME	CUSTFLD1	CUSTFLD2	CUSTFLD3	CUSTFLD4	CUSTFLD5	CUSTFLD6	CUSTFLD7	CUSTFLD8	CUSTFLD9	CUSTFLD10	CUSTFLD11	CUSTFLD12	CUSTFLD13	CUSTFLD14	CUSTFLD15	JOBDESC	JOBTYPE	JOBSTATUS	JOBSTART	JOBPROJEND	JOBEND	HIDDEN	DELCOUNT
[filter tabbed]CUST
[scratch CUSTNAME]
[value customer_number]
[tag time]%s[/tag]
[value email]
[scratch ADDR1]
[scratch ADDR2]
[scratch ADDR3]
[scratch ADDR4]
[scratch ADDR5]
[scratch SADDR1]
[scratch SADDR2]
[scratch SADDR3]
[scratch SADDR4]
[scratch SADDR5]
[value name=phone_day filter=mac]
[value name=phone_night filter=mac]
[value name=fax filter=mac]
[value name=gift_note filter=mac] 
[value fname] [value lname]
[value b_fname] [value b_lname]
Retail
Cash
[if value ISTAXABLE]Y[else]N[/else][/if]
[scratch credit_limit]
[scratch resale_number]
[value affiliate]
[if value ISTAXABLE][value state][else][/else][/if]


[value company]
[value fname]
[comment]MIDINIT[/comment]
[value lname]
[comment]CUSTFLD1[/comment]
[value email][comment]CUSTFLD2[/comment]
[comment]CUSTFLD3[/comment]
[value email]
[comment]CUSTFLD5[/comment]
[comment]CUSTFLD6[/comment]
[comment]CUSTFLD7[/comment]
[comment]CUSTFLD8[/comment]
[comment]CUSTFLD9[/comment]
[comment]CUSTFLD10[/comment]
[comment]CUSTFLD11[/comment]
[comment]CUSTFLD12[/comment]
[comment]CUSTFLD13[/comment]
[comment]CUSTFLD14[/comment]
[comment]CUSTFLD15[/comment]
[comment]JOBDESC[/comment]
[comment]JOBDESC[/comment]
[comment]JOBDESC[/comment]
[comment]JOBDESC[/comment]
[comment]JOBDESC[/comment]
[comment]JOBDESC[/comment]
N
__STORE_ID__[/filter]
!TRNS	TRNSID	TRNSTYPE	DATE	ACCNT	NAME	CLASS	AMOUNT	[if !var QB_DISABLE_DOCNUM]DOCNUM[/if]	MEMO	CLEAR	TOPRINT	NAMEISTAXABLE	ADDR1	ADDR2	ADDR3	ADDR4	ADDR5	SADDR1	SADDR2	SADDR3	SADDR4	SADDR5
!SPL	SPLID	TRNSTYPE	DATE	ACCNT	NAME	CLASS	AMOUNT	DOCNUM	MEMO	CLEAR	QNTY	PRICE	INVITEM	PAYMETH	TAXABLE	VALADJ	SERVICEDATE	OTHER2	EXTRA
!ENDTRNS
[filter tabbed]TRNS
[value mv_order_number]
[scratch TRNSTYPE]
[scratch DATE]
Accounts Receivable
[scratch CUSTNAME]

[total-cost noformat=1]
[if !var QB_DISABLE_DOCNUM][value mv_order_number][/if]
[value name=gift_note filter=mac] - Order Number: [value mv_order_number]
N
N
[scratch NAMEISTAXABLE]
[scratch ADDR1]
[scratch ADDR2]
[scratch ADDR3]
[scratch ADDR4]
[scratch ADDR5]
[scratch SADDR1]
[scratch SADDR2]
[scratch SADDR3]
[scratch SADDR4]
[scratch SADDR5][/filter]
[item-list][filter tabbed]SPL
[fcounter etc/qbline.number]
[scratch TRNSTYPE]
[scratch DATE]
[either][item-data inventory account][or]__QB_DEFAULT_ACCOUNT__[or]Other Income[/either]
[scratch CUSTNAME]

-[item-subtotal noformat]
[value mv_order_number]
[item-description][if-item-modifier size] [item-modifier size][/if-item-modifier][if-item-modifier color] [item-modifier color][/if-item-modifier]
N
-[item-quantity]
[item-price noformat=1]
[seti DESC][filter
                interpolate=1
                op="strip mac __QB_ITEM_LENGTH__ 30"
            ]
            [either]
                __QB_ITEM_PREFIX__[item-field title]
            [or]
                __QB_ITEM_PREFIX__[item-description]
            [/either]
[/filter][/seti][scratch DESC]

[if-item-field nontaxable]N[else][scratch NAMEISTAXABLE][/else][/if-item-field]
N


[/filter]
[/item-list][if scratch HASSHIPPING][filter tabbed]SPL
[fcounter etc/qbline.number]
[scratch TRNSTYPE]
[scratch DATE]
[either]__QB_SHIPPING_ACCOUNT__[or]Other Income[/either] 
[scratch CUSTNAME]

-[shipping noformat=1]
[value mv_order_number]
[shipping-desc]
N
-1
[shipping noformat=1]
[either]__QB_SHIPPING_ITEM__[or]Shipping[/either]

N
N


[/filter]
[/if][filter tabbed]SPL
[fcounter etc/qbline.number]
[scratch TRNSTYPE]
[scratch DATE]
[either]__QB_SALES_TAX_ACCOUNT__[or]Sales Tax Payable[/either]
[either]__QB_SALES_TAX_AGENCY__[or]State Board of Equalization[/either]

-[salestax noformat=1]
[value mv_order_number]
[value state]
N
-1

[either]__QB_SALES_TAX_ITEM__[or]Sales Tax Item[/either]

N
N


AUTOSTAX[/filter]
ENDTRNS
[/seti]
[calc]
	$Scratch->{qb_trans} =~ s/\r?\n/\r\n/g;
	$Scratch->{qb_trans} =~ s/\s*$/\r\n/;
	return;
[/calc]
Logging transaction to orders/qb[either]__QB_FILE_SUFFIX__[or][scratch FILEDATE][/either].iif: [tag op=log umask=022 file="orders/qb[value mv_order_number].iif" type=text interpolate=1][scratch qb_trans]
[/tag]

[calc]

	for (qw/
			ADDR1
			ADDR2
			ADDR3
			ADDR4
			ADDR5
			CUSTNAME
			DATE
			FILEDATE
			HASSHIPPING
			ISTAXABLE
			NAME
			NAMEISTAXABLE
			SADDR1
			SADDR2
			SADDR3
			SADDR4
			SADDR5
			TRNSTYPE
			qb_trans
			/)
	{
		delete $Scratch->{$_};
	}
	return;
[/calc]
[/tmp][perl]
	my $out = $Scratch->{quickbooks_record};
	$out =~ s/^\s+//mg;
	$out =~ s/\s+$//mg;
	$out =~ s/[\r\n]+/\n/;
	$out =~ s/:\n(1|yes|succe\w+|fail\w+)\n/: $1\n/g;
	return $out;
[/perl]
#### end quickbooks for [value mv_order_number] #####
