Thursday, 27 July 2017

Total in ax 2012 ssrsr report

/// <summary>
///  This method inserts data into the temporary table.
/// </summary>
/// <param name="_vendPurchOrderJour">
///  Vendor Purchase Order Confirmation journal record.
/// </param>
/// <remarks>
///  Inserts data into the temporary table.
/// </remarks>

private void insertIntoTempTable(VendPurchOrderJour _vendPurchOrderJour)
{
    PurchTable              purchTable;
    PurchLine               _PurchLine;
    PurchLineAllVersions    purchLineAllVersions;
    PurchTableAllVersions   purchTableAllVersions;
    VendTable               vendTable;
    VendParameters          vendParameters;
    str                     coutryname;
    DirPartyLocation           dirPartyLocation;
    LogisticsElectronicAddress logisticsElectronicAddress;
    DataArea                   dataArea;
    PurchtotalsForm         totalsForm;
    DirPartyPostalAddressView           _DirPartyPostalAddressView;
    ;

    purchTable                                  = PurchTable::find(_vendPurchOrderJour.PurchId);
    vendTable                                   = VendTable::find(purchTable.OrderAccount);
    select purchTableAllVersions where purchTableAllVersions.PurchTableVersionRecId == _vendPurchOrderJour.PurchTableVersion;

    purchaseOrderHeaderTmp.OrderNo              = purchTable.PurchId;
    purchaseOrderHeaderTmp.vendName             = purchTable.vendorName();
    purchaseOrderHeaderTmp.VendorAddress        = purchTable.vendorAddress();
    purchaseOrderHeaderTmp.VendorRef            = purchTableAllVersions.VendorRef;
    purchaseOrderHeaderTmp.Attention            = purchTableAllVersions.contactPersonName();
    purchaseOrderHeaderTmp.Date                 = DateTimeUtil::date(purchTable.createdDateTime);//_vendPurchOrderJour.PurchOrderDate;  //by 29224

    purchaseOrderHeaderTmp.Orderer              = HcmWorker::find(purchTable.WorkerPurchPlacer).name();
    purchaseOrderHeaderTmp.DlvTerm              = DlvTerm::find(purchTable.DlvTerm).Txt;//DlvMode::find(purchTableAllVersions.DlvMode).Txt;//DlvTerm::find(purchTableAllVersions.DlvTerm).Txt;
    purchaseOrderHeaderTmp.DlvMode              = DlvMode::find(purchTable.DlvMode).Txt;
    purchaseOrderHeaderTmp.PaymTermId           = PaymTerm::find(purchTable.Payment).Description;
    purchaseOrderHeaderTmp.DeliveryName         = purchTableAllVersions.DeliveryName;
    purchaseOrderHeaderTmp.DeliveryDate         = purchTable.DeliveryDate;
    purchaseOrderHeaderTmp.DeliveryAddress      = LogisticsPostalAddress::addressFromRecId(purchTableAllVersions.DeliveryPostalAddress);
    purchaseOrderHeaderTmp.Currency             = purchTableAllVersions.CurrencyCode;
    purchaseOrderHeaderTmp.Warehouse            = purchTableAllVersions.InventLocationId;
    purchaseOrderHeaderTmp.Remark               = purchTableAllVersions.ReqAttention;
    purchaseOrderHeaderTmp.Notes                = FormLetterRemarks::find(CompanyInfo::find().LanguageId,FormTextType::PurchPurchaseOrder).Txt;

    // AT Add this code
    Select FirstOnly * from _PurchLine where _PurchLine.PurchId == PurchTable.PurchId;
    purchaseOrderHeaderTmp.God_Customer = CustTable::find(SalesTable::find(_PurchLine.GITL_SalesId).CustAccount).name();
    purchaseOrderHeaderTmp.ReasonComment = ReasonTableRef::find(purchTable.ReasonTableRef).ReasonComment;
   // End




    //
    coutryname                                  = logisticspostaladdress::findbylocation(companyinfo::find().postaladdress().location).CountryRegionId;
    purchaseOrderHeaderTmp.God_invoiceAddressto = logisticspostaladdress::findbylocation(companyinfo::find().postaladdress().location).City +' , '+coutryname;
    purchaseOrderHeaderTmp.God_issuefrom        = logisticspostaladdress::findbylocation(companyinfo::find().postaladdress().location).City +' , '+coutryname;
    purchaseOrderHeaderTmp.God_Shippingmark     = purchTable.GITL_ShippingMark;
    purchaseOrderHeaderTmp.God_Port             = purchTable.Port;
    purchaseOrderHeaderTmp.God_site             = InventSite::find(purchTable.InventSiteId).Name;

    // For Vendor Fax only
    select firstOnly dirPartyLocation
     order by dirPartyLocation.RecId desc
    where
    dirPartyLocation.Party == vendTable.Party
    join logisticsElectronicAddress
    where
    logisticsElectronicAddress.Location == dirPartyLocation.Location
    && logisticsElectronicAddress.Type ==  LogisticsElectronicAddressMethodType::Fax;
    purchaseOrderHeaderTmp.God_VendorFax = logisticsElectronicAddress.GITL_CountryCodeForPhoneNumber + "-" +  logisticsElectronicAddress.Locator;

     select firstOnly dirPartyLocation
     order by dirPartyLocation.RecId desc
    where
    dirPartyLocation.Party == vendTable.Party
    join logisticsElectronicAddress
    where
    logisticsElectronicAddress.Location == dirPartyLocation.Location
    && logisticsElectronicAddress.Type ==  LogisticsElectronicAddressMethodType::Phone;
    purchaseOrderHeaderTmp.God_VendorPhone = logisticsElectronicAddress.GITL_CountryCodeForPhoneNumber + logisticsElectronicAddress.Locator;

      select firstOnly dirPartyLocation
     order by dirPartyLocation.RecId desc
    where
    dirPartyLocation.Party == vendTable.Party
    join logisticsElectronicAddress
    where
    logisticsElectronicAddress.Location == dirPartyLocation.Location
    && logisticsElectronicAddress.Type ==  LogisticsElectronicAddressMethodType::Email;
    purchaseOrderHeaderTmp.God_VendorEmail = logisticsElectronicAddress.GITL_CountryCodeForPhoneNumber + logisticsElectronicAddress.Locator;



    select * from _DirPartyPostalAddressView Where
                                _DirPartyPostalAddressView.Party == vendTable::find(purchTable.OrderAccount).Party;

    purchaseOrderHeaderTmp.Street = _DirPartyPostalAddressView.Street;
    purchaseOrderHeaderTmp.City = _DirPartyPostalAddressView.City;
    purchaseOrderHeaderTmp.County = _DirPartyPostalAddressView.County;
    purchaseOrderHeaderTmp.State = _DirPartyPostalAddressView.State;
    purchaseOrderHeaderTmp.CountryRegionId = _DirPartyPostalAddressView.CountryRegionId;
    purchaseOrderHeaderTmp.ZipCode = _DirPartyPostalAddressView.ZipCode;


    //For Subtotal part only//







     select sum(PurchQty) from purchLineAllVersions order by purchLineAllVersions.LineNumber
        where purchLineAllVersions.PurchTableVersionRecId == _vendPurchOrderJour.PurchTableVersion
            && purchLineAllVersions.PurchId == _vendPurchOrderJour.PurchId;

    totalsForm   = PurchtotalsForm::newPurchTotalsForm(PurchTable::find(purchTable.PurchId),1);//PurchTable::find(purchTable.PurchId),2);//purchLineAllVersions.PurchQty);
    totalsForm.calctotals();
    purchaseOrderHeaderTmp.God_Subtotal =  totalsForm.sumLinesValue();

    totalsForm   = PurchtotalsForm::newPurchTotalsForm(PurchTable::find(purchTable.PurchId),1);//PurchTable::find(purchTable.PurchId),2);//purchLineAllVersions.PurchQty);
    totalsForm.calctotals();
    purchaseOrderHeaderTmp.God_Totalvalue = totalsForm.invoiceAmountValue();
    totalsForm   = PurchtotalsForm::newPurchTotalsForm(PurchTable::find(purchTable.PurchId),1);
    totalsForm.calctotals();
    purchaseOrderHeaderTmp.God_Discount  = totalsForm.endDiscValue();

    purchaseOrderHeaderTmp.God_StrAmount = Global::numeralsToTxt_Number(purchaseOrderHeaderTmp.God_Totalvalue);


    //
    this.insertCompanyDetails();


    purchaseOrderHeaderTmp.insert();


    while select purchLineAllVersions order by purchLineAllVersions.LineNumber
        where purchLineAllVersions.PurchTableVersionRecId == _vendPurchOrderJour.PurchTableVersion
            && purchLineAllVersions.PurchId == _vendPurchOrderJour.purchid

    {
        purchaseOrderTmp.clear();
        purchaseOrderTmp.UOM            = purchLineAllVersions.PurchUnit;
        //purchaseOrderTmp.PartCode       = purchLineAllVersions.GOD_partCode();
        purchaseOrderTmp.ItemId         = purchLineAllVersions.ItemId;
        if(purchLineAllVersions.ItemId)
        purchaseOrderTmp.Description    = purchLineAllVersions.itemName();
        else
        purchaseOrderTmp.Description    = purchLineAllVersions.Name;

        //purchaseOrderTmp.NameTxt        = purchLineAllVersions.GOD_dispItemText();
        purchaseOrderTmp.Qty            = purchLineAllVersions.PurchQty;
        purchaseOrderTmp.PurchPrice     = purchLineAllVersions.PurchPrice;
        purchaseOrderTmp.DiscPercent    = purchLineAllVersions.DiscPercent;
        purchaseOrderTmp.netPrice       = purchLineAllVersions.PurchPrice - ((purchLineAllVersions.PurchPrice*purchLineAllVersions.LinePercent)/100);//purchLineAllVersions.PurchPrice * ((100 - purchLineAllVersions.DiscPercent)/100);
        purchaseOrderTmp.TotalPrice     = purchLineAllVersions.LineAmount;//purchaseOrderTmp.netPrice * purchaseOrderTmp.Qty;
        purchaseOrderTmp.insert();
    }
}




private void insertCompanyDetails()
{
    CompanyInfo                 companyInfo;
    RecId                       company;
    Common                      record;
    CompanyImage                companyImage;
    LogisticsElectronicAddress logisticsElectronicAddress;
    DirPartyLocation           dirPartyLocation;
    DataArea                   dataArea;
    ;

    company                         =   CompanyInfo::current();
    companyInfo                     =   CompanyInfo::find();
    record                          =   CompanyInfo::findRecId(company);
    companyImage                    =   CompanyImage::findByRecord(record);

    select firstOnly dataArea
    where  dataArea.id == curext();


   // PurchaseOrderHeaderTmp.CompanyBackImage     = GOD_CompanyBackgroundImage::findByRecord(record).Image;
    //PurchaseOrderHeaderTmp.FooterImage          = GOD_CompanyFooterImage::findByRecord(record).Image;
    PurchaseOrderHeaderTmp.Logo                 = companyImage.Image;
    PurchaseOrderHeaderTmp.CompanyName          = companyInfo.Name;
    purchaseOrderHeaderTmp.CompanyAddess        = companyInfo.postalAddress().Address;

    select firstOnly dirPartyLocation
     order by dirPartyLocation.RecId desc
    where
    dirPartyLocation.Party == companyInfo.RecId

    join logisticsElectronicAddress
    where
    logisticsElectronicAddress.Location == dirPartyLocation.Location
    && logisticsElectronicAddress.Type ==  LogisticsElectronicAddressMethodType::Phone;

    purchaseOrderHeaderTmp.CompanyTel           =logisticsElectronicAddress.Locator; //companyInfo.telex();

    select firstOnly dirPartyLocation
     order by dirPartyLocation.RecId desc
    where
    dirPartyLocation.Party == companyInfo.RecId
    join logisticsElectronicAddress
    where
    logisticsElectronicAddress.Location == dirPartyLocation.Location
    && logisticsElectronicAddress.Type ==  LogisticsElectronicAddressMethodType::Fax;
    purchaseOrderHeaderTmp.companyFax           = logisticsElectronicAddress.Locator;//companyInfo.teleFax();

    select firstOnly dirPartyLocation
     order by dirPartyLocation.RecId desc
    where
    dirPartyLocation.Party == companyInfo.RecId
    join logisticsElectronicAddress
    where
    logisticsElectronicAddress.Location == dirPartyLocation.Location
    && logisticsElectronicAddress.Type ==  LogisticsElectronicAddressMethodType::Email;
   purchaseOrderHeaderTmp.Companyemail       = logisticsElectronicAddress.Locator;
    //any2str(DirPartyTable::find(companyInfo.PartyNumber).PrimaryContactEmail);//LogisticsElectronicAddress::findElectronicAddress().;//companyInfo.email();

    //logisticspostaladdress::findbylocation(companyinfo::find().postaladdress().location).CountryRegionId;



}

