Wednesday, August 28, 2019

Update Cust group and segments

static void Update_CustGroup(Args _args)
{
  CustGroup                 _custGroup;
  CustTable                 _custTable;
  smmBusRelSegmentGroup     _segmentGroup;
  smmBusRelSubSegmentGroup  _subSegmentGroup;
   

    ttsBegin;
   select forUpdate _custGroup
     where _custGroup.dataAreaId == 'gh'
     && _custGroup.CustGroup == 'HOR-HO-HPB';
    {
        _custGroup.CustGroup ='HOR-HO-HRB';
        _custGroup.update();
         info(' custgroup updated done');
    }
     
   select forUpdate _subSegmentGroup
       where _subSegmentGroup.dataAreaId == 'gh'
       && _subSegmentGroup.SubsegmentId == 'HPB';
    {
        _subSegmentGroup.SubsegmentId           = 'HRB';
        _subSegmentGroup.SubSegmentDescription  = 'CAFES & BAKE SHOPS';
        _subSegmentGroup.update();
       
        info('subsegment updated done');
    }
   
    while select forUpdate _custTable
        where _custTable.dataAreaId == 'gh'
        && _custTable.CustGroup     == 'HOR-HO-HPB'
        && _custTable.SegmentId     == 'HO'
        && _custTable.SubsegmentId  == 'HPB'
        && _custTable.AccountNum    != ''
    {
        _custTable.CustGroup    ='HOR-HO-HRB';
        _custTable.SubsegmentId = 'HRB';
        _custTable.doUpdate();
        info('All customers are updated with cust group');
    }
   
   ttsCommit;
   
   
   
}

Tuesday, August 20, 2019

sending email to salesman regarding customer is on hold due to credit limit

salestable - methos
---------------------------------------------------
Public  void God_SendAlert()
{
    DirPersonUser                       dirPersonUser;
    EventNotificationSource             _source;
    CustTable                           custTable;
    EventNotification                   event = EventNotification::construct(EventNotificationSource::Sync);
   
    //--- added by kavin for sending email to salesman for cusotmer is on hold 20 aug -2019
   
    GOD_SendEmail                       god_SendEmail;
    Email                               mainContactWorkerEmail;
   //--- added by kavin for sending email to salesman for cusotmer is on hold 20 aug -2019
                    custTable = CustTable::find(this.CustAccount);

                    event.parmRecord(custTable);
                    event.parmUserId(dirPersonUser::findParty(HcmWorker::findRecId(CustTable::find(this.CustAccount).MainContactWorker).Person).User);//curuserid());//user for which this alert to be shown
                    event.parmDataSourceName('Custtable');  //form datasource
                    event.parmMenuFunction(new MenuFunction('custtable', MenuItemtype::Display));
                    event.parmSubject('Customer Unblocking notification for Sales order process');
                    event.parmMessage(strFmt("Customer %1 is Blocked. Unable to Create Sales order. Kindly take action.",custtable.AccountNum));
                   
                    //--- added by kavin for sending email to salesman for cusotmer is on hold 20 aug -2019
                    mainContactWorkerEmail = HcmWorker::emailServer(HcmWorker::find(CustTable::find(this.CustAccount).MainContactWorker).Person);
                   
                    //info(custtable.AccountNum);

                   god_SendEmail::sendmail(event.parmSubject('Customer Unblocking notification for Sales order process'),
                                           event.parmMessage(strFmt("Customer %1 is Blocked. Unable to Create Sales order. Kindly take action.",custtable.AccountNum)),
                                           'axsentmails@greenhouseuae.com',mainContactWorkerEmail);
                   //--- added by kavin for sending email to salesman for cusotmer is on hold -- 20 aug -2019
                    event.create();


}


------------------------------------------------

class

class GOD_SendEmail
{
}
------------------------------------------------

