From dfee67cf2ac09f777d1f9640b25675498153996d Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Fri, 28 Nov 2008 09:58:57 +1300 Subject: [PATCH] Helper functions for creating newbatch/newdoc... records. --- inc/transaction_helpers.php | 71 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 inc/transaction_helpers.php diff --git a/inc/transaction_helpers.php b/inc/transaction_helpers.php new file mode 100644 index 0000000..7d995b1 --- /dev/null +++ b/inc/transaction_helpers.php @@ -0,0 +1,71 @@ + +* @copyright Morphoss Ltd +* @license http://gnu.org/copyleft/gpl.html GNU GPL v2 or later +*/ + +/** +* Create a new batch +* @param string $batchtype The type of batch - 'AUTO' or 'NORM' +* @param int $documentcount The number of documents in the batch +* @param float $total The total of the transactions in the batch +* @param string $description The description of the batch +* +* @return int The batchcode for the created batch +*/ +function create_newbatch( $batchtype, $total, $description ) { + global $session; + $qry = new PgQuery("SELECT nextval('newbatch_batchcode_seq');"); + if ( $qry->Exec("approve_invoices") && $qry->rows == 1 && $row = $qry->Fetch() ) { + $batchcode = $row->nextval; + } + + $qry = new PgQuery("BEGIN;INSERT INTO newbatch ( batchcode, personcode, batchtype, total, description ) VALUES(?,?,?,?,?);", + $batchcode, $session->user_no, $batchtype, $total, $description ); + $qry->Exec("txn_helper: $description"); + + return $batchcode; +} + +/** +* Create a new document in this batch +* @param string $description The description of the document +* @param string $reference The reference for the document +* @param string $documenttype The type of document 'INVC' or 'VCHR' or 'CHEQ' or such +*/ +function create_newdocument( $description, $reference, $documenttype ) { + global $batchcode, $documentcode; + + if ( !isset($documentcode) ) $documentcode = 0; + + $sql = "INSERT INTO newdocument ( batchcode, documentcode, description, reference, documenttype ) VALUES( ?,?,?,?,? )"; + $qry = new PgQuery( $sql, $batchcode, ++$documentcode, $description, $reference, $documenttype ); + $qry->Exec("txn_helper: $reference"); +} + + +/** +* Create a new transaction in this batch +* @param string $et The entitytype for the transaction to apply against +* @param string $ec The entitycode for the transaction to apply against +* @param string $ac The accountcode for the transaction to apply against +* @param date $date The date of the transaction +* @param money $amount The value of the transaction +* @param string $description The description for this transaction (default null means use document description) +* @param string $reference The reference for this transaction (default null means use document reference) +* @param int $consequenceof This transaction is a consequence of some other transaction (default null) +* @param int $monthcode The month to post the transaction to (default to null, which means the month will be set on batch update) +*/ +function create_newtransaction( $et, $ec, $ac, $date, $amount, $description=null, $reference=null, $consequenceof=0, $monthcode=null ) { + global $batchcode, $documentcode, $transactioncode; + + if ( !isset($transactioncode) ) $transactioncode = 1; + + $sql = "INSERT INTO newaccttrans ( batchcode, documentcode, transactioncode, entitytype, entitycode, accountcode, date, description, amount, reference, consequenceof, monthcode) VALUES( ?,?,?,?,?,?,?,?,?,?,?,? )"; + $qry = new PgQuery( $sql, $batchcode, $documentcode, $transactioncode++, $et, $ec, $ac, $date, $description, $amount, $reference, $consequenceof, $monthcode ); + $qry->Exec("txn_helper: Batch $batchcode, Doc $documentcode"); +} -- 2.11.4.GIT