SALES QUOTE UPDATION AX 2012
X++ CUSTOM WEB SERVICE
Sales Quote update[AifCollectionTypeAttribute('return', Types::Container), SysEntryPointAttribute(true)]
public str updateQuote(QuotationIdBase _quoteId,CustCurrencyCode _currency, InventSiteName _site,ItemIdSmall _item,SalesQty _qty,comp_OrderType _orderType,comp_OrderCat _orderCategory,FormType_IN _saleTypeSalesTax,comp_SaleTypeExciseDuty _saleTypeExcise,
String50 _domestic,String50 _export,String50 _e1Sale,string50 _price,TaxGroup _taxGroup,MarkupValue _freight)
{
str log;
str log_1,log_2,log_3,log_4,log_5,log_6,log_7,log_8,log_9;
Inventsite site;
InventLocation ware;
SalesQuotationTable quotation,quotationIdchk;
SalesQuotationLine line,line_2;
InventDim dim;
InventItemOrderSetupType setupType = InventItemOrderSetupType::Invent;
InventTable inventTable;
CustTable cust;
InventDimCombination comb;
NoYes noyes;
TmpTaxWorkTrans tmpTax;
SalesQuotationTable salesQuotationTable;
SalesQuotationTotals_Sales salesQuotationTotals;
TaxTable taxtable;
str component;
container con;
int i ;
compProductMasterDefault prodMasterDef;
MarkupTable markTab;
MarkupTrans trans;
select * from prodMasterDef;
if(_orderCategory == 'Dealer-Customer')
changeCompany(prodMasterDef.DealerCompany)
{ // Validating from masters
select * from quotationIdchk where quotationIdchk.QuotationId == _quoteId;
if(quotationIdchk.RecId && InventSite::exist(_site) && InventTable::exist(_item) && SalesTaxFormTypes_IN::exist(_saleTypeSalesTax)&& TaxGroupHeading::exist(_taxGroup))
{
ttsBegin;
//updating header
quotation.clear();
select forupdate quotation where quotation.QuotationId == _quoteId;
if(quotation.RecId)
{
quotation.QuotationStatus = SalesQuotationStatus::Created;
quotation.CurrencyCode = _currency;
quotation.ShippingDateRequested = systemDateGet();
quotation.comp_OrderType = _orderType;
quotation.comp_OrderCat = _orderCategory;
quotation.comp_SaleTypeExciseDuty = _saleTypeExcise;
quotation.comp_E1Sale = str2enum(noyes,_e1Sale);
quotation.comp_Domestic = str2enum(NoYes,_domestic);
quotation.comp_Export = str2enum(NoYes,_export);
quotation.update();
}
//updating line
line.clear();
select forUpdate line where line.QuotationId == quotation.QuotationId;
// && line.ItemId == _item;
if(line.RecId)
{
//line.ItemId = _item;
line.initFromSalesQuotationLine(line);
line.SalesPrice = str2num(_price) - _freight;
line.TaxGroup = _taxGroup;
line.SalesQty = _qty;
line.CurrencyCode = _currency;
line.ShippingDateRequested = systemDateGet();
line.SalesTaxFormTypes_IN = SalesTaxFormTypes_IN::findbyFormType(_saleTypeSalesTax).RecId;
line.ExciseTariffCodes_IN = Inventtable::find(line.ItemId).ExciseTariffCodes_IN;
}
line.modifiedField(fieldnum(SalesQuotationLine,SalesPrice));
line.update();
markTab = MarkupTable::find((MarkupModuleType::Cust),'6');
select forupdate trans where Trans.TransTableId == line.TableId
&& Trans.TransRecId == line.RecId;
trans.ModuleType = MarkupModuleType::Cust;
trans.CurrencyCode = line.CurrencyCode;
trans.MarkupCode = markTab.MarkupCode;
trans.Txt = markTab.Txt;
trans.MarkupCategory = MarkupCategory::Pcs;
trans.Value = _Freight;
Trans.update();
ttsCommit;
salesQuotationTable = SalesQuotationTable::find(_quoteId);
salesQuotationTotals = SalesQuotationTotals_Sales::construct(salesQuotationTable);
// Calculate Tax
salesQuotationTotals.calc();
// Load tmpTaxWorkTrans
tmpTax.setTmpData(salesQuotationTotals.tax().tmpTaxWorkTrans());
// Showing taxes with tax value
while
select tmpTax
{
i++;
select taxtable where taxtable.taxcode == tmpTax.TaxCode;
component = TaxComponentTable_IN::find(taxtable.TaxComponentTable_IN).Name;
log_7 = component;
// log_8 = num2str(abs(tmpTax.TaxAmount),0,2,1,1);
log_8 = num2str(abs((tmpTax.TaxAmount)/_qty),0,2,0,0);
con = conins(Con,i,log_7+':'+log_8);
}
i =0 ;
log = con2StrUnlimited(con,'|');
}
else
{
//strFmt('Warehouse %1 is not valid for Sales Quote : %2',ware,_quoteId);
if(!InventTable::exist(_item))
{
log_3 = strFmt('Item %1 is not valid for %2 company %3',_item,_quoteId,curext());
}
if(!SalesTaxFormTypes_IN::exist(_saleTypeSalesTax))
{
log_4 = strFmt('SalesTax FormType %1 is not valid for %2',_saleTypeSalesTax,_quoteId);
}
if(!TaxGroupHeading::exist(_taxGroup))
{
log_5 = strFmt('Tax Group is %1 not valid for %2',_taxGroup,_quoteId);
}
if(!quotationIdchk.RecId )
{
log_9 = strFmt('Quote %1 does not exist',_quoteId);
}
log = strFmt("%1\n%2\n%3\n%4",log_3,log_4,log_5,log_9);
}
}
else
{
changeCompany(prodMasterDef.delCompany)
{
// validating masters
select * from quotationIdchk where quotationIdchk.QuotationId == _quoteId;
if( quotationIdchk.RecId && InventTable::exist(_item) && SalesTaxFormTypes_IN::exist(_saleTypeSalesTax)&& TaxGroupHeading::exist(_taxGroup))
{
ttsBegin;
//creating header
quotation.clear();
select forUpdate quotation where quotation.QuotationId == _quoteId;
if(quotation.RecId)
{
quotation.QuotationStatus = SalesQuotationStatus::Created;
quotation.CurrencyCode = _currency;
quotation.ShippingDateRequested = systemDateGet();
quotation.LanguageId = SystemParameters::getSystemLanguageId();
quotation.comp_OrderType = _orderType;
quotation.comp_OrderCat = _orderCategory;
quotation.comp_SaleTypeExciseDuty = _saleTypeExcise;
quotation.comp_E1Sale = str2enum(noyes,_e1Sale);
quotation.comp_Domestic = str2enum(NoYes,_domestic);
quotation.comp_Export = str2enum(NoYes,_export);
quotation.update();
}
//updating lines
line.clear();
select forUpdate line where line.QuotationId == quotation.QuotationId;
// && line.ItemId == _item;
if(line.RecId)
{
//line.ItemId = _item;
line.initFromSalesQuotationLine(line);
line.SalesPrice = str2num(_price) - _freight;
line.TaxGroup = _taxGroup;
line.SalesQty = _qty;
line.CurrencyCode = _currency;
line.ShippingDateRequested = systemDateGet();
line.SalesTaxFormTypes_IN = SalesTaxFormTypes_IN::findbyFormType(_saleTypeSalesTax).RecId;
line.ExciseTariffCodes_IN = Inventtable::find(line.ItemId).ExciseTariffCodes_IN;
}
line.modifiedField(fieldnum(SalesQuotationLine,SalesPrice));
line.update();
markTab = MarkupTable::find((MarkupModuleType::Cust),'6');
select forupdate trans where Trans.TransTableId == line.TableId
&& Trans.TransRecId == line.RecId;
trans.ModuleType = MarkupModuleType::Cust;
trans.CurrencyCode = line.CurrencyCode;
trans.MarkupCode = markTab.MarkupCode;
trans.Txt = markTab.Txt;
trans.MarkupCategory = MarkupCategory::Pcs;
trans.Value = _Freight;
Trans.update();
ttsCommit;
salesQuotationTable = SalesQuotationTable::find(_quoteId);
salesQuotationTotals = SalesQuotationTotals_Sales::construct(salesQuotationTable);
// Calculate Tax
salesQuotationTotals.calc();
// Load tmpTaxWorkTrans
tmpTax.setTmpData(salesQuotationTotals.tax().tmpTaxWorkTrans());
// Showing taxes with tax value
while
select tmpTax
{
i++;
select taxtable where taxtable.taxcode == tmpTax.TaxCode;
component = TaxComponentTable_IN::find(taxtable.TaxComponentTable_IN).Name;
log_7 = component;
log_8 = num2str(abs((tmpTax.TaxAmount)/_qty),0,2,0,0);
con = conins(Con,i,log_7+':'+log_8);
}
i =0 ;
log = con2StrUnlimited(con,'|');
}
else
{
if(!InventTable::exist(_item))
{
log_3 = strFmt('Item %1 is not valid for %2 for company %3',_item,_quoteId,curext());
}
if(!SalesTaxFormTypes_IN::exist(_saleTypeSalesTax))
{
log_4 = strFmt('SalesTax FormType %1 is not valid for %2',_saleTypeSalesTax,_quoteId);
}
if(!TaxGroupHeading::exist(_taxGroup))
{
log_5 = strFmt('Tax Group is %1 not valid for %2',_taxGroup,_quoteId);
}
if(!quotationIdchk.RecId )
{
log_9 = strFmt('Quote %1 does not exist for company %2',_quoteId,curext());
}
log = strFmt("%1\n%2\n%3\n%4",log_3,log_4,log_5,log_9);
}
}
}
info(strFmt("Sales Quote Update: %1 - %2 ",_quoteId,log));
comp_RetailExceptionActivityLog::logEvent('Sales Quote Update',infolog.export());
return log ;
}
No comments:
Post a Comment