Search in sources :

Example 11 with Company

use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.

the class IrrecoverableService method createIrrecoverablePaymentScheduleLineLine.

/**
 * Fonction permettant de créer une ligne Echéance rejetée
 *
 * @param icl Une ligne Client
 * @param invoice Une échéance rejetée
 * @param seq Un numéro de séquence
 * @return
 * @throws AxelorException
 */
public IrrecoverablePaymentScheduleLineLine createIrrecoverablePaymentScheduleLineLine(IrrecoverableCustomerLine icl, PaymentScheduleLine paymentScheduleLine, int seq) throws AxelorException {
    IrrecoverablePaymentScheduleLineLine ipsll = new IrrecoverablePaymentScheduleLineLine();
    ipsll.setPaymentScheduleLine(paymentScheduleLine);
    ipsll.setIrrecoverableCustomerLine(icl);
    Company company = paymentScheduleLine.getPaymentSchedule().getCompany();
    Tax tax = accountConfigService.getIrrecoverableStandardRateTax(accountConfigService.getAccountConfig(company));
    ipsll.setIrrecoverableReportLineList(this.createIrrecoverableReportLineList(ipsll, paymentScheduleLine, tax));
    log.debug("Ligne échéance rejetée : {}", ipsll);
    return ipsll;
}
Also used : Company(com.axelor.apps.base.db.Company) IrrecoverablePaymentScheduleLineLine(com.axelor.apps.account.db.IrrecoverablePaymentScheduleLineLine) InvoiceLineTax(com.axelor.apps.account.db.InvoiceLineTax) Tax(com.axelor.apps.account.db.Tax)

Example 12 with Company

use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.

the class ReconcileServiceImpl method reconcilePreconditions.

public void reconcilePreconditions(Reconcile reconcile) throws AxelorException {
    MoveLine debitMoveLine = reconcile.getDebitMoveLine();
    MoveLine creditMoveLine = reconcile.getCreditMoveLine();
    if (debitMoveLine == null || creditMoveLine == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.RECONCILE_1), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION));
    }
    // Check if move lines companies are the same as the reconcile company
    Company reconcileCompany = reconcile.getCompany();
    Company debitMoveLineCompany = debitMoveLine.getMove().getCompany();
    Company creditMoveLineCompany = creditMoveLine.getMove().getCompany();
    if (!debitMoveLineCompany.equals(reconcileCompany) && !creditMoveLineCompany.equals(reconcileCompany)) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, String.format(I18n.get(IExceptionMessage.RECONCILE_7), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), debitMoveLineCompany, creditMoveLineCompany, reconcileCompany));
    }
    // Check if move lines accounts are the same (debit and credit)
    if (!creditMoveLine.getAccount().equals(debitMoveLine.getAccount())) {
        log.debug("Compte ligne de credit : {} , Compte ligne de debit : {}", creditMoveLine.getAccount(), debitMoveLine.getAccount());
        // Check if move lines accounts are compatible
        if (!debitMoveLine.getAccount().getCompatibleAccountSet().contains(creditMoveLine.getAccount())) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.RECONCILE_2), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION));
        }
    }
    // Check if the amount to reconcile is != zero
    if (reconcile.getAmount() == null || reconcile.getAmount().compareTo(BigDecimal.ZERO) == 0) {
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.RECONCILE_4), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), reconcile.getReconcileSeq(), debitMoveLine.getName(), debitMoveLine.getAccount().getLabel(), creditMoveLine.getName(), creditMoveLine.getAccount().getLabel());
    }
    if ((reconcile.getAmount().compareTo(creditMoveLine.getCredit().subtract(creditMoveLine.getAmountPaid())) > 0 || (reconcile.getAmount().compareTo(debitMoveLine.getDebit().subtract(debitMoveLine.getAmountPaid())) > 0))) {
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.RECONCILE_5) + " " + I18n.get(IExceptionMessage.RECONCILE_3), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), reconcile.getReconcileSeq(), reconcile.getAmount(), debitMoveLine.getName(), debitMoveLine.getAccount().getLabel(), debitMoveLine.getDebit().subtract(debitMoveLine.getAmountPaid()), creditMoveLine.getName(), creditMoveLine.getAccount().getLabel(), creditMoveLine.getCredit().subtract(creditMoveLine.getAmountPaid()));
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) MoveLine(com.axelor.apps.account.db.MoveLine)

