use of com.axelor.apps.account.db.PaymentMode in project axelor-open-suite by axelor.
the class IntercoServiceImpl method generateIntercoSaleFromPurchase.
@Override
@Transactional(rollbackOn = { Exception.class })
public SaleOrder generateIntercoSaleFromPurchase(PurchaseOrder purchaseOrder) throws AxelorException {
SaleOrderCreateService saleOrderCreateService = Beans.get(SaleOrderCreateService.class);
SaleOrderComputeService saleOrderComputeService = Beans.get(SaleOrderComputeService.class);
Company intercoCompany = findIntercoCompany(purchaseOrder.getSupplierPartner());
// create sale order
SaleOrder saleOrder = saleOrderCreateService.createSaleOrder(null, intercoCompany, purchaseOrder.getContactPartner(), purchaseOrder.getCurrency(), purchaseOrder.getDeliveryDate(), null, null, purchaseOrder.getPriceList(), purchaseOrder.getCompany().getPartner(), null);
// in ati
saleOrder.setInAti(purchaseOrder.getInAti());
// copy date
saleOrder.setOrderDate(purchaseOrder.getOrderDate());
// copy payments
PaymentMode intercoPaymentMode = Beans.get(PaymentModeService.class).reverseInOut(purchaseOrder.getPaymentMode());
saleOrder.setPaymentMode(intercoPaymentMode);
saleOrder.setPaymentCondition(purchaseOrder.getPaymentCondition());
// copy delivery info
saleOrder.setDeliveryDate(purchaseOrder.getDeliveryDate());
saleOrder.setShipmentMode(purchaseOrder.getShipmentMode());
saleOrder.setFreightCarrierMode(purchaseOrder.getFreightCarrierMode());
// get stock location
saleOrder.setStockLocation(Beans.get(StockLocationService.class).getPickupDefaultStockLocation(intercoCompany));
// copy timetable info
saleOrder.setExpectedRealisationDate(purchaseOrder.getExpectedRealisationDate());
saleOrder.setAmountToBeSpreadOverTheTimetable(purchaseOrder.getAmountToBeSpreadOverTheTimetable());
// create lines
List<PurchaseOrderLine> purchaseOrderLineList = purchaseOrder.getPurchaseOrderLineList();
if (purchaseOrderLineList != null) {
for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
this.createIntercoSaleLineFromPurchaseLine(purchaseOrderLine, saleOrder);
}
}
saleOrder.setPrintingSettings(intercoCompany.getPrintingSettings());
// compute the sale order
saleOrderComputeService.computeSaleOrder(saleOrder);
saleOrder.setCreatedByInterco(true);
Beans.get(SaleOrderRepository.class).save(saleOrder);
if (Beans.get(AppSupplychainService.class).getAppSupplychain().getIntercoSaleOrderCreateFinalized()) {
Beans.get(SaleOrderWorkflowService.class).finalizeQuotation(saleOrder);
}
purchaseOrder.setExternalReference(saleOrder.getSaleOrderSeq());
saleOrder.setExternalReference(purchaseOrder.getPurchaseOrderSeq());
return saleOrder;
}
use of com.axelor.apps.account.db.PaymentMode 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.PaymentMode in project axelor-open-suite by axelor.
the class AdvancePaymentServiceSupplychainImpl method createMoveForAdvancePayment.
@Transactional(rollbackOn = { Exception.class })
public Move createMoveForAdvancePayment(AdvancePayment advancePayment) throws AxelorException {
SaleOrder saleOrder = advancePayment.getSaleOrder();
Company company = saleOrder.getCompany();
PaymentMode paymentMode = advancePayment.getPaymentMode();
Partner clientPartner = saleOrder.getClientPartner();
LocalDate advancePaymentDate = advancePayment.getAdvancePaymentDate();
BankDetails bankDetails = saleOrder.getCompanyBankDetails();
String ref = saleOrder.getSaleOrderSeq();
AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, bankDetails);
Move move = moveService.getMoveCreateService().createMove(journal, company, advancePayment.getCurrency(), clientPartner, advancePaymentDate, paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
BigDecimal amountConverted = currencyService.getAmountCurrencyConvertedAtDate(advancePayment.getCurrency(), saleOrder.getCurrency(), advancePayment.getAmount(), advancePaymentDate);
move.addMoveLineListItem(moveLineService.createMoveLine(move, clientPartner, paymentModeService.getPaymentModeAccount(paymentMode, company, bankDetails), amountConverted, true, advancePaymentDate, null, 1, ref, null));
move.addMoveLineListItem(moveLineService.createMoveLine(move, clientPartner, accountConfigService.getAdvancePaymentAccount(accountConfig), amountConverted, false, advancePaymentDate, null, 2, ref, null));
moveService.getMoveValidateService().validate(move);
advancePayment.setMove(move);
advancePaymentRepository.save(advancePayment);
return move;
}
use of com.axelor.apps.account.db.PaymentMode in project axelor-open-suite by axelor.
the class PaymentScheduleController method fillCompanyBankDetails.
/**
* Called on partner, company or payment mode change. Fill the bank details with a default value.
*
* @param request
* @param response
* @throws AxelorException
*/
public void fillCompanyBankDetails(ActionRequest request, ActionResponse response) throws AxelorException {
PaymentSchedule paymentSchedule = request.getContext().asType(PaymentSchedule.class);
PaymentMode paymentMode = paymentSchedule.getPaymentMode();
Company company = paymentSchedule.getCompany();
Partner partner = paymentSchedule.getPartner();
if (company == null) {
return;
}
if (partner != null) {
partner = Beans.get(PartnerRepository.class).find(partner.getId());
}
BankDetails defaultBankDetails = Beans.get(BankDetailsService.class).getDefaultCompanyBankDetails(company, paymentMode, partner, null);
response.setValue("companyBankDetails", defaultBankDetails);
}
use of com.axelor.apps.account.db.PaymentMode in project axelor-open-suite by axelor.
the class BankOrderCreateServiceHr method createBankOrder.
/**
* Method to create a bank order for an expense
*
* @param expense An expense
* @throws AxelorException
*/
public BankOrder createBankOrder(Expense expense, BankDetails bankDetails) throws AxelorException {
Company company = expense.getCompany();
Partner partner = expense.getUser().getPartner();
PaymentMode paymentMode = expense.getPaymentMode();
BigDecimal amount = expense.getInTaxTotal().subtract(expense.getAdvanceAmount()).subtract(expense.getWithdrawnCash()).subtract(expense.getPersonalExpenseAmount());
Currency currency = company.getCurrency();
LocalDate paymentDate = Beans.get(AppBaseService.class).getTodayDate(company);
BankOrder bankOrder = super.createBankOrder(paymentMode, BankOrderRepository.PARTNER_TYPE_EMPLOYEE, paymentDate, company, bankDetails, currency, expense.getFullName(), expense.getFullName(), BankOrderRepository.TECHNICAL_ORIGIN_AUTOMATIC);
bankOrder.addBankOrderLineListItem(bankOrderLineService.createBankOrderLine(paymentMode.getBankOrderFileFormat(), partner, amount, currency, paymentDate, expense.getExpenseSeq(), expense.getFullName(), expense));
bankOrder = bankOrderRepo.save(bankOrder);
return bankOrder;
}
Aggregations