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
        }

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;
}

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;
}

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 ;
}


---------------------------------------------



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));
}

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;
}

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()));

        }
    }


}

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");
}

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;
    }
}