{
  "facility_sql": "select /*FACILITY_TAG*/ Account, Barcode, Vendor, Description, Color, Size, UnitCost * Reported_Qty AS Cost, UnitCost, Reported_Qty\r\nfrom (\r\nselect  p.Product_Id as Id, CONCAT(p.REV_CATEGORY,if(LENGTH(REVENUE_SUBCATEGORY)>0,CONCAT(':',p.REVENUE_SUBCATEGORY),'')) as Account, \r\n\tp.barcode as Barcode, v.vendor_name as Vendor, p.description as Description, p.color_desc as Color, p.size_desc as Size,  \r\n\r\n\t-- Cost\r\n\t(select legacy_unit_cost from restock  where restock.product_id=p.Product_Id and restock.quantity>0 and restock.rtype in ('RESTOCK','TRANSFER_IN') and restock.postdate<='/*END_DATE*/'  order by restock.postdate desc limit 1\r\n\t) as UnitCost, \r\n\r\n\t(coalesce((select sum(QUANTITY) from restock where restock.product_id=p.product_id and restock.postdate<='/*END_DATE*/'),0)\r\n                     - coalesce((select sum(QUANTITY) from invoice_items ii2 join invoices i2 on i2.invoice_id=ii2.invoice_id where  i2.voidedinvoice=0 and ii2.product_id=p.product_id and i2.postdate<='/*END_DATE*/'),0)\r\n\t) as Reported_Qty,  \r\n\tPREPARED_INTERNAL_NOTE as Product_Notes \r\nfrom products p\r\n\tjoin vendors v on p.vendor_id=v.vendor_id \r\nwhere p.product_type in ('ISINGLE', 'ICHILD')  and not p.INACTIVE \r\n) p1\r\norder by p1.Account, p1.Vendor, p1.Description, p1.Color, p1.Size * 1 asc, p1.Size asc",
  "merge_sql": "",
  "json": "{\r\n  \"facility_column_tag\": \"/*FACILITY_TAG*/\",\r\n  \"wants_start_date\": {\r\n    \"tag\": \"/*START_DATE*/\"\r\n  },\r\n  \"wants_end_date\": {\r\n    \"tag\": \"/*END_DATE*/\"\r\n  }\r\n}",
  "name": "Inventory - Count"
}