jueves, 8 de noviembre de 2012

Crear referencias de secuencias numericas

/////////////////////////////////////////////////////7calse  NumberSeqModuleEscenarios
public class NumberSeqModuleEscenarios extends NumberSeqApplicationModule
{

}


protected void loadModule() //sobreescribir
{
    NumberSeqDatatype datatype = NumberSeqDatatype::construct();
    ;

    /* Setup application numbers */

    datatype.parmDatatypeId(extendedtypenum(ProdOptEscenario));//crear previamente el extend
    datatype.parmReferenceHelp(literalstr("Sequencia para los escenarios"));
    datatype.parmWizardIsContinuous(true);
    datatype.parmWizardIsManual(NoYes::No);
    datatype.parmWizardIsChangeDownAllowed(NoYes::No);
    datatype.parmWizardIsChangeUpAllowed(NoYes::No);
    datatype.parmWizardHighest(999999);
    datatype.parmSortField(1);

    datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);
    this.create(datatype);


}


public NumberSeqModule numberSeqModule() //sobreescribir
{
    return NumberSeqModule::Prod;
}
//////////////////////////////////////////////////////////////////////7termina clase NumberSeqModuleEscenarios
///////////////////agregar la referencia
static void CrearSequencia(Args _args)///job

{

GsNumberSeqModuleEscenarios obj = new GsNumberSeqModuleEscenarios();

obj.createReferencesForScope();

obj.load();

}



///////////////////////////////////////////////////
static void GsTestSequencia(Args _args)
{
    ;       NumberSeq::newGetNum(NumberSeqReference::findReference(extendedTypeNum(ProdOptEscenario)),true).num();
}
////////////////////////////


martes, 9 de octubre de 2012

FASTFIRSTROW" is not a recognized table hints option

para arreglar este error utilice
en el Microsoft Dynamics AX 2012 Management Shell
poner axutil.exe schema /config:standard


martes, 17 de julio de 2012

Leer un CSV Dynamics AX 2012 Con ADO


static void Job57(Args _args)
{
 
    System.Data.Common.DbConnection connection;
    System.Data.Common.DbCommand command;
    System.Data.SqlClient.SqlDataReader dataReader;
    System.Data.Common.DbProviderFactory factory=System.Data.Common.DbProviderFactories::GetFactory("System.Data.OleDb");
    int contar;
    ;
    new InteropPermission( InteropKind::ClrInterop ).assert();


    connection=factory.CreateConnection();
    connection.set_ConnectionString("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\AbinsaCobranza\\;Extended Properties=\"text;HDR=Yes;FMT=Delimited\"");

    command=factory.CreateCommand();
    command.set_CommandText("select * from BANREGIO.csv");
    command.set_Connection(connection);

    //executing SQL-query
    try
    {
        //open within catch, so that the object can correcly be disposed
        //all these try-catch are quite ennoying in X++, but this because
        //X++ does not know finally...
        connection.Open();
        try
        {
            //All code after the open must be in a seperate catch, so that the
            //open connection-object can correcly be disposed.
            dataReader = command.ExecuteReader();

            while(dataReader.Read())
            {
                if(contar>=10)
                {
                   // contar=dataReader.get_FieldCount();
                    //use the named columns instead of index.
                   info(int2str(contar));
                   print dataReader.get_Item(6);
                    pause;
                }
               
               
                contar++;

            }
            //Dispose ADO.Net objects ASAP
            dataReader.Dispose();
        }
        catch //should be more precise in a real-world application
        {
            //if exception occures while reading, DataReader need to be
            info(CLRInterop::getLastException().ToString());
            dataReader.Dispose();
        }
        catch(Exception::CLRError) //CLR exception need to be handled explicitely
        //otherwise they might be 'lost'. Happy copy&pasteing
        {
            //if exception occures while reading, DataReader need to be
            info(CLRInterop::getLastException().ToString());
            dataReader.Dispose();
        }
        connection.Dispose();
    }
    catch //should be more precise in a real-world application
    {
        info(CLRInterop::getLastException().ToString());
        connection.Dispose(); //disposing connection if it fails before opening it
    }
    catch(Exception::CLRError)
    {
        info(CLRInterop::getLastException().ToString());
        connection.Dispose();
    }
    command.Dispose();
    CodeAccessPermission::revertAssert();


}

