19 package org.turro.crm.command;
21 import java.util.Date;
22 import java.util.List;
23 import org.amic.util.date.CheckDate;
24 import org.turro.string.ObjectString;
25 import org.turro.string.Strings;
26 import org.turro.annotation.ElephantPlugin;
27 import org.turro.crm.db.CrmPU;
28 import org.turro.crm.entity.SaleAction;
29 import org.turro.crm.entity.Vendor;
30 import org.turro.crm.entity.VendorProspect;
31 import org.turro.jpa.Dao;
32 import org.turro.plugin.calendar.CalendarColor;
33 import org.turro.plugin.calendar.DefaultCalendarEvent;
34 import org.turro.plugin.command.CalendarPlugin;
35 import org.turro.plugin.contacts.IContact;
36 import org.turro.util.Chars;
37 import org.turro.util.PhraseBuilder;
50 "select v from Vendor v where v.idContact = ?",
53 Date newFrom =
new CheckDate(
getFrom()).addDays(-7).getDate(),
54 newTo =
new CheckDate(
getTo()).addDays(7).getDate();
55 List<SaleAction> list = dao.getResultList(
56 "select sa from SaleAction sa " +
57 "where sa.vendorProspect.vendor = ? " +
59 "(sa.actionDate >= ? and sa.actionDate <= ?) " +
60 "or (sa.finalDate >= ? and sa.finalDate <= ?) " +
61 "or (sa.actionDate < ? and sa.finalDate > ?) " +
63 new Object[] { vendor,
68 for(SaleAction sa : list) {
69 DefaultCalendarEvent calendarEvent =
new DefaultCalendarEvent();
70 calendarEvent.setLocked(
false);
71 calendarEvent.setDone(sa.getStatus() > 0);
72 if(sa.getStatus() > SaleAction.SA_PENDING) {
73 calendarEvent.setHeaderColor(CalendarColor.SILVER.getHeader());
74 calendarEvent.setContentColor(CalendarColor.SILVER.getContent());
76 calendarEvent.setHeaderColor(CalendarColor.GREEN.getHeader());
77 calendarEvent.setContentColor(CalendarColor.GREEN.getContent());
79 calendarEvent.setBeginDate(sa.getActionDate());
80 calendarEvent.setEndDate(sa.getFinalDate());
81 calendarEvent.setPath(CrmPU.getObjectPath(sa));
82 calendarEvent.setOrganizer(sa.getVendorProspect().getVendor().getIContact());
83 PhraseBuilder pb =
new PhraseBuilder();
84 VendorProspect vp = sa.getVendorProspect();
85 pb.addWord(vp.getSaleProspect().getCustomer().getName());
86 pb.addPendingSeparator(Chars.forward().toString());
87 pb.addWord(vp.getSaleProspect().getDescription());
88 calendarEvent.setTitle(pb.toString());
89 pb.addPendingSeparator(Chars.nl().repeat(2).toString());
90 pb.addWord(sa.getComment());
91 pb.addPendingSeparator(Chars.nl().repeat(2).toString());
92 for(IContact contact : sa.getIAttendees()) {
93 pb.addWord(contact.getName());
94 pb.addPendingSeparator(
", ");
95 calendarEvent.addAttendee(contact);
97 calendarEvent.setContent(pb.toString());
98 calendarEvent.setEventId(Strings.identifier(
"sa" + sa.getId() +
99 ObjectString.formatObject(calendarEvent.getBeginDate(), ObjectString.COMPRESSED_DATE_PATTERN,
true)));
100 addResult(calendarEvent.getEventId(), calendarEvent);
Object addResult(String key, Object value)
Object getSingleResultOrNull(SqlClause sc)