Search in sources :

Example 1 with MPaymentTerm

use of org.compiere.model.MPaymentTerm in project adempiere by adempiere.

the class HRCreateInvoice method createInvoice.

/**
     * Create invoice for employee
     * @param process
     * @param partner
     * @param employee
     * @param docTypeId
     * @return
     */
private MInvoice createInvoice(MHRProcess process, MBPartner partner, MHREmployee employee, int docTypeId, Timestamp dateInvoice) {
    MBPartnerLocation partnerLocation = getLocationBill(partner);
    if (partnerLocation == null) {
        log.log(Level.SEVERE, " @C_BPartner_Location_ID@ @NotFound@ : " + partner.getName());
        addLog(0, process.getDateAcct(), null, "@Bill_Location_ID@ @NotFound@ " + process.getDocumentNo() + " " + partner.getName());
        return null;
    }
    String paymentRule = employee.getPaymentRule();
    if (paymentRule == null || paymentRule.isEmpty())
        paymentRule = partner.getPaymentRule();
    if (paymentRule == null) {
        log.log(Level.SEVERE, " @PaymentRule@ @NotFound@ : " + partner.getName());
        addLog(0, process.getDateAcct(), null, "@PaymentRule@ @NotFound@ " + process.getDocumentNo() + " " + process.getName() + " " + partner.getValue() + " " + partner.getName());
        return null;
    }
    log.info("New Invoice for ");
    MInvoice invoice = new MInvoice(process.getCtx(), 0, partner.get_TrxName());
    invoice.setAD_Org_ID(process.getAD_Org_ID());
    invoice.setIsSOTrx(false);
    invoice.setPaymentRule(paymentRule);
    invoice.setC_DocTypeTarget_ID(docTypeId);
    invoice.setC_DocType_ID(docTypeId);
    invoice.setDescription(Msg.parseTranslation(process.getCtx(), "@HR_Process_ID@ " + process.getName() + " @DocumentNo@ " + process.getDocumentNo()));
    invoice.setDateOrdered(dateInvoice);
    invoice.setDateInvoiced(dateInvoice);
    invoice.setDateAcct(dateInvoice);
    invoice.setBPartner(partner);
    MPaymentTerm paymentTerm = MPaymentTerm.getPaymentTermByDefault(getCtx(), partner.get_TrxName());
    if (paymentTerm != null)
        invoice.setC_PaymentTerm_ID(paymentTerm.getC_PaymentTerm_ID());
    if (employee.getC_Activity_ID() != 0)
        invoice.setC_Activity_ID(employee.getC_Activity_ID());
    invoice.setDocStatus(DocAction.STATUS_Drafted);
    invoice.setDocAction(DocAction.ACTION_None);
    invoice.setSalesRep_ID(Env.getAD_User_ID(process.getCtx()));
    invoice.saveEx();
    addLog(0, invoice.getDateInvoiced(), invoice.getGrandTotal(), "@C_Invoice_ID@ " + invoice.getDocumentNo() + " @C_BPartner_ID@  @TaxId@ " + invoice.getC_BPartner().getValue() + " @Name@ " + invoice.getC_BPartner().getName());
    return invoice;
}
Also used : MPaymentTerm(org.compiere.model.MPaymentTerm) MInvoice(org.compiere.model.MInvoice) MBPartnerLocation(org.compiere.model.MBPartnerLocation)

Example 2 with MPaymentTerm

use of org.compiere.model.MPaymentTerm in project adempiere by adempiere.

the class PaymentTermValidate method doIt.

//	prepare
/**
	 *  Perform process.
	 *  @return Message
	 *  @throws Exception if not successful
	 */
@Override
protected String doIt() throws Exception {
    log.info("C_PaymentTerm_ID=" + getRecord_ID());
    MPaymentTerm pt = new MPaymentTerm(getCtx(), getRecord_ID(), get_TrxName());
    String msg = pt.validate();
    pt.saveEx();
    //
    String validMsg = Msg.parseTranslation(getCtx(), "@OK@");
    if (validMsg.equals(msg))
        return msg;
    throw new AdempiereUserError(msg);
}
Also used : MPaymentTerm(org.compiere.model.MPaymentTerm) AdempiereUserError(org.compiere.util.AdempiereUserError)

Aggregations

MPaymentTerm (org.compiere.model.MPaymentTerm)2 MBPartnerLocation (org.compiere.model.MBPartnerLocation)1 MInvoice (org.compiere.model.MInvoice)1 AdempiereUserError (org.compiere.util.AdempiereUserError)1