Wednesday, 31 October 2018

registration of sales return order by x++

public void createRegisterline(SalesTable _salestable)
{
    Integer                                 lastRec = 0;
    SalesId                                 oldSalesId;
    inventTrans                             inventTrans;
    SalesFormLetter                         salesFormLetter;
    inventTransOrigin                       inventTransOrigin;
    TradeOrderLineRegister                  tradeOrderlineRegister;
    SON_SalesReturnOrderLineRegister        salesReturnOrderLineRegister;
    InventTransWMS_Register                 inventTransWMS_register;
    TmpInventTransWMS                       TmpInventTransWMS;
    SalesLine                               salesLineReg;
    ReturnDispositionCode                   returnDispositionCode;
    SON_IPB49_InventStkTransHeader          headerTable,headerTableLoc;
    Description255                          errorMsg;

    Args                                    args = new Args();

    try
    {
        ttsBegin;
        select firstOnly * from returnDispositionCode
            where returnDispositionCode.DispositionAction == DispositionAction::Credit;

        while  select forUpdate salesLineReg
            where _salestable.SalesId  == salesLineReg.SalesId
            && _salestable.SalesType == SalesType::ReturnItem
        {
            try
            {

                args.record(salesLineReg);

                tradeOrderLineRegister = SON_SalesReturnOrderLineRegister::construct();
                tradeOrderLineRegister.parmArgs(args);
                tradeOrderLineRegister.init();
                salesReturnOrderLineRegister = tradeOrderLineRegister;
                salesReturnOrderLineRegister.runPreSuper();

                //update returnDisposioncode
                salesLineReg.ReturnDispositionCodeId = returnDispositionCode.DispositionCodeId;
                salesLineReg.update();

                select firstOnly crossCompany inventTrans
                    join RecId,InventTransId from inventTransOrigin
                        where inventTransOrigin.InventTransId == salesLineReg.InventTransId
                        && inventTrans.InventTransOrigin == inventTransOrigin.RecId;

                inventTransWMS_register = inventTransWMS_register::newStandard(tmpInventTransWMS);
                tmpInventTransWMS.clear();
                tmpInventTransWMS.initFromInventTrans(inventTrans);
                tmpInventTransWMS.InventDimId = inventTrans.InventDimId;
                tmpInventTransWMS.insert();
                inventTransWMS_register.writeTmpInventTransWMS(tmpInventTransWMS,
                                                               inventTrans,
                                                               inventTrans.inventDim());
                inventTransWMS_register.updateInvent(salesLineReg);
            }
            catch
            {
                continue;
            }
        }


        ttsCommit;
    }
    catch
    {

    }
}

sales return by x++

