← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14620: PBF Payment Adjustment

 

------------------------------------------------------------
revno: 14620
committer: samta bajpayee<samta.bajpayee@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-04-02 17:32:50 +0100
message:
  PBF Payment Adjustment
modified:
  local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/api/Lookup.java
  local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/payment/action/LoadPaymentAdjustmentDetailsAction.java
  local/in/dhis-web-maintenance-pbf/src/main/resources/struts.xml
  local/in/dhis-web-maintenance-pbf/src/main/webapp/dhis-web-maintenance-pbf/loadPaymentAdjustment.vm


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/api/Lookup.java'
--- local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/api/Lookup.java	2014-03-03 06:33:06 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/api/Lookup.java	2014-04-02 16:32:50 +0000
@@ -9,6 +9,7 @@
 {
     public static final String DS_PBF_TYPE = "DS_PBF_TYPE";    
     public static final String DS_QUALITY_TYPE = "DS_QUALITY_TYPE";
+    public static final String DS_PAYMENT_TYPE = "DS_PAYMENT_TYPE";
     
     public static final String OC_TARIFF = "OC_TARIFF";    
     public static final String QV_TARIFF = "QV_TARIFF";     

=== modified file 'local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/payment/action/LoadPaymentAdjustmentDetailsAction.java'
--- local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/payment/action/LoadPaymentAdjustmentDetailsAction.java	2014-04-01 18:59:55 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/payment/action/LoadPaymentAdjustmentDetailsAction.java	2014-04-02 16:32:50 +0000
@@ -19,6 +19,10 @@
 import org.hisp.dhis.datavalue.DataValueService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.pbf.api.Lookup;
+import org.hisp.dhis.pbf.api.LookupService;
+import org.hisp.dhis.pbf.api.QualityMaxValue;
+import org.hisp.dhis.pbf.api.QualityMaxValueService;
 import org.hisp.dhis.pbf.api.TariffDataValue;
 import org.hisp.dhis.pbf.api.TariffDataValueService;
 import org.hisp.dhis.period.Period;
@@ -32,6 +36,7 @@
     implements Action
 {
 	private final static String PAYMENT_ADJUSTMENT_AMOUNT_DE = "PAYMENT_ADJUSTMENT_AMOUNT_DE";
+	private final static String TARIFF_SETTING_AUTHORITY = "TARIFF_SETTING_AUTHORITY";
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -84,6 +89,12 @@
 	@Autowired
 	private PeriodService periodService;
 	
+	@Autowired
+    private LookupService lookupService;
+	
+	@Autowired
+	private QualityMaxValueService qualityMaxValueService;
+    
     // -------------------------------------------------------------------------
     // Input / Output
     // -------------------------------------------------------------------------
@@ -134,11 +145,22 @@
 		return tariffDataValueMap;
 	}
     
-    private String amountAvailable = "";
+    private Map<String,String> amountMap = new HashMap<String, String>();
+    
+    public Map<String, String> getAmountMap() {
+		return amountMap;
+	}
+
+	private String amountAvailable = "";
     
     public String getAmountAvailable() {
 		return amountAvailable;
 	}
+    private String unAdjustedAmount;
+    
+    public String getUnAdjustedAmount() {
+		return unAdjustedAmount;
+	}
     
     // -------------------------------------------------------------------------
     // Action implementation
@@ -159,34 +181,111 @@
 		
 		String amountDEId = paymentAmount.getValue()+"";
         
+		Constant tariff_authority = constantService.getConstantByName( TARIFF_SETTING_AUTHORITY );
+        int tariff_setting_authority = 0;
+        if ( tariff_authority == null )
+        {
+            tariff_setting_authority = 1;
+
+        }
+        else
+        {
+            tariff_setting_authority = (int) tariff_authority.getValue();
+
+        }
+        
         DataElementCategoryOptionCombo optionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
         
+        List<Lookup> lookups = new ArrayList<Lookup>( lookupService.getAllLookupsByType( Lookup.DS_PAYMENT_TYPE ) );
+		
+        Double allMax = 0.0;
+        Double allScore = 0.0;
+        double quantityValue = 0;
+        for( Lookup lookup : lookups )
+        {
+			String[] lookupType = lookup.getValue().split(":");
+			//System.out.println("lookupType[0] "+lookupType[0]+" dataSetId "+dataSetId);
+			if(Integer.parseInt( lookupType[0] ) == Integer.parseInt(dataSetId))
+			{
+				DataSet lookupdataSet = dataSetService.getDataSet(Integer.parseInt(lookupType[1]));
+				for(DataElement de : lookupdataSet.getDataElements())
+					{
+					List<QualityMaxValue> qualityMaxValues = new ArrayList<QualityMaxValue>();
+		            OrganisationUnit parentOrgunit = findParentOrgunitforTariff( organisationUnit, tariff_setting_authority );
+		            if ( parentOrgunit != null )
+		            {
+		                qualityMaxValues = new ArrayList<QualityMaxValue>( qualityMaxValueService.getQuanlityMaxValues(
+		                    parentOrgunit, de ) );
+		            }
+		            List<Period> periodList = new ArrayList<Period>( periodService.getPeriodsBetweenDates(period.getStartDate(), period.getEndDate()));
+		        	//System.out.println("Period Size: "+ periodList.size() );
+		            for(Period prd : periodList)		        		
+		        	{
+		            	
+		        		List<OrganisationUnit> orgList = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnitWithChildren( organisationUnit.getId()));
+		        		//System.out.println("orgList Size: "+ orgList.size() );
+		        		for(OrganisationUnit ou : orgList )
+		            	{
+				            DataValue dataValue = dataValueService.getDataValue( de, prd, ou, optionCombo );
+				            for ( QualityMaxValue qualityMaxValue : qualityMaxValues )
+				            {
+				            	//System.out.println("qualityMaxValue.getValue() "+qualityMaxValue.getValue());
+				                if ( qualityMaxValue.getStartDate().getTime() <= period.getStartDate().getTime()
+				                    && period.getEndDate().getTime() <= qualityMaxValue.getEndDate().getTime() )
+				                {
+				                    if ( dataValue != null )
+				                    {
+				                    	allMax = allMax + qualityMaxValue.getValue();
+				                    	//System.out.println("dataValue.getValue() "+dataValue.getValue());
+				                        allScore = allScore + Double.parseDouble(dataValue.getValue()) ;
+				                    }
+				                    break;
+				                }
+				            }
+		            	}
+		        	}
+				}
+			}
+        }
+        
+		quantityValue = Math.round(( allScore / allMax ) * 100) ;
+		System.out.println("quantityValue: "+quantityValue);
+		//quantityValue = Math.round( quantityValue );
+		double unadjusted = 0.0;
         for(DataElement de : dataElements)
         {
-        	int quantityValue = 0;
-        	int tariffValue = 0;
-        	List<OrganisationUnit> orgList = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnitWithChildren( organisationUnit.getId()));
+        	double tariffValue = 0;
+        	List<OrganisationUnit> orgList = new ArrayList<OrganisationUnit>();
+        	OrganisationUnit parentOrgunit2 = findParentOrgunitforTariff( organisationUnit, tariff_setting_authority );
+            if ( parentOrgunit2 != null )
+            {
+            	orgList = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnitWithChildren( parentOrgunit2.getId()));
+            }
+            else
+            {
+            	orgList = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnitWithChildren( organisationUnit.getId()));
+            }
         	for(OrganisationUnit ou : orgList )
         	{
         		List<Period> periodList = new ArrayList<Period>( periodService.getPeriodsBetweenDates(period.getStartDate(), period.getEndDate()));
 	        	for(Period prd : periodList)
-	        	{
-	        		DataValue dataValue = dataValueService.getDataValue(de, prd, ou, optionCombo );
-		        	if(dataValue != null)
-		        	{
-		        		quantityValue = quantityValue + Integer.parseInt(dataValue.getValue());	        		
-		        	}	        	
+	        	{       	
 		        	TariffDataValue tariffDataValue = tariffDataValueService.getTariffDataValue( ou , de, dataSet, prd.getStartDate(), prd.getEndDate());
 		        	
 		        	if(tariffDataValue != null)
 		        	{
-		        		tariffValue = tariffValue + Integer.parseInt(tariffDataValue.getValue()+"");
+		        		System.out.println( tariffDataValue.getValue() );
+		        		tariffValue = tariffValue + tariffDataValue.getValue();
 		        	}
 	        	}
         	}
         	quantityValidatedMap.put(de.getUid(), quantityValue+"" );
         	tariffDataValueMap.put(de.getUid(), tariffValue+"");
+        	double amount = ( quantityValue * tariffValue );
+        	amountMap.put(de.getUid(), amount+"" );
+        	unadjusted = unadjusted + amount;
         }
+        unAdjustedAmount = unadjusted+"";
         Collections.sort(dataElements);
         DataElement dataElement = dataElementService.getDataElement((int)paymentAmount.getValue());
         DataValue dataValue = dataValueService.getDataValue(dataElement, period, organisationUnit, optionCombo);
@@ -197,4 +296,16 @@
         }
         return SUCCESS;
     }
+	public OrganisationUnit findParentOrgunitforTariff( OrganisationUnit organisationUnit, Integer tariffOULevel )
+    {
+        Integer ouLevel = organisationUnitService.getLevelOfOrganisationUnit( organisationUnit.getId() );
+        if ( tariffOULevel == ouLevel )
+        {
+            return organisationUnit;
+        }
+        else
+        {
+            return findParentOrgunitforTariff( organisationUnit.getParent(), tariffOULevel );
+        }
+    }
 }
\ No newline at end of file

=== modified file 'local/in/dhis-web-maintenance-pbf/src/main/resources/struts.xml'
--- local/in/dhis-web-maintenance-pbf/src/main/resources/struts.xml	2014-04-01 18:59:55 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/resources/struts.xml	2014-04-02 16:32:50 +0000
@@ -192,8 +192,8 @@
       <result name="success" type="velocity">/main.vm</result>
       <param name="page">/dhis-web-maintenance-pbf/getPaymentAdjustmentList.vm</param>
       <param name="menu">/dhis-web-maintenance-pbf/menuPayment.vm</param>
