[CS-Project-svn_notify] SF.net SVN: cs-project: [699] branches/invoices
Brought to you by:
crazedsanity
From: <cra...@us...> - 2007-12-18 03:12:05
|
Revision: 699 http://cs-project.svn.sourceforge.net/cs-project/?rev=699&view=rev Author: crazedsanity Date: 2007-12-17 19:12:01 -0800 (Mon, 17 Dec 2007) Log Message: ----------- Updated schema, more methods & such. Modified Paths: -------------- branches/invoices/docs/sql/upgrades/upgradeTo1.1.0-BETA16.sql branches/invoices/lib/invoiceItem.class.php branches/invoices/lib/invoiceTransaction.class.php Modified: branches/invoices/docs/sql/upgrades/upgradeTo1.1.0-BETA16.sql =================================================================== --- branches/invoices/docs/sql/upgrades/upgradeTo1.1.0-BETA16.sql 2007-12-18 02:56:12 UTC (rev 698) +++ branches/invoices/docs/sql/upgrades/upgradeTo1.1.0-BETA16.sql 2007-12-18 03:12:01 UTC (rev 699) @@ -42,7 +42,7 @@ invoice_item_id integer NOT NULL PRIMARY KEY, invoice_id integer NOT NULL REFERENCES invoice_table(invoice_id), description text NOT NULL, - unit_price decimal(10,2), + unit_price decimal(5,2), quantity integer NOT NULL DEFAULT 1 ); @@ -52,7 +52,10 @@ invoice_transaction_id integer NOT NULL PRIMARY KEY, invoice_id integer NOT NULL REFERENCES invoice_table(invoice_id), auth_string text NOT NULL, + name text text NOT NULL, number text NOT NULL, + trans_date date NOT NULL, + amount decimal(10,2) NOT NULL, date_created date NOT NULL DEFAULT CURRENT_DATE ); Modified: branches/invoices/lib/invoiceItem.class.php =================================================================== --- branches/invoices/lib/invoiceItem.class.php 2007-12-18 02:56:12 UTC (rev 698) +++ branches/invoices/lib/invoiceItem.class.php 2007-12-18 03:12:01 UTC (rev 699) @@ -65,6 +65,7 @@ 'quantity' => 'int' ); + $invoiceArr = array(); foreach($fields as $name=>$cleanType) { if(isset($data[$name]) && strlen($this->gfObj->cleanString($data[$name], $cleanType))) { $insertArr[$name] = $this->gfObj->cleanString($data[$name], $cleanType); Modified: branches/invoices/lib/invoiceTransaction.class.php =================================================================== --- branches/invoices/lib/invoiceTransaction.class.php 2007-12-18 02:56:12 UTC (rev 698) +++ branches/invoices/lib/invoiceTransaction.class.php 2007-12-18 03:12:01 UTC (rev 699) @@ -18,13 +18,96 @@ protected $gfObj; protected $logsObj; + private $invoiceId; + + const dbTable = 'invoice_transaction_table'; + const dbSeqName = 'invoice_transaction_table_invoice_transaction_id_seq'; + //========================================================================= - public function __construct(cs_phpDB $db) { + public function __construct(cs_phpDB $db, $invoiceId) { $this->db = $db; $this->gfObj = new cs_globalFunctions; $this->gfObj->debugPrintOpt = DEBUGPRINTOPT; $this->logsObj = new logsClass($this->db, 'Invoice Transaction'); + $this->set_invoice_id($invoiceId); }//end __construct() //========================================================================= + + + + //========================================================================= + /** + * Method to set internal invoiceId value. + */ + private function set_invoice_id($invoiceId) { + if(is_numeric($invoiceId)) { + $this->invoiceId = $invoiceId; + } + else { + throw new exception(_METHOD__ .': invalid data for invoice!'); + } + }//end set_invoice_id() + //========================================================================= + + + + //========================================================================= + /** + * Insert invoice transaction record into the database. + */ + public function create_invoice_transaction(array $data) { + if(is_numeric($this->invoiceId)) { + $fields = array( + 'auth_string' => 'sql', + 'name' => 'sql', + 'number' => 'sql', + 'trans_date' => 'date', + 'amount' => 'float' + ); + + $insertArr = array(); + foreach($fields as $name=>$cleanType) { + if(isset($data[$name]) && strlen($this->gfObj->cleanString($data[$name], $cleanType))) { + $insertArr[$name] = $this->gfObj->cleanString($data[$name], $cleanType); + } + else { + throw new exception(__METHOD__ .': invalid data for '. $name .': ('. $data['name'] .')'); + } + } + + $insertArr['invoice_id'] = $this->invoiceId; + $sql = 'INSERT INTO '. $this->dbTable .' '. $this->gfObj->string_from_array($insertArr, 'insert', NULL, 'sql'); + if($this->run_sql($sql) && !strlen($this->lastError)) { + $retval = $this->get_last_inserted_item(); + } + else { + throw new exception(__METHOD__ .': failed to insert item: '. $this->lastError); + } + } + else { + throw new exception(__METHOD__ .': no invoice_id set!'); + } + }//end create_invoice_transaction() + //========================================================================= + + + + //========================================================================= + /** + * Retrieve last invoice_transaction_id inserted. + */ + private function get_last_inserted_transaction_id() { + $sql = "SELECT currval('". $this->dbSeqName ."'::text)"; + if($this->run_sql($sql)) { + $data = $this->db->farray(); + $retval = $data[0]; + } + else { + throw new exception(__METHOD__ .': failed to retrieve last invoice_transaction_id: '. $this->lastError); + } + + return($retval); + }//end get_last_inserted_transaction_id() + //========================================================================= } ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |