[CS-Project-svn_notify] SF.net SVN: cs-project: [718] trunk
Brought to you by:
crazedsanity
From: <cra...@us...> - 2007-12-27 16:38:27
|
Revision: 718 http://cs-project.svn.sourceforge.net/cs-project/?rev=718&view=rev Author: crazedsanity Date: 2007-12-27 08:38:24 -0800 (Thu, 27 Dec 2007) Log Message: ----------- Pull invoice changes from the branch into the main line of development. NOTE: changed version to 1.2.0-ALPHA1, so I know this won't be added to 1.1 SVN COMMAND::: merge -r697:HEAD https://cs-project.svn.sourceforge.net/svnroot/cs-project/branches/invoices Modified Paths: -------------- trunk/VERSION trunk/docs/sql/upgrades/upgradeTo1.1.0-BETA16.sql trunk/lib/invoice.class.php trunk/lib/invoiceItem.class.php trunk/lib/invoiceTransaction.class.php Added Paths: ----------- trunk/lib/invoiceViewer.class.php Modified: trunk/VERSION =================================================================== --- trunk/VERSION 2007-12-27 16:35:48 UTC (rev 717) +++ trunk/VERSION 2007-12-27 16:38:24 UTC (rev 718) @@ -1,4 +1,4 @@ $Id:VERSION 628 2007-11-20 16:58:45Z crazedsanity $ -VERSION: 1.1.0 +VERSION: 1.2.0-ALPHA1 $HeadURL:https://cs-project.svn.sourceforge.net/svnroot/cs-project/trunk/VERSION $ Modified: trunk/docs/sql/upgrades/upgradeTo1.1.0-BETA16.sql =================================================================== --- trunk/docs/sql/upgrades/upgradeTo1.1.0-BETA16.sql 2007-12-27 16:35:48 UTC (rev 717) +++ trunk/docs/sql/upgrades/upgradeTo1.1.0-BETA16.sql 2007-12-27 16:38:24 UTC (rev 718) @@ -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: trunk/lib/invoice.class.php =================================================================== --- trunk/lib/invoice.class.php 2007-12-27 16:35:48 UTC (rev 717) +++ trunk/lib/invoice.class.php 2007-12-27 16:38:24 UTC (rev 718) @@ -16,6 +16,7 @@ //TODO: log everything! + class invoice extends dbAbstract { protected $gfObj; @@ -29,9 +30,6 @@ const mainTable = 'invoice_table'; const mainTableSeq = 'invoice_table_invoice_id_seq'; - const itemTable = 'invoice_item_table'; - const itemTableSeq = 'invoice_item_table_invoice_item_id_seq'; - const transTable = 'invoice_transaction_table'; const transTableSeq = 'invoice_transaction_table_invoice_transaction_id_seq'; @@ -86,9 +84,18 @@ //========================================================================= /** - * Add a line item to the invoice; should be an instance of invoiceItem{}. + * Add a line item to the invoice. */ - public function add_item(invoiceItem $item) { + public function add_item(array $data) { + if(is_numeric($this->invoiceId)) { + $invoiceItem = new invoiceItem($this->db, $this->invoiceId); + $retval = $invoiceItem->create_item($data); + } + else { + throw new exception(__METHOD__ .': no invoice created!'); + } + + return($retval); }//end add_item() //========================================================================= @@ -108,6 +115,8 @@ throw new exception(__METHOD__ .": failed to retrieve last invoice_id: ". $this->lastError); } + $this->invoiceId = $retval; + return($retval); }//end get_inserted_invoice_id() //========================================================================= Modified: trunk/lib/invoiceItem.class.php =================================================================== --- trunk/lib/invoiceItem.class.php 2007-12-27 16:35:48 UTC (rev 717) +++ trunk/lib/invoiceItem.class.php 2007-12-27 16:38:24 UTC (rev 718) @@ -19,20 +19,94 @@ protected $gfObj; protected $logsObj; + const itemTable = 'invoice_item_table'; + const itemTableSeq = 'invoice_item_table_invoice_item_id_seq'; + + private $invoiceId; + //========================================================================= - public function __construct(cs_phpDB $db) { + public function __construct(cs_phpDB $db, $invoiceId=NULL) { $this->db = $db; $this->gfObj = new cs_globalFunctions; $this->gfObj->debugPrintOpt = DEBUGPRINTOPT; $this->logsObj = new logsClass($this->db, 'Invoice Item'); + + $this->set_invoice_id($invoiceId); }//end __construct() //========================================================================= //========================================================================= - public function create_item(array $data) { - }//end create_item() + /** + * Set value of internal invoiceId. + */ + protected function set_invoice_id($invoiceId) { + if(is_numeric($invoiceId)) { + $this->invoiceId = $invoiceId; + } + else { + throw new exception(__METHOD__ .': invalid data ('. $invoiceId .')'); + } + }//end set_invoice_id() //========================================================================= + + + + //========================================================================= + /** + * Insert item into the database. + */ + public function insert_item(array $data) { + if(is_numeric($this->invoiceId)) { + $fields = array( + 'description' => 'sql', + 'unit_price' => 'float', + '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); + } + else { + throw new exception(__METHOD__ .': invalid data for '. $name .': ('. $data['name'] .')'); + } + } + + $insertArr['invoice_id'] = $this->invoiceId; + $sql = 'INSERT INTO '. $this->itemTable .' '. $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 invoiceId set!'); + } + + return($retval); + }//end insert_item() + //========================================================================= + + + + //========================================================================= + private function get_last_inserted_item() { + $sql = "SELECT currval('". $this->itemTableSeq ."'::text)"; + if($this->run_sql($sql)) { + $data = $this->db->farray(); + $retval = $data[0]; + } + else { + throw new exception(__METHOD__ .': failed to retrieve last invoice_item_id: '. $this->lastError); + } + + return($retval); + }//end get_last_inserted_item() + //========================================================================= } ?> Modified: trunk/lib/invoiceTransaction.class.php =================================================================== --- trunk/lib/invoiceTransaction.class.php 2007-12-27 16:35:48 UTC (rev 717) +++ trunk/lib/invoiceTransaction.class.php 2007-12-27 16:38:24 UTC (rev 718) @@ -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() + //========================================================================= } ?> Copied: trunk/lib/invoiceViewer.class.php (from rev 717, branches/invoices/lib/invoiceViewer.class.php) =================================================================== --- trunk/lib/invoiceViewer.class.php (rev 0) +++ trunk/lib/invoiceViewer.class.php 2007-12-27 16:38:24 UTC (rev 718) @@ -0,0 +1,36 @@ +<?php +/* + * This class was built to handle creation, searching, and updates of invoices. + * For searches involving items on the invoice, use invoiceItem{}. + * invoices is handled by + * + * SVN INFORMATION::: + * ------------------ + * SVN Signature::::::: $Id$ + * Last Author::::::::: $Author$ + * Current Revision:::: $Revision$ + * Repository Location: $HeadURL$ + * Last Updated:::::::: $Date$ + * + */ + +//TODO: log everything! + + +class invoiceViewer extends invoice { + + protected $gfObj; + protected $logsObj; + + + + //========================================================================= + public function __construct(cs_phpDB $db) { + $this->db = $db; + $this->gfObj = new cs_globalFunctions; + $this->gfObj->debugPrintOpt = DEBUGPRINTOPT; + $this->logsObj = new logsClass($this->db, 'Invoice Viewer'); + }//end __construct() + //========================================================================= +} +?> Property changes on: trunk/lib/invoiceViewer.class.php ___________________________________________________________________ Name: svn:keywords + Id HeadURL Date Revision Author Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |