Advertisement
tko_pb

pak zen

Sep 27th, 2018
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.94 KB | None | 0 0
  1. package org.infinite.retail;
  2.  
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.text.DateFormat;
  6. import java.text.SimpleDateFormat;
  7. import java.util.ArrayList;
  8. import java.util.Date;
  9. import java.util.HashMap;
  10. import java.util.List;
  11.  
  12. import org.hibernate.criterion.Restrictions;
  13. import org.openbravo.base.exception.OBException;
  14. import org.openbravo.base.provider.OBProvider;
  15. import org.openbravo.dal.service.OBCriteria;
  16. import org.openbravo.dal.service.OBDal;
  17. import org.openbravo.model.common.businesspartner.BusinessPartner;
  18. import org.openbravo.model.common.businesspartner.Location;
  19. import org.openbravo.model.common.currency.Currency;
  20. import org.openbravo.model.common.enterprise.Warehouse;
  21. import org.openbravo.model.common.order.Order;
  22. import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
  23. import org.openbravo.model.financialmgmt.payment.PaymentTerm;
  24. import org.openbravo.model.pos.ExternalPOS;
  25. import org.openbravo.model.pricing.pricelist.PriceList;
  26. import org.openbravo.scheduling.ProcessBundle;
  27. import org.openbravo.service.db.DalBaseProcess;
  28. import org.wirabumi.gen.oez.ad_process.ImportOrder;
  29.  
  30. public class ProcessPostingSalesOrder extends DalBaseProcess {
  31.  
  32.     @Override
  33.     protected void doExecute(ProcessBundle bundle) throws Exception {
  34.         // TODO Auto-generated method stub
  35.  
  36.         List<String> listIdStagPos = new ArrayList<String>();
  37.         String sql = " Select ret_stagposorder_id from ret_stagposorder where isprocessed ='N' order by customer_key "; // urut by bp tapi field bp blm ada
  38.         java.sql.Connection conn = OBDal.getInstance().getConnection();
  39.         try {
  40.             PreparedStatement ps = conn.prepareStatement(sql);
  41.             ResultSet rs = ps.executeQuery();
  42.             while (rs.next()) {
  43.                 listIdStagPos.add("rs");
  44.             }
  45.  
  46.         }
  47.         catch (Exception e) {
  48.             e.printStackTrace();
  49.             throw new OBException(e);
  50.         }
  51.  
  52.         for (String stagPosOrderid : listIdStagPos )
  53.         {
  54.             StagPOSOrder stagPOSOrder = OBDal.getInstance().get(StagPOSOrder.class, stagPosOrderid);
  55.            
  56.             HashMap<Warehouse, ExternalPOS> externalPosCache = new HashMap<Warehouse, ExternalPOS>();
  57.             OBCriteria<ExternalPOS> extPosCriteria = OBDal.getInstance().createCriteria(ExternalPOS.class);
  58.             String locatorKey = stagPOSOrder.getLocatorKey();
  59.             for (ExternalPOS externalPOS : extPosCriteria.list()) {
  60.                 externalPosCache.put((Warehouse) externalPOS.getValue(locatorKey), externalPOS);
  61.             }
  62.                        
  63.             String bpartnerCustomerKey = stagPOSOrder.getCustomerKey();
  64.             if (bpartnerCustomerKey == null )
  65.             {
  66.                
  67.             }
  68.             String bpPartnerLocationKey = stagPOSOrder.getCustomerAddressKey();
  69.             Date date = stagPOSOrder.getOrderDate();
  70.             DateFormat outputFormatter = new SimpleDateFormat("dd/MM/yyyy");
  71.             String dateOrder = outputFormatter.format(date);
  72.  
  73.             // UNTUK HEADER
  74.             // get businness partner
  75.             OBCriteria<BusinessPartner> bpCriteria = OBDal.getInstance().createCriteria(BusinessPartner.class); // dapatkan list dari bpartner dari costumer key
  76.             bpCriteria.add(Restrictions.eq(BusinessPartner.PROPERTY_SEARCHKEY, bpartnerCustomerKey));
  77.             BusinessPartner bp = null;
  78.             if (bpCriteria.list().size() > 0) {
  79.                 bp = bpCriteria.list().get(0);
  80.             }
  81.             String bpartnerId = bp.getId();
  82.  
  83.             BusinessPartner businessPartner = OBDal.getInstance().get(BusinessPartner.class, bpartnerId);
  84.  
  85.             //get location business partner
  86.             OBCriteria<Location> locationBp = OBDal.getInstance().createCriteria(Location.class);
  87.             locationBp.add(Restrictions.eq(Location.PROPERTY_NAME , locationBp));
  88.             Location locBp = null;
  89.             if (locationBp.list().size()>0) {
  90.                 locBp = locationBp.list().get(0);
  91.             }
  92.  
  93.  
  94.             // untuk LINE
  95.             //
  96.            
  97.             String bpartnerIdTemp = null;
  98.             String dateOrderTemp = null;
  99.             if (bpartnerIdTemp == null) {
  100.  
  101.                 //1. buat order header
  102.                 org.openbravo.model.common.order.Order orderHeader = OBProvider.getInstance().get(org.openbravo.model.common.order.Order.class);
  103.                 orderHeader.setOrganization(stagPOSOrder.getOrganization());
  104.                 orderHeader.setBusinessPartner(bp);
  105.                 //orderHeader.setDocumentType(documentType);
  106.                 //orderHeader.setDocumentNo(documentNo);
  107.                 orderHeader.setPartnerAddress(locBp);
  108.  
  109.                 orderHeader.setDocumentStatus("CO");
  110.  
  111.                 // buat order lines
  112.                 org.openbravo.model.common.order.OrderLine orderLine = OBProvider.getInstance().get(org.openbravo.model.common.order.OrderLine.class);
  113.                 orderLine.setOrganization(orderHeader.getOrganization());
  114.  
  115.  
  116.                 dateOrderTemp = dateOrder;
  117.                 bpartnerIdTemp = bpartnerId;
  118.             } else if ( (bpartnerIdTemp.equalsIgnoreCase(bpartnerId)) || (dateOrder.equalsIgnoreCase(dateOrderTemp)) ) {
  119.  
  120.                 // buat order lines
  121.                 org.openbravo.model.common.order.OrderLine orderLine = OBProvider.getInstance().get(org.openbravo.model.common.order.OrderLine.class);
  122.                 //orderLine.setSalesOrder(salesOrder);
  123.  
  124.                 orderLine.setOrganization(stagPOSOrder.getOrganization());
  125.  
  126.  
  127.  
  128.                 dateOrderTemp = dateOrder;
  129.                 bpartnerIdTemp = bpartnerId;
  130.  
  131.             }
  132.  
  133.  
  134.         }
  135.  
  136.  
  137.     }
  138.  
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement