Wednesday, 22 May 2019

for my reference

static void SHP_ItemSiteWarehouseUpdate(Args _args)
{
    InventDim   inventdimTo;//To create the buffer for new inventDim for updated warehouse.
    InventDim    inventdim, inventdimCount;
    InventDim inventdimTo2;//To find or create new inventDimId for update in reqItemTable.
    InventDim inventdimLoc;//To get the buffer of inventDIim inside while loop.
    ReqItemTable    reqitemtable, reqitemtableUpd, reqitemtableCount;
    Counter counter;

   /*select count(recId) from reqitemtableCount group by CovInventDimId
   exists join inventdimCount
    where inventdimCount.InventSiteId == 'PL' &&
        inventdimCount.InventLocationId == 'WARE' &&
        reqitemtableCount.CovInventDimId == inventdimCount.inventDimId;

    info(strFmt("%1",reqitemtableCount.RecId));*/

    while select reqitemtable group by CovInventDimId
    join inventdim
    where inventdim.InventSiteId == 'PL' &&
        inventdim.InventLocationId == 'WARE' &&
        reqitemtable.CovInventDimId == inventdim.inventDimId
    {
        counter += 1;

        inventdimLoc = InventDim::find(reqitemtable.CovInventDimId);

        info(inventdimLoc.inventDimId + inventdimLoc.InventLocationId + inventdimLoc.InventSiteId);

        inventdimTo.InventSiteId = 'PL';
        inventdimTo.InventLocationId = 'POLUDNIOWA';
        inventdimTo.configId = inventdimLoc.configId;
        inventdimTo.InventStyleId = inventdimLoc.InventStyleId;
        inventdimTo.wMSLocationId = inventdimLoc.wMSLocationId;
        inventdimTo.inventBatchId = inventdimLoc.inventBatchId;
        inventdimTo.InventColorId = inventdimLoc.InventColorId;
        inventdimTo.inventSerialId = inventdimLoc.inventSerialId;
        inventdimTo.InventStatusId = inventdimLoc.InventStatusId;
        inventdimTo.LicensePlateId = inventdimLoc.LicensePlateId;
        inventdimTo.wmsPalletId    = inventdimLoc.wmsPalletId;

        inventdimTo2 = inventdim::findOrCreate(inventdimTo);

        update_recordSet reqitemtableUpd
        setting CovInventDimId = inventdimTo2.inventDimId where
            reqitemtableUpd.CovInventDimId == inventdimLoc.inventDimId;

    }

    info('done, records updated in item coverage');
}

Tuesday, 14 May 2019

Auto Post Packing Slip for Sales Order

private void postPackingSlip(FormDataSource salesTable_ds)
{
    salesFormLetter salesFormLetter;
    SalesTable salesTable;
    ;

    try
    {
        for (salesTable = salesTable_ds.getFirst(true) ? salesTable_ds.getFirst(true) : salesTable_ds.cursor();
         salesTable;
         salesTable = salesTable_ds.getNext())
        {
            salesFormLetter = SalesFormLetter::construct(DocumentStatus::PackingSlip);
            salesFormLetter.update(salesTable, SystemDateGet(),SalesUpdate::All, AccountOrder::None, false, false);
        }
    }
    catch(Exception::Error)
    {
        throw error(strFmt('The Sales order %1 could not be posted', salestable.SalesId));
    }
}

Tuesday, 7 May 2019

Upload Doc using X++ for Record

static void UploadDocWorking(Args _args)

{

DocuRef docuRef;

DocuActionArchive archive;

SHP_LinkLogistics _custtable;

str _name;

;



_name=@"c:\SR_SalesInvoice.pdf";

select RecId from _custtable where _custtable.SHP_ConsignmentNumber =="PL-000013";



if (_custtable!=null)

{

ttsBegin;

docuRef.clear();

docuRef.RefRecId = _custtable.RecId;

docuRef.RefTableId = tableNum("SHP_LinkLogistics");

docuRef.RefCompanyId = curext();

docuRef.Name = _name;

docuRef.TypeId = 'File';

docuRef.insert();

archive = new DocuActionArchive();

archive.add(docuRef, _name);

ttsCommit;

}





}

Download SalesInvoice(Delivery Note) using Code X++

//Single Report only we can Print for mutiple Report Code will not Execute),
//Find Bottom Code for multiple Reports.
static void SOI_SaveReportToPDFFromController(Args _args)
{

    SalesInvoiceController  salesInvoiceController;
    SalesInvoiceContract    salesInvoiceContract;
    Args                    args = new Args();
    SrsReportRunImpl        srsReportRun;
    CustInvoiceJour         custInvoiceJour;
    ReportName              reportName = "SalesInvoice.ReportMPL_PL";
    ;

    select firstOnly custInvoiceJour  where custInvoiceJour.InvoiceId == "PL/SI/17/013762";

    args.record(custInvoiceJour);

    salesInvoiceController = new SalesInvoiceController();

    salesInvoiceController.parmReportName(reportName);

    salesInvoiceContract = salesInvoiceController.parmReportContract().parmRdpContract();

    salesInvoiceContract.parmRecordId(custInvoiceJour.RecId); // Record id must be passed otherwise the report will be empty

    salesInvoiceContract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo()); // comment this code if tested in pre release

    salesInvoiceController.parmArgs(args);

    srsReportRun = salesInvoiceController.parmReportRun() as SrsReportRunImpl;

    salesInvoiceController.parmReportRun(srsReportRun);

    salesInvoiceController.parmReportContract().parmPrintSettings().printMediumType(SRSPrintMediumType::File);

    salesInvoiceController.parmReportContract().parmPrintSettings().overwriteFile(true);

    salesInvoiceController.parmReportContract().parmPrintSettings().fileFormat(SRSReportFileFormat::PDF);

    salesInvoiceController.parmReportContract().parmPrintSettings().fileName("c:\\SR_SalesInvoice.pdf");
    salesInvoiceController.parmReportContract().parmReportExecutionInfo(new SrsPrintMgmtExecutionInfo()); //If getting Error like "Parameter executionInfo cannot be null or empty"
    salesInvoiceController.runReport(); 

}

//Multiple Reports Print
static void TestSOPrint(Args _args)
{
    CustInvoiceJour     custInvoiceJour;
    smmParametersTable  parametersTable = smmParametersTable::find();
    str ext;
    str filepath;
    PrintMgmtReportFormatName printMgmtReportFormatName;
    SalesInvoiceContract    SalesInvoiceContract;
    SrsReportRunController  srsReportRunController;
    SRSPrintDestinationSettings printerSettings;
    SalesTable              salestable;

    while select SalesId, SHP_ConsignmentNumber from salestable
            where salestable.SHP_ConsignmentNumber ==  'PL-000023'
        join InvoiceId from custInvoiceJour
            where custInvoiceJour.SalesId == salestable.SalesId

    {
        if (custInvoiceJour)
        {
           
            ext = parametersTable.SHP_InboundFilePath + "\\" + strRem(custInvoiceJour.InvoiceId, '/') + "_" + salestable.SHP_ConsignmentNumber + '.pdf';
            //ext = SRSPrintDestinationSettings::findFileNameType(SRSReportFileFormat::PDF, SRSImageFileFormat::BMP);
            printMgmtReportFormatName = PrintMgmtDocType::construct(PrintMgmtDocumentType::SalesOrderInvoice).getDefaultReportFormat();
            info(strFmt(custInvoiceJour.InvoiceId));
            salesInvoiceContract = new SalesInvoiceContract();
            salesInvoiceContract.parmRecordId(custInvoiceJour.RecId);

            srsReportRunController = new SrsReportRunController();
            srsReportRunController.parmReportName(printMgmtReportFormatName);
            srsReportRunController.parmExecutionMode(SysOperationExecutionMode::Synchronous);
            srsReportRunController.parmShowDialog(false);
            srsReportRunController.parmReportContract().parmRdpContract(salesInvoiceContract);

            printerSettings = srsReportRunController.parmReportContract().parmPrintSettings();
            printerSettings.printMediumType(SRSPrintMediumType::File);
            printerSettings.fileFormat(SRSReportFileFormat::PDF);
            //printerSettings.parmFileName(custInvoiceJour.InvoiceId + filepath);
            printerSettings.parmFileName(ext);
            printerSettings.overwriteFile(true);

            srsReportRunController.runReport();
        }
    }

}