From 110335b08c6160f7c43703363f292cd12a3fbca7 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Wed, 9 Jun 2010 13:58:58 +0000 Subject: [PATCH] Merged revisions 3264-3278 via svnmerge from file:///home/developper/svn/phpcompta/branches/rel510 ........ r3268 | danydb | 2010-06-03 00:41:59 +0200 (Thu, 03 Jun 2010) | 1 line Add script for creating class based on a table ........ r3269 | danydb | 2010-06-03 00:42:51 +0200 (Thu, 03 Jun 2010) | 1 line Add script for creating class based on a table ........ r3271 | danydb | 2010-06-03 22:01:05 +0200 (Thu, 03 Jun 2010) | 10 lines remove obsolete comment ======================= include/class_lettering.php Improve generation of PHP Class for a table =========================================== dev/create_phpclass.py dev/create_file_table.sql ........ r3272 | danydb | 2010-06-03 22:30:59 +0200 (Thu, 03 Jun 2010) | 2 lines remove obsolete ........ r3273 | danydb | 2010-06-03 22:38:28 +0200 (Thu, 03 Jun 2010) | 1 line create_phpclass.php improve it ........ r3274 | danydb | 2010-06-04 01:06:20 +0200 (Fri, 04 Jun 2010) | 2 lines create_phpclass : add insert, new comment, fix load function ........ r3275 | danydb | 2010-06-04 14:02:59 +0200 (Fri, 04 Jun 2010) | 1 line add doc ........ r3276 | danydb | 2010-06-04 14:44:55 +0200 (Fri, 04 Jun 2010) | 1 line Generate child object ........ r3277 | danydb | 2010-06-09 15:57:54 +0200 (Wed, 09 Jun 2010) | 1 line Remove useless transform.py ........ r3278 | danydb | 2010-06-09 15:58:26 +0200 (Wed, 09 Jun 2010) | 1 line Housekeeping : create subfolders ........ --- dev/csv-tools/analyze.sh | 26 + dev/csv-tools/verif.py | 110 +++++ .../create-file/create_file_table.sql | 7 + .../create-file/create_phpclass.py | 445 ++++++++++++++++++ dev/{ => manage-code/housekeeping}/cleanup.sh | 0 .../housekeeping}/usage_file.py | 0 .../housekeeping}/usage_function.py | 0 .../security}/without_check.py | 1 - dev/{ => manage-code/widget}/add_require.py | 0 dev/{ => manage-code/widget}/change.py | 0 dev/{ => manage-code/widget}/transform.py | 0 dev/test-size/readme | 15 + dev/test-size/simul.py | 243 ++++++++++ include/class_lettering.php | 20 +- 14 files changed, 848 insertions(+), 19 deletions(-) create mode 100644 dev/csv-tools/analyze.sh create mode 100644 dev/csv-tools/verif.py create mode 100644 dev/manage-code/create-file/create_file_table.sql create mode 100755 dev/manage-code/create-file/create_phpclass.py rename dev/{ => manage-code/housekeeping}/cleanup.sh (100%) rename dev/{ => manage-code/housekeeping}/usage_file.py (100%) rename dev/{ => manage-code/housekeeping}/usage_function.py (100%) rename dev/{ => manage-code/security}/without_check.py (97%) rename dev/{ => manage-code/widget}/add_require.py (100%) rename dev/{ => manage-code/widget}/change.py (100%) rename dev/{ => manage-code/widget}/transform.py (100%) create mode 100644 dev/test-size/readme create mode 100755 dev/test-size/simul.py diff --git a/dev/csv-tools/analyze.sh b/dev/csv-tools/analyze.sh new file mode 100644 index 000000000..ec1c4dc82 --- /dev/null +++ b/dev/csv-tools/analyze.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# Utility for analysing CSV files +# +# GNU Gpl Author: Dany De Bontridder +######################################################################### +Help () { + echo "Usage is $0 start end " + echo "or" + echo "Usage is $0 line " +} + +Help + +FILE=file.csv + +if [ $# -eq 2 ]; then + START=$1 + END=$2 + sed -ne "${START},${END}p" $FILE | +awk 'BEGIN {FS=";"} { for ( i=1; i"$i;}}' +fi +if [ $# -eq 1 ]; then + START=$1 + sed -ne "${START}p" $FILE | +awk 'BEGIN {FS=";"} { for ( i=1; i"$i;}}' +fi diff --git a/dev/csv-tools/verif.py b/dev/csv-tools/verif.py new file mode 100644 index 000000000..0c4d53a96 --- /dev/null +++ b/dev/csv-tools/verif.py @@ -0,0 +1,110 @@ +# -*- coding: latin-1 -*- +#simple python script to check bank vs. accounts. + +import sys +import csv +import time +from datetime import date + +#bank account input file sample line: +#"Code interne";"Date";"Description";"Débit";"Crédit" +#"OD-01-00001";"18.12.2003";"versement initial capital";6200.0000; 0.0000 + +DATE_OUT_FORMAT = "%d/%m/%Y" + +def toDateString(date): + return time.strftime(DATE_OUT_FORMAT, date) + +class Extract: + def __repr__(self): + return "[%s]: %s %s" % (self.code, toDateString(self.date), self.amount) + +class Operation: + def __repr__(self): + return "[%s]: %s D: %s C: %s" % (self.code, toDateString(self.date), self.debit, self.credit) + +accountFile = sys.argv[1] +reader = csv.reader(open(accountFile, "rb"), delimiter=";") +operations = [] +reader.next() +for row in reader: + op = Operation() + #print row + if len(row) == 5: + op.code, op.date, op.desc, op.debit, op.credit = row + op.date = time.strptime(op.date, "%d.%m.%Y") + op.debit = float(op.debit) + op.credit = float(op.credit) + operations.append(op) + +print "loaded %s bank operations from %s" % (len(operations), accountFile) + +bankExtractsFile = sys.argv[2] +reader = csv.reader(open(bankExtractsFile, "rb"), delimiter=";") +extracts = [] +reader.next() +for row in reader: + ex = Extract() + #print row + ex.code, ex.date, ex.desc, ex.amount, ex.currency, ex.val_date, ex.from_account, ex.from_name, ex.com1, ex.com2, ex.ref = row + ex.com = "%s %s" % (ex.com1, ex.com2) + #transform 6.200,00 EUR in 6200.00 EUR + ex.amount = float(ex.amount.replace(".", "").replace(",", ".")) + ex.date = time.strptime(ex.date, "%d/%m/%Y") + extracts.append(ex) + +print "loaded %s bank extracts from %s" % (len(extracts), bankExtractsFile) + +#now match the two sets: +#1: we want to find one operation in financial ledger per bank extract. Amount must match. + +verbose = False + +if len(sys.argv) > 3: + operationToCheck = int(sys.argv[3]) + extracts = extracts[operationToCheck:operationToCheck+1] + verbose = True + +def matchAmount(extract, operation): + if extract.amount > 0: + return operation.debit == extract.amount + else: + return operation.credit == -extract.amount + +def checkExtract(extract, operations, verbose): + #1: get all fin. ledger operations at that date. + if verbose: + print "extract: %s" % extract + candidates = filter(lambda x: x.date == extract.date, operations) + errorMessage = None + if candidates == []: + #it may have been posted later on in the accounting. + candidates = filter(lambda x: x.date > extract.date and matchAmount(extract,x), operations) + if verbose: + print "candidates: %s " % candidates + if candidates == []: + errorMessage = "Found no ledger operations for extract: %s" % extract + else: + #2: find the one. + matches = filter(lambda x: matchAmount(extract, x) and x.code != "ANNULE", candidates) + if len(matches) != 1: + if len(matches) == 0: + errorMessage = "Problem: no candidates for extract %s" % extract + else: + errorMessage = "Problem. Multiple candidates: %s for extract %s" % (matches, extract) + else: + #remove the matched from the operations list. + operations.remove(matches[0]) + return errorMessage + + +errorCount = 0 + +for extract in extracts: + error = checkExtract(extract, operations, verbose) + if error: + errorCount = errorCount + 1 + print "%s \n" % error + + +print "Error count: %s" % errorCount diff --git a/dev/manage-code/create-file/create_file_table.sql b/dev/manage-code/create-file/create_file_table.sql new file mode 100644 index 000000000..18e2fcf21 --- /dev/null +++ b/dev/manage-code/create-file/create_file_table.sql @@ -0,0 +1,7 @@ +SELECT + columns.column_name,columns.data_type +FROM + information_schema.columns +WHERE + columns.table_name='table'; + diff --git a/dev/manage-code/create-file/create_phpclass.py b/dev/manage-code/create-file/create_phpclass.py new file mode 100755 index 000000000..913087d44 --- /dev/null +++ b/dev/manage-code/create-file/create_phpclass.py @@ -0,0 +1,445 @@ +#!/usr/bin/python + + +# Command we have to replace +# @table@ by the table name +# @id@ by the primary key +# @column_noid@ by the list of column (respect order for insert) +# @class_name@ Name of the class (uppercase) +# @column_array@ fill the $variable +# @sql_update@ the sql update +# @column_comma the column for insert and update +# read the file with the name +# first line = table name +# second line = pk + +import sys, getopt +def help(): + print """ + option are -h for help + -f input file containing the structure + -c create the code for a child class + The input file contains : + first line class name : mother class separator : (optionnal) + second line table name + 3rd PK type + ... and after all the column names and column type (see create_file_table.sql) + """ +def main(): + try: + opts,args=getopt.getopt(sys.argv[1:],'cf:h',['child','file','help']) + except getopt.GetOptError, err: + print str(err) + help() + sys.exit(-1) + filein='';child=False + for option,value in opts: + if option in ('-f','--file'): + filein=value + elif option in ('-h','--help'): + help() + sys.exit(-1) + elif option in ('-c','--child'): + child=True + if filein=='' : + help() + sys.exit(-2) + sParent="""column_name,"email"=>"column_name_email","val3"=>0); */ + + protected $variable=array(@column_array@); + function __construct ($p_cn,$p_id=0) { + $this->cn=$p_cn; + if ( $p_id == 0 ) { + /* Initialize an empty object */ + foreach ($this->variable as $key=>$value) $this->$key=''; + } else { + /* load it */ + $this->@id@=$p_id; + $this->load(); + } + } + public function get_parameter($p_string) { + if ( array_key_exists($p_string,$this->$variable) ) { + $idx=$this->$variable[$p_string]; + return $this->$idx; + } + else + throw new Exception (__FILE__.":".__LINE__.$p_string.'Erreur attribut inexistant'); + } + public function set_parameter($p_string,$p_value) { + if ( array_key_exists($p_string,$this->variable) ) { + $idx=$this->variable[$p_string]; + $this->$idx=$p_value; + } + else + throw new Exception (__FILE__.":".__LINE__.$p_string.'Erreur attribut inexistant'); + } + public function get_info() { return var_export(self::$variable,true); } + public function verify() { + // Verify that the elt we want to add is correct + /* verify only the datatype */ + @verify_data_type@ + } + public function save() { + /* please adapt */ + if ( $this->@id@ == 0 ) + $this->insert(); + else + $this->update(); + } + /** + *@brief retrieve array of object thanks a condition + *@param $cond condition (where clause) + *@param $p_array array for the SQL stmt + *@see Database::get_array + *@return an empty array if nothing is found + */ + public function seek($cond,$p_array=null) + { + $sql="select * from @table@ where $cond"; + $aobj=array(); + $array= $this->cn->get_array($cond,$p_array); + // map each row in a object + $size=$this->cn->count(); + if ( $size == 0 ) return $aobj; + for ($i=0;$i<$size;$i++) { + $oobj=new @class_name@ ($this->cn); + foreach ($array[$i] as $idx=>$value) { $oobj->$idx=$value; } + $aobj[]=clone $oobj; + } + return $aobj; + } + public function insert() { + if ( $this->verify() != 0 ) return; + /* please adapt */ + $sql="insert into @table@(@column_noid@) values (@column_insert@) returning @id@"; + + $this->@id@=$this->cn->get_value( + $sql, + array( @column_this@) + ); + + } + + public function update() { + if ( $this->verify() != 0 ) return; + /* please adapt */ + $sql="@sql_update@"; + $res=$this->cn->exec_sql( + $sql, + array(@column_comma@,$this->@id@) + ); + + } +/** + *@brief load a object + *@return 0 on success -1 the object is not found + */ + public function load() { + + $sql="select @column_select@ from @table@ where @id@=$1"; + /* please adapt */ + $res=$this->cn->get_array( + $sql, + array($this->@id@) + ); + + if ( count($res) == 0 ) { + /* Initialize an empty object */ + foreach ($this->variable as $key=>$value) $this->$key=''; + + return -1; + } + foreach ($res[0] as $idx=>$value) { $this->$idx=$value; } + return 0; + } + + public function delete() { + $sql="delete from @table@ where @id@=$1"; + $res=$this->cn->exec_sql($sql,array($this->@id@)); + } + /** + * Unit test for the class + */ + static function test_me() { + $cn=new Database(25); +$cn->start(); + echo h2info('Test object vide'); + $obj=new @class_name@($cn); + var_dump($obj); + + echo h2info('Test object NON vide'); + $obj->set_parameter('j_id',3); + $obj->load(); + var_dump($obj); + + echo h2info('Update'); + $obj->set_parameter('j_qcode','NOUVEAU CODE'); + $obj->save(); + $obj->load(); + var_dump($obj); + + echo h2info('Insert'); + $obj->set_parameter('j_id',0); + $obj->save(); + $obj->load(); + var_dump($obj); + + echo h2info('Delete'); + $obj->delete(); + echo (($obj->load()==0)?'Trouve':'non trouve'); + var_dump($obj); +$cn->rollback(); + + } + +} +@class_name@::test_me(); + +""" + sChild="""column_name,"email"=>"column_name_email","val3"=>0); */ + + protected $variable=array(@column_array@); + + public function verify() { + // Verify that the elt we want to add is correct + /* verify only the datatype */ + @verify_data_type@ + } + public function save() { + /* please adapt */ + if ( $this->@id@ == 0 ) + $this->insert(); + else + $this->update(); + } + public function insert() { + if ( $this->verify() != 0 ) return; + /* please adapt */ + $sql="insert into @table@(@column_noid@) values (@column_insert@) returning @id@"; + + $this->@id@=$this->cn->get_value( + $sql, + array( @column_this@) + ); + + } + + public function update() { + if ( $this->verify() != 0 ) return; + /* please adapt */ + $sql="@sql_update@"; + $res=$this->cn->exec_sql( + $sql, + array(@column_comma@,$this->@id@) + ); + + } +/** + *@brief load a object + *@return 0 on success -1 the object is not found + */ + public function load() { + + $sql="select @column_select@ from @table@ where @id@=$1"; + /* please adapt */ + $res=$this->cn->get_array( + $sql, + array($this->@id@) + ); + + if ( count($res) == 0 ) { + /* Initialize an empty object */ + foreach ($this->variable as $key=>$value) $this->$key=''; + + return -1; + } + foreach ($res[0] as $idx=>$value) { $this->$idx=$value; } + return 0; + } + + public function delete() { + $sql="delete from @table@ where @id@=$1"; + $res=$this->cn->exec_sql($sql,array($this->@id@)); + } + /** + * Unit test for the class + */ + static function test_me() { + $cn=new Database(25); +$cn->start(); + echo h2info('Test object vide'); + $obj=new @class_name@($cn); + var_dump($obj); + + echo h2info('Test object NON vide'); + $obj->set_parameter('j_id',3); + $obj->load(); + var_dump($obj); + + echo h2info('Update'); + $obj->set_parameter('j_qcode','NOUVEAU CODE'); + $obj->save(); + $obj->load(); + var_dump($obj); + + echo h2info('Insert'); + $obj->set_parameter('j_id',0); + $obj->save(); + $obj->load(); + var_dump($obj); + + echo h2info('Delete'); + $obj->delete(); + echo (($obj->load()==0)?'Trouve':'non trouve'); + var_dump($obj); +$cn->rollback(); + + } + +} +@class_name@::test_me(); + +""" + + # read the file + try : + file=open(filein,'r') + line=file.readlines() + mother_name='';mother_class='' + if line[0].find(':') > 0 : + class_name=(line[0].split(':'))[0].strip() + mother_name=(line[0].split(':'))[1].strip() + mother_class="extends "+mother_name + else: + class_name=line[0].strip() + mother_name='' + mother_class='' + table=line[1].strip() + (id,type_id)=line[2].strip().split('|') + id=id.strip() + column_noid='' + column_this='' + column_select='' + column_insert='' + fileoutput=open("class_"+class_name+".php",'w+') + + sep='' + i=1 + for e in line[3:]: + if e.find('|') < 0 : + continue + column_this=column_this+sep+'$this->'+(e.split('|'))[0].strip()+"\n" + column_noid=column_noid+sep+(e.split('|')[0]).strip()+"\n" + + if (e.split('|'))[1].strip() == 'date': + column_select=column_select+sep+"to_char("+(e.split('|')[0]).strip()+",'DD.MM.YYYY') as "+(e.split('|')[0]).strip()+"\n" + column_insert=column_insert+sep+"to_date($"+str(i)+",'DD.MM.YYYY') \n " + else: + column_select=column_select+sep+(e.split('|')[0]).strip()+"\n" + column_insert=column_insert+sep+'$'+str(i)+"\n" + i+=1 + sep=',' + column_array='' + sep='' + for e in line [3:]: + if e.find('|') < 0 : + continue + column_array+=sep+'"'+(e.split('|'))[0].strip()+'"=>"'+(e.split('|'))[0].strip()+'"'+"\n" + sep=',' + column_array='"'+id+'"=>"'+id+'",'+column_array + sql_update=" update "+table + i=1;sep='';set=' set ' + column_comma='' + for e in line[3:]: + if e.find('|') < 0 : + continue + if (e.split('|'))[1].strip() == 'date': + sql_update+=sep+set+(e.split('|'))[0].strip()+" =to_date($"+str(i)+",'DD.MM.YYYY')"+"\n" + else: + sql_update+=sep+set+(e.split('|'))[0].strip()+" = $"+str(i)+"\n" + set='' + column_comma+=sep+"$this->"+(e.split('|'))[0].strip()+"\n" + i+=1 + sep=',' + sql_update=sql_update+" where "+id+"= $"+str(i) + verify_data_type='' + # create verify data_type + for e in line[3:]: + if e.find('|') < 0 : + continue + + (col_id,col_type)=e.split('|') + col_id=col_id.strip() + col_type=col_type.strip() + if col_type in ('float','integer','numeric','bigint') : + verify_data_type+="if ( settype($this->"+col_id+",'float') == false )\n \ + throw new Exception('DATATYPE "+col_id+" $this->"+col_id+" non numerique');\n" + if col_type in ('date',' timestamp without time zone','timestamp with time zone'): + verify_data_type+=" if (isDate($this->"+col_id+") == null )\n \ + throw new Exception('DATATYPE "+col_id+" $this->"+col_id+" date invalide');\n" + if child == False : + sParent=sParent.replace('@id@',id) + sParent=sParent.replace('@table@',table) + sParent=sParent.replace('@class_name@',class_name) + sParent=sParent.replace('@column_noid@',column_noid) + sParent=sParent.replace('@column_array@',column_array) + sParent=sParent.replace('@sql_update@',sql_update) + sParent=sParent.replace('@column_comma@',column_comma) + sParent=sParent.replace('@column_this@',column_this) + sParent=sParent.replace('@verify_data_type@',verify_data_type) + sParent=sParent.replace('@column_select@',column_select) + sParent=sParent.replace('@column_insert@',column_insert) + sParent=sParent.replace('@mother_class@',mother_class) + fileoutput.writelines(sParent) + else: + sChild=sChild.replace('@id@',id) + sChild=sChild.replace('@table@',table) + sChild=sChild.replace('@class_name@',class_name) + sChild=sChild.replace('@column_noid@',column_noid) + sChild=sChild.replace('@column_array@',column_array) + sChild=sChild.replace('@sql_update@',sql_update) + sChild=sChild.replace('@column_comma@',column_comma) + sChild=sChild.replace('@column_this@',column_this) + sChild=sChild.replace('@verify_data_type@',verify_data_type) + sChild=sChild.replace('@column_select@',column_select) + sChild=sChild.replace('@column_insert@',column_insert) + sChild=sChild.replace('@mother_name@',mother_name) + sChild=sChild.replace('@mother_class@',mother_class) + fileoutput.writelines(sChild) + + except : + print "error " + print sys.exc_info() +if __name__ == "__main__": + main() diff --git a/dev/cleanup.sh b/dev/manage-code/housekeeping/cleanup.sh similarity index 100% rename from dev/cleanup.sh rename to dev/manage-code/housekeeping/cleanup.sh diff --git a/dev/usage_file.py b/dev/manage-code/housekeeping/usage_file.py similarity index 100% rename from dev/usage_file.py rename to dev/manage-code/housekeeping/usage_file.py diff --git a/dev/usage_function.py b/dev/manage-code/housekeeping/usage_function.py similarity index 100% rename from dev/usage_function.py rename to dev/manage-code/housekeeping/usage_function.py diff --git a/dev/without_check.py b/dev/manage-code/security/without_check.py similarity index 97% rename from dev/without_check.py rename to dev/manage-code/security/without_check.py index 2b1332330..b22589c13 100755 --- a/dev/without_check.py +++ b/dev/manage-code/security/without_check.py @@ -6,7 +6,6 @@ # Author D. DE BONTRIDDER ddebontridder@yahoo.fr -from transform import * import sys import os import glob diff --git a/dev/add_require.py b/dev/manage-code/widget/add_require.py similarity index 100% rename from dev/add_require.py rename to dev/manage-code/widget/add_require.py diff --git a/dev/change.py b/dev/manage-code/widget/change.py similarity index 100% rename from dev/change.py rename to dev/manage-code/widget/change.py diff --git a/dev/transform.py b/dev/manage-code/widget/transform.py similarity index 100% rename from dev/transform.py rename to dev/manage-code/widget/transform.py diff --git a/dev/test-size/readme b/dev/test-size/readme new file mode 100644 index 000000000..f904ac2a7 --- /dev/null +++ b/dev/test-size/readme @@ -0,0 +1,15 @@ +to use it +--------------- +a. in phpcompta create a new "dossier" +b. in the "accueil page" you can see it id +c. ./simul.py (-l|-x|-s) |psql database_name (the database name is the DOMAIN_dossierID, replace the uppercase + by the good values) + you must use -l -x or -s (see -h for help) + + +for reusing the same database +------------------------------ +* drop the database = dropdb database_name +* recreate it + createdb -T mod1 -E latin1 -O phpcompta database_name + diff --git a/dev/test-size/simul.py b/dev/test-size/simul.py new file mode 100755 index 000000000..050daf340 --- /dev/null +++ b/dev/test-size/simul.py @@ -0,0 +1,243 @@ +#!/usr/bin/python +# +# +# This file is part of PhpCompta. +# +# PhpCompta is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# PhpCompta is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with PhpCompta; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +#/ +# $Revision$ +# Copyright Author Dany De Bontridder ddebontridder@yahoo.fr + +import random +import getopt +import sys + + + + +def usage(): + print """ + For use with the demo database, this utility helps + you to create differente kind of databases for tuning + and improve the performance + parameters are : + -h help + -s generate a sql file for a small database test + -l generate a sql file for a large database test + -x generate a extra large sql for a huge database test + """ + sys.exit(-1) + +def Add_Attribut_Fiche(p_jft,p_f,p_ad_id,p_value): + # Ajout du nom + #print "insert into jnt_fic_att_value(jft_id,f_id,ad_id) values (%d,%d,%d);" % (p_jft,p_f,p_ad_id) + jnt="%d\t%d\t%d" % (p_jft,p_f,p_ad_id) + #print "insert into attr_value(jft_id,av_text) values (%d,'%s');" % (p_jft,p_value) + attr="%d\t%s" % (p_jft,p_value) + return (jnt,attr) + +def Creation_fiche (p_seq_f_id,p_seq_jft_id,p_fd_id,p_type,p_base_poste,p_nbfiche): + fiche=[] + poste_comptable=[] + Attribut=[] + jnt=[] + for i in range (0,p_nbfiche): + #def Creation fiche : + #print "insert into fiche(f_id,fd_id)values (%d,%d);" % (p_seq_f_id,p_fd_id) + fiche.append("%d\t%d" % (p_seq_f_id,p_fd_id)) + # ajout nom + nom="%s numero %08d" % (p_type,i+100) + (t1,t2)=Add_Attribut_Fiche(p_seq_jft_id,p_seq_f_id,1,nom) + jnt.append(t1) + Attribut.append(t2) + #poste comptable + str_poste_comptable='%s%04d'% (p_base_poste,i+100) + # print "insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent) values (%s,'%s',%s); " % (poste_comptable,nom,p_base_poste) + poste_comptable.append("%s\t%s\t%s" % (str_poste_comptable,nom,p_base_poste)) + p_seq_jft_id+=1 + (t1,t2)=Add_Attribut_Fiche(p_seq_jft_id,p_seq_f_id,5,str_poste_comptable) + jnt.append(t1) + Attribut.append(t2) + p_seq_jft_id+=1 + str_quick_code="FID%06d" % (p_seq_f_id) + (t1,t2)=Add_Attribut_Fiche(p_seq_jft_id,p_seq_f_id,23,str_quick_code) + jnt.append(t1) + Attribut.append(t2) + + p_seq_f_id+=1 + p_seq_jft_id+=1 + print "copy fiche(f_id,fd_id) from stdin;" + for e in fiche: print e + print "\." + print "copy tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent) from stdin;" + for e in poste_comptable: print e + print "\." + print "copy jnt_fic_att_value(jft_id,f_id,ad_id) from stdin;" + for e in jnt: print e + print "\." + print "copy attr_value(jft_id,av_text) from stdin;" + for e in Attribut: print e + print "\." + + + + +def Creation_operation(p_base,p_type): + #jrn="insert into jrn (jr_def_id,jr_montant,jr_comment,jr_date,jr_grpt_id,jr_internal,jr_tech_per)" + jrn="%d\t%.2f\t%s\t%d.%d.2005\t%d\t%s\t%d" + #jrnx="insert into jrnx (j_date,j_montant,j_poste,j_grpt,j_jrn_def,j_debit,j_tech_user,j_tech_per)" + jrnx="%d.%d.2005\t%.2f\t%s\t%d\t%d\t%s\tSIMULATION\t%d" + array_jrnx=[] + array_jrn=[] + for loop_periode in range (53,64): + for loop_day in range (1,28): + for loop_op in range (0,nb_per_day): + j_montant=round(random.randrange(100,5000)/100.0,2) + j_tva=round(j_montant*0.21,2) + month=loop_periode-52 + if p_type == 'V': + j_internal='1VEN-01-%d' % (p_base) + j_client='400%04d' % (random.randrange(1,nb_fiche)+100) + #jrnx1=jrnx % (loop_day,loop_periode-39,j_montant,j_client,p_base,2,'true',loop_periode) + array_jrnx.append(jrnx % (loop_day,month,j_montant,j_client,p_base,2,'true',loop_periode)) + #print jrnx1 + array_jrnx.append(jrnx % (loop_day,month,j_tva,'4511',p_base,2,'false',loop_periode)) + #print jrnx1 + total=j_montant+j_tva + array_jrnx.append( jrnx % (loop_day,month,total,'700',p_base,2,'false',loop_periode)) + #print jrnx1 + array_jrn.append(jrn%(2,total,j_internal,loop_day,month,p_base,j_internal,loop_periode)) + #print jrn1 + p_base+=1 + if p_type== 'A': + j_internal='1ACH-01-%d' % (p_base) + j_fournisseur='440%04d' % (random.randrange(0,nb_fiche)+100) + j_charge='61%04d' % (random.randrange(0,nb_charge)+100) + array_jrnx.append(jrnx%(loop_day,month,j_montant,j_fournisseur,p_base,3,'false',loop_periode)) + #print jrnx1 + array_jrnx.append(jrnx % (loop_day,month,j_tva,'4111',p_base,3,'true',loop_periode)) + #print jrnx1 + total=j_montant+j_tva + array_jrnx.append(jrnx % (loop_day,month,total,j_charge,p_base,3,'true',loop_periode)) + #print jrnx1 + array_jrn.append(jrn%(3,total,j_internal,loop_day,month,p_base,j_internal,loop_periode)) + ##print jrn1 + p_base+=1 + if p_type== 'O': + j_internal='4ODS-01-%d' % (p_base) + j_banque='400' + j_charge='440' + array_jrnx.append(jrnx%(loop_day,month,j_montant,j_banque,p_base,4,'false',loop_periode)) + array_jrnx.append(jrnx % (loop_day,month,j_montant,j_charge,p_base,4,'true',loop_periode)) + #print jrnx1 + array_jrn.append(jrn%(4,j_montant,j_internal,loop_day,month,p_base,j_internal,loop_periode)) + ##print jrn1 + p_base+=1 + if p_type== 'F': + j_internal='1FIN-01-%d' % (p_base) + j_banque='550' + j_charge='400' + array_jrnx.append(jrnx%(loop_day,month,j_montant,j_banque,p_base,1,'false',loop_periode)) + array_jrnx.append(jrnx % (loop_day,month,j_montant,j_charge,p_base,1,'true',loop_periode)) + #print jrnx1 + array_jrn.append(jrn%(1,j_montant,j_internal,loop_day,month,p_base,j_internal,loop_periode)) + ##print jrn1 + p_base+=1 + print """copy +jrn (jr_def_id,jr_montant,jr_comment,jr_date,jr_grpt_id,jr_internal,jr_tech_per) +from stdin;""" + for e in array_jrn: print e + print "\." + print "copy jrnx (j_date,j_montant,j_poste,j_grpt,j_jrn_def,j_debit,j_tech_user,j_tech_per) from stdin;" + for e in array_jrnx: print e + print "\." + +################################################################################ +# MAIN +################################################################################ +if len(sys.argv) == 1 : + usage() + +cmd_line=sys.argv[1:] + +try : + a1,a2=getopt.getopt(cmd_line,"slxh",['small','large','extra-large','help']) +except getopt.GetoptError,msg: + print "ERROR " + print msg.msg + usage() +for option,value in a1: + if option in ('-h','--help'): + usage() + if option in ('-s','--small'): + nb_fiche=100 + nb_charge=50 + nb_per_day=5 + break + if option in ('-l','--large'): + nb_fiche=5000 + nb_charge=350 + nb_per_day=50 + if option in ('-x','--extra-large'): + nb_fiche=10000 + nb_charge=1500 + nb_per_day=500 + +print '\\timing' +print "begin;" +print "set DateStyle=European;" +# fd_id => client +fd_id=2 +# type fiche +type='Client' + +# numero de sequence fiche +f_id=1000 +# numero de sequence jnt_fic_att_value +jft_id=1000 +# poste comptable +base_poste='400' + +Creation_fiche(f_id,jft_id,fd_id,type,'400',nb_fiche) + +# fournisseur +fd_id=4 +type='Fournisseur' +f_id+=nb_fiche+100 +jft_id+=2*nb_fiche+100 +base_poste='440' + +Creation_fiche(f_id,jft_id,fd_id,type,base_poste,nb_fiche) + +# Creation Service et bien divers +fd_id=5 +type='Charge ' +f_id+=nb_fiche+100 +jft_id+=2*nb_fiche+100 +base_poste='61' + +Creation_fiche(f_id,jft_id,fd_id,type,base_poste,nb_charge) + +#Creation_operation Vente +Creation_operation(1000,'V') + +#Creation_operation Achat +Creation_operation(17000,'A') +#Creation_operation FIN +Creation_operation(34000,'F') +#Creation_operation ODS +Creation_operation(51000,'O') + +print "commit;" diff --git a/include/class_lettering.php b/include/class_lettering.php index a7c0bc81d..85f05578f 100644 --- a/include/class_lettering.php +++ b/include/class_lettering.php @@ -157,17 +157,7 @@ class Lettering } public function insert() { if ( $this->verify() != 0 ) return; - /* please adapt - $sql="insert into tva_rate (tva_label,tva_rate,tva_comment,tva_poste) ". - " values ($1,$2,$3,$4) returning tva_id"; - $this->tva_id=$this->cn->get_value( - $sql, - array($this->tva_label, - $this->tva_rate, - $this->tva_comment, - $this->tva_poste) - ); - */ + } /** *show all the record from jrnx and their status (linked or not) @@ -254,16 +244,10 @@ class Lettering } public function load() { - - $sql="select tva_label,tva_rate, tva_comment,tva_poste from tva_rate where tva_id=$1"; - if ( Database::num_row($res) == 0 ) return; - foreach ($res as $idx=>$value) { $this->$idx=$value; } } public function delete() { - /* $sql="delete from tva_rate where tva_id=$1"; - $res=$this->cn->exec_sql($sql,array($this->tva_id)); - */ + throw new Exception ('delete not implemented'); } /** * Unit test for the class