← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13198: PBF Functionality

 

------------------------------------------------------------
revno: 13198
committer: Samta Bajpayee<samta-bajpayee@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-12-11 09:01:17 +0000
message:
  PBF Functionality
modified:
  local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/action/AddTariffDataAction.java
  local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/action/DeleteTariffDataAction.java
  local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/action/GetDataElementforTariffAction.java
  local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/action/LoadTariffDetailsAction.java
  local/in/dhis-web-maintenance-pbf/src/main/resources/META-INF/dhis/beans.xml
  local/in/dhis-web-maintenance-pbf/src/main/webapp/dhis-web-maintenance-pbf/loadDataElementsforTariff.vm
  local/in/dhis-web-maintenance-pbf/src/main/webapp/dhis-web-maintenance-pbf/loadTariffData.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/action/AddTariffDataAction.java'
--- local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/action/AddTariffDataAction.java	2013-12-10 12:41:41 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/action/AddTariffDataAction.java	2013-12-11 09:01:17 +0000
@@ -4,6 +4,7 @@
 import java.util.Date;
 
 import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 import org.hisp.dhis.dataelement.DataElementCategoryService;
 import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -124,22 +125,39 @@
 		OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit(Integer.parseInt(orgUnitId));
 		
 		OrganisationUnitGroup orgUnitGrp = organisationUnitGroupService.getOrganisationUnitGroup(Integer.parseInt(pbfType));
-		
-		TariffDataValue tariffDataValue = new TariffDataValue();
-		
-		
-		tariffDataValue.setValue(Double.parseDouble(tariff));
-		tariffDataValue.setStartDate(sDate);
-		tariffDataValue.setEndDate(eDate);
-		tariffDataValue.setTimestamp(new Date());
-		tariffDataValue.setStoredBy(currentUserService.getCurrentUsername());
-		tariffDataValue.setDataElement(dataElement);
-		tariffDataValue.setOptionCombo(categoryService.getDefaultDataElementCategoryOptionCombo());
-		tariffDataValue.setOrganisationUnitGroup(orgUnitGrp);
-		tariffDataValue.setOrganisationUnit(orgUnit);
-		
-		tariffDataValueService.addTariffDataValue(tariffDataValue);
-		
+		DataElementCategoryOptionCombo optionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
+		
+		TariffDataValue tariffDataValue = tariffDataValueService.getTariffDataValue(orgUnit, dataElement, optionCombo, orgUnitGrp, sDate, eDate);
+		
+		TariffDataValue tariffDataValue1;
+		
+		if(tariffDataValue == null)
+		{
+			tariffDataValue1 = new TariffDataValue();
+		}
+		else
+		{
+			tariffDataValue1 = tariffDataValueService.getTariffDataValue(orgUnit, dataElement, optionCombo, orgUnitGrp, sDate, eDate);
+		}
+		
+		tariffDataValue1.setValue(Double.parseDouble(tariff));
+		tariffDataValue1.setStartDate(sDate);
+		tariffDataValue1.setEndDate(eDate);
+		tariffDataValue1.setTimestamp(new Date());
+		tariffDataValue1.setStoredBy(currentUserService.getCurrentUsername());
+		tariffDataValue1.setDataElement(dataElement);
+		tariffDataValue1.setOptionCombo(optionCombo);
+		tariffDataValue1.setOrganisationUnitGroup(orgUnitGrp);
+		tariffDataValue1.setOrganisationUnit(orgUnit);
+		
+		if(tariffDataValue == null)
+		{
+			tariffDataValueService.addTariffDataValue(tariffDataValue1);
+		}
+		else
+		{
+			tariffDataValueService.updateTariffDataValue(tariffDataValue1);
+		}		
 		return SUCCESS;
 	}
 }
\ No newline at end of file

=== modified file 'local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/action/DeleteTariffDataAction.java'
--- local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/action/DeleteTariffDataAction.java	2013-12-10 12:41:41 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/action/DeleteTariffDataAction.java	2013-12-11 09:01:17 +0000
@@ -35,6 +35,7 @@
 	private String startDate;
 	
 	private String endDate;
+	
 	// -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------

=== modified file 'local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/action/GetDataElementforTariffAction.java'
--- local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/action/GetDataElementforTariffAction.java	2013-12-10 12:41:41 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/action/GetDataElementforTariffAction.java	2013-12-11 09:01:17 +0000
@@ -3,13 +3,19 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.hisp.dhis.constant.Constant;
+import org.hisp.dhis.constant.ConstantService;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
 
 import com.opensymphony.xwork2.Action;
 
 public class GetDataElementforTariffAction implements Action
 {
+	private final static String TARIFF_SETTING_AUTHORITY = "TARIFF_SETTING_AUTHORITY";
+	
 	// -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -20,6 +26,20 @@
 		this.dataElementService = dataElementService;
 	}
 	
+	private ConstantService constantService;
+
+    public void setConstantService( ConstantService constantService )
+    {
+        this.constantService = constantService;
+    }
+    
+    private OrganisationUnitService organisationUnitService;
+    
+    public void setOrganisationUnitService(
+			OrganisationUnitService organisationUnitService) {
+		this.organisationUnitService = organisationUnitService;
+	}
+
 	// -------------------------------------------------------------------------
     // Input
     // -------------------------------------------------------------------------
@@ -34,12 +54,43 @@
 		this.dataElementList = dataElementList;
 	}
 
+	private String tariff_setting_authority;
+	
+	public String getTariff_setting_authority() {
+		return tariff_setting_authority;
+	}
+	
+	private List<Integer> levelOrgUnitIds = new ArrayList<Integer>();
+	
+	public List<Integer> getLevelOrgUnitIds() {
+		return levelOrgUnitIds;
+	}
+	
 	// -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
 
 	public String execute()
     {
+		if(constantService.getConstantByName( TARIFF_SETTING_AUTHORITY) == null)
+		{
+			tariff_setting_authority = "Level 1";
+			List<OrganisationUnit> allLevelOrg =new ArrayList<OrganisationUnit>(organisationUnitService.getOrganisationUnitsAtLevel(1)) ;
+			for(OrganisationUnit org : allLevelOrg)
+			{
+				levelOrgUnitIds.add(org.getId());
+			}
+		}
+		else
+		{
+			Constant tariff_authority = constantService.getConstantByName( TARIFF_SETTING_AUTHORITY );
+			tariff_setting_authority = "Level "+Integer.parseInt(tariff_authority.getValue()+"");
+			List<OrganisationUnit> allLevelOrg =new ArrayList<OrganisationUnit>(organisationUnitService.getOrganisationUnitsAtLevel(Integer.parseInt(tariff_authority.getValue()+""))) ;
+			for(OrganisationUnit org : allLevelOrg)
+			{
+				levelOrgUnitIds.add(org.getId());
+			}
+		}
     	List<DataElement> dataElements = new ArrayList<DataElement>(dataElementService.getAllDataElements());
     	for(DataElement de : dataElements)
     	{
@@ -48,6 +99,7 @@
     			dataElementList.add("\""+de.getName()+"\"");
     		}
     	}
+    	
         return SUCCESS;
     }
 }
\ No newline at end of file

=== modified file 'local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/action/LoadTariffDetailsAction.java'
--- local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/action/LoadTariffDetailsAction.java	2013-12-10 12:41:41 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/java/org/hisp/dhis/pbf/action/LoadTariffDetailsAction.java	2013-12-11 09:01:17 +0000
@@ -86,7 +86,7 @@
 	
 	public String execute()
     {
-		OrganisationUnitGroupSet organisationUnitGroupSet =  organisationUnitGroupService.getOrganisationUnitGroupSet(3);
+		OrganisationUnitGroupSet organisationUnitGroupSet =  organisationUnitGroupService.getOrganisationUnitGroupSet(6709);
 		orGroupList = new ArrayList<OrganisationUnitGroup>(organisationUnitGroupSet.getOrganisationUnitGroups()) ;
 		selecteddataElement = dataElementService.getDataElementByName(dataElementName);
 		OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(Integer.parseInt(orgUnitId));

=== modified file 'local/in/dhis-web-maintenance-pbf/src/main/resources/META-INF/dhis/beans.xml'
--- local/in/dhis-web-maintenance-pbf/src/main/resources/META-INF/dhis/beans.xml	2013-12-10 12:41:41 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/resources/META-INF/dhis/beans.xml	2013-12-11 09:01:17 +0000
@@ -22,6 +22,8 @@
 	<!-- Data Element for Tariff -->
 	<bean id="org.hisp.dhis.pbf.action.GetDataElementforTariffAction" class="org.hisp.dhis.pbf.action.GetDataElementforTariffAction" scope="prototype">
 		<property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
+		<property name="constantService" ref="org.hisp.dhis.constant.ConstantService" />
+		<property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
     </bean>
     
     <!-- Get Tariff Data -->

=== modified file 'local/in/dhis-web-maintenance-pbf/src/main/webapp/dhis-web-maintenance-pbf/loadDataElementsforTariff.vm'
--- local/in/dhis-web-maintenance-pbf/src/main/webapp/dhis-web-maintenance-pbf/loadDataElementsforTariff.vm	2013-12-10 12:41:41 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/webapp/dhis-web-maintenance-pbf/loadDataElementsforTariff.vm	2013-12-11 09:01:17 +0000
@@ -44,9 +44,26 @@
 }
 
 function organisationUnitSelected( orgUnits, orgUnitNames )
-{ 
-	setFieldValue("orgUnit", orgUnitNames[0]);
-	setFieldValue("orgUnitId", orgUnits[0]);
+{
+	var countryTags = $levelOrgUnitIds;
+	var bValue = false;
+	for(var i=0;i<=countryTags.length-1;i++)
+	{
+    	if(countryTags[i] == orgUnits[0] )
+    	{
+    		bValue = true;
+    	}
+	}
+	if(bValue == false)
+	{
+		alert('Please Select Correct level OrgUnit');
+	}
+	else
+	{
+		setFieldValue("orgUnit", orgUnitNames[0]);
+		setFieldValue("orgUnitId", orgUnits[0]);
+	}
+	
 }
 
 selection.setListenerFunction( organisationUnitSelected );
@@ -56,7 +73,7 @@
 <table width="100%">
 	<tr>
 		<td >Orgainsation Unit <input type="text" id="orgUnit" name="orgUnit" readonly/></td>
-		<td >Tariff Setting Authority <input type="text" readonly/></td>
+		<td >Tariff Setting Authority <input type="text" readonly id="tariff_authority" value="$!tariff_setting_authority"/></td>
 	</tr>
 	<tr >
 		<td >&nbsp;</td>

=== modified file 'local/in/dhis-web-maintenance-pbf/src/main/webapp/dhis-web-maintenance-pbf/loadTariffData.vm'
--- local/in/dhis-web-maintenance-pbf/src/main/webapp/dhis-web-maintenance-pbf/loadTariffData.vm	2013-12-10 12:41:41 +0000
+++ local/in/dhis-web-maintenance-pbf/src/main/webapp/dhis-web-maintenance-pbf/loadTariffData.vm	2013-12-11 09:01:17 +0000
@@ -1,14 +1,24 @@
 <script >
 $(function() {
+
+$( "#startDate" ).datepicker();
+$( "#endDate" ).datepicker();
+
 $("#openAddTariff").button()
 			.click(function() {
 				$( "#addTariff" ).dialog( "open" );
+				$("#pbfType option:selected").remove();
+			$("#pbfType ").removeAttr('disabled');
+			$("#tariff").val('');			
+			$("#startDate").val('');
+			$("#startDate ").removeAttr('disabled');
+			$("#endDate").val('');
+			$("#endDate ").removeAttr('disabled');
 });
-
+			
+			
 $( "#addTariff" ).dialog({
-			autoOpen: false,
-			height: 450,
-			width: 350,
+			autoOpen: false,			
 			modal: true,
 			buttons: {
 			"Save": function() {
@@ -38,24 +48,69 @@
 		});
 		 function handleSuccess( json )
 	    {	
+			$("#pbfType option:selected").remove();
+			$("#pbfType ").removeAttr('disabled');
+			$("#tariff").val('');			
+			$("#startDate").val('');
+			$("#startDate ").removeAttr('disabled');
+			$("#endDate").val('');
+			$("#endDate ").removeAttr('disabled');
+			
+			getTariffData();
 			$( "#addTariff" ).dialog( "close" );
 	    }
 	    function handleError( json )
 	    {
+			$("#pbfType option:selected").remove();
+			$("#pbfType ").removeAttr('disabled');
+			$("#tariff").val('');			
+			$("#startDate").val('');
+			$("#startDate ").removeAttr('disabled');
+			$("#endDate").val('');
+			$("#endDate ").removeAttr('disabled');
+			getTariffData();
 			$( "#addTariff" ).dialog( "close" );
 	    }
 });
-function deleteTariffDataValue(tariffId)
+function deleteTariffDataValue(organisationUnitId,dataElementId,optionComboId,organisationUnitGroupId,startDate,endDate)
 {
 				var dataValue = {
-        		        		
+        		        		'organisationUnitId' : organisationUnitId ,
+								'dataElementId' : dataElementId,
+								'categoryOptionComboId' : optionComboId,
+								'organisationUnitGroupId' : organisationUnitGroupId,
+								'startDate' : startDate,
+								'endDate' : endDate
         		    			};
 								
 								jQuery.ajax( {
                                 url: 'deleteTariffData.action', 
 								data: dataValue,
-                                dataType: 'json'
+                                dataType: 'json',
+								success: handleSuccess,
+                                error: handleError
                               } );
+		function handleSuccess( json )
+	    {
+			getTariffData();			
+	    }
+	    function handleError( json )
+	    {
+			getTariffData();			
+	    }
+}
+function editTariffDataValue ( organisationUnitId,dataElementId,optionComboId,organisationUnitGroupId,startDate,endDate,value )
+{
+	$( "#addTariff" ).attr('selected','Edit Tariff')
+	$('#pbfType option[value='+organisationUnitGroupId+']').attr('selected','selected');
+	$('#pbfType').attr('disabled','disabled');
+	$('#tariff').val(value);
+	$('#startDate').val(startDate);
+	$('#startDate').attr('disabled','disabled');
+	$('#endDate').val(endDate);
+	$('#endDate').attr('disabled','disabled');
+	
+	$( "#addTariff" ).dialog( "open" );
 }
 </script>
 <div style="width:100%">
@@ -74,23 +129,32 @@
         </tr>
 	</thead>
 	<tbody id="list">
+		#set( $mark = false )
 		#foreach($tariff in $tariffList )
-		<tr >
+			#if( $mark )
+    						#set( $mark = false )
+    					#else
+    						#set( $mark = true )
+    					#end
+		<tr #if( $mark ) bgcolor = "#FFFFFF" #else bgcolor="#E0ECF8"  #end>
 			<td >$!tariff.organisationUnitGroup.name</td>
 			<td >$!tariff.value</td>
 			<td >$!tariff.startDate</td>
 			<td >$!tariff.endDate</td>
-            <td><img src="images/delete.png" width="17px" onclick="deleteTariffDataValue('')"/></td>
+            <td>
+				<img src="images/delete.png" width="17px" onclick="deleteTariffDataValue('$tariff.organisationUnit.id','$tariff.dataElement.id','$tariff.optionCombo.id','$tariff.organisationUnitGroup.id','$tariff.startDate','$tariff.endDate')"/>
+				<img src="../images/edit.png" alt="$i18n.getString( 'edit' )" onclick="editTariffDataValue('$tariff.organisationUnit.id','$tariff.dataElement.id','$tariff.optionCombo.id','$tariff.organisationUnitGroup.id','$tariff.startDate','$tariff.endDate','$tariff.value')">
+			</td>
         </tr>
 		#end
     </tbody>
 </table>
 <div id="addTariff" title="Add New Tariff">
-	<table style="width:100%">
+	<table style="width:100%;table-layout:fixed;">
 		<tr >
-			<td>&nbsp;</td>
-			<td>
-				<select id="pbfType">
+			<td style="width:40%;">&nbsp;</td>
+			<td style="width:60%;">
+				<select id="pbfType" style="width:100%;">
 					<option >Select PBF Type</option>
 					#foreach($orGrp in $orGroupList)
 						<option value="$orGrp.id">$orGrp.name</option>
@@ -99,16 +163,16 @@
 			</td>
         </tr>
 		<tr >
-			<td>Tariff</td>
-			<td><input type="text" id="tariff"/></td>
-        </tr>
-		<tr >
-			<td>Start Date</td>
-			<td><input type="text" id="startDate"/></td>
-        </tr>
-		<tr >
-			<td>End Date</td>
-			<td><input type="text" id="endDate"/></td>
+			<td style="width:40%;">Tariff</td>
+			<td style="width:60%;"><input type="text" id="tariff" style="width:100%;"/></td>
+        </tr>
+		<tr >
+			<td style="width:40%;">Start Date</td>
+			<td style="width:60%;"><input type="text" id="startDate" style="width:100%;"/></td>
+        </tr>
+		<tr >
+			<td style="width:40%;">End Date</td>
+			<td style="width:60%;"><input type="text" id="endDate" style="width:100%;"/></td>
         </tr>
     </table>
 </div>
\ No newline at end of file