public static PaymentsModel loadInstance(AppView app) throws BasicException { PaymentsModel p = new PaymentsModel(); // Propiedades globales p.m_sHost = app.getProperties().getHost(); p.m_iSeq = app.getActiveCashSequence(); p.m_dDateStart = app.getActiveCashDateStart(); p.m_dDateEnd = null; // Pagos Object[] valtickets = (Object[]) new StaticSentence( app.getSession(), "SELECT COUNT(*), SUM(PAYMENTS.TOTAL) " + "FROM PAYMENTS, RECEIPTS " + "WHERE PAYMENTS.RECEIPT = RECEIPTS.ID AND RECEIPTS.MONEY = ?", SerializerWriteString.INSTANCE, new SerializerReadBasic(new Datas[] {Datas.INT, Datas.DOUBLE})) .find(app.getActiveCashIndex()); if (valtickets == null) { p.m_iPayments = new Integer(0); p.m_dPaymentsTotal = new Double(0.0); } else { p.m_iPayments = (Integer) valtickets[0]; p.m_dPaymentsTotal = (Double) valtickets[1]; } List l = new StaticSentence( app.getSession(), "SELECT PAYMENTS.PAYMENT, SUM(PAYMENTS.TOTAL) " + "FROM PAYMENTS, RECEIPTS " + "WHERE PAYMENTS.RECEIPT = RECEIPTS.ID AND RECEIPTS.MONEY = ? " + "GROUP BY PAYMENTS.PAYMENT", SerializerWriteString.INSTANCE, new SerializerReadClass( PaymentsModel.PaymentsLine .class)) // new SerializerReadBasic(new Datas[] {Datas.STRING, // Datas.DOUBLE})) .list(app.getActiveCashIndex()); if (l == null) { p.m_lpayments = new ArrayList(); } else { p.m_lpayments = l; } // Sales Object[] recsales = (Object[]) new StaticSentence( app.getSession(), "SELECT COUNT(DISTINCT RECEIPTS.ID), SUM(TICKETLINES.UNITS * TICKETLINES.PRICE) " + "FROM RECEIPTS, TICKETLINES WHERE RECEIPTS.ID = TICKETLINES.TICKET AND RECEIPTS.MONEY = ?", SerializerWriteString.INSTANCE, new SerializerReadBasic(new Datas[] {Datas.INT, Datas.DOUBLE})) .find(app.getActiveCashIndex()); if (recsales == null) { p.m_iSales = null; p.m_dSalesBase = null; } else { p.m_iSales = (Integer) recsales[0]; p.m_dSalesBase = (Double) recsales[1]; } // Taxes Object[] rectaxes = (Object[]) new StaticSentence( app.getSession(), "SELECT SUM(TAXLINES.AMOUNT) " + "FROM RECEIPTS, TAXLINES WHERE RECEIPTS.ID = TAXLINES.RECEIPT AND RECEIPTS.MONEY = ?", SerializerWriteString.INSTANCE, new SerializerReadBasic(new Datas[] {Datas.DOUBLE})) .find(app.getActiveCashIndex()); if (rectaxes == null) { p.m_dSalesTaxes = null; } else { p.m_dSalesTaxes = (Double) rectaxes[0]; } List<SalesLine> asales = new StaticSentence( app.getSession(), "SELECT TAXCATEGORIES.NAME, SUM(TAXLINES.AMOUNT) " + "FROM RECEIPTS, TAXLINES, TAXES, TAXCATEGORIES WHERE RECEIPTS.ID = TAXLINES.RECEIPT AND TAXLINES.TAXID = TAXES.ID AND TAXES.CATEGORY = TAXCATEGORIES.ID " + "AND RECEIPTS.MONEY = ?" + "GROUP BY TAXCATEGORIES.NAME", SerializerWriteString.INSTANCE, new SerializerReadClass(PaymentsModel.SalesLine.class)) .list(app.getActiveCashIndex()); if (asales == null) { p.m_lsales = new ArrayList<SalesLine>(); } else { p.m_lsales = asales; } return p; }
private void btnPayActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnPayActionPerformed paymentdialog.setPrintSelected(true); // MSL : get total of selected tickets double tt = 0; for (Object tl : jList1.getSelectedValues()) { FindTicketsInfoCustomer sTicket = (FindTicketsInfoCustomer) tl; TicketInfo t = new TicketInfo(); try { t = dlsales.loadTicket(0, sTicket.getTicketId()); tt = tt + t.getTotal(); // - t.getTotalPaid(); } catch (BasicException e) { } } // ------------- // if (paymentdialog.showDialog(customerext.getCurdebt(), null)) { if (paymentdialog.showDialog(tt, null)) { // Save the ticket /*TicketInfo ticket = new TicketInfo(); ticket.setTicketType(TicketInfo.RECEIPT_PAYMENT); List<PaymentInfo> payments = paymentdialog.getSelectedPayments(); double total = 0.0; for (PaymentInfo p : payments) { total += p.getTotal(); } payments.add(new PaymentInfoTicket(-total, "debtpaid")); ticket.setPayments(payments); ticket.setUser(app.getAppUserView().getUser().getUserInfo()); ticket.setActiveCash(app.getActiveCashIndex()); ticket.setDate(new Date()); ticket.setCustomer(customerext); try { dlsales.saveTicket(ticket, app.getInventoryLocation()); } catch (BasicException eData) { MessageInf msg = new MessageInf(MessageInf.SGN_NOTICE, AppLocal.getIntString("message.nosaveticket"), eData); msg.show(this); } * */ // Save the ticket TicketInfo ticket = new TicketInfo(); ticket.setTicketType(TicketInfo.RECEIPT_PAYMENT); List<PaymentInfo> payments = paymentdialog.getSelectedPayments(); double total = 0.0; for (PaymentInfo p : payments) { total += p.getTotal(); } double reste = total; for (Object tl : jList1.getSelectedValues()) { FindTicketsInfoCustomer sTicket = (FindTicketsInfoCustomer) tl; TicketInfo t = new TicketInfo(); if (reste > 0) { try { t = dlsales.loadTicket(0, sTicket.getTicketId()); payments.add(new PaymentInfoTicket(-t.getTotal(), "debtpaid")); reste = total - t.getTotal(); ticket.setPayments(payments); ticket.setUser(app.getAppUserView().getUser().getUserInfo()); ticket.setActiveCash(app.getActiveCashIndex()); ticket.setDate(new Date()); ticket.setCustomer(customerext); dlsales.saveTicket(ticket, app.getInventoryLocation()); new StaticSentence( this.app.getSession(), "UPDATE TICKETS Set STATUS=9 WHERE ID = ?", SerializerWriteString.INSTANCE) .exec(t.getId()); // MSL : break the system : set the receipt with original one // TODO : split the amount paid to the ticket values /*new StaticSentence(this.app.getSession() , "UPDATE RECEIPTS Set ID=? WHERE ID = ?" , new SerializerWriteBasic(new Datas[] {Datas.STRING, Datas.STRING})) .exec(new Object[] {t.getId(), ticket.getId()}); */ new StaticSentence( this.app.getSession(), "UPDATE PAYMENTS Set TICKETID=? WHERE RECEIPT = ?", new SerializerWriteBasic(new Datas[] {Datas.STRING, Datas.STRING})) .exec(new Object[] {t.getId(), ticket.getId()}); } catch (BasicException eData) { MessageInf msg = new MessageInf( MessageInf.SGN_NOTICE, AppLocal.getIntString("message.nosaveticket"), eData); msg.show(this); } } } // MSL : no tickets selected if ((jList1.getSelectedValues() == null) || (reste > 0)) { payments.add(new PaymentInfoTicket(-reste, "debtpaid")); ticket.setPayments(payments); ticket.setUser(app.getAppUserView().getUser().getUserInfo()); ticket.setActiveCash(app.getActiveCashIndex()); ticket.setDate(new Date()); ticket.setCustomer(customerext); try { dlsales.saveTicket(ticket, app.getInventoryLocation()); } catch (BasicException eData) { MessageInf msg = new MessageInf( MessageInf.SGN_NOTICE, AppLocal.getIntString("message.nosaveticket"), eData); msg.show(this); } } // reload customer CustomerInfoExt c; try { c = dlsales.loadCustomerExt(customerext.getId()); if (c == null) { MessageInf msg = new MessageInf( MessageInf.SGN_WARNING, AppLocal.getIntString("message.cannotfindcustomer")); msg.show(this); } else { editCustomer(c); } } catch (BasicException ex) { c = null; MessageInf msg = new MessageInf( MessageInf.SGN_WARNING, AppLocal.getIntString("message.cannotfindcustomer"), ex); msg.show(this); } printTicket( paymentdialog.isPrintSelected() ? "Printer.CustomerPaid" : "Printer.CustomerPaid2", ticket, c); } editorcard.reset(); editorcard.activate(); } // GEN-LAST:event_btnPayActionPerformed
private void m_jCloseCashActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_m_jCloseCashActionPerformed // TODO add your handling code here: int res = JOptionPane.showConfirmDialog( this, AppLocal.getIntString("message.wannaclosecash"), AppLocal.getIntString("message.title"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (res == JOptionPane.YES_OPTION) { Date dNow = new Date(); try { // Cerramos la caja si esta pendiente de cerrar. if (m_App.getActiveCashDateEnd() == null) { new StaticSentence( m_App.getSession(), "UPDATE CLOSEDCASH SET DATEEND = ? WHERE HOST = ? AND MONEY = ?", new SerializerWriteBasic( new Datas[] {Datas.TIMESTAMP, Datas.STRING, Datas.STRING})) .exec( new Object[] {dNow, m_App.getProperties().getHost(), m_App.getActiveCashIndex()}); } } catch (BasicException e) { MessageInf msg = new MessageInf( MessageInf.SGN_NOTICE, AppLocal.getIntString("message.cannotclosecash"), e); msg.show(this); } try { // Creamos una nueva caja m_App.setActiveCash( UUID.randomUUID().toString(), m_App.getActiveCashSequence() + 1, dNow, null); // creamos la caja activa m_dlSystem.execInsertCash( new Object[] { m_App.getActiveCashIndex(), m_App.getProperties().getHost(), m_App.getActiveCashSequence(), m_App.getActiveCashDateStart(), m_App.getActiveCashDateEnd() }); // ponemos la fecha de fin m_PaymentsToClose.setDateEnd(dNow); // print report printPayments("Printer.CloseCash"); // Mostramos el mensaje JOptionPane.showMessageDialog( this, AppLocal.getIntString("message.closecashok"), AppLocal.getIntString("message.title"), JOptionPane.INFORMATION_MESSAGE); } catch (BasicException e) { MessageInf msg = new MessageInf( MessageInf.SGN_NOTICE, AppLocal.getIntString("message.cannotclosecash"), e); msg.show(this); } try { loadData(); } catch (BasicException e) { MessageInf msg = new MessageInf( MessageInf.SGN_NOTICE, AppLocal.getIntString("label.noticketstoclose"), e); msg.show(this); } } } // GEN-LAST:event_m_jCloseCashActionPerformed