Professional Documents
Culture Documents
CompanyInfo InventItemSalesSetup boolean TransDate ret = false ; inventTrans ; warehouse ; inventTable ; inventBatch ; companyInfo ; itemSalesSetup ; begeningOfLoop = true; _today ; toDate, depotId, itemType,
fromDate,
excelTemplateName)
_intRow, x ; totalRecords ; sourceFileName, targetFileName, whereClause ; sqlQueryString ; _itemId, _inventSiteId, _inventLocationId, _inventBatchId, _depotId,
perm ;
_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)
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" ;
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 ;
_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) ;
_Cell = _Cells.item(_intRow,26);
_Cell.value(enum2str(inventTable.ACX_ItemType));
return ret ; }