ecb5e1799b9e830943ae7ccf7a89664dbdf80ceb
[freeside.git] / htdocs / docs / billing.html
1 <head>
2   <title>Billing</title>
3 </head>
4 <body>
5   <h1>Billing</h1>
6   <ul>
7     <li>To enable billing, you <b>must</b> create an <a href="config.html#invoice_template">invoice_template</a> configuration file.  An example file is available in the <i>conf/</i> directory of the distribution.  You also need to create an <a href="config.html#lpr">lpr</a> configuration file to enable postal invoices.
8     <ul>
9       <li>Optional: Invoice template customization
10         <ul>
11           <li>See the <a href="http://search.cpan.org/doc/MJD/Text-Template-1.23/Template.pm">Text::Template</a> documentation for details on the substitution language.
12           <li>You <b>must</b> call the invoice_lines() function at least once - pass it a number of lines, and it returns a list of array references, each of two elements: a service description column, and a price column.
13           <li>In addition, the following variables are available:
14             <ul>
15               <li>$invnum - invoice number
16               <li>$date - as a UNIX timestamp (see <a href="http://search.cpan.org/doc/GBARR/TimeDate-1.09/lib/Date/Format.pm">Date::Format</a> for conversion functions).
17               <li>$page - current page
18               <li>$total_pages - total pages
19               <li>@address - A six-element array containing the customer name, company, and address.
20               <li>$overdue - true if this invoice is overdue
21             </ul>
22         </ul>
23     </ul>
24     <li>You can bill individual customers by clicking on the <i>Bill now</i> link on the main customer view.
25     <li> The <b>freeside-bill</b> script can be run daily to bill all customers.  Usage:<pre>freeside-bill [ -c [ i ] ] [ -d <i>date</i> ] [ -b ] <i>user</i></pre>
26       <ul>
27         <li>-c: Turn on collecting (you probably want this).
28         <li>-i: Real-time billing (as opposed to bacth billing).  Only relevant for credit cards.
29         <li>-d: Pretend it is <i>date</i> (parsed by <a href="http://search.cpan.org/doc/GBARR/TimeDate-1.09/lib/Date/Parse.pm">Date::Parse</a>)
30         <li>-b: N/A
31       </ul>
32       <br><br>Batch credit card processing
33       <ul>
34         <li>After this script is run, a credit card batch will be in the <a href="schema.html#cust_pay_batch">cust_pay_batch</a> table.  Export this table to your credit card batching.
35         <li>When your batch completes, erase the cust_pay_batch records in that batch and add any necessary paymants to the <a href="schema.html#cust_pay">cust_pay</a> table.  Example code to add payments is:
36         <pre>use FS::cust_pay;
37
38 # loop over all records in batch
39
40 my $payment=create FS::cust_pay (
41   'invnum' => $invnum,
42   'paid' => $paid,
43   '_date' => $_date,
44   'payby' => $payby,
45   'payinfo' => $payinfo,
46   'paybatch' => $paybatch,
47 );
48
49 my $error=$payment->insert;
50 if ( $error ) {
51   #process error
52 }
53
54 # end loop
55 </pre>
56 All fields except paybatch are contained in the cust_pay_batch table.  You can use paybatch field to track particular batches and/or particular transactions within a batch.<br><br>
57         <li>The <b>freeside-print-batch</b> script can print or email pending credit card batches for manual entry.  Usage: freeside-print-batch [-v] [-p] [-e] [-a] [-d] <i>user</i>
58           <ul>
59             <li>-v: Verbose - Prints records to STDOUT.
60             <li>-p: Print to printer lpr as found in the conf directory.
61             <li>-e: Email output to user found in the Conf email file.
62             <li>-a: Automatically pays all records in cust_pay_batch.  Use -d with this option usually.
63             <li>-d: Delete - Pays account and deletes record from cust_pay_batch.
64           </ul>
65       </ul>
66   </ul>
67 </body>