Tuesday, June 17, 2008

Dynamics AX

static void Job171(Args _args)
{
    InventTable inventTable = InventTable::find("Vouch312");
    InventTable InventTableTemplate = InventTable::find("Vouch310");
 
 
 
    inventItemPurchSetup inventItemPurchSetup , newinventItemPurchSetup;
    newinventItemPurchSetup = InventTable.inventItemPurchSetup();
    inventItemPurchSetup = InventTableTemplate.inventItemPurchSetup();
 
    newinventItemPurchSetup.selectForUpdate(true);
    newinventItemPurchSetup.InventDimId =  inventItemPurchSetup.InventDimId;
    newinventItemPurchSetup.InventDimIdDefault = inventItemPurchSetup.InventDimIdDefault;
    newinventItemPurchSetup.HighestQty =   inventItemPurchSetup.HighestQty;
    newinventItemPurchSetup.MultipleQty =  inventItemPurchSetup.MultipleQty ;
    newinventItemPurchSetup.LowestQty =  inventItemPurchSetup.LowestQty ;
    newinventItemPurchSetup.LeadTime =  inventItemPurchSetup.LeadTime ;
    newinventItemPurchSetup.write();

   ***Element: CLS

; Microsoft Dynamics AX Class: dbsLib unloaded
; --------------------------------------------------------------------------------
  CLSVERSION 1
 
  CLASS #dbsLib
    Id 50205
    PROPERTIES
      Name                #dbsLib
      Extends             #
      RunOn               #Called from
    ENDPROPERTIES
   
    METHODS
      Version: 3
      SOURCE #classDeclaration
        #// M.Kubiena    16/06/09    Created class
        #class dbsLib
        #{
        #}
      ENDSOURCE
      SOURCE #convertedMemoField
        #// M.Kubiena    16/06/09    takes an input string and line size and returns a memo field with cr/lf after each line.
        #static smmBusRelMemo convertedMemoField(smmBusRelMemo _inputString, int _lineSize)
        #{
        #    smmBusRelMemo       newField = '';
        #    int                 maxLine,lineCount;
        #
        #    #define.dbsLF(10)
        #    #define.dbsCR(13)
        #    ;
        #
        #    if (strlen(_inputString))
        #    {
        #        maxLine = ((strlen(_inputString) - 1) / _lineSize) + 1;
        #
        #        for (lineCount=1; lineCount<=maxLine; lineCount++)
        #        {
        #            if (lineCount == 1)
        #            {
        #                newField = strrtrim(subStr(_inputString,((lineCount-1)*_lineSize)+1,_lineSize));
        #            }
        #            else
        #            {
        #                newField = strrtrim(newField) +
        #                            num2char(#dbsCR) + num2char(#dbsLF) +
        #                            strrtrim(subStr(_inputString,((lineCount-1)*_lineSize)+1,_lineSize));
        #            }
        #        }
        #    }
        #
        #    return newField;
        #}
      ENDSOURCE
      SOURCE #dbsAddCRLF
        #// Phil ONeill  13/10/2009   Add CRLF at the end of a string
        #//                           Options : 1 = Add STX at the beginning
        #//                                     2 = Add ETX at the end
        #static str dbsAddCRLF(str _inStr, int _escOpt = 0)
        #{
        #    #define.dbsCR(13)                       // [ESC] CR
        #    #define.dbsLF(10)                       // [ESC] LF
        #    #define.dbsSTX(2)                       // [ESC] Start Transmission
        #    #define.dbsETX(3)                       // [ESC] End Transmission
        #    ;
        #    _instr = strRtrim(_instr);
        #    switch (_escOpt)
        #    {
        #        case 0 :
        #            return _instr + num2char(13) + num2char(10);
        #        case 1 :
        #            return num2char(#dbsSTX) + _instr + num2char(13) + num2char(10);
        #        case 2 :
        #            return _instr + num2char(#dbsETX);
        #        default:
        #            return _instr + num2char(13) + num2char(10);
        #    }
        #}
      ENDSOURCE
      SOURCE #dbsGetJulianDate
        #// Phil ONeill  12/08/2009   Accepts a date and returns the Julian Date
        #static int64 dbsGetJulianDate(Date _date)
        #{
        #    System.DateTime     passedDate;
        #    int64               julianDays;
        #    ;
        #    passedDate  = new System.DateTime(Year(_date), mthofyr(_date), dayofmth(_date));
        #    return passedDate.ToOADate();
        #}
      ENDSOURCE
      SOURCE #dbsGetNextDay
        #// Phill ONeill  22/02/2010   Find the date of the next/ last weekday passed in
        #// eg dbsGetNextDay(22/02/2010, saturday) = 27/02/2010
        #static transDate dbsGetNextDay(transDate _date, str _day, str _nextLast = 'Next')
        #{
        #    int     dayLoop;
        #    boolean validDay = False;
        #    ;
        #    for (dayLoop = 1; dayLoop <= 7; dayLoop++)                  //Check a valid day has been passed in
        #        if (dayName(dayloop) == _day)
        #            validDay  = True;
        #
        #    if (!validDay)
        #        return _date;
        #
        #    if (dayName(dayOfWk(_date)) == _day)
        #        return _date;
        #
        #    if (_nextLast == 'Next')
        #        return dbsLib::dbsGetNextDay(_date + 1, _day, _nextLast);   //Next day
        #    else
        #        return dbsLib::dbsGetNextDay(_date - 1, _day, _nextLast);   //Previous day
        #}
      ENDSOURCE
      SOURCE #dbsGetRegionId
        #static dbsRegionId dbsGetRegionId(dbsPostRegion _postRegion)
        #{
        #    str         stringBit;
        #    int         intBit;
        #    container   regionCont;
        #    ;
        #    regionCont = dbsLib::dbsSplitString(_postRegion);
        #
        #    stringBit = conpeek(regionCont, 1);
        #    intBit    = conpeek(regionCont, 2);
        #
        #    switch (stringBit)
        #    {
        #        case 'BT' :
        #            return 'NI';
        #
        #        case 'JE','GY' :
        #            return 'CI';
        #
        #        case 'IV', 'ZE', 'KW', 'HS', 'IM' :
        #            return 'H&I' ;
        #
        #        case 'KA' :
        #            if (intBit == 27 || intBit == 28)
        #                return 'H&I';
        #
        #        case 'PH' :
        #            if (intBit >= 17 && intBit <= 26)
        #                return 'H&I';
        #            if (intBit >= 30 && intBit <= 44)
        #                return 'H&I';
        #            if (intBit == 49 || intBit == 50)
        #                return 'H&I';
        #
        #        case 'PA' :
        #            if (intBit >= 20 && intBit <= 49)
        #                return 'H&I';
        #            if (intBit >= 60 && intBit <= 78)
        #                return 'H&I';
        #
        #        case 'TR' :
        #            if (intBit >= 21 && intBit <= 25)
        #                return 'H&I';
        #    }
        #    return 'UKMain';
        #
        #
        #}
      ENDSOURCE
      SOURCE #dbsNextWorkingDate
        #// Changed on 25 Feb 2010 at 11:45:24 by ponei
        #// Returns the next/ previous working date from that passed in
        #static transDate dbsNextWorkingDate(transDate _date, DlvModeId _dlvMode, InventLocationId _location,
        #                                    boolean _inclusive = True, boolean _previousDay = False)
        #{
        #    transDate           workingDate;
        #    workCalendarSched   workCalendarSched = new workCalendarSched();
        #    ;
        #    workingDate = _date;
        #
        #    if (!_inclusive)
        #        if (_previousDay)
        #            workingDate--;
        #        else
        #            workingDate++;
        #
        #    while (!workCalendarSched.isPickupDate(custVendTransportCalendarSetup::find(_dlvMode, _location).Calendar, workingDate))
        #    {
        #        if (_previousDay)
        #            workingDate--;
        #        else
        #            workingDate++;
        #
        #        if (year(workingDate) > 3000)
        #            throw error("@DBS2066" + custVendTransportCalendarSetup::find(_dlvMode, _location).Calendar);
        #    }
        #
        #    return workingDate;
        #}
      ENDSOURCE
      SOURCE #dbsReplaceString
        #// Phill ONeill  27/01/2010   Search and Replace string
        #static str dbsReplaceString(str _inString, str _search, str _replace, int _startPos = 1)
        #{
        #    int     pos = strScan(_inString, _search, _startPos, strLen(_inString))
        #    ;
        #    if (_search == _replace)
        #        return _instring;
        #
        #    if (!pos)
        #        return _inString;
        #    else
        #        return dbsLib::dbsReplaceString(subStr(_inString, 1, pos - 1) + _replace + substr(_inString, pos + strLen(_search), strLen(_inString)), _search, _replace, pos);
        #}
      ENDSOURCE
      SOURCE #dbsSetCase
        #// Phil ONeill  12/10/2009   Set the Case of a string
        #//  1   =   Case each word
        #//  2   =   All Uppper Case
        #//  3   =   All Lower Case
        #static str dbsSetCase(str _inStr, int _option = 1)
        #{
        #    str     outStr, type, newChar;
        #    int     loop, ascVal;
        #    boolean newWord = True;
        #    int     offset;
        #    ;
        #    offset = char2num('a', 1) - char2num('A', 1);
        #
        #    for (loop = 1; loop <= strLen(_inStr); loop++)
        #    {
        #        newChar = substr(_inStr, loop, 1);
        #        ascVal = char2num(newChar, 1);
        #
        #        type = 'N';
        #        if (ascVal >= char2num('A', 1) && ascVal <= char2num('Z', 1))          //Upper case A-Z
        #            type = 'U';
        #
        #        if (ascVal >= char2num('a', 1) && ascVal <= char2num('z', 1))          //Lower Case a-z
        #            type = 'L';
        #
        #        switch (_option)
        #        {
        #            case 1 :
        #            {
        #                if (newWord)
        #                {
        #                    if (type == 'L')
        #                        newChar = num2char(ascVal - offset);
        #                    newWord = False;
        #                }
        #                else
        #                    if (type == 'U')
        #                        newChar = num2char(ascVal + offset);
        #                break;
        #            }
        #
        #            case 2 :
        #            {
        #                if (type == 'L')
        #                    newChar = num2char(ascVal - offset);
        #                break;
        #            }
        #
        #            case 3 :
        #            {
        #                if (type == 'U')
        #                    newChar = num2char(ascVal + offset);
        #                break;
        #            }
        #        }
        #
        #        if (ascVal == char2num(' ', 1))                                        //Space
        #            newWord = True;
        #
        #        outStr += newChar;
        #    }
        #    return outStr;
        #}
      ENDSOURCE
      SOURCE #dbsSortContainer
        #// Phil ONeill  10/08/2009   Sort Container
        #// Sorts a container of ints. Sort direction as parameter2 (ascending/ descending)
        #static Container dbsSortContainer(container _dimensions, str _direction = 'D')
        #{
        #    container   sorted, returned;
        #    int         highest, highestPos, loop, loop2;
        #    NoYes       compare;
        #    ;
        #    while (conlen(sorted) < conlen(_dimensions))
        #    {
        #        if (highestPos)
        #            sorted += highestPos;                                               //Add to container
        #
        #        highest = 0;
        #        for (loop = 1; loop <= conlen(_dimensions); loop++)                     //Loop through container, ignoring ints that have been previoulsy highest
        #        {
        #            compare = NoYes::Yes;
        #            for (loop2 = 1; loop2 <= conlen(sorted); loop2++)
        #                if (loop == conpeek(sorted, loop2))
        #                    compare = Noyes::No;
        #
        #            if (compare == NoYes::No)
        #                continue;
        #
        #            if (conpeek(_dimensions, loop) >= highest)
        #            {
        #                highest    = conpeek(_dimensions, loop);
        #                highestPos = loop;
        #            }
        #        }
        #    }
        #
        #    if (_direction == 'D')
        #        for (loop = 1; loop <= conlen(_dimensions); loop++)                         //Compile sorted container descending
        #            returned += conpeek(_dimensions, conpeek(sorted, loop));
        #    else
        #        for (loop = conlen(_dimensions); loop >= 1; loop--)                         //Compile sorted container ascending
        #            returned += conpeek(_dimensions, conpeek(sorted, loop));
        #
        #    return returned;
        #}
      ENDSOURCE
      SOURCE #dbsSplitString
        #// Changed on 25 Feb 2010 at 11:53:22 by ponei
        #// Returns a container. The first element is the alpha part of the string,
        #// the second is the non-alpha part
        #static container dbsSplitString(str _string)
        #{
        #    int     loop;
        #    ;
        #    loop = 1;
        #    while (!dbsLib::trueNumeric(substr(_string, loop, 1)))
        #        loop++;
        #
        #    return [substr(_string, 1, loop-1), substr(_string, loop, strLen(_string))];
        #}
        #
      ENDSOURCE
      SOURCE #dbsStrip
        #// Phil ONeill  06/10/2009   String format
        #static str dbsStrip(str _inStr, dbsStripType _dbsStripType = dbsStripType::dbsSpaces)
        #{
        #    int     loop;
        #    str     outStr;
        #    str     removeChar = " ";
        #    str     replaceChar = "";
        #    ;
        #    switch (_dbsStripType)
        #    {
        #        case dbsStripType::dbsLeadingSpaces :
        #            return StrLRTrim(_inStr);
        #
        #        case dbsStripType::dbsDoubleQuotes : removeChar = '"';          //Remove spaces/ double quotes
        #        case dbsStripType::dbsSpaces :
        #            return dbsLib::dbsReplaceString(_instr, removeChar, "");
        #
        #        case dbsStripType::dbsReplacePunctuation : replaceChar = " ";
        #        default :
        #            outStr = _instr;
        #            for (loop = 1; loop <= 126; loop++)
        #            {
        #                if (loop >= 48 && loop <= 57 && _dbsStripType != dbsStripType::dbsNumeric)
        #                    continue;
        #
        #                if (loop >= 65 && loop <= 90 && _dbsStripType != dbsStripType::dbsAlpha)
        #                    continue;
        #
        #                if (loop >= 97 && loop <= 122 && _dbsStripType != dbsStripType::dbsAlpha)
        #                    continue;
        #
        #                if (_dbsStripType == dbsStripType::dbsSpacesPunctuationExcNegative && loop == 45) //'-'
        #                    continue;
        #
        #                if ((_dbsStripType == dbsStripType::dbsNonPrintable) && (loop < 31))
        #                    continue;
        #
        #                outStr = dbsLib::dbsReplaceString(outStr, num2Char(loop), replaceChar);
        #            }
        #        break;
        #    }
        #    return outStr;
        #
        #//        case dbsStripType::dbsSpacesPunctuationExcNegative :
        #//        case dbsStripType::dbsReplacePunctuation :                      //Replace punctuation with spaces
        #//        case dbsStripType::dbsSpacesPunctuationEtc :                    //Remove punctuation and spaces
        #//        case dbsStripType::dbsNumeric :                                 //Remove all numeric
        #//        case dbsStripType::dbsAlpha :                                   //Remove all non numeric
        #//        case dbsStripType::dbsNonPrintable :
        #}
      ENDSOURCE
      SOURCE #dbsUkWorkingDate
        #// Michael Kubiena  30/03/2010  high6851    P7  Return next working date X days from the date pased in
        #
        #static transDate dbsUkWorkingDate(transDate _date,
        #                                  int       _numberOfDays,
        #                                  boolean   _inclusive = false)
        #{
        #    workCalendarSched   workCalendarSched = new workCalendarSched();
        #
        #    transDate           workingDate;
        #    real                loop, workingDays;
        #    ;
        #
        #    workingDate = _date;
        #    workingDays = abs(_numberOfDays);
        #
        #    for (loop=1; loop<=workingDays; loop++)
        #    {
        #        if (! _inclusive || loop > 1)
        #            if (_numberOfDays > 0)
        #                workingDate++;
        #            else
        #                workingDate--;
        #
        #        while (! workCalendarSched.isPickupDate(inventParameters::find().dbsWorkingCalendarId, workingDate))
        #        {
        #            if (_numberOfDays > 0)
        #                workingDate++;
        #            else
        #                workingDate--;
        #
        #            if (year(workingDate) > 3000)
        #                throw error("@DBS2066" + inventParameters::find().dbsWorkingCalendarId);
        #        }
        #    }
        #
        #    return workingDate;
        #}
      ENDSOURCE
      SOURCE #dbsValidatePostcode
        #// Phil ONeill  06/10/2009   Validates a postcode format
        #// If a valid postcode is passed:
        #//      Return [formatted post code, area, district, sector, unit]
        #// If an invalid postcode is passed:
        #//      Return ["ERROR"]
        #//
        #// If _pafCheck is true, the paf file is read and a pass/ fail message is added to the returned container:
        #//      ["PAF_FOUND"] or ["PAF_NOT_FOUND"]
        #//
        #static container dbsValidatePostcode(dbsPostCode _postCode, Boolean _pafCheck = False)
        #{
        #    int                         loop;
        #    str                         postCode, postMap;
        #    str                         area, district, sector, unit;
        #    dbsPostCode                 formattedPostCode;
        #    dbsFormattedPAFData         pafData;
        #    ;
        #
        #    postCode = dbsLib::dbsSetCase(dbsLib::dbsStrip(_postCode, dbsStripType::dbsSpaces), 2);
        #
        #    if (substr(postCode, 1, 4) == 'BFPO')
        #        return [postCode, area, district, sector, unit, "NOPAFCHECK - British Forces"];
        #
        #    for (loop = 1;  loop <= strLen(postCode); loop++)
        #    {
        #        if (dbsLib::trueNumeric(substr(postCode, loop, 1)))
        #            postMap += "#";
        #        else
        #            postMap += "A";
        #    }
        #    switch (postMap)
        #    {
        #        case 'A##AA' :
        #            area     = substr(postCode, 1, 1);
        #            district = substr(postCode, 2, 1);
        #            sector   = substr(postCode, 3, 1);
        #            unit     = substr(postCode, 4, 2);
        #        break;
        #
        #        case 'A###AA' :
        #            area     = substr(postCode, 1, 1);
        #            district = substr(postCode, 2, 2);
        #            sector   = substr(postCode, 4, 1);
        #            unit     = substr(postCode, 5, 2);
        #        break;
        #
        #        case 'A#A#AA' :
        #            area     = substr(postCode, 1, 1);
        #            district = substr(postCode, 2, 2);
        #            sector   = substr(postCode, 4, 1);
        #            unit     = substr(postCode, 5, 2);
        #        break;
        #
        #        case 'AA##AA' :
        #            area     = substr(postCode, 1, 2);
        #            district = substr(postCode, 3, 1);
        #            sector   = substr(postCode, 4, 1);
        #            unit     = substr(postCode, 5, 2);
        #        break;
        #
        #        case 'AA###AA' :
        #            area     = substr(postCode, 1, 2);
        #            district = substr(postCode, 3, 2);
        #            sector   = substr(postCode, 5, 1);
        #            unit     = substr(postCode, 6, 2);
        #        break;
        #
        #        case 'AA#A#AA' :
        #            area     = substr(postCode, 1, 2);
        #            district = substr(postCode, 3, 2);
        #            sector   = substr(postCode, 5, 1);
        #            unit     = substr(postCode, 6, 2);
        #        break;
        #
        #        case 'AAA#AA' :
        #            area     = substr(postCode, 1, 3);
        #            sector   = substr(postCode, 4, 1);
        #            unit     = substr(postCode, 5, 2);
        #        break;
        #
        #        case 'AAAA' :
        #            area     = substr(postCode, 1, 3);
        #            district = substr(postCode, 4, 1);
        #        break;
        #
        #        case '####' :
        #            area     = substr(postCode, 1, 3);
        #            district = substr(postCode, 4, 1);
        #        break;
        #
        #        default:
        #            return ["ERROR"];
        #    }
        #
        #
        #    formattedPostCode = area + district + " " + sector + unit;
        #
        #    if (!_pafCheck)
        #    {
        #        return [formattedPostCode, area, district, sector, unit, "NOPAFCHECK"];
        #    }
        #    else
        #    {
        #        select firstOnly pafData
        #            where pafData.PostCode == formattedPostCode;
        #        if (pafData)
        #        {
        #            return [formattedPostCode, area, district, sector, unit, "PAF_FOUND"];
        #        }
        #        else
        #        {
        #            return [formattedPostCode, area, district, sector, unit, "PAF_NOT_FOUND"];
        #        }
        #    }
        #}
      ENDSOURCE
      SOURCE #splitStreetField
        #// T.Dixon 05/08/09 - Takes an AddressStreet field and returns a container, with each line of the address being an element.
        #static container splitStreetField(AddressStreet _street)
        #{
        #    Container   lStreetFields;
        #    int         loop;
        #    ;
        #
        #    for (loop = 0; loop <=2; loop++)
        #    {
        #        lStreetFields += [strLine(_street, loop)];
        #    }
        #
        #    return lStreetFields;
        #}
      ENDSOURCE
      SOURCE #trueNumeric
        #static NoYes trueNumeric(str _string)
        #{
        #    int         ascVal, loop;
        #    ;
        #    for (loop = 1; loop <= strLen(_string); loop++)
        #    {
        #        ascVal = char2num(_string, loop);
        #        if (ascVal < 48 || ascVal > 57)
        #            return NoYes::No;
        #    }
        #
        #    return NoYes::Yes;
        #}
      ENDSOURCE
    ENDMETHODS
  ENDCLASS
<Table:Record name="TmpSysLabel"
       xmlns:Table='urn:www.microsoft.com/Formats/Table'>
    <Table:Field name="Language">en-gb</Table:Field>
    <Table:Field name="Label">Error - No available working days</Table:Field>
    <Table:Field name="Description"></Table:Field>
    <Table:Field name="LabelId">@DBS2066</Table:Field>
    <Table:Field name="SysLabelApplModule">0</Table:Field>
    <Table:Field name="recVersion">0</Table:Field>
</Table:Record>
<Table:Record name="TmpSysLabel"
       xmlns:Table='urn:www.microsoft.com/Formats/Table'>
    <Table:Field name="Language">en-us</Table:Field>
    <Table:Field name="Label"></Table:Field>
    <Table:Field name="Description"></Table:Field>
    <Table:Field name="LabelId">@DBS2066</Table:Field>
    <Table:Field name="SysLabelApplModule">0</Table:Field>
    <Table:Field name="recVersion">0</Table:Field>
</Table:Record>


***Element: CLS

; Microsoft Dynamics AX Class: dbsDeliveryCharge unloaded
; --------------------------------------------------------------------------------
  CLSVERSION 1
 
  CLASS #dbsDeliveryCharge
    Id 51470
    PROPERTIES
      Name                #dbsDeliveryCharge
      Extends             #
      RunOn               #Called from
    ENDPROPERTIES
   
    METHODS
      Version: 3
      SOURCE #classDeclaration
        #// Phill ONeill  19/02/2010 HIGH6898 S06 Calculate carriage cost
        #class dbsDeliveryCharge
        #{
        #}
      ENDSOURCE
      SOURCE #dbsGetAmountCarriage
        #// Phill ONeill  11/03/2010 6898 S06 Get amount based surcharge from shipping define
        #container dbsGetAmountCarriage(dbsRegionId _region, jsPHScheduleShipping _shipping, amountCur _salesTotal)
        #{
        #    jsPHScheduleShippingDefine  shippingDefine;
        #    amountCur                   carriageCost;
        #    recId                       shippingRec;
        #    dbsShippingZone             shippingZone;
        #    ;
        #    while select shippingDefine
        #        index hint ScheduleShipping
        #        where shippingDefine.ScheduleName        == _shipping.ScheduleName
        #           && shippingDefine.dbsScheduleFromDate == _shipping.dbsScheduleFromDate
        #           && shippingDefine.dbsRegionId         == _region
        #           && shippingDefine.dbsDlvModeGroupId   == _shipping.dbsDlvModeGroupId
        #           && shippingDefine.DeliveryMode        == _shipping.DeliveryMode
        #    {
        #        if (shippingDefine.OrderGreaterEqualTo <= _salesTotal)
        #        {
        #            shippingRec = shippingDefine.RecId;
        #            switch (shippingDefine.ScheduleType)
        #            {
        #                case jsPHScheduleType::Amount :
        #                case jsPHScheduleType::dbsAmountZoneWeight :
        #                    carriageCost += Currency::amount(shippingDefine.AmountPercent, CompanyInfo::standardCurrency());
        #                    break;
        #
        #                case jsPHScheduleType::Percent :
        #                    carriageCost +=  Currency::amount(abs(_salesTotal) * shippingDefine.AmountPercent / 100,
        #                                                                                 CompanyInfo::standardCurrency());
        #                    break;
        #            }
        #        }
        #    }
        #    return [shippingRec, carriageCost];
        #}
      ENDSOURCE
      SOURCE #dbsGetWeightCarriage
        #// Phill ONeill  11/03/2010 6898 S06 Get weight based surcharge from shipping define
        #amountCur dbsGetWeightCarriage(recId _shippingDefineRecId, itemNetWeight _itemWeight)
        #{
        #    dbsCarriageDlvModeWeight    weight;
        #    amountCur                   carriageCost;
        #    recId                       lastWeight;
        #    boolean                     overWeight = True;
        #    ;
        #    while select weight
        #        index hint refRecIndexIdx
        #        where weight.refRecId       == _shippingDefineRecId
        #           && weight.weightFrom     <= _itemWeight
        #    {
        #        lastWeight    = weight.RecId;
        #        carriageCost += weight.Price;
        #
        #        if (weight.weightTo >= _itemWeight)
        #        {
        #            overWeight = False;
        #            break;
        #        }
        #    }
        #    if (overWeight)                                 // Add overweight surcharge
        #    {
        #        weight        = dbsCarriageDlvModeWeight::findRecId(lastWeight);
        #        carriageCost += weight.Surcharge * (_itemWeight - weight.weightTo);
        #    }
        #   return carriageCost;
        #}
      ENDSOURCE
      SOURCE #dbsCalculateCarriageCost
        #// Phill ONeill  11/03/2010 6898 S06 Calculate total carriage cost
        #static amountCur dbsCalculateCarriageCost(dbsRegionId _region,
        #                                          recId _shippingRecId,
        #                                          salesIdBase _salesId)
        #{
        #    amountCur                   carriageCost;
        #    dbsShippingZone             shippingZone;
        #    salesLine                   salesLine;
        #    itemNetWeight               itemWeight;
        #    amountCur                   salesTotal;
        #    jsPHScheduleShipping        shipping;
        #    container                   amountReturn;       //[amount recid, carriage charge from amount]
        #    dbsDeliveryCharge           deliveryCharge = new dbsDeliveryCharge();
        #    ;
        #    shipping = jsPHscheduleShipping::findRecId(_shippingRecId);
        #    if (!shipping)
        #        return carriageCost;
        #
        #    if (shipping.ScheduleType == jsPHScheduleType::Free)
        #        return 0;
        #
        #    shippingZone = dbsShippingZone::find(_region, shipping.dbsDlvModeGroupId, shipping.DeliveryMode, shipping.ScheduleName,
        #                                         shipping.dbsScheduleFromDate);
        #
        #    carriageCost = shippingZone.surcharge;
        #
        #    while select salesLine
        #        where salesLine.SalesId == _salesId
        #    {
        #        itemWeight += inventTable::find(salesLine.ItemId).NetWeight * salesLine.SalesQty;
        #        salesTotal += salesLine.SalesPrice * salesLine.SalesQty;
        #    }
        #
        #    amountReturn = deliveryCharge.dbsGetAmountCarriage(_region, shipping, salesTotal);
        #    carriageCost += conPeek(amountReturn, 2);
        #
        #    if (conpeek(amountReturn, 1))
        #        carriageCost += deliveryCharge.dbsGetWeightCarriage(conpeek(amountReturn, 1), itemWeight);
        #
        #    return carriageCost;
        #}
      ENDSOURCE
      SOURCE #dbsCopyDeliveryMode
        #// Phill ONeill  01/03/2010 6898 S06 Copy delivery mode shipping information
        #static void dbsCopyDeliveryMode(dbsProfileName _profile, dbsScheduleFromDate _fromDate, container _deliveryModeFrom, container _deliveryModeTo)
        #{
        #    jsPHSchedules                   jsPHSchedules;
        #    jsPHScheduleShipping            scheduleShippingFrom, scheduleShippingTo;
        #    jsPHScheduleShippingDefine      scheduleShippingDefineFrom, scheduleShippingDefineTo;
        #    dbsCarriageDlvModeWeight        carriageWeightFrom, carriageWeightTo;
        #    dbsShippingZone                 shippingZoneFrom, shippingZoneTo;
        #    RecId                           SavedRecId;
        #    dbsDlvModeGroupId               groupFrom, groupTo;
        #    dlvModeId                       modeFrom, modeTo;
        #    ;
        #    [groupFrom, modeFrom] = _deliveryModeFrom;
        #    [groupTo, modeTo]     = _deliveryModeTo;
        #
        #    jsPHschedules = jsPHschedules::findByDate(_profile, _fromDate);
        #    if (!jsPHschedules)
        #        return;
        #
        #    scheduleShippingFrom = jsPHScheduleShipping::findPrfDate(jsPHSchedules.ScheduleName, jsPHSchedules.dbsFromDate, groupFrom, modeFrom);
        #    if (!scheduleShippingFrom)
        #        return;
        #
        #    ttsBegin;
        #    scheduleShippingTo =  scheduleShippingFrom;
        #    scheduleShippingTo.dbsDlvModeGroupId = groupTo;
        #    scheduleShippingTo.DeliveryMode = modeTo;
        #    scheduleShippingTo.insert();
        #
        #    while select shippingZoneFrom
        #           where shippingZoneFrom.dbsProfileName        == jsPHSchedules.ScheduleName
        #              && shippingZoneFrom.dbsScheduleFromDate   == jsPHSchedules.dbsFromDate
        #              && shippingZoneFrom.dbsDlvModeGroup       == groupFrom
        #              && shippingZoneFrom.DlvModeId             == modeFrom
        #    {
        #        shippingZoneTo = shippingZoneFrom;
        #        shippingZoneTo.dbsDlvModeGroup = groupTo;
        #        shippingZoneTo.DlvModeId       = modeTo;
        #        if (!dbsShippingZone::find(shippingZoneTo.regionId, shippingZoneTo.dbsDlvModeGroup, shippingZoneTo.DlvModeId,jsPHSchedules.ScheduleName, jsPHSchedules.dbsFromDate ))
        #            shippingZoneTo.insert();
        #    }
        #
        #    while select scheduleShippingDefineFrom
        #        where scheduleShippingDefineFrom.ScheduleName        == scheduleShippingFrom.ScheduleName
        #           && scheduleShippingDefineFrom.dbsScheduleFromDate == scheduleShippingFrom.dbsScheduleFromDate
        #           && scheduleShippingDefineFrom.dbsDlvModeGroupId   == groupFrom
        #           && scheduleShippingDefineFrom.DeliveryMode        == modeFrom
        #    {
        #        savedRecId = scheduleShippingDefineFrom.RecId;
        #        scheduleShippingDefineTo =  scheduleShippingDefineFrom;
        #        scheduleShippingDefineTo.dbsDlvModeGroupId = groupTo;
        #        scheduleShippingDefineTo.DeliveryMode      = modeTo;
        #        scheduleShippingDefineTo.insert();
        #
        #        while select forupdate carriageWeightFrom
        #            where carriageWeightFrom.RefTableId == tableNum(jsPHScheduleShippingDefine)
        #               && carriageWeightFrom.refRecId == savedRecId
        #       {
        #            carriageWeightTo            = carriageWeightFrom;
        #            carriageWeightTo.refRecId   = scheduleShippingDefineTo.RecId;
        #            carriageWeightTo.insert();
        #       }
        #    }
        #    ttsCommit;
        #}
      ENDSOURCE
      SOURCE #dbsCopyProfile
        #// Phill ONeill  01/03/2010 6898 S06 Copy profile shipping information
        #static void dbsCopyProfile(dbsProfileName _profileFrom, dbsProfileName _profileTo, dbsScheduleFromDate _fromDate)
        #{
        #    jsPHSchedules                   schedulesFrom, schedulesTo;
        #    RecId                           SavedRecId;
        #    dbsShippingZone                 shippingZoneFrom, shippingZoneTo;
        #    jsPHScheduleShipping            scheduleShippingFrom, scheduleShippingTo;
        #    jsPHScheduleShippingDefine      scheduleShippingDefineFrom, scheduleShippingDefineTo;
        #    dbsCarriageDlvModeWeight        carriageWeightFrom, carriageWeightTo;
        #    ;
        #    if (!dbsProfileTable::find(_profileFrom) || !dbsProfileTable::find(_profileTo))
        #        return;
        #
        #    if (jsPHSchedules::findByDate(_profileTo, _fromDate))
        #        return;
        #
        #    ttsBegin;
        #    while select schedulesFrom
        #        where schedulesFrom.ScheduleName == _profileFrom
        #           && schedulesFrom.dbsFromDate ==  _fromDate
        #    {
        #        schedulesTo.clear();
        #        schedulesTo = schedulesFrom;
        #        schedulesTo.ScheduleName = _profileTo;
        #        schedulesTo.insert();
        #    }
        #
        #    while select scheduleShippingFrom
        #           where scheduleShippingFrom.ScheduleName        == _profileFrom
        #              && scheduleShippingFrom.dbsScheduleFromDate == _fromDate
        #    {
        #        scheduleShippingTo =  scheduleShippingFrom;
        #        scheduleShippingFrom.ScheduleName           = _profileTo;
        #        scheduleShippingFrom.dbsScheduleFromDate    = _fromDate;
        #        scheduleShippingTo.insert();
        #    }
        #
        #    while select shippingZoneFrom
        #           where shippingZoneFrom.dbsProfileName        == _profileFrom
        #              && shippingZoneFrom.dbsScheduleFromDate   == _fromDate
        #    {
        #        shippingZoneTo = shippingZoneFrom;
        #        shippingZoneTo.dbsProfileName       = _profileTo;
        #        shippingZoneTo.dbsScheduleFromDate  = _fromDate;
        #        if (!dbsShippingZone::find(shippingZoneTo.regionId, shippingZoneTo.dbsDlvModeGroup, shippingZoneTo.DlvModeId,_profileTo, _fromDate ))
        #            shippingZoneTo.insert();
        #    }
        #
        #    while select scheduleShippingDefineFrom
        #           where scheduleShippingDefineFrom.ScheduleName         == _profileFrom
        #              && scheduleShippingDefineFrom.dbsScheduleFromDate == _fromDate
        #    {
        #        savedRecId = scheduleShippingDefineFrom.RecId;
        #        scheduleShippingDefineTo =  scheduleShippingDefineFrom;
        #        scheduleShippingDefineTo.ScheduleName        = _profileTo;
        #        scheduleShippingDefineTo.dbsScheduleFromDate = _fromDate;
        #        scheduleShippingDefineTo.insert();
        #
        #        while select forupdate carriageWeightFrom
        #                where carriageWeightFrom.RefTableId == tableNum(jsPHScheduleShippingDefine)
        #                   && carriageWeightFrom.refRecId == savedRecId
        #        {
        #            carriageWeightTo            = carriageWeightFrom;
        #            carriageWeightTo.refRecId   = scheduleShippingDefineTo.RecId;
        #            carriageWeightTo.insert();
        #        }
        #    }
        #    ttsCommit;
        #}
      ENDSOURCE
      SOURCE #dbsCopyRegion
        #// Phill ONeill  01/03/2010 6898 S06 Copy profile shipping information
        #static void dbsCopyRegion(dbsRegionId _regionFrom, dbsRegionId _regionTo, recID _shippingRecId)
        #{
        #    dbsShippingZone                 shippingZoneFrom, shippingZoneTo;
        #    jsPHScheduleShipping            jsPHScheduleShipping, scheduleShippingFrom, scheduleShippingTo;
        #    jsPHScheduleShippingDefine      scheduleShippingDefineFrom, scheduleShippingDefineTo;
        #    dbsCarriageDlvModeWeight        carriageWeightFrom, carriageWeightTo;
        #    RecId                           SavedRecId;
        #    ;
        #    jsPHScheduleShipping =  jsPHScheduleShipping::findRecID(_shippingRecId);
        #
        #    ttsBegin;
        #    while select shippingZoneFrom
        #           where shippingZoneFrom.regionId        == _regionFrom
        #              && shippingZoneFrom.dbsDlvModeGroup == jsPHScheduleShipping.dbsDlvModeGroupId
        #              && shippingZoneFrom.DlvModeId       == jsPHScheduleShipping.DeliveryMode
        #
        #    {
        #        shippingZoneTo = shippingZoneFrom;
        #        shippingZoneTo.regionId = _regionTo;
        #        shippingZoneTo.insert();
        #
        #    }
        #
        #    while select scheduleShippingDefineFrom
        #           where scheduleShippingDefineFrom.dbsRegionId             == _regionFrom
        #              && scheduleShippingDefineFrom.ScheduleName            == jsPHScheduleShipping.ScheduleName
        #              && scheduleShippingDefineFrom.dbsScheduleFromDate     == jsPHScheduleShipping.dbsScheduleFromDate
        #              && scheduleShippingDefineFrom.dbsDlvModeGroupId       == jsPHScheduleShipping.dbsDlvModeGroupId
        #              && scheduleShippingDefineFrom.DeliveryMode            == jsPHScheduleShipping.DeliveryMode
        #
        #    {
        #        savedRecId = scheduleShippingDefineFrom.RecId;
        #        scheduleShippingDefineTo =  scheduleShippingDefineFrom;
        #        scheduleShippingDefineFrom.dbsRegionId = _regionTo;
        #        scheduleShippingDefineTo.insert();
        #
        #        while select forupdate carriageWeightFrom
        #                where carriageWeightFrom.RefTableId == tableNum(jsPHScheduleShippingDefine)
        #                   && carriageWeightFrom.refRecId == savedRecId
        #        {
        #            carriageWeightTo            = carriageWeightFrom;
        #            carriageWeightTo.refRecId   = scheduleShippingDefineTo.RecId;
        #            carriageWeightTo.insert();
        #        }
        #     }
        #     ttsCommit;
        #}
      ENDSOURCE
      SOURCE #getCurrentProfile
        #// Phill ONeill  05/03/2010 6898 S06 Get profile from date
        #static jsPHSchedules getCurrentProfile(dbsProfileName _profile, transDate _date)
        #{
        #    jsPHSchedules       _schedules;
        #    ;
        #    while select _schedules
        #        where _schedules.ScheduleName == _profile
        #    {
        #            if (_schedules.dbsFromDate <= _date && _schedules.dbsToDate >= _date)
        #                break;
        #    }
        #    return _schedules;
        #}
      ENDSOURCE
    ENDMETHODS
  ENDCLASS

***Element: CLS

; Microsoft Dynamics AX Class: dbsDeliveryOptions unloaded
; --------------------------------------------------------------------------------
  CLSVERSION 1
 
  CLASS #dbsDeliveryOptions
    Id 51457
    PROPERTIES
      Name                #dbsDeliveryOptions
      Extends             #
      RunOn               #Called from
    ENDPROPERTIES
   
    METHODS
      Version: 3
      SOURCE #classDeclaration
        #// Phill ONeill  25/02/2010 6898 S06 Calls dbsDeliveryOptions form
        #class dbsDeliveryOptions
        #{
        #}
      ENDSOURCE
      SOURCE #main
        #// Phill ONeill  09/03/2010 6898 S06 Class to call delivery options form
        #static void main(Args args, boolean _allowCancel = True)
        #{
        #
        #    Common                          record;
        #    SalesTable                      salesTable;
        #    FormRun                         deliveryFormRun;
        #    args                            deliveryArgs;
        #    struct                          deliveryStruct;
        #    custTable                       custTable;
        #    addressZipCodeId                postCode;
        #    transDate                       requestedDate;
        #    dbsProfileName                  profile;
        #    ;
        #    if (! args)
        #        throw error("@SYS25407");
        #
        #    _allowCancel = True;
        #
        #    record  = args.record();
        #
        #    if (record.TableId == tableNum(salesTable))
        #    {
        #        salesTable = record;
        #        custTable = custTable::find(salesTable.CustAccount);
        #        if (!custTable)
        #            throw error("@DBS2096");
        #
        #        profile   = custTable.dbsProfileName;                                       //If no customer profile, then check the
        #        if (!profile)                                                               //customer group, failing that, check
        #            profile = custGroup::find(custTable.CustGroup).jsPHScheduleName;        //the store group
        #
        #        if (!profile)
        #            profile = custTable.dbsStoreGroup().dbsProfileName;
        #
        #        postCode  = salesTable.DeliveryZipCode;
        #        if (!postCode)
        #            throw error("@DBS2097");
        #
        #        requestedDate =  salesTable.jsRequestedDate;
        #    }
        #    else
        #    {
        #        requestedDate = systemDateGet();
        #        profile = 'dabs.com';
        #    }
        #
        #    deliveryStruct = new Struct("dbsProfileName profile; addressZipCodeId postCode; transDate requestedDate; salesIdBase salesId; boolean allowCancel");
        #    deliveryStruct.value("postCode", postCode);
        #    deliveryStruct.value("requestedDate", requestedDate);
        #    deliveryStruct.value("profile", profile);
        #    deliveryStruct.value("salesId", salesTable.SalesId);
        #
        #    deliveryStruct.value("allowCancel", _allowCancel);
        #
        #    deliveryArgs = new Args();
        #    deliveryArgs.name(formstr(dbsDeliveryOptions));
        #    deliveryArgs.parmObject(deliveryStruct);
        #
        #    deliveryFormRun = classFactory.formRunClass(deliveryArgs);
        #    deliveryFormRun.formOnTop();
        #    deliveryFormRun.run();
        #    deliveryFormRun.wait();
        #
        #}
      ENDSOURCE
    ENDMETHODS
  ENDCLASS
<Table:Record name="TmpSysLabel"
       xmlns:Table='urn:www.microsoft.com/Formats/Table'>
    <Table:Field name="Language">en-gb</Table:Field>
    <Table:Field name="Label">Update must be called with parameters.</Table:Field>
    <Table:Field name="Description"></Table:Field>
    <Table:Field name="LabelId">@SYS25407</Table:Field>
    <Table:Field name="SysLabelApplModule">0</Table:Field>
    <Table:Field name="recVersion">0</Table:Field>
</Table:Record>
<Table:Record name="TmpSysLabel"
       xmlns:Table='urn:www.microsoft.com/Formats/Table'>
    <Table:Field name="Language">en-us</Table:Field>
    <Table:Field name="Label">Update must be called with parameters.</Table:Field>
    <Table:Field name="Description"></Table:Field>
    <Table:Field name="LabelId">@SYS25407</Table:Field>
    <Table:Field name="SysLabelApplModule">0</Table:Field>
    <Table:Field name="recVersion">0</Table:Field>
</Table:Record>

<Table:Record name="TmpSysLabel"
       xmlns:Table='urn:www.microsoft.com/Formats/Table'>
    <Table:Field name="Language">en-gb</Table:Field>
    <Table:Field name="Label">Customer not found</Table:Field>
    <Table:Field name="Description"></Table:Field>
    <Table:Field name="LabelId">@DBS2096</Table:Field>
    <Table:Field name="SysLabelApplModule">0</Table:Field>
    <Table:Field name="recVersion">0</Table:Field>
</Table:Record>
<Table:Record name="TmpSysLabel"
       xmlns:Table='urn:www.microsoft.com/Formats/Table'>
    <Table:Field name="Language">en-us</Table:Field>
    <Table:Field name="Label"></Table:Field>
    <Table:Field name="Description"></Table:Field>
    <Table:Field name="LabelId">@DBS2096</Table:Field>
    <Table:Field name="SysLabelApplModule">0</Table:Field>
    <Table:Field name="recVersion">0</Table:Field>
</Table:Record>

<Table:Record name="TmpSysLabel"
       xmlns:Table='urn:www.microsoft.com/Formats/Table'>
    <Table:Field name="Language">en-gb</Table:Field>
    <Table:Field name="Label">Postcode not passed</Table:Field>
    <Table:Field name="Description"></Table:Field>
    <Table:Field name="LabelId">@DBS2097</Table:Field>
    <Table:Field name="SysLabelApplModule">0</Table:Field>
    <Table:Field name="recVersion">0</Table:Field>
</Table:Record>
<Table:Record name="TmpSysLabel"
       xmlns:Table='urn:www.microsoft.com/Formats/Table'>
    <Table:Field name="Language">en-us</Table:Field>
    <Table:Field name="Label"></Table:Field>
    <Table:Field name="Description"></Table:Field>
    <Table:Field name="LabelId">@DBS2097</Table:Field>
    <Table:Field name="SysLabelApplModule">0</Table:Field>
    <Table:Field name="recVersion">0</Table:Field>
</Table:Record>
 

}

No comments: