use of com.axelor.apps.account.db.AccountingSituation in project axelor-open-suite by axelor.
the class IntercoServiceImpl method generateIntercoInvoice.
@Override
public Invoice generateIntercoInvoice(Invoice invoice) throws AxelorException {
PartnerService partnerService = Beans.get(PartnerService.class);
InvoiceRepository invoiceRepository = Beans.get(InvoiceRepository.class);
InvoiceService invoiceService = Beans.get(InvoiceService.class);
boolean isPurchase;
// set the status
int generatedOperationTypeSelect;
int priceListRepositoryType;
switch(invoice.getOperationTypeSelect()) {
case InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE:
generatedOperationTypeSelect = InvoiceRepository.OPERATION_TYPE_CLIENT_SALE;
priceListRepositoryType = PriceListRepository.TYPE_SALE;
isPurchase = false;
break;
case InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND:
generatedOperationTypeSelect = InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND;
priceListRepositoryType = PriceListRepository.TYPE_SALE;
isPurchase = false;
break;
case InvoiceRepository.OPERATION_TYPE_CLIENT_SALE:
generatedOperationTypeSelect = InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE;
priceListRepositoryType = PriceListRepository.TYPE_PURCHASE;
isPurchase = true;
break;
case InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND:
generatedOperationTypeSelect = InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND;
priceListRepositoryType = PriceListRepository.TYPE_PURCHASE;
isPurchase = true;
break;
default:
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.INVOICE_MISSING_TYPE), invoice);
}
Company intercoCompany = findIntercoCompany(invoice.getPartner());
Partner intercoPartner = invoice.getCompany().getPartner();
PaymentMode intercoPaymentMode = Beans.get(PaymentModeService.class).reverseInOut(invoice.getPaymentMode());
Address intercoAddress = partnerService.getInvoicingAddress(intercoPartner);
BankDetails intercoBankDetails = partnerService.getDefaultBankDetails(intercoPartner);
AccountingSituation accountingSituation = Beans.get(AccountingSituationService.class).getAccountingSituation(intercoPartner, intercoCompany);
PriceList intercoPriceList = Beans.get(PartnerPriceListService.class).getDefaultPriceList(intercoPartner, priceListRepositoryType);
Invoice intercoInvoice = invoiceRepository.copy(invoice, true);
intercoInvoice.setOperationTypeSelect(generatedOperationTypeSelect);
intercoInvoice.setCompany(intercoCompany);
intercoInvoice.setPartner(intercoPartner);
intercoInvoice.setAddress(intercoAddress);
intercoInvoice.setAddressStr(Beans.get(AddressService.class).computeAddressStr(intercoAddress));
intercoInvoice.setPaymentMode(intercoPaymentMode);
intercoInvoice.setBankDetails(intercoBankDetails);
Set<Invoice> invoices = invoiceService.getDefaultAdvancePaymentInvoice(intercoInvoice);
intercoInvoice.setAdvancePaymentInvoiceSet(invoices);
if (accountingSituation != null) {
intercoInvoice.setInvoiceAutomaticMail(accountingSituation.getInvoiceAutomaticMail());
intercoInvoice.setInvoiceMessageTemplate(accountingSituation.getInvoiceMessageTemplate());
intercoInvoice.setPfpValidatorUser(accountingSituation.getPfpValidatorUser());
}
intercoInvoice.setPriceList(intercoPriceList);
intercoInvoice.setInvoicesCopySelect((intercoPartner.getInvoicesCopySelect() == 0) ? DEFAULT_INVOICE_COPY : intercoPartner.getInvoicesCopySelect());
intercoInvoice.setCreatedByInterco(true);
intercoInvoice.setInterco(false);
intercoInvoice.setPrintingSettings(intercoCompany.getPrintingSettings());
if (intercoInvoice.getInvoiceLineList() != null) {
for (InvoiceLine invoiceLine : intercoInvoice.getInvoiceLineList()) {
invoiceLine.setInvoice(intercoInvoice);
createIntercoInvoiceLine(invoiceLine, isPurchase);
}
}
invoiceService.compute(intercoInvoice);
intercoInvoice.setExternalReference(invoice.getInvoiceId());
intercoInvoice = invoiceRepository.save(intercoInvoice);
if (Beans.get(AppSupplychainService.class).getAppSupplychain().getIntercoInvoiceCreateValidated()) {
Beans.get(InvoiceService.class).validate(intercoInvoice);
}
invoice.setExternalReference(intercoInvoice.getInvoiceId());
return intercoInvoice;
}
use of com.axelor.apps.account.db.AccountingSituation in project axelor-open-suite by axelor.
the class PartnerController method createAccountingSituations.
public void createAccountingSituations(ActionRequest request, ActionResponse response) throws AxelorException {
Partner partner = request.getContext().asType(Partner.class);
List<AccountingSituation> accountingSituationList = Beans.get(AccountingSituationInitService.class).createAccountingSituation(Beans.get(PartnerRepository.class).find(partner.getId()));
if (accountingSituationList != null) {
response.setValue("accountingSituationList", accountingSituationList);
}
}
use of com.axelor.apps.account.db.AccountingSituation in project axelor-open-suite by axelor.
the class ImportPartnerAccount method importAccountingSituation.
public Object importAccountingSituation(Object bean, Map<String, Object> values) {
assert bean instanceof Partner;
try {
Partner partner = (Partner) bean;
for (Company company : partner.getCompanySet()) {
AccountingSituation accountingSituation = new AccountingSituation();
accountingSituation.setPartner(partner);
accountingSituation.setCompany(company);
accountingSituation.setCustomerAccount(accountRepo.all().filter("self.code = ?1 AND self.company = ?2", values.get("customerAccount_code").toString(), company).fetchOne());
accountingSituation.setSupplierAccount(accountRepo.all().filter("self.code = ?1 AND self.company = ?2", values.get("supplierAccount_code").toString(), company).fetchOne());
if (partner.getAccountingSituationList() == null) {
partner.setAccountingSituationList(new ArrayList<AccountingSituation>());
}
partner.getAccountingSituationList().add(accountingSituation);
}
return partner;
} catch (Exception e) {
e.printStackTrace();
}
return bean;
}
use of com.axelor.apps.account.db.AccountingSituation in project axelor-open-suite by axelor.
the class AccountingSituationSupplychainController method computeUsedCredit.
public void computeUsedCredit(ActionRequest request, ActionResponse response) {
AccountingSituation accountingSituation = request.getContext().asType(AccountingSituation.class);
try {
accountingSituation = Beans.get(AccountingSituationSupplychainServiceImpl.class).computeUsedCredit(accountingSituation);
response.setValue("usedCredit", accountingSituation.getUsedCredit());
} catch (Exception e) {
TraceBackService.trace(e);
response.setError(e.getMessage());
}
}
use of com.axelor.apps.account.db.AccountingSituation in project axelor-open-suite by axelor.
the class AccountCustomerService method flagPartners.
@Transactional(rollbackOn = { Exception.class })
public void flagPartners(List<Partner> partnerList, Company company) throws AxelorException {
for (Partner partner : partnerList) {
AccountingSituation accountingSituation = accountingSituationService.getAccountingSituation(partner, company);
if (accountingSituation == null) {
accountingSituation = accountingSituationInitService.createAccountingSituation(partner, company);
}
if (accountingSituation != null) {
accountingSituation.setCustAccountMustBeUpdateOk(true);
accSituationRepo.save(accountingSituation);
}
}
}
Aggregations