Пример #1
0
 /**
  * Insert an Invoice
  * 
  * ToDo: missing check foreign keys
  * 
  * @see lib/Zend/Db/Table/Zend_Db_Table_Abstract::insert()
  */
 public function insert($data)
 {
     $SI_PREFERENCES = new SimpleInvoices_Db_Table_Preferences();
     $pref_group = $SI_PREFERENCES->getPreferenceById($_POST['preference_id']);
     $auth_session = Zend_Registry::get('auth_session');
     $data['domain_id'] = $auth_session->domain_id;
     $data['index_id'] = SimpleInvoices_Db_Table_Index::NEXT('invoice', $pref_group['index_group']);
     $result = parent::insert($data);
     $this->_last_inserted_id = $this->getAdapter()->lastInsertId($this->_name, 'id');
     // Increment Index if inserted
     if ($result) {
         SimpleInvoices_Db_Table_Index::INCREMENT('invoice', $pref_group['index_group']);
     }
     return $result;
 }
Пример #2
0
    public static function increment($node,$sub_node="")
    {
    
        $next = SimpleInvoices_Db_Table_Index::NEXT($node,$sub_node);

        global $db;
        global $auth_session;
        global $dbh;
        
        /*
        if ($sub_node !="") 
        {
            $subnode = "and sub_node = ".$sub_node; 
        }
        */

        if ($next == 1)
        {

            $sql = "insert into ".TB_PREFIX."index (id, node, sub_node, domain_id) VALUES (:id, :node, :sub_node, :domain_id);";

        } else {

            $sql ="update
                        ".TB_PREFIX."index 
                    set 
                        id = :id 
                    where
                        node = :node
                    and
                        domain_id = :domain_id
                    and
                        sub_node = :sub_node";
        }

        $sth = $db->query($sql,':id',$next,':node',$node,':sub_node', $sub_node,':domain_id',$auth_session->domain_id) or die(htmlsafe(end($dbh->errorInfo())));

        return $next;

    }
Пример #3
0
	public function insert()
	{
		//insert in si)invoice

		global $dbh;
		global $db_server;
		global $auth_session;
        $SI_PREFERENCES = new SimpleInvoices_Db_Table_Preferences();

		$sql = "INSERT
				INTO
			".TB_PREFIX."invoices (
				id,
		 		index_id,
				domain_id,
				biller_id,
				customer_id,
				type_id,
				preference_id,
				date,
				note,
				custom_field1,
				custom_field2,
				custom_field3,
				custom_field4,
                inv_status,
			)
			VALUES
			(
				NULL,
				:index_id,
				:domain_id,
				:biller_id,
				:customer_id,
				:type_id,
				:preference_id,
				:date,
				:note,
				:custom_field1,
				:custom_field2,
				:custom_field3,
				:custom_field4,
                NULL
				)";

		$pref_group= $SI_PREFERENCES->getPreferenceById($this->preference_id);

		$sth= dbQuery($sql,
			':index_id', SimpleInvoices_Db_Table_Index::NEXT('invoice',$pref_group[index_group],$this->biller_id),
			':domain_id', $auth_session->domain_id,
			':biller_id', $this->biller_id,
			':customer_id', $this->customer_id,
			':type_id', $this->type_id,
			':preference_id', $this->preference_id,
			':date', $this->date,
			':note', $this->note,
			':custom_field1', $this->custom_field1,
			':custom_field2', $this->custom_field2,
			':custom_field3', $this->custom_field3,
			':custom_field4', $this->custom_field4
			);

	    SimpleInvoices_Db_Table_Index::INCREMENT('invoice',$pref_group[index_group],$this->biller_id);

	    //return $sth;
        return SimpleInvoices_Db_Table_Invoices::LAST_INSERT_ID();
		//insert into si_invoice_items

		//insert into

	}
Пример #4
0
function updateInvoice($invoice_id) {

    global $logger;
    $SI_PREFERENCES = new SimpleInvoices_Db_Table_Preferences();
    
    $current_invoice = invoice::select($_POST['id']);
    $current_pref_group = $SI_PREFERENCES->getPreferenceById($current_invoice[preference_id]);

    $new_pref_group= $SI_PREFERENCES->getPreferenceById($_POST[preference_id]);

    $index_id = $current_invoice['index_id'];

//	$logger->log('Curent Index Group: '.$description, Zend_Log::INFO);
//	$logger->log('Description: '.$description, Zend_Log::INFO);

    if ($current_pref_group['index_group'] != $new_pref_group['index_group'])
    {
        $index_id = SimpleInvoices_Db_Table_Index::INCREMENT('invoice',$new_pref_group['index_group']);
    }

	if ($db_server == 'mysql' && !_invoice_check_fk(
		$_POST['biller_id'], $_POST['customer_id'],
		$type, $_POST['preference_id'])) {
		return null;
	}
	$sql = "UPDATE
			".TB_PREFIX."invoices
		SET
			index_id = :index_id,
			biller_id = :biller_id,
			customer_id = :customer_id,
			preference_id = :preference_id,
			date = :date,
			note = :note,
			custom_field1 = :customField1,
			custom_field2 = :customField2,
			custom_field3 = :customField3,
			custom_field4 = :customField4
		WHERE
			id = :invoice_id";

	return dbQuery($sql,
        ':index_id', $index_id,
		':biller_id', $_POST['biller_id'],
		':customer_id', $_POST['customer_id'],
		':preference_id', $_POST['preference_id'],
		':date', $_POST['date'],
		':note', $_POST['note'],
		':customField1', $_POST['customField1'],
		':customField2', $_POST['customField2'],
		':customField3', $_POST['customField3'],
		':customField4', $_POST['customField4'],
		':invoice_id', $invoice_id
		);
}