<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://developerzone-stg.pastel.co.za/index.php?action=history&amp;feed=atom&amp;title=Delphi_Sales_Orders</id>
		<title>Delphi Sales Orders - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://developerzone-stg.pastel.co.za/index.php?action=history&amp;feed=atom&amp;title=Delphi_Sales_Orders"/>
		<link rel="alternate" type="text/html" href="https://developerzone-stg.pastel.co.za/index.php?title=Delphi_Sales_Orders&amp;action=history"/>
		<updated>2026-04-17T16:52:54Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.25.2</generator>

	<entry>
		<id>https://developerzone-stg.pastel.co.za/index.php?title=Delphi_Sales_Orders&amp;diff=181&amp;oldid=prev</id>
		<title>Admin: Created page with &quot;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...&quot;</title>
		<link rel="alternate" type="text/html" href="https://developerzone-stg.pastel.co.za/index.php?title=Delphi_Sales_Orders&amp;diff=181&amp;oldid=prev"/>
				<updated>2015-10-26T09:50:59Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;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...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;If you are using Delphi.NET, the API can be used by referencing the DLL (a .NET assembly) directly.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Follow these steps to get started:&lt;br /&gt;
&lt;br /&gt;
# Refer to the [[Initialisation#COM|COM procedure]] for registering the DLL for COM.&lt;br /&gt;
# Import the type library.  View the [[SDK Delphi Import | procedure here]].&lt;br /&gt;
# Add '''Pastel_Evolution_TLB''' to your unit's ''uses'' declaration.&lt;br /&gt;
# Add the files '''mscorlib_TLB.pas''' and '''System_TLB.pas''' to your project.  You can either generate them yourself, or download them [[SDK Downloads | here]].&lt;br /&gt;
# Refer to the below example procedure for jump-starting your integration tasks.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;delphi&amp;quot;&amp;gt;&lt;br /&gt;
procedure TForm1.Button1Click(Sender: TObject);&lt;br /&gt;
var&lt;br /&gt;
  stkItem : _InventoryItem;&lt;br /&gt;
  customer : _Customer;&lt;br /&gt;
  helper : _ComHelper;&lt;br /&gt;
  orderDetail : _OrderDetail;&lt;br /&gt;
  salesOrder : _SalesOrder;&lt;br /&gt;
  reference, itemCode, customerCode : string;&lt;br /&gt;
  recordID : integer;&lt;br /&gt;
begin&lt;br /&gt;
  try&lt;br /&gt;
    itemCode := 'ABC001';&lt;br /&gt;
    customerCode := 'CASH33';&lt;br /&gt;
    Log('Connecting...');&lt;br /&gt;
    helper := CoComHelper.Create();&lt;br /&gt;
    helper.CreateCommonDBConnection('server=.;initial catalog=EvolutionCommon;integrated security=SSPI');&lt;br /&gt;
    helper.SetLicense('DEMO', '47481667230473');&lt;br /&gt;
    helper.CreateConnection('server=.;initial catalog=50127;integrated security=SSPI');&lt;br /&gt;
    helper.BeginTran;&lt;br /&gt;
    Log('...connected');&lt;br /&gt;
    Log('Expected DB version', helper.CompatibleEvolutionDatabaseVersion);&lt;br /&gt;
    Log('Current DB version: ', helper.CurrentEvolutionDatabaseVersion);&lt;br /&gt;
    if helper.CompatibleEvolutionDatabaseVersion &amp;lt;&amp;gt; helper.CurrentEvolutionDatabaseVersion then&lt;br /&gt;
      Log('WARNING', 'The current database version differs from version expected by the API.');&lt;br /&gt;
    recordID := helper.FindARAccountByCode(customerCode);&lt;br /&gt;
    if recordID = -1 then&lt;br /&gt;
    begin&lt;br /&gt;
      // account does not exist, so create it&lt;br /&gt;
      customer := CoCustomer.Create();&lt;br /&gt;
      customer.Code := customerCode;&lt;br /&gt;
      customer.Description := 'Demo Account';&lt;br /&gt;
      customer.Save;&lt;br /&gt;
      Log('Account created', customer.ID);&lt;br /&gt;
    end&lt;br /&gt;
    else&lt;br /&gt;
    begin&lt;br /&gt;
      // account exists, so simply load it&lt;br /&gt;
      customer := helper.GetARAccount(customerCode);&lt;br /&gt;
    end;&lt;br /&gt;
    Log('Creating order...');&lt;br /&gt;
    salesOrder := CoSalesOrder.Create();&lt;br /&gt;
    salesOrder.Customer := customer;&lt;br /&gt;
    Log('Creating detail...');&lt;br /&gt;
    orderDetail := CoOrderDetail.Create;&lt;br /&gt;
    // find inventory item&lt;br /&gt;
    recordID := helper.FindStockItemByCode(itemCode);&lt;br /&gt;
    if recordID = -1 then&lt;br /&gt;
    begin&lt;br /&gt;
      // item does not exist, so create it&lt;br /&gt;
      stkItem := CoInventoryItem.Create();&lt;br /&gt;
      stkItem.Code := itemCode;&lt;br /&gt;
      stkItem.IsServiceItem := True;&lt;br /&gt;
      stkItem.Description := 'Demo Item';&lt;br /&gt;
      stkItem.Save;&lt;br /&gt;
      Log('Item created', stkItem.ID)&lt;br /&gt;
    end&lt;br /&gt;
    else&lt;br /&gt;
    begin&lt;br /&gt;
      // item exists, so simply load it&lt;br /&gt;
      stkItem := helper.GetStockItem(itemCode);&lt;br /&gt;
    end;&lt;br /&gt;
    orderDetail.InventoryItem := stkItem;&lt;br /&gt;
    // if this is a new item, it gets created as a service item (above),&lt;br /&gt;
    //   and the quantity on hand will be irrelevant&lt;br /&gt;
    Log('Stock on hand', stkItem.QtyOnHand);&lt;br /&gt;
    orderDetail.Quantity := 5;&lt;br /&gt;
    orderDetail.UnitSellingPrice := 100;&lt;br /&gt;
    orderDetail.Discount := 100;&lt;br /&gt;
    Log('Line total (excl.)', orderDetail.TotalExcl);&lt;br /&gt;
    Log('Adding detail...');&lt;br /&gt;
    Log('...done');&lt;br /&gt;
    salesOrder.Detail.Add_2(orderDetail);&lt;br /&gt;
    Log('Order Total (excl)', salesOrder.TotalExcl);&lt;br /&gt;
    reference := salesOrder.Complete;&lt;br /&gt;
    Log('Invoice No', reference);&lt;br /&gt;
    helper.CommitTran;&lt;br /&gt;
  except&lt;br /&gt;
    on E : Exception do&lt;br /&gt;
    begin&lt;br /&gt;
      helper.RollbackTran;&lt;br /&gt;
      ShowMessage(E.Message);&lt;br /&gt;
    end;&lt;br /&gt;
  end;&lt;br /&gt;
end;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>