'' group by DATE_FORMAT(doc_date, '%Y-%m'), customer_id, customer_code, customer_name, ncc_customer_code) so_order inner join (select customer_id, customer_code, customer_code_ncc, customer_name, sum(ifnull(amt_total, 0)) as invoice_amt_total from so_invoice where year(DATE_FORMAT(doc_date, '%Y-%m-%d')) = '@{year}' and month(DATE_FORMAT(doc_date, '%Y-%m-%d')) = '@{month}' and state_code = 'Open' and is_red = 'F' group by customer_id, customer_code, customer_code_ncc, customer_name) so_invoice on so_order.customer_id = so_invoice.customer_id left join (select customer_id, customer_code, customer_code_ncc, customer_name, sum(ifnull(amt, 0)) as receipt_amt_total from so_receipt where year(DATE_FORMAT(doc_date, '%Y-%m-%d')) = '@{year}' and month(DATE_FORMAT(doc_date, '%Y-%m-%d')) = '@{month}' and state_code = 'Open' and is_red = 'F' group by customer_id, customer_code, customer_code_ncc, customer_name) so_receipt on so_order.customer_id = so_receipt.customer_id left join (select customer_id, customer_code, customer_code_ncc, customer_name, sum(ifnull(amt_total, 0)) as statement_amt_total from so_statement where year(DATE_FORMAT(doc_date, '%Y-%m-%d')) = '@{year}' and month(DATE_FORMAT(doc_date, '%Y-%m-%d')) = '@{month}' and state_code = 'Open' and is_red = 'F' group by customer_id, customer_code, customer_code_ncc, customer_name) so_statement on so_order.customer_id = so_statement.customer_id ]]> '') group by customer_id, customer_code, customer_name, ncc_customer_code) so_order inner join (select customer_id, customer_code, customer_code_ncc, customer_name, sum(ifnull(amt_total, 0)) as invoice_amt_total from so_invoice where DATE_FORMAT(doc_date, '%Y-%m') = DATE_FORMAT(DATE_SUB(now(),INTERVAL 1 month), '%Y-%m') and state_code = 'Open' and is_red = 'F' group by customer_id, customer_code, customer_code_ncc, customer_name) so_invoice on so_order.customer_id = so_invoice.customer_id left join (select customer_id, customer_code, customer_code_ncc, customer_name, sum(ifnull(amt, 0)) as receipt_amt_total from so_receipt where DATE_FORMAT(doc_date, '%Y-%m') = DATE_FORMAT(DATE_SUB(now(),INTERVAL 1 month), '%Y-%m') and state_code = 'Open' and is_red = 'F' group by customer_id, customer_code, customer_code_ncc, customer_name) so_receipt on so_order.customer_id = so_receipt.customer_id left join (select customer_id, customer_code, customer_code_ncc, customer_name, sum(ifnull(amt_total, 0)) as statement_amt_total from so_statement where DATE_FORMAT(doc_date, '%Y-%m') = DATE_FORMAT(DATE_SUB(now(),INTERVAL 1 month), '%Y-%m') and state_code = 'Open' and is_red = 'F' group by customer_id, customer_code, customer_code_ncc, customer_name) so_statement on so_order.customer_id = so_statement.customer_id ]]> update @{documentTable} document set update_time = now() where document.id = '@{document_id}' IFNull(wm_book_detail.qty_available, 0) ]]>