Tuesday 5 November 2019

Generate list of customer addresses with purposes

Recently I was asked by one of the customers to generate the list of all customer addresses with their purpose. The job below retrieves the information with ease.

static void GetCustomerExtract(Args _args)
{
    CustTable custTable;
    DirPartyTable dirPartyTable;
    LogisticsPostalAddressView postAddress;
    LogisticsLocationRole logisticsLocationRole;
    LogisticsLocationParty logisticsLocationparty;
    int iCount = 0;
    CommaIo file;
    ;
    file = new CommaIo(@"FILEPATH","W");
    file.write("dirPartyTable.Name","dirPartyTable.RecId","custTable.AccountNum","custTable.InvoiceAccount","custTable.TaxGroup","custTable.SalesGroup","custTable.DataAreaId","logisticsLocationRole.Name","postAddress.LocationName","postAddress.County","postAddress.District","postAddress.PostBox","postAddress.Address","postAddress.BuildingCompliment","postAddress.City","postAddress.CountryRegionId","postAddress.Latitude","postAddress.Longitude","postAddress.State","postAddress.Street","postAddress.StreetNumber","postAddress.TimeZone","postAddress.ZipCode","postAddress.PostalAddressRecId","postAddress.PostalAddress","postAddress.DistrictName","postAddress.ISOCode);
   
         
        while select custTable
        join dirPartyTable where (custTable.Party == dirPartyTable.RecId)
        join logisticsLocationparty where (custTable.party == logisticsLocationparty.Party)
        join postAddress where (logisticsLocationparty.location == postAddress.Location)
        join logisticsLocationRole where (logisticsLocationparty.LocationRole == logisticsLocationRole.RecId)
       
    {
        file.write(dirPartyTable.Name,dirPartyTable.RecId,custTable.AccountNum,custTable.InvoiceAccount,custTable.TaxGroup,custTable.SalesGroup,custTable.DataAreaId,logisticsLocationRole.Name,postAddress.LocationName,postAddress.County,postAddress.District,postAddress.PostBox,postAddress.Address,postAddress.BuildingCompliment,postAddress.City,postAddress.CountryRegionId,postAddress.Latitude,postAddress.Longitude,postAddress.State,postAddress.Street,postAddress.StreetNumber,postAddress.TimeZone,postAddress.ZipCode,postAddress.PostalAddressRecId,postAddress.PostalAddress,postAddress.DistrictName,postAddress.ISOCode);
        iCount++;
    }
    info(int2str(iCount)+" Records exctracted");

}


Sunday 13 January 2019

Division by zero error Sales Order Invoice Postings

Recently, came across an issue with the customer where they were getting an error as below everytime generating an invoice for the sales orders. { Division by zero. - (S)\Classes\SalesInvoiceDP\insertIntoSalesInvoiceTmp - line 123 }



I discovered there was an unhandled exception in the line of code for \classes\SalesInvoiceDP\insertIntoSalesInvoiceTmp method on a certain line of code as below

Line 122 of the method states

salesInvoiceTmp.SalesPrice =   _custInvoiceTrans.SalesPrice / (_custInvoiceTrans.LineAmount +_custInvoiceTrans.LineAmountTax) * _custInvoiceTrans.LineAmount;

Changing that line of code to below resolves the issue

// changes made to avoid division by zero error.
if((_custInvoiceTrans.LineAmount +_custInvoiceTrans.LineAmountTax) * _custInvoiceTrans.LineAmount == 0)
     salesInvoiceTmp.SalesPrice = 0 ;
else
     salesInvoiceTmp.SalesPrice =   _custInvoiceTrans.SalesPrice / (_custInvoiceTrans.LineAmount +_custInvoiceTrans.LineAmountTax) * _custInvoiceTrans.LineAmount;