Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.aoi.enh.process;
- import java.math.BigDecimal;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.Timestamp;
- import java.util.List;
- import java.util.logging.Level;
- import org.aoi.enh.model.X_rz_invoice_fwd;
- import org.aoi.enh.model.X_rz_invoice_fwdline;
- import org.compiere.model.MBPartner;
- import org.compiere.model.MInOut;
- import org.compiere.model.MInvoice;
- import org.compiere.model.MInvoiceLine;
- import org.compiere.model.MPriceList;
- import org.compiere.model.MProject;
- import org.compiere.model.Query;
- import org.compiere.process.ProcessInfoParameter;
- import org.compiere.process.SvrProcess;
- import org.compiere.util.DB;
- import org.compiere.util.Env;
- public class GenerateInvoiceVendorDetail extends SvrProcess
- {
- private int M_InOut_ID;
- private int p_DocTypeAP_Invoice;
- private int p_C_ConversionType_ID;
- protected void prepare() {
- ProcessInfoParameter[] para = getParameter();
- for (int i = 0; i < para.length; i++) {
- String name = para[i].getParameterName();
- if (name.equals("C_DocType_ID")) {
- p_DocTypeAP_Invoice = para[i].getParameterAsInt();
- } else if (name.equals("C_ConversionType_ID")) {
- p_C_ConversionType_ID = para[i].getParameterAsInt();
- } else {
- log.log(Level.SEVERE, "Unknown Parameter: " + name);
- }
- }
- M_InOut_ID = getRecord_ID();
- }
- protected String doIt() throws Exception {
- String msg = "";
- String InvName = "";
- String InvFwd = "";
- MInOut shipment = new MInOut(getCtx(), this.M_InOut_ID, get_TrxName());
- StringBuffer sql = new StringBuffer();
- sql.append("select distinct(invoice_fwd) as invoice_fwd from rz_invoice_fwd where IsInvoiced = 'N' AND processed = 'N' ")
- .append("AND m_inout_ID = ? ");
- PreparedStatement pstmt = null;
- ResultSet rs = null;
- try {
- pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
- pstmt.setInt(1, this.M_InOut_ID);
- rs = pstmt.executeQuery();
- while (rs.next()) {
- int lineNo = 0;
- int PrjID = 0;
- int PartnerID = 0;
- int PartnerLocID = 0;
- InvFwd = rs.getString("invoice_fwd");
- if (InvFwd == null) msg = String.valueOf(msg) + "Invoice_Fwd is Null, ";
- X_rz_invoice_fwd mfwd = (X_rz_invoice_fwd)(new Query(getCtx(), "rz_invoice_fwd", " invoice_fwd = ? AND processed='N' ", get_TrxName()))
- .setClient_ID()
- .setOnlyActiveRecords(true)
- .setParameters(new Object[] { rs.getString("invoice_fwd")})
- .first();
- PrjID = mfwd.getC_Project_ID();
- if (PrjID == 0) msg = String.valueOf(msg) + "Forwarder is Not Set, ";
- MProject prj = new MProject(getCtx(), PrjID, get_TrxName());
- PartnerID = prj.getC_BPartner_ID();
- PartnerLocID = prj.getC_BPartner_Location_ID();
- MBPartner bpForwarder = new MBPartner(getCtx(), PartnerID, get_TrxName());
- if (PartnerID == 0) {
- msg = msg.toString() + "Bpartner Forwarder " + InvFwd + " Kosong..... ";
- }
- else if (PartnerLocID == 0) {
- msg = msg.toString() + "Bpartner Forwarder " + InvFwd + " PO Payment Term Not Set... ";
- }
- if (msg == "") {
- MInvoice invoice = new MInvoice(getCtx(), 0, get_TrxName());
- invoice.setAD_Org_ID(shipment.getAD_Org_ID());
- invoice.setC_DocTypeTarget_ID(this.p_DocTypeAP_Invoice);
- invoice.setC_DocType_ID(this.p_DocTypeAP_Invoice);
- invoice.setIsSOTrx(false);
- invoice.setDateInvoiced(new Timestamp(System.currentTimeMillis()));
- invoice.setDateAcct(new Timestamp(System.currentTimeMillis()));
- invoice.setC_BPartner_ID(PartnerID);
- invoice.setC_BPartner_Location_ID(PartnerLocID);
- invoice.setPaymentRule("P");
- //invoice.setC_PaymentTerm_ID(bpForwarder.getPO_PaymentTerm_ID());
- invoice.setC_PaymentTerm_ID(prj.getC_PaymentTerm_ID());
- invoice.setC_ConversionType_ID(this.p_C_ConversionType_ID);
- MPriceList pl = (MPriceList)(new Query(getCtx(), "M_PriceList", " C_Currency_ID = ? AND isSOPriceList = 'N' ", get_TrxName()))
- .setClient_ID()
- .setOnlyActiveRecords(true)
- .setParameters(new Object[] { Integer.valueOf(mfwd.getC_Currency_ID())})
- .first();
- invoice.setM_PriceList_ID(pl.get_ID());
- invoice.setC_Currency_ID(mfwd.getC_Currency_ID());
- invoice.set_ValueOfColumn("kst_InvoiceVendor", InvFwd);
- invoice.setDescription("Invoice Forwarder");
- invoice.saveEx(get_TrxName());
- int fwdID = 0;
- /* Modified by Roynaldo - 20190821 */
- //String sqlFwd = "invoice_fwd = ? AND processed = 'N' ";
- String sqlFwd = "invoice_fwd = ? AND processed = 'N' AND M_InOut_ID=?";
- /* End Modified by Roynaldo - 20190821 */
- List<X_rz_invoice_fwd> fwd = (new Query(getCtx(), "rz_invoice_fwd", sqlFwd, get_TrxName()))
- .setClient_ID()
- .setOnlyActiveRecords(true)
- /* Modified by Roynaldo - 20190821 */
- //.setParameters(new Object[] {InvFwd})
- .setParameters(new Object[] {InvFwd, M_InOut_ID})
- /* End Modified by Roynaldo - 20190821 */
- .list();
- for (X_rz_invoice_fwd m_forwarder : fwd) {
- fwdID = m_forwarder.get_ID();
- m_forwarder.setProcessed(true);
- m_forwarder.setIsInvoiced(true);
- m_forwarder.saveEx();
- /* Added by Roynaldo - 20200109 */
- int C_Activity_ID = m_forwarder.get_ValueAsInt("C_Activity_ID");
- int C_Campaign_ID = m_forwarder.get_ValueAsInt("C_Campaign_ID");
- invoice.setC_Activity_ID(C_Activity_ID);
- invoice.setC_Campaign_ID(C_Campaign_ID);
- invoice.saveEx(get_TrxName());
- /* End Added by Roynaldo - 20200109 */
- BigDecimal actamt = Env.ZERO;
- String sqlFwdline = " rz_invoice_fwd_ID = ? ";
- List<X_rz_invoice_fwdline> fwdline = (new Query(getCtx(), "rz_invoice_fwdline", sqlFwdline, get_TrxName()))
- .setClient_ID()
- .setOnlyActiveRecords(true)
- .setParameters(new Object[] { Integer.valueOf(fwdID) })
- .setOrderBy("Line ASC")
- .list();
- for (X_rz_invoice_fwdline fwdl : fwdline) {
- actamt = actamt.add(fwdl.getActualAmt());
- MInvoiceLine invLine = new MInvoiceLine(invoice);
- lineNo++;
- invLine.setLine(lineNo * 10);
- invLine.setC_Charge_ID(fwdl.getC_Charge_ID());
- invLine.setPrice(fwdl.getActualAmt());
- invLine.setQty(Env.ONE);
- invLine.set_ValueOfColumn("rz_invoice_fwd_ID", Integer.valueOf(fwdID));
- invLine.set_ValueOfColumn("rz_invoice_fwdline_ID", Integer.valueOf(fwdl.get_ID()));
- /* Added by Roynaldo - 20200109 */
- invLine.setC_Activity_ID(C_Activity_ID);
- invLine.setC_Campaign_ID(C_Campaign_ID);
- /* End Added by Roynaldo - 20200109 */
- invLine.saveEx(get_TrxName());
- fwdl.setProcessed(true);
- fwdl.saveEx();
- }
- }
- InvName = String.valueOf(InvName) + invoice.getDocumentNo() + " ( " + lineNo + " Lines ), ";
- }
- }
- } catch (Exception e) {
- log.log(Level.WARNING, e.toString());
- } finally {
- DB.close(rs, pstmt);
- pstmt = null;
- rs = null;
- }
- return msg.toString() + InvName;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement