Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.infinite.retail;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.text.DateFormat;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import org.hibernate.criterion.Restrictions;
- import org.openbravo.base.exception.OBException;
- import org.openbravo.base.provider.OBProvider;
- import org.openbravo.dal.service.OBCriteria;
- import org.openbravo.dal.service.OBDal;
- import org.openbravo.model.common.businesspartner.BusinessPartner;
- import org.openbravo.model.common.businesspartner.Location;
- import org.openbravo.model.common.currency.Currency;
- import org.openbravo.model.common.enterprise.Warehouse;
- import org.openbravo.model.common.order.Order;
- import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
- import org.openbravo.model.financialmgmt.payment.PaymentTerm;
- import org.openbravo.model.pos.ExternalPOS;
- import org.openbravo.model.pricing.pricelist.PriceList;
- import org.openbravo.scheduling.ProcessBundle;
- import org.openbravo.service.db.DalBaseProcess;
- import org.wirabumi.gen.oez.ad_process.ImportOrder;
- public class ProcessPostingSalesOrder extends DalBaseProcess {
- @Override
- protected void doExecute(ProcessBundle bundle) throws Exception {
- // TODO Auto-generated method stub
- List<String> listIdStagPos = new ArrayList<String>();
- String sql = " Select ret_stagposorder_id from ret_stagposorder where isprocessed ='N' order by customer_key "; // urut by bp tapi field bp blm ada
- java.sql.Connection conn = OBDal.getInstance().getConnection();
- try {
- PreparedStatement ps = conn.prepareStatement(sql);
- ResultSet rs = ps.executeQuery();
- while (rs.next()) {
- listIdStagPos.add("rs");
- }
- }
- catch (Exception e) {
- e.printStackTrace();
- throw new OBException(e);
- }
- for (String stagPosOrderid : listIdStagPos )
- {
- StagPOSOrder stagPOSOrder = OBDal.getInstance().get(StagPOSOrder.class, stagPosOrderid);
- HashMap<Warehouse, ExternalPOS> externalPosCache = new HashMap<Warehouse, ExternalPOS>();
- OBCriteria<ExternalPOS> extPosCriteria = OBDal.getInstance().createCriteria(ExternalPOS.class);
- String locatorKey = stagPOSOrder.getLocatorKey();
- for (ExternalPOS externalPOS : extPosCriteria.list()) {
- externalPosCache.put((Warehouse) externalPOS.getValue(locatorKey), externalPOS);
- }
- String bpartnerCustomerKey = stagPOSOrder.getCustomerKey();
- if (bpartnerCustomerKey == null )
- {
- }
- String bpPartnerLocationKey = stagPOSOrder.getCustomerAddressKey();
- Date date = stagPOSOrder.getOrderDate();
- DateFormat outputFormatter = new SimpleDateFormat("dd/MM/yyyy");
- String dateOrder = outputFormatter.format(date);
- // UNTUK HEADER
- // get businness partner
- OBCriteria<BusinessPartner> bpCriteria = OBDal.getInstance().createCriteria(BusinessPartner.class); // dapatkan list dari bpartner dari costumer key
- bpCriteria.add(Restrictions.eq(BusinessPartner.PROPERTY_SEARCHKEY, bpartnerCustomerKey));
- BusinessPartner bp = null;
- if (bpCriteria.list().size() > 0) {
- bp = bpCriteria.list().get(0);
- }
- String bpartnerId = bp.getId();
- BusinessPartner businessPartner = OBDal.getInstance().get(BusinessPartner.class, bpartnerId);
- //get location business partner
- OBCriteria<Location> locationBp = OBDal.getInstance().createCriteria(Location.class);
- locationBp.add(Restrictions.eq(Location.PROPERTY_NAME , locationBp));
- Location locBp = null;
- if (locationBp.list().size()>0) {
- locBp = locationBp.list().get(0);
- }
- // untuk LINE
- //
- String bpartnerIdTemp = null;
- String dateOrderTemp = null;
- if (bpartnerIdTemp == null) {
- //1. buat order header
- org.openbravo.model.common.order.Order orderHeader = OBProvider.getInstance().get(org.openbravo.model.common.order.Order.class);
- orderHeader.setOrganization(stagPOSOrder.getOrganization());
- orderHeader.setBusinessPartner(bp);
- //orderHeader.setDocumentType(documentType);
- //orderHeader.setDocumentNo(documentNo);
- orderHeader.setPartnerAddress(locBp);
- orderHeader.setDocumentStatus("CO");
- // buat order lines
- org.openbravo.model.common.order.OrderLine orderLine = OBProvider.getInstance().get(org.openbravo.model.common.order.OrderLine.class);
- orderLine.setOrganization(orderHeader.getOrganization());
- dateOrderTemp = dateOrder;
- bpartnerIdTemp = bpartnerId;
- } else if ( (bpartnerIdTemp.equalsIgnoreCase(bpartnerId)) || (dateOrder.equalsIgnoreCase(dateOrderTemp)) ) {
- // buat order lines
- org.openbravo.model.common.order.OrderLine orderLine = OBProvider.getInstance().get(org.openbravo.model.common.order.OrderLine.class);
- //orderLine.setSalesOrder(salesOrder);
- orderLine.setOrganization(stagPOSOrder.getOrganization());
- dateOrderTemp = dateOrder;
- bpartnerIdTemp = bpartnerId;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement