Tuesday 9 June 2015

SALES QUOTE CREATION AX 2012 X++ CUSTOM WEB SERVICE

SALES QUOTE CREATION AX 2012 
X++ CUSTOM WEB SERVICE

[AifCollectionTypeAttribute('return', Types::String), SysEntryPointAttribute(true)]
public str CreateQuote(QuotationIdBase _quoteId,smmBusRelAccount _prospectId,CustAccount _customerId,LogisticsAddressing _billToAddress,LogisticsAddressing _shipToAddress,CustCurrencyCode _currency,
                        InventSiteName _site,InventLocationName _warehouse,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,k ;
    // changes
    compProductMasterDefault         prodMasterDefault;
    MarkupTable                             markTab;
    MarkupTrans                             trans;

    select * from prodMasterDefault;

   if(_orderCategory == 'Dealer-Customer')
            changeCompany(prodMasterDefault.DealerCompany)
    {  // Validating from masters
        select * from quotationIdchk where quotationIdchk.QuotationId == _quoteId;

     if(!quotationIdchk.RecId &&InventSite::exist(_site) && InventLocation::exist(_warehouse) && InventTable::exist(_item) && SalesTaxFormTypes_IN::exist(_saleTypeSalesTax)  &&  TaxGroupHeading::exist(_taxGroup))

        {

            ttsBegin;
            //creating header
            quotation.clear();
            quotation.initValue();
            quotation.CustAccount = _customerId;
            quotation.QuotationName = _customerId;
            quotation.InvoiceAccount = _customerId;
            quotation.initFromCustTable(true);
            quotation.QuotationId = _quoteId;
            quotation.BusRelAccount = _prospectId;
            quotation.QuotationStatus  = SalesQuotationStatus::Created;
            quotation.CurrencyCode = _currency;
            quotation.InventSiteId = _site;
            quotation.InventLocationId = _warehouse;
            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.insert();
            //creating line
            line.initValue();
            line.initFromSalesQuotationTable(quotation);
            line.initFromCustTable();
            inventTable = InventTable::find(_item);
            line.initFromInventTable(inventTable);
            line.ItemId = _item;
            //creating Inventory Dimensions
            dim.InventSiteId = _site;
            dim.InventLocationId  =_warehouse;
           // dim.configId = InventTable::find(line.ItemId).StandardConfigId;
            dim.configId = prodMasterDefault.DefaultConfig;
            dim = InventDim::findOrCreate(dim);
            dim.write();
            line.SalesQty = _qty;
            line.CurrencyCode = _currency;
            line.ShippingDateRequested = systemDateGet();
            line.InventDimId = dim.inventDimId;
            line.SalesTaxFormTypes_IN = SalesTaxFormTypes_IN::findbyFormType(_saleTypeSalesTax).RecId;
            line.initFromSalesQuotationLine_IN(line);
            comb = InventDimCombination::findByInventDim(line.ItemId,dim);
            line.RetailVariantId = comb.RetailVariantId  ;
            line.ExciseTariffCodes_IN = Inventtable::find(_item).ExciseTariffCodes_IN;
            line.createLine(true,true,false,false,false,false,'',false);


            markTab = MarkupTable::find((MarkupModuleType::Cust),'6');
            trans.clear();
            trans.initFromSalesQuotationLine(line);
            trans.initFromMarkupTable(marktab);
            trans.MarkupCategory = MarkupCategory::Pcs;
            trans.Value = _Freight;
            trans.LineNum = k;
            trans.insert();
            k++;

            //updating line Price
            select forUpdate line_2 where line_2.QuotationId == line.QuotationId
                        && line_2.ItemId == line.ItemId
                        && line_2.LineNum == line.LineNum;
            if(line_2.RecId)
            {
             line_2.SalesPrice = str2num(_price) - _freight;
             line_2.TaxGroup = _taxGroup;
            }
            line_2.modifiedField(fieldnum(SalesQuotationLine,SalesPrice));
            line_2.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,'|');
            //info(strFmt('%1',log));
         }
        else
        {
            //InventSite::exist(_site) && InventLocation::exist(_warehouse)
            if(!InventSite::exist(_site))
            {
               log_1 = strFmt('Site %1 is not valid for Sales Quote - %2 for company %3',_site,_quoteId,curext());
            }
            if(!InventLocation::exist(_warehouse))
            {
                log_2 = strFmt('Warehouse %1 is not valid for Sales Quote - %2',_warehouse,_quoteId);
            }
            if(!InventTable::exist(_item))
            {
                log_3 = strFmt('Item %1 is not valid for Sales Quote - %2',_item,_quoteId);
            }
            if(!SalesTaxFormTypes_IN::exist(_saleTypeSalesTax))
            {
                log_4 = strfmt('SalesTax FormType %1 is not valid for Sales Quote - %2',_saleTypeSalesTax,_quoteId);
            }
            if(!TaxGroupHeading::exist(_taxGroup))
            {
                log_5 = strFmt('Tax Group is not valid for Sales Quote - %2',_taxGroup,_quoteId);
            }
            if(quotationIdchk.RecId)
            {
                log_9 = strFmt('Sales Quote %1 already Exist',_quoteId);
            }
            log = strFmt("%1\n%2\n%3\n%4\n%5\n%6",log_1,log_2,log_3,log_4,log_5,log_9);
        }

      }
      else
      {
           changeCompany(prodMasterDefault.delCompany)
          {
          select * from quotationIdchk where quotationIdchk.QuotationId == _quoteId;

       // validating masters
     // if(site.RecId && ware.RecId && InventTable::exist(_item) && SalesTaxFormTypes_IN::exist(_saleTypeSalesTax))
     if(!quotationIdchk.RecId &&InventSite::exist(_site) && InventLocation::exist(_warehouse) && InventTable::exist(_item) && SalesTaxFormTypes_IN::exist(_saleTypeSalesTax)  &&  TaxGroupHeading::exist(_taxGroup))

        {
             ttsBegin;
            //creating header
            quotation.clear();
            quotation.initValue();
            quotation.CustAccount = _customerId;
            quotation.QuotationName = _customerId;
            quotation.InvoiceAccount = _customerId;
            quotation.initFromCustTable(true);
            quotation.QuotationId = _quoteId;
            quotation.BusRelAccount = _prospectId;
            quotation.QuotationStatus  = SalesQuotationStatus::Created;
            quotation.CurrencyCode = _currency;
            quotation.InventSiteId = _site;
            quotation.InventLocationId = _warehouse;
            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.insert();
            //creating lines
            line.initValue();
            line.initFromSalesQuotationTable(quotation);
            line.initFromCustTable();
            inventTable = InventTable::find(_item);
            line.initFromInventTable(inventTable);
            line.ItemId = _item;
            //creating inventory dimension
            dim.InventSiteId = _site;
            dim.InventLocationId  =_warehouse;
            //dim.configId = InventTable::find(line.ItemId).StandardConfigId;
            dim.configId = prodMasterDefault.DefaultConfigdel;
            dim = InventDim::findOrCreate(dim);
            dim.write();
            line.SalesQty = _qty;
            line.CurrencyCode = _currency;
            line.ShippingDateRequested = systemDateGet();
            line.InventDimId = dim.inventDimId;
            line.SalesTaxFormTypes_IN = SalesTaxFormTypes_IN::findbyFormType(_saleTypeSalesTax).RecId;
            line.initFromSalesQuotationLine_IN(line);
            comb = InventDimCombination::findByInventDim(line.ItemId,dim);
            line.RetailVariantId = comb.RetailVariantId  ;
            line.ExciseTariffCodes_IN = Inventtable::find(_item).ExciseTariffCodes_IN;
            line.createLine(true,true,false,false,false,false,'',false);


            markTab = MarkupTable::find((MarkupModuleType::Cust),'6');
            trans.clear();
            trans.initFromSalesQuotationLine(line);
            trans.initFromMarkupTable(marktab);
            trans.MarkupCategory = MarkupCategory::Pcs;
            trans.Value = _Freight;
            trans.LineNum = k;
            trans.insert();
            K++;
            //updating price
             select forUpdate line_2 where line_2.QuotationId == line.QuotationId
                        && line_2.ItemId == line.ItemId
                        && line_2.LineNum == line.LineNum;
            if(line_2.RecId)
            {
             line_2.SalesPrice = str2num(_price)- _freight;
             line_2.TaxGroup = _taxGroup;

            }
            line_2.modifiedField(fieldnum(SalesQuotationLine,SalesPrice));
            line_2.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);


            }
            log = con2StrUnlimited(con,'|');
            i =0 ;
            //log = con2Str(con,'');

         }
        else
        {
            if(!InventSite::exist(_site))
            {
               log_1 = strFmt('Site %1 is not valid for Sales Quote - %2 for company %3',_site,_quoteId,curext());
            }
            if(!InventLocation::exist(_warehouse))
            {
                log_2 = strFmt('Warehouse %1 is not valid for Sales Quote - %2',_warehouse,_quoteId);
            }
            if(!InventTable::exist(_item))
            {
                log_3 = strFmt('Item %1 is not valid for Sales Quote - %2',_item,_quoteId);
            }
            if(!SalesTaxFormTypes_IN::exist(_saleTypeSalesTax))
            {
                log_4 = strfmt('SalesTax FormType %1 is not valid for Sales Quote - %2',_saleTypeSalesTax,_quoteId);
            }
            if(!TaxGroupHeading::exist(_taxGroup))
            {
                log_5 = strFmt('Tax Group is not valid for Sales Quote - %2',_taxGroup,_quoteId);
            }
             if(quotationIdchk.RecId)
            {
                log_9 = strFmt('Sales Quote %1 already Exist',_quoteId);
            }
            log = strFmt("%1\n%2\n%3\n%4\n%5\n%6",log_1,log_2,log_3,log_4,log_5,log_9);

        }
          }
      }
   //  info(strFmt(" Sales Quote
     info(strFmt("Sales Quote for %1 is created - %2",_quoteId,log));
     comp_RetailExceptionActivityLog::logEvent('Sales Quote',infolog.export());
     return log ;
    }

No comments:

Post a Comment

AZURE INTERVIEW QUESTIONS AND ANSWERS

AZURE INTERVIEW QUESTIONS AND ANSWERES 2021 2. What is cloud computing? Explanation:  It is the use of servers on the internet to “store...