lunes, 9 de julio de 2012

Crear Cliente AX 2012


CustCustomerService CustCustomerService;

    CustCustomer CustCustomer;
    //CustCustomer_DirParty CustCustomer_DirParty;
    CustCustomer_DirParty_DirOrganization dirOrg;
    CustCustomer_DirPartyPostalAddressView CustCustomer_DirPartyPostalAddressView;
    CustCustomer_DirPartyContactInfoView CustCustomer_DirPartyContactInfoView;


    CustCustomer_CustTable CustCustomer_CustTable;
;
    ////////////////////////////////////////////////////////////////7
    CustCustomerService= CustCustomerService::construct();
    CustCustomer=new CustCustomer();

    CustCustomer_CustTable=new CustCustomer_CustTable();
    dirOrg = new CustCustomer_DirParty_DirOrganization();
    ////////////////////////////////////////////////////////////////////////7
    CustCustomer_CustTable.parmAccountNum("0027");
    CustCustomer_CustTable.parmCustGroup("Empleados");
    CustCustomer_CustTable.parmGsCueCobClaveReferenciada("1234512333");
    CustCustomer_CustTable.parmTaxGroup("IVA 16");
    //CustCustomer_DirParty=new CustCustomer_DirParty();

   // CustCustomer_CustTable.parmAccountNum("prue1");


    dirOrg.parmName("MyCustomerName_OrgName");
    dirOrg.parmLanguageId("es-mx");
    CustCustomer_CustTable.createDirParty().add(dirOrg);
 
    CustCustomer_DirPartyPostalAddressView=dirOrg.createDirPartyPostalAddressView().addNew();
    CustCustomer_DirPartyPostalAddressView.parmStreet("De la villa");
    CustCustomer_DirPartyPostalAddressView.parmCountryRegionId("Mex");
    CustCustomer_DirPartyPostalAddressView.parmRoles("Business");
   
    CustCustomer_DirPartyContactInfoView=dirOrg.createDirPartyContactInfoView().addNew();
    CustCustomer_DirPartyContactInfoView.parmLocationName("Telefono");
    CustCustomer_DirPartyContactInfoView.parmLocator("000000000");
 
    CustCustomer_DirPartyContactInfoView.parmType(LogisticsElectronicAddressMethodType::Phone);
    CustCustomer_DirPartyContactInfoView.parmRoles("Business");
   
 
    CustCustomer.createCustTable().add(CustCustomer_CustTable);

    CustCustomerService.create(CustCustomer);






}

jueves, 7 de junio de 2012

Crear Diario de inv


