You are on page 1of 11

server static boolean stockSummary(TransDate TransDate ACX_DepotId ACX_ItemType str 250 { #AviFiles boolean InventTrans InventLocation InventTable InventBatch

CompanyInfo InventItemSalesSetup boolean TransDate ret = false ; inventTrans ; warehouse ; inventTable ; inventBatch ; companyInfo ; itemSalesSetup ; begeningOfLoop = true; _today ; toDate, depotId, itemType,

fromDate,

excelTemplateName)

SysExcelApplication SysExcelWorkBooks SysExcelWorkBook SysExcelWorksheets sysExcelWorksheet SysExcelCells SysExcelCell SysExcelFormatCondition

_Application; _Workbooks; _Workbook; _Worksheets; _Worksheet; _Cells; _Cell; _formatCondition;

SysOperationProgress int int64 str 1024 str str 20 _depotName ; real

progress = new SysOperationProgress() ;

_intRow, x ; totalRecords ; sourceFileName, targetFileName, whereClause ; sqlQueryString ; _itemId, _inventSiteId, _inventLocationId, _inventBatchId, _depotId,

_openingQty, _receiptQty, _issueQty, _closingQty ;

SqlStatementExecutePermission Connection Statement ResultSet

perm ;

sqlConnection ; sqlStatement ; sqlResultSet ;

_today = ACX_Base::getServerDate() ;

sourceFileName = CompanyInfo::find().ACX_ExcelReportPath + excelTemplateName ; targetFileName = ACX_UserSetup::find(curUserId()).ACX_ExcelFilePath + curUserId() + excelTemplateName ; WinAPI::copyFile(sourceFileName, targetFileName, true) ;

companyInfo = CompanyInfo::find() ;

whereClause = " where (a.OpeningQty <> 0 or a.ReceiptQty <> 0 or a.IssueQty <> 0) " ;

if (depotId)

whereClause = whereClause + " and c.DepotId = '" + depotId + "'" ;

if (itemType) whereClause = whereClause + " and d.ACX_ItemType = " + int2str(enum2int(itemType)) ;

sqlQueryString = "select rank() OVER (ORDER BY a.ItemId, a.InventSiteId, a.InventLocationId, a.InventBatchId) as TotalRecords, " + "a.ItemId, a.InventSiteId, a.InventLocationId, c.DepotId, c.Name as DepotName, a.InventBatchId, " + "a.OpeningQty, a.ReceiptQty, a.IssueQty, (a.OpeningQty + a.ReceiptQty + a.IssueQty) as ClosingQty " + "from " + "( " + "select distinct a.ItemId, a.InventSiteId, a.InventLocationId, a.InventBatchId, " + "(select isnull(sum(Qty), 0) " + "from InventTrans as aa " + "where aa.ItemId = a.ItemId and aa.InventSiteId = a.InventSiteId and aa.InventLocationId = a.InventLocationId " + "and aa.InventBatchId = a.InventBatchId and aa.DatePhysical < '"+fromDate+"' and aa.DatePhysical >= '01 Jan 2000' " + "and aa.dataareaid = '" + companyInfo.dataAreaId + "'" + ") as OpeningQty, " + "(select isnull(sum(Qty), 0) " + "from InventTrans as aa " + "where aa.ItemId = a.ItemId and aa.InventSiteId = a.InventSiteId and aa.InventLocationId = a.InventLocationId " + "and aa.InventBatchId = a.InventBatchId and aa.DatePhysical between '"+fromDate+"' and '"+toDate+"' " +

"and aa.Qty >= 0 " + "and aa.dataareaid = '" + companyInfo.dataAreaId + "'" + ") as ReceiptQty, " + "(select isnull(sum(Qty), 0) " + "from InventTrans as aa " + "where aa.ItemId = a.ItemId and aa.InventSiteId = a.InventSiteId and aa.InventLocationId = a.InventLocationId " + "and aa.InventBatchId = a.InventBatchId and aa.DatePhysical between '"+fromDate+"' and '"+toDate+"' " + "and aa.Qty < 0 " + "and aa.dataareaid = '" + companyInfo.dataAreaId + "'" + ") as IssueQty " + "from inventTrans as a " + "where a.dataareaid = '" + companyInfo.dataAreaId + "'" + ") as a " + "left outer join InventLocation as b on b.InventLocationId = a.InventLocationId and b.Dataareaid = '" + companyInfo.dataAreaId + "'" + "left outer join ACX_DepotTable as c on c.DepotId = b.ACX_DepotId and c.dataareaid = '" + companyInfo.dataAreaId + "'" + "left outer join InventTable as d on d.ItemId = a.ItemId and d.dataareaid = '" + companyInfo.dataAreaId + "'" + whereClause + " order by TotalRecords desc" ;

sqlConnection = new Connection() ; sqlStatement = sqlConnection.createStatement() ; perm = new SqlStatementExecutePermission(sqlQueryString) ;

perm.objectOnServer() ; perm.assert() ;

sqlResultSet = sqlStatement.executeQuery(sqlQueryString) ;

_Application = SysExcelApplication::construct(); _Workbooks =_Application.workbooks(); _Workbooks.open(targetFileName) ; _Workbook = _Workbooks.item(1); _Worksheets = _Workbook.worksheets(); _Worksheet = _Worksheets.itemFromName('MainData'); //_Worksheet.columns().autoFit() ; _Cells = _Worksheet.cells();

_intRow = 1 ;

while (sqlResultSet.next()) { if (begeningOfLoop) { totalRecords = sqlResultSet.getInt(1) ;

progress.reset() ; progress.setCaption("Exporting data"); progress.setTotal(totalRecords);

begeningOfLoop = false ; } x ++ ; progress.setCount(x, 1); progress.update(true) ;

_itemId _inventSiteId

= sqlResultSet.getString(2) ; = sqlResultSet.getString(3) ;

_inventLocationId = sqlResultSet.getString(4) ; _depotId _depotName _inventBatchId _openingQty _receiptQty _issueQty _closingQty = sqlResultSet.getString(5) ; = sqlResultSet.getString(6) ; = sqlResultSet.getString(7) ; = sqlResultSet.getReal(8) ; = sqlResultSet.getReal(9) ; = sqlResultSet.getReal(10) ; = sqlResultSet.getReal(11) ;

inventTable = InventTable::find(_itemID) ;

_intRow ++ ; _Cell = _Cells.item(_intRow,1); _Cell.value(_itemId);

_Cell = _Cells.item(_intRow,2); _Cell.value(inventTable.ItemName);

_Cell = _Cells.item(_intRow,3); _Cell.value(inventTable.ACX_ItemPrintName);

_Cell = _Cells.item(_intRow,4); _Cell.value(inventTable.Acx_PackingSize);

_Cell = _Cells.item(_intRow,5); _Cell.value(inventTable.ACX_TechnicalName);

_Cell = _Cells.item(_intRow,6); _Cell.value(inventTable.ACX_ChemicalType);

_Cell = _Cells.item(_intRow,7); _Cell.value(inventTable.ACX_ChemicalSubtype);

_Cell = _Cells.item(_intRow,8); _Cell.value(inventTable.ExciseTariffCode_IN);

_Cell = _Cells.item(_intRow,9); _Cell.value(InventItemGroup::find(inventTable.ItemGroupId).Name);

_Cell = _Cells.item(_intRow,10); _Cell.value(inventTable.Dimension[6]);

_Cell = _Cells.item(_intRow,11); _Cell.value(TransferPrice_IN::getSiteTransferPrice(_inventSiteId, _itemId, toDate).Price);

_Cell = _Cells.item(_intRow,12); _Cell.value(inventTable.inventUnitId());

select firstonly itemSalesSetup where itemSalesSetup.ItemId == _itemId ; _Cell = _Cells.item(_intRow,13); _Cell.value(itemSalesSetup.MultipleQty);

_Cell = _Cells.item(_intRow,14); _Cell.value(_openingQty);

_Cell = _Cells.item(_intRow,15); _Cell.value(_receiptQty);

_Cell = _Cells.item(_intRow,16); _Cell.value(-_issueQty);

_Cell = _Cells.item(_intRow,17); _Cell.value(_closingQty);

_Cell = _Cells.item(_intRow,18); _Cell.value(_inventSiteId);

_Cell = _Cells.item(_intRow,19); _Cell.value(_inventLocationId);

_Cell = _Cells.item(_intRow,20); _Cell.value(_inventBatchId);

_Cell = _Cells.item(_intRow,21); _Cell.value(_depotName);

inventBatch = InventBatch::find(_inventBatchId, _itemId) ;

_Cell = _Cells.item(_intRow,22); _Cell.value(inventBatch.prodDate);

_Cell = _Cells.item(_intRow,23); _Cell.value(inventBatch.expDate);

_Cell = _Cells.item(_intRow,24); _Cell.value(inventBatch.MRP);

_Cell = _Cells.item(_intRow,25); _Cell.value(inventBatch.expDate - _today);

_Cell = _Cells.item(_intRow,26);

_Cell.value(enum2str(inventTable.ACX_ItemType));

_Cell = _Cells.item(_intRow,27); _Cell.value(enum2str(inventTable.ACX_DiscontinuedItem));

If (itemSalesSetup.MultipleQty) { _Cell = _Cells.item(_intRow,28); _Cell.value(_openingQty/itemSalesSetup.MultipleQty);

_Cell = _Cells.item(_intRow,29); _Cell.value(_receiptQty/itemSalesSetup.MultipleQty);

_Cell = _Cells.item(_intRow,30); _Cell.value(-_issueQty/itemSalesSetup.MultipleQty);

_Cell = _Cells.item(_intRow,31); _Cell.value(_closingQty/itemSalesSetup.MultipleQty); }

} _Workbook.saved() ; CodeAccessPErmission::revertAssert() ; _Application.visible(true);

return ret ; }

You might also like