[CS-Project-svn_notify] SF.net SVN: cs-project: [691] trunk
Brought to you by:
crazedsanity
From: <cra...@us...> - 2007-12-14 01:06:08
|
Revision: 691 http://cs-project.svn.sourceforge.net/cs-project/?rev=691&view=rev Author: crazedsanity Date: 2007-12-13 17:05:59 -0800 (Thu, 13 Dec 2007) Log Message: ----------- SQL & class changes. /docs/sql/upgrades/upgradeTo1.1.0-BETA16.sql: * added "description" to invoice status records * insert available status records. * set default for invoice_status_id on invoice_table. /lib/invoice.class.php: * MAIN::: -- updated comments at top to explain what the class is for. -- created some private members. -- created constants (table & sequence names). * create_invoice() [NEW]: -- public method to create an invoice * get_inserted_invoice_id() [NEW,PRIVATE]: -- private method for getting value of the invoice_id sequence. /lib/invoiceItem.class.php: * MAIN::: -- extends invoice instead of dbAbstract. /lib/invoiceTransaction.class.php: * MAIN::: -- extends invoice instead of dbAbstract. Modified Paths: -------------- trunk/docs/sql/upgrades/upgradeTo1.1.0-BETA16.sql trunk/lib/invoice.class.php trunk/lib/invoiceItem.class.php trunk/lib/invoiceTransaction.class.php Modified: trunk/docs/sql/upgrades/upgradeTo1.1.0-BETA16.sql =================================================================== --- trunk/docs/sql/upgrades/upgradeTo1.1.0-BETA16.sql 2007-12-13 23:42:23 UTC (rev 690) +++ trunk/docs/sql/upgrades/upgradeTo1.1.0-BETA16.sql 2007-12-14 01:05:59 UTC (rev 691) @@ -10,9 +10,15 @@ CREATE TABLE invoice_status_table ( invoice_status_id integer NOT NULL PRIMARY KEY, name text NOT NULL UNIQUE, + description text NOT NULL UNIQUE, is_updateable boolean NOT NULL DEFAULT FALSE ); +-- NOTE: by setting the invoice_status_id, we ensure they always get set properly, and new ones can't be readily inserted without specifying that too. +INSERT INTO invoice_status_table (invoice_status_id, name, description, is_updateable) VALUES (-1, 'W/0', 'Write Off', FALSE); +INSERT INTO invoice_status_table (invoice_status_id, name, description, is_updateable) VALUES (0, 'New', 'Open, pending changes', TRUE); +INSERT INTO invoice_status_table (invoice_status_id, name, description, is_updateable) VALUES (1, 'OK', 'Completed', FALSE); + CREATE TABLE invoice_table ( invoice_id integer NOT NULL PRIMARY KEY, poc text, @@ -24,7 +30,7 @@ city text, state text, zip text, - invoice_status_id integer NOT NULL REFERENCES invoice_status_table(invoice_status_id), + invoice_status_id integer NOT NULL DEFAULT 0 REFERENCES invoice_status_table(invoice_status_id), creator_contact_id integer NOT NULL REFERENCES contact_table(contact_id), billing_contact_id integer NOT NULL REFERENCES contact_table(contact_id), is_proforma boolean NOT NULL DEFAULT FALSE, Modified: trunk/lib/invoice.class.php =================================================================== --- trunk/lib/invoice.class.php 2007-12-13 23:42:23 UTC (rev 690) +++ trunk/lib/invoice.class.php 2007-12-14 01:05:59 UTC (rev 691) @@ -1,5 +1,8 @@ <?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::: * ------------------ @@ -18,6 +21,20 @@ protected $gfObj; protected $logsObj; + private $invoiceId = NULL; + private $creatorContactId = NULL; + private $billingContactId = NULL; + + //set some internal things that should NEVER be changed after initialization. + 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'; + //========================================================================= public function __construct(cs_phpDB $db) { $this->db = $db; @@ -30,8 +47,69 @@ //========================================================================= + /** + * Method to handle creating the main invoice record. + */ + public function create_invoice(array $invoiceData, $isProforma=FALSE) { + $cleanFields = array( + 'poc','company', 'address1', 'address2', 'phone', 'fax', 'city', + 'state', 'zip' + ); + + $insertArr = array(); + foreach($invoiceData as $name=>$value) { + $insertArr[$name] = $this->gfObj->cleanString($value, 'sql'); + } + + if($isProforma === TRUE) { + $insertArr['is_proforma'] = 't'; + } + + $insertString = $this->gfObj->string_from_array($insertArr, 'insert', NULL, 'sql'); + + $sql = "INSERT INTO ". $this->mainTable .' '. $insertString; + + if($this->run_sql($sql)) { + //pull the new invoice id. + $retval = $this->get_inserted_invoice_id(); + } + else { + throw new exception(__METHOD__ .': failed to insert new invoice: '. $this->lastError ."<BR>\nSQL::: ". $sql); + } + + return($retval); + + }//end create_invoice() + //========================================================================= + + + + //========================================================================= + /** + * Add a line item to the invoice; should be an instance of invoiceItem{}. + */ public function add_item(invoiceItem $item) { }//end add_item() //========================================================================= + + + + //========================================================================= + /** + * Retrieve the invoice_id that was last inserted. + */ + private function get_inserted_invoice_id() { + $sql = "SELECT currval('". $this->mainTableSeq ."'::text)"; + if($this->run_sql($sql)) { + $data = $this->db->farray(); + $retval = $data[0]; + } + else { + throw new exception(__METHOD__ .": failed to retrieve last invoice_id: ". $this->lastError); + } + + return($retval); + }//end get_inserted_invoice_id() + //========================================================================= } ?> Modified: trunk/lib/invoiceItem.class.php =================================================================== --- trunk/lib/invoiceItem.class.php 2007-12-13 23:42:23 UTC (rev 690) +++ trunk/lib/invoiceItem.class.php 2007-12-14 01:05:59 UTC (rev 691) @@ -14,7 +14,7 @@ //TODO: log everything! -class invoiceItem extends dbAbstract { +class invoiceItem extends invoice { protected $gfObj; protected $logsObj; Modified: trunk/lib/invoiceTransaction.class.php =================================================================== --- trunk/lib/invoiceTransaction.class.php 2007-12-13 23:42:23 UTC (rev 690) +++ trunk/lib/invoiceTransaction.class.php 2007-12-14 01:05:59 UTC (rev 691) @@ -13,7 +13,7 @@ //TODO: log everything! -class invoiceTransaction extends dbAbstract { +class invoiceTransaction extends invoice { protected $gfObj; protected $logsObj; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |