Package com.suarte.core

Examples of com.suarte.core.Invoice


    public String generateInvoice() {
        HttpServletRequest request = getRequest();
        Date date = new Date();
        requestUser = userManager.getUserByUsername(request.getRemoteUser());

        Invoice invoice = new Invoice();
        invoice.setCompany(quotation.getCompany());
        invoice.setContact(quotation.getContact());
        invoice.setDescription(quotation.getDescription());
        invoice.setQuotation(quotation);
        invoice.setDate(new Date());
        invoice.setSubTotal(MathUtils.round(quotation.getSubtotal()));
        invoice.setTax(MathUtils.round(quotation.getTax()));
        invoice.setTotal(MathUtils.round(quotation.getTotalCost()));
        invoice.setCurrency(quotation.getCurrency());
        invoice.setExchangeCurrency(quotation.getExchangeCurrency());
        invoice.setExchangeRate(quotation.getExchangeRate());
        invoice.setEquivalentAmount(MathUtils.round(quotation.getEquivalentAmount()));
        invoice.setCreatedBy(requestUser);
        invoice.setCreatedOn(date);
        invoice.setModifiedBy(requestUser);
        invoice.setModifiedOn(date);
        invoice.setStatus(DocumentStatus.ACTIVA);

        if (quotation.getCurrency() != null && quotation.getCurrency().getSymbol().equals("C$")) {
            invoice.setLocalAmount(MathUtils.round(quotation.getTotalCost()));
            invoice.setForeignAmount(MathUtils.round(quotation.getEquivalentAmount()));
        } else if (quotation.getCurrency() != null && quotation.getCurrency().getSymbol().equals("$")) {
            invoice.setLocalAmount(MathUtils.round(quotation.getEquivalentAmount()));
            invoice.setForeignAmount(MathUtils.round(quotation.getTotalCost()));
        }

        // Calculate delivery days
        Integer days = quotation.getCompany().getCreditDays();
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_MONTH, days.intValue());
        Date expirationDate = calendar.getTime();

        invoice.setExpirationDate(expirationDate);

        for (QuotationDetail qDetail : quotation.getDetails()) {
            InvoiceDetail invoiceDetail = new InvoiceDetail();
            invoiceDetail.setQuotationDetail(qDetail);
            invoice.addDetail(invoiceDetail);
        }
        invoiceManager.save(invoice);

        if (quotation.getCurrency().getSymbol().equals("$")) {
            quotation.getCompany().debit(MathUtils.round(quotation.getTotalCost()), MathUtils.round(quotation.getEquivalentAmount()));
View Full Code Here


        companies = companyManager.getAll();

        if (id != null) {
            invoice = invoiceManager.get(id);
        } else {
            invoice = new Invoice();
        }

        return "edit";
    }
View Full Code Here

        payment.setStatus(PaymentStatus.ANULADO);

        List<InvoicePayment> invoicePayments = invoiceManager.findInvoiceByPayment(payment);

        for (InvoicePayment detail : invoicePayments) {
            Invoice invoice = detail.getInvoice();
            Float totalAmountPaid = 0F;

            if (payment.getCurrency() != null && payment.getCurrency().isLocal()) {
                totalAmountPaid = invoice.getLocalAmountPaid() - detail.getLocalAmount();
                invoice.setLocalAmountPaid(totalAmountPaid);
                invoice.setAmountPaid(totalAmountPaid);
                // Balance increase with anulation
                Float companyLocalBalance = payment.getCompany().getBalanceLocal() + detail.getLocalAmount();
                payment.getCompany().setBalanceLocal(companyLocalBalance);
               
                Float foreignAmount = detail.getForeignAmount();
                Float totalForeignAmount = invoice.getForeignAmountPaid() - foreignAmount;
                invoice.setForeignAmountPaid(totalForeignAmount);
                // Balance increase with anulation
                Float companyBalance = payment.getCompany().getBalance() + foreignAmount;
                payment.getCompany().setBalance(companyBalance);               

                Float pendingBalance = invoice.getLocalAmount() - (invoice.getLocalAmountPaid() != null ? invoice.getLocalAmountPaid() : 0f);
                if (pendingBalance == 0f) {
                    invoice.setStatus(DocumentStatus.PAGADA);
                } else if (pendingBalance.equals(invoice.getLocalAmount())) {
                    invoice.setStatus(DocumentStatus.ACTIVA);
                } else if (pendingBalance > 0f) {
                    invoice.setStatus(DocumentStatus.PAGADA_PARCIAL);
                }
            } else if (payment.getCurrency() != null && !payment.getCurrency().isLocal()) {
                totalAmountPaid = invoice.getForeignAmountPaid() - detail.getForeignAmount();
                invoice.setForeignAmountPaid(totalAmountPaid);
                invoice.setAmountPaid(totalAmountPaid);
                // Balance increase with anulation
                Float companyBalance = payment.getCompany().getBalance() + detail.getForeignAmount();
                payment.getCompany().setBalance(companyBalance);
               
                Float localAmount = detail.getLocalAmount();
                Float totalLocalAmount = invoice.getLocalAmountPaid() - localAmount;
                invoice.setLocalAmountPaid(totalLocalAmount);
                // Balance increase with anulation
                Float companyLocalBalance = payment.getCompany().getBalanceLocal() + localAmount;
                payment.getCompany().setBalanceLocal(companyLocalBalance);
               
                Float pendingBalance = invoice.getForeignAmount() - (invoice.getForeignAmountPaid() != null ? invoice.getForeignAmountPaid() : 0f);
                if (pendingBalance == 0f) {
                    invoice.setStatus(DocumentStatus.PAGADA);
                } else if (pendingBalance.equals(invoice.getForeignAmount())) {
                    invoice.setStatus(DocumentStatus.ACTIVA);
                } else if (pendingBalance > 0f) {
                    invoice.setStatus(DocumentStatus.PAGADA_PARCIAL);
                }
            }
            companyManager.save(payment.getCompany());
            invoice.setCurrentPayment(null);
            invoiceManager.save(invoice);
        }

        paymentManager.save(payment);
        String key = "payment.updated";
View Full Code Here

    }

    public void deleteInvoice(ActionEvent e) {
        UIParameter param = (UIParameter) e.getComponent().getChildren().get(0);
        Long index = Long.valueOf(param.getValue().toString());
        Invoice invoice = invoices.get(index.intValue());
        invoices.remove(invoice);
        localPendingAmount -= invoice.getLocalAmount() - (invoice.getLocalAmountPaid() != null ? invoice.getLocalAmountPaid() : 0f);
        pendingAmount -= invoice.getForeignAmount() - (invoice.getForeignAmountPaid() != null ? invoice.getForeignAmountPaid() : 0f);
    }
View Full Code Here

        String myType = request.getParameter("type");
        if (myType.equals("invoice")) {
            response.setContentType("application/pdf");

            id = Long.valueOf(request.getParameter("id"));
            Invoice invoice = invoiceManager.get(id);

            InvoiceFormatToPdf pdf = new InvoiceFormatToPdf();
            pdf.write(invoice, response.getOutputStream());

            response.getOutputStream().close();
View Full Code Here

TOP

Related Classes of com.suarte.core.Invoice

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.