Automatically Create Purchase Order from Consignment Order

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Automatically Create Purchase Order from Consignment Order

Sky9928
Hi, i need to create the automatic created purchase order from Consignment. User input the product, quantity, and supplier from product then after submit button. Purchase Order automatically created until completed and create the invoice. I have successfully created the purchase order automatically but the problem is the shipping for order is missing so can't be received and the invoice is not created.  What step is missing in my code? Or there is better way tor create automatically order (Especially Purchase Order) ? Thanks...

Here is my code:
 public static Map<String, Object> createPOFromConsignment(DispatchContext dctx, Map<String, ? extends Object> context) throws GenericEntityException, CartItemModifyException, ItemNotFoundException {
                Delegator delegator = dctx.getDelegator();
                String productId = (String) context.get("productId");
                String partyId = (String) context.get("partyId");
                BigDecimal quantity = (BigDecimal) context.get("purchaseQuantity");
                ShoppingCart cart = new ShoppingCart(delegator, null, null,"IDR");
                cart.setOrderType("PURCHASE_ORDER");
                cart.setAttribute("supplierPartyId", partyId);
                cart.setBillFromVendorPartyId(partyId);
                ShoppingCartHelper cartHelper = new ShoppingCartHelper(delegator, dctx.getDispatcher(), cart);
                cartHelper.setCurrency("IDR");
                GenericValue orderHeader = new GenericValue();
                cart.addOrIncreaseItem(productId, null, quantity , null, null, null, null, null, null, null, null, null, null, null, null, dctx.getDispatcher());
                cart.setOrderId(delegator.getNextSeqId("OrderHeader"));
                cart.setOrderTermSet(true);
                cart.setShipGroupFacilityId(0,"10010");
                cart.setFacilityId("10010");
                CheckOutHelper checkOutHelper = new CheckOutHelper(dctx.getDispatcher(), delegator, cart);
                checkOutHelper.finalizeOrderEntryShip(0, "10075", null);
                cart.clearOrderNotes();
                cart.clearInternalOrderNotes();
                checkOutHelper.finalizeOrderEntryOptions(0, "STANDARD@_NA_", null, "false", null, "false", null, "", "", "", "");
                //checkOutHelper.createSalesConsignmentOrder((GenericValue)context.get("userLogin"));
                // create the result map
               GenericValue userLogin = (GenericValue)context.get("userLogin");
               List<GenericValue> trackingCodeOrders = FastList.newInstance();
               checkOutHelper.createOrder(userLogin, null, null, trackingCodeOrders, false, (String)dctx.getDelegator().getNextSeqId("Visit"), null);
               Map<String, Object> serviceContext = UtilMisc.<String, Object> toMap("orderId", cart.getOrderId(), "statusId",
                        "ORDER_APPROVED", "userLogin", userLogin);
                Map<String, Object> newSttsResult = null;
                try {
                    newSttsResult = dctx.getDispatcher().runSync("changeOrderStatus", serviceContext);
                     Map<String, Object> serviceContext2 = UtilMisc.<String, Object> toMap("orderId", cart.getOrderId(), "statusId",
                                "ORDER_COMPLETED", "userLogin", userLogin);
                        Map<String, Object> newSttsResult2 = null;
                        try {
                            newSttsResult2 = dctx.getDispatcher().runSync("changeOrderStatus", serviceContext2);
                        } catch (GenericServiceException e) {
                            Debug.logError(e, "Problem calling the changeOrderStatus service", module);
                        }
                } catch (GenericServiceException e) {
                    Debug.logError(e, "Problem calling the changeOrderStatus service", module);
                }
                Map<String, Object> result = ServiceUtil.returnSuccess("BERHASILLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL");

                return result;
        }