locked
create purchOrder programmatically using connectvity studio classes. RRS feed

  • Question

  • void documentReadFinish(AppDataDocument theDocument)
    {
        str             supplierID;
        NumberSeq       num;
        PurchId         tmpPurchId;

        ;
        try
        {
            supplierID = '';

            ttsbegin;
            while select * from lIQ_TempPurchLineItem order by  lIQ_TempPurchLineItem.SupplierID asc
            {
                if (supplierID != lIQ_TempPurchLineItem.SupplierID)
                {
                    supplierID = lIQ_TempPurchLineItem.SupplierID;

                    //Create Purchase Table
                    purchTable.clear();
                    purchTable.initValue();

                    num = NumberSeq::newGetNum(PurchParameters::numRefPurchId());
                    tmpPurchId = num.num();

                    if (PurchTable::exist(tmpPurchId))
                    {
                        num.abort();
                        checkFailed("@SYS19304");
                        checkFailed(strfmt("@SYS24176", tmpPurchId));
                        throw error("@SYS23020");
                    }

                    purchTable.PurchId = tmpPurchId;
                    num.used();

                    select * from vendTable where vendTable.AccountNum == lIQ_TempPurchLineItem.SupplierID;

                    purchTable.initFromVendTable(vendTable);

                    if (purchTable.InvoiceAccount != this.invoiceAccount())
                    {
                        purchTable.InvoiceAccount = this.invoiceAccount();
                        purchTable.initInvoiceAccount();
                    }

                    purchTable.OrderAccount    = lIQ_TempPurchLineItem.SupplierID;
                    purchTable.InventSiteId    = lIQ_TempPurchLineItem.StoreNo;
                    purchTable.InventLocationId = lIQ_TempPurchLineItem.StoreNo;
                    purchTable.ShippingDateRequested = systemdateget();
                    purchTable.ShippingDateConfirmed = systemdateget();
                    purchTable.PurchStatus = purchStatus::Backorder;
                    purchTable.PurchaseType = PurchaseType::Purch;
                    purchTable.insert();


                }

         //Create Purchase Line
         purchLine.initFromPurchTable(purchTable);
         purchline.PurchStatus = purchStatus::Backorder;

         select inventTable where inventTable.ItemId == lIQ_TempPurchLineItem.ProductNo;

         purchLine.ItemId     = lIQ_TempPurchLineItem.ProductNo;

         purchline.initFromInventTable(inventTable);
         select inventDim where inventDim.InventLocationId == purchTable.InventLocationId && inventdim.InventSiteId == purchTable.InventSiteId;

         purchLine.InventDimId = inventDim.inventDimId;
         purchLine.PurchQty   = str2int(lIQ_TempPurchLineItem.Quantity);
         purchLine.QtyOrdered = str2int(lIQ_TempPurchLineItem.Quantity);
         purchLine.RemainInventPhysical = str2int(lIQ_TempPurchLineItem.Quantity);
         purchline.RemainPurchPhysical  = str2int(lIQ_TempPurchLineItem.Quantity);

         purchLine.insert();

        }
            //Delete from Temp table
            delete_from lIQ_TempPurchLineItem;
            ttscommit;

        }
        catch(Exception::Error)
        {
            ttsabort;
            this.writeToException(Exception::Error);
        }
    }


    Raghu Rama Raju.ch
    Thursday, August 12, 2010 12:47 AM

Answers