private void loadArticlesUsedOnSelectedDay() { String date = dtDate.getYear() + String.format("%02d", dtDate.getMonth() + 1) + String.format("%02d", dtDate.getDay()); Query<Konsultation> qbe = new Query<Konsultation>(Konsultation.class); qbe.add(Konsultation.FLD_DATE, Query.EQUALS, date); List<Konsultation> cons = qbe.execute(); StringBuilder sb = new StringBuilder(); for (Konsultation c : cons) { List<Verrechnet> leistungen = c.getLeistungen(); for (Verrechnet v : leistungen) { IVerrechenbar vv = v.getVerrechenbar(); if (vv instanceof Artikel) { Artikel art = (Artikel) vv; Mandant mandator = ElexisEventDispatcher.getSelectedMandator(); IStockEntry stockEntry = CoreHub.getStockService() .findPreferredStockEntryForArticle( art.storeToString(), (mandator != null) ? mandator.getId() : null); if (stockEntry != null) { StockEntry se = (StockEntry) stockEntry; currOrder.addBestellungEntry( se.getArticle(), se.getStock(), se.getProvider(), v.getZahl()); } else { sb.append(art.getLabel() + " ist kein Lagerartikel.\n"); } } } } }
/** Der Konstruktor liest eine ESR-Zeile ein und konstruiert daraus den Datensatz. */ public ESRRecord(final String file, final String codeline) { super.create(null); Mandant m; Rechnung rn = null; String mandantID; REJECT rejectCode; String[] vals = new String[11]; vals[0] = new TimeTool().toString(TimeTool.DATE_COMPACT); vals[10] = file; rejectCode = REJECT.OK; // Code/Modus. MODE mode = MODE.Unbekannt; String smd = codeline.substring(0, 3); if (smd.equals("002")) { // $NON-NLS-1$ mode = MODE.Gutschrift_edv; } else if (smd.equals("012")) { // $NON-NLS-1$ mode = MODE.Gutschrift_Schalter; } else if (smd.equals("005")) { // $NON-NLS-1$ mode = MODE.Storno_edv; } else if (smd.equals("015")) { // $NON-NLS-1$ mode = MODE.Storno_Schalter; } else if (smd.equals("008")) { // $NON-NLS-1$ mode = MODE.Korrektur_edv; } else if (smd.equals("018")) { // $NON-NLS-1$ mode = MODE.Korrektur_Schalter; } else if (smd.equals("999")) { // $NON-NLS-1$ mode = MODE.Summenrecord; } vals[5] = Integer.toString(mode.ordinal()); // Daten parsen. Der ESR-Record liefert 6-stellige Daten, wir wollen 8-stellige String prefix = vals[0].substring(0, 2); // TODO Das funktioniert nur bis ins Jahr 2099 :-) TimeTool dat = new TimeTool(prefix + codeline.substring(59, 65)); vals[1] = dat.toString(TimeTool.DATE_GER); dat.set(prefix + codeline.substring(65, 71)); vals[2] = dat.toString(TimeTool.DATE_GER); dat.set(prefix + codeline.substring(71, 77)); vals[3] = (dat.toString(TimeTool.DATE_GER)); if (mode.equals(MODE.Summenrecord)) { // Betrag (führende Nullen entfernen) vals[4] = Integer.toString(Integer.parseInt(codeline.substring(39, 51).trim())); // Totalbetrag // 12-stellig } else { vals[4] = Integer.toString(Integer.parseInt(codeline.substring(39, 49).trim())); // Zeilenbetrag // 10-stellig String esrline = codeline.substring(12, 39); // Von der RechnungsNummer führende Nullen wegbringen int rnnr = Integer.parseInt(esrline.substring(POSITION_RN_NR, 26)); Query<Rechnung> qbe_r = new Query<Rechnung>(Rechnung.class); String rnid = qbe_r.findSingle("RnNummer", "=", Integer.toString(rnnr)); // $NON-NLS-1$ //$NON-NLS-2$ if (rnid == null) { rejectCode = REJECT.RN_NUMMER; vals[6] = ""; // $NON-NLS-1$ mandantID = ""; // $NON-NLS-1$ } else { vals[6] = rnid; rn = Rechnung.load(rnid); if (rn == null) { rejectCode = REJECT.RN_NUMMER; vals[6] = ""; // $NON-NLS-1$ mandantID = ""; // $NON-NLS-1$ } else { m = rn.getMandant(); if (m == null) { rejectCode = REJECT.MANDANT; vals[6] = ""; // $NON-NLS-1$ mandantID = ""; // $NON-NLS-1$ } else { mandantID = m.getId(); } } } String PatNr = esrline.substring(POSITION_PAT_NR, POSITION_RN_NR); long patnr = Long.parseLong(PatNr); // führende Nullen wegbringen String PatID = new Query<Patient>(Patient.class) .findSingle("PatientNr", "=", Long.toString(patnr)); // $NON-NLS-1$ //$NON-NLS-2$ if (PatID == null) { if (rejectCode == REJECT.OK) { rejectCode = REJECT.PAT_NUMMER; } vals[7] = ""; // $NON-NLS-1$ } else if ((rn != null) && (!rn.getFall().getPatient().getId().equals(PatID))) { if (rejectCode == REJECT.OK) { rejectCode = REJECT.PAT_FALSCH; } vals[7] = ""; // $NON-NLS-1$ } else { vals[7] = PatID; } vals[8] = mandantID; } vals[9] = Integer.toString(rejectCode.ordinal()); set( new String[] { "Datum", "Eingelesen", "Verarbeitet", "Gutgeschrieben", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ "BetragInRp", CODE, RECHNUNGS_ID, PATIENT_ID, MANDANT_ID, FLD_REJECT_CODE, "File" }, vals); //$NON-NLS-1$ //$NON-NLS-2$ }
@Override protected IStatus createContent(IProgressMonitor monitor) { int total = 10000000; Query<AccountTransaction> qbe = new Query<AccountTransaction>(AccountTransaction.class); TimeTool ttStart = new TimeTool(this.getStartDate().getTimeInMillis()); TimeTool ttEnd = new TimeTool(this.getEndDate().getTimeInMillis()); qbe.add( AccountTransaction.FLD_DATE, Query.GREATER_OR_EQUAL, ttStart.toString(TimeTool.DATE_COMPACT)); // $NON-NLS-1$ //$NON-NLS-2$ qbe.add( AccountTransaction.FLD_DATE, Query.LESS_OR_EQUAL, ttEnd.toString(TimeTool.DATE_COMPACT)); // $NON-NLS-1$ //$NON-NLS-2$ monitor.beginTask(NAME, total); monitor.subTask(Messages.FakturaJournal_DatabaseQuery); List<AccountTransaction> transactions = qbe.execute(); int sum = transactions.size(); final ArrayList<Comparable<?>[]> result = new ArrayList<Comparable<?>[]>(); if (sum == 0) { monitor.done(); this.dataSet.setContent(result); return Status.OK_STATUS; } int step = total / sum; monitor.worked(20 * step); PatientIdFormatter pif = new PatientIdFormatter(8); String actMnId = CoreHub.actMandant.getId(); for (AccountTransaction at : transactions) { Patient pat = at.getPatient(); if (pat != null) { if (bOnlyActiveMandator) { Rechnung rn = at.getRechnung(); if (rn == null) { continue; } Mandant mn = rn.getMandant(); if (mn != null) { if (!mn.getId().equals(actMnId)) { continue; } } } Comparable<?>[] row = new Comparable<?>[this.dataSet.getHeadings().size()]; row[0] = pif.format(pat.get(Patient.FLD_PATID)); row[1] = new DateTool(at.getDate()); row[2] = at.getAmount(); row[4] = at.getRemark(); if (((Money) row[2]).isNegative()) { row[3] = Messages.FakturaJournal_FA; } else { if (((String) row[4]).toLowerCase().contains("storno")) { // $NON-NLS-1$ row[3] = Messages.FakturaJournal_ST; } else { row[3] = Messages.FakturaJournal_GU; } } if (monitor.isCanceled()) { return Status.CANCEL_STATUS; } result.add(row); } monitor.worked(step); } // Set content. this.dataSet.setContent(result); // Job finished successfully monitor.done(); return Status.OK_STATUS; }