|  | @@ -16,6 +16,154 @@
 | 
	
		
			
				|  |  |          </if>
 | 
	
		
			
				|  |  |          limit #{pageStart},#{pageEnd}
 | 
	
		
			
				|  |  |      </select>
 | 
	
		
			
				|  |  | +    <select id="queryByCostHeadx" resultType="org.jeecg.modules.cost.entity.SyCostAllocation">
 | 
	
		
			
				|  |  | +         SELECT max(ss.iExchRate) as exchangeRate,min(s.iTaxUnitPrice) as soPrice,'101' as pkOrg,
 | 
	
		
			
				|  |  | +            max(o.omCode) as planNum,max(s.cdefine22) as poStyleNum,max(pe.cPersonName) as exportSales,
 | 
	
		
			
				|  |  | +            max(ss.cSOCode) as garmentContractno,max(de.cDepName) as department,
 | 
	
		
			
				|  |  | +            max(cc.cCusAbbName) as customerShortame,v.cVenAbbName as processUnit,
 | 
	
		
			
				|  |  | +            max(ss.iTaxRate) as taxrate,max(ss.cMaker) as preparedBy,sum(s.iNatSum) as salesordersLocaltotal,
 | 
	
		
			
				|  |  | +            sum(s.iSum) as salesrrdersOriginaltotal,sum(o.iQuantity) as planQuantity
 | 
	
		
			
				|  |  | +        FROM  UFDATA_101_2021.dbo.SO_SODetails s
 | 
	
		
			
				|  |  | +        inner JOIN UFDATA_101_2021.dbo.SO_SOMain ss on ss.ID= s.ID
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        inner JOIN (
 | 
	
		
			
				|  |  | +                     SELECT
 | 
	
		
			
				|  |  | +                     om.cCode AS omCode,
 | 
	
		
			
				|  |  | +                     om.MOID AS ompoId,od.MODetailsID AS ompoIdItem,
 | 
	
		
			
				|  |  | +                     om.cVenCode AS supplierCode,od.cInvCode,od.isosid,od.iQuantity
 | 
	
		
			
				|  |  | +                     FROM
 | 
	
		
			
				|  |  | +                     UFDATA_101_2021.dbo.OM_MOMain om
 | 
	
		
			
				|  |  | +                     inner JOIN UFDATA_101_2021.dbo.OM_MODetails od ON om.MOID = od.MOID
 | 
	
		
			
				|  |  | +   inner JOIN (select MOID,max(iSendQTY) as iSendQTY from UFDATA_101_2021.dbo.OM_MOMaterials GROUP BY MOID) ot on ot.MOID=om.MOID
 | 
	
		
			
				|  |  | +      WHERE
 | 
	
		
			
				|  |  | +                     om.iVerifyStateNew = 2  and om.cCode like  CONCAT('%',#{code},'%')
 | 
	
		
			
				|  |  | +                     and (om.cCloser is null or ( (od.iReceivedQTY is not null or od.iReceivedQTY != 0) and (ot.iSendQTY is not null or ot.iSendQTY !=0) )or om.cCloser='asuser')
 | 
	
		
			
				|  |  | +                     ) o ON s.isosid  = o.isosid AND s.cInvCode = o.cInvCode
 | 
	
		
			
				|  |  | +        inner JOIN UFDATA_101_2021.dbo.Vendor v ON o.supplierCode= v.cVenCode
 | 
	
		
			
				|  |  | +        inner JOIN UFDATA_101_2021.dbo.Inventory c on c.cInvCode=s.cInvCode
 | 
	
		
			
				|  |  | +        inner JOIN UFDATA_101_2021.dbo.Person  pe ON ss.cPersonCode = pe.cPersonCode
 | 
	
		
			
				|  |  | +        inner JOIN UFDATA_101_2021.dbo.Department de ON ss.cDepCode = de.cDepCode
 | 
	
		
			
				|  |  | +        inner JOIN UFDATA_101_2021.dbo.Customer cc ON ss.cCusCode = cc.cCusCode
 | 
	
		
			
				|  |  | +        WHERE c.cInvCcode like '19%' GROUP BY v.cVenAbbName
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        union all
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        SELECT max(ss.iExchRate) as exchangeRate,min(s.iTaxUnitPrice) as soPrice,'103' as pkOrg,
 | 
	
		
			
				|  |  | +            max(o.omCode) as planNum,max(s.cdefine22) as poStyleNum,max(pe.cPersonName) as exportSales,
 | 
	
		
			
				|  |  | +            max(ss.cSOCode) as garmentContractno,max(de.cDepName) as department,
 | 
	
		
			
				|  |  | +            max(cu.cCusAbbName) as customerShortame,v.cVenAbbName as processUnit,
 | 
	
		
			
				|  |  | +            max(ss.iTaxRate) as taxrate,max(ss.cMaker) as preparedBy,sum(s.iNatSum) as salesordersLocaltotal,
 | 
	
		
			
				|  |  | +            sum(s.iSum) as salesrrdersOriginaltotal,sum(o.iQuantity) as planQuantity
 | 
	
		
			
				|  |  | +        FROM  UFDATA_103_2021.dbo.SO_SODetails a
 | 
	
		
			
				|  |  | +        inner JOIN UFDATA_103_2021.dbo.SO_SOMain b on b.ID= a.ID
 | 
	
		
			
				|  |  | +        inner JOIN (
 | 
	
		
			
				|  |  | +                     SELECT
 | 
	
		
			
				|  |  | +                     om.cCode AS omCode, od.csoordercode,
 | 
	
		
			
				|  |  | +                     om.MOID AS ompoId,od.MODetailsID AS ompoIdItem,
 | 
	
		
			
				|  |  | +                     om.cVenCode AS supplierCode,od.cInvCode,od.isosid,od.iQuantity
 | 
	
		
			
				|  |  | +                     FROM
 | 
	
		
			
				|  |  | +                     UFDATA_103_2021.dbo.OM_MOMain om
 | 
	
		
			
				|  |  | +                     inner JOIN UFDATA_103_2021.dbo.OM_MODetails od ON om.MOID = od.MOID
 | 
	
		
			
				|  |  | +   inner JOIN (select MOID,max(iSendQTY) as iSendQTY from UFDATA_103_2021.dbo.OM_MOMaterials GROUP BY MOID) ot on ot.MOID=om.MOID
 | 
	
		
			
				|  |  | +      WHERE
 | 
	
		
			
				|  |  | +                     om.iVerifyStateNew = 2  and om.cCode like  CONCAT('%',#{code},'%')
 | 
	
		
			
				|  |  | +                     and (om.cCloser is null or ( (od.iReceivedQTY is not null or od.iReceivedQTY != 0) and (ot.iSendQTY is not null or ot.iSendQTY !=0) )or om.cCloser='asuser')
 | 
	
		
			
				|  |  | +                     ) o ON a.isosid  = o.isosid AND a.cInvCode = o.cInvCode
 | 
	
		
			
				|  |  | +        inner JOIN UFDATA_103_2021.dbo.Vendor v ON o.supplierCode= v.cVenCode
 | 
	
		
			
				|  |  | +        inner JOIN UFDATA_103_2021.dbo.Inventory c on c.cInvCode=a.cInvCode
 | 
	
		
			
				|  |  | +        inner JOIN UFDATA_103_2021.dbo.Person  pe ON b.cPersonCode = pe.cPersonCode
 | 
	
		
			
				|  |  | +        inner JOIN UFDATA_103_2021.dbo.Department de ON b.cDepCode = de.cDepCode
 | 
	
		
			
				|  |  | +        inner JOIN UFDATA_103_2021.dbo.Customer cc ON b.cCusCode = cc.cCusCode
 | 
	
		
			
				|  |  | +        inner join UFDATA_102_2021.dbo.PO_Pomain f on f.cPOID=o.csoordercode
 | 
	
		
			
				|  |  | +        inner join UFDATA_102_2021.dbo.po_podetails g on g.POID=f.POID and g.ivouchrowno=a.iRowNo
 | 
	
		
			
				|  |  | +        inner join UFDATA_102_2021.dbo.SO_SODetails s on s.iSOsID=g.iorderdid
 | 
	
		
			
				|  |  | +        inner join UFDATA_102_2021.dbo.so_somain ss on ss.id=s.id
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        inner join UFDATA_102_2021.dbo.Person j on j.cPersonCode=ss.cPersonCode
 | 
	
		
			
				|  |  | +        inner JOIN UFDATA_102_2021.dbo.Customer cu ON ss.cCusCode = cu.cCusCode
 | 
	
		
			
				|  |  | +        WHERE cc.cCusCode in ('T020001','0001') and ss.cCusCode not in ('T020001','0001') and c.cInvCcode like '19%' GROUP BY v.cVenAbbName
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        union all
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        SELECT max(ss.iExchRate) as exchangeRate,min(s.iTaxUnitPrice) as soPrice,'103' as pkOrg,
 | 
	
		
			
				|  |  | +            max(o.omCode) as planNum,max(s.cdefine22) as poStyleNum,max(pe.cPersonName) as exportSales,
 | 
	
		
			
				|  |  | +            max(ss.cSOCode) as garmentContractno,max(de.cDepName) as department,
 | 
	
		
			
				|  |  | +            max(cu.cCusAbbName) as customerShortame,v.cVenAbbName as processUnit,
 | 
	
		
			
				|  |  | +            max(ss.iTaxRate) as taxrate,max(ss.cMaker) as preparedBy,sum(s.iNatSum) as salesordersLocaltotal,
 | 
	
		
			
				|  |  | +            sum(s.iSum) as salesrrdersOriginaltotal,sum(o.iQuantity) as planQuantity
 | 
	
		
			
				|  |  | +        FROM  UFDATA_103_2021.dbo.SO_SODetails a
 | 
	
		
			
				|  |  | +        inner JOIN UFDATA_103_2021.dbo.SO_SOMain b on b.ID= a.ID
 | 
	
		
			
				|  |  | +        inner JOIN (
 | 
	
		
			
				|  |  | +                     SELECT
 | 
	
		
			
				|  |  | +                     om.cCode AS omCode, od.csoordercode,
 | 
	
		
			
				|  |  | +                     om.MOID AS ompoId,od.MODetailsID AS ompoIdItem,
 | 
	
		
			
				|  |  | +                     om.cVenCode AS supplierCode,od.cInvCode,od.isosid,od.iQuantity
 | 
	
		
			
				|  |  | +                     FROM
 | 
	
		
			
				|  |  | +                     UFDATA_103_2021.dbo.OM_MOMain om
 | 
	
		
			
				|  |  | +                     inner JOIN UFDATA_103_2021.dbo.OM_MODetails od ON om.MOID = od.MOID
 | 
	
		
			
				|  |  | +                     inner JOIN (select MOID,max(iSendQTY) as iSendQTY from UFDATA_103_2021.dbo.OM_MOMaterials GROUP BY MOID) ot on ot.MOID=om.MOID
 | 
	
		
			
				|  |  | +                     WHERE
 | 
	
		
			
				|  |  | +                     om.iVerifyStateNew = 2  and om.cCode like  CONCAT('%',#{code},'%')
 | 
	
		
			
				|  |  | +                     and (om.cCloser is null or ( (od.iReceivedQTY is not null or od.iReceivedQTY != 0) and (ot.iSendQTY is not null or ot.iSendQTY !=0) )or om.cCloser='asuser')
 | 
	
		
			
				|  |  | +                     ) o ON a.isosid  = o.isosid AND a.cInvCode = o.cInvCode
 | 
	
		
			
				|  |  | +        inner JOIN UFDATA_103_2021.dbo.Vendor v ON o.supplierCode= v.cVenCode
 | 
	
		
			
				|  |  | +        inner JOIN UFDATA_103_2021.dbo.Inventory c on c.cInvCode=a.cInvCode
 | 
	
		
			
				|  |  | +        inner JOIN UFDATA_103_2021.dbo.Person  pe ON b.cPersonCode = pe.cPersonCode
 | 
	
		
			
				|  |  | +        inner JOIN UFDATA_103_2021.dbo.Department de ON b.cDepCode = de.cDepCode
 | 
	
		
			
				|  |  | +        inner JOIN UFDATA_103_2021.dbo.Customer cc ON b.cCusCode = cc.cCusCode
 | 
	
		
			
				|  |  | +        inner join UFDATA_101_2021.dbo.PO_Pomain f on f.cPOID=o.csoordercode
 | 
	
		
			
				|  |  | +        inner join UFDATA_101_2021.dbo.po_podetails g on g.POID=f.POID and g.ivouchrowno=a.iRowNo
 | 
	
		
			
				|  |  | +        inner join UFDATA_101_2021.dbo.SO_SODetails s on s.iSOsID=g.iorderdid
 | 
	
		
			
				|  |  | +        inner join UFDATA_101_2021.dbo.so_somain ss on ss.id=s.id
 | 
	
		
			
				|  |  | +        inner join UFDATA_101_2021.dbo.Person j on j.cPersonCode=ss.cPersonCode
 | 
	
		
			
				|  |  | +        inner JOIN UFDATA_101_2021.dbo.Customer cu ON ss.cCusCode = cu.cCusCode
 | 
	
		
			
				|  |  | +        WHERE cc.cCusCode in ('T020001') and ss.cCusCode not in ('T020001','0001') and c.cInvCcode like '19%' GROUP BY v.cVenAbbName
 | 
	
		
			
				|  |  | +     UNION ALL
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +             SELECT max(ss1.iExchRate) as exchangeRate,min(s1.iTaxUnitPrice) as soPrice,'103' as pkOrg,
 | 
	
		
			
				|  |  | +            max(o.omCode) as planNum,max(s1.cdefine22) as poStyleNum,max(pe.cPersonName) as exportSales,
 | 
	
		
			
				|  |  | +            max(ss1.cSOCode) as garmentContractno,max(de.cDepName) as department,
 | 
	
		
			
				|  |  | +            max(cu.cCusAbbName) as customerShortame,v.cVenAbbName as processUnit,
 | 
	
		
			
				|  |  | +            max(ss1.iTaxRate) as taxrate,max(ss1.cMaker) as preparedBy,sum(s.iNatSum) as salesordersLocaltotal,
 | 
	
		
			
				|  |  | +            sum(s.iSum) as salesrrdersOriginaltotal,sum(o.iQuantity) as planQuantity
 | 
	
		
			
				|  |  | +        FROM  UFDATA_103_2021.dbo.SO_SODetails a
 | 
	
		
			
				|  |  | +        inner JOIN UFDATA_103_2021.dbo.SO_SOMain b on b.ID= a.ID
 | 
	
		
			
				|  |  | +        inner JOIN (
 | 
	
		
			
				|  |  | +                     SELECT
 | 
	
		
			
				|  |  | +                     om.cCode AS omCode, od.csoordercode,
 | 
	
		
			
				|  |  | +                     om.MOID AS ompoId,od.MODetailsID AS ompoIdItem,
 | 
	
		
			
				|  |  | +                     om.cVenCode AS supplierCode,od.cInvCode,od.isosid,od.iQuantity
 | 
	
		
			
				|  |  | +                     FROM
 | 
	
		
			
				|  |  | +                     UFDATA_103_2021.dbo.OM_MOMain om
 | 
	
		
			
				|  |  | +                     inner JOIN UFDATA_103_2021.dbo.OM_MODetails od ON om.MOID = od.MOID
 | 
	
		
			
				|  |  | +                        inner JOIN (select MOID,max(iSendQTY) as iSendQTY from UFDATA_103_2021.dbo.OM_MOMaterials GROUP BY MOID) ot on ot.MOID=om.MOID
 | 
	
		
			
				|  |  | +                           WHERE
 | 
	
		
			
				|  |  | +                     om.iVerifyStateNew = 2  and om.cCode like CONCAT('%',#{code},'%')
 | 
	
		
			
				|  |  | +                     and (om.cCloser is null or ( (od.iReceivedQTY is not null or od.iReceivedQTY != 0) and (ot.iSendQTY is not null or ot.iSendQTY !=0) )or om.cCloser='asuser')
 | 
	
		
			
				|  |  | +                     ) o ON a.isosid  = o.isosid AND a.cInvCode = o.cInvCode
 | 
	
		
			
				|  |  | +        inner JOIN UFDATA_103_2021.dbo.Vendor v ON o.supplierCode= v.cVenCode
 | 
	
		
			
				|  |  | +        inner JOIN UFDATA_103_2021.dbo.Inventory c on c.cInvCode=a.cInvCode
 | 
	
		
			
				|  |  | +        inner JOIN UFDATA_103_2021.dbo.Person  pe ON b.cPersonCode = pe.cPersonCode
 | 
	
		
			
				|  |  | +        inner JOIN UFDATA_103_2021.dbo.Department de ON b.cDepCode = de.cDepCode
 | 
	
		
			
				|  |  | +        inner JOIN UFDATA_103_2021.dbo.Customer cc ON b.cCusCode = cc.cCusCode
 | 
	
		
			
				|  |  | +        left join UFDATA_102_2021.dbo.PO_Pomain f on f.cPOID=o.csoordercode
 | 
	
		
			
				|  |  | +        left join UFDATA_102_2021.dbo.po_podetails g on g.POID=f.POID and g.ivouchrowno=a.iRowNo
 | 
	
		
			
				|  |  | +        left join UFDATA_102_2021.dbo.SO_SODetails s on s.iSOsID=g.iorderdid
 | 
	
		
			
				|  |  | +        left join UFDATA_102_2021.dbo.so_somain ss on ss.id=s.id
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +				left join UFDATA_101_2021.dbo.PO_Pomain f1 on f1.cPOID=ss.csocode
 | 
	
		
			
				|  |  | +        left join UFDATA_101_2021.dbo.po_podetails g1 on g1.POID=f1.POID and g1.ivouchrowno=s.iRowNo
 | 
	
		
			
				|  |  | +        left join UFDATA_101_2021.dbo.SO_SODetails s1 on s1.iSOsID=g1.iorderdid
 | 
	
		
			
				|  |  | +        left join UFDATA_101_2021.dbo.so_somain ss1 on ss1.id=s1.id
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        left join UFDATA_101_2021.dbo.Person j on j.cPersonCode=ss1.cPersonCode
 | 
	
		
			
				|  |  | +        left JOIN UFDATA_101_2021.dbo.Customer cu ON ss1.cCusCode = cu.cCusCode
 | 
	
		
			
				|  |  | +        WHERE cc.cCusCode in ('0001') and ss.cCusCode in ('T020001') and c.cInvCcode like '19%'
 | 
	
		
			
				|  |  | +		GROUP BY v.cVenAbbName;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    </select>
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      <select id="queryByCostHead" resultType="org.jeecg.modules.cost.entity.SyCostAllocation">
 | 
	
		
			
				|  |  |           SELECT max(ss.iExchRate) as exchangeRate,min(s.iTaxUnitPrice) as soPrice,'101' as pkOrg,
 |