Search in sources :

Example 11 with MoveLine

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

the class ReimbursementExportService method createReimbursementInvoice.

/*
  /**
   * Méthode permettant de créer un fichier xml de virement au format SEPA
   * @param export
   * @param datetime
   * @param reimbursementList
   * @throws AxelorException
   * @throws DatatypeConfigurationException
   * @throws JAXBException
   * @throws IOException
  public void exportSepa(Company company, ZonedDateTime datetime, List<Reimbursement> reimbursementList, BankDetails bankDetails) throws AxelorException, DatatypeConfigurationException, JAXBException, IOException {

  	String exportFolderPath = accountConfigService.getReimbursementExportFolderPath(accountConfigService.getAccountConfig(company));

  	if (exportFolderPath == null) {
  		throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.REIMBURSEMENT_2), company.getName());
  	}


  	DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  	DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
  	Date date = Date.from(datetime.toInstant());
  	BigDecimal ctrlSum = BigDecimal.ZERO;
  	int nbOfTxs = 0;

  /**
   * Création du documemnt XML en mémoire
   -/

  	ObjectFactory factory = new ObjectFactory();

  // Débit

  	// Paiement
  	ServiceLevel2Choice svcLvl = factory.createServiceLevel2Choice();
  	svcLvl.setCd(ServiceLevel1Code.SEPA);

  	PaymentTypeInformation1 pmtTpInf = factory.createPaymentTypeInformation1();
  	pmtTpInf.setSvcLvl(svcLvl);

  	// Payeur
  	PartyIdentification8 dbtr = factory.createPartyIdentification8();
  	dbtr.setNm(bankDetails.getOwnerName());

  	// IBAN
  	AccountIdentification3Choice iban = factory.createAccountIdentification3Choice();
  	iban.setIBAN(bankDetails.getIban());

  	CashAccount7 dbtrAcct = factory.createCashAccount7();
  	dbtrAcct.setId(iban);

  	// BIC
  	FinancialInstitutionIdentification5Choice finInstnId = factory.createFinancialInstitutionIdentification5Choice();
  	finInstnId.setBIC(bankDetails.getBank().getCode());

  	BranchAndFinancialInstitutionIdentification3 dbtrAgt = factory.createBranchAndFinancialInstitutionIdentification3();
  	dbtrAgt.setFinInstnId(finInstnId);

  // Lot

  	PaymentInstructionInformation1 pmtInf = factory.createPaymentInstructionInformation1();
  	pmtInf.setPmtMtd(PaymentMethod3Code.TRF);
  	pmtInf.setPmtTpInf(pmtTpInf);
  	pmtInf.setReqdExctnDt(datatypeFactory.newXMLGregorianCalendar(dateFormat.format(date)));
  	pmtInf.setDbtr(dbtr);
  	pmtInf.setDbtrAcct(dbtrAcct);
  	pmtInf.setDbtrAgt(dbtrAgt);

  // Crédit
  	CreditTransferTransactionInformation1 cdtTrfTxInf = null; PaymentIdentification1 pmtId = null;
  	AmountType2Choice amt = null; CurrencyAndAmount instdAmt = null;
  	PartyIdentification8 cbtr = null; CashAccount7 cbtrAcct = null;
  	BranchAndFinancialInstitutionIdentification3 cbtrAgt = null;
  	RemittanceInformation1 rmtInf = null;
  	for (Reimbursement reimbursement : reimbursementList){

  		reimbursement = reimbursementRepo.find(reimbursement.getId());

  		nbOfTxs++;
  		ctrlSum = ctrlSum.add(reimbursement.getAmountReimbursed());
  		bankDetails = reimbursement.getBankDetails();

  		// Paiement
  		pmtId = factory.createPaymentIdentification1();
  		pmtId.setEndToEndId(reimbursement.getRef());

  		// Montant
  		instdAmt = factory.createCurrencyAndAmount();
  		instdAmt.setCcy("EUR");
  		instdAmt.setValue(reimbursement.getAmountReimbursed());

  		amt = factory.createAmountType2Choice();
  		amt.setInstdAmt(instdAmt);

  		// Débiteur
  		cbtr = factory.createPartyIdentification8();
  		cbtr.setNm(bankDetails.getOwnerName());

  		// IBAN
  		iban = factory.createAccountIdentification3Choice();
  		iban.setIBAN(bankDetails.getIban());

  		cbtrAcct = factory.createCashAccount7();
  		cbtrAcct.setId(iban);

  		// BIC
  		finInstnId = factory.createFinancialInstitutionIdentification5Choice();
  		finInstnId.setBIC(bankDetails.getBank().getCode());

  		cbtrAgt = factory.createBranchAndFinancialInstitutionIdentification3();
  		cbtrAgt.setFinInstnId(finInstnId);

  		rmtInf = factory.createRemittanceInformation1();

  		rmtInf.getUstrd().add(reimbursement.getDescription());

  		// Transaction
  		cdtTrfTxInf = factory.createCreditTransferTransactionInformation1();
  		cdtTrfTxInf.setPmtId(pmtId);
  		cdtTrfTxInf.setAmt(amt);
  		cdtTrfTxInf.setCdtr(cbtr);
  		cdtTrfTxInf.setCdtrAcct(cbtrAcct);
  		cdtTrfTxInf.setCdtrAgt(cbtrAgt);
  		cdtTrfTxInf.setRmtInf(rmtInf);

  		pmtInf.getCdtTrfTxInf().add(cdtTrfTxInf);
  	}

  // En-tête
  	dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");

  	GroupHeader1 grpHdr = factory.createGroupHeader1();
  	grpHdr.setCreDtTm(datatypeFactory.newXMLGregorianCalendar(dateFormat.format(date)));
  	grpHdr.setNbOfTxs(Integer.toString(nbOfTxs));
  	grpHdr.setCtrlSum(ctrlSum);
  	grpHdr.setGrpg(Grouping1Code.MIXD);
  	grpHdr.setInitgPty(dbtr);

  // Parent
  	Pain00100102 pain00100102 = factory.createPain00100102();
  	pain00100102.setGrpHdr(grpHdr);
  	pain00100102.getPmtInf().add(pmtInf);

  // Document
  	Document xml = factory.createDocument();
  	xml.setPain00100102(pain00100102);

  	/**
  	 * Création du documemnt XML physique
  	 -/
  	Marschaller.marschalFile(factory.createDocument(xml), "com.axelor.apps.xsd.sepa",
  			exportFolderPath, String.format("%s.xml", dateFormat.format(date)));

  }
     */
