/*
* TableModelFoundClients.java
*
* Created on 23 Декабрь 2007 г., 17:56
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package clips.service;
import clips.delegate.contract.ServisePriceData;
import cli_fmw.main.ClipsException;
import clips.delegate.service.SerRenLocal;
import framework.utils.Converter;
import cli_fmw.utils.ErrorValue;
import cli_fmw.utils.MessageBox;
import clips.delegate.directory.ro.DirectoryCollaboratorItem;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import javax.swing.table.AbstractTableModel;
/**
* Модель таблицы, отображающая список услуг
* Необходимо передать serRenLocalList
* @author ViP
*/
public class TableModelSerRenList extends AbstractTableModel {
private List<SerRenLocal> serRenIterator;
public static final int COLCOUNT = 10;
public static final int COL_PACKET = 0;
public static final int COL_SERVICE = 1;
public static final int COL_DIRECTED = 2;
public static final int COL_RENDERED = 3;
public static final int COL_PRICE = 4;
public static final int COL_MONEY = 5;
public static final int COL_DISCOUNT = 6;
public static final int COL_REST = 7;
public static final int COL_PAY = 8;
public static final int COL_STT = 9;
public TableModelSerRenList(List<SerRenLocal> serRens) {
this.serRenIterator = serRens;
java.util.Collections.sort(serRenIterator, new SerRenByDateComparator());
}
@Override
public boolean isCellEditable(int r, int c) {
return false;
}
@Override
public Object getValueAt(int r, int c) {
try {
SerRenLocal serRenLocal = serRenIterator.get(r);
switch (c) {
case COL_PACKET: {
return serRenLocal.getPacketServiceID();
}
case COL_SERVICE: {
//наименование услуги
return serRenLocal.getService().toString();
}
case COL_DIRECTED: {
//Направил + дата
DirectoryCollaboratorItem serRenDirector = serRenLocal.getSerRenDirector();
Date date = serRenLocal.getSerDate();
return serRenDirector.toString() + " " +
Converter.dateToString(date);
}
case COL_RENDERED: {
//Обслужил + дата
if (serRenLocal.isRendered()) {
DirectoryCollaboratorItem cl = serRenLocal.getCollaboratorFunctions().getCollaborator();
Date dateOrder = serRenLocal.getSerRenderDate();
return cl.toString() + " " +
Converter.dateToString(dateOrder);
} else {
return "Не оказана";
}
}
case COL_PRICE: {
//Полная стоимость услуги
ServisePriceData contractServiceData = serRenLocal.getContractService();
if (contractServiceData != null && !serRenLocal.hasReferencedSerRen()) {
return String.format("%.2f", ((float) contractServiceData.getPrice()) /
100);
} else {
return "";
}
}
case COL_MONEY: {
//оплачивается договором
ServisePriceData contractServiceData = serRenLocal.getContractService();
if (contractServiceData != null && !serRenLocal.hasReferencedSerRen()) {
return String.format("%.2f", ((float) contractServiceData.getMoney()) /
100);
} else {
return "";
}
}
case COL_DISCOUNT: {
//скидка услуги
return serRenLocal.getCalculatedDiscount();
}
case COL_REST: {
//осталось оплатить
ServisePriceData contractServiceData = serRenLocal.getContractService();
if (contractServiceData != null && !serRenLocal.hasReferencedSerRen()) {
float discount = (float) serRenLocal.getCalculatedDiscount() / 100;
float lack = contractServiceData.getLack() * (1 - discount) / 100;
return String.format("%.2f", lack);
} else {
return "";
}
}
case COL_PAY: {
//Внесено денег
return String.format("%.2f", ((float) serRenLocal.getTransactionSumm()) /
100);
}
case COL_STT: {
//привязка к заболеванию
return serRenLocal.getDiseaseLocal() != null;
}
default:
return null;
}
} catch (ClipsException ex) {
return new ErrorValue(ex);
}
}
@Override
public int getColumnCount() {
return COLCOUNT;
}
@Override
public int getRowCount() {
if (serRenIterator != null) {
return serRenIterator.size();
} else {
return 0;
}
}
@Override
public String getColumnName(int c) {
String s;
switch (c) {
case COL_PACKET:
s = "Пакет";
break;
case COL_SERVICE:
s = "Услуга";
break;
case COL_DIRECTED:
s = "Направлен";
break;
case COL_RENDERED:
s = "Обслужен";
break;
case COL_PRICE:
s = "Стоимость";
break;
case COL_MONEY:
s = "Договор";
break;
case COL_DISCOUNT:
s = "Скидка (%)";
break;
case COL_REST:
s = "Стоимость со скидкой";
break;
case COL_PAY:
s = "Оплата";
break;
case COL_STT:
s = "Заболевание";
break;
default:
throw new IllegalArgumentException("Некорректный номер столбца");
}
return s;
}
class SerRenByDateComparator implements Comparator<SerRenLocal> {
@Override
public int compare(SerRenLocal o1, SerRenLocal o2) {
try {
if (o1.getSerDate().after(o2.getSerDate())) {
return 1;
} else {
return -1;
}
} catch (ClipsException ex) {
MessageBox.showException(ex);
return 0;
}
}
}
}