Overview
The Calculate Freight function automatically calculates the shipping charge for an order.
Setup
Administrator access to the SQL server is required to set up the freight values. SalesPad ships with the sppGetSalesDocumentFreight stored procedure but will need to have an additional stored procedure created to store the freight calculation rules and values. An example stored procedure, cp_CalculateFreight, containing freight rules and values is shown below. To create a new stored procedure on the SQL server:
- Name it cp_CalculateFreight
- Copy and paste the code below
- Edit the section below CASE to be the desired freight rules and values
- Save the changes
cp_CalculateFreight Stored Procedure (copy and paste)
SET ANSI_NULLS ON GO
SET QUOTED_IDENTIFIER ON USE [TWO]
GO
SET ANSI_NULLS ON GO
SET QUOTED_IDENTIFIER ON
ALTER procedure [dbo].[cp_CalculateFreight]
@freight_amt money output,
@ship_method varchar(40),
@Subtotal money,
@returnRecordSet as bit = 0
AS
set @freight_amt =
'CASE
WHEN (@Subtotal < 25) THEN 11.95
WHEN (@Subtotal < 50) THEN 15.95
WHEN (@Subtotal < 100) THEN 16.95
WHEN (@Subtotal >= 100) THEN 55.99
ELSE 0
END'
Finally, edit the sppGetSalesDocumentFreight stored procedure:
- Select sppGetSalesDocumentFreight from the stored procedures list
- Right-click and select Modify
- The text shown below in red must have the same name as the new stored procedure created with the freight rules and values.
sppGetSalesDocumentFreight Stored Procedure
SET ANSI_NULLS ON GO
SET QUOTED_IDENTIFIER ON GO
ALTER procedure [dbo].[sppGetSalesDocumentFreight]
@Shipping_Method as varchar(50) = '',
@Subtotal as numeric(19,5) = 0,
@Weight as numeric(19,5) = 0,
@Freight as numeric(19,5) = 0,
@Message as varchar(500) = ''
as
if (object_id('cp_CalculateFreight') is not null ) begin
exec cp_CalculateFreight @Freight output, @Shipping_Method,
@Subtotal end
select Shipping_Method=@Shipping_Method, Subtotal=@Subtotal, Weight=@Weight,
Freight = cast(@Freight as numeric (19,5)), Message = ''
Usage
Select any order and open it. There will now be an ellipsis in the Freight box. Clicking on the ellipsis (...) will automatically calculate freight based on the defined freight rules and values:
Settings
Calculate Freight Enabled - Enables the Calculate freight button link in a Sales Document