Example 13 with Company

use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.

the class AnalyticMoveLineServiceImpl method createAnalyticMoveLine.

public AnalyticMoveLine createAnalyticMoveLine(AnalyticDistributionLine analyticDistributionLine, BigDecimal total, int typeSelect, LocalDate date) {
    AnalyticMoveLine analyticMoveLine = new AnalyticMoveLine();
    analyticMoveLine.setOriginalPieceAmount(total);
    analyticMoveLine.setAnalyticAccount(analyticDistributionLine.getAnalyticAccount());
    analyticMoveLine.setAnalyticAxis(analyticDistributionLine.getAnalyticAxis());
    analyticMoveLine.setAnalyticJournal(analyticDistributionLine.getAnalyticJournal());
    AnalyticJournal analyticJournal = analyticDistributionLine.getAnalyticJournal();
    Company company = analyticJournal == null ? null : analyticJournal.getCompany();
    if (company != null) {
        analyticMoveLine.setCurrency(company.getCurrency());
    }
    analyticMoveLine.setDate(date);
    analyticMoveLine.setPercentage(analyticDistributionLine.getPercentage());
    analyticMoveLine.setAmount(computeAmount(analyticMoveLine));
    analyticMoveLine.setTypeSelect(typeSelect);
    return analyticMoveLine;
}
Also used : Company(com.axelor.apps.base.db.Company) AnalyticJournal(com.axelor.apps.account.db.AnalyticJournal) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine)

Example 14 with Company

use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.

the class PrintServiceImpl method generateHtml.

protected String generateHtml(Print print) {
    StringBuilder htmlBuilder = new StringBuilder();
    htmlBuilder.append("<!DOCTYPE html>");
    htmlBuilder.append("<html>");
    htmlBuilder.append("<head>");
    htmlBuilder.append("<title></title>");
    htmlBuilder.append("<meta charset=\"utf-8\"/>");
    htmlBuilder.append("<style type=\"text/css\">");
    htmlBuilder.append("</style>");
    htmlBuilder.append("</head>");
    htmlBuilder.append("<body>");
    if (!print.getHidePrintSettings()) {
        Company company = print.getCompany();
        Integer logoPosition = print.getLogoPositionSelect();
        String pdfHeader = print.getPrintPdfHeader() != null ? print.getPrintPdfHeader() : "";
        String imageTag = "";
        String logoWidth = print.getLogoWidth() != null ? "width: " + print.getLogoWidth() + ";" : "width: 50%;";
        String headerWidth = print.getHeaderContentWidth() != null ? "width: " + print.getHeaderContentWidth() + ";" : "width: 40%;";
        if (company != null && company.getLogo() != null && logoPosition != PrintRepository.LOGO_POSITION_NONE && new File(attachmentPath + company.getLogo().getFilePath()).exists()) {
            String width = company.getWidth() != 0 ? "width='" + company.getWidth() + "px'" : "";
            String height = company.getHeight() != 0 ? company.getHeight() + "px" : "71px";
            imageTag = "<img src='" + company.getLogo().getFilePath() + "' height='" + height + "' " + width + "/>";
        }
        switch(logoPosition) {
            case PrintRepository.LOGO_POSITION_LEFT:
                htmlBuilder.append("<table style='width: 100%;'><tr><td valign='top' style='text-align: left; " + logoWidth + "'>" + imageTag + "</td><td valign='top' style='width: 10%'></td><td valign='top' style='text-align: left; " + headerWidth + "'>" + pdfHeader + "</td></tr></table>");
                break;
            case PrintRepository.LOGO_POSITION_CENTER:
                htmlBuilder.append("<table style=\"width: 100%;\"><tr><td valign='top' style='width: 33.33%;'></td><td valign='top' style='text-align: center; width: 33.33%;'>" + imageTag + "</td><td valign='top' style='text-align: left; width: 33.33%;'>" + pdfHeader + "</td></tr></table>");
                break;
            case PrintRepository.LOGO_POSITION_RIGHT:
                htmlBuilder.append("<table style='width: 100%;'><tr><td valign='top' style='text-align: left; " + headerWidth + "'>" + pdfHeader + "</td><td valign='top' style='width: 10%'></td><td valign='top' style='text-align: center; " + logoWidth + "'>" + imageTag + "</td></tr></table>");
                break;
            default:
                htmlBuilder.append("<table style='width: 100%;'><tr><td style='width: 60%;'></td><td valign='top' style='text-align: left; width: 40%'>" + pdfHeader + "</td></tr></table>");
                break;
        }
        if (!pdfHeader.isEmpty() || !imageTag.isEmpty()) {
            htmlBuilder.append("<hr>");
        }
    }
    if (ObjectUtils.notEmpty(print)) {
        List<PrintLine> printLineList = print.getPrintLineList();
        if (CollectionUtils.isNotEmpty(printLineList)) {
            for (PrintLine printLine : printLineList) {
                htmlBuilder.append(printLine.getIsWithPageBreakAfter() ? "<div style=\"page-break-after: always;\">" : "<div>");
                htmlBuilder.append("<table>");
                htmlBuilder.append("<tr>");
                if (printLine.getIsSignature()) {
                    htmlBuilder.append("<td>&nbsp;</td></tr></table></div>");
                    continue;
                }
                Integer nbColumns = printLine.getNbColumns() == 0 ? 1 : printLine.getNbColumns();
                for (int i = 0; i < nbColumns; i++) {
                    htmlBuilder.append("<td style=\"padding: 0px 10px 0px 10px\">");
                    if (StringUtils.notEmpty(printLine.getTitle())) {
                        htmlBuilder.append(printLine.getTitle());
                    }
                    if (StringUtils.notEmpty(printLine.getContent())) {
                        htmlBuilder.append(printLine.getContent());
                    }
                    htmlBuilder.append("</td>");
                }
                htmlBuilder.append("</tr>");
                htmlBuilder.append("</table>");
                htmlBuilder.append("</div>");
            }
        }
    }
    htmlBuilder.append("</body>");
    htmlBuilder.append("</html>");
    return htmlBuilder.toString();
}
Also used : Company(com.axelor.apps.base.db.Company) PrintLine(com.axelor.apps.base.db.PrintLine) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile) Print(com.axelor.apps.base.db.Print)

Example 15 with Company

use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.

the class PrintTemplateLineServiceImpl method initMaker.

@SuppressWarnings("unchecked")
protected TemplateMaker initMaker(Long objectId, String model, String simpleModel, Locale locale) throws ClassNotFoundException {
    String timezone = null;
    Company activeCompany = Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null);
    if (activeCompany != null) {
        timezone = activeCompany.getTimezone();
    }
    TemplateMaker maker = new TemplateMaker(timezone, locale, TEMPLATE_DELIMITER, TEMPLATE_DELIMITER);
    Class<? extends Model> modelClass = (Class<? extends Model>) Class.forName(model);
    maker.setContext(JPA.find(modelClass, objectId), simpleModel);
    return maker;
}
Also used : Company(com.axelor.apps.base.db.Company) TemplateMaker(com.axelor.tool.template.TemplateMaker) Model(com.axelor.db.Model) MetaModel(com.axelor.meta.db.MetaModel)

Aggregations

Company (com.axelor.apps.base.db.Company)213 Transactional (com.google.inject.persist.Transactional)72 Partner (com.axelor.apps.base.db.Partner)68 AxelorException (com.axelor.exception.AxelorException)65 BigDecimal (java.math.BigDecimal)54 Move (com.axelor.apps.account.db.Move)35 MoveLine (com.axelor.apps.account.db.MoveLine)35 LocalDate (java.time.LocalDate)35 ArrayList (java.util.ArrayList)31 PaymentMode (com.axelor.apps.account.db.PaymentMode)28 AccountConfig (com.axelor.apps.account.db.AccountConfig)27 Journal (com.axelor.apps.account.db.Journal)26 Account (com.axelor.apps.account.db.Account)25 Invoice (com.axelor.apps.account.db.Invoice)25 BankDetails (com.axelor.apps.base.db.BankDetails)22 Currency (com.axelor.apps.base.db.Currency)19 Product (com.axelor.apps.base.db.Product)17 StockLocation (com.axelor.apps.stock.db.StockLocation)17 StockMove (com.axelor.apps.stock.db.StockMove)15 List (java.util.List)15