Batch Report for Backordered Items#
Description#
Example Batch Report which outputs a CSV of Backordered Items across all selected orders.
Snippet#
==========================================================
Installation Steps:
1) Create a Template Based Batch Report - Type: Order
2) Assign Items:
admin_order
tbr_order_contents
3) Paste the contents below in the 'Template' section
==========================================================
<mvt:comment>
| ------------------------
| Output all items in Orders with a status of 'Backordered'
| ------------------------
</mvt:comment>
<mvt:assign name="g.debug" value="0"/>
<mvt:comment>
| Force Download of Output
</mvt:comment>
<mvt:if expr="NOT g.debug">
<mvt:assign name="l.header" value="miva_output_header( 'Content-Type', 'text/csv' )" />
<mvt:assign name="l.header" value="miva_output_header( 'Content-Disposition', 'attachment; filename=Backorders.csv' )" />
</mvt:if>
<mvt:comment>
| Helper Variables
</mvt:comment>
<mvt:assign name="l.new_line" value="asciichar(10)"/>
<mvt:assign name="l.comma" value="asciichar(44)"/>
<mvt:assign name="l.quote" value="asciichar(34)"/>
<mvt:assign name="l.tab" value="asciichar(9)"/>
<mvt:comment>
| File Settings
</mvt:comment>
<mvt:assign name="l.file_delimiter" value="l.quote $ l.comma $ l.quote"/>
<mvt:assign name="l.temp_delimiter" value="'%^%'"/>
<mvt:comment>
| Output the Header Row
</mvt:comment>
<mvt:assign name="l.settings:header:row" value="
'Order #' $ l.temp_delimiter $
'Date' $ l.temp_delimiter $
'Ship to Name' $ l.temp_delimiter $
'Product Name' $ l.temp_delimiter $
'Options' $ l.temp_delimiter $
'SKU/Part' $ l.temp_delimiter $
'Quantity'
"/>
<mvt:comment><!-- Escape Quotes for CSV and output row --></mvt:comment>
<mvt:eval expr="l.quote $ glosub( glosub(l.settings:header:row, l.quote, l.quote $ l.quote) , l.temp_delimiter, l.file_delimiter ) $ l.quote $ l.newline"/>
<mvt:comment>
| Output Each Order's Items (Groups) as a Row
</mvt:comment>
<mvt:foreach iterator="order" array="admin_order:orders">
<mvt:foreach iterator="item" array="order:items">
<mvt:if expr="l.settings:item:status EQ 400">
<mvt:assign name="l.settings:order:output:ship_to_name" value="l.settings:order:ship_fname $ ' ' $ l.settings:order:ship_lname" />
<mvt:if expr="l.settings:item:option_count GT 0">
<mvt:foreach iterator="option" array="item:options">
<mvt:assign name="l.settings:item:output:options" value="l.settings:item:output:options $ l.settings:option:attr_prompt $ ': ' $ l.settings:option:opt_prompt" />
<mvt:if expr="(POS3 GE 1) AND (POS3 LT l.settings:item:option_count)">
<mvt:assign name="l.settings:item:output:options" value="l.settings:item:output:options $ ' | '" />
</mvt:if>
</mvt:foreach>
<mvt:else>
<mvt:assign name="l.settings:item:output:options" value="''" />
</mvt:if>
<mvt:if expr="l.settings:item:part_count GT 0">
<mvt:foreach iterator="part" array="item:parts">
<mvt:if expr="l.settings:part:sku">
<mvt:assign name="l.settings:item:output:sku" value="l.settings:part:sku" />
<mvt:else>
<mvt:assign name="l.settings:item:output:sku" value="l.settings:part:code" />
</mvt:if>
<mvt:assign name="l.settings:item:output:row" value="
l.settings:order:id $ l.temp_delimiter $
l.settings:order:date $ l.temp_delimiter $
l.settings:order:output:ship_to_name $ l.temp_delimiter $
l.settings:item:name $ l.temp_delimiter $
l.settings:item:output:options $ l.temp_delimiter $
l.settings:item:output:sku $ l.temp_delimiter $
l.settings:part:total_quantity
"/>
<mvt:comment><!-- Escape Quotes for CSV and output row --></mvt:comment>
<mvt:eval expr="l.quote $ glosub( glosub(l.settings:item:output:row, l.quote, l.quote $ l.quote) , l.temp_delimiter, l.file_delimiter ) $ l.quote $ l.newline"/>
</mvt:foreach>
<mvt:foreachcontinue />
<mvt:else>
<mvt:if expr="l.settings:item:product:sku">
<mvt:assign name="l.settings:item:output:sku" value="l.settings:item:product:sku" />
<mvt:else>
<mvt:assign name="l.settings:item:output:sku" value="l.settings:item:code" />
</mvt:if>
<mvt:assign name="l.settings:item:output:row" value="
l.settings:order:id $ l.temp_delimiter $
l.settings:order:date $ l.temp_delimiter $
l.settings:order:output:ship_to_name $ l.temp_delimiter $
l.settings:item:name $ l.temp_delimiter $
l.settings:item:output:options $ l.temp_delimiter $
l.settings:item:output:sku $ l.temp_delimiter $
l.settings:item:quantity
"/>
<mvt:comment><!-- Escape Quotes for CSV and output row --></mvt:comment>
<mvt:eval expr="l.quote $ glosub( glosub(l.settings:item:output:row, l.quote, l.quote $ l.quote) , l.temp_delimiter, l.file_delimiter ) $ l.quote $ l.newline"/>
</mvt:if>
</mvt:if>
</mvt:foreach>
</mvt:foreach>
<mvt:comment>
| Debugging Helper
</mvt:comment>
<mvt:if expr="g.debug">
<hr>
<mvt:eval expr="decodeattribute(glosub(miva_array_serialize(l.settings:admin_order), ',', '<br>'))" />
</mvt:if>