# HG changeset patch
# User Ranjith S R <ranjith@qualiantech.com>
# Date 1488259674 -19800
#      Tue Feb 28 10:57:54 2017 +0530
# Node ID 63c9cf8589db91d6190bca4c30fa2690f2910557
# Parent  3d4325370ae99bb3d8270743dd770aa0193f62a1
Related to issue 35216 : Invoice Line should not be created again, if it is already created in OrderLoader

* If Invoice Line are already created in OrderLoader, then while doing cashup, Invoice line should not be created/splited again

diff -r 3d4325370ae9 -r 63c9cf8589db src/org/openbravo/retail/posterminal/OrderGroupingProcessor.java
--- a/src/org/openbravo/retail/posterminal/OrderGroupingProcessor.java	Tue Feb 28 10:50:28 2017 +0530
+++ b/src/org/openbravo/retail/posterminal/OrderGroupingProcessor.java	Tue Feb 28 10:57:54 2017 +0530
@@ -128,7 +128,7 @@
 
     // check if there are orderlines splitted by inoutlines
     OrderGroupingProcessorData[] orderLinesToSplit = OrderGroupingProcessorData
-        .selectSplitOrderLines(conn, cashUpId);
+        .selectSplitOrderLines(conn, cashUpId, strCurrentDate);
 
     for (OrderGroupingProcessorData orderLineToSplit : orderLinesToSplit) {
       OrderLine orderLine = OBDal.getInstance().get(OrderLine.class, orderLineToSplit.cOrderlineId);
diff -r 3d4325370ae9 -r 63c9cf8589db src/org/openbravo/retail/posterminal/OrderGroupingProcessor_data.xsql
--- a/src/org/openbravo/retail/posterminal/OrderGroupingProcessor_data.xsql	Tue Feb 28 10:50:28 2017 +0530
+++ b/src/org/openbravo/retail/posterminal/OrderGroupingProcessor_data.xsql	Tue Feb 28 10:57:54 2017 +0530
@@ -14,13 +14,16 @@
     <SqlMethodComment>select orderlines with multiple shipmentlines</SqlMethodComment>
     <Sql>
     <![CDATA[
-        select ol.c_orderline_id, o.c_order_id, '' as c_invoice_id
-        from c_orderline ol, c_order o
-        where ol.c_order_id = o.c_order_id
-        and (select count(1) from m_inoutline il where il.c_orderline_id = ol.c_orderline_id) > 1
+        select ol.c_orderline_id, o.c_order_id, i.c_invoice_id
+        from c_orderline ol
+        join c_order o on ol.c_order_id = o.c_order_id
+        left join c_invoice i on i.c_order_id = o.c_order_id
+        where (select count(1) from m_inoutline il where il.c_orderline_id = ol.c_orderline_id) > 1
         and o.em_obpos_app_cashup_id = ?
+        and (case when (i.c_invoice_id is not null and i.dateinvoiced != to_timestamp(to_char(?), to_char('DD-MM-YYYY HH24:MI:SS'))) then 0 else 1 end) = 1
     ]]></Sql>
     <Parameter name="cashupId"/>
+    <Parameter name="currentDate"/>
   </SqlMethod>
   <SqlMethod name="insertHeaderGrouping" type="preparedStatement" return="rowcount">
     <SqlMethodComment>Insert invoice headers grouping orders</SqlMethodComment>
