30 Temmuz 2008 Çarşamba

Expand number of columns dynamically in report - Fetch example

// You should create tmp tables named TmpTotalTable and TmpTotalHeader and extended data type that has maximum number of elements. Then create a field in tmp tables type of extended data type.

public boolean fetch()
{
TmpTotalTable tmpsum,totalsum,totalsumym;
CustInvoiceJour custinvoicejour, custinvoicejourgr;
custGroup custgroup;
custTable custTable;

iNt i,j,offsetym,lastcol;
ReportStringControl headerfield;
ReportTextControl space;
ReportRealControl sumfield;
ReportRealControl percentfield;

Amount totalamountcur , totalamountYTL, totalamountEUR;

;



if (element.prompt())
{
sums.setTmpdata(tmpsum);
headers.clear();

while select currencycode from custinvoicejour
group by currencycode
where custinvoicejour.InvoiceDate >= datefrom
&& custinvoicejour.InvoiceDate <= dateto
{


i++;
headers.TotalName[i] = custinvoicejour.CurrencyCode;

headerfield = headersection.addStringControl(tablenum(TmpTotalHeader),fieldid2ext(fieldnum(TmpTotalHeader,TotalName),i));
headerfield.alignment(Alignment::Right);
headerfield.width(16,units::Char);
sumfield = sumsection.addRealControl(tablenum(TmpTotalTable),fieldid2ext(fieldnum(TmpTotalTable,Total),i));
sumfield.width(16,units::Char);
sumfield.sumAll(true);

}
colcount = i;
offsetym = i+1;

headers.insert();
this.send(headers);
headersection.executeSection();


while select custgroup from custinvoicejourgr
group by custgroup
where custinvoicejourgr.InvoiceDate >= datefrom
&& custinvoicejourgr.InvoiceDate <= dateto
{
sums.clear();
totalamountcur = 0;
totalamountytl = 0;
totalamounteur = 0;
sums.MaddeGrubu = custinvoicejourgr.CustGroup;
for (i=1; i<=colcount ; i++)
{
totalamountcur = 0;
select
sum(InvoiceAmount) , sum(InvoiceAmountMST), sum(SumTax), sum(SumTaxMST)
from custinvoicejour
where
custinvoicejour.CustGroup == custinvoicejourgr.CustGroup
&& custinvoicejour.CurrencyCode == headers.TotalName[i]
&& custinvoicejour.InvoiceDate >=datefrom
&& custinvoicejour.InvoiceDate <=dateto ;
{
totalamountcur += custinvoicejour.InvoiceAmount - custinvoicejour.SumTax;
total[i] +=totalamountcur;
}
sums.Total[i] = totalamountcur;

}
sums.insert();

}

sums.clear();
sums.totalname ="TOPLAM";
for (i=1; i<=colcount ; i++)
{
sums.Total[i] = total[i];
}
sums.insert();

while select sums
{
this.send(sums);
sumsection.executeSection();

}

}
return true;
}

Excel Export

static void exportVendorToExcelTEST1(Args _args)
{

SysExcelApplication SysExcelApplication;
SysExcelWorksheet SysExcelWorksheet;
SysExcelWorksheets SysExcelWorksheets;
SysExcelWorkbooks SysExcelWorkbooks;
SysExcelWorkbook SysExcelWorkbook;
SysExcelRange SysExcelRange;
SysExcelCell SysExcelCell;
SysExcelCells SysExcelCells;
COMVariant COMVariant1;
Kriterler kriterler;
VendTable vtab;
Dialog dialog = new Dialog();
DialogField dflItem = dialog.addField(typeid(VendAccount));

#excel
;

while select vtab
where vtab.AccountNum like "S0000*"
{
try
{
sysExcelApplication = SysExcelApplication::construct();
sysExcelApplicatioN.displayAlerts(FALSE);
sysExcelApplication.visible(FALSE);
sysExcelWorkbooks = sysExcelApplication.workbooks();

// for filename
sysExcelApplication.workbooks().open("C:\\"+vtab.AccountNum+".XLS");
sysExcelWorkbook = sysExcelApplication.workbooks().item(1);
SysExcelWorksheets = sysExcelWorkbook.worksheets();
SysExcelWorksheet = SysExcelWorksheets.itemFromNum(1);

SysExcelRange = SysExcelWorksheet.cells().range(#ExcelTotalRange);

SysExcelCell = SysExcelWorksheet.cells().item(1,1);
SysExcelCell.value(systemdateget());

SysExcelCell = SysExcelWorksheet.cells().item(2,2);
SysExcelCell.value(vtab.AccountNum);

sysExcelApplication.save();
sysExcelApplication.quit();
}
catch (exception::Error)
{
}
}


}

Explode BOM

//The function below explodes BOM to the lowest level.
//You should create PlanBOM table before executing this function or change the code according to your target.

void explodeBOM()
{
ETGProdPlanBOMTable PlanBOM;


void qtyexplode(ETGProdPlanId _planid, ItemId _ItemId,Qty _qtySerie,int _level)
{
BOM BOMd;
InventTable itabled;
BOMVersion BOMVersiond;
;

select firstonly BOMVersiond
where BOMVersiond.ItemId == _itemid
&& BOMVersiond.Active
&& BOMVersiond.FromDate <= systemdateget()
&& (!BOMVersiond.ToDate || BOMVersiond.ToDate >= systemdateget());

if (BOMVersiond.RecId)
{
While select BOMd
where BOMd.BOMId == BOMVersiond.BOMId
join itabled
where BOMd.ItemId == itabled.ItemId
{

if (itabled.ItemType == ItemType::Item)
{
PlanBOM.clear();
PlanBOM.ItemId = BOMd.ItemId;
PlanBOM.RefItemId = BOMVersiond.ItemId;
PlanBOM.Qty = BOMd.BOMQty / BOMd.BOMQtySerie * _qtyserie;
PlanBOM.PlanId = _planid;
PlanBOM.Level = _level;
PlanBOM.insert();

}
else if (itabled.ItemType == ItemType::BOM)
{
qtyexplode(_planid, BOMd.ItemId, BOMd.BOMQty/BOMd.BOMQtySerie * _qtySerie, _level+1);
}
}

}
}
;

delete_from PlanBOM
where PlanBOM.PlanId == this.ProdPlanrec().PlanId;
qtyexplode(this.ProdPlanrec().PlanId, this.ProdPlanrec().ItemId,this.ProdPlanrec().Qty,1);





}

4 Haziran 2008 Çarşamba

Document Management - Opening file from code for a spesific rec.

void showDocument()
{
args args;
docuref docuref;
;
args = new args();

docuRef = docuref::find(salesTable.dataAreaId,tablenum(SalesTable),salesTable.RecId,today());
args.record(docuRef);
args.parmEnumType(enumnum(Docucode));
args.parmEnum(Docucode::Open);
docuaction::main(args);
}

http://dax-lessons.spaces.live.com/Blog/cns!D89D0800DE72FCD1!123.entry