Search in sources :

Example 31 with MInvoice

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;
    }
}
Also used : Query(org.compiere.model.Query) HashMap(java.util.HashMap) MInvoice(org.compiere.model.MInvoice) ValueNamePair(org.compiere.util.ValueNamePair) AdempierePOSException(org.adempiere.pos.AdempierePOSException) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 32 with MInvoice

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");
    }
}
Also used : AdempierePOSException(org.adempiere.pos.AdempierePOSException) MInvoice(org.compiere.model.MInvoice) ProcessInfo(org.compiere.process.ProcessInfo) AdempierePOSException(org.adempiere.pos.AdempierePOSException)

Example 33 with MInvoice

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;
}
Also used : MPayment(org.compiere.model.MPayment) MInvoice(org.compiere.model.MInvoice)

Example 34 with MInvoice

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@";
}
Also used : Arrays(java.util.Arrays) MHREmployee(org.eevolution.model.MHREmployee) MHRAttribute(org.eevolution.model.MHRAttribute) Timestamp(java.sql.Timestamp) Env(org.compiere.util.Env) MPaymentTerm(org.compiere.model.MPaymentTerm) MBPartnerLocation(org.compiere.model.MBPartnerLocation) Level(java.util.logging.Level) MInvoice(org.compiere.model.MInvoice) MHRProcess(org.eevolution.model.MHRProcess) BigDecimal(java.math.BigDecimal) List(java.util.List) Query(org.compiere.model.Query) MHRMovement(org.eevolution.model.MHRMovement) MBPartner(org.compiere.model.MBPartner) MInvoiceLine(org.compiere.model.MInvoiceLine) Msg(org.compiere.util.Msg) Trx(org.compiere.util.Trx) DocAction(org.compiere.process.DocAction) I_C_BPartner(org.compiere.model.I_C_BPartner) I_C_BPartner_Location(org.compiere.model.I_C_BPartner_Location) MHRProcess(org.eevolution.model.MHRProcess) MHRAttribute(org.eevolution.model.MHRAttribute) MInvoice(org.compiere.model.MInvoice) MBPartner(org.compiere.model.MBPartner) Timestamp(java.sql.Timestamp) MHREmployee(org.eevolution.model.MHREmployee) MHRMovement(org.eevolution.model.MHRMovement)

Example 35 with MInvoice

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;
}
Also used : MPaymentTerm(org.compiere.model.MPaymentTerm) MInvoice(org.compiere.model.MInvoice) MBPartnerLocation(org.compiere.model.MBPartnerLocation)

Aggregations

MInvoice (org.compiere.model.MInvoice)70 BigDecimal (java.math.BigDecimal)25 MInvoiceLine (org.compiere.model.MInvoiceLine)23 MPayment (org.compiere.model.MPayment)12 ResultSet (java.sql.ResultSet)10 Timestamp (java.sql.Timestamp)10 MBPartner (org.compiere.model.MBPartner)10 MInOut (org.compiere.model.MInOut)10 MOrder (org.compiere.model.MOrder)10 PreparedStatement (java.sql.PreparedStatement)9 MInOutLine (org.compiere.model.MInOutLine)8 MOrderLine (org.compiere.model.MOrderLine)6 ArrayList (java.util.ArrayList)5 AdempiereException (org.adempiere.exceptions.AdempiereException)5 MDocType (org.compiere.model.MDocType)5 KeyNamePair (org.compiere.util.KeyNamePair)5 ValueNamePair (org.compiere.util.ValueNamePair)5 MCashLine (org.compiere.model.MCashLine)4 MClient (org.compiere.model.MClient)4 MProduct (org.compiere.model.MProduct)4