static void TestCrearDiarioInventario(Args _args)
{
    GsInventJournalTService GsInventJournalTService;
    GsInventJournalT GsInventJournalT;


    GsInventJournalT_InventJournalTable_1 GsInventJournalT_InventJournalTable_1;
    GsInventJournalT_InventJournalTrans_1 GsInventJournalT_InventJournalTrans_1;
 
    GsInventJournalT_InventDim_1 GsInventJournalT_InventDim_1;

    AifMultiTypeAccount AifMultiTypeAccount;

    AifDimensionAttributeValueSet AifDimensionAttributeValueSet= new AifDimensionAttributeValueSet();
    AifDimensionAttributeValue          dimensionAttributeValue;
    AfStronglyTypedDataContainerList    dimensionAttributeValues;
    #AifDimensionDataContainerTypes
    AifLedgerAccount AifLedgerAccount;
    ;
 
   GsInventJournalTService=GsInventJournalTService::construct();
   GsInventJournalT=new GsInventJournalT();
   GsInventJournalT.createInventJournalTable_1().addNew();
   GsInventJournalT_InventJournalTable_1=GsInventJournalT.parmInventJournalTable_1().addNew();
 
    GsInventJournalT_InventJournalTable_1.parmJournalNameId("Mov");
 
    GsInventJournalT_InventJournalTable_1.createInventJournalTrans_1();
    GsInventJournalT_InventJournalTrans_1=GsInventJournalT_InventJournalTable_1.parmInventJournalTrans_1().addNew();
 
    GsInventJournalT_InventJournalTrans_1.parmItemId("CIC00731400A36");
    GsInventJournalT_InventJournalTrans_1.parmQty(1);
    GsInventJournalT_InventJournalTrans_1.parmCostPrice(100);
    GsInventJournalT_InventJournalTrans_1.parmCostAmount(100);
 
    AifLedgerAccount=new AifLedgerAccount();
    AifLedgerAccount.parmDisplayValue("51100001");
    AifLedgerAccount.parmMainAccount("51100001");
 
    GsInventJournalT_InventJournalTrans_1.parmLedgerDimension(AifLedgerAccount);
 
    dimensionAttributeValues = new AfStronglyTypedDataContainerList(#AifDimensionAttributeValue);

    dimensionAttributeValue = dimensionAttributeValues.addNew();
    dimensionAttributeValue.parmName("Sucursal");
    dimensionAttributeValue.parmValue("QRO");

    dimensionAttributeValue = dimensionAttributeValues.addNew();
    dimensionAttributeValue.parmName("División");
    dimensionAttributeValue.parmValue("ABINSA");
    AifDimensionAttributeValueSet.parmValues(dimensionAttributeValues);
    GsInventJournalT_InventJournalTrans_1.parmDefaultDimension(AifDimensionAttributeValueSet);
 
    GsInventJournalT_InventJournalTrans_1.createInventDim_1();
    GsInventJournalT_InventDim_1=GsInventJournalT_InventJournalTrans_1.parmInventDim_1().addNew();
 
    GsInventJournalT_InventDim_1.parmInventSizeId("GM");
    GsInventJournalT_InventDim_1.parmInventColorId("110");
    GsInventJournalT_InventDim_1.parmInventSiteId("130");
    GsInventJournalT_InventDim_1.parmInventLocationId("MP 130");
    GsInventJournalT_InventDim_1.parmInventBatchId("1");
    GsInventJournalT_InventDim_1.parmWMSLocationId("E1");
 
 
 
    GsInventJournalTService.create(GsInventJournalT);
 
 
 
 
 
 

}

miércoles, 6 de junio de 2012

Mostrar Código de Barras Horizontal



static container MostrarBarCodeHorizontal()
{
System.Drawing.Bitmap   BarcodeBitmap;

System.Drawing.Graphics BarcodeGraphics;

int     dx=350;
int     dy=30;

str     barcodetxt;
Image   BarcodeImage;

System.Drawing.Pen                TxtPen;
System.Drawing.Brush              TxtBrush;

System.Drawing.Brush              DrawBrush;

System.Drawing.StringFormat       StringFormat;
System.Drawing.StringAlignment    StringAlignment;

System.Drawing.Font BarcodeFont = new System.Drawing.Font('BC C128 Medium',22,System.Drawing.FontStyle::Regular);

Int64             BarcodeBitmapPtr;
//BarcodeCode39    MyBarcode = BarcodeCode39::construct();
BarcodeCode128 MyBarcode=BarcodeCode128::construct();



    ;

BarcodeImage = new Image();

BarcodeBitmap = new System.Drawing.Bitmap(dx,dy);
BarcodeGraphics = System.Drawing.Graphics::FromImage(BarcodeBitmap);
//BarcodeGraphics.set_PixelOffsetMode(5);
barcodetxt="12123456789012omar98";
MyBarCode.string(true,barcodetxt);
MyBarCode.encode();
barcodetxt=MyBarCode.barcodeStr();

// clear canvas
DrawBrush = System.Drawing.Brushes::get_White();
BarcodeGraphics.FillRectangle(DrawBrush,0,0,any2int(dx),any2int(dy));

// set barcode text
TxtBrush = System.Drawing.Brushes::get_Black();
TxtPen = new System.Drawing.Pen(TxtBrush);

// set text alignment
StringFormat = new System.Drawing.StringFormat();
StringAlignment = System.Drawing.StringAlignment::Center;
StringFormat.set_Alignment(StringAlignment);
StringFormat.set_LineAlignment(StringAlignment);

// init rotation
//BarcodeGraphics.TranslateTransform(any2int(dx),0);
//BarcodeGraphics.RotateTransform(90);

// draw text
BarcodeGraphics.DrawString(barcodetxt, BarcodeFont,TxtBrush, 0 , 0);

// transfer image to Ax

BarcodeBitmapPtr=BarcodeBitmap.GetHbitmap();
BarcodeImage.importBitmap(BarcodeBitmapPtr);


BarcodeImage.resize(dx,dy+10,InterpolationMode::InterpolationModeNearestNeighbor);
//BarcodeImage.saveImage("c:\\prueba.bmp");



return BarcodeImage.getData();
}

Mostrar Código de Barras Vertical



static container MostrarBarCodeVertical()
{
System.Drawing.Bitmap   BarcodeBitmap;
System.Drawing.Graphics BarcodeGraphics;

int     dx=30;
int     dy=300;

str     barcodetxt;
Image   BarcodeImage;

System.Drawing.Pen                TxtPen;
System.Drawing.Brush              TxtBrush;

System.Drawing.Brush              DrawBrush;

System.Drawing.StringFormat       StringFormat;
System.Drawing.StringAlignment    StringAlignment;

System.Drawing.Font BarcodeFont = new System.Drawing.Font('BC C128 Medium',22,System.Drawing.FontStyle::Regular);

Int64             BarcodeBitmapPtr;
//BarcodeCode39    MyBarcode = BarcodeCode39::construct();
BarcodeCode128 MyBarcode=BarcodeCode128::construct();

    ;

BarcodeImage = new Image();

BarcodeBitmap = new System.Drawing.Bitmap(dx,dy);
BarcodeGraphics = System.Drawing.Graphics::FromImage(BarcodeBitmap);

barcodetxt="123456789012345678901234567890";
MyBarCode.string(true,barcodetxt);
MyBarCode.encode();
barcodetxt=MyBarCode.barcodeStr();

// clear canvas
DrawBrush = System.Drawing.Brushes::get_White();
BarcodeGraphics.FillRectangle(DrawBrush,0,0,any2int(dx),any2int(dy));

// set barcode text
TxtBrush = System.Drawing.Brushes::get_Black();
TxtPen = new System.Drawing.Pen(TxtBrush);

// set text alignment
StringFormat = new System.Drawing.StringFormat();
StringAlignment = System.Drawing.StringAlignment::Center;
StringFormat.set_Alignment(StringAlignment);
StringFormat.set_LineAlignment(StringAlignment);

// init rotation
BarcodeGraphics.TranslateTransform(any2int(dx),0);
BarcodeGraphics.RotateTransform(90);
  //  BarcodeGraphics.RotateTransform(

// draw text
BarcodeGraphics.DrawString(barcodetxt, BarcodeFont,TxtBrush, 0,0);

// transfer image to Ax
BarcodeBitmapPtr=BarcodeBitmap.GetHbitmap();
BarcodeImage.importBitmap(BarcodeBitmapPtr);

BarcodeImage.resize(dx+10,dy,InterpolationMode::InterpolationModeNearestNeighbor);
//BarcodeImage.saveImage("c:\\prueba.bmp");
return BarcodeImage.getData();
}

martes, 8 de mayo de 2012

Obtener Dimensiones Ax 2012


  container dimensionValueIn;
   
    ;
   

print AxdDimensionUtil::getMultiTypeAccountId(enumName2Id("LedgerJournalACType"),0,["ABTECH-MTY-Produccion","11161004"]);
print AxdDimensionUtil::getDimensionAttributeValueSetId([2,"División","ABTECH","Sucursal","MTY"]);
  dimensionValueIn=AxdDimensionUtil::getDimensionAttributeValueSetValue(AxdDimensionUtil::getDimensionAttributeValueSetId([2,"División","ABTECH","Sucursal","MTY"]));
 
   pause;

miércoles, 28 de marzo de 2012

Crear y leer Archivos Dynamics ax 2012

static void Job_File_IO_TextIo_Write_Read(Args _args)
{
    TextIo txIoRead,
         txIoWrite;
    FileIOPermission fioPermission;
    container containFromRead;
    int xx,
        iConLength;
    str sTempPath,
        sFileName = "Test_File_IO.txt",
        sOneRecord;
    ;
    // Get the temporary path.
    sTempPath = WINAPI::getTempPath();
    info("File is at: " + sTempPath + sFileName);

    // Assert permission.
    fioPermission = new FileIOPermission
        (sTempPath + sFileName ,"RW");
    fioPermission.assert();
 
    // If the test file already exists, delete it.
    if (WINAPI::fileExists(sFileName))
    {
        WINAPI::deleteFile(sTempPath + sFileName);
    }
    
    // Open a test file for writing.
    // "W" mode overwrites existing content, or creates the file.
    txIoWrite = new TextIo( sTempPath + sFileName ,"W");

    // Write records to the file.
    txIoWrite.write("Hello        World.");
    txIoWrite.write("The sky is blue.");
    txIoWrite.write("");
    txIoWrite.write("// EOFile");

    // Close the test file.
    txIoRead = null;

    // Open the same file for reading.
    txIoRead = new TextIo(sTempPath + sFileName ,"R");
    // Read the entire file into a container.
    containFromRead = txIoRead.read();

    // Loop through the container of file records.
    while (containFromRead)
    {
        sOneRecord = "";
        iConLength = conLen(containFromRead);
        // Loop through the token in the current record.
        for (xx=1; xx <= iConLength; xx++)
        {
            if (xx > 1) sOneRecord += " ";
            sOneRecord += conPeek(containFromRead ,xx);
        }
        info(sOneRecord);

        // Read the next record from the container.
        containFromRead = txIoRead.read();
    }

    // Close the test file.
    txIoRead = null;
    // Delete the test file.
    WINAPI::deleteFile(sTempPath + sFileName);

    // revertAssert is not really necessary here,
    // because the job (or method) is ending.
    CodeAccessPermission::revertAssert();
}
Fuente: http://msdn.microsoft.com/en-us/library/cc967403.aspx

martes, 13 de marzo de 2012

Crear Asiento Ax 2012

 LedgerVoucher   lv;
    NumberSeq       numberSeq;
   currencyExchangeHelper currencyExchangeHelper ;
    LedgerVoucherTransObject LedgerVoucherTransObject;
   LedgerVoucherObject LedgerVoucherObject;
    ;
    currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::current(), today());
    ttsBegin;
    numberSeq = NumberSeq::newGetVoucher(LedgerParameters::numRefLedgerExchAdjVoucher());

    lv = LedgerVoucher::newLedgerPost(
        DetailSummary::Detail,
        SysModule::Ledger,
        numberSeq.parmNumberSequenceCode());

    LedgerVoucherObject= LedgerVoucherObject::newVoucher(numberSeq.voucher(),today(), SysModule::Ledger,LedgerTransType::Invent);
    lv.addVoucher(LedgerVoucherObject);

    LedgerVoucherTransObject=LedgerVoucherTransObject::newTransactionAmountDefault(
            LedgerVoucherObject,//("ABI-000437"),
            LedgerPostingType::LedgerJournal,
            DimensionDefaultingService::serviceCreateLedgerDimension(5637157573),           // Ledger account
            Ledger::find(Ledger::current()).AccountingCurrency,
            2004,              // Amount
            currencyExchangeHelper);
     lv.addTrans(LedgerVoucherTransObject);

     LedgerVoucherTransObject=LedgerVoucherTransObject::newTransactionAmountDefault(
            LedgerVoucherObject,//("ABI-000437"),
            LedgerPostingType::LedgerJournal,
            DimensionDefaultingService::serviceCreateLedgerDimension(5637158025),           // Ledger account
            Ledger::find(Ledger::current()).AccountingCurrency,
            -2004,              // Amount
            currencyExchangeHelper);
     lv.addTrans(LedgerVoucherTransObject);
    lv.end();
    ttsCommit

jueves, 9 de febrero de 2012

AifQueueManager Manual

static void AIFProcessing(Args _args)
{
AifOutboundProcessingService outboundService = new AifOutBoundProcessingService();
AifGatewaySendService sendService = new AifGatewaySendService();
;
outboundService.run();
sendService.run();
}