No comments:

Post a Comment

Labels

#veryusefulcode (1) AIF (8) AOT Maps (1) Args (1) Ax 2009 Reports (2) AX 2012 navigation (1) Ax 2012 Interview Questions (1) AX 7 (2) AX Architecture (1) Ax Backup (1) AX Workflow (2) AX2012 (1) AX2012 R2 (1) Ax2012R3 (1) AX2012R3 Dynamics Connector Step by Step Installation and Configuration (1) AX2012R3 EP Step by Step Installation and Configuration EP R3 (1) AX2012R3 HelpServer Step by Step Installation and Configuration (1) AX2012R3 Rapid Start Connector Step by Step Installation and Configuration (1) AX2012R3 Report Server and Analysis Server Step by Step Installation and Configuration (1) AX7 (1) Best practices (1) Blocking user to enter (1) Collection Classes (1) Container (1) D365FO (3) Data Migration Frame Work ax 2012R3 (1) Deleting duplicate Record from Table – Ax2012 (1) Delivery due date notification workflow in Ax 2012 (1) Development Steps EP (1) Dimensions (1) DIXF (1) DMF in Ax 2012 R3 (1) Dynamics Ax 2012 Interview Questions (1) DYNAMICS AX 2012 INTERVIEW QUESTIONS PART 2 (1) DYNAMICS AX 7 (1) EDT relation Migration Tool (1) EP AX 2012 (1) Ep Lookup (1) Error (1) Event Handler (1) F5 (1) File Handling (4) Filter on AX2012 Listpage (1) filtering (2) financial dimensions in AX 2012 (3) form (1) images (1) Installation and Configration (4) Installation and Configuration (11) Installation of Management Reporter 2012 for AX 2012 (1) Interaction class in ax 2012 (1) Interview Question (1) Interview Questions For Ax 2012 (1) Invent DIm (1) Jobs (2) license (1) List page and form menuitem enable code (1) Methods (1) microsoft Dynamics AX 365FO (1) Number Sequence Generation – AX 2012 (5) Number Sequence2012 (1) OLTP-OLAP (1) Passing Args (1) Passing form caller and menu item caller in ax 2012 (1) Passing Multiple Records Args (1) Posting in Ax 2012 (1) POSTING PURCHASE ORDER (1) Query (1) Query Filter Form (2) Query Ranges in X++ (1) Question and Answer (1) Report (1) Reports Controller class (1) RLS in ax 2009 (1) SALES ORDER IMPORT/EXPORT FRAMEWORK BY DMF (1) Security (1) security roles (1) Security Sysqueryrangeutil (1) Sharepoint 2016 (1) SQL SERVER (1) SSRS (2) SSRS Reports Controller class (2) Table collections & Virtual company (1) Time (1) TIPS AND TRICKS (1) Web service AIF (3) Web Services on IIS (AIF) Step by Step Installation and Configuration (1) workflow ax2012 (1) Workflow installation (1) Workflow Method (3) X++ (1)