static void GH_excel_CustomerEmailUpload(Args _args)
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
Filename filename;
str filePath, fileNameOnly;
Dialog dialog;
DialogField dialogFileName;
int row;
container record, roles;
GOD_VacationBalances vacationBalances;
HcmPersonnelNumberId personnelNumber;
real vacationBalance;
TransDate upToDate;
DirPartyContactInfoView contactView;
CustTable CustTable;
DirParty dirParty;
DirPartyRecId partyRecId;
CustAccount _custAccount;
LogisticsPostalAddress address;
DirPartyPostalAddressView addressView;
;
dialog = new Dialog();
dialog.caption("Pick excel file");
dialogFileName = dialog.addField(extendedTypeStr(FilenameOpen), "Enter excel file", "Browse excel file");
if(!dialog.run())
return;
filename = dialogFileName.value();
[filePath,fileNameOnly] = fileNameSplit(filename);
application = SysExcelApplication::construct();
workbooks = application.workbooks();
try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error(strFmt("Filename %1 cannot be blank.",filename));
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
row = 1;
do
{
try
{
row++;
_custAccount = cells.item(row, 1).value().bStr();
partyRecId = CustTable::find(_custAccount ).Party;
DirParty = DirParty::constructFromPartyRecId(partyRecId );
contactView.clear();
if(strLRTrim(cells.item(row, 1).value().bStr())!= "")
{
contactView.LocationName = "Email-SOA";
contactView.Locator = strLRTrim(cells.item(row, 2).value().bStr());
contactView.Type = LogisticsElectronicAddressMethodType::Email;
contactView.Party = partyRecId;
contactView.IsPrimary = NoYes::No;
DirParty = DirParty::constructFromPartyRecId(CustTable.Party);
roles = [LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Home).RecId];
ttsBegin;
dirParty.createOrUpdateContactInfo(contactView,roles);
ttsCommit;
}
else
{
warning(strFmt("Row %1 not updated.", row));
}
}
catch
{
error(strfmt("Row %1 not updated.", row));
}
type = cells.item(row+1, 1).value().variantType();
}
while (type != COMVariantType::VT_EMPTY);
workbook.saved(true);
application.visible(false);
application.quit();
info("Excel uploaded successfully");
}
Tuesday, October 1, 2019
Saturday, September 28, 2019
Sales Price WMS
Public void God_SalesPriceWMSChangeQty()
{
InventTable inventTableLoc;
God_AlternativeItems _God_AlternativeItems;
Amount4decimal amount,amount1,factorconv;
CustParameters _custparamenter;
SalesTable SalesTableLoc;
CustGroup CustGroup;
CustTable CustTable;
real margin, totalamount;
InventTrans inventtrans;
InventSum inventsum;
int i=0;
boolean flag =true;
InventTransOrigin InventTransOrigin;
// Sample Sales Order Calculation
select SalesTableLoc
where SalesTableLoc.SalesId == this.SalesId
&& SalesTableLoc.God_SampleType == "SAMPLE ORDER";
{
if(SalesTableLoc)
{
// select god_marginsamplerate
// from _custparameters;
if(!amount)
amount = this.GOD_averageCostPriceUnitWMSChangeQty(this.ItemID);
if(!amount)
{
amount = InventTableModule::find(this.ItemId,ModuleInventPurchSales::Invent).Price;
amount = UnitOfMeasureConverter::convert(amount,
UnitOfMeasure::unitOfMeasureIdBySymbol(this.SalesUnit),
UnitOfMeasure::unitOfMeasureIdBySymbol(InventTableModule::find(this.ItemId,ModuleInventPurchSales::Invent).UnitId),NoYes::Yes,
InventTable::itemProduct(this.ItemId),NoYes::No,NoYes::No);
}
margin = amount * CustParameters::find().god_marginsamplerate/100;
totalamount = amount + margin;
this.salesprice = round(totalamount,0.01);
this.lineamount = this.calclineamount();
}
}
// Subsidiary Sales CAlculation
select SalesTableLoc
where SalesTableLoc.SalesId == this.SalesId
&& SalesTableLoc.God_subsidiarySales == NoYes::Yes;
{
if(SalesTableLoc)
{
while select inventtrans order by inventtrans.DateFinancial desc
where inventtrans.ItemId == this.ItemId
&& inventtrans.StatusReceipt == StatusReceipt::Purchased
join InventTransOrigin
where InventTransOrigin.RecId == inventtrans.InventTransOrigin
&& InventTransOrigin.ReferenceCategory == InventTransType::Purch
{
if(inventtrans)
{
i++;
if(i == 1)
{
amount= round(inventTrans.CostValue() / inventtrans.Qty,0.01);
amount = UnitOfMeasureConverter::convert(amount,
UnitOfMeasure::unitOfMeasureIdBySymbol(this.SalesUnit),
UnitOfMeasure::unitOfMeasureIdBySymbol(InventTableModule::find(this.ItemId,ModuleInventPurchSales::Invent).UnitId),NoYes::Yes,
InventTable::itemProduct(this.ItemId),NoYes::No);
break;
}
}
}
if(!amount)
amount = this.GOD_averageCostPriceUnitWMSChangeQty(this.ItemID); //amount = round(inventsum::find(salesline.ItemId,SalesLine.InventDimId).averageCostPrice(),0.01);
if(!amount)
{
amount = InventTableModule::find(this.ItemId,ModuleInventPurchSales::Invent).Price;
amount = UnitOfMeasureConverter::convert(amount,
UnitOfMeasure::unitOfMeasureIdBySymbol(this.SalesUnit),
UnitOfMeasure::unitOfMeasureIdBySymbol(InventTableModule::find(this.ItemId,ModuleInventPurchSales::Invent).UnitId),NoYes::Yes,
InventTable::itemProduct(this.ItemId),NoYes::No);
}
margin = amount * CustGroup::find(this.CustGroup).GOD_MarkupPercentage/100;
totalamount = amount + margin;
this.salesprice = round(totalamount,0.01);
// salesquotationline.lineamount = salesquotationline.calclineamount();
this.lineamount = this.calclineamount();
}
}
// End Code
}
{
InventTable inventTableLoc;
God_AlternativeItems _God_AlternativeItems;
Amount4decimal amount,amount1,factorconv;
CustParameters _custparamenter;
SalesTable SalesTableLoc;
CustGroup CustGroup;
CustTable CustTable;
real margin, totalamount;
InventTrans inventtrans;
InventSum inventsum;
int i=0;
boolean flag =true;
InventTransOrigin InventTransOrigin;
// Sample Sales Order Calculation
select SalesTableLoc
where SalesTableLoc.SalesId == this.SalesId
&& SalesTableLoc.God_SampleType == "SAMPLE ORDER";
{
if(SalesTableLoc)
{
// select god_marginsamplerate
// from _custparameters;
if(!amount)
amount = this.GOD_averageCostPriceUnitWMSChangeQty(this.ItemID);
if(!amount)
{
amount = InventTableModule::find(this.ItemId,ModuleInventPurchSales::Invent).Price;
amount = UnitOfMeasureConverter::convert(amount,
UnitOfMeasure::unitOfMeasureIdBySymbol(this.SalesUnit),
UnitOfMeasure::unitOfMeasureIdBySymbol(InventTableModule::find(this.ItemId,ModuleInventPurchSales::Invent).UnitId),NoYes::Yes,
InventTable::itemProduct(this.ItemId),NoYes::No,NoYes::No);
}
margin = amount * CustParameters::find().god_marginsamplerate/100;
totalamount = amount + margin;
this.salesprice = round(totalamount,0.01);
this.lineamount = this.calclineamount();
}
}
// Subsidiary Sales CAlculation
select SalesTableLoc
where SalesTableLoc.SalesId == this.SalesId
&& SalesTableLoc.God_subsidiarySales == NoYes::Yes;
{
if(SalesTableLoc)
{
while select inventtrans order by inventtrans.DateFinancial desc
where inventtrans.ItemId == this.ItemId
&& inventtrans.StatusReceipt == StatusReceipt::Purchased
join InventTransOrigin
where InventTransOrigin.RecId == inventtrans.InventTransOrigin
&& InventTransOrigin.ReferenceCategory == InventTransType::Purch
{
if(inventtrans)
{
i++;
if(i == 1)
{
amount= round(inventTrans.CostValue() / inventtrans.Qty,0.01);
amount = UnitOfMeasureConverter::convert(amount,
UnitOfMeasure::unitOfMeasureIdBySymbol(this.SalesUnit),
UnitOfMeasure::unitOfMeasureIdBySymbol(InventTableModule::find(this.ItemId,ModuleInventPurchSales::Invent).UnitId),NoYes::Yes,
InventTable::itemProduct(this.ItemId),NoYes::No);
break;
}
}
}
if(!amount)
amount = this.GOD_averageCostPriceUnitWMSChangeQty(this.ItemID); //amount = round(inventsum::find(salesline.ItemId,SalesLine.InventDimId).averageCostPrice(),0.01);
if(!amount)
{
amount = InventTableModule::find(this.ItemId,ModuleInventPurchSales::Invent).Price;
amount = UnitOfMeasureConverter::convert(amount,
UnitOfMeasure::unitOfMeasureIdBySymbol(this.SalesUnit),
UnitOfMeasure::unitOfMeasureIdBySymbol(InventTableModule::find(this.ItemId,ModuleInventPurchSales::Invent).UnitId),NoYes::Yes,
InventTable::itemProduct(this.ItemId),NoYes::No);
}
margin = amount * CustGroup::find(this.CustGroup).GOD_MarkupPercentage/100;
totalamount = amount + margin;
this.salesprice = round(totalamount,0.01);
// salesquotationline.lineamount = salesquotationline.calclineamount();
this.lineamount = this.calclineamount();
}
}
// End Code
}
FSP / RSP
//GITL::366842 added for BPC to display FSP
public display Amount GOD_FSP()
{
PriceDiscTable _PriceDiscTable;
PriceDiscGroup _PriceDiscGroup;
;
select _PriceDiscTable
join _PriceDiscGroup
where _PriceDiscTable.ItemCode == TableGroupAll::Table
&& _PriceDiscTable.ItemRelation == this.ItemId
&& _PriceDiscTable.relation == PriceType::PriceSales
&& _PriceDiscGroup.GroupId == _PriceDiscTable.AccountRelation
&& _PriceDiscGroup.GOD_PriceType == GOD_CustPriceType::FSP
&& _PriceDiscGroup.Module == ModuleInventCustVend::Cust;
return _PriceDiscTable.Amount;
}
----------------------------------------------------------
//GITL::366842 added for BPC to display RSP
public display Amount GOD_RSP()
{
PriceDiscTable _PriceDiscTable;
PriceDiscGroup _PriceDiscGroup;
;
select _PriceDiscTable
join _PriceDiscGroup
where _PriceDiscTable.ItemCode == TableGroupAll::Table
&& _PriceDiscTable.ItemRelation == this.ItemId
&& _PriceDiscTable.relation == PriceType::PriceSales
&& _PriceDiscGroup.GroupId == _PriceDiscTable.AccountRelation
&& _PriceDiscGroup.GOD_PriceType == GOD_CustPriceType::RSP
&& _PriceDiscGroup.Module == ModuleInventCustVend::Cust;
return _PriceDiscTable.Amount;
}
public display Amount GOD_FSP()
{
PriceDiscTable _PriceDiscTable;
PriceDiscGroup _PriceDiscGroup;
;
select _PriceDiscTable
join _PriceDiscGroup
where _PriceDiscTable.ItemCode == TableGroupAll::Table
&& _PriceDiscTable.ItemRelation == this.ItemId
&& _PriceDiscTable.relation == PriceType::PriceSales
&& _PriceDiscGroup.GroupId == _PriceDiscTable.AccountRelation
&& _PriceDiscGroup.GOD_PriceType == GOD_CustPriceType::FSP
&& _PriceDiscGroup.Module == ModuleInventCustVend::Cust;
return _PriceDiscTable.Amount;
}
----------------------------------------------------------
//GITL::366842 added for BPC to display RSP
public display Amount GOD_RSP()
{
PriceDiscTable _PriceDiscTable;
PriceDiscGroup _PriceDiscGroup;
;
select _PriceDiscTable
join _PriceDiscGroup
where _PriceDiscTable.ItemCode == TableGroupAll::Table
&& _PriceDiscTable.ItemRelation == this.ItemId
&& _PriceDiscTable.relation == PriceType::PriceSales
&& _PriceDiscGroup.GroupId == _PriceDiscTable.AccountRelation
&& _PriceDiscGroup.GOD_PriceType == GOD_CustPriceType::RSP
&& _PriceDiscGroup.Module == ModuleInventCustVend::Cust;
return _PriceDiscTable.Amount;
}
Physical Stock
public display SalesOrderedQty God_PhysicalStock()
{
InventSum invSum;
InventDim invDim, salesDim;
SalesOrderedQty FactorConv,_qty;
;
salesDim = InventDim::find(this.InventDimId);
select sum(postedQty), sum(Received), sum(deducted), sum(registered), sum(Picked), sum(ReservPhysical),
sum(Ordered), sum(Arrived), sum(ReservOrdered),sum(OnOrder)
from invSum group by ItemId
where invSum.ItemId == this.ItemId
exists join invDim
where invDim.inventDimId == invSum.InventDimId
&& invDim.InventLocationId == salesDim.InventLocationId
&& invDim.InventSiteId == salesDim.InventSiteId;
_qty = invSum.PostedQty + invSum.Received - invSum.Deducted + invSum.Registered - invSum.Picked;
FactorConv = UnitOfMeasureConverter::convert(_qty,
UnitOfMeasure::unitOfMeasureIdBySymbol(InventTableModule::find(this.ItemId,ModuleInventPurchSales::Invent).UnitId),
UnitOfMeasure::unitOfMeasureIdBySymbol(this.SalesUnit), NoYes::Yes,
InventTable::itemProduct(this.ItemId));
return FactorConv;
}
{
InventSum invSum;
InventDim invDim, salesDim;
SalesOrderedQty FactorConv,_qty;
;
salesDim = InventDim::find(this.InventDimId);
select sum(postedQty), sum(Received), sum(deducted), sum(registered), sum(Picked), sum(ReservPhysical),
sum(Ordered), sum(Arrived), sum(ReservOrdered),sum(OnOrder)
from invSum group by ItemId
where invSum.ItemId == this.ItemId
exists join invDim
where invDim.inventDimId == invSum.InventDimId
&& invDim.InventLocationId == salesDim.InventLocationId
&& invDim.InventSiteId == salesDim.InventSiteId;
_qty = invSum.PostedQty + invSum.Received - invSum.Deducted + invSum.Registered - invSum.Picked;
FactorConv = UnitOfMeasureConverter::convert(_qty,
UnitOfMeasure::unitOfMeasureIdBySymbol(InventTableModule::find(this.ItemId,ModuleInventPurchSales::Invent).UnitId),
UnitOfMeasure::unitOfMeasureIdBySymbol(this.SalesUnit), NoYes::Yes,
InventTable::itemProduct(this.ItemId));
return FactorConv;
}
Customized Logic in Sale line table
//GITL::366842 added for BPC to display BarCode
public display str GOD_BarCodeBCP()
{
RetailInventTable _RetailInventTable;
InventDim invDim, salesDim;
;
_RetailInventTable = RetailInventTable::find(this.ItemId);
return _RetailInventTable.getDefaultBarcode();
}
-------------------------------------------------------------------------------
customer reserved qty
public display SalesOrderedQty God_CustReser()
{
InventBlocking _inventBlocking;
SalesOrderedQty FactorConv;
Select sum(Qty) from _inventBlocking where _InventBlocking.ItemId == this.ItemId &&
_inventBlocking.God_HoldCode == SalesTable::find(this.SalesId).God_HoldCode;
//_inventBlocking.GOD_ParentCustomer == CustTable::find(SalesTable::find(this.SalesId).CustAccount).GOD_ParentCustomer;
FactorConv = UnitOfMeasureConverter::convert(_inventBlocking.Qty,
UnitOfMeasure::unitOfMeasureIdBySymbol(InventTableModule::find(this.ItemId,ModuleInventPurchSales::Invent).UnitId),
UnitOfMeasure::unitOfMeasureIdBySymbol(this.SalesUnit), NoYes::Yes,
InventTable::itemProduct(this.ItemId));
return FactorConv;
}
------------------------------------------------------------
//GITL::366842 added for BPC to display ItemPackingType
public display str GOD_ItemPackingType()
{
return InventTable::find(this.ItemId).GOD_ItemPackingType;
}
----------------------------------------------------------
//GITL::366842 added for BPC to display last Invoiced Date
public display date GOD_LastInvoiceDate()
{
SalesTable _SalesTable;
CustInvoiceJour _CustInvoiceJour;
CustInvoiceTrans _CustInvoiceTrans;
;
_SalesTable = SalesTable::find(this.SalesId);
select firstonly _CustInvoiceJour
index InvoiceNumIdx
order by InvoiceId desc
join _CustInvoiceTrans
where _CustInvoiceJour.InvoiceAccount == _SalesTable.InvoiceAccount
&& _CustInvoiceTrans.InvoiceId == _CustInvoiceJour.InvoiceId
&& _CustInvoiceTrans.ItemId == this.ItemId;
return _CustInvoiceJour.InvoiceDate;
}
----------------------------------------------
//GITL::366842 added for BPC to display last Invoiced Id
public display str GOD_LastInvoiceId()
{
SalesTable _SalesTable;
CustInvoiceJour _CustInvoiceJour;
CustInvoiceTrans _CustInvoiceTrans;
;
_SalesTable = SalesTable::find(this.SalesId);
select firstonly _CustInvoiceJour
index InvoiceNumIdx
order by InvoiceId desc
join _CustInvoiceTrans
where _CustInvoiceJour.InvoiceAccount == _SalesTable.InvoiceAccount
&& _CustInvoiceTrans.InvoiceId == _CustInvoiceJour.InvoiceId
&& _CustInvoiceTrans.ItemId == this.ItemId;
return _CustInvoiceJour.InvoiceId;
}
---------------------------------------
//GITL::366842 added for BPC to display last Invoiced Price
public display Amount GOD_LastInvoicePrice()
{
SalesTable _SalesTable;
CustInvoiceTrans _CustInvoiceTrans;
CustInvoiceJour _CustInvoiceJour;
;
_SalesTable = SalesTable::find(this.SalesId);
select firstonly _CustInvoiceJour
index InvoiceNumIdx
order by InvoiceId desc
join _CustInvoiceTrans
where _CustInvoiceJour.InvoiceAccount == _SalesTable.InvoiceAccount
&& _CustInvoiceTrans.InvoiceId == _CustInvoiceJour.InvoiceId
&& _CustInvoiceTrans.ItemId == this.ItemId;
return _CustInvoiceTrans.SalesPrice;
}
--------------------------------------------------------------
public display SalesOrderedQty God_OnOrdered()
{
InventSum invSum;
InventDim invDim, salesDim;
SalesOrderedQty FactorConv;
;
salesDim = InventDim::find(this.InventDimId);
select sum(postedQty), sum(Received), sum(deducted), sum(registered), sum(Picked), sum(ReservPhysical),
sum(Ordered), sum(Arrived), sum(ReservOrdered),sum(OnOrder)
from invSum group by ItemId
where invSum.ItemId == this.ItemId
exists join invDim
where invDim.inventDimId == invSum.InventDimId
&& invDim.InventLocationId == salesDim.InventLocationId
&& invDim.InventSiteId == salesDim.InventSiteId;
FactorConv = UnitOfMeasureConverter::convert(invSum.OnOrder,
UnitOfMeasure::unitOfMeasureIdBySymbol(InventTableModule::find(this.ItemId,ModuleInventPurchSales::Invent).UnitId),
UnitOfMeasure::unitOfMeasureIdBySymbol(this.SalesUnit), NoYes::Yes,
InventTable::itemProduct(this.ItemId));
return FactorConv ;
}
---------------------------------------------
public display str GOD_BarCodeBCP()
{
RetailInventTable _RetailInventTable;
InventDim invDim, salesDim;
;
_RetailInventTable = RetailInventTable::find(this.ItemId);
return _RetailInventTable.getDefaultBarcode();
}
-------------------------------------------------------------------------------
customer reserved qty
public display SalesOrderedQty God_CustReser()
{
InventBlocking _inventBlocking;
SalesOrderedQty FactorConv;
Select sum(Qty) from _inventBlocking where _InventBlocking.ItemId == this.ItemId &&
_inventBlocking.God_HoldCode == SalesTable::find(this.SalesId).God_HoldCode;
//_inventBlocking.GOD_ParentCustomer == CustTable::find(SalesTable::find(this.SalesId).CustAccount).GOD_ParentCustomer;
FactorConv = UnitOfMeasureConverter::convert(_inventBlocking.Qty,
UnitOfMeasure::unitOfMeasureIdBySymbol(InventTableModule::find(this.ItemId,ModuleInventPurchSales::Invent).UnitId),
UnitOfMeasure::unitOfMeasureIdBySymbol(this.SalesUnit), NoYes::Yes,
InventTable::itemProduct(this.ItemId));
return FactorConv;
}
------------------------------------------------------------
//GITL::366842 added for BPC to display ItemPackingType
public display str GOD_ItemPackingType()
{
return InventTable::find(this.ItemId).GOD_ItemPackingType;
}
----------------------------------------------------------
//GITL::366842 added for BPC to display last Invoiced Date
public display date GOD_LastInvoiceDate()
{
SalesTable _SalesTable;
CustInvoiceJour _CustInvoiceJour;
CustInvoiceTrans _CustInvoiceTrans;
;
_SalesTable = SalesTable::find(this.SalesId);
select firstonly _CustInvoiceJour
index InvoiceNumIdx
order by InvoiceId desc
join _CustInvoiceTrans
where _CustInvoiceJour.InvoiceAccount == _SalesTable.InvoiceAccount
&& _CustInvoiceTrans.InvoiceId == _CustInvoiceJour.InvoiceId
&& _CustInvoiceTrans.ItemId == this.ItemId;
return _CustInvoiceJour.InvoiceDate;
}
----------------------------------------------
//GITL::366842 added for BPC to display last Invoiced Id
public display str GOD_LastInvoiceId()
{
SalesTable _SalesTable;
CustInvoiceJour _CustInvoiceJour;
CustInvoiceTrans _CustInvoiceTrans;
;
_SalesTable = SalesTable::find(this.SalesId);
select firstonly _CustInvoiceJour
index InvoiceNumIdx
order by InvoiceId desc
join _CustInvoiceTrans
where _CustInvoiceJour.InvoiceAccount == _SalesTable.InvoiceAccount
&& _CustInvoiceTrans.InvoiceId == _CustInvoiceJour.InvoiceId
&& _CustInvoiceTrans.ItemId == this.ItemId;
return _CustInvoiceJour.InvoiceId;
}
---------------------------------------
//GITL::366842 added for BPC to display last Invoiced Price
public display Amount GOD_LastInvoicePrice()
{
SalesTable _SalesTable;
CustInvoiceTrans _CustInvoiceTrans;
CustInvoiceJour _CustInvoiceJour;
;
_SalesTable = SalesTable::find(this.SalesId);
select firstonly _CustInvoiceJour
index InvoiceNumIdx
order by InvoiceId desc
join _CustInvoiceTrans
where _CustInvoiceJour.InvoiceAccount == _SalesTable.InvoiceAccount
&& _CustInvoiceTrans.InvoiceId == _CustInvoiceJour.InvoiceId
&& _CustInvoiceTrans.ItemId == this.ItemId;
return _CustInvoiceTrans.SalesPrice;
}
--------------------------------------------------------------
public display SalesOrderedQty God_OnOrdered()
{
InventSum invSum;
InventDim invDim, salesDim;
SalesOrderedQty FactorConv;
;
salesDim = InventDim::find(this.InventDimId);
select sum(postedQty), sum(Received), sum(deducted), sum(registered), sum(Picked), sum(ReservPhysical),
sum(Ordered), sum(Arrived), sum(ReservOrdered),sum(OnOrder)
from invSum group by ItemId
where invSum.ItemId == this.ItemId
exists join invDim
where invDim.inventDimId == invSum.InventDimId
&& invDim.InventLocationId == salesDim.InventLocationId
&& invDim.InventSiteId == salesDim.InventSiteId;
FactorConv = UnitOfMeasureConverter::convert(invSum.OnOrder,
UnitOfMeasure::unitOfMeasureIdBySymbol(InventTableModule::find(this.ItemId,ModuleInventPurchSales::Invent).UnitId),
UnitOfMeasure::unitOfMeasureIdBySymbol(this.SalesUnit), NoYes::Yes,
InventTable::itemProduct(this.ItemId));
return FactorConv ;
}
---------------------------------------------
Average Cost Price Unit
public real GOD_averageCostPriceUnitWMSChangeQty(ItemId _ItemID)
{
InventDim dim;
InventSum _inventSum;
inventDim _inventDim;
InventTable inventTable;
InventCostPriceCache inventCostPriceCache;
UnitOfMeasureConverter_Product secondaryToInventUnitConverter;
UnitOfMeasureRecId fromUnitOfMeasureRecId;
UnitOfMeasureRecId toUnitOfMeasureRecId;
select ItemId,sum(PostedValue),sum(PostedQty),sum(Received),sum(Deducted),sum(PhysicalValue) from _inventSum
group by ItemId
where _inventSum.ItemId == _ItemID;
//join inventDim;
///if (!inventSum.InventDimId)
{
dim = InventDim::findDim(_inventDim);
if (dim.InventDimId)
{
_inventSum.InventDimId = dim.InventDimId;
}
}
inventCostPriceCache = InventCostPriceCache::construct();
inventTable = _inventSum.inventTable();
fromUnitOfMeasureRecId = UnitOfMeasure::findBySymbol(this.SalesUnit).RecId;
toUnitOfMeasureRecId = UnitOfMeasure::findBySymbol(inventTable.inventUnitId()).RecId;
secondaryToInventUnitConverter = UnitOfMeasureConverter_Product::construct();
secondaryToInventUnitConverter.parmProduct(inventTable.Product);
secondaryToInventUnitConverter.parmFromUnitOfMeasure(fromUnitOfMeasureRecId);
secondaryToInventUnitConverter.parmToUnitOfMeasure(toUnitOfMeasureRecId);
secondaryToInventUnitConverter.parmRoundAbsoluteValue(NoYes::Yes);
secondaryToInventUnitConverter.parmApplyRounding(NoYes::No);
//if( _INventSum.PostedValue <=0 && _InventSum.PostedQty <=0)
//return 0;
// else
return Currency::amount(inventCostPriceCache.costPricePcs(_inventSum, _inventDim) * secondaryToInventUnitConverter.convertValue(1));
}
{
InventDim dim;
InventSum _inventSum;
inventDim _inventDim;
InventTable inventTable;
InventCostPriceCache inventCostPriceCache;
UnitOfMeasureConverter_Product secondaryToInventUnitConverter;
UnitOfMeasureRecId fromUnitOfMeasureRecId;
UnitOfMeasureRecId toUnitOfMeasureRecId;
select ItemId,sum(PostedValue),sum(PostedQty),sum(Received),sum(Deducted),sum(PhysicalValue) from _inventSum
group by ItemId
where _inventSum.ItemId == _ItemID;
//join inventDim;
///if (!inventSum.InventDimId)
{
dim = InventDim::findDim(_inventDim);
if (dim.InventDimId)
{
_inventSum.InventDimId = dim.InventDimId;
}
}
inventCostPriceCache = InventCostPriceCache::construct();
inventTable = _inventSum.inventTable();
fromUnitOfMeasureRecId = UnitOfMeasure::findBySymbol(this.SalesUnit).RecId;
toUnitOfMeasureRecId = UnitOfMeasure::findBySymbol(inventTable.inventUnitId()).RecId;
secondaryToInventUnitConverter = UnitOfMeasureConverter_Product::construct();
secondaryToInventUnitConverter.parmProduct(inventTable.Product);
secondaryToInventUnitConverter.parmFromUnitOfMeasure(fromUnitOfMeasureRecId);
secondaryToInventUnitConverter.parmToUnitOfMeasure(toUnitOfMeasureRecId);
secondaryToInventUnitConverter.parmRoundAbsoluteValue(NoYes::Yes);
secondaryToInventUnitConverter.parmApplyRounding(NoYes::No);
//if( _INventSum.PostedValue <=0 && _InventSum.PostedQty <=0)
//return 0;
// else
return Currency::amount(inventCostPriceCache.costPricePcs(_inventSum, _inventDim) * secondaryToInventUnitConverter.convertValue(1));
}
Available Physical Qty
public display SalesOrderedQty God_AvailablePhysical()
{
InventSum invSum;
InventDim invDim, salesDim;
SalesOrderedQty FactorConv,_qty;
;
salesDim = InventDim::find(this.InventDimId);
select sum(postedQty), sum(Received), sum(deducted), sum(registered), sum(Picked), sum(ReservPhysical),
sum(Ordered), sum(Arrived), sum(ReservOrdered),sum(OnOrder)
from invSum group by ItemId
where invSum.ItemId == this.ItemId
exists join invDim
where invDim.inventDimId == invSum.InventDimId
&& invDim.InventLocationId == salesDim.InventLocationId
&& invDim.InventSiteId == salesDim.InventSiteId;
_qty = invSum.PostedQty + invSum.Received - invSum.Deducted + invSum.Registered - invSum.Picked - invSum.ReservPhysical;
FactorConv = UnitOfMeasureConverter::convert(_Qty,
UnitOfMeasure::unitOfMeasureIdBySymbol(InventTableModule::find(this.ItemId,ModuleInventPurchSales::Invent).UnitId),
UnitOfMeasure::unitOfMeasureIdBySymbol(this.SalesUnit), NoYes::Yes,
InventTable::itemProduct(this.ItemId));
return FactorConv;
}
{
InventSum invSum;
InventDim invDim, salesDim;
SalesOrderedQty FactorConv,_qty;
;
salesDim = InventDim::find(this.InventDimId);
select sum(postedQty), sum(Received), sum(deducted), sum(registered), sum(Picked), sum(ReservPhysical),
sum(Ordered), sum(Arrived), sum(ReservOrdered),sum(OnOrder)
from invSum group by ItemId
where invSum.ItemId == this.ItemId
exists join invDim
where invDim.inventDimId == invSum.InventDimId
&& invDim.InventLocationId == salesDim.InventLocationId
&& invDim.InventSiteId == salesDim.InventSiteId;
_qty = invSum.PostedQty + invSum.Received - invSum.Deducted + invSum.Registered - invSum.Picked - invSum.ReservPhysical;
FactorConv = UnitOfMeasureConverter::convert(_Qty,
UnitOfMeasure::unitOfMeasureIdBySymbol(InventTableModule::find(this.ItemId,ModuleInventPurchSales::Invent).UnitId),
UnitOfMeasure::unitOfMeasureIdBySymbol(this.SalesUnit), NoYes::Yes,
InventTable::itemProduct(this.ItemId));
return FactorConv;
}
Wednesday, September 11, 2019
User role based form grid field controlling
public void init()
{
#Admin
UserInfo userInfo, userInfoAdmin;
SecurityUserRole userRole;
SecurityRole securityRole;
super();
verticalSplitter = new SysFormSplitter_X(VSplitter, GridContainer, element, 300);
while select userRole
where userRole.User == curUserId()
join securityRole where securityRole.RecId == userRole.SecurityRole
{
if(securityRole.AotName == 'GH_Logistics_Menus' )
{
GOD_CashCollection_ds.object(fieldNum(GOD_CashCollection , AccountConfirmed)).allowEdit(false);
GOD_CashCollection_ds.object(fieldNum(GOD_CashCollection , Delivered)).enabled(true);
//info(strFmt("name01 %1", curUserId()));
}
else if(securityRole.AotName == 'LedgerAccountant' )
{
GOD_CashCollection_ds.object(fieldNum(GOD_CashCollection , Delivered)).allowEdit(false);
GOD_CashCollection_ds.object(fieldNum(GOD_CashCollection , AccountConfirmed)).enabled(true);
//info(strFmt("name02 %1", curUserId()));
}
}
}
{
#Admin
UserInfo userInfo, userInfoAdmin;
SecurityUserRole userRole;
SecurityRole securityRole;
super();
verticalSplitter = new SysFormSplitter_X(VSplitter, GridContainer, element, 300);
while select userRole
where userRole.User == curUserId()
join securityRole where securityRole.RecId == userRole.SecurityRole
{
if(securityRole.AotName == 'GH_Logistics_Menus' )
{
GOD_CashCollection_ds.object(fieldNum(GOD_CashCollection , AccountConfirmed)).allowEdit(false);
GOD_CashCollection_ds.object(fieldNum(GOD_CashCollection , Delivered)).enabled(true);
//info(strFmt("name01 %1", curUserId()));
}
else if(securityRole.AotName == 'LedgerAccountant' )
{
GOD_CashCollection_ds.object(fieldNum(GOD_CashCollection , Delivered)).allowEdit(false);
GOD_CashCollection_ds.object(fieldNum(GOD_CashCollection , AccountConfirmed)).enabled(true);
//info(strFmt("name02 %1", curUserId()));
}
}
}
Wednesday, September 4, 2019
Updating Customer Email Address as primary and business
static void excelCustomerEmailUpload(Args _args)
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
Filename filename;
str filePath, fileNameOnly;
Dialog dialog;
DialogField dialogFileName;
int row;
GOD_VacationBalances vacationBalances;
HcmPersonnelNumberId personnelNumber;
real vacationBalance;
TransDate upToDate;
DirPartyContactInfoView contactView;
CustTable CustTable;
DirParty dirParty;
DirPartyRecId partyRecId;
CustAccount _custAccount;
LogisticsPostalAddress address;
DirPartyPostalAddressView addressView;
;
dialog = new Dialog();
dialog.caption("Pick excel file");
dialogFileName = dialog.addField(extendedTypeStr(FilenameOpen), "Enter excel file", "Browse excel file");
if(!dialog.run())
return;
filename = dialogFileName.value();
[filePath,fileNameOnly] = fileNameSplit(filename);
application = SysExcelApplication::construct();
workbooks = application.workbooks();
try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error(strFmt("Filename %1 cannot be blank.",filename));
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
row = 1;
do
{
try
{
row++;
_custAccount = cells.item(row, 1).value().bStr();
partyRecId = CustTable::find(_custAccount ).Party;
DirParty = DirParty::constructFromPartyRecId(partyRecId );
contactView.clear();
if(strLRTrim(cells.item(row, 1).value().bStr())!= "")
{
contactView.LocationName = "Email";
contactView.Locator = strLRTrim(cells.item(row, 2).value().bStr());
contactView.Type = LogisticsElectronicAddressMethodType::Email;
contactView.Party = partyRecId;
contactView.IsPrimary = NoYes::Yes;
ttsBegin;
dirParty.createOrUpdateContactInfo(contactView);
ttsCommit;
}
else
{
warning(strFmt("Row %1 not updated.", row));
}
}
catch
{
error(strfmt("Row %1 not updated.", row));
}
type = cells.item(row+1, 1).value().variantType();
}
while (type != COMVariantType::VT_EMPTY);
workbook.saved(true);
application.visible(false);
application.quit();
info("Excel uploaded successfully");
}
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
Filename filename;
str filePath, fileNameOnly;
Dialog dialog;
DialogField dialogFileName;
int row;
GOD_VacationBalances vacationBalances;
HcmPersonnelNumberId personnelNumber;
real vacationBalance;
TransDate upToDate;
DirPartyContactInfoView contactView;
CustTable CustTable;
DirParty dirParty;
DirPartyRecId partyRecId;
CustAccount _custAccount;
LogisticsPostalAddress address;
DirPartyPostalAddressView addressView;
;
dialog = new Dialog();
dialog.caption("Pick excel file");
dialogFileName = dialog.addField(extendedTypeStr(FilenameOpen), "Enter excel file", "Browse excel file");
if(!dialog.run())
return;
filename = dialogFileName.value();
[filePath,fileNameOnly] = fileNameSplit(filename);
application = SysExcelApplication::construct();
workbooks = application.workbooks();
try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error(strFmt("Filename %1 cannot be blank.",filename));
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
row = 1;
do
{
try
{
row++;
_custAccount = cells.item(row, 1).value().bStr();
partyRecId = CustTable::find(_custAccount ).Party;
DirParty = DirParty::constructFromPartyRecId(partyRecId );
contactView.clear();
if(strLRTrim(cells.item(row, 1).value().bStr())!= "")
{
contactView.LocationName = "Email";
contactView.Locator = strLRTrim(cells.item(row, 2).value().bStr());
contactView.Type = LogisticsElectronicAddressMethodType::Email;
contactView.Party = partyRecId;
contactView.IsPrimary = NoYes::Yes;
ttsBegin;
dirParty.createOrUpdateContactInfo(contactView);
ttsCommit;
}
else
{
warning(strFmt("Row %1 not updated.", row));
}
}
catch
{
error(strfmt("Row %1 not updated.", row));
}
type = cells.item(row+1, 1).value().variantType();
}
while (type != COMVariantType::VT_EMPTY);
workbook.saved(true);
application.visible(false);
application.quit();
info("Excel uploaded successfully");
}
Deleting Customer Business Address Primary
static void GH_Cust_BusinessAddress_Delete(Args _args)
{
CustTable cust;
DirPartyLocation dirPartyLocation;
LogisticsElectronicAddress elecAddress;
LogisticsElectronicAddressRole elecAddressRole;
LogisticsLocationRole locRole;
while select cust
{ // where cust.AccountNum == 'C-04474';
ttsBegin;
while select DirPartyLocation
where dirPartyLocation.party == cust.Party
{
while select forUpdate elecAddress
where elecAddress.Location == dirPartyLocation.Location
&& elecAddress.Type == LogisticsElectronicAddressMethodType::Email
{
while select forUpdate elecAddressRole
where elecAddressRole.ElectronicAddress == elecAddress.RecId
join locRole
where locRole.RecId == elecAddressRole.LocationRole
//&& locRole.Type == LogisticsLocationRoleType::Business
{
info(strFmt("%1 - %2 - %3",cust.AccountNum, locRole.Name , elecAddress.Locator));
//elecAddress.delete();
}
}
}
ttsCommit;
}
}
{
CustTable cust;
DirPartyLocation dirPartyLocation;
LogisticsElectronicAddress elecAddress;
LogisticsElectronicAddressRole elecAddressRole;
LogisticsLocationRole locRole;
while select cust
{ // where cust.AccountNum == 'C-04474';
ttsBegin;
while select DirPartyLocation
where dirPartyLocation.party == cust.Party
{
while select forUpdate elecAddress
where elecAddress.Location == dirPartyLocation.Location
&& elecAddress.Type == LogisticsElectronicAddressMethodType::Email
{
while select forUpdate elecAddressRole
where elecAddressRole.ElectronicAddress == elecAddress.RecId
join locRole
where locRole.RecId == elecAddressRole.LocationRole
//&& locRole.Type == LogisticsLocationRoleType::Business
{
info(strFmt("%1 - %2 - %3",cust.AccountNum, locRole.Name , elecAddress.Locator));
//elecAddress.delete();
}
}
}
ttsCommit;
}
}
Wednesday, August 28, 2019
Update Cust group and segments
static void Update_CustGroup(Args _args)
{
CustGroup _custGroup;
CustTable _custTable;
smmBusRelSegmentGroup _segmentGroup;
smmBusRelSubSegmentGroup _subSegmentGroup;
ttsBegin;
select forUpdate _custGroup
where _custGroup.dataAreaId == 'gh'
&& _custGroup.CustGroup == 'HOR-HO-HPB';
{
_custGroup.CustGroup ='HOR-HO-HRB';
_custGroup.update();
info(' custgroup updated done');
}
select forUpdate _subSegmentGroup
where _subSegmentGroup.dataAreaId == 'gh'
&& _subSegmentGroup.SubsegmentId == 'HPB';
{
_subSegmentGroup.SubsegmentId = 'HRB';
_subSegmentGroup.SubSegmentDescription = 'CAFES & BAKE SHOPS';
_subSegmentGroup.update();
info('subsegment updated done');
}
while select forUpdate _custTable
where _custTable.dataAreaId == 'gh'
&& _custTable.CustGroup == 'HOR-HO-HPB'
&& _custTable.SegmentId == 'HO'
&& _custTable.SubsegmentId == 'HPB'
&& _custTable.AccountNum != ''
{
_custTable.CustGroup ='HOR-HO-HRB';
_custTable.SubsegmentId = 'HRB';
_custTable.doUpdate();
info('All customers are updated with cust group');
}
ttsCommit;
}
{
CustGroup _custGroup;
CustTable _custTable;
smmBusRelSegmentGroup _segmentGroup;
smmBusRelSubSegmentGroup _subSegmentGroup;
ttsBegin;
select forUpdate _custGroup
where _custGroup.dataAreaId == 'gh'
&& _custGroup.CustGroup == 'HOR-HO-HPB';
{
_custGroup.CustGroup ='HOR-HO-HRB';
_custGroup.update();
info(' custgroup updated done');
}
select forUpdate _subSegmentGroup
where _subSegmentGroup.dataAreaId == 'gh'
&& _subSegmentGroup.SubsegmentId == 'HPB';
{
_subSegmentGroup.SubsegmentId = 'HRB';
_subSegmentGroup.SubSegmentDescription = 'CAFES & BAKE SHOPS';
_subSegmentGroup.update();
info('subsegment updated done');
}
while select forUpdate _custTable
where _custTable.dataAreaId == 'gh'
&& _custTable.CustGroup == 'HOR-HO-HPB'
&& _custTable.SegmentId == 'HO'
&& _custTable.SubsegmentId == 'HPB'
&& _custTable.AccountNum != ''
{
_custTable.CustGroup ='HOR-HO-HRB';
_custTable.SubsegmentId = 'HRB';
_custTable.doUpdate();
info('All customers are updated with cust group');
}
ttsCommit;
}
Tuesday, August 20, 2019
sending email to salesman regarding customer is on hold due to credit limit
salestable - methos
---------------------------------------------------
Public void God_SendAlert()
{
DirPersonUser dirPersonUser;
EventNotificationSource _source;
CustTable custTable;
EventNotification event = EventNotification::construct(EventNotificationSource::Sync);
//--- added by kavin for sending email to salesman for cusotmer is on hold 20 aug -2019
GOD_SendEmail god_SendEmail;
Email mainContactWorkerEmail;
//--- added by kavin for sending email to salesman for cusotmer is on hold 20 aug -2019
custTable = CustTable::find(this.CustAccount);
event.parmRecord(custTable);
event.parmUserId(dirPersonUser::findParty(HcmWorker::findRecId(CustTable::find(this.CustAccount).MainContactWorker).Person).User);//curuserid());//user for which this alert to be shown
event.parmDataSourceName('Custtable'); //form datasource
event.parmMenuFunction(new MenuFunction('custtable', MenuItemtype::Display));
event.parmSubject('Customer Unblocking notification for Sales order process');
event.parmMessage(strFmt("Customer %1 is Blocked. Unable to Create Sales order. Kindly take action.",custtable.AccountNum));
//--- added by kavin for sending email to salesman for cusotmer is on hold 20 aug -2019
mainContactWorkerEmail = HcmWorker::emailServer(HcmWorker::find(CustTable::find(this.CustAccount).MainContactWorker).Person);
//info(custtable.AccountNum);
god_SendEmail::sendmail(event.parmSubject('Customer Unblocking notification for Sales order process'),
event.parmMessage(strFmt("Customer %1 is Blocked. Unable to Create Sales order. Kindly take action.",custtable.AccountNum)),
'axsentmails@greenhouseuae.com',mainContactWorkerEmail);
//--- added by kavin for sending email to salesman for cusotmer is on hold -- 20 aug -2019
event.create();
}
------------------------------------------------
class
class GOD_SendEmail
{
}
------------------------------------------------
public static void sendmail(Description _Subject,string255 _body,string50 _fromaddress,string50 _toaddress)
{
SysEmailParameters parameters = SysEmailParameters::find();
SMTPRelayServerName relayServer;
SMTPPortNumber portNumber;
SMTPUserName userName;
SMTPPassword password;
Str1260 subject,body;
InteropPermission interopPermission;
SysMailer mailer;
System.Exception e;
;
if (parameters.SMTPRelayServerName)
relayServer = parameters.SMTPRelayServerName;
else
relayServer = parameters.SMTPServerIPAddress;
portNumber = parameters.SMTPPortNumber;
userName = parameters.SMTPUserName;
password = SysEmailParameters::password();
subject = _Subject;
body = _body; //"<B> " + _body + " </B>";
CodeAccessPermission::revertAssert();
try
{
interopPermission = new InteropPermission(InteropKind::ComInterop);
interopPermission.assert();
mailer = new SysMailer();
mailer.SMTPRelayServer(relayServer,portNumber,userName,password, parameters.NTLM);
//instantiate email
mailer.fromAddress(_fromaddress);
mailer.tos().appendAddress(_toaddress);
mailer.subject(subject);
mailer.htmlBody(body);
mailer.sendMail();
CodeAccessPermission::revertAssert();
info("Email has been send!");
}
catch (Exception::CLRError)
{
e = ClrInterop::getLastException();
while (e)
{
info(e.get_Message());
e = e.get_InnerException();
}
CodeAccessPermission::revertAssert();
info ("Failed to Send Email some Error occure");
}
}
---------------------------------------------------
Public void God_SendAlert()
{
DirPersonUser dirPersonUser;
EventNotificationSource _source;
CustTable custTable;
EventNotification event = EventNotification::construct(EventNotificationSource::Sync);
//--- added by kavin for sending email to salesman for cusotmer is on hold 20 aug -2019
GOD_SendEmail god_SendEmail;
Email mainContactWorkerEmail;
//--- added by kavin for sending email to salesman for cusotmer is on hold 20 aug -2019
custTable = CustTable::find(this.CustAccount);
event.parmRecord(custTable);
event.parmUserId(dirPersonUser::findParty(HcmWorker::findRecId(CustTable::find(this.CustAccount).MainContactWorker).Person).User);//curuserid());//user for which this alert to be shown
event.parmDataSourceName('Custtable'); //form datasource
event.parmMenuFunction(new MenuFunction('custtable', MenuItemtype::Display));
event.parmSubject('Customer Unblocking notification for Sales order process');
event.parmMessage(strFmt("Customer %1 is Blocked. Unable to Create Sales order. Kindly take action.",custtable.AccountNum));
//--- added by kavin for sending email to salesman for cusotmer is on hold 20 aug -2019
mainContactWorkerEmail = HcmWorker::emailServer(HcmWorker::find(CustTable::find(this.CustAccount).MainContactWorker).Person);
//info(custtable.AccountNum);
god_SendEmail::sendmail(event.parmSubject('Customer Unblocking notification for Sales order process'),
event.parmMessage(strFmt("Customer %1 is Blocked. Unable to Create Sales order. Kindly take action.",custtable.AccountNum)),
'axsentmails@greenhouseuae.com',mainContactWorkerEmail);
//--- added by kavin for sending email to salesman for cusotmer is on hold -- 20 aug -2019
event.create();
}
------------------------------------------------
class
class GOD_SendEmail
{
}
------------------------------------------------
public static void sendmail(Description _Subject,string255 _body,string50 _fromaddress,string50 _toaddress)
{
SysEmailParameters parameters = SysEmailParameters::find();
SMTPRelayServerName relayServer;
SMTPPortNumber portNumber;
SMTPUserName userName;
SMTPPassword password;
Str1260 subject,body;
InteropPermission interopPermission;
SysMailer mailer;
System.Exception e;
;
if (parameters.SMTPRelayServerName)
relayServer = parameters.SMTPRelayServerName;
else
relayServer = parameters.SMTPServerIPAddress;
portNumber = parameters.SMTPPortNumber;
userName = parameters.SMTPUserName;
password = SysEmailParameters::password();
subject = _Subject;
body = _body; //"<B> " + _body + " </B>";
CodeAccessPermission::revertAssert();
try
{
interopPermission = new InteropPermission(InteropKind::ComInterop);
interopPermission.assert();
mailer = new SysMailer();
mailer.SMTPRelayServer(relayServer,portNumber,userName,password, parameters.NTLM);
//instantiate email
mailer.fromAddress(_fromaddress);
mailer.tos().appendAddress(_toaddress);
mailer.subject(subject);
mailer.htmlBody(body);
mailer.sendMail();
CodeAccessPermission::revertAssert();
info("Email has been send!");
}
catch (Exception::CLRError)
{
e = ClrInterop::getLastException();
while (e)
{
info(e.get_Message());
e = e.get_InnerException();
}
CodeAccessPermission::revertAssert();
info ("Failed to Send Email some Error occure");
}
}
Monday, August 19, 2019
Send Report Throw Mail
static void God_sendReportThrowMail(Args _args)
{
SrsReportRunController ssrsController = new SrsReportRunController();
GOD_GRVReportController GoodDestructionReportcontroller;
GOD_GRVReportContract Contract = new GOD_GRVReportContract();
SRSPrintDestinationSettings printerSettings;
str ReportPath;
// Send Email throw Code
str Body;
str Subject;
str cc1;
str mailAddressFrom;
str mailAddressTo;
UserInfo userInfo;
SysINetMail mail = new SysINetMail();
SysMailer Mailer;
InventParameters _InventParameter;
// End
Mailer =new SysMailer();
select _InventParameter;
ReportPath = "C:\\" + "GRVReportGH" +".pdf";
Subject = _InventParameter.God_EmailSubject;
Body = _InventParameter.God_EmailBody;
ssrsController.parmReportName(ssrsReportStr(GOD_GRVReport, Report_GH));
ssrsController.parmExecutionMode(SysOperationExecutionMode::Synchronous);
ssrsController.parmShowDialog(false);
Contract.parmRecId(5637144581);
// Contract.parmRecordId(VendPurchOrderJour.RecId);
ssrsController.parmReportContract().parmRdpContract(Contract);
//link the printer settings to the controller
printerSettings = ssrsController.parmReportContract().parmPrintSettings();
//print to pdf and always overwrite if the file exists
printerSettings.printMediumType(SRSPrintMediumType::File);
printerSettings.fileFormat(SRSReportFileFormat::PDF);
printerSettings.overwriteFile(true);
printerSettings.fileName(@ReportPath);
ssrsController.runReport();
//assign the values to send email
mailAddressFrom = "axsentmails@gxxxxxx.com";
mailAddressTo = "axxxxxx@gxxx.com";
cc1 = "bxxxxx@gxxx.com";
//Send Mail
if (mailer !=null)
{
mailer.quickSend(mailAddressFrom,mailAddressTo,Subject,Body,cc1,ReportPath);
//mailer.finalize()
}
//mail.sendMailAttach(mailAddressTo,cc1,Subject,Body,false,ReportPath);
// mailer.quickSend(mailAddressFrom,mailAddressTo,"Attach GRV Report","GRV Report",ReportPath);
info("Mail Send ");
}
{
SrsReportRunController ssrsController = new SrsReportRunController();
GOD_GRVReportController GoodDestructionReportcontroller;
GOD_GRVReportContract Contract = new GOD_GRVReportContract();
SRSPrintDestinationSettings printerSettings;
str ReportPath;
// Send Email throw Code
str Body;
str Subject;
str cc1;
str mailAddressFrom;
str mailAddressTo;
UserInfo userInfo;
SysINetMail mail = new SysINetMail();
SysMailer Mailer;
InventParameters _InventParameter;
// End
Mailer =new SysMailer();
select _InventParameter;
ReportPath = "C:\\" + "GRVReportGH" +".pdf";
Subject = _InventParameter.God_EmailSubject;
Body = _InventParameter.God_EmailBody;
ssrsController.parmReportName(ssrsReportStr(GOD_GRVReport, Report_GH));
ssrsController.parmExecutionMode(SysOperationExecutionMode::Synchronous);
ssrsController.parmShowDialog(false);
Contract.parmRecId(5637144581);
// Contract.parmRecordId(VendPurchOrderJour.RecId);
ssrsController.parmReportContract().parmRdpContract(Contract);
//link the printer settings to the controller
printerSettings = ssrsController.parmReportContract().parmPrintSettings();
//print to pdf and always overwrite if the file exists
printerSettings.printMediumType(SRSPrintMediumType::File);
printerSettings.fileFormat(SRSReportFileFormat::PDF);
printerSettings.overwriteFile(true);
printerSettings.fileName(@ReportPath);
ssrsController.runReport();
//assign the values to send email
mailAddressFrom = "axsentmails@gxxxxxx.com";
mailAddressTo = "axxxxxx@gxxx.com";
cc1 = "bxxxxx@gxxx.com";
//Send Mail
if (mailer !=null)
{
mailer.quickSend(mailAddressFrom,mailAddressTo,Subject,Body,cc1,ReportPath);
//mailer.finalize()
}
//mail.sendMailAttach(mailAddressTo,cc1,Subject,Body,false,ReportPath);
// mailer.quickSend(mailAddressFrom,mailAddressTo,"Attach GRV Report","GRV Report",ReportPath);
info("Mail Send ");
}
Find Customer Address
static void FindCustomerAddress(Args _args)
{
CustTable custTable;
DirPartyTable dirParty;
LogisticsElectronicAddress electronicAddress;
DirPartyLocation dirPartyLoc;
//find the customer
custTable = CustTable::find("C-00016");
//find the party for the customer
dirParty = DirPartyTable::findRec(custTable.Party);
//find all of the contacts for the current customer
while SELECT * FROM electronicAddress
EXISTS JOIN * FROM dirPartyLoc
WHERE electronicAddress.Location == dirPartyLoc.Location && dirParty.RecId==dirPartyLoc.Party
{
info(electronicAddress.Locator);
}
}
{
CustTable custTable;
DirPartyTable dirParty;
LogisticsElectronicAddress electronicAddress;
DirPartyLocation dirPartyLoc;
//find the customer
custTable = CustTable::find("C-00016");
//find the party for the customer
dirParty = DirPartyTable::findRec(custTable.Party);
//find all of the contacts for the current customer
while SELECT * FROM electronicAddress
EXISTS JOIN * FROM dirPartyLoc
WHERE electronicAddress.Location == dirPartyLoc.Location && dirParty.RecId==dirPartyLoc.Party
{
info(electronicAddress.Locator);
}
}
Emp Contract Master
static void EmpContractMaster(Args _args)
{
#AviFiles
FilenameOpen filename;
dialogField dialogFilename,DialogJournalType;
int jounaltype;
Dialog dialog= new Dialog("Excel Upoad");
Container excelCont[];
GOD_PaymentMode PaymentType;
int rowIdx;
Counter linesImported;
int lastRow,dimcount;
boolean ok = true;
Description c1,c3,c4,c5,c6,c7,c8,c9,c2,c10,c11,c12;
//int64 c2;
str input;
container accEntryPattern;
BudgetType budgetType;
SysExcelApplication application;
SysExcelWorkBooks workBooks;
SysExcelWorkSheets workSheets;
SysExcelWorkSheet workSheet;
SysExcelCells cells;
GOD_EmplContract GOD_EmplContract;
GOD_ContractValidity GOD_ContractValidity;
GOD_ContractType GOD_ContractType;
GOD_ContractNo contractNo;
HcmEmployment hcmEmployment;
NoYes NoYes;
SysOperationProgress progress;
struct struct= new Struct();
boolean ret = true;
dirPersonName dirPersonName;
HcmWorker hcmworker;
#define.CurrentVersion(1)
#localmacro.CurrentList
filename
#endmacro
#Excel
#define.Star('*')
#define.Space(' ')
// convert into str from excel cell value
str COMVariant2Str(COMVariant _cv, int _decimals = 0, int _characters = 0, int _separator1 = 0, int _separator2 = 0)
{
switch (_cv.variantType())
{
case (COMVariantType::VT_BSTR):
return _cv.bStr();
case (COMVariantType::VT_R4):
return num2str(_cv.float(),_characters,_decimals,_separator1,_separator2);
case (COMVariantType::VT_R8):
return num2str(_cv.double(),_characters,_decimals,_separator1,_separator2);
case (COMVariantType::VT_DECIMAL):
return num2str(_cv.decimal(),_characters,_decimals,_separator1,_separator2);
case (COMVariantType::VT_DATE):
return date2str(_cv.date(),123,2,1,2,1,4);
case (COMVariantType::VT_EMPTY):
return "";
default:
throw error(strfmt("@SYS26908", _cv.variantType()));
}
return "";
}
// Find last row from excel
int findLastRow(SysExcelWorkSheet _workSheet)
{
SysExcelRange range;
;
range = _workSheet.cells().range(#ExcelTotalRange);
try
{
// Finds the row where the first contents is found.
range = range.find(#Star, null, #xlFormulas, #xlWhole, #xlByRows, #xlPrevious);
}
catch (Exception::Error)
{
error("@SYS59926");
return 0;
}
if (range)
{
return range.row();
}
else
{
return 0;
}
}
;
dialogFilename = dialog.addField(extendedtypestr(FilenameOpen));
// DialogJournalType = dialog.addField(enumstr(God_JournalToUpload),"Journal Type");
dialog.filenameLookupFilter(["@SYS28576",#XLS,#Xlsx]);
dialog.filenameLookupTitle("Upload from Excel");
dialogFilename.value(filename);
if(!dialog.run())
return;
filename = dialogFilename.value();
// ttsbegin;
application = SysExcelApplication::construct();
workBooks = application.workbooks();
workBooks.open(filename,0,true);
workSheets = workBooks.item(1).worksheets();
// this.importExcel("Sheet1");
input = "Sheet1";
workSheet = workSheets.itemFromNum(1);//.itemFromName(input);
cells = workSheet.cells();
lastRow = findLastRow(workSheet);
rowIdx = 2;
progress = new SysOperationProgress();
progress.setCaption("Excel Importing");
progress.setTotal(lastRow);
progress.setAnimation(#AviTransfer);
setprefix("Excel Import");
while (rowIdx <= lastRow)
{
setPrefix(strfmt("Excel Row: %1", rowIdx));
c1 = COMVariant2Str(cells.item(rowIdx,1).value());
c2 = COMVariant2Str(cells.item(rowIdx,2).value());
c3 = COMVariant2Str(cells.item(rowIdx,3).value());
c4 = COMVariant2Str(cells.item(rowIdx,4).value());
c5 = COMVariant2Str(cells.item(rowIdx,5).value());
c6 = COMVariant2Str(cells.item(rowIdx,6).value());
c7 = COMVariant2Str(cells.item(rowIdx,7).value());
c8 = COMVariant2Str(cells.item(rowIdx,8).value());
c9 = COMVariant2Str(cells.item(rowIdx,9).value());
c10 = COMVariant2Str(cells.item(rowIdx,10).value());
c11 = COMVariant2Str(cells.item(rowIdx,11).value());
c12 = COMVariant2Str(cells.item(rowIdx,11).value());
linesImported++;
//ttsBegin;
hcmworker = HcmWorker::findByPersonnelNumber(c1);
select firstonly hcmEmployment where hcmEmployment.Worker == hcmworker.RecId;
contractNo = str2int(c2);
if(HcmWorker)
{
ttsBegin;
select forUpdate GOD_EmplContract
where GOD_EmplContract.EmplId == hcmworker.PersonnelNumber
&& GOD_EmplContract.ContractNo == contractNo && GOD_EmplContract.Active == NoYes::Yes;
if(GOD_EmplContract)
{
GOD_EmplContract.ContractNo = contractNo;
GOD_EmplContract.GradeId = c3;
GOD_EmplContract.GradeLevelId = c4;
GOD_EmplContract.BasicSalary = any2real(c5);
GOD_EmplContract.PaymentType = str2enum(PaymentType,c6);
GOD_EmplContract.OrganizationUnitId = c7;
GOD_EmplContract.OMCostCenter= c8;
GOD_EmplContract.EmployeeType = str2enum(GOD_ContractType,c9);
GOD_EmplContract.Validity = str2enum(GOD_ContractValidity,c10);
GOD_EmplContract.ProbationCompleted = str2enum(NoYes,c11);
GOD_EmplContract.ProfileGroupId = c12;
GOD_EmplContract.StartDate = any2date(hcmEmployment.ValidFrom);
GOD_EmplContract.EffectiveDate = any2date(hcmEmployment.ValidFrom);
GOD_EmplContract.update();
}
else
{
GOD_EmplContract.ContractNo = contractNo;
GOD_EmplContract.GradeId = c3;
GOD_EmplContract.GradeLevelId = c4;
GOD_EmplContract.BasicSalary = any2real(c5);
GOD_EmplContract.PaymentType = str2enum(PaymentType,c6);
GOD_EmplContract.OrganizationUnitId = c7;
GOD_EmplContract.OMCostCenter = c8;
GOD_EmplContract.EmployeeType = str2enum(GOD_ContractType,c9);
GOD_EmplContract.Validity = str2enum(GOD_ContractValidity,c10);
GOD_EmplContract.ProbationCompleted = str2enum(NoYes,c11);
GOD_EmplContract.ProfileGroupId = c12;
GOD_EmplContract.EmplId = hcmworker.PersonnelNumber;
GOD_EmplContract.Active = NoYes::Yes;
GOD_EmplContract.StartDate = any2date(hcmEmployment.ValidFrom);
GOD_EmplContract.EffectiveDate = any2date(hcmEmployment.ValidFrom);
GOD_EmplContract.insert();
}
ttsCommit;
}
progress.setText("Importing " + c1);
progress.setCount(linesImported);
rowIdx++;
}
info("done");
}
{
#AviFiles
FilenameOpen filename;
dialogField dialogFilename,DialogJournalType;
int jounaltype;
Dialog dialog= new Dialog("Excel Upoad");
Container excelCont[];
GOD_PaymentMode PaymentType;
int rowIdx;
Counter linesImported;
int lastRow,dimcount;
boolean ok = true;
Description c1,c3,c4,c5,c6,c7,c8,c9,c2,c10,c11,c12;
//int64 c2;
str input;
container accEntryPattern;
BudgetType budgetType;
SysExcelApplication application;
SysExcelWorkBooks workBooks;
SysExcelWorkSheets workSheets;
SysExcelWorkSheet workSheet;
SysExcelCells cells;
GOD_EmplContract GOD_EmplContract;
GOD_ContractValidity GOD_ContractValidity;
GOD_ContractType GOD_ContractType;
GOD_ContractNo contractNo;
HcmEmployment hcmEmployment;
NoYes NoYes;
SysOperationProgress progress;
struct struct= new Struct();
boolean ret = true;
dirPersonName dirPersonName;
HcmWorker hcmworker;
#define.CurrentVersion(1)
#localmacro.CurrentList
filename
#endmacro
#Excel
#define.Star('*')
#define.Space(' ')
// convert into str from excel cell value
str COMVariant2Str(COMVariant _cv, int _decimals = 0, int _characters = 0, int _separator1 = 0, int _separator2 = 0)
{
switch (_cv.variantType())
{
case (COMVariantType::VT_BSTR):
return _cv.bStr();
case (COMVariantType::VT_R4):
return num2str(_cv.float(),_characters,_decimals,_separator1,_separator2);
case (COMVariantType::VT_R8):
return num2str(_cv.double(),_characters,_decimals,_separator1,_separator2);
case (COMVariantType::VT_DECIMAL):
return num2str(_cv.decimal(),_characters,_decimals,_separator1,_separator2);
case (COMVariantType::VT_DATE):
return date2str(_cv.date(),123,2,1,2,1,4);
case (COMVariantType::VT_EMPTY):
return "";
default:
throw error(strfmt("@SYS26908", _cv.variantType()));
}
return "";
}
// Find last row from excel
int findLastRow(SysExcelWorkSheet _workSheet)
{
SysExcelRange range;
;
range = _workSheet.cells().range(#ExcelTotalRange);
try
{
// Finds the row where the first contents is found.
range = range.find(#Star, null, #xlFormulas, #xlWhole, #xlByRows, #xlPrevious);
}
catch (Exception::Error)
{
error("@SYS59926");
return 0;
}
if (range)
{
return range.row();
}
else
{
return 0;
}
}
;
dialogFilename = dialog.addField(extendedtypestr(FilenameOpen));
// DialogJournalType = dialog.addField(enumstr(God_JournalToUpload),"Journal Type");
dialog.filenameLookupFilter(["@SYS28576",#XLS,#Xlsx]);
dialog.filenameLookupTitle("Upload from Excel");
dialogFilename.value(filename);
if(!dialog.run())
return;
filename = dialogFilename.value();
// ttsbegin;
application = SysExcelApplication::construct();
workBooks = application.workbooks();
workBooks.open(filename,0,true);
workSheets = workBooks.item(1).worksheets();
// this.importExcel("Sheet1");
input = "Sheet1";
workSheet = workSheets.itemFromNum(1);//.itemFromName(input);
cells = workSheet.cells();
lastRow = findLastRow(workSheet);
rowIdx = 2;
progress = new SysOperationProgress();
progress.setCaption("Excel Importing");
progress.setTotal(lastRow);
progress.setAnimation(#AviTransfer);
setprefix("Excel Import");
while (rowIdx <= lastRow)
{
setPrefix(strfmt("Excel Row: %1", rowIdx));
c1 = COMVariant2Str(cells.item(rowIdx,1).value());
c2 = COMVariant2Str(cells.item(rowIdx,2).value());
c3 = COMVariant2Str(cells.item(rowIdx,3).value());
c4 = COMVariant2Str(cells.item(rowIdx,4).value());
c5 = COMVariant2Str(cells.item(rowIdx,5).value());
c6 = COMVariant2Str(cells.item(rowIdx,6).value());
c7 = COMVariant2Str(cells.item(rowIdx,7).value());
c8 = COMVariant2Str(cells.item(rowIdx,8).value());
c9 = COMVariant2Str(cells.item(rowIdx,9).value());
c10 = COMVariant2Str(cells.item(rowIdx,10).value());
c11 = COMVariant2Str(cells.item(rowIdx,11).value());
c12 = COMVariant2Str(cells.item(rowIdx,11).value());
linesImported++;
//ttsBegin;
hcmworker = HcmWorker::findByPersonnelNumber(c1);
select firstonly hcmEmployment where hcmEmployment.Worker == hcmworker.RecId;
contractNo = str2int(c2);
if(HcmWorker)
{
ttsBegin;
select forUpdate GOD_EmplContract
where GOD_EmplContract.EmplId == hcmworker.PersonnelNumber
&& GOD_EmplContract.ContractNo == contractNo && GOD_EmplContract.Active == NoYes::Yes;
if(GOD_EmplContract)
{
GOD_EmplContract.ContractNo = contractNo;
GOD_EmplContract.GradeId = c3;
GOD_EmplContract.GradeLevelId = c4;
GOD_EmplContract.BasicSalary = any2real(c5);
GOD_EmplContract.PaymentType = str2enum(PaymentType,c6);
GOD_EmplContract.OrganizationUnitId = c7;
GOD_EmplContract.OMCostCenter= c8;
GOD_EmplContract.EmployeeType = str2enum(GOD_ContractType,c9);
GOD_EmplContract.Validity = str2enum(GOD_ContractValidity,c10);
GOD_EmplContract.ProbationCompleted = str2enum(NoYes,c11);
GOD_EmplContract.ProfileGroupId = c12;
GOD_EmplContract.StartDate = any2date(hcmEmployment.ValidFrom);
GOD_EmplContract.EffectiveDate = any2date(hcmEmployment.ValidFrom);
GOD_EmplContract.update();
}
else
{
GOD_EmplContract.ContractNo = contractNo;
GOD_EmplContract.GradeId = c3;
GOD_EmplContract.GradeLevelId = c4;
GOD_EmplContract.BasicSalary = any2real(c5);
GOD_EmplContract.PaymentType = str2enum(PaymentType,c6);
GOD_EmplContract.OrganizationUnitId = c7;
GOD_EmplContract.OMCostCenter = c8;
GOD_EmplContract.EmployeeType = str2enum(GOD_ContractType,c9);
GOD_EmplContract.Validity = str2enum(GOD_ContractValidity,c10);
GOD_EmplContract.ProbationCompleted = str2enum(NoYes,c11);
GOD_EmplContract.ProfileGroupId = c12;
GOD_EmplContract.EmplId = hcmworker.PersonnelNumber;
GOD_EmplContract.Active = NoYes::Yes;
GOD_EmplContract.StartDate = any2date(hcmEmployment.ValidFrom);
GOD_EmplContract.EffectiveDate = any2date(hcmEmployment.ValidFrom);
GOD_EmplContract.insert();
}
ttsCommit;
}
progress.setText("Importing " + c1);
progress.setCount(linesImported);
rowIdx++;
}
info("done");
}
Upload Customer Region
static void UploadCustomerRegion(Args _args)
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
int row;
CommaTextIO csvFile;
container readCon;
counter icount,updated;
Dialog dialog;
DialogField dfFileName;
FileName fileName;
Name name;
DirPartyContactInfoView contactView;
CustTable CustTable;
DirParty dirParty;
DirPartyRecId partyRecId;
LogisticsPostalAddress address;
DirPartyPostalAddressView addressView;
updated = 0;
#File
application = SysExcelApplication::construct();
workbooks = application.workbooks();
dialog = new Dialog("Pick the file");
dfFileName = dialog.addField(extendedTypeStr("FilenameOpen"));
dialog.filenameLookupFilter(["All files", #AllFiles]);
if (dialog.run())
{
fileName = dfFileName.value() ;
try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error("File cannot be opened.");
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
ttsBegin;
{
row++;
name = strLRTrim(cells.item(row, 2).value().bStr());
partyRecId = DirPartyTable::createNew( DirPartyType::Organization, name).RecId;
custTable.clear();
custTable.initValue();
custTable.Party = partyRecId;
custTable.AccountNum = strLRTrim(cells.item(row, 1).value().bStr());
custTable.CustGroup = strLRTrim(cells.item(row, 3).value().bStr());
custTable.Currency = strLRTrim(cells.item(row, 4).value().bStr());
custTable.DlvMode = strLRTrim(cells.item(row, 5).value().bStr());
custTable.PaymTermId = strLRTrim(cells.item(row, 6).value().bStr());
custTable.update();
custTable = Custtable::find(strLRTrim(cells.item(row, 1).value().bStr()));
partyRecId = custTable.Party;
DirParty = DirParty::constructFromPartyRecId(partyRecId );
address.clear();
//address.PostBox = strLRTrim(conPeek(readCon,13));
address.CountryRegionId = strLRTrim(cells.item(row, 7).value().bStr());
if( address.CountryRegionId != "")
{
address.State = strLRTrim(cells.item(row, 8).value().bStr());
address.ZipCode = strLRTrim(cells.item(row, 9).value().bStr());
address.Street = strLRTrim(cells.item(row, 10).value().bStr());
address.City = strLRTrim(cells.item(row, 11).value().bStr());
//address.Address = conPeek(readCon,4);
addressView.LocationName = "Address";
addressView.IsPrimary = NoYes::Yes;
addressView.Party = partyRecId;
addressview.initFromPostalAddress(address);
DirParty = DirParty::constructFromPartyRecId(addressView.Party );
DirParty.createOrUpdatePostalAddress(addressView);
}
contactView.clear();
if(strLRTrim(cells.item(row, 12).value().bStr()) != "")
{
contactView.LocationName = "Phone Number";
contactView.Locator = strLRTrim(cells.item(row, 12).value().bStr());
contactView.Type = LogisticsElectronicAddressMethodType::Phone;
contactView.Party = partyRecId;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
}
if(strLRTrim(cells.item(row, 13).value().bStr()) != "")
{
contactView.LocationName = "Fax Number";
contactView.Locator = strLRTrim(cells.item(row, 13).value().bStr());
contactView.Type = LogisticsElectronicAddressMethodType::Fax;
contactView.Party = partyRecId;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
}
if(strLRTrim(cells.item(row, 14).value().bStr()) != "")
{
contactView.LocationName = "Website";
contactView.Locator = strLRTrim(cells.item(row, 14).value().bStr());
contactView.Type = LogisticsElectronicAddressMethodType::URL;
contactView.Party = partyRecId;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
}
if(strLRTrim(cells.item(row, 15).value().bStr())!= "")
{
contactView.LocationName = "Email";
contactView.Locator = strLRTrim(cells.item(row, 15).value().bStr());
contactView.Type = LogisticsElectronicAddressMethodType::Email;
contactView.Party = partyRecId;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
}
}
ttsCommit;
}
}
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
int row;
CommaTextIO csvFile;
container readCon;
counter icount,updated;
Dialog dialog;
DialogField dfFileName;
FileName fileName;
Name name;
DirPartyContactInfoView contactView;
CustTable CustTable;
DirParty dirParty;
DirPartyRecId partyRecId;
LogisticsPostalAddress address;
DirPartyPostalAddressView addressView;
updated = 0;
#File
application = SysExcelApplication::construct();
workbooks = application.workbooks();
dialog = new Dialog("Pick the file");
dfFileName = dialog.addField(extendedTypeStr("FilenameOpen"));
dialog.filenameLookupFilter(["All files", #AllFiles]);
if (dialog.run())
{
fileName = dfFileName.value() ;
try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error("File cannot be opened.");
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
ttsBegin;
{
row++;
name = strLRTrim(cells.item(row, 2).value().bStr());
partyRecId = DirPartyTable::createNew( DirPartyType::Organization, name).RecId;
custTable.clear();
custTable.initValue();
custTable.Party = partyRecId;
custTable.AccountNum = strLRTrim(cells.item(row, 1).value().bStr());
custTable.CustGroup = strLRTrim(cells.item(row, 3).value().bStr());
custTable.Currency = strLRTrim(cells.item(row, 4).value().bStr());
custTable.DlvMode = strLRTrim(cells.item(row, 5).value().bStr());
custTable.PaymTermId = strLRTrim(cells.item(row, 6).value().bStr());
custTable.update();
custTable = Custtable::find(strLRTrim(cells.item(row, 1).value().bStr()));
partyRecId = custTable.Party;
DirParty = DirParty::constructFromPartyRecId(partyRecId );
address.clear();
//address.PostBox = strLRTrim(conPeek(readCon,13));
address.CountryRegionId = strLRTrim(cells.item(row, 7).value().bStr());
if( address.CountryRegionId != "")
{
address.State = strLRTrim(cells.item(row, 8).value().bStr());
address.ZipCode = strLRTrim(cells.item(row, 9).value().bStr());
address.Street = strLRTrim(cells.item(row, 10).value().bStr());
address.City = strLRTrim(cells.item(row, 11).value().bStr());
//address.Address = conPeek(readCon,4);
addressView.LocationName = "Address";
addressView.IsPrimary = NoYes::Yes;
addressView.Party = partyRecId;
addressview.initFromPostalAddress(address);
DirParty = DirParty::constructFromPartyRecId(addressView.Party );
DirParty.createOrUpdatePostalAddress(addressView);
}
contactView.clear();
if(strLRTrim(cells.item(row, 12).value().bStr()) != "")
{
contactView.LocationName = "Phone Number";
contactView.Locator = strLRTrim(cells.item(row, 12).value().bStr());
contactView.Type = LogisticsElectronicAddressMethodType::Phone;
contactView.Party = partyRecId;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
}
if(strLRTrim(cells.item(row, 13).value().bStr()) != "")
{
contactView.LocationName = "Fax Number";
contactView.Locator = strLRTrim(cells.item(row, 13).value().bStr());
contactView.Type = LogisticsElectronicAddressMethodType::Fax;
contactView.Party = partyRecId;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
}
if(strLRTrim(cells.item(row, 14).value().bStr()) != "")
{
contactView.LocationName = "Website";
contactView.Locator = strLRTrim(cells.item(row, 14).value().bStr());
contactView.Type = LogisticsElectronicAddressMethodType::URL;
contactView.Party = partyRecId;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
}
if(strLRTrim(cells.item(row, 15).value().bStr())!= "")
{
contactView.LocationName = "Email";
contactView.Locator = strLRTrim(cells.item(row, 15).value().bStr());
contactView.Type = LogisticsElectronicAddressMethodType::Email;
contactView.Party = partyRecId;
contactView.IsPrimary = NoYes::Yes;
dirParty.createOrUpdateContactInfo(contactView);
}
}
ttsCommit;
}
}
Wednesday, July 24, 2019
Update Journal Trans date
static void Job34(Args _args)
{
InventJournalTrans InventJournalTrans;
while select forUpdate InventJournalTrans
where InventJournalTrans.JournalId == 'JOUR-00011'
{
//info("hi");
InventJournalTrans.TransDate = str2Date('30/11/2017',123);
InventJournalTrans.update();
}
info("done");
}
{
InventJournalTrans InventJournalTrans;
while select forUpdate InventJournalTrans
where InventJournalTrans.JournalId == 'JOUR-00011'
{
//info("hi");
InventJournalTrans.TransDate = str2Date('30/11/2017',123);
InventJournalTrans.update();
}
info("done");
}
Journal number with dataarea id
static void Job29(Args _args)
{
VendTrans VendTrans;
VendSettlement VendSettlement;
ledgerJournalTrans ledgerJournalTrans;
while select VendTrans
join VendSettlement
join ledgerJournalTrans
where
vendtrans.voucher == ledgerJournalTrans.Voucher
&& VendSettlement.TransCompany == VendTrans.dataAreaId
&& VendSettlement.TransRecId == VendTrans.RecId
&& VendSettlement.AccountNum == VendTrans.AccountNum
{
info(ledgerJournalTrans.JournalNum);
info(VendTrans.dataAreaId);
}
}
{
VendTrans VendTrans;
VendSettlement VendSettlement;
ledgerJournalTrans ledgerJournalTrans;
while select VendTrans
join VendSettlement
join ledgerJournalTrans
where
vendtrans.voucher == ledgerJournalTrans.Voucher
&& VendSettlement.TransCompany == VendTrans.dataAreaId
&& VendSettlement.TransRecId == VendTrans.RecId
&& VendSettlement.AccountNum == VendTrans.AccountNum
{
info(ledgerJournalTrans.JournalNum);
info(VendTrans.dataAreaId);
}
}
Monthly Attendance Infolog
static void MonthlyAttendance(Args _args)
{
GOD_EmplMonthlyAttendanceTmp emplMonthlyAttendanceTmp;
select * from emplMonthlyAttendanceTmp
where emplMonthlyAttendanceTmp.EmplId == "120009"
//emplTable.PersonnelNumber
&& emplMonthlyAttendanceTmp.Type == "@SYS5921";
{
info(strFmt("%1",emplMonthlyAttendanceTmp.Day19));
}
}
{
GOD_EmplMonthlyAttendanceTmp emplMonthlyAttendanceTmp;
select * from emplMonthlyAttendanceTmp
where emplMonthlyAttendanceTmp.EmplId == "120009"
//emplTable.PersonnelNumber
&& emplMonthlyAttendanceTmp.Type == "@SYS5921";
{
info(strFmt("%1",emplMonthlyAttendanceTmp.Day19));
}
}
Tuesday, July 23, 2019
Vendor transaction amount
static void VendorAmount(Args _args)
{
vendTrans vendTrans;
vendTransOpen vendTransOpen;
select vendtrans
where vendTrans.AccountNum == 'V0191'
join sum(AmountCur)
from vendTransOpen
where vendTransOpen.RefRecId == vendTrans.RecId;
info(strFmt('%1',vendTransOpen.AmountCur));
/*
select CurrencyCode
from vendTrans
group by CurrencyCode
where vendTrans.AccountNum == _accountNum
join sum(AmountCur), sum(AmountMST)
from vendTransOpen
where vendTransOpen.RefRecId == vendTrans.RecId
*/
}
{
vendTrans vendTrans;
vendTransOpen vendTransOpen;
select vendtrans
where vendTrans.AccountNum == 'V0191'
join sum(AmountCur)
from vendTransOpen
where vendTransOpen.RefRecId == vendTrans.RecId;
info(strFmt('%1',vendTransOpen.AmountCur));
/*
select CurrencyCode
from vendTrans
group by CurrencyCode
where vendTrans.AccountNum == _accountNum
join sum(AmountCur), sum(AmountMST)
from vendTransOpen
where vendTransOpen.RefRecId == vendTrans.RecId
*/
}
Customer Credit Limit
static void CustCreditLimit(Args _args)
{
custCreditLimit custCreditLimit;
custCreditLimit = CustCreditLimit::construct(custtable::find('C-01977'));
//custCreditLimit.calcCreditAvailable()/custtable.CreditMax * 100) <= CustParameters::find().GOD_CreditLimitThresold )
info(strFmt('%1',custCreditLimit.calcCreditAvailable()));
info(strFmt('%1',custCreditLimit.getBalance()));
}
{
custCreditLimit custCreditLimit;
custCreditLimit = CustCreditLimit::construct(custtable::find('C-01977'));
//custCreditLimit.calcCreditAvailable()/custtable.CreditMax * 100) <= CustParameters::find().GOD_CreditLimitThresold )
info(strFmt('%1',custCreditLimit.calcCreditAvailable()));
info(strFmt('%1',custCreditLimit.getBalance()));
}
Print Sales Invoice
static void PrintSalesInvoice(Args _args)
{
Args salesArgs = new Args();
SalesInvoiceContract salesInvoiceContract;
SalesInvoiceController controller;
SrsReportRunImpl srsReportRunImpl;
str fileName;
CustInvoiceJour custInvoiceJour = _args.record();
// select custInvoiceJour where custInvoiceJour.InvoiceId=="GH-INV-000107";
salesArgs.record(custInvoiceJour);
controller = new SrsReportRunController();
salesInvoiceContract = new SalesInvoiceContract();
controller.parmReportName(ssrsReportStr(SalesInvoice,ReportGH));
controller.parmShowDialog(true);
controller.parmReportContract().parmPrintSettings().printMediumType(SRSPrintMediumType::Printer);
// controller.parmReportContract().parmPrintSettings().printerName(@"\\espprn03\Follow Me - MFP");
salesInvoiceContract.parmRecordId(custInvoiceJour.RecId); // Record id must be passed otherwise the report will be empty
salesInvoiceContract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo()); // comment this code if tested in pre release
controller.parmReportContract().parmRdpContract(salesInvoiceContract);
controller.startOperation();
}
{
Args salesArgs = new Args();
SalesInvoiceContract salesInvoiceContract;
SalesInvoiceController controller;
SrsReportRunImpl srsReportRunImpl;
str fileName;
CustInvoiceJour custInvoiceJour = _args.record();
// select custInvoiceJour where custInvoiceJour.InvoiceId=="GH-INV-000107";
salesArgs.record(custInvoiceJour);
controller = new SrsReportRunController();
salesInvoiceContract = new SalesInvoiceContract();
controller.parmReportName(ssrsReportStr(SalesInvoice,ReportGH));
controller.parmShowDialog(true);
controller.parmReportContract().parmPrintSettings().printMediumType(SRSPrintMediumType::Printer);
// controller.parmReportContract().parmPrintSettings().printerName(@"\\espprn03\Follow Me - MFP");
salesInvoiceContract.parmRecordId(custInvoiceJour.RecId); // Record id must be passed otherwise the report will be empty
salesInvoiceContract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo()); // comment this code if tested in pre release
controller.parmReportContract().parmRdpContract(salesInvoiceContract);
controller.startOperation();
}
Update Item Family
static void GOD_UpdateItemFamily(Args _args)
{
#AviFiles
FilenameOpen filename;
dialogField dialogFilename;
Dialog dialog= new Dialog("Excel Upoad");
Container excelCont[];
str valuestr;
int rowIdx;
Counter linesImported;
int lastRow,dimcount;
boolean ok = true;
NoYes noYes;
str 50 c1,c2,c12;
real c3,c4,c5;
str input;
container accEntryPattern;
InventItemBarcode inventItemBarcodeCreate;
NumberSeq numberSeq;
SysExcelApplication application;
SysExcelWorkBooks workBooks;
SysExcelWorkSheets workSheets;
SysExcelWorkSheet workSheet;
SysExcelCells cells;
SysOperationProgress progress;
InventTable _InventTable,_InventTableupdate;
//GOD_ItemFamilyMaster _GOD_ItemFamilyMaster;
struct struct= new Struct();
DocuRef docuRef;
DocuValue docuValue;
System.String[] fileNames;
int fileCount, i;
str ImagefileName, trimmedFileName, fileNameWithExt;
BinData binData = new BinData();
str extention, path, nameOfFile;
container imageContainer;
str imageFilePathName,FileImageName;
#define.CurrentVersion(1)
#localmacro.CurrentList
filename
#endmacro
#Excel
#define.Star('*')
#define.Space(' ')
// convert into str from excel cell value
str COMVariant2Str(COMVariant _cv, int _decimals = 0, int _characters = 0, int _separator1 = 0, int _separator2 = 0)
{
switch (_cv.variantType())
{
case (COMVariantType::VT_BSTR):
return _cv.bStr();
case (COMVariantType::VT_R4):
return num2str(_cv.float(),_characters,_decimals,_separator1,_separator2);
case (COMVariantType::VT_R8):
return num2str(_cv.double(),_characters,_decimals,_separator1,_separator2);
//case COMVariantType::VT_R4 :
//case COMVariantType::VT_R8 :
//
//if(_cv.double())
//{
//valueStr = strFmt("@SYS311964",
//num2Str0(_cv.double(), 0),
//num2str(_cv.double(),
//0,
//numOfDec(_cv.double()),
//1,
//0));
//}
//return valuestr;
//break;
case (COMVariantType::VT_DECIMAL):
return num2str(_cv.decimal(),_characters,_decimals,_separator1,_separator2);
case (COMVariantType::VT_DATE):
return date2str(_cv.date(),123,2,1,2,1,4);
case (COMVariantType::VT_EMPTY):
return "";
default:
throw error(strfmt("@SYS26908", _cv.variantType()));
}
return "";
}
// Find last row from excel
int findLastRow(SysExcelWorkSheet _workSheet)
{
SysExcelRange range;
;
range = _workSheet.cells().range(#ExcelTotalRange);
try
{
// Finds the row where the first contents is found.
range = range.find(#Star, null, #xlFormulas, #xlWhole, #xlByRows, #xlPrevious);
}
catch (Exception::Error)
{
error("@SYS59926");
return 0;
}
if (range)
{
return range.row();
}
else
{
return 0;
}
}
;
dialogFilename = dialog.addField(extendedtypestr(FilenameOpen));
dialog.filenameLookupFilter(["@SYS28576", #XLSX, "@SYS28576", #XLS]);
dialog.filenameLookupTitle("Upload from Excel");
dialogFilename.value(filename);
if(!dialog.run())
return;
filename = dialogFilename.value();
//ttsbegin;
application = SysExcelApplication::construct();
workBooks = application.workbooks();
workBooks.open(filename,0,true);
workSheets = workBooks.item(1).worksheets();
input = "Sheet1";
workSheet = workSheets.itemFromNum(1);
cells = workSheet.cells();
lastRow = findLastRow(workSheet);
rowIdx = 2;
progress = new SysOperationProgress();
progress.setCaption("Excel Importing");
progress.setTotal(lastRow);
progress.setAnimation(#AviTransfer);
setprefix("Excel Import");
try
{
while (rowIdx <= lastRow)
{
setPrefix(strfmt("Excel Row: %1", rowIdx));
c1 = COMVariant2Str(cells.item(rowIdx,1).value());
c2 = COMVariant2Str(cells.item(rowIdx,2).value());
c3 = cells.item(rowIdx,3).value().double();
c4 = cells.item(rowIdx,4).value().double();
c5 = cells.item(rowIdx,5).value().double();
linesImported++;
progress.setText("Importing " + c12);
progress.setCount(linesImported);
rowIdx++;
dimcount =0;
select firstOnly _InventTable where _InventTable.ItemId == c1;
if (_InventTable)
{
ttsBegin;
select forUpdate _InventTableupdate
where _InventTableupdate.ItemId == _InventTable.ItemId;
//if (c2)
// select firstonly _GOD_ItemFamilyMaster where _GOD_ItemFamilyMaster.Code == c2;
//if(_GOD_ItemFamilyMaster)
//_InventTableupdate.GOD_FamilyCode = c2;
if (c3)
_InventTableupdate.grossDepth =c3;
if(c4)
_InventTableupdate.grossWidth = c4;
if(c5)
_InventTableupdate.grossHeight = c5;
_InventTableupdate.update();
ttsCommit;
}
}
}
catch
{
info(strFmt("Error at line %1",rowIdx-1));
}
application.quit();
application = null;
//ttscommit;
info(strFmt("done %1",rowIdx-2));
}
{
#AviFiles
FilenameOpen filename;
dialogField dialogFilename;
Dialog dialog= new Dialog("Excel Upoad");
Container excelCont[];
str valuestr;
int rowIdx;
Counter linesImported;
int lastRow,dimcount;
boolean ok = true;
NoYes noYes;
str 50 c1,c2,c12;
real c3,c4,c5;
str input;
container accEntryPattern;
InventItemBarcode inventItemBarcodeCreate;
NumberSeq numberSeq;
SysExcelApplication application;
SysExcelWorkBooks workBooks;
SysExcelWorkSheets workSheets;
SysExcelWorkSheet workSheet;
SysExcelCells cells;
SysOperationProgress progress;
InventTable _InventTable,_InventTableupdate;
//GOD_ItemFamilyMaster _GOD_ItemFamilyMaster;
struct struct= new Struct();
DocuRef docuRef;
DocuValue docuValue;
System.String[] fileNames;
int fileCount, i;
str ImagefileName, trimmedFileName, fileNameWithExt;
BinData binData = new BinData();
str extention, path, nameOfFile;
container imageContainer;
str imageFilePathName,FileImageName;
#define.CurrentVersion(1)
#localmacro.CurrentList
filename
#endmacro
#Excel
#define.Star('*')
#define.Space(' ')
// convert into str from excel cell value
str COMVariant2Str(COMVariant _cv, int _decimals = 0, int _characters = 0, int _separator1 = 0, int _separator2 = 0)
{
switch (_cv.variantType())
{
case (COMVariantType::VT_BSTR):
return _cv.bStr();
case (COMVariantType::VT_R4):
return num2str(_cv.float(),_characters,_decimals,_separator1,_separator2);
case (COMVariantType::VT_R8):
return num2str(_cv.double(),_characters,_decimals,_separator1,_separator2);
//case COMVariantType::VT_R4 :
//case COMVariantType::VT_R8 :
//
//if(_cv.double())
//{
//valueStr = strFmt("@SYS311964",
//num2Str0(_cv.double(), 0),
//num2str(_cv.double(),
//0,
//numOfDec(_cv.double()),
//1,
//0));
//}
//return valuestr;
//break;
case (COMVariantType::VT_DECIMAL):
return num2str(_cv.decimal(),_characters,_decimals,_separator1,_separator2);
case (COMVariantType::VT_DATE):
return date2str(_cv.date(),123,2,1,2,1,4);
case (COMVariantType::VT_EMPTY):
return "";
default:
throw error(strfmt("@SYS26908", _cv.variantType()));
}
return "";
}
// Find last row from excel
int findLastRow(SysExcelWorkSheet _workSheet)
{
SysExcelRange range;
;
range = _workSheet.cells().range(#ExcelTotalRange);
try
{
// Finds the row where the first contents is found.
range = range.find(#Star, null, #xlFormulas, #xlWhole, #xlByRows, #xlPrevious);
}
catch (Exception::Error)
{
error("@SYS59926");
return 0;
}
if (range)
{
return range.row();
}
else
{
return 0;
}
}
;
dialogFilename = dialog.addField(extendedtypestr(FilenameOpen));
dialog.filenameLookupFilter(["@SYS28576", #XLSX, "@SYS28576", #XLS]);
dialog.filenameLookupTitle("Upload from Excel");
dialogFilename.value(filename);
if(!dialog.run())
return;
filename = dialogFilename.value();
//ttsbegin;
application = SysExcelApplication::construct();
workBooks = application.workbooks();
workBooks.open(filename,0,true);
workSheets = workBooks.item(1).worksheets();
input = "Sheet1";
workSheet = workSheets.itemFromNum(1);
cells = workSheet.cells();
lastRow = findLastRow(workSheet);
rowIdx = 2;
progress = new SysOperationProgress();
progress.setCaption("Excel Importing");
progress.setTotal(lastRow);
progress.setAnimation(#AviTransfer);
setprefix("Excel Import");
try
{
while (rowIdx <= lastRow)
{
setPrefix(strfmt("Excel Row: %1", rowIdx));
c1 = COMVariant2Str(cells.item(rowIdx,1).value());
c2 = COMVariant2Str(cells.item(rowIdx,2).value());
c3 = cells.item(rowIdx,3).value().double();
c4 = cells.item(rowIdx,4).value().double();
c5 = cells.item(rowIdx,5).value().double();
linesImported++;
progress.setText("Importing " + c12);
progress.setCount(linesImported);
rowIdx++;
dimcount =0;
select firstOnly _InventTable where _InventTable.ItemId == c1;
if (_InventTable)
{
ttsBegin;
select forUpdate _InventTableupdate
where _InventTableupdate.ItemId == _InventTable.ItemId;
//if (c2)
// select firstonly _GOD_ItemFamilyMaster where _GOD_ItemFamilyMaster.Code == c2;
//if(_GOD_ItemFamilyMaster)
//_InventTableupdate.GOD_FamilyCode = c2;
if (c3)
_InventTableupdate.grossDepth =c3;
if(c4)
_InventTableupdate.grossWidth = c4;
if(c5)
_InventTableupdate.grossHeight = c5;
_InventTableupdate.update();
ttsCommit;
}
}
}
catch
{
info(strFmt("Error at line %1",rowIdx-1));
}
application.quit();
application = null;
//ttscommit;
info(strFmt("done %1",rowIdx-2));
}
Subscribe to:
Posts (Atom)