use of com.axelor.apps.base.db.Partner in project axelor-open-suite by axelor.
the class EmployeeServiceImpl method generateNewDPAE.
@Override
@Transactional(rollbackOn = { Exception.class })
public Long generateNewDPAE(Employee employee) throws AxelorException {
EmploymentContract mainEmploymentContract = employee.getMainEmploymentContract();
if (mainEmploymentContract == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.EMPLOYEE_CONTRACT_OF_EMPLOYMENT), employee.getName());
}
Company payCompany = mainEmploymentContract.getPayCompany();
Partner employer = payCompany.getPartner();
DPAE newDPAE = new DPAE();
// Employer
newDPAE.setRegistrationCode(employer.getRegistrationCode());
if (employer.getMainActivity() != null && employer.getMainActivity().getFullName() != null) {
newDPAE.setMainActivityCode(employer.getMainActivity().getFullName());
}
newDPAE.setCompany(payCompany);
newDPAE.setCompanyAddress(employer.getMainAddress());
newDPAE.setCompanyFixedPhone(employer.getFixedPhone());
if (payCompany.getHrConfig() != null) {
newDPAE.setHealthService(payCompany.getHrConfig().getHealthService());
newDPAE.setHealthServiceAddress(payCompany.getHrConfig().getHealthServiceAddress());
}
// Employee
newDPAE.setLastName(employee.getContactPartner().getName());
newDPAE.setFirstName(employee.getContactPartner().getFirstName());
newDPAE.setSocialSecurityNumber(employee.getSocialSecurityNumber());
newDPAE.setSexSelect(employee.getSexSelect());
newDPAE.setBirthDate(employee.getBirthDate());
newDPAE.setDepartmentOfBirth(employee.getDepartmentOfBirth());
newDPAE.setCityOfBirth(employee.getCityOfBirth());
newDPAE.setCountryOfBirth(employee.getCountryOfBirth());
// Contract
newDPAE.setHireDate(mainEmploymentContract.getStartDate());
newDPAE.setHireTime(mainEmploymentContract.getStartTime());
newDPAE.setTrialPeriodDuration(mainEmploymentContract.getTrialPeriodDuration());
newDPAE.setContractType(mainEmploymentContract.getContractType());
newDPAE.setContractEndDate(mainEmploymentContract.getEndDate());
employee.addDpaeListItem(newDPAE);
Beans.get(EmployeeRepository.class).save(employee);
return newDPAE.getId();
}
use of com.axelor.apps.base.db.Partner in project axelor-open-suite by axelor.
the class EmployeeHRRepository method save.
@Override
public Employee save(Employee entity) {
Partner partner = entity.getContactPartner();
if (!partner.getIsContact() && partner.getPartnerTypeSelect() == 0) {
partner.setIsContact(true);
partner.setIsEmployee(true);
Beans.get(PartnerHRRepository.class).save(partner);
} else {
Beans.get(PartnerService.class).setPartnerFullName(partner);
}
EmploymentContract employmentContract = entity.getMainEmploymentContract();
if (employmentContract != null && employmentContract.getEmployee() == null) {
employmentContract.setEmployee(entity);
}
return super.save(entity);
}
use of com.axelor.apps.base.db.Partner in project axelor-open-suite by axelor.
the class SaleOrderInvoiceServiceImpl method createInvoiceAndLines.
public Invoice createInvoiceAndLines(SaleOrder saleOrder, List<SaleOrderLineTax> taxLineList, Product invoicingProduct, BigDecimal percentToInvoice, int operationSubTypeSelect, Account partnerAccount) throws AxelorException {
InvoiceGenerator invoiceGenerator = this.createInvoiceGenerator(saleOrder);
Invoice invoice = invoiceGenerator.generate();
List<InvoiceLine> invoiceLinesList = (taxLineList != null && !taxLineList.isEmpty()) ? this.createInvoiceLinesFromTax(invoice, taxLineList, invoicingProduct, percentToInvoice) : this.createInvoiceLinesFromSO(invoice, saleOrder, invoicingProduct, percentToInvoice);
invoiceGenerator.populate(invoice, invoiceLinesList);
invoice.setAddressStr(saleOrder.getMainInvoicingAddressStr());
invoice.setOperationSubTypeSelect(operationSubTypeSelect);
if (partnerAccount != null) {
Partner partner = invoice.getPartner();
if (partner != null) {
partnerAccount = Beans.get(FiscalPositionAccountService.class).getAccount(partner.getFiscalPosition(), partnerAccount);
}
invoice.setPartnerAccount(partnerAccount);
}
return invoice;
}
use of com.axelor.apps.base.db.Partner in project axelor-open-suite by axelor.
the class IntercoServiceImpl method createIntercoInvoiceLine.
protected InvoiceLine createIntercoInvoiceLine(InvoiceLine invoiceLine, boolean isPurchase) throws AxelorException {
AccountManagementAccountService accountManagementAccountService = Beans.get(AccountManagementAccountService.class);
InvoiceLineService invoiceLineService = Beans.get(InvoiceLineService.class);
Invoice intercoInvoice = invoiceLine.getInvoice();
Partner partner = intercoInvoice.getPartner();
if (intercoInvoice.getCompany() != null) {
Account account = accountManagementAccountService.getProductAccount(invoiceLine.getProduct(), intercoInvoice.getCompany(), partner.getFiscalPosition(), isPurchase, false);
invoiceLine.setAccount(account);
TaxLine taxLine = invoiceLineService.getTaxLine(intercoInvoice, invoiceLine, isPurchase);
invoiceLine.setTaxLine(taxLine);
invoiceLine.setTaxRate(taxLine.getValue());
invoiceLine.setTaxCode(taxLine.getTax().getCode());
TaxEquiv taxEquiv = accountManagementAccountService.getProductTaxEquiv(invoiceLine.getProduct(), intercoInvoice.getCompany(), intercoInvoice.getPartner().getFiscalPosition(), isPurchase);
invoiceLine.setTaxEquiv(taxEquiv);
invoiceLine.setCompanyExTaxTotal(invoiceLineService.getCompanyExTaxTotal(invoiceLine.getExTaxTotal(), intercoInvoice));
invoiceLine.setCompanyInTaxTotal(invoiceLineService.getCompanyExTaxTotal(invoiceLine.getInTaxTotal(), intercoInvoice));
if (invoiceLine.getAnalyticDistributionTemplate() != null) {
invoiceLine.setAnalyticDistributionTemplate(accountManagementAccountService.getAnalyticDistributionTemplate(invoiceLine.getProduct(), intercoInvoice.getCompany()));
List<AnalyticMoveLine> analyticMoveLineList = invoiceLineService.createAnalyticDistributionWithTemplate(invoiceLine);
analyticMoveLineList.forEach(analyticMoveLine -> analyticMoveLine.setInvoiceLine(invoiceLine));
invoiceLine.setAnalyticMoveLineList(analyticMoveLineList);
}
}
return invoiceLine;
}
use of com.axelor.apps.base.db.Partner in project axelor-open-suite by axelor.
the class AccountingSituationSupplychainServiceImpl method updateCustomerCreditFromSaleOrder.
@Override
@Transactional(rollbackOn = { AxelorException.class, Exception.class }, ignore = { BlockedSaleOrderException.class })
public void updateCustomerCreditFromSaleOrder(SaleOrder saleOrder) throws AxelorException {
if (!appAccountService.getAppAccount().getManageCustomerCredit()) {
return;
}
Partner partner = saleOrder.getClientPartner();
List<AccountingSituation> accountingSituationList = partner.getAccountingSituationList();
for (AccountingSituation accountingSituation : accountingSituationList) {
if (accountingSituation.getCompany().equals(saleOrder.getCompany())) {
// Update UsedCredit
accountingSituation = this.computeUsedCredit(accountingSituation);
if (saleOrder.getStatusSelect() == SaleOrderRepository.STATUS_DRAFT_QUOTATION) {
BigDecimal inTaxInvoicedAmount = getInTaxInvoicedAmount(saleOrder);
BigDecimal usedCredit = accountingSituation.getUsedCredit().add(saleOrder.getInTaxTotal()).subtract(inTaxInvoicedAmount);
accountingSituation.setUsedCredit(usedCredit);
}
boolean usedCreditExceeded = isUsedCreditExceeded(accountingSituation);
if (usedCreditExceeded) {
saleOrder.setBlockedOnCustCreditExceed(true);
if (!saleOrder.getManualUnblock()) {
String message = accountingSituation.getCompany().getOrderBloquedMessage();
if (Strings.isNullOrEmpty(message)) {
message = String.format(I18n.get(IExceptionMessage.SALE_ORDER_CLIENT_PARTNER_EXCEEDED_CREDIT), partner.getFullName(), saleOrder.getSaleOrderSeq());
}
throw new BlockedSaleOrderException(accountingSituation, message);
}
}
}
}
}
Aggregations