/**
 * *********************** Remboursement lors d'une facture fin de cycle
 * ********************************
 */
/**
 * Procédure permettant de créer un remboursement si un trop perçu est généré à la facture fin de
 * cycle
 *
 * @param partner Un tiers
 * @param company Une société
 * @param moveLineList Une liste de trop-perçu
 * @throws AxelorException
 */
@SuppressWarnings("unchecked")
@Transactional(rollbackOn = { Exception.class })
public void createReimbursementInvoice(Partner partner, Company company, List<? extends MoveLine> moveLineList) throws AxelorException {
    BigDecimal total = this.getTotalAmountRemaining((List<MoveLine>) moveLineList);
    if (total.compareTo(BigDecimal.ZERO) > 0) {
        this.testCompanyField(company);
        Reimbursement reimbursement = this.createReimbursement(partner, company);
        this.fillMoveLineSet(reimbursement, (List<MoveLine>) moveLineList, total);
        if (total.compareTo(company.getAccountConfig().getUpperThresholdReimbursement()) > 0 || reimbursement.getBankDetails() == null) {
            // Seuil haut dépassé
            reimbursement.setStatusSelect(ReimbursementRepository.STATUS_TO_VALIDATE);
        } else {
            // Seuil haut non dépassé
            reimbursement.setStatusSelect(ReimbursementRepository.STATUS_VALIDATED);
        }
        reimbursementRepo.save(reimbursement);
    }
}
Also used : MoveLine(com.axelor.apps.account.db.MoveLine) Reimbursement(com.axelor.apps.account.db.Reimbursement) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 12 with MoveLine

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

