use of org.compiere.model.MInvoice in project adempiere by adempiere.
the class CPOS method getCreditNotes.
// getCreditCards
/**
* Get Credit Notes
*
*/
public ValueNamePair[] getCreditNotes() {
try {
String whereClause = "C_BPartner_ID = ? " + "AND IsPaid ='N' " + "AND EXISTS(SELECT 1 " + " FROM C_DocType dt " + " WHERE dt.C_DocType_ID = C_Invoice.C_DocType_ID " + " AND dt.DocBaseType ='ARC'" + ")";
List<MInvoice> invoiceList = new Query(Env.getCtx(), MInvoice.Table_Name, whereClause, null).setParameters(currentOrder.getC_BPartner_ID()).list();
//
// to eliminate duplicates
HashMap<String, ValueNamePair> map = new HashMap<String, ValueNamePair>();
ValueNamePair valueNamePair;
for (MInvoice invoice : invoiceList) {
Integer id = invoice.getC_Invoice_ID();
valueNamePair = new ValueNamePair(id.toString(), invoice.getDocumentNo() + " " + invoice.getOpenAmt().toString());
map.put(invoice.getDocumentNo(), valueNamePair);
}
// for all payment processors
//
ValueNamePair[] retValue = new ValueNamePair[map.size()];
map.values().toArray(retValue);
return retValue;
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
use of org.compiere.model.MInvoice in project adempiere by adempiere.
the class POSGenericTicketHandler method printTicket.
@Override
public void printTicket() {
try {
ProcessInfo info = new ProcessInfo(null, 0);
info.setTransactionName(getPOS().get_TrxName());
if (!getPOS().isInvoiced()) {
ReportCtl.startDocumentPrint(ReportEngine.ORDER, null, getPOS().getC_Order_ID(), null, getPOS().getWindowNo(), false, null, info);
} else {
for (MInvoice invoice : getPOS().getOrder().getInvoices()) {
ReportCtl.startDocumentPrint(ReportEngine.INVOICE, null, invoice.getC_Invoice_ID(), null, getPOS().getWindowNo(), false, null, info);
}
}
} catch (Exception e) {
throw new AdempierePOSException("PrintTicket - Error Printing Ticket");
}
}
use of org.compiere.model.MInvoice in project adempiere by adempiere.
the class Collect method createPayment.
// payCheck
/**
* Create Payment object
* Refer to invoice if there is an invoice.
* Otherwise refer to order (it is a prepayment)
*
* @return Payment object
*
*/
private MPayment createPayment(String tenderType) {
MPayment payment = new MPayment(Env.getCtx(), 0, trxName);
payment.setAD_Org_ID(entityPOS.getAD_Org_ID());
payment.setC_POS_ID(entityPOS.getC_POS_ID());
payment.setTenderType(tenderType);
payment.setIsReceipt(true);
payment.setC_Order_ID(order.getC_Order_ID());
payment.setIsPrepayment(true);
payment.setC_BPartner_ID(getC_BPartner_ID());
payment.setDateTrx(getDateTrx());
payment.setDateAcct(getDateTrx());
int invoiceId = order.getC_Invoice_ID();
if (invoiceId > 0) {
payment.setC_Invoice_ID(invoiceId);
MInvoice invoice = new MInvoice(Env.getCtx(), payment.getC_Invoice_ID(), trxName);
payment.setDescription(Msg.getMsg(Env.getCtx(), "Invoice No ") + invoice.getDocumentNo());
} else {
payment.setDescription(Msg.getMsg(Env.getCtx(), "Order No ") + order.getDocumentNo());
}
order.setC_POS_ID(entityPOS.getC_POS_ID());
order.saveEx(trxName);
return payment;
}
use of org.compiere.model.MInvoice in project adempiere by adempiere.
the class HRCreateInvoice method doIt.
// prepare
/**
* Process
* @return message
* @throws Exception
*/
protected String doIt() throws Exception {
MHRProcess process = new MHRProcess(getCtx(), getPayrollProcessId(), get_TrxName());
final Timestamp dateInvoice = getDateInvoiced() != null ? getDateInvoiced() : process.getHR_Period_ID() > 0 ? process.getHR_Period().getStartDate() : process.getDateAcct();
Arrays.stream(getEmployeeIds(process)).filter(partnerId -> partnerId > 0).forEach(partnerId -> {
Trx.run(trxName -> {
int lastPartnerId = 0;
MHREmployee employee = null;
MInvoice invoice = null;
for (MHRMovement movement : getPayrollMovement(getPayrollProcessId(), partnerId, trxName)) {
MBPartner partner = new MBPartner(getCtx(), partnerId, trxName);
MHRAttribute attribute = MHRAttribute.getByConceptIdAndPartnerId(movement.getCtx(), movement.getHR_Concept_ID(), movement.getC_BPartner_ID(), movement.getValidFrom(), trxName);
if (attribute != null && attribute.getC_DocType_ID() == 0) {
log.log(Level.SEVERE, "@HR_Employee_ID@ " + partner.getName() + " @HR_Concept_ID@ " + movement.getHR_Concept().getName() + " @C_DocType_ID@ @NotFound@ : ");
addLog(0, null, null, "@HR_Employee_ID@ " + partner.getName() + " @HR_Concept_ID@ " + movement.getHR_Concept().getName() + " @C_DocType_ID@ @NotFound@ : ");
continue;
}
if (attribute != null && attribute.getC_Charge_ID() == 0) {
log.log(Level.SEVERE, "@HR_Employee_ID@ " + partner.getName() + " @HR_Concept_ID@ " + movement.getHR_Concept().getName() + " @C_Charge_ID@ @NotFound@ : ");
addLog(0, null, null, "@HR_Employee_ID@ " + partner.getName() + " @HR_Concept_ID@ " + movement.getHR_Concept().getName() + " @C_Charge_ID@ @NotFound@ : ");
continue;
}
if (movement.getC_BPartner_ID() != lastPartnerId) {
lastPartnerId = movement.getC_BPartner_ID();
employee = MHREmployee.getActiveEmployee(getCtx(), partner.getC_BPartner_ID(), trxName);
invoice = createInvoice(process, partner, employee, attribute.getC_DocType_ID(), dateInvoice);
if (invoice == null)
continue;
}
if (invoice != null)
createInvoiceLine(invoice, employee, movement, attribute.getC_Charge_ID());
}
});
});
return "@OK@";
}
use of org.compiere.model.MInvoice 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;
}
Aggregations