boolean active;
List<Invoice> incomingInvoices;
List<Invoice> outgoingInvoices;
-
+ List<Treasury> treasuries;
}
--- /dev/null
+package hu.user.lis.db;
+
+import lombok.*;
+
+import java.util.Date;
+
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+public class Treasury {
+ String id;
+ double buyAmount;
+ Currency buyCurrency;
+ double sellAmount;
+ Currency sellCurrency;
+ Date transactionDate;
+ Date valueDate;
+}
int count = RandomUtils.nextInt(2, 5);
List<Invoice> result = new ArrayList<>();
for (int i = 0; i < count; i++) {
- int index = RandomUtils.nextInt(0, 500);
+ int index = RandomUtils.nextInt(0, GENERATE_COUNT);
if (income) {
result.add(incomingEntities.get(index));
incomingEntities.remove(index);
--- /dev/null
+package hu.user.lis.services.data;
+
+import hu.user.lis.db.Treasury;
+
+import java.util.List;
+
+public interface TreasuryService {
+ List<Treasury> getAll();
+
+ Treasury createNew();
+
+ Treasury copy(Treasury sourceEntity);
+
+ String toString(Treasury sourceEntity);
+
+ Treasury copy(Treasury sourceEntity, String property, Object value);
+
+ List<Treasury> getRandom();
+}
--- /dev/null
+package hu.user.lis.services.data;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import hu.user.lis.db.Currency;
+import hu.user.lis.db.Treasury;
+import lombok.extern.log4j.Log4j2;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.commons.lang3.RandomUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.lang.reflect.Field;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+@Service
+@Log4j2
+public class TreasuryServiceImpl implements TreasuryService {
+ int GENERATE_COUNT = 500;
+ @Autowired
+ DataGeneratorService dataGeneratorService;
+ @Autowired
+ ObjectMapper mapper;
+ private List<Treasury> entities;
+
+ @Override
+ public List<Treasury> getAll() {
+ if (entities == null) {
+ try {
+ entities = generate();
+ } catch (ParseException e) {
+ log.catching(e);
+ }
+ }
+ return entities;
+ }
+
+ @Override
+ public Treasury createNew() {
+ String id = RandomStringUtils.random(8, "0123456789abcdef");
+ return Treasury.builder().id(id).build();
+ }
+
+ private List<Treasury> generate() throws ParseException {
+ List<Treasury> result = new ArrayList<>();
+
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
+ for (int i = 0; i < GENERATE_COUNT; i++) {
+ String id = RandomStringUtils.random(8, "0123456789abcdef");
+ Date transactionDate = dataGeneratorService.faker().date().between(formatter.parse("2010-01-01"), new Date());
+ Date valueDate = dataGeneratorService.faker().date().future(RandomUtils.nextInt(6, 20), TimeUnit.DAYS, transactionDate);
+
+ int currencyIndex = RandomUtils.nextInt(0, 3);
+ Currency buyCurrency = Arrays.stream(Currency.values())
+ .filter(p -> p.getVal() == currencyIndex)
+ .findFirst().get();
+ Currency sellCurrency = Arrays.stream(Currency.values())
+ .filter(p -> p.getVal() == currencyIndex)
+ .findFirst().get();
+
+ double buyAmount = RandomUtils.nextFloat(500, 100000);
+ double sellAmount = RandomUtils.nextFloat(500, 100000);
+ Treasury entity = Treasury.builder()
+ .id(id)
+ .buyCurrency(buyCurrency)
+ .sellCurrency(sellCurrency)
+ .transactionDate(transactionDate)
+ .valueDate(valueDate)
+ .buyAmount(buyAmount)
+ .sellAmount(sellAmount)
+ .build();
+ result.add(entity);
+ }
+ return result;
+ }
+
+ @Override
+ public List<Treasury> getRandom() {
+ int count = RandomUtils.nextInt(2, 5);
+ List<Treasury> result = new ArrayList<>();
+ for (int i = 0; i < count; i++) {
+ int index = RandomUtils.nextInt(0, GENERATE_COUNT);
+ result.add(entities.get(index));
+ entities.remove(index);
+ }
+ return result;
+ }
+
+ @Override
+ public Treasury copy(Treasury sourceEntity) {
+ Treasury result = null;
+ try {
+ String json = toString(sourceEntity);
+ result = mapper.readValue(json, Treasury.class);
+ } catch (JsonProcessingException e) {
+ log.catching(e);
+ }
+ return result;
+ }
+
+ @Override
+ public String toString(Treasury sourceEntity) {
+ String result = null;
+ try {
+ result = mapper.writeValueAsString(sourceEntity);
+ } catch (JsonProcessingException e) {
+ log.catching(e);
+ }
+ return result;
+ }
+
+ @Override
+ public Treasury copy(Treasury sourceEntity, String property, Object value) {
+ Treasury result = copy(sourceEntity);
+ Field field = null;
+ try {
+ field = result.getClass().getDeclaredField(property);
+ field.setAccessible(true);
+ field.set(result, value);
+ } catch (Exception e) {
+ log.catching(e);
+ }
+ return result;
+ }
+
+}
import hu.user.lis.db.Associate;
import hu.user.lis.db.Invoice;
import hu.user.lis.db.Project;
+import hu.user.lis.db.Treasury;
import hu.user.lis.services.data.InvoiceService;
import hu.user.lis.services.data.ProjectAssociateService;
import hu.user.lis.services.data.ProjectService;
+import hu.user.lis.services.data.TreasuryService;
import hu.user.lis.ui.Constants;
import hu.user.lis.ui.data.AssociatesDataModel;
import hu.user.lis.ui.data.PartnerSelectorDataModel;
private InvoiceService invoiceServiceImpl;
@WireVariable
private ProjectService projectServiceImpl;
+
+ @WireVariable
+ private TreasuryService treasuryServiceImpl;
@WireVariable
private EventBus eventBus;
private boolean formInvalid = true;
private Invoice selectedIncomingInvoice;
private Invoice selectedOutgoingInvoice;
+ private Treasury selectedTreasury;
+
private String partialAssociateName;
validate(projectServiceImpl.copy(formDocument));
}
+ @Command
+ public void onAddTreasury() {
+ String page = "~./outgoing-invoice-editor.zul";
+ Invoice editEntity = invoiceServiceImpl.createNew();
+ Window editorWindow = (Window) Executions.createComponents(page, null,
+ Collections.singletonMap("formDocument", editEntity));
+ editorWindow.addEventListener("onClose", e -> {
+ if (e.getData() != null) {
+ formDocument.getOutgoingInvoices().add(editEntity);
+ selectedOutgoingInvoice = editEntity;
+ BindUtils.postNotifyChange(this, "selectedOutgoingInvoice");
+ BindUtils.postNotifyChange(this.formDocument, "outgoingInvoices");
+ validate(projectServiceImpl.copy(formDocument));
+ }
+ });
+ editorWindow.doModal();
+ }
+
+ @Command
+ public void onEditTreasury() throws JsonProcessingException {
+ String page = "~./outgoing-invoice-editor.zul";
+ Invoice editEntity = invoiceServiceImpl.copy(selectedOutgoingInvoice);
+ Map<String, Object> arg = new HashMap<>();
+ arg.put("origDocument", selectedOutgoingInvoice);
+ arg.put("formDocument", editEntity);
+ Window editorWindow = (Window) Executions.createComponents(page, null, arg);
+ editorWindow.addEventListener("onClose", e -> {
+ if (e.getData() != null) {
+ Invoice modifiedEntity = (Invoice) e.getData();
+ List<Invoice> outgoingInvoices = formDocument.getOutgoingInvoices();
+ int index = outgoingInvoices.indexOf(selectedOutgoingInvoice);
+ outgoingInvoices.remove(selectedOutgoingInvoice);
+ outgoingInvoices.add(index, modifiedEntity);
+ selectedOutgoingInvoice = modifiedEntity;
+ BindUtils.postNotifyChange(this, "selectedOutgoingInvoice");
+ BindUtils.postNotifyChange(this.formDocument, "outgoingInvoices");
+ validate(projectServiceImpl.copy(formDocument));
+ }
+ });
+ editorWindow.doModal();
+ }
+
+ @Command
+ public void onRemoveTreasury() {
+ if (selectedOutgoingInvoice == null) {
+ return;
+ }
+ formDocument.getOutgoingInvoices().remove(selectedOutgoingInvoice);
+ selectedOutgoingInvoice = null;
+ BindUtils.postNotifyChange(this, "selectedOutgoingInvoice");
+ BindUtils.postNotifyChange(this.formDocument, "outgoingInvoices");
+ validate(projectServiceImpl.copy(formDocument));
+ }
+
private void updateFormInvalid(boolean invalid) {
setFormInvalid(invalid);
BindUtils.postNotifyChange(this, "formInvalid");
</panelchildren>
</panel>
- <!-- <panel collapsible="true" open="false" border="rounded"-->
- <!-- onOpen="@command('onOpenInvoicePanel', parentPanel=centerPanel)">-->
- <!-- <caption label="Treasury műveletek"-->
- <!-- onClick="@command('onClickInvoicePanel', parentPanel=centerPanel, panel=self.parent)"/>-->
- <!-- <panelchildren>-->
- <!-- <vlayout>-->
- <!-- <toolbar>-->
- <!-- <toolbarbutton label="Hozzáadás" iconSclass="z-icon-plus"-->
- <!-- onClick="@command('onAddIncoming')"/>-->
- <!-- <toolbarbutton label="Szerkesztés" iconSclass="z-icon-edit"-->
- <!-- onClick="@command('onEditIncoming')"-->
- <!-- disabled="@load(empty vm.selectedIncomingInvoice)"/>-->
- <!-- <toolbarbutton label="Törlés" iconSclass="z-icon-remove"-->
- <!-- onClick="@command('onRemoveIncoming')"-->
- <!-- disabled="@load(empty vm.selectedIncomingInvoice)"/>-->
- <!-- </toolbar>-->
+ <panel collapsible="true" open="false" border="rounded"
+ onOpen="@command('onOpenInvoicePanel', parentPanel=centerPanel)">
+ <caption label="Treasury műveletek"
+ onClick="@command('onClickInvoicePanel', parentPanel=centerPanel, panel=self.parent)"/>
+ <panelchildren>
+ <vlayout>
+ <toolbar>
+ <toolbarbutton label="Hozzáadás" iconSclass="z-icon-plus"
+ onClick="@command('onAddTreasury')"/>
+ <toolbarbutton label="Szerkesztés" iconSclass="z-icon-edit"
+ onClick="@command('onEditTreasury')"
+ disabled="@load(empty vm.selectedTreasury)"/>
+ <toolbarbutton label="Törlés" iconSclass="z-icon-remove"
+ onClick="@command('onRemoveTreasury')"
+ disabled="@load(empty vm.selectedTreasury)"/>
+ </toolbar>
- <!-- <listbox model="@load(vm.formDocument.incomingInvoices)"-->
- <!-- selectedItem="@bind(vm.selectedIncomingInvoice)"-->
- <!-- onDoubleClick="@command('onEditIncoming')"-->
- <!-- forward="onOK=submit.onClick, onCancel=cancel.onClick">-->
- <!-- <listhead>-->
- <!-- <listheader label="Szállító" align="left"/>-->
- <!-- <listheader label="Megnevezés" align="left"/>-->
- <!-- <listheader label="Nettó összeg" align="left"/>-->
- <!-- <listheader label="Pénznem" align="left"/>-->
- <!-- <listheader label="Fizetési határidő" align="left"/>-->
- <!-- </listhead>-->
- <!-- <template name="model">-->
- <!-- <listitem>-->
- <!-- <listcell label="@load(each.partner.name)"/>-->
- <!-- <listcell label="@load(each.title)"/>-->
- <!-- <listcell-->
- <!-- label="@load(each.netAmount) @converter('hu.user.lis.ui.converter.DoubleToStringConverter')"/>-->
- <!-- <listcell label="@load(each.currency)"/>-->
- <!-- <listcell-->
- <!-- label="@load(each.paymentDeadline) @converter('hu.user.lis.ui.converter.DateToStringConverter')"/>-->
- <!-- </listitem>-->
- <!-- </template>-->
- <!-- </listbox>-->
- <!-- </vlayout>-->
- <!-- </panelchildren>-->
- <!-- </panel>-->
+ <listbox model="@load(vm.formDocument.treasuries)"
+ selectedItem="@bind(vm.selectedTreasury)"
+ onDoubleClick="@command('onEditTreasury')"
+ forward="onOK=submit.onClick, onCancel=cancel.onClick">
+ <auxhead>
+ <auxheader label="Eladás" colspan="2"/>
+ <auxheader label="Vétel" colspan="2"/>
+ </auxhead>
+ <listhead>
+ <listheader label="Összeg" align="left"/>
+ <listheader label="Pénznem" align="left"/>
+ <listheader label="Összeg" align="left"/>
+ <listheader label="Pénznem" align="left"/>
+ <listheader label="Üzletkötés dátuma" align="left"/>
+ <listheader label="Értéknap" align="left"/>
+ </listhead>
+ <template name="model">
+ <listitem>
+ <listcell
+ label="@load(each.sellAmount) @converter('hu.user.lis.ui.converter.DoubleToStringConverter')"/>
+ <listcell label="@load(each.sellCurrency)"/>
+ <listcell
+ label="@load(each.buyAmount) @converter('hu.user.lis.ui.converter.DoubleToStringConverter')"/>
+ <listcell label="@load(each.buyCurrency)"/>
+ <listcell
+ label="@load(each.transactionDate) @converter('hu.user.lis.ui.converter.DateToStringConverter')"/>
+ <listcell
+ label="@load(each.valueDate) @converter('hu.user.lis.ui.converter.DateToStringConverter')"/>
+ </listitem>
+ </template>
+ </listbox>
+ </vlayout>
+ </panelchildren>
+ </panel>
<panel collapsible="true" open="false" border="rounded"
onOpen="@command('onOpenInvoicePanel', parentPanel=centerPanel)">