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();

}

Advertisements
 
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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

 
All About Dynamics 365

Dynamics 365, D365, Implementor

syedrafayali

This blog contains information about Functional techniques and guidelines in Microsoft Dynamics AX, including tips, tricks, tutorials, tools and upcoming news enhancement in Microsoft Dynamics Ax

Philippsen's Blog

Everyday findings in my world of .net and related stuff

Microsoft Dynamics AX

A great WordPress.com site

Finite Minds

Adventures in IoT

Dynamics Ax

Technical Knowledge

timsaxblog

A blog about implementing Microsoft Dynamics AX and Dynamics 365 for Operations

Microsoft Dynamics 365 Blog

All Things Dynamics 365, A Blog by sandeep chaudhury

DEVSerra - Dynamics AX development blog

Your official Microsoft Dynamics AX blog.

OrganicAX

Discovering Dynamics

AX

A blog by Hai Nguyen

Learn Dynamics Ax with Johnkrish

Live as if you were to die tomorrow. Learn as if you were to live forever - Mahatma Gandhi ****** The more I learn, the less I know - Albert Einstein

Twisted Untwirled

Just another WordPress.com site

ramdynamicsax

Just another WordPress.com site

guyterry's Dynamics AX blog

Just another Dynamics AX blog

Chaitanya kumar

Happy DAXing...!!! :)

%d bloggers like this: