Search in sources :

Example 76 with Invoice

use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.

the class InvoiceController method checkBankOrderAlreadyExist.

public void checkBankOrderAlreadyExist(ActionRequest request, ActionResponse response) {
    try {
        Invoice invoice = request.getContext().asType(Invoice.class);
        invoice = Beans.get(InvoiceRepository.class).find(invoice.getId());
        Beans.get(InvoicePaymentCreateServiceBankPay.class).checkBankOrderAlreadyExist(invoice);
    } catch (Exception e) {
        TraceBackService.trace(response, e, ResponseMessageType.ERROR);
    }
}
Also used : InvoicePaymentCreateServiceBankPay(com.axelor.apps.bankpayment.service.invoice.payment.InvoicePaymentCreateServiceBankPay) Invoice(com.axelor.apps.account.db.Invoice)

Example 77 with Invoice

use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.

the class InvoicingProjectService method generateAnnex.

public void generateAnnex(InvoicingProject invoicingProject) throws AxelorException, IOException {
    String title = I18n.get("InvoicingProjectAnnex") + "-" + Beans.get(AppBaseService.class).getTodayDateTime().format(DateTimeFormatter.ofPattern(DATE_FORMAT_YYYYMMDDHHMM));
    ReportSettings reportSettings = ReportFactory.createReport(IReport.INVOICING_PROJECT_ANNEX, title).addParam("InvProjectId", invoicingProject.getId()).addParam("Timezone", getTimezone(invoicingProject)).addParam("Locale", ReportSettings.getPrintingLocale(null));
    if (invoicingProject.getAttachAnnexToInvoice()) {
        List<File> fileList = new ArrayList<>();
        MetaFiles metaFiles = Beans.get(MetaFiles.class);
        Invoice invoice = invoicingProject.getInvoice();
        fileList.add(Beans.get(InvoicePrintServiceImpl.class).print(invoice, null, ReportSettings.FORMAT_PDF, null));
        fileList.add(reportSettings.generate().getFile());
        MetaFile metaFile = metaFiles.upload(PdfTool.mergePdf(fileList));
        metaFile.setFileName(title + ".pdf");
        metaFiles.attach(metaFile, null, invoicingProject);
        return;
    }
    reportSettings.toAttach(invoicingProject).generate();
}
Also used : MetaFiles(com.axelor.meta.MetaFiles) Invoice(com.axelor.apps.account.db.Invoice) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) ReportSettings(com.axelor.apps.report.engine.ReportSettings) ArrayList(java.util.ArrayList) MetaFile(com.axelor.meta.db.MetaFile) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile)

Example 78 with Invoice

use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.

the class DeclarationOfExchangesExporterGoods method exportLineToCsv.

protected String[] exportLineToCsv(StockMoveLine stockMoveLine, int lineNum) throws AxelorException {
    String[] data = new String[columnHeadersList.size()];
    StockMove stockMove = stockMoveLine.getStockMove();
    String customsCode = stockMoveLine.getCustomsCode();
    Product product = stockMoveLine.getProduct();
    if (StringUtils.isBlank(customsCode)) {
        if (product == null) {
            customsCode = I18n.get("Product is missing.");
        }
        if (product != null && product.getCustomsCodeNomenclature() != null) {
            customsCode = product.getCustomsCodeNomenclature().getCode();
        }
        if (StringUtils.isBlank(customsCode)) {
            customsCode = String.format(I18n.get("Customs code nomenclature is missing on product %s."), product.getCode());
        }
    }
    BigDecimal fiscalValue = stockMoveLine.getCompanyUnitPriceUntaxed().multiply(stockMoveLine.getRealQty()).setScale(0, RoundingMode.HALF_UP);
    // Only positive fiscal value should be take into account
    if (fiscalValue.compareTo(BigDecimal.ZERO) <= 0) {
        return new String[0];
    }
    Regime regime = stockMoveLine.getRegime();
    if (regime == null) {
        if (stockMove.getTypeSelect() == StockMoveRepository.TYPE_OUTGOING) {
            regime = Regime.EXONERATED_SHIPMENT_AND_TRANSFER;
        } else if (stockMove.getTypeSelect() == StockMoveRepository.TYPE_INCOMING) {
            regime = Regime.INTRACOMMUNITY_ACQUISITION_TAXABLE_IN_FRANCE;
        }
    }
    BigDecimal totalNetMass = stockMoveLine.getTotalNetMass().setScale(0, RoundingMode.HALF_UP);
    BigInteger supplementaryUnit = stockMoveLine.getRealQty().setScale(0, RoundingMode.CEILING).toBigInteger();
    NatureOfTransaction natTrans = stockMoveLine.getNatureOfTransaction();
    if (natTrans == null) {
        natTrans = stockMove.getIsReversion() ? NatureOfTransaction.RETURN_OF_GOODS : NatureOfTransaction.FIRM_PURCHASE_OR_SALE;
    }
    ModeOfTransport modeOfTransport = stockMove.getModeOfTransport();
    if (modeOfTransport == null) {
        modeOfTransport = ModeOfTransport.CONSIGNMENTS_BY_POST;
    }
    String srcDstCountry;
    String dept;
    try {
        Address partnerAddress = stockMoveToolService.getPartnerAddress(stockMoveLine.getStockMove());
        srcDstCountry = partnerAddress.getAddressL7Country().getAlpha2Code();
    } catch (AxelorException e) {
        srcDstCountry = e.getMessage();
    }
    try {
        Address companyAddress = stockMoveToolService.getCompanyAddress(stockMoveLine.getStockMove());
        dept = companyAddress.getCity().getDepartment().getCode();
    } catch (AxelorException e) {
        dept = e.getMessage();
    }
    String countryOrigCode;
    if (stockMoveLine.getCountryOfOrigin() != null) {
        countryOrigCode = stockMoveLine.getCountryOfOrigin().getAlpha2Code();
    } else {
        if (stockMove.getTypeSelect() == StockMoveRepository.TYPE_INCOMING) {
            countryOrigCode = srcDstCountry;
        } else {
            countryOrigCode = "";
        }
    }
    String taxNbr;
    if (stockMove.getTypeSelect() == StockMoveRepository.TYPE_OUTGOING && stockMoveLine.getRegime() != Regime.OTHER_EXPEDITIONS) {
        if (stockMove.getPartner() == null) {
            taxNbr = String.format(I18n.get("Partner is missing on stock move %s."), stockMove.getName());
        } else if (StringUtils.isBlank(stockMove.getPartner().getTaxNbr())) {
            taxNbr = String.format(I18n.get("Tax number is missing on partner %s."), stockMove.getPartner().getName());
        } else {
            taxNbr = stockMove.getPartner().getTaxNbr();
        }
    } else {
        taxNbr = "";
    }
    String partnerSeq = "";
    if (stockMove.getPartner() != null) {
        partnerSeq = stockMove.getPartner().getPartnerSeq();
    }
    String productCode = "";
    String productName = "";
    if (product != null) {
        productCode = product.getCode();
        productName = product.getName();
    }
    String invoiceId = "";
    Set<Invoice> invoiceSet = stockMove.getInvoiceSet();
    if (invoiceSet != null) {
        for (Invoice invoice : invoiceSet) {
            if (invoice.getStatusSelect() == InvoiceRepository.STATUS_VENTILATED) {
                invoiceId += invoice.getInvoiceId() + "|";
            }
        }
        if (invoiceId != null && !invoiceId.isEmpty()) {
            invoiceId = invoiceId.substring(0, invoiceId.length() - 1);
        }
    }
    data[columnHeadersList.indexOf(LINE_NUM)] = String.valueOf(lineNum);
    data[columnHeadersList.indexOf(NOMENCLATURE)] = customsCode;
    data[columnHeadersList.indexOf(SRC_DST_COUNTRY)] = srcDstCountry;
    data[columnHeadersList.indexOf(FISC_VAL)] = String.valueOf(fiscalValue);
    data[columnHeadersList.indexOf(REGIME)] = String.valueOf(regime.getValue());
    data[columnHeadersList.indexOf(MASS)] = String.valueOf(totalNetMass);
    data[columnHeadersList.indexOf(UNITS)] = String.valueOf(supplementaryUnit);
    data[columnHeadersList.indexOf(NAT_TRANS)] = String.valueOf(natTrans.getValue());
    data[columnHeadersList.indexOf(TRANSP)] = String.valueOf(modeOfTransport.getValue());
    data[columnHeadersList.indexOf(DEPT)] = dept;
    data[columnHeadersList.indexOf(COUNTRY_ORIG)] = countryOrigCode;
    data[columnHeadersList.indexOf(ACQUIRER)] = taxNbr;
    data[columnHeadersList.indexOf(PRODUCT_CODE)] = productCode;
    data[columnHeadersList.indexOf(PRODUCT_NAME)] = productName;
    data[columnHeadersList.indexOf(PARTNER_SEQ)] = partnerSeq;
    data[columnHeadersList.indexOf(INVOICE)] = invoiceId;
    return data;
}
Also used : Regime(com.axelor.apps.stock.db.Regime) AxelorException(com.axelor.exception.AxelorException) StockMove(com.axelor.apps.stock.db.StockMove) Invoice(com.axelor.apps.account.db.Invoice) Address(com.axelor.apps.base.db.Address) Product(com.axelor.apps.base.db.Product) NatureOfTransaction(com.axelor.apps.stock.db.NatureOfTransaction) BigDecimal(java.math.BigDecimal) ModeOfTransport(com.axelor.apps.stock.db.ModeOfTransport) BigInteger(java.math.BigInteger)

Example 79 with Invoice

use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.

the class SubscriptionInvoiceServiceImpl method generateSubscriptionInvoice.

@Override
@Transactional(rollbackOn = { Exception.class })
public Invoice generateSubscriptionInvoice(SaleOrder saleOrder) throws AxelorException {
    TemporalUnit temporalUnit = ChronoUnit.MONTHS;
    Invoice invoice = saleOrderInvoiceService.generateInvoice(saleOrderRepo.find(saleOrder.getId()));
    if (invoice != null) {
        if (saleOrder.getPeriodicityTypeSelect() == 1) {
            temporalUnit = ChronoUnit.DAYS;
        }
        invoice.setInvoiceDate(appBaseService.getTodayDate(saleOrder.getCompany()));
        invoice.setOperationSubTypeSelect(InvoiceRepository.OPERATION_SUB_TYPE_SUBSCRIPTION);
        LocalDate invoicingPeriodStartDate = saleOrder.getNextInvoicingStartPeriodDate();
        invoice.setSubscriptionFromDate(invoicingPeriodStartDate);
        invoice.setSubscriptionToDate(saleOrder.getNextInvoicingEndPeriodDate());
        if (invoicingPeriodStartDate != null) {
            LocalDate nextInvoicingStartPeriodDate = invoicingPeriodStartDate.plus(saleOrder.getNumberOfPeriods(), temporalUnit);
            saleOrder.setNextInvoicingStartPeriodDate(nextInvoicingStartPeriodDate);
            LocalDate nextInvoicingEndPeriodDate = nextInvoicingStartPeriodDate.plus(saleOrder.getNumberOfPeriods(), temporalUnit).minusDays(1);
            saleOrder.setNextInvoicingEndPeriodDate(nextInvoicingEndPeriodDate);
        }
        LocalDate nextInvoicingDate = saleOrder.getNextInvoicingDate();
        if (nextInvoicingDate != null) {
            nextInvoicingDate = nextInvoicingDate.plus(saleOrder.getNumberOfPeriods(), temporalUnit);
        }
        saleOrder.setNextInvoicingDate(nextInvoicingDate);
    }
    return invoice;
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) TemporalUnit(java.time.temporal.TemporalUnit) LocalDate(java.time.LocalDate) Transactional(com.google.inject.persist.Transactional)

Example 80 with Invoice

use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.

the class StockMoveMultiInvoiceServiceImpl method areFieldsConflictedToGenerateCustInvoice.

@Override
public Map<String, Object> areFieldsConflictedToGenerateCustInvoice(List<StockMove> stockMoveList) throws AxelorException {
    Map<String, Object> mapResult = new HashMap<>();
    boolean paymentConditionToCheck = false;
    boolean paymentModeToCheck = false;
    boolean contactPartnerToCheck = false;
    checkForAlreadyInvoicedStockMove(stockMoveList);
    List<Invoice> dummyInvoiceList = stockMoveList.stream().map(this::createDummyOutInvoice).collect(Collectors.toList());
    checkOutStockMoveRequiredFieldsAreTheSame(dummyInvoiceList);
    if (!dummyInvoiceList.isEmpty()) {
        PaymentCondition firstPaymentCondition = dummyInvoiceList.get(0).getPaymentCondition();
        PaymentMode firstPaymentMode = dummyInvoiceList.get(0).getPaymentMode();
        Partner firstContactPartner = dummyInvoiceList.get(0).getContactPartner();
        paymentConditionToCheck = !dummyInvoiceList.stream().map(Invoice::getPaymentCondition).allMatch(paymentCondition -> Objects.equals(paymentCondition, firstPaymentCondition));
        paymentModeToCheck = !dummyInvoiceList.stream().map(Invoice::getPaymentMode).allMatch(paymentMode -> Objects.equals(paymentMode, firstPaymentMode));
        contactPartnerToCheck = !dummyInvoiceList.stream().map(Invoice::getContactPartner).allMatch(contactPartner -> Objects.equals(contactPartner, firstContactPartner));
        mapResult.put("paymentCondition", firstPaymentCondition);
        mapResult.put("paymentMode", firstPaymentMode);
        mapResult.put("contactPartner", firstContactPartner);
    }
    mapResult.put("paymentConditionToCheck", paymentConditionToCheck);
    mapResult.put("paymentModeToCheck", paymentModeToCheck);
    mapResult.put("contactPartnerToCheck", contactPartnerToCheck);
    return mapResult;
}
Also used : PaymentCondition(com.axelor.apps.account.db.PaymentCondition) RefundInvoice(com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice) Invoice(com.axelor.apps.account.db.Invoice) HashMap(java.util.HashMap) Partner(com.axelor.apps.base.db.Partner) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Aggregations

Invoice (com.axelor.apps.account.db.Invoice)195 AxelorException (com.axelor.exception.AxelorException)69 ArrayList (java.util.ArrayList)48 Transactional (com.google.inject.persist.Transactional)46 BigDecimal (java.math.BigDecimal)32 Company (com.axelor.apps.base.db.Company)31 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)29 Partner (com.axelor.apps.base.db.Partner)27 InvoiceRepository (com.axelor.apps.account.db.repo.InvoiceRepository)22 InvoiceService (com.axelor.apps.account.service.invoice.InvoiceService)22 PaymentMode (com.axelor.apps.account.db.PaymentMode)21 Map (java.util.Map)21 List (java.util.List)20 StockMove (com.axelor.apps.stock.db.StockMove)19 RefundInvoice (com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice)18 MoveLine (com.axelor.apps.account.db.MoveLine)17 LocalDate (java.time.LocalDate)17 InvoiceGenerator (com.axelor.apps.account.service.invoice.generator.InvoiceGenerator)16 Context (com.axelor.rpc.Context)15 InvoicePayment (com.axelor.apps.account.db.InvoicePayment)14