-      <param name="javascripts">../dhis-web-commons/ouwt/ouwt.js,javascript/paymentAdjustment.js,../dhis-web-commons/javascripts/ext/ext-all.js,javascript/TransformGrid.js</param>
-      <param name="stylesheets">../dhis-web-commons/javascripts/ext/resources/css/ext-all-gray.css,css/dataentry.css</param>
+      <param name="javascripts">../dhis-web-commons/ouwt/ouwt.js,javascript/paymentAdjustment.js</param>
+      <param name="stylesheets">css/dataentry.css</param>
     </action>
     
 	<!-- Load Payment Adjustment List -->

=== modified file 'local/in/dhis-web-maintenance-pbf/src/main/webapp/dhis-web-maintenance-pbf/loadPaymentAdjustment.vm'
--- local/in/dhis-web-maintenance-pbf/src/main/webapp/dhis-web-maintenance-pbf/loadPaymentAdjustment.vm	2014-04-02 04:48:04 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/webapp/dhis-web-maintenance-pbf/loadPaymentAdjustment.vm	2014-04-02 16:32:50 +0000
@@ -1,88 +1,15 @@
 
 <script type="text/javascript" >
 	jQuery(document).ready( function(){
-		document.getElementById("amountAvail").value = $amountAvailable;
+		document.getElementById("amountAvail").value = '$amountAvailable';
 		adjustPer();
 	});
-	var total = 0;
-	var windowWidth = $(window).width();
-	var windowHeight = $(window).height();
-	var tableWidth = (parseInt( windowWidth ) * 75) / 100 ;	
-	var columnWidth = (parseInt( windowWidth ) * 10) / 100 ;
-	var indicatorWidth = (parseInt( windowWidth ) * 15) / 100 ;
-	Ext.Loader.setConfig({
-		enabled: true
-	});
-	Ext.Loader.setPath('Ext.ux.grid', 'javascript');
-	Ext.require([
-		'Ext.data.*',
-		'Ext.grid.*',
-		'Ext.toolbar.Paging',
-		'Ext.ux.grid.TransformGrid'
-	]);
+	var total = 0.0;
 	
 </script>
 
 <script >
