Difference between revisions of "Delphi Sales Orders"

From Sage Evolution SDK | Documentation Portal
Jump to: navigation, search
(Created page with "If you are using Delphi.NET, the API can be used by referencing the DLL (a .NET assembly) directly. However, the Pastel Evolution SDK can also be used from Delphi for Win32 b...")
 
(No difference)

Latest revision as of 12:50, 26 October 2015

If you are using Delphi.NET, the API can be used by referencing the DLL (a .NET assembly) directly.

However, the Pastel Evolution SDK can also be used from Delphi for Win32 by importing the COM type library distributed with the API as a .tlb file.

Follow these steps to get started:

  1. Refer to the COM procedure for registering the DLL for COM.
  2. Import the type library. View the procedure here.
  3. Add Pastel_Evolution_TLB to your unit's uses declaration.
  4. Add the files mscorlib_TLB.pas and System_TLB.pas to your project. You can either generate them yourself, or download them here.
  5. Refer to the below example procedure for jump-starting your integration tasks.


procedure TForm1.Button1Click(Sender: TObject);
var
  stkItem : _InventoryItem;
  customer : _Customer;
  helper : _ComHelper;
  orderDetail : _OrderDetail;
  salesOrder : _SalesOrder;
  reference, itemCode, customerCode : string;
  recordID : integer;
begin
  try
    itemCode := 'ABC001';
    customerCode := 'CASH33';
    Log('Connecting...');
    helper := CoComHelper.Create();
    helper.CreateCommonDBConnection('server=.;initial catalog=EvolutionCommon;integrated security=SSPI');
    helper.SetLicense('DEMO', '47481667230473');
    helper.CreateConnection('server=.;initial catalog=50127;integrated security=SSPI');
    helper.BeginTran;
    Log('...connected');
    Log('Expected DB version', helper.CompatibleEvolutionDatabaseVersion);
    Log('Current DB version: ', helper.CurrentEvolutionDatabaseVersion);
    if helper.CompatibleEvolutionDatabaseVersion <> helper.CurrentEvolutionDatabaseVersion then
      Log('WARNING', 'The current database version differs from version expected by the API.');
    recordID := helper.FindARAccountByCode(customerCode);
    if recordID = -1 then
    begin
      // account does not exist, so create it
      customer := CoCustomer.Create();
      customer.Code := customerCode;
      customer.Description := 'Demo Account';
      customer.Save;
      Log('Account created', customer.ID);
    end
    else
    begin
      // account exists, so simply load it
      customer := helper.GetARAccount(customerCode);
    end;
    Log('Creating order...');
    salesOrder := CoSalesOrder.Create();
    salesOrder.Customer := customer;
    Log('Creating detail...');
    orderDetail := CoOrderDetail.Create;
    // find inventory item
    recordID := helper.FindStockItemByCode(itemCode);
    if recordID = -1 then
    begin
      // item does not exist, so create it
      stkItem := CoInventoryItem.Create();
      stkItem.Code := itemCode;
      stkItem.IsServiceItem := True;
      stkItem.Description := 'Demo Item';
      stkItem.Save;
      Log('Item created', stkItem.ID)
    end
    else
    begin
      // item exists, so simply load it
      stkItem := helper.GetStockItem(itemCode);
    end;
    orderDetail.InventoryItem := stkItem;
    // if this is a new item, it gets created as a service item (above),
    //   and the quantity on hand will be irrelevant
    Log('Stock on hand', stkItem.QtyOnHand);
    orderDetail.Quantity := 5;
    orderDetail.UnitSellingPrice := 100;
    orderDetail.Discount := 100;
    Log('Line total (excl.)', orderDetail.TotalExcl);
    Log('Adding detail...');
    Log('...done');
    salesOrder.Detail.Add_2(orderDetail);
    Log('Order Total (excl)', salesOrder.TotalExcl);
    reference := salesOrder.Complete;
    Log('Invoice No', reference);
    helper.CommitTran;
  except
    on E : Exception do
    begin
      helper.RollbackTran;
      ShowMessage(E.Message);
    end;
  end;
end;