the class ReimbursementExportService method createReimbursementMove.

/**
 * Methode permettant de créer l'écriture de remboursement
 *
 * @param reimbursement Un objet d'export des prélèvements
 * @throws AxelorException
 */
public void createReimbursementMove(Reimbursement reimbursement, Company company) throws AxelorException {
    reimbursement = reimbursementRepo.find(reimbursement.getId());
    Partner partner = null;
    Move newMove = null;
    boolean first = true;
    AccountConfig accountConfig = company.getAccountConfig();
    if (reimbursement.getMoveLineSet() != null && !reimbursement.getMoveLineSet().isEmpty()) {
        int seq = 1;
        for (MoveLine moveLine : reimbursement.getMoveLineSet()) {
            BigDecimal amountRemaining = moveLine.getAmountRemaining();
            if (amountRemaining.compareTo(BigDecimal.ZERO) > 0) {
                partner = moveLine.getPartner();
                // On passe les lignes d'écriture (trop perçu) à l'état 'remboursé'
                moveLine.setReimbursementStatusSelect(MoveLineRepository.REIMBURSEMENT_STATUS_REIMBURSED);
                if (first) {
                    newMove = moveService.getMoveCreateService().createMove(accountConfig.getReimbursementJournal(), company, null, partner, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
                    first = false;
                }
                // Création d'une ligne au débit
                MoveLine newDebitMoveLine = moveLineService.createMoveLine(newMove, partner, moveLine.getAccount(), amountRemaining, true, appAccountService.getTodayDate(company), seq, reimbursement.getRef(), reimbursement.getDescription());
                newMove.getMoveLineList().add(newDebitMoveLine);
                if (reimbursement.getDescription() != null && !reimbursement.getDescription().isEmpty()) {
                    newDebitMoveLine.setDescription(reimbursement.getDescription());
                }
                seq++;
                // Création de la réconciliation
                Reconcile reconcile = reconcileService.createReconcile(newDebitMoveLine, moveLine, amountRemaining, false);
                if (reconcile != null) {
                    reconcileService.confirmReconcile(reconcile, true);
                }
            }
        }
        // Création de la ligne au crédit
        MoveLine newCreditMoveLine = moveLineService.createMoveLine(newMove, partner, accountConfig.getReimbursementAccount(), reimbursement.getAmountReimbursed(), false, appAccountService.getTodayDate(company), seq, reimbursement.getRef(), reimbursement.getDescription());
        newMove.getMoveLineList().add(newCreditMoveLine);
        if (reimbursement.getDescription() != null && !reimbursement.getDescription().isEmpty()) {
            newCreditMoveLine.setDescription(reimbursement.getDescription());
        }
        moveService.getMoveValidateService().validate(newMove);
        moveRepo.save(newMove);
    }
}
Also used : Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) Partner(com.axelor.apps.base.db.Partner) BigDecimal(java.math.BigDecimal) AccountConfig(com.axelor.apps.account.db.AccountConfig) Reconcile(com.axelor.apps.account.db.Reconcile)

Example 13 with MoveLine

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

the class ReimbursementImportService method createReimbursementRejectMove.

public void createReimbursementRejectMove(List<String[]> rejectList, Company company) throws AxelorException {
    int seq = 1;
    if (rejectList != null && !rejectList.isEmpty()) {
        LocalDate rejectDate = rejectImportService.createRejectDate(rejectList.get(0)[0]);
        Move move = this.createMoveReject(company, rejectDate);
        for (String[] reject : rejectList) {
            this.createReimbursementRejectMoveLine(reject, company, seq, move, rejectDate);
            seq++;
        }
        if (move != null) {
            // Création d'une ligne au débit
            MoveLine debitMoveLine = moveLineService.createMoveLine(move, null, company.getAccountConfig().getReimbursementAccount(), this.getTotalAmount(move), true, rejectDate, seq, null, null);
            move.getMoveLineList().add(debitMoveLine);
            this.validateMove(move);
        }
    }
}
Also used : Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) LocalDate(java.time.LocalDate)

Example 14 with MoveLine

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

the class ReimbursementImportService method createOppositeRejectMoveLine.

@Transactional(rollbackOn = { Exception.class })
public MoveLine createOppositeRejectMoveLine(Move move, int seq, LocalDate rejectDate) throws AxelorException {
    // Création d'une ligne au débit
    MoveLine debitMoveLine = moveLineService.createMoveLine(move, null, move.getCompany().getAccountConfig().getReimbursementAccount(), this.getTotalAmount(move), true, rejectDate, seq, null, null);
    move.getMoveLineList().add(debitMoveLine);
    moveRepo.save(move);
    return debitMoveLine;
}
Also used : MoveLine(com.axelor.apps.account.db.MoveLine) Transactional(com.google.inject.persist.Transactional)

Example 15 with MoveLine

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

the class ReconcileGroupServiceImpl method findOrMergeGroup.

@Override
public Optional<ReconcileGroup> findOrMergeGroup(Reconcile reconcile) {
    List<ReconcileGroup> otherReconcileGroupList;
    MoveLine debitMoveLine = reconcile.getDebitMoveLine();
    MoveLine creditMoveLine = reconcile.getCreditMoveLine();
    otherReconcileGroupList = new ArrayList<>();
    if (debitMoveLine.getReconcileGroup() != null) {
        otherReconcileGroupList.add(debitMoveLine.getReconcileGroup());
    }
    if (creditMoveLine.getReconcileGroup() != null) {
        otherReconcileGroupList.add(creditMoveLine.getReconcileGroup());
    }
    otherReconcileGroupList = otherReconcileGroupList.stream().distinct().collect(Collectors.toList());
    if (otherReconcileGroupList.isEmpty()) {
        return Optional.empty();
    } else if (otherReconcileGroupList.size() == 1) {
        return Optional.of(otherReconcileGroupList.get(0));
    } else {
        return Optional.of(mergeReconcileGroups(otherReconcileGroupList));
    }
}
Also used : ReconcileGroup(com.axelor.apps.account.db.ReconcileGroup) MoveLine(com.axelor.apps.account.db.MoveLine)

Aggregations

MoveLine (com.axelor.apps.account.db.MoveLine)135 BigDecimal (java.math.BigDecimal)60 Move (com.axelor.apps.account.db.Move)51 Transactional (com.google.inject.persist.Transactional)42 AxelorException (com.axelor.exception.AxelorException)40 Company (com.axelor.apps.base.db.Company)38 ArrayList (java.util.ArrayList)38 Partner (com.axelor.apps.base.db.Partner)33 Account (com.axelor.apps.account.db.Account)28 LocalDate (java.time.LocalDate)27 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)25 Journal (com.axelor.apps.account.db.Journal)22 Reconcile (com.axelor.apps.account.db.Reconcile)22 AccountConfig (com.axelor.apps.account.db.AccountConfig)17 Invoice (com.axelor.apps.account.db.Invoice)15 List (java.util.List)13 TaxPaymentMoveLine (com.axelor.apps.account.db.TaxPaymentMoveLine)8 Tax (com.axelor.apps.account.db.Tax)7 TaxLine (com.axelor.apps.account.db.TaxLine)7 MoveLineRepository (com.axelor.apps.account.db.repo.MoveLineRepository)7