public static void sendmail(Description  _Subject,string255 _body,string50  _fromaddress,string50 _toaddress)
{
    SysEmailParameters parameters = SysEmailParameters::find();
    SMTPRelayServerName relayServer;
    SMTPPortNumber portNumber;
    SMTPUserName userName;
    SMTPPassword password;
    Str1260 subject,body;
    InteropPermission interopPermission;
    SysMailer mailer;
    System.Exception e;

    ;
    if (parameters.SMTPRelayServerName)
    relayServer = parameters.SMTPRelayServerName;
    else
    relayServer = parameters.SMTPServerIPAddress;
    portNumber = parameters.SMTPPortNumber;
    userName = parameters.SMTPUserName;
    password = SysEmailParameters::password();
    subject = _Subject;
    body = _body; //"<B> " + _body  + " </B>";

    CodeAccessPermission::revertAssert();

    try
    {
        interopPermission = new InteropPermission(InteropKind::ComInterop);
        interopPermission.assert();
        mailer = new SysMailer();
        mailer.SMTPRelayServer(relayServer,portNumber,userName,password, parameters.NTLM);
        //instantiate email
        mailer.fromAddress(_fromaddress);

        mailer.tos().appendAddress(_toaddress);
        mailer.subject(subject);
        mailer.htmlBody(body);
        mailer.sendMail();
        CodeAccessPermission::revertAssert();
        info("Email has been send!");
    }
    catch (Exception::CLRError)
    {
        e = ClrInterop::getLastException();

        while (e)
        {
            info(e.get_Message());
            e = e.get_InnerException();
        }

        CodeAccessPermission::revertAssert();

        info ("Failed to Send Email some Error occure");
    }

}


Monday, August 19, 2019

Send Report Throw Mail

static void God_sendReportThrowMail(Args _args)
{




    SrsReportRunController                          ssrsController = new SrsReportRunController();
    GOD_GRVReportController             GoodDestructionReportcontroller;


    GOD_GRVReportContract      Contract = new GOD_GRVReportContract();
    SRSPrintDestinationSettings     printerSettings;
       str                             ReportPath;


    // Send Email throw Code

    str             Body;
    str             Subject;
    str             cc1;
    str             mailAddressFrom;
    str             mailAddressTo;
    UserInfo        userInfo;
    SysINetMail mail = new SysINetMail();
    SysMailer           Mailer;
    InventParameters     _InventParameter;
// End

    Mailer  =new SysMailer();

    select _InventParameter;



     ReportPath = "C:\\" + "GRVReportGH" +".pdf";
    Subject = _InventParameter.God_EmailSubject;
    Body = _InventParameter.God_EmailBody;
     ssrsController.parmReportName(ssrsReportStr(GOD_GRVReport, Report_GH));
    ssrsController.parmExecutionMode(SysOperationExecutionMode::Synchronous);
    ssrsController.parmShowDialog(false);

    Contract.parmRecId(5637144581);
   // Contract.parmRecordId(VendPurchOrderJour.RecId);
    ssrsController.parmReportContract().parmRdpContract(Contract);

    //link the printer settings to the controller
    printerSettings = ssrsController.parmReportContract().parmPrintSettings();
    //print to pdf and always overwrite if the file exists

    printerSettings.printMediumType(SRSPrintMediumType::File);
    printerSettings.fileFormat(SRSReportFileFormat::PDF);
    printerSettings.overwriteFile(true);
    printerSettings.fileName(@ReportPath);
    ssrsController.runReport();

     //assign the values ​​to send email
    mailAddressFrom     = "axsentmails@gxxxxxx.com";
    mailAddressTo       = "axxxxxx@gxxx.com";
    cc1 = "bxxxxx@gxxx.com";


    //Send Mail
    if (mailer !=null)
             {
            mailer.quickSend(mailAddressFrom,mailAddressTo,Subject,Body,cc1,ReportPath);

            //mailer.finalize()

            }




    //mail.sendMailAttach(mailAddressTo,cc1,Subject,Body,false,ReportPath);
   // mailer.quickSend(mailAddressFrom,mailAddressTo,"Attach GRV Report","GRV Report",ReportPath);

   info("Mail Send ");



}

Find Customer Address

static void FindCustomerAddress(Args _args)
{
     CustTable custTable;
    DirPartyTable dirParty;
    LogisticsElectronicAddress electronicAddress;
    DirPartyLocation dirPartyLoc;

    //find the customer
    custTable = CustTable::find("C-00016");
    //find the party for the customer
    dirParty = DirPartyTable::findRec(custTable.Party);

    //find all of the contacts for the current customer
    while SELECT  * FROM electronicAddress
    EXISTS JOIN * FROM dirPartyLoc
    WHERE electronicAddress.Location == dirPartyLoc.Location && dirParty.RecId==dirPartyLoc.Party
    {
        info(electronicAddress.Locator);
    }

}

Emp Contract Master

static void EmpContractMaster(Args _args)
{
     #AviFiles
    FilenameOpen filename;
    dialogField dialogFilename,DialogJournalType;
    int jounaltype;
    Dialog dialog= new Dialog("Excel Upoad");
    Container excelCont[];
    GOD_PaymentMode PaymentType;
    int rowIdx;
    Counter linesImported;
    int lastRow,dimcount;
    boolean ok = true;
    Description c1,c3,c4,c5,c6,c7,c8,c9,c2,c10,c11,c12;
    //int64 c2;
    str input;
    container       accEntryPattern;
    BudgetType      budgetType;
    SysExcelApplication application;
    SysExcelWorkBooks workBooks;
    SysExcelWorkSheets workSheets;
    SysExcelWorkSheet workSheet;
    SysExcelCells cells;
    GOD_EmplContract    GOD_EmplContract;
    GOD_ContractValidity    GOD_ContractValidity;
    GOD_ContractType  GOD_ContractType;
    GOD_ContractNo  contractNo;
    HcmEmployment   hcmEmployment;
    NoYes NoYes;

    SysOperationProgress progress;
    struct      struct= new Struct();
    boolean                                 ret = true;
    dirPersonName dirPersonName;
    HcmWorker hcmworker;

    #define.CurrentVersion(1)
    #localmacro.CurrentList
    filename
    #endmacro

    #Excel
    #define.Star('*')
    #define.Space(' ')


    // convert into str from excel cell value
    str COMVariant2Str(COMVariant _cv, int _decimals = 0, int _characters = 0, int _separator1 = 0, int _separator2 = 0)
    {
        switch (_cv.variantType())
        {
            case (COMVariantType::VT_BSTR):
            return _cv.bStr();

            case (COMVariantType::VT_R4):
            return num2str(_cv.float(),_characters,_decimals,_separator1,_separator2);

            case (COMVariantType::VT_R8):
            return num2str(_cv.double(),_characters,_decimals,_separator1,_separator2);

            case (COMVariantType::VT_DECIMAL):
            return num2str(_cv.decimal(),_characters,_decimals,_separator1,_separator2);

            case (COMVariantType::VT_DATE):
            return date2str(_cv.date(),123,2,1,2,1,4);

            case (COMVariantType::VT_EMPTY):
            return "";

            default:
            throw error(strfmt("@SYS26908", _cv.variantType()));
        }
        return "";
    }

    // Find last row from excel

    int findLastRow(SysExcelWorkSheet _workSheet)
    {
        SysExcelRange range;
        ;

        range = _workSheet.cells().range(#ExcelTotalRange);

        try
        {
            // Finds the row where the first contents is found.
            range = range.find(#Star, null, #xlFormulas, #xlWhole, #xlByRows, #xlPrevious);
        }
        catch (Exception::Error)
        {
            error("@SYS59926");
            return 0;
        }

        if (range)
        {
            return range.row();
        }
        else
        {
            return 0;
        }
    }


    ;


    dialogFilename = dialog.addField(extendedtypestr(FilenameOpen));
   // DialogJournalType = dialog.addField(enumstr(God_JournalToUpload),"Journal Type");
    dialog.filenameLookupFilter(["@SYS28576",#XLS,#Xlsx]);
    dialog.filenameLookupTitle("Upload from Excel");
    dialogFilename.value(filename);

    if(!dialog.run())
    return;

    filename = dialogFilename.value();

   // ttsbegin;

    application = SysExcelApplication::construct();
    workBooks = application.workbooks();
    workBooks.open(filename,0,true);

    workSheets = workBooks.item(1).worksheets();
    // this.importExcel("Sheet1");

    input = "Sheet1";
    workSheet = workSheets.itemFromNum(1);//.itemFromName(input);
    cells = workSheet.cells();
    lastRow = findLastRow(workSheet);
    rowIdx = 2;
    progress = new SysOperationProgress();
    progress.setCaption("Excel Importing");
    progress.setTotal(lastRow);
    progress.setAnimation(#AviTransfer);
    setprefix("Excel Import");
    while (rowIdx <= lastRow)
    {

        setPrefix(strfmt("Excel Row: %1", rowIdx));

        c1 = COMVariant2Str(cells.item(rowIdx,1).value());
        c2 = COMVariant2Str(cells.item(rowIdx,2).value());
        c3 = COMVariant2Str(cells.item(rowIdx,3).value());
        c4 = COMVariant2Str(cells.item(rowIdx,4).value());
        c5 = COMVariant2Str(cells.item(rowIdx,5).value());
        c6 = COMVariant2Str(cells.item(rowIdx,6).value());
        c7 = COMVariant2Str(cells.item(rowIdx,7).value());
        c8 = COMVariant2Str(cells.item(rowIdx,8).value());
        c9 = COMVariant2Str(cells.item(rowIdx,9).value());
        c10 = COMVariant2Str(cells.item(rowIdx,10).value());
        c11 = COMVariant2Str(cells.item(rowIdx,11).value());
        c12 = COMVariant2Str(cells.item(rowIdx,11).value());

        linesImported++;

        //ttsBegin;
        hcmworker = HcmWorker::findByPersonnelNumber(c1);
        select firstonly hcmEmployment where hcmEmployment.Worker == hcmworker.RecId;
        contractNo = str2int(c2);

        if(HcmWorker)
        {
            ttsBegin;
            select forUpdate GOD_EmplContract
            where GOD_EmplContract.EmplId == hcmworker.PersonnelNumber
               && GOD_EmplContract.ContractNo == contractNo && GOD_EmplContract.Active == NoYes::Yes;
            if(GOD_EmplContract)
            {
                GOD_EmplContract.ContractNo = contractNo;
                GOD_EmplContract.GradeId = c3;
                GOD_EmplContract.GradeLevelId  = c4;
                GOD_EmplContract.BasicSalary = any2real(c5);
                GOD_EmplContract.PaymentType = str2enum(PaymentType,c6);
                GOD_EmplContract.OrganizationUnitId = c7;
                GOD_EmplContract.OMCostCenter= c8;
                GOD_EmplContract.EmployeeType = str2enum(GOD_ContractType,c9);
                GOD_EmplContract.Validity = str2enum(GOD_ContractValidity,c10);
                GOD_EmplContract.ProbationCompleted = str2enum(NoYes,c11);
                GOD_EmplContract.ProfileGroupId = c12;
                GOD_EmplContract.StartDate = any2date(hcmEmployment.ValidFrom);
                GOD_EmplContract.EffectiveDate = any2date(hcmEmployment.ValidFrom);
                GOD_EmplContract.update();
            }
            else
            {
                GOD_EmplContract.ContractNo = contractNo;
                GOD_EmplContract.GradeId = c3;
                GOD_EmplContract.GradeLevelId  = c4;
                GOD_EmplContract.BasicSalary = any2real(c5);
                GOD_EmplContract.PaymentType = str2enum(PaymentType,c6);
                GOD_EmplContract.OrganizationUnitId = c7;
                GOD_EmplContract.OMCostCenter = c8;
                GOD_EmplContract.EmployeeType = str2enum(GOD_ContractType,c9);
                GOD_EmplContract.Validity = str2enum(GOD_ContractValidity,c10);
                GOD_EmplContract.ProbationCompleted = str2enum(NoYes,c11);
                GOD_EmplContract.ProfileGroupId = c12;
                GOD_EmplContract.EmplId = hcmworker.PersonnelNumber;
                GOD_EmplContract.Active = NoYes::Yes;
                GOD_EmplContract.StartDate = any2date(hcmEmployment.ValidFrom);
                GOD_EmplContract.EffectiveDate = any2date(hcmEmployment.ValidFrom);
                GOD_EmplContract.insert();
            }
            ttsCommit;
        }

        progress.setText("Importing " + c1);
        progress.setCount(linesImported);
        rowIdx++;
     }

     info("done");
}

Upload Customer Region

static void UploadCustomerRegion(Args _args)
{

    SysExcelApplication application;
    SysExcelWorkbooks   workbooks;
    SysExcelWorkbook    workbook;
    SysExcelWorksheets  worksheets;
    SysExcelWorksheet   worksheet;
    SysExcelCells       cells;
    int                 row;
    CommaTextIO         csvFile;
    container           readCon;
    counter             icount,updated;
    Dialog              dialog;
    DialogField         dfFileName;


    FileName            fileName;
    Name                name;

    DirPartyContactInfoView   contactView;
    CustTable                 CustTable;
    DirParty                  dirParty;
    DirPartyRecId             partyRecId;

    LogisticsPostalAddress    address;
    DirPartyPostalAddressView addressView;

    updated                  = 0;

    #File

    application = SysExcelApplication::construct();
    workbooks   = application.workbooks();
    dialog      = new Dialog("Pick the file");
    dfFileName  = dialog.addField(extendedTypeStr("FilenameOpen"));
    dialog.filenameLookupFilter(["All files", #AllFiles]);


    if (dialog.run())
    {
      fileName = dfFileName.value() ;
    try
    {
      workbooks.open(filename);
    }
    catch (Exception::Error)
    {
      throw error("File cannot be opened.");
    }

    workbook   = workbooks.item(1);
    worksheets = workbook.worksheets();
    worksheet  = worksheets.itemFromNum(1);
    cells      = worksheet.cells();

    ttsBegin;
    {

    row++;
    name       = strLRTrim(cells.item(row, 2).value().bStr());
    partyRecId = DirPartyTable::createNew( DirPartyType::Organization, name).RecId;

    custTable.clear();
    custTable.initValue();
    custTable.Party         = partyRecId;
    custTable.AccountNum    = strLRTrim(cells.item(row, 1).value().bStr());
    custTable.CustGroup     = strLRTrim(cells.item(row, 3).value().bStr());
    custTable.Currency      = strLRTrim(cells.item(row, 4).value().bStr());
    custTable.DlvMode       = strLRTrim(cells.item(row, 5).value().bStr());
    custTable.PaymTermId    = strLRTrim(cells.item(row, 6).value().bStr());
    custTable.update();

    custTable               = Custtable::find(strLRTrim(cells.item(row, 1).value().bStr()));
    partyRecId              = custTable.Party;

    DirParty                = DirParty::constructFromPartyRecId(partyRecId );
    address.clear();
    //address.PostBox = strLRTrim(conPeek(readCon,13));
    address.CountryRegionId = strLRTrim(cells.item(row, 7).value().bStr());
    if( address.CountryRegionId != "")
    {
        address.State           = strLRTrim(cells.item(row, 8).value().bStr());
        address.ZipCode         = strLRTrim(cells.item(row, 9).value().bStr());
        address.Street          = strLRTrim(cells.item(row, 10).value().bStr());
        address.City            = strLRTrim(cells.item(row, 11).value().bStr());

        //address.Address = conPeek(readCon,4);

        addressView.LocationName = "Address";
        addressView.IsPrimary    = NoYes::Yes;
        addressView.Party        = partyRecId;
        addressview.initFromPostalAddress(address);


        DirParty                 = DirParty::constructFromPartyRecId(addressView.Party );
        DirParty.createOrUpdatePostalAddress(addressView);
    }

    contactView.clear();

    if(strLRTrim(cells.item(row, 12).value().bStr()) != "")
    {
        contactView.LocationName = "Phone Number";
        contactView.Locator      = strLRTrim(cells.item(row, 12).value().bStr());
        contactView.Type         = LogisticsElectronicAddressMethodType::Phone;
        contactView.Party        = partyRecId;
        contactView.IsPrimary    = NoYes::Yes;
        dirParty.createOrUpdateContactInfo(contactView);
    }

    if(strLRTrim(cells.item(row, 13).value().bStr()) != "")
    {
        contactView.LocationName = "Fax Number";
        contactView.Locator      = strLRTrim(cells.item(row, 13).value().bStr());
        contactView.Type         = LogisticsElectronicAddressMethodType::Fax;
        contactView.Party        = partyRecId;
        contactView.IsPrimary    = NoYes::Yes;
        dirParty.createOrUpdateContactInfo(contactView);
    }

    if(strLRTrim(cells.item(row, 14).value().bStr()) != "")
    {
        contactView.LocationName = "Website";
        contactView.Locator      = strLRTrim(cells.item(row, 14).value().bStr());
        contactView.Type         = LogisticsElectronicAddressMethodType::URL;
        contactView.Party        = partyRecId;
        contactView.IsPrimary    = NoYes::Yes;
        dirParty.createOrUpdateContactInfo(contactView);
    }

    if(strLRTrim(cells.item(row, 15).value().bStr())!= "")
    {
        contactView.LocationName = "Email";
        contactView.Locator      = strLRTrim(cells.item(row, 15).value().bStr());
        contactView.Type         = LogisticsElectronicAddressMethodType::Email;
        contactView.Party        = partyRecId;
        contactView.IsPrimary    = NoYes::Yes;
        dirParty.createOrUpdateContactInfo(contactView);
    }



    }
    ttsCommit;
  }
}