Author: jpepin Date: 2010-05-27 12:42:24 +0200 (Thu, 27 May 2010) New Revision: 2912 Url: http://chorem.org/repositories/revision/lima/2912 Log: Correction cr?\195?\169ation des p?\195?\169riodes financi?\195?\168res lors de la cr?\195?\169ation d'un exercice. Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FinancialPeriodComboBoxRenderer.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FiscalPeriodComboBoxRenderer.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/AddPeriod.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/model/FiscalPeriodTableModel.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java 2010-05-27 09:26:39 UTC (rev 2911) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java 2010-05-27 10:42:24 UTC (rev 2912) @@ -1,8 +1,10 @@ package org.chorem.lima.business.accountingrules; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; +import java.util.GregorianCalendar; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -104,9 +106,7 @@ if (fiscalPeriodDAO.findAll().size()!=0){ TopiaQuery query = fiscalPeriodDAO.createQuery(); - fiscalPeriodDAO.findAllByQuery(query); - query.addOrderDesc(FiscalPeriod.END_DATE); - + query.addOrderDesc(FiscalPeriod.END_DATE); //get the last fiscal period FiscalPeriod lastFiscalPeriod = fiscalPeriodDAO.findByQuery(query); @@ -138,18 +138,40 @@ financialPeriodService = new FinancialPeriodServiceImpl(); } - // FinancialPeriod of 1 month are created + // FinancialPeriods of 1 month are created Date loopDate = beginDate; - while (loopDate.compareTo(endDate) <= 0) { - Date loopUpperDate = DateUtils.addMonths(loopDate, 1); - Date periodEndDate = DateUtils.addMilliseconds(loopUpperDate, -1); + while (loopDate.before(endDate)) { FinancialPeriod financialPeriod = new FinancialPeriodImpl(); - financialPeriod.setBeginDate(loopDate); + Date periodBeginDate = new Date(); + Date periodEndDate = new Date(); + // if first period dd/mm/yy to 31/mm/yy + if (loopDate.equals(beginDate)){ + //dd/mm/yy + periodBeginDate = beginDate; + //31/mm/yy + periodEndDate = DateUtils.addMonths(loopDate, 1); + periodEndDate = DateUtils.truncate(periodEndDate, Calendar.MONTH); + periodEndDate = DateUtils.addMilliseconds(periodEndDate, -1); + } else { + //other period 01/mm/yy to 31/mm/yy + periodBeginDate = DateUtils.truncate(loopDate, Calendar.MONTH); + periodEndDate = DateUtils.addMonths(loopDate, 1); + periodEndDate = DateUtils.truncate(periodEndDate, Calendar.MONTH); + periodEndDate = DateUtils.addMilliseconds(periodEndDate, -1); + } + //set period + financialPeriod.setBeginDate(periodBeginDate); financialPeriod.setEndDate(periodEndDate); - fiscalPeriod.addFinancialPeriod(financialPeriod); - loopDate = loopUpperDate; + //create it financialPeriodService.createFinancialPeriodWithTransaction(financialPeriod, transaction); + //incremente loop + loopDate = DateUtils.addMonths(loopDate, 1); } + //create last period 01/mm/yy to dd/mm/yy + FinancialPeriod financialPeriod = new FinancialPeriodImpl(); + financialPeriod.setBeginDate(DateUtils.truncate(loopDate, Calendar.MONTH)); + financialPeriod.setEndDate(endDate); + financialPeriodService.createFinancialPeriodWithTransaction(financialPeriod, transaction); } catch (TopiaException ex) { doCatch(transaction, ex, log); Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2010-05-27 09:26:39 UTC (rev 2911) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2010-05-27 10:42:24 UTC (rev 2912) @@ -185,7 +185,6 @@ FiscalPeriodDAO fiscalPeriodDAO = LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); TopiaQuery query = fiscalPeriodDAO.createQuery(); - fiscalPeriodDAO.findAllByQuery(query); query.addOrderDesc(FiscalPeriod.END_DATE); //get the last fiscal period Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FinancialPeriodComboBoxRenderer.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FinancialPeriodComboBoxRenderer.java 2010-05-27 09:26:39 UTC (rev 2911) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FinancialPeriodComboBoxRenderer.java 2010-05-27 10:42:24 UTC (rev 2912) @@ -21,6 +21,7 @@ import static org.nuiton.i18n.I18n._; import java.awt.Component; +import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; @@ -40,21 +41,13 @@ boolean isSelected, boolean cellHasFocus) { // TODO Auto-generated method stub - - String[] monthName = {_("lima.date.january"), _("lima.date.february"), - _("lima.date.march"), _("lima.date.april"), _("lima.date.may"), - _("lima.date.june"), _("lima.date.july"), _("lima.date.august"), - _("lima.date.september"), _("lima.date.october"), - _("lima.date.november"), _("lima.date.december")}; JLabel label = new JLabel(); - FinancialPeriod financialperiod = (FinancialPeriod) value; - if (financialperiod != null){ - Date d = financialperiod.getBeginDate(); - Calendar beginDate = Calendar.getInstance(); - beginDate.setTime(d); - int year = beginDate.get(Calendar.YEAR); - label.setText(monthName[beginDate.get(Calendar.MONTH)]+" "+String.valueOf(year)); + FinancialPeriod financialPeriod = (FinancialPeriod) value; + if (financialPeriod != null){ + SimpleDateFormat simpleDateFormat + = new SimpleDateFormat("dd MMM yy"); + label.setText(simpleDateFormat.format(financialPeriod.getBeginDate())+" - "+simpleDateFormat.format(financialPeriod.getEndDate())); } return label; } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FiscalPeriodComboBoxRenderer.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FiscalPeriodComboBoxRenderer.java 2010-05-27 09:26:39 UTC (rev 2911) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FiscalPeriodComboBoxRenderer.java 2010-05-27 10:42:24 UTC (rev 2912) @@ -19,6 +19,7 @@ package org.chorem.lima.ui.combobox; import java.awt.Component; +import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; @@ -41,12 +42,11 @@ JLabel label = new JLabel(); FiscalPeriod fiscalPeriod = (FiscalPeriod) value; - if (fiscalPeriod != null){ - Date d = fiscalPeriod.getBeginDate(); - Calendar beginDate = Calendar.getInstance(); - beginDate.setTime(d); - int date = beginDate.get(Calendar.YEAR); - label.setText(String.valueOf(date)); + if (fiscalPeriod != null){ + SimpleDateFormat simpleDateFormat = + new SimpleDateFormat("dd MMM yy"); + label.setText(simpleDateFormat.format(fiscalPeriod.getBeginDate()) + + " - " + simpleDateFormat.format(fiscalPeriod.getEndDate())); } return label; } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodTableModel.java 2010-05-27 09:26:39 UTC (rev 2911) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodTableModel.java 2010-05-27 10:42:24 UTC (rev 2912) @@ -144,12 +144,11 @@ closedPeriodicEntryBook.getFinancialPeriod(); SimpleDateFormat simpleDateFormat - = new SimpleDateFormat("MMMMM yyyy"); + = new SimpleDateFormat("dd MMM yyyy"); switch (columnIndex) { case 0: - result = StringUtils.capitalize(simpleDateFormat. - format(financialPeriod.getBeginDate())); + result = simpleDateFormat.format(financialPeriod.getBeginDate())+" - "+simpleDateFormat.format(financialPeriod.getEndDate()); break; case 1: result = entryBook.getCode()+" - "+entryBook.getLabel(); Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/AddPeriod.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/AddPeriod.jaxx 2010-05-27 09:26:39 UTC (rev 2911) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/AddPeriod.jaxx 2010-05-27 10:42:24 UTC (rev 2912) @@ -50,6 +50,7 @@ // get end date Calendar calendarEnd = Calendar.getInstance(); endDate = DateUtils.addYears(beginDate, 1); + endDate = DateUtils.addDays(endDate, -1); getEndDatePicker().setDate(endDate); protected void performOk() { Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/model/FiscalPeriodTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/model/FiscalPeriodTableModel.java 2010-05-27 09:26:39 UTC (rev 2911) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/model/FiscalPeriodTableModel.java 2010-05-27 10:42:24 UTC (rev 2912) @@ -145,14 +145,14 @@ FiscalPeriod fiscalPeriod = periods.get(rowIndex); if (fiscalPeriod != null){ - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMMMM yyyy"); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMM yyyy"); switch (columnIndex) { case 0: - result = StringUtils.capitalize(simpleDateFormat. - format(fiscalPeriod.getBeginDate())) - + " - " + StringUtils.capitalize(simpleDateFormat. - format(fiscalPeriod.getEndDate())); + result = simpleDateFormat. + format(fiscalPeriod.getBeginDate()) + + " - " + simpleDateFormat. + format(fiscalPeriod.getEndDate()); break; case 1: if(fiscalPeriod.getLocked()){