public void createReturnOrder(PurchTable _purchtable)
{
    SalesLine                           salesLine;
    SalesTable                          salesTable, salesTableloc;
    SalesParameters                     salesParameters;
    ReturnPeriodOfValidity              periodofValid;
    SON_AttachmentELMOInvoice   attachmentELMOInvoiceloc, attachmentELMOSumQty,SON_AttachmentELMOInvoice;
    SON_ELMOSummaryInvoice  SON_ELMOSummaryInvoice;
    AxSalesTable            axsalesTable;
    AxSalesLine axSalesLine;
    SalesFormLetter salesFormLetter;
    PurchTable PurchTableLocal;
    PurchFormLetter purchFormLetter;
    SON_ELMOISalesTable SON_ELMOISalesTable;
    SON_DeliveryNote    SON_DeliveryNote;

    try
    {
        salesParameters = SalesParameters::find();
        periodofValid   = salesParameters.ReturnPeriodOfValidity;

        select SON_ELMOSummaryInvoice  where SON_ELMOSummaryInvoice.AXPONumber == _purchtable.PurchId;

        while select SON_AttachmentELMOInvoice group by StoreID
            where SON_AttachmentELMOInvoice.SummaryInvoiceNumber == SON_ELMOSummaryInvoice.InvoiceNumber
                && SON_AttachmentELMOInvoice.InvoiceDate == SON_ELMOSummaryInvoice.InvoiceDate
        {

            //insert sales table
            {
                salesParameters = SalesParameters::find();
                periodofValid   = salesParameters.ReturnPeriodOfValidity;
                salesTable.SON_StoreId = SON_AttachmentELMOInvoice.StoreID;
                salesTable.SON_VendAccount = _purchTable.OrderAccount;
                salesTable.SON_PBSalesOrder=NoYes::Yes;
                salesTable.CustAccount             = RetailStoreTable::find(SON_AttachmentELMOInvoice.StoreID).SON_DefaultCustAccount;
                salesTable.InvoiceAccount          = salesTable.CustAccount;
                salesTable.SalesId                 = NumberSeq::newGetNum(SalesParameters::numRefSalesId()).num();
                salesTable.ReturnItemNum           = salesTable.SalesId;
                salesTable.SalesType               = SalesType::ReturnItem;
                salesTable.ReturnStatus            = ReturnStatusHeader::Created;
                salesTable.DeliveryDateControlType = SalesDeliveryDateControlType::None;
                salesTable.SON_InvStkTrans         = NoYes::Yes;
                salesTable.ShippingDateRequested   = today();
                salesTable.ShippingDateConfirmed   = salesTable.ShippingDateRequested;
                salesTable.ReceiptDateConfirmed    = salesTable.ShippingDateRequested;
                salesTable.ReceiptDateRequested    = salesTable.ShippingDateRequested;

                salesTable.initFromCustTable();
                salesTable.ReturnDeadline          = salesTable.ShippingDateRequested;
                salesTable.InventLocationId        = InventParameters::find().SON_DD;
                salesTable.InventSiteId            = InventLocation::find(salesTable.InventLocationId).InventSiteId;
                salesTable.DefaultDimension        = SON_InventStockTransfer::getStoreCostCenter(salesTable.SON_StoreId);
                axsalesTable = AxSalesTable::newSalesTable(salesTable);
                axsalesTable.parmSON_StoreOrderType(SON_StoreOrderType::ELMO);
                axsalesTable.doSave();

                SON_ELMOISalesTable.clear();
                SON_ELMOISalesTable.PurchId = _purchTable.PurchId;
                SON_ELMOISalesTable.SalesId = salesTable.SalesId;
                SON_ELMOISalesTable.CustAccount = salesTable.CustAccount;
                SON_ELMOISalesTable.insert();

            }

            //insert lines
            while select attachmentELMOInvoiceloc where attachmentELMOInvoiceloc.StoreID == SON_AttachmentELMOInvoice.StoreID
                && attachmentELMOInvoiceloc.SummaryInvoiceNumber == SON_ELMOSummaryInvoice.InvoiceNumber
                && attachmentELMOInvoiceloc.InvoiceDate == SON_ELMOSummaryInvoice.InvoiceDate
                {
                    //insert saleslines
                    salesLine.clear();
                    salesLine.initValue();
                    salesLine.initFromSalesTable(salesTable);
                    salesLine.initFromCustTable();
                    salesLine.initFromSalesTable(salesTable);
                    salesLine.ItemId            = this.GetEANCode(attachmentELMOInvoiceloc);
                    salesLine.SON_EANCode       = attachmentELMOInvoiceloc.EANCode;
                    salesLine.SalesUnit         = InventTableModule::find(salesLine.ItemId, ModuleInventPurchSales::Invent).UnitId;
                    salesLine.DefaultDimension  = SON_InventStockTransfer::salesLineDefaultDimension(salesTable, InventTable::find(salesLine.ItemId));
                    salesLine.SalesQty          = attachmentELMOInvoiceloc.InvoicedQty;
                    salesLine.ExpectedRetQty    = salesLine.SalesQty;
                    salesLine.LineAmount        = attachmentELMOInvoiceloc.VendorInvoiceAmt;
                    salesLine.SON_deliveryNote  = attachmentELMOInvoiceloc.DeliveryNote;
                    axSalesLine                 = AxSalesLine::newSalesLine(salesLine);
                    axSalesLine.Save();

                }//while select attachmentELMOInvoiceloc

                attachmentELMOInvoiceloc.clear();

                select firstOnly attachmentELMOInvoiceloc  where attachmentELMOInvoiceloc.SummaryInvoiceNumber == SON_ELMOSummaryInvoice.InvoiceNumber
                && attachmentELMOInvoiceloc.InvoiceDate == SON_ELMOSummaryInvoice.InvoiceDate;

                // for client testing
                delete_from SON_DeliveryNote;
                SON_DeliveryNote.DeliveryNote = attachmentELMOInvoiceloc.DeliveryNote;
                SON_DeliveryNote.insert();
                // for client testing

                ttsBegin;
                select forUpdate salesTableloc  where salesTableloc.SalesId == salesTable.SalesId;
                salesTableloc.SON_deliveryNote = attachmentELMOInvoiceloc.DeliveryNote;
                salesTableloc.doUpdate();
                ttsCommit;

            salesFormLetter = SalesFormLetter::construct(DocumentStatus::Confirmation);
            salesFormLetter.update(SalesTable::find(salesTable.SalesId), today());
            changeCompany (salesTable.InterCompanyCompanyId)
            {
                select  crossCompany  PurchTableLocal
                where PurchTableLocal.dataAreaId  == salesTable.InterCompanyCompanyId
                &&    PurchTableLocal.PurchId == salesTable.InterCompanyPurchId;

                // PO confirmation
                purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
                purchFormLetter.update(PurchTableLocal, strFmt("POConfirm_%1",PurchTableLocal.PurchId));
                info(strFmt("purchase order %1 confirmed succssfully.",PurchTableLocal.PurchId));

                // PO packing slip
                // purchFormLetter = PurchFormLetter::construct(DocumentStatus::PackingSlip);
                // purchFormLetter.update(PurchTableLocal, strFmt("POPack_%1", PurchTableLocal.PurchId));
                // this.partialPOPacking(PurchTableLocal.PurchId);
                // info(strFmt("purchase order %1 packing slip posted succssfully.",PurchTableLocal.PurchId));

            }//change company
            this.createRegisterline(salesTable);
            this.partialSOPacking(salesTable, _purchTable );

        }
    }
    catch
    {

         warning("error found while creating sales order for purchase order");
    }

  //  return isSuccess;
}

Wednesday, 10 October 2018

code for posting partial packing slip for intercompany PO

say we have a sales order and we have created  a partial packing slip for the sales order  and want to  post packing slip for the relevant purchline with the same  packing slip.


static void Job203(Args _args)
{   

    CustPackingSlipJour CustPackingSlipJour;


    select CustPackingSlipJour  where CustPackingSlipJour.SalesId == "00001283"
    && CustPackingSlipJour.PackingSlipId == "TT43953408";
    if(CustPackingSlipJour)
    {
        CustPackingSlipJour::interCompanyUpdateIL([custPackingSlipJour]);
    }

    info("done");

}

intercompany PO multiple product receipt by x++

public void processStampICPO(PackingSlipId _deliveryNote,                             Transdate _deliverydate,                             ...