RSS

create sales order

26 Jul

void CreateSalesOrder(container con,CustAccount custAccount,Description custDescription)
{
NumberSeq num;
str customerRef;
str deliveryName;
str deliveryStreet;
ExternalItemId externalItemId;

;

//create sales table
salesTable.clear();
salesTable.initValue();

num = NumberSeq::newGetNum(SalesParameters::numRefSalesId());
newSalesId = num.num();

if (salesTable::exist(newSalesId))
{
num.abort();
checkFailed(“@LIQ1977”);
checkFailed(strfmt(“@LIQ1978”, newSalesId));
throw error(“@SYS23020”);
}

salesTable.SalesId = newSalesId;
num.used();

if(custDescription != “”)
{
salesTable.SalesName = custDescription;
}

//fetch the customer details from cust table using account no selected from drop-down list
select * from custTable where custTable.AccountNum == custAccount;

salesTable.CustAccount = custTable.AccountNum;
salesTable.InvoiceAccount = custTable.InvoiceAccount;
salesTable.SalesType = SalesType::Sales;
salesTable.SalesStatus = SalesStatus::Backorder;
salesTable.CurrencyCode = custTable.Currency;

salesTable.CustGroup = custTable.CustGroup;
salesTable.DeliveryDateControlType = SalesDeliveryDateControlType::SalesLeadTime;

//Set dates as systemDateTime
salesTable.ReceiptDateRequested = systemdateget();
salesTable.ShippingDateRequested = systemdateget();

salesTable.PurchOrderFormNum = conpeek(con,4);
customerRef = substr(conpeek(con,7),7,2);
salesTable.CustomerRef = customerRef;
salesTable.LanguageId = #Language;
salesTable.DlvMode = #DlvMode;

//Init from cust table
salesTable.initFromCustTable();

//Overwrite customer address with the address from user file.
//concatenate string
deliveryName = conpeek(con,8) + ‘ ‘ + conpeek(con,9) + ‘ ‘ + conpeek(con,10);
salesTable.DeliveryName = deliveryName;
//concatenate string
deliveryStreet = conpeek(con,11) + ‘ \ ‘ + conpeek(con,12) + ‘ ‘ + conpeek(con,13);
salesTable.DeliveryStreet = deliveryStreet;

salesTable.DeliveryCity = strrtrim(conpeek(con,14));
salesTable.DeliveryState = strrtrim(conpeek(con,15));
salesTable.DeliveryZipCode = strrtrim(conpeek(con,16));
salesTable.ShipCarrierDeliveryContact = conpeek(con,17);

//Craete Sales Order
salesTable.insert();

// Create Sales Order Line
salesLine.SalesId = salesTable.SalesId;
salesLine.initFromSalesTable(salesTable);

externalItemId = conpeek(con,3);
//Get ItemId from custVendExternalItem table using externalItemId from file
select ItemId,RecId from custVendExternalItem where custVendExternalItem.ExternalItemId == externalItemId;
if(custVendExternalItem.RecId == 0)
{
throw error(‘@LIQ2648’);
}
//Set sales item id from custVendExternalItem table
salesLine.ItemId = custVendExternalItem.ItemId;
salesLine.SalesUnit = InventTable::find(salesLine.ItemId).salesUnitId();
select * from inventTable where inventTable.ItemId == salesLine.ItemId;
salesLine.initFromInventTable(inventTable);

select * from inventDim where inventDim.InventLocationId == custTable.InventLocation && inventDim.InventSiteId == custTable.InventSiteId;

if(inventDim.RecId != 0)
{
salesLine.InventDimId = inventDim.inventDimId;
}
else
{
throw error(“@LIQ1979”);
}

//Set Qty as 1 by default as per business – Bo
salesLine.SalesQty = 1;
salesLine.ConfirmedDlv = salesTable.ShippingDateConfirmed;
salesLine.lineNum = SalesLine::lastLineNum(salesLine.salesId) + 1.0;
salesLine.LinePercent = 10;
salesLine.RemainInventPhysical = 1;
salesLine.RemainSalesPhysical = 1;
salesLine.DlvMode = #DlvMode;
salesLine.SalesStatus = SalesStatus::Backorder;
//salesLine.SalesPrice;
salesLine.setPriceDisc(inventDim);

//Insert sales line items
salesLine.insert();

}

 
Leave a comment

Posted by on July 26, 2011 in X++

 

Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
axhowto

Blog about ax with sample codes, tips and tricks.

GM Dynamics Blogs

Transform IT with Digital Trasformation and Social Innovation

Ms. Dynamic Millennial

Unboxing Microsoft Dynamics 365 for Finance and Operations

DynaD365Power

Exploring the new vision of the Power platform

Dynamics Vision 365

The FinOps pulse

Breaking Bong

I write when no one is watching

ErpCoder

Microsoft Dynamics 365 Business Management Solution Enthusiast

Dynamics 365 Finance

Dynamics 365 Finance & Much More.

Microsoft Dynamics AX

“ANYONE WHO STOPS LEARNING IS OLD, WHETHER AT TWENTY OR EIGHTY.” —HENRY FORD

Sumit Potbhare

Dynamics 365 for Commerce

iotsolution.se

This is your site about D365 (Finance and Supply Chain Management), IoT (Internet of Things) and HoloLens

Omni 365

Dynamics 365 Finance and Operations Blog

DIY D365

Power Platform Done Your Way

Azure Integration services for Dynamics 365

Azure Integration services for Dynamics 365 Unified Operations, Logic Apps, Azure Functions, REST

%d bloggers like this: