@mohamed1walha,
Below is the sample to create the Sales Order through code. Hope this help!!
SOOrder newOrder = new SOOrder();
newOrder.OrderType = "SO";
newOrder = SOGraph.Document.Insert(newOrder);
newOrder = PXCache<SOOrder>.CreateCopy(SOGraph.Document.Search<SOOrder.orderNbr>(newOrder.OrderNbr));
newOrder = PXCache<SOOrder>.CreateCopy(SOGraph.Document.Update(newOrder));
newOrder.CustomerID = BaseGraph.Document.Current.CustomerID;
newOrder.CustomerLocationID = BaseGraph.Document.Current.CustomerLocationID;
newOrder.OrderDesc = "CM Order Created for " + objSOOrder.OrderType + " :" + objSOOrder.OrderNbr;
newOrder.TaxZoneID = BaseGraph.Document.Current.TaxZoneID;
newOrder.GetExtension<SOOrderAMIOEExt>().UsrKNAMIShipTermsID = null;
SOGraph.Document.Current = newOrder;
SOGraph.Document.Current = SOGraph.Document.Update(SOGraph.Document.Current);
SOGraph.Document.Current.ShipAddressID = BaseGraph.Document.Current.ShipAddressID;
SOGraph.Document.Current.ShipContactID = BaseGraph.Document.Current.ShipContactID;
SOGraph.Document.Current.BillAddressID = BaseGraph.Document.Current.BillAddressID;
SOGraph.Document.Current.BillContactID = BaseGraph.Document.Current.BillContactID;
SOGraph.Document.Current = SOGraph.Document.Update(SOGraph.Document.Current);
foreach (SOLine objSOLine in BaseGraph.Transactions.Select().FirstTableItems.ToList().Where(x => x.GetExtension<SOLineAMIOEExt>().UsrKNAMIOERefundQty > 0))
{
SOLineAMIOEExt lineExt = objSOLine.GetExtension<SOLineAMIOEExt>();
SOLine newitem = (SOLine)SOGraph.Transactions.Cache.Insert();
newitem.InventoryID = objSOLine.InventoryID;
SOGraph.Transactions.Cache.Update(newitem);
newitem.Qty = lineExt.UsrKNAMIOERefundQty;
newitem.ReasonCode = lineExt.UsrKNAMIOEReasonCode;
newitem.ManualPrice = true;
newitem.SiteID = objSOLine.SiteID;
newitem.CuryUnitPrice = objSOLine.CuryUnitPrice;
SOGraph.Transactions.Cache.Update(newitem);
}
if (shipRefundFilter.RefundFreightAmount > 0)
{
InventoryItem objItem = PXSelect<InventoryItem, Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>.
Select(SOGraph, SOGraph.sosetup.Current.GetExtension<SOSetupAMIOEExt>().UsrKNAMIFreightChrg);
if (objItem != null)
{
SOLine newitem = (SOLine)SOGraph.Transactions.Cache.Insert();
newitem.InventoryID = objItem.InventoryID;
SOGraph.Transactions.Cache.Update(newitem);
newitem.Qty = 1;
newitem.ReasonCode = "DAMAGED";
newitem.ManualPrice = true;
newitem.SiteID = objItem.DfltSiteID;
newitem.CuryUnitPrice = shipRefundFilter.RefundFreightAmount;
SOGraph.Transactions.Cache.Update(newitem);
}
}
if (shipRefundFilter.RefundDiscountAmount > 0)
{
InventoryItem objDiscITem = PXSelect<InventoryItem, Where<InventoryItem.inventoryCD, Equal<Required<InventoryItem.inventoryCD>>>>.Select(SOGraph, "ORDERDISCOUNT");
if (objDiscITem != null)
{
SOLine newitem = (SOLine)SOGraph.Transactions.Cache.Insert();
newitem.InventoryID = objDiscITem.InventoryID;
SOGraph.Transactions.Cache.Update(newitem);
newitem.Qty = 1;
newitem.ReasonCode = "DAMAGED";
newitem.ManualPrice = true;
newitem.SiteID = objDiscITem.DfltSiteID;
newitem.CuryUnitPrice = -(Math.Abs(Convert.ToDecimal(shipRefundFilter.RefundDiscountAmount)));
SOGraph.Transactions.Cache.Update(newitem);
}
}
SOGraph.Save.Press();
}