In one of implementation project. I got a requirement in this Client wants to update sales orders that were created in past.Requirement was to update sales price by applying new trade agreements that were created later in system after the sales order creation.
I used the following code to update the sales price.
private void updateSalesPrice()
{
SalesLine salesLine;
PriceDiscPolicyCheckPolicy checkPolicy;
str text;
SysOperationProgress operationProgress;
boolean salesLineFound;
#AviFiles
// 2013-09-25 #23667_DA0374 dkos: Update Sales Order Unit Price -->
Dialog dialog;
DialogField dfStartDate;
DialogText dialogText;
TransDate startDate;
// 2013-09-25 #23667_DA0374 dkos: Update Sales Order Unit Price <-- font="">-->
;
operationProgress = new SysOperationProgress();
operationProgress.setCaption("@DTD849");
operationProgress.setAnimation(#AviUpdate);
// 2013-09-25 #23667_DA0374 dkos: Update Sales Order Unit Price -->
dialog = new Dialog("@DTD847");
dfStartDate = dialog.addField(extendedTypeStr(TransDate), "@DTD1042");
dfStartDate.value(dateNull());
text = "@DTD845" + '\n\n' +"@DTD846" ;
dialogText = dialog.addText(text);
dialogText.displayHeight(4);
dialogText.displayLengthValue(50);
if (dialog.run())
{
startDate = dfStartDate.value();
// 2013-09-25 #23667_DA0374 dkos: Update Sales Order Unit Price <-- font="">-->
ttsBegin;
while select forUpdate salesLine
where salesLine.SalesType == SalesType::Sales
&& salesLine.SalesStatus <= SalesStatus::Delivered
&& !salesLine.InventTransIdReturn //optimisation dkos 2013-09-25
&& (salesLine.ShippingDateRequested >= startDate || startDate == dateNull()) // 2013-09-25 #23667_DA0374 dkos: Update Sales Order Unit Price
{
salesLine.ManualEntryChangepolicy = 0; //optimisation dkos 2013-09-25
// 2013-02-18 #20169 csek: Job to update SOprice -->
salesLine.SystemEntryChangePolicy = 0; //optimisation dkos 2013-09-25
// 2013-02-18 #20169 csek: Job to update SOprice <-- font="">-->
checkPolicy = PriceDiscPolicyCheckPolicy::newFromParm(salesLine.PriceDiscResultFields::parmPriceDiscResultFields());
salesLine.salesPurchLine::resetPriceAgreement();
salesLine.setPriceAgreement(salesLine.inventDim(), null ,false,true);// 2013-02-07 #20169 csek: Job to update SOprice
salesLine.LineAmount = salesLine.calcLineAmountForced(salesLine.SalesQty, checkPolicy);
operationProgress.setText(strFmt("@DTD850",salesLine.SalesId));
salesLine.update();
salesLineFound = true;
}
ttsCommit;
}
if (salesLineFound)
{
info("@DTD1041"); // 2013-09-25 #23667_DA0374 dkos: Update Sales Order Unit Price
}
}
I used the following code to update the sales price.
private void updateSalesPrice()
{
SalesLine salesLine;
PriceDiscPolicyCheckPolicy checkPolicy;
str text;
SysOperationProgress operationProgress;
boolean salesLineFound;
#AviFiles
// 2013-09-25 #23667_DA0374 dkos: Update Sales Order Unit Price -->
Dialog dialog;
DialogField dfStartDate;
DialogText dialogText;
TransDate startDate;
// 2013-09-25 #23667_DA0374 dkos: Update Sales Order Unit Price <-- font="">-->
;
operationProgress = new SysOperationProgress();
operationProgress.setCaption("@DTD849");
operationProgress.setAnimation(#AviUpdate);
// 2013-09-25 #23667_DA0374 dkos: Update Sales Order Unit Price -->
dialog = new Dialog("@DTD847");
dfStartDate = dialog.addField(extendedTypeStr(TransDate), "@DTD1042");
dfStartDate.value(dateNull());
text = "@DTD845" + '\n\n' +"@DTD846" ;
dialogText = dialog.addText(text);
dialogText.displayHeight(4);
dialogText.displayLengthValue(50);
if (dialog.run())
{
startDate = dfStartDate.value();
// 2013-09-25 #23667_DA0374 dkos: Update Sales Order Unit Price <-- font="">-->
ttsBegin;
while select forUpdate salesLine
where salesLine.SalesType == SalesType::Sales
&& salesLine.SalesStatus <= SalesStatus::Delivered
&& !salesLine.InventTransIdReturn //optimisation dkos 2013-09-25
&& (salesLine.ShippingDateRequested >= startDate || startDate == dateNull()) // 2013-09-25 #23667_DA0374 dkos: Update Sales Order Unit Price
{
salesLine.ManualEntryChangepolicy = 0; //optimisation dkos 2013-09-25
// 2013-02-18 #20169 csek: Job to update SOprice -->
salesLine.SystemEntryChangePolicy = 0; //optimisation dkos 2013-09-25
// 2013-02-18 #20169 csek: Job to update SOprice <-- font="">-->
checkPolicy = PriceDiscPolicyCheckPolicy::newFromParm(salesLine.PriceDiscResultFields::parmPriceDiscResultFields());
salesLine.salesPurchLine::resetPriceAgreement();
salesLine.setPriceAgreement(salesLine.inventDim(), null ,false,true);// 2013-02-07 #20169 csek: Job to update SOprice
salesLine.LineAmount = salesLine.calcLineAmountForced(salesLine.SalesQty, checkPolicy);
operationProgress.setText(strFmt("@DTD850",salesLine.SalesId));
salesLine.update();
salesLineFound = true;
}
ttsCommit;
}
if (salesLineFound)
{
info("@DTD1041"); // 2013-09-25 #23667_DA0374 dkos: Update Sales Order Unit Price
}
}
Good post, do you have any post about massive change of products retail price and agreements in AX 2012 CU3? I want to convert the commercial agreement from USD to MXN (Mexican Pesos) and apply to them a exchange rate of 16.50 with a VAT of 16%, I know how to do it in SQL but no idea in X++ :)
ReplyDeleteupdate MicrosoftDynamicsAX.dbo.PriceDiscTable set CURRENCY='MXN',AMOUNT=round(round(AMOUNT*16.50*1.16,0)/1.16,2)
where ITEMRELATION='063535' and DATAAREAID='CORP' and ACCOUNTRELATION='AIR';
update MicrosoftDynamicsAX.dbo.PRICEDISCADMTRANS set PRICEDISCADMTRANS.CURRENCY=x.CURRENCY,AMOUNT=x.AMOUNT
from (select * from MicrosoftDynamicsAX.dbo.PriceDiscTable where ITEMRELATION='063535' and DATAAREAID='CORP' and ACCOUNTRELATION='AIR') as x
where PRICEDISCADMTRANS.ITEMRELATION=x.ITEMRELATION and PRICEDISCADMTRANS.DATAAREAID=x.DATAAREAID
and PRICEDISCADMTRANS.ACCOUNTRELATION=x.ACCOUNTRELATION and PRICEDISCADMTRANS.PRICEDISCTABLEREF=x.RECID;
Can yo please tell me what is the use of these two fields?
ReplyDeletesalesLine.ManualEntryChangepolicy = 0;
salesLine.SystemEntryChangePolicy = 0;
I have to update Line Discounts in salesLine, how do I achieve this,because for a product I have discount in value and in
ReplyDeletepercentage.