Implement button to create a new personal expense sheet
Modified behavior of create and edit expense sheet form, to disable resource fields if it is personal. FEA: ItEr76S28UserDashboard
This commit is contained in:
parent
44f8c1fba6
commit
1649e83479
9 changed files with 221 additions and 31 deletions
|
|
@ -228,4 +228,8 @@ public class ExpenseSheet extends IntegrationEntity implements IHumanIdentifiabl
|
|||
this.personal = personal;
|
||||
}
|
||||
|
||||
public boolean isNotPersonal() {
|
||||
return !personal;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -40,6 +40,7 @@ import org.libreplan.web.common.BaseCRUDController;
|
|||
import org.libreplan.web.common.Level;
|
||||
import org.libreplan.web.common.Util;
|
||||
import org.libreplan.web.common.components.bandboxsearch.BandboxSearch;
|
||||
import org.libreplan.web.common.entrypoints.IURLHandlerRegistry;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.WrongValueException;
|
||||
|
|
@ -63,7 +64,8 @@ import org.zkoss.zul.Textbox;
|
|||
*
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
public class ExpenseSheetCRUDController extends BaseCRUDController<ExpenseSheet> {
|
||||
public class ExpenseSheetCRUDController extends
|
||||
BaseCRUDController<ExpenseSheet> implements IExpenseSheetCRUDController {
|
||||
|
||||
private static final org.apache.commons.logging.Log LOG = LogFactory
|
||||
.getLog(ExpenseSheetCRUDController.class);
|
||||
|
|
@ -89,6 +91,15 @@ public class ExpenseSheetCRUDController extends BaseCRUDController<ExpenseSheet>
|
|||
|
||||
private ExpenseSheetLineRenderer expenseSheetLineRenderer = new ExpenseSheetLineRenderer();
|
||||
|
||||
private IURLHandlerRegistry URLHandlerRegistry;
|
||||
|
||||
@Override
|
||||
public void doAfterCompose(Component comp) throws Exception {
|
||||
super.doAfterCompose(comp);
|
||||
URLHandlerRegistry.getRedirectorFor(IExpenseSheetCRUDController.class)
|
||||
.register(this, page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() throws ValidationException {
|
||||
expenseSheetModel.confirmSave();
|
||||
|
|
@ -525,8 +536,7 @@ public class ExpenseSheetCRUDController extends BaseCRUDController<ExpenseSheet>
|
|||
|
||||
@Override
|
||||
protected void initCreate() {
|
||||
expenseSheetModel.initCreate();
|
||||
loadComponentsEditWindow();
|
||||
initCreate(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -563,4 +573,21 @@ public class ExpenseSheetCRUDController extends BaseCRUDController<ExpenseSheet>
|
|||
return Util.getMoneyFormat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void goToCreatePersonalExpenseSheet() {
|
||||
state = CRUDControllerState.CREATE;
|
||||
initCreate(true);
|
||||
showEditWindow();
|
||||
}
|
||||
|
||||
private void initCreate(boolean personal) {
|
||||
expenseSheetModel.initCreate(personal);
|
||||
loadComponentsEditWindow();
|
||||
}
|
||||
|
||||
public String getResource() {
|
||||
Resource resource = expenseSheetModel.getResource();
|
||||
return resource == null ? "" : resource.getShortDescription();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,9 @@ import org.libreplan.business.orders.daos.ISumExpensesDAO;
|
|||
import org.libreplan.business.orders.entities.Order;
|
||||
import org.libreplan.business.orders.entities.OrderElement;
|
||||
import org.libreplan.business.orders.entities.OrderLineGroup;
|
||||
import org.libreplan.business.resources.entities.Resource;
|
||||
import org.libreplan.business.users.entities.User;
|
||||
import org.libreplan.web.UserUtil;
|
||||
import org.libreplan.web.common.IntegrationEntityModel;
|
||||
import org.libreplan.web.common.concurrentdetection.OnConcurrentModification;
|
||||
import org.libreplan.web.resources.worker.WorkerModel;
|
||||
|
|
@ -90,6 +93,8 @@ public class ExpenseSheetModel extends IntegrationEntityModel implements IExpens
|
|||
|
||||
private Set<ExpenseSheetLine> deletedExpenseSheetLinesSet = new HashSet<ExpenseSheetLine>();
|
||||
|
||||
private Resource resource;
|
||||
|
||||
public void setExpenseSheet(ExpenseSheet expenseSheet) {
|
||||
this.expenseSheet = expenseSheet;
|
||||
}
|
||||
|
|
@ -142,7 +147,7 @@ public class ExpenseSheetModel extends IntegrationEntityModel implements IExpens
|
|||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public void initCreate() {
|
||||
public void initCreate(boolean personal) {
|
||||
this.setSelectedProject(null);
|
||||
resetExpenseSheetLineDTO();
|
||||
this.expenseSheet = ExpenseSheet.create();
|
||||
|
|
@ -155,6 +160,28 @@ public class ExpenseSheetModel extends IntegrationEntityModel implements IExpens
|
|||
setDefaultCode();
|
||||
}
|
||||
deletedExpenseSheetLinesSet = new HashSet<ExpenseSheetLine>();
|
||||
|
||||
expenseSheet.setPersonal(personal);
|
||||
resource = initResource();
|
||||
}
|
||||
|
||||
private Resource initResource() {
|
||||
if (expenseSheet.isNotPersonal()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
SortedSet<ExpenseSheetLine> expenseSheetLines = expenseSheet
|
||||
.getExpenseSheetLines();
|
||||
if (!expenseSheetLines.isEmpty()) {
|
||||
return expenseSheetLines.iterator().next().getResource();
|
||||
}
|
||||
|
||||
User user = UserUtil.getUserFromSession();
|
||||
if (user.isBound()) {
|
||||
return user.getWorker();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -166,6 +193,7 @@ public class ExpenseSheetModel extends IntegrationEntityModel implements IExpens
|
|||
this.expenseSheet = getFromDB(expenseSheet);
|
||||
initOldCodes();
|
||||
deletedExpenseSheetLinesSet = new HashSet<ExpenseSheetLine>();
|
||||
resource = initResource();
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
|
|
@ -252,9 +280,13 @@ public class ExpenseSheetModel extends IntegrationEntityModel implements IExpens
|
|||
|
||||
@Override
|
||||
public void addExpenseSheetLine() {
|
||||
if (getExpenseSheet() != null) {
|
||||
this.getExpenseSheetLineDTO().setExpenseSheet(getExpenseSheet());
|
||||
getExpenseSheet().add(this.getExpenseSheetLineDTO());
|
||||
if (expenseSheet != null) {
|
||||
ExpenseSheetLine line = this.getExpenseSheetLineDTO();
|
||||
line.setExpenseSheet(expenseSheet);
|
||||
if (expenseSheet.isPersonal()) {
|
||||
line.setResource(resource);
|
||||
}
|
||||
expenseSheet.add(line);
|
||||
}
|
||||
this.resetExpenseSheetLineDTO();
|
||||
}
|
||||
|
|
@ -316,4 +348,9 @@ public class ExpenseSheetModel extends IntegrationEntityModel implements IExpens
|
|||
return selectedProject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource getResource() {
|
||||
return resource;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* This file is part of LibrePlan
|
||||
*
|
||||
* Copyright (C) 2012 Igalia, S.L.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.libreplan.web.expensesheet;
|
||||
|
||||
import org.libreplan.business.expensesheet.entities.ExpenseSheet;
|
||||
import org.libreplan.web.common.entrypoints.EntryPoint;
|
||||
import org.libreplan.web.common.entrypoints.EntryPoints;
|
||||
|
||||
/**
|
||||
* Entry points for CRUD actions over a {@link ExpenseSheet}
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
@EntryPoints(page = "/expensesheet/expenseSheet.zul", registerAs = "expenseSheetCRUDController")
|
||||
public interface IExpenseSheetCRUDController {
|
||||
|
||||
@EntryPoint("create")
|
||||
void goToCreatePersonalExpenseSheet();
|
||||
|
||||
@EntryPoint("edit")
|
||||
void goToEditForm(ExpenseSheet expenseSheet);
|
||||
|
||||
}
|
||||
|
|
@ -26,6 +26,8 @@ import org.libreplan.business.expensesheet.entities.ExpenseSheet;
|
|||
import org.libreplan.business.expensesheet.entities.ExpenseSheetLine;
|
||||
import org.libreplan.business.orders.entities.Order;
|
||||
import org.libreplan.business.orders.entities.OrderElement;
|
||||
import org.libreplan.business.resources.entities.Resource;
|
||||
import org.libreplan.business.users.entities.User;
|
||||
import org.libreplan.web.common.IIntegrationEntityModel;
|
||||
|
||||
/**
|
||||
|
|
@ -39,7 +41,7 @@ public interface IExpenseSheetModel extends IIntegrationEntityModel {
|
|||
|
||||
void prepareToList();
|
||||
|
||||
void initCreate();
|
||||
void initCreate(boolean personal);
|
||||
|
||||
void prepareToEdit(ExpenseSheet expenseSheet);
|
||||
|
||||
|
|
@ -67,4 +69,16 @@ public interface IExpenseSheetModel extends IIntegrationEntityModel {
|
|||
|
||||
void generateExpenseSheetLineCodesIfIsNecessary();
|
||||
|
||||
/**
|
||||
* Returns the {@link Resource} associated to the <b>personal</b>
|
||||
* {@link ExpenseSheet}.<br />
|
||||
*
|
||||
* In <b>personal</b> {@link ExpenseSheet ExpenseSheets} all
|
||||
* {@link ExpenseSheetLine} has the same {@link Resource}.<br />
|
||||
*
|
||||
* It tries to get the {@link Resource} from the first {@link ExpenseSheet}
|
||||
* and if not it tries to get it from bound {@link User}.
|
||||
*/
|
||||
Resource getResource();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* This file is part of LibrePlan
|
||||
*
|
||||
* Copyright (C) 2012 Igalia, S.L.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.libreplan.web.users.dashboard;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.libreplan.web.expensesheet.IExpenseSheetCRUDController;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.util.GenericForwardComposer;
|
||||
|
||||
/**
|
||||
* Controller for "Expenses" area in the user dashboard window
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class ExpensesAreaController extends GenericForwardComposer {
|
||||
|
||||
@Resource
|
||||
private IExpenseSheetCRUDController expenseSheetCRUDController;
|
||||
|
||||
@Override
|
||||
public void doAfterCompose(Component comp) throws Exception {
|
||||
super.doAfterCompose(comp);
|
||||
comp.setAttribute("controller", this);
|
||||
}
|
||||
|
||||
public void newExpenseSheet() {
|
||||
expenseSheetCRUDController.goToCreatePersonalExpenseSheet();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -54,7 +54,8 @@
|
|||
access="ROLE_ADMINISTRATION" />
|
||||
<intercept-url pattern="/workreports/workReportTypes.zul"
|
||||
access="ROLE_ADMINISTRATION" />
|
||||
<intercept-url pattern="/expensesheet/**" access="ROLE_ADMINISTRATION,ROLE_EXPENSE_TRACKING"/>
|
||||
<!-- FIXME review when role for bound users is set -->
|
||||
<!-- intercept-url pattern="/expensesheet/**" access="ROLE_ADMINISTRATION,ROLE_EXPENSE_TRACKING"/ -->
|
||||
<intercept-url pattern="/**" access="IS_AUTHENTICATED_FULLY" />
|
||||
|
||||
<!-- These have been added because of auto-config is false now in order
|
||||
|
|
|
|||
|
|
@ -88,19 +88,33 @@
|
|||
<caption label="${i18n:_('Identification')}" />
|
||||
<separator bar="false" spacing="5px" orient="horizontal"/>
|
||||
<vbox>
|
||||
<hbox>
|
||||
<label value="${i18n:_('Code')}" />
|
||||
<textbox id="txtExpenseCode" width="350px" value="@{controller.expenseSheet.code}"
|
||||
constraint="@{controller.checkConstraintExpendeCode}"
|
||||
disabled="@{controller.expenseSheet.codeAutogenerated}" />
|
||||
<checkbox id="generateCode" label="${i18n:_('Generate code')}"
|
||||
onCheck="controller.onCheckGenerateCode(event)"
|
||||
checked="@{controller.expenseSheet.codeAutogenerated}" />
|
||||
</hbox>
|
||||
<hbox>
|
||||
<label value="${i18n:_('Description')}" />
|
||||
<textbox width="500px" value="@{controller.expenseSheet.description}"/>
|
||||
</hbox>
|
||||
<grid fixedLayout="true">
|
||||
<columns>
|
||||
<column width="100px" />
|
||||
<column />
|
||||
</columns>
|
||||
<rows>
|
||||
<row>
|
||||
<label value="${i18n:_('Code')}" />
|
||||
<hbox>
|
||||
<textbox id="txtExpenseCode" value="@{controller.expenseSheet.code}"
|
||||
constraint="@{controller.checkConstraintExpendeCode}"
|
||||
disabled="@{controller.expenseSheet.codeAutogenerated}" />
|
||||
<checkbox id="generateCode" label="${i18n:_('Generate code')}"
|
||||
onCheck="controller.onCheckGenerateCode(event)"
|
||||
checked="@{controller.expenseSheet.codeAutogenerated}" />
|
||||
</hbox>
|
||||
</row>
|
||||
<row>
|
||||
<label value="${i18n:_('Description')}" />
|
||||
<textbox width="400px" value="@{controller.expenseSheet.description}"/>
|
||||
</row>
|
||||
<row visible="@{controller.expenseSheet.personal}">
|
||||
<label value="${i18n:_('Resource')}" />
|
||||
<label value="@{controller.resource}" />
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
</vbox>
|
||||
</groupbox>
|
||||
<separator bar="false" spacing="5px" orient="horizontal"/>
|
||||
|
|
@ -151,12 +165,14 @@
|
|||
|
||||
<separator bar="false" spacing="10px" orient="vertical"/>
|
||||
|
||||
<label value="${i18n:_('Resource')}" />
|
||||
<bandboxSearch id="bandboxResource"
|
||||
widthBandbox="285px"
|
||||
widthListbox="400px"
|
||||
finder="ResourceInExpenseSheetBandboxFinder"
|
||||
selectedElement="@{controller.expenseSheetLineDTO.resource, access='both'}"/>
|
||||
<div visible="@{controller.expenseSheet.notPersonal}">
|
||||
<label value="${i18n:_('Resource')}" />
|
||||
<bandboxSearch id="bandboxResource"
|
||||
widthBandbox="285px"
|
||||
widthListbox="400px"
|
||||
finder="ResourceInExpenseSheetBandboxFinder"
|
||||
selectedElement="@{controller.expenseSheetLineDTO.resource, access='both'}"/>
|
||||
</div>
|
||||
|
||||
<separator bar="false" spacing="10px" orient="vertical"/>
|
||||
<button onClick="controller.addExpenseSheetLine();" label="${i18n:_('New')}"/>
|
||||
|
|
@ -170,7 +186,8 @@
|
|||
<column label="${i18n:_('Value')}" />
|
||||
<column label="${i18n:_('Concept')}" />
|
||||
<column label="${i18n:_('Date')}" />
|
||||
<column label="${i18n:_('Resource')}" width="275px" />
|
||||
<column label="${i18n:_('Resource')}" width="275px"
|
||||
visible="@{controller.expenseSheet.notPersonal}" />
|
||||
<column label="${i18n:_('Code')}" />
|
||||
<column label="${i18n:_('Operations')}" />
|
||||
</columns>
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
<http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<groupbox>
|
||||
<groupbox apply="org.libreplan.web.users.dashboard.ExpensesAreaController">
|
||||
<caption label="${i18n:_('Expenses')}" />
|
||||
|
||||
<grid mold="paging" pageSize="10">
|
||||
|
|
@ -32,6 +32,7 @@
|
|||
</columns>
|
||||
</grid>
|
||||
|
||||
<button label="${i18n:_('New expense sheet')}" />
|
||||
<button label="${i18n:_('New expense sheet')}"
|
||||
onClick="controller.newExpenseSheet();" />
|
||||
|
||||
</groupbox>
|
||||
Loading…
Add table
Reference in a new issue