← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2055: Work in Progress for Bangladesh Manpower Module

 

------------------------------------------------------------
revno: 2055
committer: Neeraj <neeraj.hisp@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2010-11-14 19:50:26 +0530
message:
  Work in Progress for Bangladesh Manpower Module
added:
  local/bd/dhis-web-linelisting-manpower/src/main/java/org/hisp/dhis/ll/action/lldataentry/GetValidatePostVacantAction.java
modified:
  local/bd/dhis-web-linelisting-manpower/src/main/java/org/hisp/dhis/ll/action/lldataentry/SaveEmplyeePostAction.java
  local/bd/dhis-web-linelisting-manpower/src/main/resources/META-INF/dhis/beans.xml
  local/bd/dhis-web-linelisting-manpower/src/main/resources/struts.xml
  local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/employeePost.vm
  local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/form.vm
  local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/javascript/form.js
  local/in/dhis-in-services/dhis-in-service-dbmanager/src/main/java/org/hisp/dhis/dbmanager/DataBaseManagerInterface.java
  local/in/dhis-in-services/dhis-in-service-dbmanager/src/main/java/org/hisp/dhis/dbmanager/mysql/MySQLDataBaseManager.java


--
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
=== added file 'local/bd/dhis-web-linelisting-manpower/src/main/java/org/hisp/dhis/ll/action/lldataentry/GetValidatePostVacantAction.java'
--- local/bd/dhis-web-linelisting-manpower/src/main/java/org/hisp/dhis/ll/action/lldataentry/GetValidatePostVacantAction.java	1970-01-01 00:00:00 +0000
+++ local/bd/dhis-web-linelisting-manpower/src/main/java/org/hisp/dhis/ll/action/lldataentry/GetValidatePostVacantAction.java	2010-11-14 14:20:26 +0000
@@ -0,0 +1,273 @@
+package org.hisp.dhis.ll.action.lldataentry;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+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.datavalue.DataValue;
+import org.hisp.dhis.datavalue.DataValueService;
+import org.hisp.dhis.dbmanager.DataBaseManagerInterface;
+import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.linelisting.LineListGroup;
+import org.hisp.dhis.linelisting.LineListOption;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.period.DailyPeriodType;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodService;
+import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.user.CurrentUserService;
+
+import com.opensymphony.xwork2.Action;
+
+public class GetValidatePostVacantAction
+    implements Action
+{
+    // --------------------------------------------------------------------------
+    // Dependency
+    // --------------------------------------------------------------------------
+
+    private SelectedStateManager selectedStateManager;
+
+    public void setSelectedStateManager( SelectedStateManager selectedStateManager )
+    {
+        this.selectedStateManager = selectedStateManager;
+    }
+
+    private DataBaseManagerInterface dataBaseManagerInterface;
+
+    public void setDataBaseManagerInterface( DataBaseManagerInterface dataBaseManagerInterface )
+    {
+        this.dataBaseManagerInterface = dataBaseManagerInterface;
+    }
+
+    private DataValueService dataValueService;
+
+    public void setDataValueService( DataValueService dataValueService )
+    {
+        this.dataValueService = dataValueService;
+    }
+
+    private CurrentUserService currentUserService;
+
+    public void setCurrentUserService( CurrentUserService currentUserService )
+    {
+        this.currentUserService = currentUserService;
+    }
+
+    private DataElementService dataElementService;
+
+    public void setDataElementService( DataElementService dataElementService )
+    {
+        this.dataElementService = dataElementService;
+    }
+
+    private DataElementCategoryService optionComboService;
+
+    public void setOptionComboService( DataElementCategoryService optionComboService )
+    {
+        this.optionComboService = optionComboService;
+    }
+    
+    private PeriodService periodService;
+
+    public void setPeriodService( PeriodService periodService )
+    {
+        this.periodService = periodService;
+    }
+
+    private I18nFormat format;
+
+    public void setFormat( I18nFormat format )
+    {
+        this.format = format;
+    }
+
+    // --------------------------------------------------------------------------
+    // Input/Output
+    // --------------------------------------------------------------------------
+    private String datavalue;
+
+    public void setDatavalue( String datavalue )
+    {
+        this.datavalue = datavalue;
+    }
+
+    private String dataValueMapKey;
+
+    public void setDataValueMapKey( String dataValueMapKey )
+    {
+        this.dataValueMapKey = dataValueMapKey;
+    }
+
+    private String message;
+
+    public String getMessage()
+    {
+        return message;
+    }
+    
+    public String reportingDate;
+
+    public void setReportingDate( String reportingDate )
+    {
+        this.reportingDate = reportingDate;
+    }
+
+    private String storedBy;
+    
+    private LineListGroup lineListGroup;
+
+    // --------------------------------------------------------------------------
+    // Action Implementation
+    // --------------------------------------------------------------------------
+
+    public String execute()
+    {
+        OrganisationUnit organisationunit = selectedStateManager.getSelectedOrganisationUnit();
+        
+        Period period = selectedStateManager.getSelectedPeriod();
+        
+        lineListGroup = selectedStateManager.getSelectedLineListGroup();
+        
+        LineListOption lineListOption = selectedStateManager.getSelectedLineListOption();
+        
+        String postLineListElementName = lineListGroup.getLineListElements().iterator().next().getShortName();
+        String lastWorkingDateLLElementName  = "lastworkingdate";
+        String departmentLineListName = lineListGroup.getName();
+        
+        // preparing map to filter records from linelist table
+        Map<String, String> llElementValueMap = new HashMap<String, String>();
+        llElementValueMap.put( postLineListElementName, lineListOption.getName() );
+        llElementValueMap.put( lastWorkingDateLLElementName, "null" );
+
+        int recordNo = dataBaseManagerInterface.getLLValueCountByLLElements( departmentLineListName, llElementValueMap, organisationunit, period );
+        
+        int dataValue = Integer.parseInt( datavalue );
+
+        if( dataValue > recordNo )
+        {
+            message = "Number of Sanctioned Position is " + dataValue + "And Number of Filled Position is " + recordNo + "\n Do you want to Add ?";
+            saveDataValue();
+            return SUCCESS;
+        }
+        else
+        {
+            message = "Number of Filled Position is equal to Number Sanctioned Post";
+            
+            return INPUT;
+        }
+    }
+
+    private void saveDataValue()
+    {
+        OrganisationUnit organisationunit = selectedStateManager.getSelectedOrganisationUnit();
+
+        Period historyPeriod = getHistoryPeriod();
+
+        storedBy = currentUserService.getCurrentUsername();
+
+        String[] partsOfDatavalueMap = dataValueMapKey.split( ":" );
+
+        int dataElementId = Integer.parseInt( partsOfDatavalueMap[1] );
+
+        int optionComboId = Integer.parseInt( partsOfDatavalueMap[2] );
+
+        DataElement dataElement = dataElementService.getDataElement( dataElementId );
+
+        DataElementCategoryOptionCombo optionCombo = optionComboService
+        .getDataElementCategoryOptionCombo( optionComboId );
+
+        if ( datavalue != null && datavalue.trim().length() == 0 )
+        {
+            datavalue = null;
+        }
+        if ( datavalue != null )
+        {
+            datavalue = datavalue.trim();
+        }
+
+        DataValue dataValueObj = dataValueService.getDataValue( organisationunit, dataElement, historyPeriod, optionCombo );
+
+        if ( storedBy == null )
+        {
+            storedBy = "[unknown]";
+        }
+
+        if ( dataValueObj == null )
+        {
+            if ( datavalue != null )
+            {
+                dataValueObj = new DataValue( dataElement, historyPeriod, organisationunit, datavalue, storedBy, new Date(), null,
+                    optionCombo );
+                dataValueService.addDataValue( dataValueObj );
+            }
+        }
+        else
+        {
+            dataValueObj.setValue( datavalue );
+            dataValueObj.setTimestamp( new Date() );
+            dataValueObj.setStoredBy( storedBy );
+
+            dataValueService.updateDataValue( dataValueObj );
+        }
+    }
+    
+    private Period getHistoryPeriod( )
+    {
+        //lineListGroup = selectedStateManager.getSelectedLineListGroup();
+        Date historyDate = format.parseDate( reportingDate );
+        System.out.println("Report Date is :::::::" + reportingDate );
+        
+        Period period;
+        period = periodService.getPeriod( 0 );
+        Period historyPeriod;
+        
+
+        if ( lineListGroup != null && lineListGroup.getPeriodType().getName().equalsIgnoreCase( "OnChange" ) )
+        {
+            PeriodType dailyPeriodType = new DailyPeriodType();
+            historyPeriod = dailyPeriodType.createPeriod( historyDate );
+            
+            System.out.println( reportingDate + " : " + historyPeriod );
+            if ( historyPeriod == null )
+            {
+                System.out.println( "historyPeriod is null" );
+            }
+            historyPeriod = reloadPeriodForceAdd( historyPeriod );
+        }
+        else
+        {
+            period = selectedStateManager.getSelectedPeriod();
+
+            period = reloadPeriodForceAdd( period );
+
+            historyPeriod = period;
+        }
+        
+        return historyPeriod;
+    }
+    
+    private final Period reloadPeriod( Period period )
+    {
+        return periodService.getPeriod( period.getStartDate(), period.getEndDate(), period.getPeriodType() );
+    }
+
+    private final Period reloadPeriodForceAdd( Period period )
+    {
+        Period storedPeriod = reloadPeriod( period );
+
+        if ( storedPeriod == null )
+        {
+            periodService.addPeriod( period );
+
+            return period;
+        }
+
+        return storedPeriod;
+    }
+
+}

=== modified file 'local/bd/dhis-web-linelisting-manpower/src/main/java/org/hisp/dhis/ll/action/lldataentry/SaveEmplyeePostAction.java'
--- local/bd/dhis-web-linelisting-manpower/src/main/java/org/hisp/dhis/ll/action/lldataentry/SaveEmplyeePostAction.java	2010-11-12 14:18:09 +0000
+++ local/bd/dhis-web-linelisting-manpower/src/main/java/org/hisp/dhis/ll/action/lldataentry/SaveEmplyeePostAction.java	2010-11-14 14:20:26 +0000
@@ -126,8 +126,6 @@
         
         int recordNo = dbManagerInterface.getMaxRecordNumber( department ) + 1;
         
-        System.out.println("Record No is :::::" + recordNo );
-        
         Map<String, String> llElementValuesMap = new HashMap<String, String>();
         LineListDataValue llDataValue = new LineListDataValue();
         for ( LineListElement linelistElement : linelistElements )

=== modified file 'local/bd/dhis-web-linelisting-manpower/src/main/resources/META-INF/dhis/beans.xml'
--- local/bd/dhis-web-linelisting-manpower/src/main/resources/META-INF/dhis/beans.xml	2010-11-12 14:18:09 +0000
+++ local/bd/dhis-web-linelisting-manpower/src/main/resources/META-INF/dhis/beans.xml	2010-11-14 14:20:26 +0000
@@ -457,7 +457,7 @@
     class="org.hisp.dhis.ll.action.lldataentry.SaveValueAction" scope="prototype">
         <property name="currentUserService"
             ref="org.hisp.dhis.user.CurrentUserService"/>
-
+	
         <property name="dataBaseManagerInterface">
             <ref bean="org.hisp.dhis.dbmanager.DataBaseManagerInterface"/>
         </property>
@@ -474,8 +474,19 @@
         </property>
 
     </bean>
-
-
+	
+	<bean id="org.hisp.dhis.ll.action.lldataentry.GetValidatePostVacantAction"
+    class="org.hisp.dhis.ll.action.lldataentry.GetValidatePostVacantAction" scope="prototype">
+		<property name="selectedStateManager" ref="org.hisp.dhis.ll.action.lldataentry.SelectedStateManager"/>
+		<property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService"/>
+        <property name="dataBaseManagerInterface" ref="org.hisp.dhis.dbmanager.DataBaseManagerInterface"/>
+        <property name="periodService" ref="org.hisp.dhis.period.PeriodService"/>
+        <property name="dataValueService" ref="org.hisp.dhis.datavalue.DataValueService"/>
+		<property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService"/>
+		<property name="optionComboService" ref="org.hisp.dhis.dataelement.DataElementCategoryService"/>
+	</bean>
+	
+	
     <bean id="org.hisp.dhis.ll.action.llValidation.GetLineListValidationRuleListAction"
     class="org.hisp.dhis.ll.action.llValidation.GetLineListValidationRuleListAction">
         <property name="validationRuleService">

=== modified file 'local/bd/dhis-web-linelisting-manpower/src/main/resources/struts.xml'
--- local/bd/dhis-web-linelisting-manpower/src/main/resources/struts.xml	2010-11-12 14:18:09 +0000
+++ local/bd/dhis-web-linelisting-manpower/src/main/resources/struts.xml	2010-11-14 14:20:26 +0000
@@ -425,6 +425,15 @@
             <result name="input" type="velocity-xml">/dhis-web-linelisting-mp/responseInput.vm</result>
             <param name="onExceptionReturn">plainTextError</param>
         </action>
+		
+		<action name="getValidatePostVacant"
+            class="org.hisp.dhis.ll.action.lldataentry.GetValidatePostVacantAction">
+			<!--<result name="success" type="velocity">/main.vm</result>
+			<param name="page">/dhis-web-linelisting-mp/responseSuccess.vm</param>-->
+            <result name="success" type="velocity-xml">/dhis-web-linelisting-mp/responseSuccess.vm</result>
+            <result name="input" type="velocity-xml">/dhis-web-linelisting-mp/responseInput.vm</result>
+            <param name="onExceptionReturn">plainTextError</param>
+        </action>
         
     <!-- Org unit -->
         <action name="getOrgUnitDetails"

=== modified file 'local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/employeePost.vm'
--- local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/employeePost.vm	2010-11-12 14:18:09 +0000
+++ local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/employeePost.vm	2010-11-14 14:20:26 +0000
@@ -18,7 +18,7 @@
 			</td>
 			<td>
 				<input type="hidden" name="groupid" id="groupid" value="$linelistGroupId">
-				<input type="text" name="reportingDate" id="reportingDate" value="$reportingDate">
+				<input type="hidden" name="reportingDate" id="reportingDate" value="$reportingDate">
 			</td>
 		</tr>
 		

=== modified file 'local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/form.vm'
--- local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/form.vm	2010-11-12 14:18:09 +0000
+++ local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/form.vm	2010-11-14 14:20:26 +0000
@@ -3,6 +3,12 @@
 
 <script>
     var rowCount = 0;
+    var sancPos = 0;
+    
+    function setSancPost( curSancPos )
+    {
+    	sancPos = curSancPos;
+    }
 </script>
 
 <form id="LineListDataEntryForm" action="saveValueAction.action" method="post" onsubmit="return calMaxRecords()">
@@ -22,9 +28,10 @@
 		<tr>
 			<td align="center">$count1</td>
 			<td>$dataElementName</td>
-			<td align="center"><input type="text" id="$dataValueMapKey" name="$dataValueMapKey" value="$!dataValue.value" />
+			<td align="center"><input type="text" id="$dataValueMapKey" name="$dataValueMapKey" value="$!dataValue.value" onchange="setSancPost(this.value)"/>
+			<script>sancPos='$!dataValue.value';</script>
 			#if( $sactionedPostdataelement == $dataValueMapKey)
-				<input type="button" value="Add" onclick="return addEmployeePostDetail( '$dataValueMapKey' )">
+				<input type="button" value="Add" onclick="validatePostVacant( '$dataValueMapKey' )">
 			#end
 			</td>
 		<tr>		
@@ -214,7 +221,6 @@
                     if (element==temparray[k])
                     {
                         flag=1;
-
                     }
                 }
 
@@ -225,21 +231,6 @@
             }
             return true;
 		}
-		
-		function addEmployeePostDetail( dataValueMapKey ) 
-		{
-			 var reportingDate = document.getElementById( "reportingDate" ).value;
-			var url = 'showEmployeePostForm.action?reportingDate=' + reportingDate;
-			$('#contentDataRecord').dialog('destroy').remove();
-		    $('<div id="contentDataRecord" style="z-index: 1;">' ).load(url).dialog({
-	        title: 'Employee Post Detail',
-			maximize: true, 
-			closable: true,
-			modal:true,
-			overlay:{background:'#000000', opacity:0.1},
-			width: 420,
-  	        height: 380
-  		});
 }
 
 </script>
\ No newline at end of file

=== modified file 'local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/javascript/form.js'
--- local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/javascript/form.js	2010-11-12 14:18:09 +0000
+++ local/bd/dhis-web-linelisting-manpower/src/main/webapp/dhis-web-linelisting-mp/javascript/form.js	2010-11-14 14:20:26 +0000
@@ -1,8 +1,36 @@
 
 var currentPDSCode;
+
+function validatePostVacant( dataValueMapKey )
+{
+	var reportingDate = document.getElementById('reportingDate').value;
+	
+	alert( sancPos +" : " + reportingDate  );
+	var request = new Request();
+	request.setResponseTypeXML('element');
+	request.setCallbackSuccess( elementReceived );
+	request.send( 'getValidatePostVacant.action?datavalue=' + sancPos + '&dataValueMapKey=' + dataValueMapKey + '&reportingDate=' + reportingDate);
+	//window.location.href = 'getValidatePostVacant.action?datavalue=' + sancPos + '&dataValueMapKey=' + dataValueMapKey + '&reportingDate=' + reportingDate;
+}
+
+function elementReceived( recordNo )
+{
+	var type = recordNo.getAttribute( "type" );
+	if (type == 'success' )
+	{
+		if( confirm ( recordNo.firstChild.nodeValue ) )
+		{
+			showEmployeePostForm();
+		}
+	}
+	else if (type == 'input' )
+	{
+		alert( recordNo.firstChild.nodeValue );
+	}
+
+}
 function getEmployeeName( pdsCodeField, pdsCode )
 	{
-	 
 		currentPDSCode = pdsCodeField;
 		var request = new Request();
 		request.setResponseTypeXML( 'employee' );
@@ -14,7 +42,6 @@
 {
 	//messageElement = employeeElement.getElementsByTagName( "message" )[0];
 	var type = employeeElement.getAttribute( "type" );
-	
 	if (type == 'success') 
 	{
 		if( confirm( employeeElement.firstChild.nodeValue ) )
@@ -132,3 +159,22 @@
 
 }
 
+function showEmployeePostForm() 
+{
+	//alert( dataValueMapKey );
+	var reportingDate = document.getElementById( "reportingDate" ).value;
+	var url = 'showEmployeePostForm.action?reportingDate=' + reportingDate;
+	$('#contentDataRecord').dialog('destroy').remove();
+    $('<div id="contentDataRecord" style="z-index: 1;">' ).load(url).dialog({
+    title: 'Employee Post Detail',
+	maximize: true, 
+	closable: true,
+	modal:true,
+	overlay:{background:'#000000', opacity:0.1},
+	width: 420,
+    height: 380
+});
+}
+
+
+

=== modified file 'local/in/dhis-in-services/dhis-in-service-dbmanager/src/main/java/org/hisp/dhis/dbmanager/DataBaseManagerInterface.java'
--- local/in/dhis-in-services/dhis-in-service-dbmanager/src/main/java/org/hisp/dhis/dbmanager/DataBaseManagerInterface.java	2010-11-12 14:18:09 +0000
+++ local/in/dhis-in-services/dhis-in-service-dbmanager/src/main/java/org/hisp/dhis/dbmanager/DataBaseManagerInterface.java	2010-11-14 14:20:26 +0000
@@ -35,6 +35,8 @@
 
     public boolean updateLLValue( List<LineListDataValue> llDataValuesList, String tableName );
     
+    public int getLLValueCountByLLElements( String tablename, Map<String,String> llElementValueMap, Source source, Period  period );
+    
     public List<LineListDataValue> getLLValuesFilterByLLElements( String tableName, Map<String,String> llElementValueMap, Source source, Period  period );
 
     public List<LineListDataValue> getLLValuesByLLElementValue( String tableName, String llElementName, String llElementValue, Source source, Period  period );

=== modified file 'local/in/dhis-in-services/dhis-in-service-dbmanager/src/main/java/org/hisp/dhis/dbmanager/mysql/MySQLDataBaseManager.java'
--- local/in/dhis-in-services/dhis-in-service-dbmanager/src/main/java/org/hisp/dhis/dbmanager/mysql/MySQLDataBaseManager.java	2010-11-12 14:18:09 +0000
+++ local/in/dhis-in-services/dhis-in-service-dbmanager/src/main/java/org/hisp/dhis/dbmanager/mysql/MySQLDataBaseManager.java	2010-11-14 14:20:26 +0000
@@ -665,6 +665,62 @@
 
     }
 
+    public int getLLValueCountByLLElements( String tableName, Map<String, String> llElementValueMap, Source source, Period period )
+    {
+        String columnDefinition = "";
+        int noOfRows = 0;
+        if ( source != null )
+        {
+            //columnDefinition += "SELECT COUNT(*) FROM " + tableName + " WHERE periodid = " + period.getId() + " AND sourceid = " + source.getId();
+            columnDefinition += "SELECT COUNT(*) FROM " + tableName + " WHERE sourceid = " + source.getId();
+
+            List<String> llElementNames = new ArrayList<String>( llElementValueMap.keySet() );
+            Iterator<String> llENamesIterator = llElementNames.iterator();
+            while ( llENamesIterator.hasNext() )
+            {
+                String lleName = llENamesIterator.next();
+
+                String lleValue = llElementValueMap.get( lleName );
+
+                if ( lleValue.equalsIgnoreCase( "notnull" ) )
+                {
+                    columnDefinition += " AND " + lleName + " IS NOT NULL";
+                } else
+                {
+                    if ( lleValue.equalsIgnoreCase( "null" ) )
+                    {
+                        columnDefinition += " AND " + lleName + " IS NULL";
+                    } else
+                    {
+                        columnDefinition += " AND " + lleName + " LIKE '" + lleValue + "'";
+                    }
+                }
+            }
+        
+
+            columnDefinition += " order by recordnumber";
+            System.out.println( columnDefinition );
+
+            try
+            {
+                SqlRowSet rs = jdbcTemplate.queryForRowSet( columnDefinition );
+               
+                if( rs.next() )
+                {
+                    noOfRows = rs.getInt( 1 );
+                }
+            } 
+            catch ( Exception e )
+            {
+                e.printStackTrace();
+            }
+        }
+        return noOfRows;
+    }
+
+    
+    
+    
     public List<LineListDataValue> getLLValuesSortBy( String tableName, String sortBy, Source source, Period period )
     {
         String columnDefinition = "";