-jQuery(document).ready( function(){
-			Ext.QuickTips.init();
-			
-			var grid = Ext.create('Ext.ux.grid.TransformGrid', "paymentDetails", {				
-			sortableColumns: true,
-            enableColumnMove: true,
-            enableColumnResize: true,
-            sortOnLoad: true,
-			width: tableWidth,
-        	height: 200,			
-            sorters: {direction: 'ASC'},
-			autoCreateViewPort:false,
-			renderTo: Ext.Element.get('#paymentTable'),
-        	layout: {
-            	type: 'hbox',
-            	align: 'stretch'
-        	},
-			columns: [
-    		{
-                text     : '$i18n.getString( "indicator" )',
-    			width    : indicatorWidth,            
-                sortable : true
-            },
-			{
-                text     : '$i18n.getString( "quantity_for" )',
-    			width    : columnWidth,            
-                sortable : true
-            },
-			{
-                text     : '$i18n.getString( "Tariff" )',
-    			width    : columnWidth,						
-                sortable : true
-            },
-			{
-                text     : '$i18n.getString( "amount" )',
-    			width    : columnWidth,						
-                sortable : true
-            },
-			{
-                text     : '$i18n.getString( "amount_including_quality" )',
-    			width    : columnWidth,						
-                sortable : true
-            },
-			{
-                text     : '$i18n.getString( "adjusted_per" )',
-    			width    : columnWidth,						
-                sortable : true
-            },
-			{
-                text     : '$i18n.getString( "adjusted_per" )',
-    			width    : columnWidth,						
-                sortable : false
-            }
-			]
-			});
-			
-			grid.render();
 
-});
 </script>
 <style >
 	.mandatory
@@ -93,10 +20,10 @@
 </style>
 
 <input type="hidden" id="dataElementId" name="dataElementId" value="$!selecteddataElement.id"/>
-<div style="width:100%;" id="paymentTable">
-<table id="paymentDetails" name="paymentDetails" cellspacing="0">
+<div style="width:95%;" id="paymentTable">
+<table style="width:100%;" id="paymentDetails" name="paymentDetails" cellspacing="0" class="formSection">
 	<thead >
-		<tr >
+		<tr bgcolor="#CBDDEB">
 			<th >$i18n.getString( "indicator" )</th>
 			<th >$i18n.getString( "quantity_for" )</th>
 			<th >$i18n.getString( "Tariff" )</th>			
@@ -108,6 +35,7 @@
 	</thead>
 	<tbody>
 		#set( $mark = false )
+		
 		#foreach( $dataElement in $dataElements )
 			#if( $mark )
                 #set( $mark = false )
@@ -115,31 +43,33 @@
 				#set( $mark = true )
 			#end
 			
-            <tr >
+            <tr #if( $mark ) bgcolor = "#FFFFFF" #else bgcolor="#E0ECF8" #end>
 				<td>$!dataElement.name</td>
 				<td>$!quantityValidatedMap.get( $dataElement.uid )</td>
 				<td>$!tariffDataValueMap.get( $dataElement.uid )</td>				
-				<td id="amount_$dataElement.id"></td>
+				<td>$!amountMap.get( $dataElement.uid )</td>
 				<td>&nbsp; </td>
-				<td>&nbsp;</td>
+				<td id="adjusted_$dataElement.uid">&nbsp;</td>
 	            <td>&nbsp;</td>		            		
         </tr>
         <script>
-        	function calVal( ) {
-        		var amount = 0.0;
-        		amount = parseFloat( $!quantityValidatedMap.get( $dataElement.uid ) ) * parseFloat( $!tariffDataValueMap.get( $dataElement.uid ) );
-        		document.getElementById("amount_"+$dataElement.id).firstChild.nodeValue = amount.toFixed(2);
-        		
-        		total = total + parseFloat( amount  );
-        		document.getElementById("total").value = total.toFixed(2) ;
+        	function calValue()
+        	{
+        		var adjusted = $("#adjustment").val();
+        		var amount = '$!tariffDataValueMap.get( $dataElement.uid )';
+        		var adjustedPer = 0.0;
+        		adjustedPer = (parseFloat(amount)/parseFloat(adjusted))*100
+        		$('#adjusted_$dataElement.uid').text(adjustedPer.toFixed(2));
         	}
-        	calVal( );
+        	calValue();
         </script>
 		#end
 		<tr>
-			<td>&nbsp; </td>			
-			<td colspan="3" >Unadjusted Amount </td>
-			<td colspan="3"><input type="text" name="total" id="total"/></td>			
+			<td>&nbsp; </td>						
+			<td colspan="2" >Unadjusted Amount </td>
+			<td colspan="2"><input type="text" name="total" id="total" value="$!unAdjustedAmount"/></td>			
+			<td>&nbsp; </td>
+			<td>&nbsp; </td>
 		</tr>
     </tbody>
 </table>