class ASAPG_DeliveryNoteDialog extends RunBase
{
Dialog dialog;
DialogField dialogCustId;
DialogField dialogSalesId;
DialogRunbase dialogRunbase;
CustAccount custId;
// Str1260 salesId;
NumberSeq numberSeq;
ASAPG_DeliveryNote newDeliveryNumber;
ASAP_DeliveryNoteLines entryFieldsCapture;
ASAP_DeliveryNoteHeader entryCaptureHeader;
ANA_DeliveryListTmp OGSInvCumPackListTmp, OGSInvCumPackListTmpLoc;
ANA_DeliveryListTmpHist OGSInvCumPackListTmpHist1,ANA_DeliveryListTmpHist;
}
----------------
private void buf2BufByName(Common _from, Common _to)
{
DictTable dictTableFrom;
DictTable dictTableTo;
DictField dictFieldFrom;
FieldId fieldIdFrom;
FieldId fieldIdTo;
dictTableFrom = new DictTable(_from.TableId);
dictTableTo = new DictTable(_to.TableId);
fieldIdFrom = dictTableFrom.fieldNext(0);
while (fieldIdFrom && ! isSysId(fieldIdFrom))
{
dictFieldFrom = new DictField(_from.TableId, fieldIdFrom);
if(dictFieldFrom)
{
fieldIdTo = dictTableTo.fieldName2Id(dictFieldFrom.name());
if(fieldIdTo)
_to.(fieldIdTo) = _from.(fieldIdFrom);
}
fieldIdFrom = dictTableFrom.fieldNext(fieldIdFrom);
}
}
-----------
public void CustIdLookup(FormStringControl control)
{
boolean ret;
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tablenum(CustTable), control);
Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange;
;
queryBuildDataSource = query.addDataSource(tablenum(CustTable));
sysTableLookup.addLookupfield(fieldnum(CustTable, AccountNum));
sysTableLookup.addLookupfield(fieldnum(CustTable, party ));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
------------
public Object Dialog()
{
FormRun formRun;
FormStringControl ctrlSalesId, ctrlCustId;
;
super();
dialog =super();
dialog.caption("Delivery note creation ");
dialogCustId = dialog.addField(extendedTypeStr(CustAccount));
dialogSalesId = dialog.addField (extendedTypeStr(Str1260),"Sales ID");
ctrlCustId = dialogCustId.control();
ctrlCustId.registerOverrideMethod(methodStr(FormStringControl,lookup), methodStr(ASAPG_DeliveryNoteDialog, custIdLookup),this);
ctrlSalesId = dialogSalesId.control();
ctrlSalesId.registerOverrideMethod(methodStr(FormStringControl,lookup), methodStr(ASAPG_DeliveryNoteDialog, salesIdLookup),this);
return dialog;
}
------------
public void run()
{
Query query = new Query();//(ANA_DeliveryCumPackList);
QueryRun queryRun;
QueryBuildDataSource salesLineBuildDataSource;
QueryBuildDataSource invemtDimBuildDataSource;
QueryBuildRange salesLineRange;
String50 tempStr;
container c;
SalesLine salesLine, salesLineLocation;
InventTable inventTable;
CustTable custTable;
InventDim inventDim,inventDimOrig, inventDimInterCompany;
TmpFrmIntercompany tmpFrmIntercompany;
boolean recordFound = false;
InventSite inventSite;
SalesTable salesTable;
String20 warehouse;
OGSAmountTxt amountByWarehoseTxt, totalAmountTxt;
InventModelGroup inventModelGroup;
InventModelType inventModelType;
InventSum inventSum;
CompanyInfo statementCompanyInfo;
TmpFrmIntercompany _tmpFrmIntercompany;
int i;
str salesId;
str 255 location1,allLocationIDs,symbolAdd,idsAllLocation;
str 25 a,b,d;
// added for groupy by inventsite
container ConSiteId;
int x;
//end
ASAPG_DeliveryNote previousId;
;
statementCompanyInfo = CompanyInfo::find();
custId = dialogCustId.value();
salesId = dialogSalesId.value();
salesId = strReplace(salesId,";",",");
if (!custId || !salesId )
{
throw error("You must either specify the customer and sales orders or report id!");
}
else
{
custTable = CustTable::find(custId);
salesLineBuildDataSource = query.addDataSource(tableNum(SalesLine));
invemtDimBuildDataSource = salesLineBuildDataSource.addDataSource(tableNum(InventDim));
invemtDimBuildDataSource.addLink(fieldNum(salesLine,InventDimId),fieldNum(inventDim, InventDimId));
//salesLineBuildDataSource.addGroupByField(fieldNum(SalesLine, SalesId));
// salesLineBuildDataSource.addGroupByField(fieldNum(SalesLine, ConfirmedDlv));
salesLineBuildDataSource.addRange(fieldNum(SalesLine,SalesId)).value(salesId);
numberSeq = NumberSeq::newGetNum(SalesParameters::numRefDeliveryNote());
newDeliveryNumber = numberSeq.num();
numberSeq.used();
info(strFmt("New DeliveryNote %1", newDeliveryNumber));
entryFieldsCapture.ReportId = newDeliveryNumber;
entryFieldsCapture.insert();
// Run the query with modified ranges.
queryRun = new QueryRun(query);
OGSInvCumPackListTmp.clear();
while(queryRun.next())
{
salesLine = queryRun.get(tablenum(SalesLine));
inventDim = queryRun.get(tablenum(InventDim));
location1 = '';
inventTable = InventTable::find(salesLine.ItemId);
OGSInvCumPackListTmp.SalesLineRecId = salesLine.RecId;
OGSInvCumPackListTmp.SalesId = salesLine.SalesId;
OGSInvCumPackListTmp.ConfirmedDate = salesLine.ConfirmedDlv;//kain
OGSInvCumPackListTmp.ItemId = salesLine.ItemId;
OGSInvCumPackListTmp.ItemName = inventTable.itemName();
OGSInvCumPackListTmp.NetWeight = inventTable.NetWeight;
OGSInvCumPackListTmp.GrossWeight = inventTable.grossWeight();
OGSInvCumPackListTmp.HSCode = inventTable.OGSHSCode;
OGSInvCumPackListTmp.HSCodeDesc = OGSHSCodeTable::find(inventTable.OGSHSCode).Description;
OGSInvCumPackListTmp.OEMNumber = inventTable.OGSOEMNumber;
OGSInvCumPackListTmp.Origin = inventTable.OGSOrigin;
OGSInvCumPackListTmp.StockNo = inventTable.OGSSetCode;
OGSInvCumPackListTmp.Qty = salesLine.QtyOrdered;
// added for non repeating the salesid in dropdown --start
ttsBegin;
select forUpdate salesTable where salesTable.SalesId == OGSInvCumPackListTmp.SalesId;
{
salesTable.IsGenerated = NoYes::Yes;
salesTable.update();
}
ttsCommit;
// -- end
select sum(PostedValue), sum(PostedQty), sum(PhysicalValue), sum(Received), sum(Deducted)
from inventSum
group by ItemId
where inventSum.ItemId == salesLine.ItemId;
OGSInvCumPackListTmp.UnitPrice = roundup(inventSum.costPricePcs(), 1);
OGSInvCumPackListTmp.Amount = OGSInvCumPackListTmp.UnitPrice * salesLine.QtyOrdered;
OGSInvCumPackListTmp.CustAccount = custTable.AccountNum;
OGSInvCumPackListTmp.CustName = custTable.name();
OGSInvCumPackListTmp.CustomerTeleFax = custTable.telefax();
OGSInvCumPackListTmp.CustomerPhone = custTable.phone();
OGSInvCumPackListTmp.CustomerCountry = custTable.countryName();
OGSInvCumPackListTmp.CustAddress = custTable.address();
OGSInvCumPackListTmp.ReportId = newDeliveryNumber; //d;//rptId;
OGSInvCumPackListTmp.InventSiteId = inventDim.InventSiteId;
OGSInvCumPackListTmp.InventLocationId = inventDim.InventLocationId;
OGSInvCumPackListTmp.UserName = XUserInfo::find(false, curUserId()).name;
//------ group by the inventsite name
ConSiteId = connull();
x = 0;
while select crosscompany salesLineLocation
//group by salesLineLocation.InventDimId
where salesLineLocation.SalesId == salesLine.SalesId
{
while select crossCompany _TmpFrmIntercompany
where _TmpFrmIntercompany .RefRecId ==salesLineLocation.RecId
{
select crosscompany inventDimOrig
where inventDimOrig.inventDimId == salesLineLocation.InventDimId;
select crossCompany Name from inventSite
where inventSite.dataAreaId == _TmpFrmIntercompany .Company;
if(conFind(ConSiteId, inventSite.Name) == 0)
{
location1 = location1 ? location1 +','+ inventSite.Name : inventSite.Name;
x++;
ConSiteId = conIns(ConSiteId, x, inventSite.Name);
}
}
}
OGSInvCumPackListTmp.LocationId = location1;
idsAllLocation += OGSInvCumPackListTmp.LocationId;
symbolAdd = ',';
allLocationIDs += idsAllLocation + symbolAdd;
// Company Info
OGSInvCumPackListTmp.CompanyName = statementCompanyInfo.name();
OGSInvCumPackListTmp.CompanyAddress = statementCompanyInfo.postalAddress().Address;
OGSInvCumPackListTmp.CompanyLogo = FormLetter::companyLogo();
// Company logo
if (conLen(OGSInvCumPackListTmp.CompanyLogo) == 0)
{
OGSInvCumPackListTmp.PrintLogo = NoYes::No;
}
else
{
OGSInvCumPackListTmp.PrintLogo = NoYes::Yes;
}
OGSInvCumPackListTmp.UserName = XUserInfo::find(false, curUserId()).name;
OGSInvCumPackListTmp.insert();
this.buf2BufbyName(OGSInvCumPackListTmp, ANA_DeliveryListTmpHist);
ANA_DeliveryListTmpHist.insert();
}
}
entryCaptureHeader.LocationIds = allLocationIDs;
entryCaptureHeader.ReportId = newDeliveryNumber;
entryCaptureHeader.SalesIds = SalesId;
entryCaptureHeader.CustAccount = custTable.AccountNum;
entryCaptureHeader.CustName = custTable.name();
entryCaptureHeader.CustomerTeleFax = custTable.telefax();
entryCaptureHeader.CustomerPhone = custTable.phone();
entryCaptureHeader.CustomerCountry = custTable.countryName();
entryCaptureHeader.CustAddress = custTable.address();
entryCaptureHeader.UserName = XUserInfo::find(false, curUserId()).name;
entryCaptureHeader.insert();
}
----------------
public void salesIdLookup(FormStringControl SalesOrderLookup)
{
Query query = new Query(queryStr(ANA_OGSOpenOrders));
QueryBuildDataSource qbdsSO;
container cnt;
SysLookupMultiSelectGrid SysLookupMultiSelectGrid;
;
if(dialogCustId.value())
{
query.dataSourceTable(tableNum(SalesTable)).addRange(fieldNum(SalesTable, CustAccount)).value(dialogCustId.value());
if (SalesOrderLookup != null)
{
SysLookupMultiSelectGrid::lookup(query, SalesOrderLookup, SalesOrderLookup, cnt);
}
}
}
-------
public static void main(Args args)
{
ASAPG_DeliveryNoteDialog deliveryNoteDialog = new ASAPG_DeliveryNoteDialog();
;
deliveryNoteDialog.prompt();
deliveryNoteDialog.run();
}
No comments:
Post a Comment